Problem:


問題 C : Apples 

問題文

あるところに銃の腕に自信をもつ猟師がいました．
猟師はある日，「ウィリアムテルというスイス人が，息子の頭にりんごを乗せて遠くから矢で撃ち落とすパフォーマンスで有名になった」というお話を聞きました．
それを聞いて"自分のほうがもっと凄い!!"と思った猟師は動いている人の上にりんごを乗せて撃ちぬくパフォーマンスを考えつきました．

猟師は広場に N 人の人を集め，それぞれの人の上にりんごを乗せました．
i 番目の人は時刻 t=0 のとき，座標 (x_i, &thinsp;y_i) にいます．
そこから単位時間あたり速度ベクトル (u_i,&thinsp; v_i) にしたがって歩きます．
すなわち，時刻 t &thinsp;≥&thinsp; 0 のとき，i 番目の人は座標 (x_i + t \times u_i &thinsp;, &ensp; y_i + t \times v_i) にいます．
ここで，人々は十分小さいので，同じ座標に複数の人がいたり，同じ座標ですれ違ったりできると仮定します．

猟師は人々を驚嘆させるために，一発の弾丸でできるだけ多くのりんごを撃ち落とすことにしました．
猟師は t ≥ 0 であるような任意の時刻に，任意の座標から任意の方向に向けて弾丸を放つことができます．
放たれた弾丸は無限の速さで直線軌道で移動し，りんごに当たった場合貫通して移動します．
弾丸を一発だけ打つとき，最大で何個のりんごを撃ち落とせるか計算してください．

入力形式

入力は以下の形式で与えられる

N
x_0 y_0 u_0 v_0
...
x_{N-1} y_{N-1} u_{N-1} v_{N-1}

出力形式

撃ち落とせるりんごの最大個数を1行に出力せよ．

制約

1 ≤ N ≤ 200

0 ≤ &thinsp; |x_i|, &thinsp; |y_i|  &thinsp; ≤ 10

0 ≤ &thinsp; |u_i|, &thinsp; |v_i| &thinsp; ≤ 3

入力値はすべて整数である。

入出力例

入力例 1

5
0 0 0 0
1 0 -1 1
-1 0 1 -1
1 1 -1 1
-1 -1 1 -1

出力例 1

5

時刻１に５人がｙ軸上に並ぶので最大５つのりんごを撃ち落とせる．

入力例 2

5
0 0 0 0
1 0 1 0
-1 0 -1 0
1 1 1 1
-1 -1 -1 -1

出力例 2

3  

入力例 3

15
-10 9 2 1
2 10 0 -1
-10 -4 0 -3
-2 8 0 -1
0 -10 -1 -2
-8 5 0 -1
-7 -8 -3 1
10 -6 -2 -3
9 -6 1 0
10 -5 3 1
10 1 0 -3
-4 7 0 -1
10 -9 2 2
2 -5 -1 1
9 -10 3 1

出力例 3

5



Sample input:
5
0 0 0 0
1 0 -1 1
-1 0 1 -1
1 1 -1 1
-1 -1 1 -1


Sample output:
5

Submission status: Wrong Answer

Solution code:
# return [2?¬?????¨????????§£],0==a==b==c
def quadratic_equation(a,b,c):
    if a:
        d = b * b - 4 * a * c
        if d < 0:
            ans = []
        elif d == 0:
            ans = [-b / (2 * a)]
        else:
            d **= 0.5
            d /= 2 * a
            b /= 2 * a
            ans = [-b + d, -b - d]
    elif b:
        ans = [-c / b]
    else:
        ans = []
    return ans, 0 == a == b == c

def eq(a, b):
    return round(abs(a - b), 10) == 0

def cross(v1,v2):
    return v1.real * v2.imag - v1.imag * v2.real

from itertools import combinations
from itertools import groupby
def solve(xyuv):
    if len(xyuv) <= 2 or is_all_same(xyuv):
        return len(xyuv)
    max_ij = 0
    for i, j in combinations(range(len(xyuv)), 2):
        if xyuv[i] == xyuv[j]:
            continue
            
        always_lined_point = 0
        t = []
        for k in range(len(xyuv)):
            if i == k or j == k:
                continue
            xyi,uvi = xyuv[i]
            xyj,uvj = xyuv[j]
            xyk,uvk = xyuv[k]
            xyi -= xyk
            xyj -= xyk
            uvi -= uvk
            uvj -= uvk
            
            ans,flg = quadratic_equation(cross(uvi, uvj), cross(xyi, uvj) + cross(uvi, xyj), cross(xyi, xyj))
            #ans,flg = quadratic_equation(c*h-d*g, a*h-b*g + c*f-d*e, a*f-b*e)
            t.extend(ans)
            if flg:
                always_lined_point += 1

        t = [round(ti, 10) for ti in t] #?????????
        t = [ti for ti in t if 0 <= ti] #t<0?????????

        
        xy,uv = xyuv[i]
        xyj,uvj = xyuv[j]
        xy -= xyj
        uv -= uvj

        t.sort()
        max_group_length = 0
        for k, g in groupby(t):
            if not eq(xy + uv * k, 0):
                max_group_length = max(max_group_length, sum(1 for _ in g))
            
        max_ij = max(max_ij, max_group_length + always_lined_point + 2)
    return max_ij

def is_all_same(xyuv):
    for xyuvi in xyuv:
        if xyuvi != xyuv[0]:
            return False
    return True

import sys
f = sys.stdin

def take2(i):
    while True:
        yield next(i),next(i)

_ = int(f.readline())
xyuv = [[x+y*1j for x,y in take2(map(int, line.split()))] for line in f]

print(solve(xyuv))

Submission status: Wrong Answer

Solution code:
# return [2?¬?????¨????????§£],0==a==b==c
def quadratic_equation(a,b,c):
    if a:
        d = b * b - 4 * a * c
        if d < 0:
            ans = []
        elif d == 0:
            ans = [-b / (2 * a)]
        else:
            d **= 0.5
            d /= 2 * a
            b /= 2 * a
            ans = [-b + d, -b - d]
    elif b:
        ans = [-c / b]
    else:
        ans = []
    return ans, 0 == a == b == c

def eq(a, b):
    return abs(a - b) <= 10 ** -9

def cross(v1,v2):
    return v1.real * v2.imag - v1.imag * v2.real

from itertools import combinations
from itertools import groupby
def solve(xyuv):
    if len(xyuv) <= 2 or is_all_same(xyuv):
        return len(xyuv)
    max_ij = 0
    for i, j in combinations(range(len(xyuv)), 2):
        if xyuv[i] == xyuv[j]:
            continue
            
        always_lined_point = 0
        t = []
        for k in range(len(xyuv)):
            if i == k or j == k:
                continue
            xyi,uvi = xyuv[i]
            xyj,uvj = xyuv[j]
            xyk,uvk = xyuv[k]
            xyi -= xyk
            xyj -= xyk
            uvi -= uvk
            uvj -= uvk
            
            ans,flg = quadratic_equation(cross(uvi, uvj), cross(xyi, uvj) + cross(uvi, xyj), cross(xyi, xyj))
            #ans,flg = quadratic_equation(c*h-d*g, a*h-b*g + c*f-d*e, a*f-b*e)
            t.extend(ans)
            if flg:
                always_lined_point += 1

        t = [round(ti, 10) for ti in t] #?????????
        t = [ti for ti in t if 0 <= ti] #t<0?????????

        
        xy,uv = xyuv[i]
        xyj,uvj = xyuv[j]
        xy -= xyj
        uv -= uvj

        t.sort()
        max_group_length = 0
        for k, g in groupby(t):
            if not eq(xy + uv * k, 0):
                max_group_length = max(max_group_length, sum(1 for _ in g))
            
        max_ij = max(max_ij, max_group_length + always_lined_point + 2)
    return max_ij

def is_all_same(xyuv):
    for xyuvi in xyuv:
        if xyuvi != xyuv[0]:
            return False
    return True

import sys
f = sys.stdin

def take2(i):
    while True:
        yield next(i),next(i)

_ = int(f.readline())
xyuv = [[x+y*1j for x,y in take2(map(int, line.split()))] for line in f]

print(solve(xyuv))

Submission status: Wrong Answer

Solution code:
# return [2?¬?????¨????????§£],0==a==b==c
def quadratic_equation(a,b,c):
    if a:
        d = b * b - 4 * a * c
        if d < 0:
            ans = []
        elif d == 0:
            ans = [-b / (2 * a)]
        else:
            d **= 0.5
            d /= 2 * a
            b /= 2 * a
            ans = [-b + d, -b - d]
    elif b:
        ans = [-c / b]
    else:
        ans = []
    return ans, 0 == a == b == c

def eq(a, b):
    return abs(a - b) <= 10 ** -9

def cross(v1,v2):
    return v1.real * v2.imag - v1.imag * v2.real

from itertools import combinations
from itertools import groupby
def solve(xyuv):
    if len(xyuv) <= 2 or is_all_same(xyuv):
        return len(xyuv)
    max_ij = 0
    for i, j in combinations(range(len(xyuv)), 2):
        if xyuv[i] == xyuv[j]:
            continue
            
        always_lined_point = 0
        t = []
        for k in range(len(xyuv)):
            if i == k or j == k:
                continue
            xyi,uvi = xyuv[i]
            xyj,uvj = xyuv[j]
            xyk,uvk = xyuv[k]
            xyi -= xyk
            xyj -= xyk
            uvi -= uvk
            uvj -= uvk
            
            ans,flg = quadratic_equation(cross(uvi, uvj), cross(xyi, uvj) + cross(uvi, xyj), cross(xyi, xyj))
            #ans,flg = quadratic_equation(c*h-d*g, a*h-b*g + c*f-d*e, a*f-b*e)
            t.extend(ans)
            if flg:
                always_lined_point += 1

        t = [round(ti, 10) for ti in t] #?????????
        t = [ti for ti in t if 0 <= ti] #t<0?????????

        
        xy,uv = xyuv[i]
        xyj,uvj = xyuv[j]
        xy -= xyj
        uv -= uvj

        t.sort()
        max_group_length = 0
        for k, g in groupby(t):
            group_length = 1 if eq(xy + uv * k, 0) else sum(1 for _ in g)
            max_group_length = max(max_group_length, group_length)
            
        max_ij = max(max_ij, max_group_length + always_lined_point + 2)
    return max_ij

def is_all_same(xyuv):
    for xyuvi in xyuv:
        if xyuvi != xyuv[0]:
            return False
    return True

import sys
f = sys.stdin

def take2(i):
    while True:
        yield next(i),next(i)

_ = int(f.readline())
xyuv = [[x+y*1j for x,y in take2(map(int, line.split()))] for line in f]

print(solve(xyuv))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from itertools import groupby
def solve(xyuv):
    if len(xyuv) <= 2 or is_all_same(xyuv) or is_all_same_attime(xyuv):
        return len(xyuv)
    print('test')
    max_ij = 0
    for i, j in combinations(range(len(xyuv)), 2):
        if xyuv[i] == xyuv[j]:
            continue
        xyi,uvi = xyuv[i]
        xyj,uvj = xyuv[j]
            
        always_lined_point = 0
        t = []
        for k in range(len(xyuv)):
            if i == k or j == k:
                continue
            xyk,uvk = xyuv[k]
            ans, flg = get_t(xyi - xyk, uvi - uvk, xyj - xyk, uvj - uvk)
            t.extend(ans)
            if flg:
                always_lined_point += 1

        t = [round(ti, 10) for ti in t] #?????????
        t = [ti for ti in t if 0 <= ti] #t<0?????????
        t.sort()
        
        xyi -= xyj
        uvi -= uvj

        max_group_length = 0
        for k, g in groupby(t):
            group_length = 1 if eq(xyi + uvi * k, 0) else sum(1 for _ in g)
            max_group_length = max(max_group_length, group_length)
            
        max_ij = max(max_ij, max_group_length + always_lined_point + 2)
    return max_ij

def get_t(xy1,uv1,xy2,uv2):
    print(xy1,uv1,xy2,uv2)
    a = cross(uv1, uv2)
    b = cross(xy1, uv2) + cross(uv1, xy2)
    c = cross(xy1, xy2)
    print(a,b,c)
    ans, flg = quadratic_equation(a, b, c)
    return ans, flg

def is_all_same_attime(xyuv):
    xy0, uv0 = xyuv[0]
    for i in range(len(xyuv)):
        if xyuv[0] == xyuv[i]:
            continue
        xyi,uvi = xyuv[i]

        t = get_cross_time(xy0,xyi,xy0 + uv0,xyi + uvi)

        if t is None or t < 0:
            return False

        p0 = xy0 + uv0 * t
        for j in range(i + 1,len(xyuv)):
            xyj, uvj = xyuv[j]
            pj = xyj + uvj * t
            if eq(pj, p0):
                continue
            return False
        break
    return True

def get_cross_time(p1,p2,p3,p4):
    s1 = cross(p4-p2,p1-p2)
    s2 = cross(p4-p2,p2-p3)
    if s1 + s2 == 0:
        return None
    return s1 / (s1 + s2)

def take2(i):
    while True:
        yield next(i),next(i)
def main(f):
    _ = int(f.readline())
    xyuv = [[x+y*1j for x,y in take2(map(int, line.split()))] for line in f]

    print(solve(xyuv))

def is_all_same(xyuv):
    for xyuvi in xyuv:
        if xyuvi != xyuv[0]:
            return False
    return True

def cross(v1,v2):
    return v1.real * v2.imag - v1.imag * v2.real
def eq(a, b):
    return abs(a - b) <= 10 ** -9
# return [2?¬?????¨????????§£],0==a==b==c
def quadratic_equation(a,b,c):
    if a:
        d = b * b - 4 * a * c
        if d < 0:
            ans = []
        elif d == 0:
            ans = [-b / (2 * a)]
        else:
            d **= 0.5
            d /= 2 * a
            b /= 2 * a
            ans = [-b + d, -b - d]
    elif b:
        ans = [-c / b]
    else:
        ans = []
    return ans, 0 == a == b == c

import sys
f = sys.stdin

main(f)

Submission status: Wrong Answer

Solution code:
def take2(i):
    while True:
        yield next(i),next(i)
def main(f):
    _ = int(f.readline())
    xyuv = [[x+y*1j for x,y in take2(map(int, line.split()))] for line in f]

    print(solve(xyuv))
def is_all_same_attime(xyuv):
    xy0, uv0 = xyuv[0]
    for i in range(len(xyuv)):
        if xyuv[0] == xyuv[i]:
            continue
        xyi,uvi = xyuv[i]

        t = get_cross_time(xy0 - xyi, uv0 - uvi)

        if t is None or t < 0:
            return False

        p0 = xy0 + uv0 * t
        for j in range(i + 1,len(xyuv)):
            xyj, uvj = xyuv[j]
            pj = xyj + uvj * t
            if is_zero(pj - p0):
                continue
            return False
        break
    return True
def get_cross_time(xy,uv):
     denominator = uv.real - uv.imag
     return (xy.imag - xy.real) / denominator if denominator else None

def is_all_same(xyuv):
    for xyuvi in xyuv:
        if xyuvi != xyuv[0]:
            return False
    return True

def is_zero(a):
    return abs(a) < 0.00001

def get_t(xy1,uv1,xy2,uv2):
    a = uv1.real * uv2.imag - uv1.imag * uv2.real
    b = xy1.real * uv2.imag - xy1.imag * uv2.real + uv1.real * xy2.imag - uv1.imag * xy2.real
    c = xy1.real * xy2.imag - xy1.imag * xy2.real
    if a:
        d = b * b - 4 * a * c
        if d < 0:
            return []
        elif d == 0:
            return [-b / (2 * a)]
        else:
            d = d ** 0.5 / (2 * a)
            b /= 2 * a
            return [-b + d, -b - d]
    if b:
        return [-c / b]
    if not c:
        global always_lined_point
        always_lined_point += 1
    return []

from itertools import combinations
from itertools import groupby
from collections import Counter
#@profile
def solve(xyuv):
    global always_lined_point
    if len(xyuv) <= 2 or is_all_same(xyuv) or is_all_same_attime(xyuv):
        return len(xyuv)
    max_ij = 0
    for i, j in combinations(range(len(xyuv)), 2):
        if xyuv[i] == xyuv[j]:
            continue
        xyi,uvi = xyuv[i]
        xyj,uvj = xyuv[j]
            
        always_lined_point = 0
        t = []
        for indeces in (range(i),range(i + 1,j),range(j + 1,len(xyuv))):
            for k in indeces:
                xyk,uvk = xyuv[k]
                t.extend(get_t(xyi - xyk, uvi - uvk, xyj - xyk, uvj - uvk))

        t = [ti for ti in t if 0 <= ti] #t<0?????????
        t = [round(ti, 10) for ti in t] #?????????
        t = Counter(t)

        group_lengths = [0]
        for k, c in t.most_common(2):
            group_length = 1 if is_zero(xyi + uvi * k) else c
            group_lengths.append(group_length)
             
        max_ij = max(max_ij, max(group_lengths) + always_lined_point + 2)
    return max_ij

import sys
f = sys.stdin

main(f)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
km = []
for i in range(N):
    km.append(input().split(' '))

nmax = 0
for i in range(20):
    ks = []
    for j in range(N):
        x, y, u, v = list(map(int, list(km[j])))
        ks.append((x + u * i, y + v * i))
    for k in list(itertools.combinations(ks, 2)):
        (x1, y1), (x2, y2) = k
        xd = x1 - x2
        yd = y1 - y2
        t = 0

        for j in ks:
            (x3, y3) = j
            #for di in range(-20, 20):
            if ((xd == 0 and yd == 0 and x3 == x1 and y1 == y3) or 
                    ((xd != 0 or yd != 0) and (x1 - x3) * yd == (y1 - y3) * xd)):
                t += 1
#        print(nmax, ks, k)
        nmax = max(nmax, t)

print(nmax)


# 5
# 0 0 0 0
# 1 0 -1 1
# -1 0 1 -1
# 1 1 -1 1
# -1 -1 1 -1

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
km = []
for i in range(N):
    km.append(input().split(' '))


nmax = 0
try:
    for i in range(100):
        ks = []
        for j in range(N):
            x, y, u, v = list(map(int, list(km[j])))
            ks.append((x + u * i, y + v * i))
        for k in list(itertools.combinations(ks, 2)):
            (x1, y1), (x2, y2) = k
            xd = x1 - x2
            yd = y1 - y2
            t = 0
            for j in ks:
                (x3, y3) = j
                #for di in range(-20, 20):
                if ((xd == 0 and yd == 0 and x3 == x1 and y1 == y3) or 
                        ((xd != 0 or yd != 0) and (x1 - x3) * yd == (y1 - y3) * xd)):
                    t += 1
            nmax = max(nmax, t)
            if nmax == N:
                raise Exception

except Exception:
    pass

print(nmax)

Submission status: Accepted

Solution code:
def take2(i):
    while True:
        yield next(i),next(i)
def main(f):
    _ = int(f.readline())
    xyuv = [[x+y*1j for x,y in take2(map(int, line.split()))] for line in f]

    print(solve(xyuv))
def is_all_same_attime(xyuv):
    xy0, uv0 = xyuv[0]
    for i in range(len(xyuv)):
        if xyuv[0] == xyuv[i]:
            continue
        xyi,uvi = xyuv[i]

        t = get_cross_time(xy0 - xyi, uv0 - uvi)

        if t is None or t < 0:
            return False

        p0 = xy0 + uv0 * t
        for j in range(i + 1,len(xyuv)):
            xyj, uvj = xyuv[j]
            pj = xyj + uvj * t
            if is_zero(pj - p0):
                continue
            return False
        break
    return True
def get_cross_time(xy,uv):
     denominator = uv.real - uv.imag
     return (xy.imag - xy.real) / denominator if denominator else None

def is_all_same(xyuv):
    for xyuvi in xyuv:
        if xyuvi != xyuv[0]:
            return False
    return True

def is_zero(a):
    return abs(a) < 0.00001

def get_t(xy1,uv1,xy2,uv2):
    a = uv1.real * uv2.imag - uv1.imag * uv2.real
    b = xy1.real * uv2.imag - xy1.imag * uv2.real + uv1.real * xy2.imag - uv1.imag * xy2.real
    c = xy1.real * xy2.imag - xy1.imag * xy2.real
    if a:
        d = b * b - 4 * a * c
        if d < 0:
            return []
        elif d == 0:
            return [-b / (2 * a)]
        else:
            d = d ** 0.5 / (2 * a)
            b /= 2 * a
            return [-b + d, -b - d]
    if b:
        return [-c / b]
    if not c:
        global always_lined_point
        always_lined_point += 1
    return []

from itertools import combinations
from itertools import groupby
from collections import Counter
#@profile
def solve(xyuv):
    global always_lined_point
    if len(xyuv) <= 2 or is_all_same(xyuv) or is_all_same_attime(xyuv):
        return len(xyuv)
    max_ij = 0
    for i, j in combinations(range(len(xyuv)), 2):
        if xyuv[i] == xyuv[j]:
            continue
        xyi,uvi = xyuv[i]
        xyj,uvj = xyuv[j]
            
        always_lined_point = 0
        t = []
        for indeces in (range(i),range(i + 1,j),range(j + 1,len(xyuv))):
            for k in indeces:
                xyk,uvk = xyuv[k]
                t.extend(get_t(xyi - xyk, uvi - uvk, xyj - xyk, uvj - uvk))

        t = [ti for ti in t if 0 <= ti] #t<0?????????
        t = [round(ti, 10) for ti in t] #?????????
        t = Counter(t)

        xyi -= xyj
        uvi -= uvj

        group_lengths = [0]
        for k, c in t.most_common(2):
            group_length = 1 if is_zero(xyi + uvi * k) else c
            group_lengths.append(group_length)
             
        max_ij = max(max_ij, max(group_lengths) + always_lined_point + 2)
    return max_ij

import sys
f = sys.stdin

main(f)

Submission status: Runtime Error

Solution code:
from itertools import combinations
from itertools import groupby
def solve(xyuv):
    if len(xyuv) <= 2 or is_all_same(xyuv) or is_all_same_attime(xyuv):
        return len(xyuv)
    max_ij = 0
    for i, j in combinations(range(len(xyuv)), 2):
        if xyuv[i] == xyuv[j]:
            continue
        xyi,uvi = xyuv[i]
        xyj,uvj = xyuv[j]
            
        always_lined_point = 0
        t = []
        for k in range(len(xyuv)):
            if i == k or j == k:
                continue
            xyk,uvk = xyuv[k]
            ans, flg = get_t(xyi - xyk, uvi - uvk, xyj - xyk, uvj - uvk)
            t.extend(ans)
            if flg:
                always_lined_point += 1

        t = [round(ti, 10) for ti in t] #?????????
        t = [ti for ti in t if 0 <= ti] #t<0?????????
        t.sort()
        
        xyi -= xyj
        uvi -= uvj

        max_group_length = 0
        for k, g in groupby(t):
            group_length = 1 if eq(xyi + uvi * k, 0) else sum(1 for _ in g)
            max_group_length = max(max_group_length, group_length)
            
        max_ij = max(max_ij, max_group_length + always_lined_point + 2)
    return max_ij

def get_t(xy1,uv1,xy2,uv2):
    a = cross(uv1, uv2)
    b = cross(xy1, uv2) + cross(uv1, xy2)
    c = cross(xy1, xy2)
    ans, flg = quadratic_equation(a, b, c)
    return ans, flg

def is_all_same_attime(xyuv):
    xy0, uv0 = xyuv[0]
    for i in range(len(xyuv)):
        if xyuv[0] == xyuv[i]:
            continue
        xyi,uvi = xyuv[i]

        t = get_cross_time(xy0,xyi,xy0 + uv0,xyi + uvi)

        if t is None or t < 0:
            return False

        p0 = xy0 + uv0 * t
        for j in range(i + 1,len(xyuv)):
            xyj, uvj = xyuv[j]
            pj = xyj + uvj * t
            if eq(pj, p0):
                continue
            return False
        break
    return True

def get_cross_time(p1,p2,p3,p4):
    s1 = cross(p4-p2,p1-p2)
    s2 = cross(p4-p2,p2-p3)
    if s1 + s2 == 0:
        return None
    return s1 / (s1 + s2)
def take2(i):
    while True:
        yield next(i),next(i)
def main(f):
    _ = int(f.readline())
    xyuv = [[x+y*1j for x,y in take2(map(int, line.split()))] for line in f]

    print(solve(xyuv))
def is_all_same(xyuv):
    for xyuvi in xyuv:
        if xyuvi != xyuv[0]:
            return False
    return True
def cross(v1,v2):
    return v1.real * v2.imag - v1.imag * v2.real
def eq(a, b):
    return abs(a - b) <= 10 ** -9
# return [2?¬?????¨????????§£],0==a==b==c
def quadratic_equation(a,b,c):
    if a:
        d = b * b - 4 * a * c
        if d < 0:
            ans = []
        elif d == 0:
            ans = [-b / (2 * a)]
        else:
            d **= 0.5
            d /= 2 * a
            b /= 2 * a
            ans = [-b + d, -b - d]
    elif b:
        ans = [-c / b]
    else:
        ans = []
    return ans, 0 == a == b == c


import sys
f = sys.stdin

main(f)

Submission status: Runtime Error

Solution code:
def take2(i):
    while True:
        yield next(i),next(i)
def main(f):
    _ = int(f.readline())
    xyuv = [[x+y*1j for x,y in take2(map(int, line.split()))] for line in f]

    print(solve(xyuv))
def is_all_same_attime(xyuv):
    xy0, uv0 = xyuv[0]
    for i in range(len(xyuv)):
        if xyuv[0] == xyuv[i]:
            continue
        xyi,uvi = xyuv[i]

        t = get_cross_time(xy0 - xyi, uv0 - uvi)

        if t is None or t < 0:
            return False

        p0 = xy0 + uv0 * t
        for j in range(i + 1,len(xyuv)):
            xyj, uvj = xyuv[j]
            pj = xyj + uvj * t
            if is_zero(pj - p0):
                continue
            return False
        break
    return True
def get_cross_time(xy,uv):
     denominator = uv.real - uv.imag
     return (xy.imag - xy.real) / denominator if denominator else None

def is_all_same(xyuv):
    for xyuvi in xyuv:
        if xyuvi != xyuv[0]:
            return False
    return True

def is_zero(a):
    return abs(a) < 0.00001

def get_t(xy1,uv1,xy2,uv2):
    a = uv1.real * uv2.imag - uv1.imag * uv2.real
    b = xy1.real * uv2.imag - xy1.imag * uv2.real + uv1.real * xy2.imag - uv1.imag * xy2.real
    c = xy1.real * xy2.imag - xy1.imag * xy2.real
    if a:
        d = b * b - 4 * a * c
        if d < 0:
            return []
        elif d == 0:
            return [-b / (2 * a)]
        else:
            d = d ** 0.5 / (2 * a)
            b /= 2 * a
            return [-b + d, -b - d]
    if b:
        return [-c / b]
    if not c:
        global always_lined_point
        always_lined_point += 1
    return []

from itertools import combinations
from itertools import groupby
from collections import Counter
def solve(xyuv):
    global always_lined_point
    if len(xyuv) <= 2 or is_all_same(xyuv) or is_all_same_attime(xyuv):
        return len(xyuv)
    max_ij = 0
    for i, j in combinations(range(len(xyuv)), 2):
        if xyuv[i] == xyuv[j]:
            continue
        xyi,uvi = xyuv[i]
        xyj,uvj = xyuv[j]
            
        always_lined_point = 0
        t = []
        for indeces in (range(i),range(i + 1,j),range(j + 1,len(xyuv))):
            for k in indeces:
                xyk,uvk = xyuv[k]
                t.extend(get_t(xyi - xyk, uvi - uvk, xyj - xyk, uvj - uvk))

        t = [ti for ti in t if 0 <= ti] #t<0?????????
        t = [round(ti, 10) for ti in t] #?????????
        t = Counter(t)

        group_lengths = []
        for k, c in t.most_common(2):
            group_length = 1 if is_zero(xyi + uvi * k) else c
            group_lengths.append(group_length)
             
        max_ij = max(max_ij, max(group_lengths) + always_lined_point + 2)
    return max_ij

import sys
f = sys.stdin

main(f)

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())
km = []
for i in range(N):
    km.append(input().split(' '))


nmax = 0
try:
    for i in range(1000):
        ks = []
        for j in range(N):
            x, y, u, v = list(map(int, list(km[j])))
            ks.append((x + u * i, y + v * i))
        for k in list(itertools.combinations(ks, 2)):
            (x1, y1), (x2, y2) = k
            xd = x1 - x2
            yd = y1 - y2
            t = 0
            for j in ks:
                (x3, y3) = j
                #for di in range(-20, 20):
                if ((xd == 0 and yd == 0 and x3 == x1 and y1 == y3) or 
                        ((xd != 0 or yd != 0) and (x1 - x3) * yd == (y1 - y3) * xd)):
                    t += 1
            nmax = max(nmax, t)
            if nmax == N:
                raise Exception

except Exception:
    pass

print(nmax)