message
stringlengths
2
44.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
276
109k
cluster
float64
23
23
__index_level_0__
int64
552
217k
Provide tags and a correct Python 3 solution for this coding contest problem. 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>
instruction
0
31,821
23
63,642
Tags: brute force, strings Correct Solution: ``` import math class CodeforcesTask1147BSolution: def __init__(self): self.result = '' self.n_m = [] self.points = [] def read_input(self): self.n_m = [int(x) for x in input().split(" ")] for x in range(self.n_m[1]): self.points.append([int(y) for y in input().split(" ")]) def process_task(self): can = False segm = {} for point in self.points: segm["{0}_{1}".format(*point)] = True segm["{1}_{0}".format(*point)] = True for k in range(1, self.n_m[0]): if not self.n_m[0] % k: #print(k) do = True for p in self.points: a, b = (p[0] + k) % self.n_m[0], (p[1] + k) % self.n_m[0] if not a: a = self.n_m[0] if not b: b = self.n_m[0] if not "{0}_{1}".format(a, b) in segm: do = False break if do: can = do break self.result = "Yes" if can else "No" def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask1147BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
output
1
31,821
23
63,643
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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> Submitted Solution: ``` 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' if __name__ == '__main__': [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)) ```
instruction
0
31,822
23
63,644
Yes
output
1
31,822
23
63,645
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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> Submitted Solution: ``` from collections import defaultdict, deque n, m = [int(item) for item in input().split()] s = [] for _ in range(m): s.append([int(item) for item in input().split()]) divs = [] for i in range(1, n): if n % i == 0: divs.append(i) def gcd(a, b): while b: a, b = b, a % b return a def isSubArray(A, B): n, m = len(A), len(B) i = 0 j = 0 while (i < n and j < m): if (A[i] == B[j]): i += 1 j += 1 if (j == m): return True else: i += 1 j = 0 return False def check(a, v): new = [(x + v - 1) % n + 1 for x in a] # print(new, a) return sorted(new) == sorted(a) def get_value(a): if len(a) == 1: return -1 p = len(a) for v in divs: if check(a, v): return v return -1 def solve(): if n == 2: return True d = defaultdict(list) for l, r in s: d[min(abs(l - r), n - abs(l - r))].extend([l, r]) # for x in d: # d[x].sort() # print(dict(d)) verdict = True values = [] for x in d: values.append(get_value(d[x])) if -1 in values: return False v = values[0] for x in values[1:]: v = v * x // gcd(v, x) if v < n: return True return False # print(get_value([1, 2, 4, 5, 7, 8, 10, 11])) print("Yes" if solve() else "No") ```
instruction
0
31,823
23
63,646
Yes
output
1
31,823
23
63,647
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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> Submitted Solution: ``` def main(): from sys import stdin, stdout def read(): return stdin.readline().rstrip('\n') def read_array(sep=None, maxsplit=-1): return read().split(sep, maxsplit) def read_int(): return int(read()) def read_int_array(sep=None, maxsplit=-1): return [int(a) for a in read_array(sep, maxsplit)] def write(*args, **kwargs): sep = kwargs.get('sep', ' ') end = kwargs.get('end', '\n') stdout.write(sep.join(str(a) for a in args) + end) def write_array(array, **kwargs): sep = kwargs.get('sep', ' ') end = kwargs.get('end', '\n') stdout.write(sep.join(str(a) for a in array) + end) n, m = read_int_array() lines = set() for _ in range(m): a, b = read_int_array() lines.add((min(a, b)-1, max(a, b)-1)) for i in range(1, n): if n % i == 0: for a, b in lines: a, b = (a + i) % n, (b + i) % n if a > b: a, b = b, a if (a, b) not in lines: break else: write("Yes") return write("No") main() ```
instruction
0
31,824
23
63,648
Yes
output
1
31,824
23
63,649
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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> Submitted Solution: ``` def main(): from sys import stdin, stdout def read(): return stdin.readline().rstrip('\n') def read_array(sep=None, maxsplit=-1): return read().split(sep, maxsplit) def read_int(): return int(read()) def read_int_array(sep=None, maxsplit=-1): return [int(a) for a in read_array(sep, maxsplit)] def write(*args, **kwargs): sep = kwargs.get('sep', ' ') end = kwargs.get('end', '\n') stdout.write(sep.join(str(a) for a in args) + end) def write_array(array, **kwargs): sep = kwargs.get('sep', ' ') end = kwargs.get('end', '\n') stdout.write(sep.join(str(a) for a in array) + end) def list_factors(x): floor = math.floor(math.sqrt(x)) lower_side = [] higher_side = [] for i in range(1, floor + 1): if x % i == 0: lower_side.append(i) higher_side.append(x // i) if lower_side[-1] == higher_side[-1]: higher_side.pop() return lower_side + higher_side[::-1] n, m = read_int_array() lines = set() for _ in range(m): a, b = read_int_array() lines.add((min(a, b)-1, max(a, b)-1)) for i in range(1, n): if n % i == 0: for a, b in lines: a, b = (a + i) % n, (b + i) % n if a > b: a, b = b, a if (a, b) not in lines: break else: write("Yes") return write("No") main() ```
instruction
0
31,825
23
63,650
Yes
output
1
31,825
23
63,651
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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> Submitted Solution: ``` import sys input=sys.stdin.readline import math # method to print the divisors def pr(n) : a=[] # Note that this loop runs till square root i = 1 while i <= math.sqrt(n): if (n % i == 0) : # If divisors are equal, print only one if (n / i == i) : a.append(i) else : # Otherwise print both a.append(i) a.append(n//i) i = i + 1 return sorted(a) n,m=list(map(int,input().split())) c=set([]) d=[] for i in range(m): a,b=list(map(int,input().split())) a=a%n b=b%n c.add((a,b)) d.append([a,b]) e=pr(n) vis=[0]*m for i in range(len(e)-1): for j in range(m): if ((d[j][0]+e[i])%n,(d[j][1]+e[i])%n) in c or ((d[j][1]+e[i])%n,(d[j][0]+e[i])%n) in c: vis[j]=1 if vis==[1]*m: print("Yes") else: print("No") ```
instruction
0
31,826
23
63,652
No
output
1
31,826
23
63,653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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> Submitted Solution: ``` num_points, num_segments = map(int, input().split()) segments = {tuple(map(int, input().split())) for _ in range(num_segments)} for i in segments: if i[0] > i[1]: segments.remove(i) segments.add((i[1], i[0])) def rotate(segs, amount): result = set() for i in segs: a = i[0] + amount b = i[1] + amount if a > num_points: a -= num_points if b > num_points: b -= num_points result.add((min(a, b), max(a, b))) return result thing = False for i in range(1, int(num_points ** .5)): if num_points % i == 0: if segments == rotate(segments, i): thing = True break print('Yes' if thing else 'No') ```
instruction
0
31,827
23
63,654
No
output
1
31,827
23
63,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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> Submitted Solution: ``` 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(2,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") ```
instruction
0
31,828
23
63,656
No
output
1
31,828
23
63,657
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. 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> Submitted Solution: ``` from math import gcd def primes(): yield 2; yield 3; yield 5; yield 7; bps = (p for p in primes()) # separate supply of "base" primes (b.p.) p = next(bps) and next(bps) # discard 2, then get 3 q = p * p # 9 - square of next base prime to keep track of, sieve = {} # in the sieve dict n = 9 # n is the next candidate number while True: if n not in sieve: # n is not a multiple of any of base primes, if n < q: # below next base prime's square, so yield n # n is prime else: p2 = p + p # n == p * p: for prime p, add p * p + 2 * p sieve[q + p2] = p2 # to the dict, with 2 * p as the increment step p = next(bps); q = p * p # pull next base prime, and get its square else: s = sieve.pop(n); nxt = n + s # n's a multiple of some b.p., find next multiple while nxt in sieve: nxt += s # ensure each entry is unique sieve[nxt] = s # nxt is next non-marked multiple of this prime n += 2 # work on odds only import itertools def get_prime_divisors(limit): return list(itertools.filterfalse(lambda p: limit % p, itertools.takewhile(lambda p: p <= limit, primes()))) n, m = map(int, input().split()) data = {} for _ in range(m): a, b = map(int, input().split()) a, b = min(a, b), max(a, b) x, y = b-a, n-b+a if x <= y: if x in data: data[x].add(a) else: data[x] = set([a]) if y <= x: if y in data: data[y].add(b) else: data[y] = set([b]) t = n for s in data.values(): t = gcd(t, len(s)) if t == 1: print("No") else: tests = get_prime_divisors(t) for k in tests: d = n//k for s in data.values(): if any(map(lambda v: (v+d)%n not in s, s)): break else: print("Yes") break else: print("No") ```
instruction
0
31,829
23
63,658
No
output
1
31,829
23
63,659
Provide tags and a correct Python 3 solution for this coding contest problem. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image>
instruction
0
32,210
23
64,420
Tags: geometry, graphs Correct Solution: ``` from math import * eps = 1e-9 ans = dict() ans[(0,0,0)] = 4 ans[(0,0,1)] = 4 ans[(0,1,0)] = 4 ans[(1,0,0)] = 4 ans[(0,1,1)] = 4 ans[(1,0,1)] = 4 ans[(1,1,0)] = 4 ans[(1,1,1)] = 5 ans[(0,0,2)] = 5 ans[(0,2,0)] = 5 ans[(2,0,0)] = 5 ans[(0,1,2)] = 5 ans[(0,2,1)] = 5 ans[(1,0,2)] = 5 ans[(1,2,0)] = 5 ans[(2,0,1)] = 5 ans[(2,1,0)] = 5 ans[(1,1,2)] = 6 ans[(1,2,1)] = 6 ans[(2,1,1)] = 6 ans[(0,2,2)] = 6 ans[(2,0,2)] = 6 ans[(2,2,0)] = 6 ans[(1,2,2)] = 7 ans[(2,1,2)] = 7 ans[(2,2,1)] = 7 ans[(2,2,2)] = 8 def dist(A, B): return ((A[0] - B[0]) ** 2 + (A[1] - B[1]) ** 2) ** 0.5 def equal(A, B): return dist(A, B) < eps def belong(P, i): return abs(dist(P, (c[i][0], c[i][1])) - c[i][2]) < eps def intersection(c1, c2): O1 = c1[0], c1[1] O2 = c2[0], c2[1] r1, r2 = c1[2], c2[2] OO = (O2[0]- O1[0], O2[1]- O1[1]) d = dist(O1, O2) if d > r1 + r2 or d < abs(r1 - r2): return [] alp = atan2(OO[1], OO[0]) phi = acos((r1**2 + d**2 - r2**2) / (2 * r1 * d)) P1 = (r1 * cos(alp + phi) + O1[0], r1 * sin(alp + phi) + O1[1]) P2 = (r1 * cos(alp - phi) + O1[0], r1 * sin(alp - phi) + O1[1]) if equal(P1, P2): return [P1] return [P1, P2] def solve(): if n == 1: return 2 if n == 2: res = 3 inter = intersection(c[0], c[1]) if len(inter) == 2: res += 1 return res cnt = 0 inter = [0, 0, 0] p = [] for i in range(3): for j in range(i + 1, 3): cur = intersection(c[i], c[j]) for P in cur: p.append(P) inter[i + j - 1] += 1 for P in p: flag = 1 for i in range(3): if not belong(P, i): flag = 0 if flag: cnt += 1 res = ans[tuple(inter)] - cnt // 3 return res n = int(input()) c = [tuple(map(int, input().split())) for i in range(n)] print(solve()) ```
output
1
32,210
23
64,421
Provide tags and a correct Python 3 solution for this coding contest problem. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image>
instruction
0
32,211
23
64,422
Tags: geometry, graphs Correct Solution: ``` import sys import math def dist(a, b): return math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])) def samep(a, b): EPS = 0.00001 if a - b < -EPS or a - b > EPS: return False return True def same(a, b): return samep(a[0], b[0]) and samep(a[1], b[1]) def stat(a, tata): if tata[a] == a: return a x = stat(tata[a], tata) tata[a] = x return x def unesc(a, b, tata): y = stat(b, tata) x = stat(a, tata) if x != y: tata[x] = y return #fin = open('cerc.in', 'r') #fout = open('cerc.out', 'w') fin = sys.stdin fout = sys.stdout n = int(fin.readline()) a = [] for i in range(0, n): a.append(tuple([int(number) for number in fin.readline().split()])) #find V pnt = [] pntc = [] for i in range(0, n): for j in range(i + 1, n): if (a[i][0] != a[j][0] or a[i][1] != a[j][1]): a0, a1, a2 = a[i] b0, b1, b2 = a[j] c0 = 2 * (b0 - a0) c1 = 2 * (b1 - a1) c2 = -a0 * a0 + -a1 * a1 + a2 * a2 + b0 * b0 + b1 * b1 - b2 * b2 npoints = [] if c0 == 0: y0 = c2 / c1 x1 = a2 * a2 - (y0 - a1) * (y0 - a1) x0 = math.sqrt(x1) npoints.append((-x0 + a0, y0)) npoints.append((x0 + a0, y0)) else: d0 = -c1 / c0 d1 = c2 / c0 e0 = (d0 * d0 + 1) e1 = 2 * d0 * (d1 - a0) - 2 * a1 e2 = (d1 - a0) * (d1 - a0) + a1 * a1 - a2 * a2 dt = e1 * e1 - 4 * e2 * e0 if dt >= -0.000001 and dt <= 0.000001: y0 = -e1 / (2 * e0) x0 = d0 * y0 + d1 npoints.append((x0, y0)) elif dt > 0: y0 = (-e1 - math.sqrt(dt)) / (2 * e0) y1 = (-e1 + math.sqrt(dt)) / (2 * e0) x0 = d0 * y0 + d1 x1 = d0 * y1 + d1 npoints.append((x0, y0)) npoints.append((x1, y1)) for np in npoints: g = 0 for poz in range(0, len(pnt)): if same(pnt[poz], np): g = 1 pntc[poz].add(i) pntc[poz].add(j) break if g == 0: pnt.append(np) pntc.append(set({i, j})) pntc = [list(x) for x in pntc] V = len(pnt) #find C tata = list(range(0, n)) C = 1 for p in range(0, V): for i in range(0, len(pntc[p])): for j in range(i + 1, len(pntc[p])): unesc(pntc[p][i], pntc[p][j], tata) for p in range(0, n): if tata[p] == p: C += 1 #find E E = 0 for p in range(0, V): for x in pntc[p]: E += 1 F = E + C - V fout.write(repr(F)) if fin != sys.stdin: fin.close() fout.close() ```
output
1
32,211
23
64,423
Provide tags and a correct Python 3 solution for this coding contest problem. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image>
instruction
0
32,212
23
64,424
Tags: geometry, graphs Correct Solution: ``` from math import sqrt pt = lambda *a, **k: print(*a, **k, flush=True) rd = lambda: map(int, input().split()) n = int(input()) def f(x1, y1, r1, x2, y2, r2): a = (r1 + r2) ** 2 b = (r1 - r2) ** 2 d = (x1 - x2) ** 2 + (y1 - y2) ** 2 if d > a: return 1 elif d == a: return 4 elif d < b: return 3 elif d == b: return 5 else: return 2 def g(x1, y1, r1, x2, y2, r2): ds = (x1 - x2) ** 2 + (y1 - y2) ** 2 d = sqrt(ds) A = (r1 ** 2 - r2 ** 2 + ds) / (2 * d) h = sqrt(r1 ** 2 - A ** 2) x = x1 + A * (x2 - x1) / d y = y1 + A * (y2 - y1) / d x3 = x - h * (y2 - y1) / d y3 = y + h * (x2 - x1) / d x4 = x + h * (y2 - y1) / d y4 = y - h * (x2 - x1) / d return x3, y3, x4, y4 if n is 1: pt(2) if n is 2: x1, y1, r1 = rd() x2, y2, r2 = rd() a = f(x1, y1, r1, x2, y2, r2) pt(4 if a is 2 else 3) if n is 3: x1, y1, r1 = rd() x2, y2, r2 = rd() x3, y3, r3 = rd() a = f(x1, y1, r1, x2, y2, r2) b = f(x1, y1, r1, x3, y3, r3) c = f(x3, y3, r3, x2, y2, r2) t = [a, b, c] t.sort() a, b, c = t if a is 1 and b is 1 and c in [1, 3, 4, 5]: pt(4) if a is 1 and b is 1 and c is 2: pt(5) if a is 1 and b is 2 and c is 2: pt(6) if a is 1 and b is 2 and c in [3, 4, 5]: pt(5) if a is 1 and b in [3, 4, 5]: pt(4) if a is 2 and b is 2 and c is 2: x4, y4, x5, y5 = g(x1, y1, r1, x2, y2, r2) r = 8 if abs((x4 - x3) ** 2 + (y4 - y3) ** 2 - r3 ** 2) < 1e-6: r -= 1 if abs((x5 - x3) ** 2 + (y5 - y3) ** 2 - r3 ** 2) < 1e-6: r -= 1 pt(r) if a is 2 and b is 2 and c is 3: pt(6) if a is 2 and b is 2 and c in [4, 5]: x4, y4, x5, y5 = g(x1, y1, r1, x2, y2, r2) if abs((x4 - x3) ** 2 + (y4 - y3) ** 2 - r3 ** 2) < 1e-6 or abs((x5 - x3) ** 2 + (y5 - y3) ** 2 - r3 ** 2) < 1e-6: pt(6) else: pt(7) if a is 2 and b is 3: pt(5) if a is 2 and b in [4, 5]: pt(6) if a is 3 and b in [3, 4, 5]: pt(4) if a is 4 and b is 4 and c is 4: pt(5) if a is 4 and b is 4 and c is 5: pt(4) if a is 4 and b is 5 and c is 5: pt(5) if a is 5 and b is 5 and c is 5: pt(4) # Made By Mostafa_Khaled ```
output
1
32,212
23
64,425
Provide tags and a correct Python 3 solution for this coding contest problem. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image>
instruction
0
32,213
23
64,426
Tags: geometry, graphs Correct Solution: ``` from math import * ans = dict() ans[(0,0,0)] = ans[(0,0,1)] = ans[(0,1,1)] = 4 ans[(1,1,1)] = ans[(0,0,2)] = ans[(0,1,2)] = ans[(1,2,0)] = 5 ans[(1,1,2)] = ans[(0,2,2)] = 6 ans[(1,2,2)] = 7 ans[(2,2,2)] = 8 dist = lambda A, B: ((A[0] - B[0]) ** 2 + (A[1] - B[1]) ** 2) ** 0.5 belong = lambda P, i: abs(dist(P, (c[i][0], c[i][1])) - c[i][2]) < 1e-9 def intersection(c1, c2): O1 = c1[0], c1[1] O2 = c2[0], c2[1] r1, r2 = c1[2], c2[2] OO = O2[0]- O1[0], O2[1]- O1[1] d = dist(O1, O2) if d > r1 + r2 or d < abs(r1 - r2): return [] alp = atan2(OO[1], OO[0]) phi = acos((r1**2 + d**2 - r2**2) / (2 * r1 * d)) P1 = (r1 * cos(alp + phi) + O1[0], r1 * sin(alp + phi) + O1[1]) P2 = (r1 * cos(alp - phi) + O1[0], r1 * sin(alp - phi) + O1[1]) return [P1] if dist(P1, P2) < 1e-9 else [P1, P2] def solve(): if n == 1: return 2 if n == 2: return 3 + int(len(intersection(c[0], c[1])) == 2) inter = [0, 0, 0] p = [] for i in range(3): for j in range(i + 1, 3): cur = intersection(c[i], c[j]) p += cur inter[i + j - 1] += len(cur) cnt = sum(int(sum(belong(P, i) for i in (0, 1, 2)) == 3) for P in p) return ans[tuple(sorted(inter))] - cnt // 3 n = int(input()) c = [tuple(map(int, input().split())) for i in range(n)] print(solve()) ```
output
1
32,213
23
64,427
Provide tags and a correct Python 3 solution for this coding contest problem. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image>
instruction
0
32,214
23
64,428
Tags: geometry, graphs Correct Solution: ``` from decimal import * getcontext().prec = 40 eps = Decimal('1e-10') class Circle: def __init__(self, x, y, r): self.x = x self.y = y self.r = r def contains(self, c): dd = (self.x - c.x)**2 + (self.y - c.y)**2 # dd = d*d return dd < (self.r - c.r)**2 and self.r > c.r def in_touches(self, c): dd = (self.x - c.x)**2 + (self.y - c.y)**2 # dd = d*d return dd == (self.r - c.r)**2 and self.r > c.r def ex_touches(self, c): dd = (self.x - c.x)**2 + (self.y - c.y)**2 # dd = d*d return dd == (self.r + c.r)**2 def intersects(self, c): dd = (self.x - c.x)**2 + (self.y - c.y)**2 # dd = d*d return (self.r - c.r)**2 < dd < (self.r + c.r)**2 def not_intersects(self, c): dd = (self.x - c.x)**2 + (self.y - c.y)**2 # dd = d*d return dd > (self.r + c.r)**2 def get_intersections(self, c): x1, y1, r1, x2, y2, r2 = map(Decimal, [self.x, self.y, self.r, c.x, c.y, c.r]) RR = (x1-x2)**2 + (y1-y2)**2 rx1 = (x1+x2)/2 + (r1**2-r2**2)/(2*RR)*(x2-x1) + (2*(r1**2+r2**2)/RR-(r1**2-r2**2)**2/(RR**2)-1).sqrt()/2 * (y2-y1) ry1 = (y1+y2)/2 + (r1**2-r2**2)/(2*RR)*(y2-y1) + (2*(r1**2+r2**2)/RR-(r1**2-r2**2)**2/(RR**2)-1).sqrt()/2 * (x1-x2) rx2 = (x1+x2)/2 + (r1**2-r2**2)/(2*RR)*(x2-x1) - (2*(r1**2+r2**2)/RR-(r1**2-r2**2)**2/(RR**2)-1).sqrt()/2 * (y2-y1) ry2 = (y1+y2)/2 + (r1**2-r2**2)/(2*RR)*(y2-y1) - (2*(r1**2+r2**2)/RR-(r1**2-r2**2)**2/(RR**2)-1).sqrt()/2 * (x1-x2) return {(rx1, ry1), (rx2, ry2)} def is_on(self, p): return abs((self.x - p[0])**2 + (self.y - p[1])**2 - self.r**2) < eps def __repr__(self): return "(%s, %s, %s)" % (self.x, self.y, self.r) def count_regions(n, circles): if n == 1: return 2 if n == 2: return 3 + circles[0].intersects(circles[1]) if n == 3: c0, c1, c2 = circles if c0.not_intersects(c1): if c0.intersects(c2): return 5 + c1.intersects(c2) elif c0.ex_touches(c2) or c2.not_intersects(c0): return 4 + c1.intersects(c2) elif c0.contains(c2) or c0.in_touches(c2): return 4 elif c0.contains(c1): if c0.in_touches(c2) or c0.contains(c2): return 4 + c1.intersects(c2) elif c0.ex_touches(c2) or c0.not_intersects(c2): return 4 elif c0.intersects(c2): return 5 + c1.intersects(c2) elif c0.in_touches(c1): if c0.in_touches(c2): if c1.intersects(c2): return 6 elif c1.ex_touches(c2): return 5 else: return 4 elif c0.not_intersects(c2) or c0.ex_touches(c2): return 4 elif c0.contains(c2): return 4 + c1.intersects(c2) elif c0.intersects(c2): if c1.intersects(c2): # intersects: 7/6, depends on intersections c0_x_c2 = c0.get_intersections(c2) return 6 + all(not c1.is_on(p) for p in c0_x_c2) else: return 5 + (c1.ex_touches(c2) or c2.in_touches(c1)) elif c0.ex_touches(c1): if c0.in_touches(c2) or c0.contains(c2): return 4 elif c0.ex_touches(c2): if c1.intersects(c2): return 6 elif c1.ex_touches(c2): return 5 else: return 4 elif c0.not_intersects(c2): return 4 + c1.intersects(c2) elif c0.intersects(c2): if c1.intersects(c2): # intersects: 8/7/6? c0_x_c1 = c0.get_intersections(c1) return 7 + all(not c2.is_on(p) for p in c0_x_c1) elif c1.ex_touches(c2): return 6 else: return 5 elif c0.intersects(c1): if c0.not_intersects(c2): return 5 + c1.intersects(c2) elif c0.contains(c2): # [?] c1.intersects(c2) -> ? return 5 + c1.intersects(c2) elif c0.in_touches(c2) or c0.ex_touches(c2): if c1.intersects(c2): c0_x_c2 = c0.get_intersections(c2) return 6 + all(not c1.is_on(p) for p in c0_x_c2) else: return 5 + (c1.in_touches(c2) or c1.ex_touches(c2)) elif c0.intersects(c2): c0_x_c1 = c0.get_intersections(c1) if c1.intersects(c2): if all(not c2.is_on(p) for p in c0_x_c1): return 8 elif all(c2.is_on(p) for p in c0_x_c1): return 6 else: return 7 elif c1.in_touches(c2) or c1.ex_touches(c2) or c2.in_touches(c1): return 7 - any(c2.is_on(p) for p in c0_x_c1) else: # if c1.contains(c2) or c2.contains(c1) or c1.not_intersects(c2): return 6 return 4 return 0 def main(): n = int(input()) circles = [tuple(map(int, input().split())) for c in range(n)] circles.sort(key=lambda c: (-c[2], c[0], c[1])) circles = [Circle(*u) for u in circles] # print(n, circles) print(count_regions(n, circles)) if __name__ == '__main__': main() ```
output
1
32,214
23
64,429
Provide tags and a correct Python 3 solution for this coding contest problem. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image>
instruction
0
32,215
23
64,430
Tags: geometry, graphs Correct Solution: ``` from math import sqrt class vector: def __init__(self, _x = 0, _y = 0): self.x = _x self.y = _y def len(self): return sqrt(self.x ** 2 + self.y ** 2) def len_sq(self): return self.x ** 2 + self.y ** 2 def __mul__(self, other): if (type(self) == type(other)): return self.x * other.x + self.y * other.y return vector(self.x * other, self.y * other) def __mod__(self, other): return self.x * other.y - self.y * other.x def normed(self): length = self.len() return vector(self.x / length, self.y / length) def normate(self): self = self.normed() def __str__(self): return "(" + str(self.x) + ", " + str(self.y) + ")" def __add__(self, other): return vector(self.x + other.x, self.y + other.y); def __sub__(self, other): return vector(self.x - other.x, self.y - other.y); def __eq__(self, other): return self.x == other.x and self.y == other.y def rot(self): return vector(self.y, -self.x) class line: def __init__(self, a = 0, b = 0, c = 0): self.a = a self.b = b self.c = c def intersect(self, other): d = self.a * other.b - self.b * other.a dx = self.c * other.b - self.b * other.c dy = self.a * other.c - self.c * other.a return vector(dx / d, dy / d) def fake(self, other): d = self.a * other.b - self.b * other.a return d def __str__(self): return str(self.a) + "*x + " + str(self.b) + "*y = " + str(self.c) def line_pt(A, B): d = (A - B).rot() return line(d.x, d.y, d * A) class circle: def __init__(self, O = vector(0, 0), r = 0): self.O = O self.r = r def intersect(self, other): O1 = self.O O2 = other.O r1 = self.r r2 = other.r if (O1 == O2): return [] if ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2): return [] rad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq()) central = line_pt(O1, O2) M = rad_line.intersect(central) # print(M) if ((O1 - O2).len_sq() == r1 ** 2 + r2 ** 2 + 2 * r1 * r2): return [M] d = (O2 - O1).normed().rot() if (r1 ** 2 - (O1 - M).len_sq() < 0): return [] d = d * (sqrt(r1 ** 2 - (O1 - M).len_sq())) return [M + d, M - d] def fake(self, other): O1 = self.O O2 = other.O r1 = self.r r2 = other.r if (O1 == O2): return 1 if ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2): return 1 rad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq()) central = line_pt(O1, O2) return rad_line.fake(central) # a = vector(3, 4) # b = vector(4, 4) # print(circle(vector(1, 2), 3).intersect(circle(vector(2, 1), 6))) n = int(input()) arr = [] m = 1 for i in range(n): x, y, r = map(int, input().split()) arr.append(circle(vector(x, y), r)) for i in range(n): for j in range(i + 1, n): m *= arr[i].fake(arr[j]) for i in range(n): arr[i].O = arr[i].O * m arr[i].r = arr[i].r * m # print(m) s = set() V = 0 for i in range(n): for j in range(i + 1, n): tmp = arr[i].intersect(arr[j]) for e in tmp: s.add((round(e.x, 6), round(e.y, 6))) V += len(s) E = 0 par = [i for i in range(n)] def get_par(v): if (par[v] != v): par[v] = get_par(par[v]) return par[v] def unite(v, u): par[get_par(v)] = get_par(u) for i in range(n): s = set() for j in range(n): tmp = arr[i].intersect(arr[j]) if (len(tmp)): unite(i, j) for e in tmp: s.add((round(e.x, ), round(e.y, ))) E += len(s) # print(V, E) # print(len({get_par(i) for i in range(n)})) print(E - V + 1 + len({get_par(i) for i in range(n)})) ```
output
1
32,215
23
64,431
Provide tags and a correct Python 3 solution for this coding contest problem. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image>
instruction
0
32,216
23
64,432
Tags: geometry, graphs Correct Solution: ``` from math import sqrt def pt(x): print(x) rd = lambda: map(int, input().split()) n = int(input()) def f(x1, y1, r1, x2, y2, r2): a = (r1 + r2) ** 2 b = (r1 - r2) ** 2 d = (x1 - x2) ** 2 + (y1 - y2) ** 2 if d > a: return 1 elif d == a: return 4 elif d < b: return 3 elif d == b: return 5 else: return 2 def g(x1, y1, r1, x2, y2, r2): ds = (x1 - x2) ** 2 + (y1 - y2) ** 2 d = sqrt(ds) A = (r1 ** 2 - r2 ** 2 + ds) / (2 * d) h = sqrt(r1 ** 2 - A ** 2) x = x1 + A * (x2 - x1) / d y = y1 + A * (y2 - y1) / d x3 = x - h * (y2 - y1) / d y3 = y + h * (x2 - x1) / d x4 = x + h * (y2 - y1) / d y4 = y - h * (x2 - x1) / d return x3, y3, x4, y4 if n is 1: pt(2) if n is 2: x1, y1, r1 = rd() x2, y2, r2 = rd() a = f(x1, y1, r1, x2, y2, r2) pt(4 if a is 2 else 3) if n is 3: x1, y1, r1 = rd() x2, y2, r2 = rd() x3, y3, r3 = rd() a = f(x1, y1, r1, x2, y2, r2) b = f(x1, y1, r1, x3, y3, r3) c = f(x3, y3, r3, x2, y2, r2) t = [a, b, c] t.sort() a, b, c = t if a is 1 and b is 1 and c in [1, 3, 4, 5]: pt(4) if a is 1 and b is 1 and c is 2: pt(5) if a is 1 and b is 2 and c is 2: pt(6) if a is 1 and b is 2 and c in [3, 4, 5]: pt(5) if a is 1 and b in [3, 4, 5]: pt(4) if a is 2 and b is 2 and c is 2: x4, y4, x5, y5 = g(x1, y1, r1, x2, y2, r2) r = 8 if abs((x4 - x3) ** 2 + (y4 - y3) ** 2 - r3 ** 2) < 1e-6: r -= 1 if abs((x5 - x3) ** 2 + (y5 - y3) ** 2 - r3 ** 2) < 1e-6: r -= 1 pt(r) if a is 2 and b is 2 and c is 3: pt(6) if a is 2 and b is 2 and c in [4, 5]: x4, y4, x5, y5 = g(x1, y1, r1, x2, y2, r2) if abs((x4 - x3) ** 2 + (y4 - y3) ** 2 - r3 ** 2) < 1e-6 or abs((x5 - x3) ** 2 + (y5 - y3) ** 2 - r3 ** 2) < 1e-6: pt(6) else: pt(7) if a is 2 and b is 3: pt(5) if a is 2 and b in [4, 5]: pt(6) if a is 3 and b in [3, 4, 5]: pt(4) if a is 4 and b is 4 and c is 4: pt(5) if a is 4 and b is 4 and c is 5: pt(4) if a is 4 and b is 5 and c is 5: pt(5) if a is 5 and b is 5 and c is 5: pt(4) ```
output
1
32,216
23
64,433
Provide tags and a correct Python 3 solution for this coding contest problem. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image>
instruction
0
32,217
23
64,434
Tags: geometry, graphs Correct Solution: ``` from math import sqrt pt = lambda *a, **k: print(*a, **k, flush=True) rd = lambda: map(int, input().split()) n = int(input()) def f(x1, y1, r1, x2, y2, r2): a = (r1 + r2) ** 2 b = (r1 - r2) ** 2 d = (x1 - x2) ** 2 + (y1 - y2) ** 2 if d > a: return 1 elif d == a: return 4 elif d < b: return 3 elif d == b: return 5 else: return 2 def g(x1, y1, r1, x2, y2, r2): ds = (x1 - x2) ** 2 + (y1 - y2) ** 2 d = sqrt(ds) A = (r1 ** 2 - r2 ** 2 + ds) / (2 * d) h = sqrt(r1 ** 2 - A ** 2) x = x1 + A * (x2 - x1) / d y = y1 + A * (y2 - y1) / d x3 = x - h * (y2 - y1) / d y3 = y + h * (x2 - x1) / d x4 = x + h * (y2 - y1) / d y4 = y - h * (x2 - x1) / d return x3, y3, x4, y4 if n is 1: pt(2) if n is 2: x1, y1, r1 = rd() x2, y2, r2 = rd() a = f(x1, y1, r1, x2, y2, r2) pt(4 if a is 2 else 3) if n is 3: x1, y1, r1 = rd() x2, y2, r2 = rd() x3, y3, r3 = rd() a = f(x1, y1, r1, x2, y2, r2) b = f(x1, y1, r1, x3, y3, r3) c = f(x3, y3, r3, x2, y2, r2) t = [a, b, c] t.sort() a, b, c = t if a is 1 and b is 1 and c in [1, 3, 4, 5]: pt(4) if a is 1 and b is 1 and c is 2: pt(5) if a is 1 and b is 2 and c is 2: pt(6) if a is 1 and b is 2 and c in [3, 4, 5]: pt(5) if a is 1 and b in [3, 4, 5]: pt(4) if a is 2 and b is 2 and c is 2: x4, y4, x5, y5 = g(x1, y1, r1, x2, y2, r2) r = 8 if abs((x4 - x3) ** 2 + (y4 - y3) ** 2 - r3 ** 2) < 1e-6: r -= 1 if abs((x5 - x3) ** 2 + (y5 - y3) ** 2 - r3 ** 2) < 1e-6: r -= 1 pt(r) if a is 2 and b is 2 and c is 3: pt(6) if a is 2 and b is 2 and c in [4, 5]: x4, y4, x5, y5 = g(x1, y1, r1, x2, y2, r2) if abs((x4 - x3) ** 2 + (y4 - y3) ** 2 - r3 ** 2) < 1e-6 or abs((x5 - x3) ** 2 + (y5 - y3) ** 2 - r3 ** 2) < 1e-6: pt(6) else: pt(7) if a is 2 and b is 3: pt(5) if a is 2 and b in [4, 5]: pt(6) if a is 3 and b in [3, 4, 5]: pt(4) if a is 4 and b is 4 and c is 4: pt(5) if a is 4 and b is 4 and c is 5: pt(4) if a is 4 and b is 5 and c is 5: pt(5) if a is 5 and b is 5 and c is 5: pt(4) ```
output
1
32,217
23
64,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image> Submitted Solution: ``` from math import * ans = dict() ans[(0,0,0)] = ans[(0,0,1)] = ans[(0,1,1)] = 4 ans[(1,1,1)] = ans[(0,0,2)] = ans[(0,1,2)] = ans[(1,2,0)] = 5 ans[(1,1,2)] = ans[(0,2,2)] = 6 ans[(1,2,2)] = 7 ans[(2,2,2)] = 8 dist = lambda A, B: ((A[0] - B[0]) ** 2 + (A[1] - B[1]) ** 2) ** 0.5 belong = lambda P, i: abs(dist(P, (c[i][0], c[i][1])) - c[i][2]) < 1e-9 def intersection(c1, c2): O1 = c1[0], c1[1] O2 = c2[0], c2[1] r1, r2 = c1[2], c2[2] OO = O2[0]- O1[0], O2[1]- O1[1] d = dist(O1, O2) if d > r1 + r2 or d < abs(r1 - r2): return [] alp = atan2(OO[1], OO[0]) phi = acos((r1**2 + d**2 - r2**2) / (2 * r1 * d)) P1 = (r1 * cos(alp + phi) + O1[0], r1 * sin(alp + phi) + O1[1]) P2 = (r1 * cos(alp - phi) + O1[0], r1 * sin(alp - phi) + O1[1]) return [P1] if dist(P1, P2) < 1e-9 else [P1, P2] def solve(): if n == 1: return 2 if n == 2: return 3 + len(intersection(c[0], c[1])) == 2 inter = [0, 0, 0] p = [] for i in range(3): for j in range(i + 1, 3): cur = intersection(c[i], c[j]) p += cur inter[i + j - 1] += len(cur) cnt = sum(int(sum(belong(P, i) for i in (0, 1, 2)) == 3) for P in p) return ans[tuple(sorted(inter))] - cnt // 3 n = int(input()) c = [tuple(map(int, input().split())) for i in range(n)] print(solve()) ```
instruction
0
32,218
23
64,436
No
output
1
32,218
23
64,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image> Submitted Solution: ``` from math import * n=int(input()) x=[0]*n y=[0]*n r=[0]*n for i in range(n): x[i],y[i],r[i]=map(int,input().split()) if n>1: cnt=0 flag=0 for i in range(n): if sqrt((x[(i+1)%n]-x[i%n])**2+(y[(i+1)%n]-y[i%n])**2)<(r[(i+1)%n]+r[i]) and sqrt((x[(i+1)%n]-x[i%n])**2+(y[(i+1)%n]-y[i%n])**2)>abs(r[(i+1)%n]-r[i]): flag+=1 cnt+=1 if flag==3: cnt+=1 print(n+1+cnt) else: print(n+1) ```
instruction
0
32,219
23
64,438
No
output
1
32,219
23
64,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image> Submitted Solution: ``` import sys import math def dist(a, b): return math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])) def samep(a, b): EPS = 0.01 if a - b < -EPS or a - b > EPS: return False return True def same(a, b): return samep(a[0], b[0]) and samep(a[1], b[1]) def stat(a, tata): if tata[a] == a: return a x = stat(tata[a], tata) tata[a] = x return x def unesc(a, b, tata): y = stat(b, tata) x = stat(a, tata) if x != y: tata[x] = y return #fin = open('cerc.in', 'r') #fout = open('cerc.out', 'w') fin = sys.stdin fout = sys.stdout n = int(fin.readline()) a = [] for i in range(0, n): a.append(tuple([int(number) for number in fin.readline().split()])) #find V pnt = [] pntc = [] for i in range(0, n): for j in range(i + 1, n): if (a[i][0] != a[j][0] or a[i][1] != a[j][1]): a0, a1, a2 = a[i] b0, b1, b2 = a[j] c0 = 2 * (b0 - a0) c1 = 2 * (b1 - a1) c2 = -a0 * a0 + -a1 * a1 + a2 * a2 + b0 * b0 + b1 * b1 - b2 * b2 npoints = [] if c0 == 0: y0 = c2 / c1 x1 = a2 * a2 - (y0 - a1) * (y0 - a1) x0 = math.sqrt(x1) + a0 npoints.append((-x0, y0)) npoints.append((x0, y0)) else: d0 = -c1 / c0 d1 = c2 / c0 e0 = (d0 * d0 + 1) e1 = 2 * d0 * (d1 - a0) - 2 * a1 e2 = (d1 - a0) * (d1 - a0) + a1 * a1 - a2 * a2 dt = e1 * e1 - 4 * e2 * e0 print(e0, e1, e2, dt) if dt >= -0.0001 and dt <= 0.0001: y0 = -e1 / (2 * e0) x0 = d0 * y0 + d1 npoints.append((x0, y0)) elif dt > 0: y0 = (-e1 - math.sqrt(dt)) / (2 * e0) y1 = (-e1 + math.sqrt(dt)) / (2 * e0) x0 = d0 * y0 + d1 x1 = d0 * y1 + d1 npoints.append((x0, y0)) npoints.append((x1, y1)) for np in npoints: g = 0 for poz in range(0, len(pnt)): if same(pnt[poz], np): g = 1 pntc[poz].add(i) pntc[poz].add(j) break; if g == 0: pnt.append(np) pntc.append(set({i, j})) pntc = [list(x) for x in pntc] V = len(pnt) print(V) #find C tata = list(range(0, n)) C = 1 for p in range(0, V): for i in range(0, len(pntc[p])): for j in range(i + 1, len(pntc[p])): unesc(pntc[p][i], pntc[p][j], tata) for p in range(0, n): if tata[p] == p: C += 1 #find E E = 0 for p in range(0, V): for x in pntc[p]: E += 1 F = E + C - V fout.write(repr(F)) if fin != sys.stdin: fin.close() fout.close() ```
instruction
0
32,220
23
64,440
No
output
1
32,220
23
64,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. Input The first line of input contains one integer n (1 ≀ n ≀ 3), denoting the number of circles. The following n lines each contains three space-separated integers x, y and r ( - 10 ≀ x, y ≀ 10, 1 ≀ r ≀ 10), describing a circle whose center is (x, y) and the radius is r. No two circles have the same x, y and r at the same time. Output Print a single integer β€” the number of regions on the plane. Examples Input 3 0 0 1 2 0 1 4 0 1 Output 4 Input 3 0 0 2 3 0 2 6 0 2 Output 6 Input 3 0 0 2 2 0 2 1 1 2 Output 8 Note For the first example, <image> For the second example, <image> For the third example, <image> Submitted Solution: ``` from math import sqrt class vector: def __init__(self, _x = 0, _y = 0): self.x = _x self.y = _y def len(self): return sqrt(self.x ** 2 + self.y ** 2) def len_sq(self): return self.x ** 2 + self.y ** 2 def __mul__(self, other): if (type(self) == type(other)): return self.x * other.x + self.y * other.y return vector(self.x * other, self.y * other) def __mod__(self, other): return self.x * other.y - self.y * other.x def normed(self): length = self.len() return vector(self.x / length, self.y / length) def normate(self): self = self.normed() def __str__(self): return "(" + str(self.x) + ", " + str(self.y) + ")" def __add__(self, other): return vector(self.x + other.x, self.y + other.y); def __sub__(self, other): return vector(self.x - other.x, self.y - other.y); def __eq__(self, other): return self.x == other.x and self.y == other.y def rot(self): return vector(self.y, -self.x) class line: def __init__(self, a = 0, b = 0, c = 0): self.a = a self.b = b self.c = c def intersect(self, other): d = self.a * other.b - self.b * other.a dx = self.c * other.b - self.b * other.c dy = self.a * other.c - self.c * other.a return vector(dx / d, dy / d) def fake(self, other): d = self.a * other.b - self.b * other.a return d def __str__(self): return str(self.a) + "*x + " + str(self.b) + "*y = " + str(self.c) def line_pt(A, B): d = (A - B).rot() return line(d.x, d.y, d * A) class circle: def __init__(self, O = vector(0, 0), r = 0): self.O = O self.r = r def intersect(self, other): O1 = self.O O2 = other.O r1 = self.r r2 = other.r if (O1 == O2): return [] if ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2): return [] rad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq()) central = line_pt(O1, O2) M = rad_line.intersect(central) # print(M) if ((O1 - O2).len_sq() == r1 ** 2 + r2 ** 2 + 2 * r1 * r2): return [M] d = (O2 - O1).normed().rot() if (r1 ** 2 - (O1 - M).len_sq() < 0): return [] d = d * (sqrt(r1 ** 2 - (O1 - M).len_sq())) return [M + d, M - d] def fake(self, other): O1 = self.O O2 = other.O r1 = self.r r2 = other.r if (O1 == O2): return 1 if ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2): return 1 rad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq()) central = line_pt(O1, O2) return rad_line.fake(central) # a = vector(3, 4) # b = vector(4, 4) # print(circle(vector(1, 2), 3).intersect(circle(vector(2, 1), 5))) n = int(input()) arr = [] m = 1 for i in range(n): x, y, r = map(int, input().split()) arr.append(circle(vector(x, y), r)) for i in range(n): for j in range(i + 1, n): m *= arr[i].fake(arr[j]) for i in range(n): arr[i].O = arr[i].O * m arr[i].r = arr[i].r * m # print(m) s = set() V = 0 for i in range(n): for j in range(i + 1, n): tmp = arr[i].intersect(arr[j]) for e in tmp: s.add((round(e.x, 100), round(e.y, 100))) V += len(s) E = 0 par = [i for i in range(n)] def get_par(v): if (par[v] != v): par[v] = get_par(par[v]) return par[v] def unite(v, u): par[get_par(v)] = get_par(u) for i in range(n): s = set() for j in range(n): tmp = arr[i].intersect(arr[j]) if (len(tmp)): unite(i, j) for e in tmp: s.add((round(e.x, 100), round(e.y, 100))) E += len(s) # print(V, E) # print(len({get_par(i) for i in range(n)})) print(E - V + 1 + len({get_par(i) for i in range(n)})) ```
instruction
0
32,221
23
64,442
No
output
1
32,221
23
64,443
Provide tags and a correct Python 3 solution for this coding contest problem. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.
instruction
0
32,222
23
64,444
Tags: brute force, math Correct Solution: ``` n=int(input()) s=set(map(int,input().split())) m=max(s) p=0 for x in s: d=1 while x+d<=m: y=x+d if y in s: p=x,y if y+d in s: print(3);print(x,y,y+d);exit() d*=2 if p: print(2);print(*p) else:print('1\n'+str(m)) ```
output
1
32,222
23
64,445
Provide tags and a correct Python 3 solution for this coding contest problem. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.
instruction
0
32,223
23
64,446
Tags: brute force, math Correct Solution: ``` #!/usr/bin/env python3 from sys import stdin, stdout def rint(): return map(int, stdin.readline().split()) #lines = stdin.readlines() n = int(input()) x = set(rint()) x_list = list(x) x_list.sort() #print(x) #print(x_list) max_len = 1 for i in range(len(x_list)): start = x_list[i] for j in range(0, 1000): candidate = [start] next = start + 2**j if next > x_list[-1]: break if next in x: candidate.append(next) next = start + 2**(j+1) if next in x: candidate.append(next) print(3) print(*candidate) exit() else: ans = candidate max_len = 2 if max_len == 2: print(2) print(*ans) else: print(1) print(x_list[0]) ```
output
1
32,223
23
64,447
Provide tags and a correct Python 3 solution for this coding contest problem. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.
instruction
0
32,224
23
64,448
Tags: brute force, math Correct Solution: ``` from sys import stdout, stdin, setrecursionlimit from io import BytesIO, IOBase from collections import * from itertools import * from random import * from bisect import * from string import * from queue import * from heapq import * from math import * from re import * from os import * ####################################---fast-input-output----######################################### class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = read(self._fd, max(fstat(self._fd).st_size, 8192)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = read(self._fd, max(fstat(self._fd).st_size, 8192)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") stdin, stdout = IOWrapper(stdin), IOWrapper(stdout) def fast(): return stdin.readline().strip() def zzz(): return [int(i) for i in fast().split()] z, zz = fast, lambda: (map(int, z().split())) szz, graph, mod, szzz = lambda: sorted( zz()), {}, 10**9 + 7, lambda: sorted(zzz()) def lcd(xnum1, xnum2): return (xnum1 * xnum2 // gcd(xnum1, xnum2)) def output(answer, end='\n'): stdout.write(str(answer) + end) dx = [-1, 1, 0, 0, 1, -1, 1, -1] dy = [0, 0, 1, -1, 1, -1, -1, 1] #################################################---Some Rule For Me To Follow---################################# """ --instants of Reading problem continuously try to understand them. --If you Know some-one , Then you probably don't know him ! --Try & again try """ ##################################################---START-CODING---############################################### n = int(z()) arr = set(zz()) def solve(): for i in arr: for k in range(31): if i - (1 << k) in arr and i + (1 << k) in arr: return [i - (1 << k), i, i + (1 << k)] for i in arr: for k in range(31): if i + (1 << k) in arr: return [i, i + (1 << k)] for i in arr: return [i] lst = solve() # print(lst) print(len(lst)) for i in lst: output(i,' ') ```
output
1
32,224
23
64,449
Provide tags and a correct Python 3 solution for this coding contest problem. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.
instruction
0
32,225
23
64,450
Tags: brute force, math Correct Solution: ``` from sys import stdout, stdin, setrecursionlimit from io import BytesIO, IOBase from collections import * from itertools import * from random import * from bisect import * from string import * from queue import * from heapq import * from math import * from re import * from os import * ####################################---fast-input-output----######################################### class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = read(self._fd, max(fstat(self._fd).st_size, 8192)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = read(self._fd, max(fstat(self._fd).st_size, 8192)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") stdin, stdout = IOWrapper(stdin), IOWrapper(stdout) def fast(): return stdin.readline().strip() def zzz(): return [int(i) for i in fast().split()] z, zz = fast, lambda: (map(int, z().split())) szz, graph, mod, szzz = lambda: sorted( zz()), {}, 10**9 + 7, lambda: sorted(zzz()) def lcd(xnum1, xnum2): return (xnum1 * xnum2 // gcd(xnum1, xnum2)) def output(answer, end='\n'): stdout.write(str(answer) + end) dx = [-1, 1, 0, 0, 1, -1, 1, -1] dy = [0, 0, 1, -1, 1, -1, -1, 1] #################################################---Some Rule For Me To Follow---################################# """ --instants of Reading problem continuously try to understand them. --If you Know some-one , Then you probably don't know him ! --Try & again try """ ##################################################---START-CODING---############################################### n = int(z()) a = zzz() d = {} power = [2**i for i in range(31)] ans = [] for i in a: d[i] = 0 for num in d.keys(): for p in power: if num+p in d: ans = [num, num+p] if num+p+p in d: print(3) ans.append(num+p+p) print(*ans) exit() if ans: print(2) print(*ans) else: print(1) print(a[0]) ```
output
1
32,225
23
64,451
Provide tags and a correct Python 3 solution for this coding contest problem. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.
instruction
0
32,226
23
64,452
Tags: brute force, math Correct Solution: ``` # -*- coding:utf-8 -*- """ created by shuangquan.huang at 1/17/20 """ import collections import time import os import sys import bisect import heapq from typing import List def solve(N, A): wc = collections.Counter(A) vals = set(wc.keys()) minv, maxv = min(vals), max(vals) ans = 0 selected = [] for v in vals: if wc[v] > ans: ans = wc[v] selected = [v] k = 1 while v + k <= maxv: if v + k in vals: if v + k * 2 in vals: count = wc[v] + wc[v+k] + wc[v+k*2] if count > ans: ans = count selected = [v, v+k, v+k*2] else: count = wc[v] + wc[v + k] if count > ans: ans = count selected = [v, v + k] k *= 2 k = 1 while v-k >= minv: if v-k in vals: if v-k*2 in vals: count = wc[v] + wc[v-k] + wc[v-k*2] if count > ans: ans = count selected = [v, v-k, v-k*2] else: count = wc[v] + wc[v-k] if count > ans: ans = count selected = [v, v-k] k *= 2 print(ans) print(' '.join([' '.join(map(str, [v] * wc[v])) for v in selected])) N = int(input()) A = [int(x) for x in input().split()] solve(N, A) ```
output
1
32,226
23
64,453
Provide tags and a correct Python 3 solution for this coding contest problem. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.
instruction
0
32,227
23
64,454
Tags: brute force, math Correct Solution: ``` n=int(input()) ar=set(map(int,input().split())) Max = max(ar) ans=() flag=0 for i in ar: j=1 while i+j<=Max: if i+j in ar: ans=(i,i+j) flag=1 if i+2*j in ar: print("3") print(i,i+j,i+2*j) exit() j*=2 if flag==1: print("2") print(*ans) else: print("1") print(Max) ```
output
1
32,227
23
64,455
Provide tags and a correct Python 3 solution for this coding contest problem. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.
instruction
0
32,228
23
64,456
Tags: brute force, math Correct Solution: ``` N = int(input()) L = list(map(int, input().split())) L = sorted(L) import bisect as bi P = [] for i in range (0, 31): P.append(2**i) max = 1 saved = [L[0]] for i in range (0, N): for j in range (0, 31): if bi.bisect_left(L, L[i]+P[j])!=bi.bisect_right(L, L[i]+P[j]): max = 2 saved = [L[i], L[i]+P[j]] if bi.bisect_left(L, L[i]+2*P[j])!=bi.bisect_right(L, L[i]+2*P[j]): print(3) print(L[i], L[i]+P[j], L[i]+2*P[j]) exit() print(max) print(*saved) ```
output
1
32,228
23
64,457
Provide tags and a correct Python 3 solution for this coding contest problem. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property.
instruction
0
32,229
23
64,458
Tags: brute force, math Correct Solution: ``` n = int(input()) a = [] _2 = [1] FS = lambda x : x in S def F(x): l,r=0,len(a)-1 while l<r-1 : mid = (l+r)>>1 if a[mid]==x : return True elif a[mid]<x: l = mid+1 else : r = mid-1 else : return a[l]==x or a[r]==x for i in range(30): _2.append(_2[i]*2) #for i in _2: # print(i) for i in map(int,input().split()): a.append(i) #a.sort() S = set(a) #for i in a: # print(i) ans = 1 A = [0,a[0],0] for i in a: if ans == 3 : break for j in _2: if ans == 3: break; if FS(i-j) : if ans<=2 : ans = 2 A[0] = i-j A[1] = A[2] = i if FS(i+j): ans = 3 A[2] = i+j # print("ans is ",i,j) break print(ans) if(ans==3): print(*A) else : print(A[1],end=" ") if(ans==2): print(A[0]+A[2]-A[1]) else : print() ```
output
1
32,229
23
64,459
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property. Submitted Solution: ``` n=int(input()) l=list(map(int,input().split())) s=set(l) ans=[l[0]] for i in l: j=1 while(j<int(2e9)): if i+j in s and i+2*j in s: print("3") print(i,i+j,i+2*j) quit() elif i+j in s: ans=[i,i+j] j*=2 print(len(ans)) for i in ans: print(i,end=" ") ```
instruction
0
32,230
23
64,460
Yes
output
1
32,230
23
64,461
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property. Submitted Solution: ``` powersoftwo=[2**i for i in range(0,34)] N=int(input()) array=[int(x) for x in input().split()] checker=set(array) total=-1 for i in array: for j in powersoftwo: z=1 a=1 b=1 if i-j in checker: z+=1 a+=1 if j+i in checker: z+=1 b+=1 total=max(z,total) if total==z: if a==2: something=[i, i-j] if b==2: something=[i,i+j] if a==2 and b==2: something=[i,i+j,i-j] print(total) if total>1: print(*something) else: print(array[0]) ```
instruction
0
32,231
23
64,462
Yes
output
1
32,231
23
64,463
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property. Submitted Solution: ``` def read_numbers(): return (int(s) for s in input().strip().split(' ')) # keys_set = {128, 1, 2, 256, 4, 512, 1024, 2048, 8, 4096, 32768, 131072, 524288, 262144, 8192, 1048576, 16, 16384, 4194304, 32, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 64, 65536, 2097152} # keys = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824] keys = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824] def main(): _ = input() dots = set(read_numbers()) # print(keys) # print(dots) max_res = [] for dot in dots: for dist in keys: res = [dot] d1 = dot - dist d2 = dot + dist if d1 in dots: res.append(d1) if d2 in dots: res.append(d2) if len(res) > len(max_res): max_res = res if len(max_res) == 3: print(len(max_res)) print(' '.join(str(n) for n in max_res)) return print(len(max_res)) print(' '.join(str(n) for n in max_res)) if __name__ == '__main__': main() ```
instruction
0
32,232
23
64,464
Yes
output
1
32,232
23
64,465
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property. Submitted Solution: ``` import sys def solve(io): N = io.readInt() X = io.readIntArray(N) has = set(X) best = (X[0],) for v in X: for b in range(0, 31): p = 1 << b a = v + p if a in has: if len(best) < 2: best = (v, a) b = a + p if b in has and len(best) < 3: best = (v, a, b) break io.println(len(best)) io.printlnArray(best) # +---------------------+ # | TEMPLATE CODE BELOW | # | DO NOT MODIFY | # +---------------------+ # TODO: maybe reading byte-by-byte is faster than reading and parsing tokens. class IO: input = None output = None def __init__(self, inputStream, outputStream): self.input = inputStream self.output = outputStream @staticmethod def isSpaceChar(c): return c == ' ' or c == '\n' or c == '\0' or c == '\r' or c == '\t' @staticmethod def isLineBreakChar(c): return c == '\n' or c == '\0' or c == '\r' def readChar(self): return self.input.read(1) def readString(self): c = self.readChar() while IO.isSpaceChar(c): c = self.readChar() sb = [] while not IO.isSpaceChar(c): sb.append(c) c = self.readChar() return ''.join(sb) def readLine(self): c = self.readChar() while IO.isSpaceChar(c): c = self.readChar() sb = [] while not IO.isLineBreakChar(c): sb.append(c) c = self.readChar() return ''.join(sb) def readInt(self): c = self.readChar() while IO.isSpaceChar(c): c = self.readChar() sgn = 1 if c == '-': sgn = -1 c = self.readChar() res = 0 while not IO.isSpaceChar(c): res = (res * 10) + ord(c) - 48 c = self.readChar() return sgn * res def readFloat(self): return float(self.readString()) def readStringArray(self, N, offset=0): arr = [None] * offset for _ in range(0, N): arr.append(self.readString()) return arr def readIntArray(self, N, offset=0): arr = [None] * offset for _ in range(0, N): arr.append(self.readInt()) return arr def readFloatArray(self, N, offset=0): arr = [None] * offset for _ in range(0, N): arr.append(self.readFloat()) return arr def print(self, s): self.output.write(str(s)) def println(self, s): self.print(s) self.print('\n') def printlnArray(self, arr, sep = ' '): self.println(sep.join(str(x) for x in arr)) def flushOutput(self): self.output.flush() pythonIO = IO(sys.stdin, sys.stdout) solve(pythonIO) pythonIO.flushOutput() ```
instruction
0
32,233
23
64,466
Yes
output
1
32,233
23
64,467
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property. Submitted Solution: ``` n = int(input()) n1 = input().split() n2 = [] s1 = set() for x in n1: n2.append(int(x)) s1.add(int(x)) n2.sort() max = n2[len(n2)-1]-n2[0] count = 0 num = 1 while(num<max): num = num*2 count = count + 1 flag = 0 base0 = 0 base1 = 0 base2 = -1 cflag = 0 for x in n2: for z in (0, count+1): if(x+2**z in s1): if(flag==0): flag = 1 base0 = x base1 = x+2**z if(x+2**(z+1) in s1): cflag = 1 base0 = x base1 = x+2**z base2 = x+2**(z+1) break if(cflag==1): break if(cflag==1): s = "3\n" + str(base0) + " " + str(base1) + " " + str(base2) print(s) if(cflag==0 and flag==1): s = "2\n" + str(base0) + " " + str(base1) print(s) if(cflag==0 and flag==0): s = "1\n" + str(n2[0]) print(s) ```
instruction
0
32,234
23
64,468
No
output
1
32,234
23
64,469
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property. Submitted Solution: ``` import math import heapq,bisect import sys from collections import deque from fractions import Fraction # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a + b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) #-------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD #--------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m #--------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z #--------------------------------------------------product---------------------------------------- def product(l): por=1 for i in range(len(l)): por*=l[i] return por #--------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] <= key): # At least (mid + 1) elements are there # whose values are less than # or equal to key count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count #--------------------------------------------------binary---------------------------------------- def countGreater(arr, n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) # If mid element is greater than # k update leftGreater and r if (arr[m] > k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) #--------------------------------------------------binary---------------------------------------- n=int(input()) l=list(map(int,input().split())) po=[pow(2,i) for i in range(30)] d=dict() for i in range(n): if l[i] not in d: d.update({l[i]:1}) else: d[l[i]]+=1 tot=1 er=0 er1=0 for i in range(n): for j in range(30): r=0 r1=0 if l[i]+po[j] in d: r=d[l[i]+po[j]] if j<29 and l[i]+po[j+1] in d: r1=d[l[i]+po[j+1]] tot=max(tot,r+r1+1) if r+r1+1==tot: if r>0: er=po[j] if r1>0: er1=po[j+1] st=i #print(tot,er,er1) ans=[l[st]] for i in range(d[l[st]+er]): ans.append(l[st]+er) for i in range(d[l[st]+er1]): ans.append(l[st]+er1) print(*ans[:tot],sep=" ") ```
instruction
0
32,235
23
64,470
No
output
1
32,235
23
64,471
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property. Submitted Solution: ``` import math import sys amount = int(input()) array = [int(s) for s in input().split()] even = [] odd = [] for i in range(len(array)): if array[i] % 2: odd.append(array[i]) else: even.append(array[i]) counter_1 = 0 counter_2 = 0 odd = sorted(odd) even = sorted(even) ans_1 = [] ans_2 = [] #print(odd) for i in range(len(odd) - 1): if math.log(odd[i + 1] - odd[i], 2) % 1 == 0: if not odd[i] in ans_1: ans_1.append(odd[i]) if not odd[i + 1] in ans_1: ans_1.append(odd[i + 1]) for i in range(len(even) - 1): if math.log(even[i + 1] - even[i], 2) % 1 == 0: if not even[i] in ans_2: ans_2.append(even[i]) if not even[i + 1] in ans_2: ans_2.append(even[i + 1]) if len(ans_2) == len(ans_1) and len(ans_2) == 0: print(1) print(array[0]) sys.exit(0) if len(ans_2) >= len(ans_1): print(len(ans_2)) print(' '.join([str(s) for s in ans_2])) else: print(len(ans_1)) print(' '.join([str(s) for s in ans_1])) ```
instruction
0
32,236
23
64,472
No
output
1
32,236
23
64,473
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property. Submitted Solution: ``` def main(): count = input() seq = list(map(int, input().split())) find_sub_set(seq) def find_sub_set(seqence): sub_sets = [k for k in range(len(seqence))] for i in range(len(seqence)): sub_sets[i] = list() sub_sets[i].append(seqence[i]) for j in range(i + 1, len(seqence)): if is_pow(abs(sub_sets[i][0] - seqence[j])): sub_sets[i].append(seqence[j]) max = 0 for i in range(len(sub_sets)): if len(sub_sets[i]) > len(sub_sets[max]): max = i for x in sub_sets[max]: print(x, end=' ') def is_pow(n): if n > 1: return (n & (n - 1)) == 0 else: return False if __name__ == '__main__': main() ```
instruction
0
32,237
23
64,474
No
output
1
32,237
23
64,475
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n distinct points on a coordinate line, the coordinate of i-th point equals to x_i. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points x_{i_1}, x_{i_2}, ..., x_{i_m} such that for each pair x_{i_j}, x_{i_k} it is true that |x_{i_j} - x_{i_k}| = 2^d where d is some non-negative integer number (not necessarily the same for each pair of points). Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of points. The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (-10^9 ≀ x_i ≀ 10^9) β€” the coordinates of points. Output In the first line print m β€” the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print m integers β€” the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. Examples Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 Note In the first example the answer is [7, 3, 5]. Note, that |7-3|=4=2^2, |7-5|=2=2^1 and |3-5|=2=2^1. You can't find a subset having more points satisfying the required property. Submitted Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') def pr_arr(arr): pr(' '.join(map(str,arr))+'\n') range = xrange # not for python 3.0+ # main code n=int(raw_input()) l=in_arr() d=Counter(l) pw=[] p=1 while p<=1000000000: pw.append(p) p*=2 ans=[] for i in range(n): c=1 temp=[l[i]] ck=0 temp1=[] for j in pw: c2=0 temp2=[] if d[l[i]-j]: c2+=1 temp2.append(l[i]-j) if d[l[i]+j]: c2+=1 temp2.append(l[i]+j) if c2>ck: ck=c2 temp1=list(temp2) temp+=temp1 c+=ck if c==3: pr_num(3) pr_arr(temp) exit() ans.append([c]+temp) ans.sort(reverse=True) pr_num(ans[0][0]) pr_arr(ans[0][1:]) ```
instruction
0
32,238
23
64,476
No
output
1
32,238
23
64,477
Provide a correct Python 3 solution for this coding contest problem. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24
instruction
0
32,319
23
64,638
"Correct Solution: ``` N,i=map(int,input().split()) print((N-1)*(i-1)) ```
output
1
32,319
23
64,639
Provide a correct Python 3 solution for this coding contest problem. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24
instruction
0
32,320
23
64,640
"Correct Solution: ``` A, B = map(int, input().rstrip().split()) print(A*B-A-B+1) ```
output
1
32,320
23
64,641
Provide a correct Python 3 solution for this coding contest problem. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24
instruction
0
32,321
23
64,642
"Correct Solution: ``` a, b = map(int, input().split()) print(a*b+1-a-b) ```
output
1
32,321
23
64,643
Provide a correct Python 3 solution for this coding contest problem. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24
instruction
0
32,322
23
64,644
"Correct Solution: ``` a,b = (int(_) for _ in input().split()) print((a-1)*(b-1)) ```
output
1
32,322
23
64,645
Provide a correct Python 3 solution for this coding contest problem. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24
instruction
0
32,323
23
64,646
"Correct Solution: ``` a,b = map(int,(input().split())) print((a * b) - (a+b-1)) ```
output
1
32,323
23
64,647
Provide a correct Python 3 solution for this coding contest problem. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24
instruction
0
32,324
23
64,648
"Correct Solution: ``` A,B = map(int,input().split()) print(int((A*B)-A-B+1)) ```
output
1
32,324
23
64,649
Provide a correct Python 3 solution for this coding contest problem. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24
instruction
0
32,325
23
64,650
"Correct Solution: ``` x,y = [int(x) for x in input().split()] print((x-1)*(y-1)) ```
output
1
32,325
23
64,651
Provide a correct Python 3 solution for this coding contest problem. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24
instruction
0
32,326
23
64,652
"Correct Solution: ``` a,b = map(int,input().split()) x = a*b x -= a+b-1 print(x) ```
output
1
32,326
23
64,653
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24 Submitted Solution: ``` a,b=map(int,input().split()) a<b print((a-1)*(b-1)) ```
instruction
0
32,327
23
64,654
Yes
output
1
32,327
23
64,655
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24 Submitted Solution: ``` X,Y=map(int,input().split()) ans=X*Y-(X+Y-1) print(ans) ```
instruction
0
32,328
23
64,656
Yes
output
1
32,328
23
64,657
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24 Submitted Solution: ``` A,B = map(int, input().split()) print(int(A * B - A - B +1)) ```
instruction
0
32,329
23
64,658
Yes
output
1
32,329
23
64,659
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. Constraints * A is an integer between 2 and 100 (inclusive). * B is an integer between 2 and 100 (inclusive). Input Input is given from Standard Input in the following format: A B Output Print the area of this yard excluding the roads (in square yards). Examples Input 2 2 Output 1 Input 5 7 Output 24 Submitted Solution: ``` x,y = map(int,input().split()) print(x*y-(x+y-1)) ```
instruction
0
32,330
23
64,660
Yes
output
1
32,330
23
64,661