Problem:
Projection For given three points p1, p2, p , find the projection point x of p onto p1p2 .   Input  x p1  y p1  x p2  y p2  q  x p 0  y p 0  x p 1  y p 1 ... x p q−1  y p q−1  In the first line, integer coordinates of p1 and p2 are given. Then, q queries are given for integer coordinates of p . Output For each query, print the coordinate of the projection point x . The output values should be in a decimal fraction with an error less than 0.00000001. Constraints   1 ≤ q ≤ 1000    -10000 ≤ x i , y i ≤ 10000    p1 and p2 are not identical.  Sample Input 1 0 0 2 0
3
-1 1
0 1
1 1 Sample Output 1 -1.0000000000 0.0000000000
0.0000000000 0.0000000000
1.0000000000 0.0000000000 Sample Input 2 0 0 3 4
1
2 5 Sample Output 2 3.1200000000 4.1600000000

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())




def sgn(a):
    if a < -eps: return -1
    if a >  eps: return  1
    return 0

class Point:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        pass

    def tolist(self):
        return [self.x,self.y]

    def __add__(self,p):
        return Point(self.x+p.x, self.y+p.y)
    def __iadd__(self,p):
        return self + p

    def __sub__(self,p):
        return Point(self.x - p.x, self.y - p.y)
    def __isub__(self,p):
        return self - p

    def __truediv__(self,n):
        return Point(self.x/n, self.y/n)
    def __itruediv__(self,n):
        return self / n

    def __mul__(self,n):
        return Point(self.x*n, self.y*n)
    def __imul__(self,n):
        return self * n

    def __lt__(self,other):
        tmp = sgn(self.x - other.x)
        if tmp != 0:
            return tmp < 0
        else:
            return sgn(self.y - other.y) < 0

    def abs(self):
        return math.sqrt(self.x**2+self.y**2)

    def dot(self,p):
        return self.x * p.x + self.y*p.y

    def det(self,p):
        return self.x * p.y - self.y*p.x

    def arg(self,p):
        return math.atan2(y,x)


def iSP(a,b,c):
    tmp = sgn((b-a).det(c-a))
    if tmp > 0:   return 1   
    elif tmp < 0: return -1  
    else: 
        if sgn((b-a).dot(c-a)) < 0: return -2 
        if sgn((a-b).dot(c-b)) < 0: return  2 
        return 0 


def isToleranceLine(a,b,c,d):
    if sgn((b-a).det(c-d)) != 0: return 1 
    else:
        if sgn((b-a).det(c-a)) != 0: return 0 
        else: return -1 


def isToleranceSegline(a,b,c,d):
    return sgn(iSP(a,b,c)*iSP(a,b,d))<=0 and sgn(iSP(c,d,a)*iSP(c,d,b)) <= 0


def Intersection(a,b,c,d):
    tmp1 = (b-a)*((c-a).det(d-c))
    tmp2 = (b-a).det(d-c)
    return a+(tmp1/tmp2)


def DistanceLineToPoint(a,b,c):
    return abs(((c-a).det(b-a))/((b-a).abs()))


def DistanceSeglineToPoint(a,b,c):
    if sgn((b-a).dot(c-a)) < 0: 
        return (c-a).abs()
    if sgn((a-b).dot(c-b)) < 0: 
        return (c-b).abs()
    return DistanceLineToPoint(a,b,c)


def Vfoot(a,b,c):
    d = c + Point((b-a).y,-(b-a).x)
    return Intersection(a,b,c,d)


def PolygonArea(Plist):
    Plist = ConvexHull(Plist)
    L = len(Plist)
    S = 0
    for i in range(L):
        tmpS = (Plist[i-1].det(Plist[i]))/2
        S += tmpS
    return S


def PolygonG(Plist):
    Plist = ConvexHull(Plist)
    L = len(Plist)
    S = 0
    G = Point(0,0)
    for i in range(L):
        tmpS = (Plist[i-1].det(Plist[i]))/2
        S += tmpS
        G += (Plist[i-1]+Plist[i])/3*tmpS
    return G/S


def ConvexHull(Plist):
    Plist.sort()
    L = len(Plist)
    qu = deque([])
    quL = 0
    for p in Plist:
        while quL >= 2 and iSP(qu[quL-2],qu[quL-1],p) == 1:
            qu.pop()
            quL -= 1
        qu.append(p)
        quL += 1

    qd = deque([])
    qdL = 0
    for p in Plist:
        while qdL >= 2 and iSP(qd[qdL-2],qd[qdL-1],p) == -1:
            qd.pop()
            qdL -= 1
        qd.append(p)
        qdL += 1

    qd.pop()
    qu.popleft()
    hidari = list(qd) + list(reversed(qu)) 
    return hidari

x1,y1,x2,y2 = inpl()
a,b = Point(x1,y1), Point(x2,y2)
q = inp()
for _ in range(q):
    p = Point(*inpl())
    print(*Vfoot(a,b,p).tolist())

Solution (Python):
import math

line = input()
x1, y1, x2, y2 = list(map(int, line.split()))
line = input()
q = int(line)
pts = []
for _ in range(0, q):
    line = input()
    x, y = list(map(int, line.split()))
    pts += [[x, y]]

def solve():
    l1 = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
    for x, y in pts:
        l2 = math.sqrt((x - x1)**2 + (y - y1)**2)
        dx = (x2 - x1) / l1
        dy = (y2 - y1) / l1
        ip = (x - x1) * (x2 - x1) + (y - y1) * (y2 - y1)
        xx = x1 + dx * ip / l1
        yy = y1 + dy * ip / l1
        print(xx, yy)

solve()

Solution (Python):
import math

HORIZONTAL = 0
VERTICAL = 1
ELSE = 2
mode = ELSE

x_p1, y_p1, x_p2, y_p2 = [int(i) for i in input().split()]
if x_p2-x_p1 == 0:
    mode = VERTICAL
elif y_p2-y_p1 == 0:
    mode = HORIZONTAL
else:
    a = (y_p2-y_p1)/(x_p2-x_p1)
    b = y_p1 - a * x_p1

q = int(input())
for _ in range(q):
    x_p0, y_p0 = [int(i) for i in input().split()]
    u = x_p0-x_p1
    v = y_p0-y_p1
    if mode == VERTICAL:
        print(x_p1, y_p0)
    elif mode == HORIZONTAL:
        print(x_p0, y_p1)
    else:
        x = (x_p0/a+y_p0-b)/(a+1/a)
        y = a* x + b
        print(x, y)

Solution (Python):
pp  = list(map(int, input().split()))
n = int(input())

def project(bb, p=pp):
    ans = []
    a = (p[0]-p[2], p[1]-p[3])
    b = (bb[0]-p[0], bb[1]-p[1])
    c = dot(a,b)/length(a)**2
    ans += [c*i for i in a] 
    print(ans[0]+p[0], ans[1]+p[1])
    

def length(vector):
    ans = 0
    for i in vector:
        ans += i**2
    return ans**(1/2)
    
    
def dot(a, b):
    n = len(a)
    if n != len(b):
        return None
    ans = 0
    for i, j in zip(a, b):
        ans += i*j
    return ans
    
for i in range(n):
    b = list(map(int, input().split()))
    project(b)

Solution (Python):
import math


class Point:
    EPS = 1 << 10

    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Point(self.x+other.x, self.y+other.y)

    def __sub__(self, other):
        return Point(self.x-other.x, self.y-other.y)

    def __mul__(self, other):
        return Point(self.x*other, self.y*other)

    def __floordiv__(self, other):
        return Point(self.x/other.x, self.y/other.y)

    def __abs__(self):
        return math.sqrt(self.norm())

    def norm(self):
        return self.x**2 + self.y**2

    def __eq__(self, other):
        EPS = self.__class__.EPS
        return abs(self.x-other.x) < EPS and abs(self.x-other.x) < EPS

    def dot(self, other):
        return self.x*other.x + self.y*other.y

    def cross(self, other):
        return self.x*other.y - self.y*other.x

    def isOrthogonal(self, a, b):
        return a.dot(b) == 0.0

    def isParallel(self, a, b):
        return a.cross(b) == 0.0

    def __str__(self):
        return str(self.x)+' '+str(self.y)


class Vector(Point):
    pass


class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

    def isOrthogonal(s1, s2):
        return (s1.p2-s1.p1).dot(s2.p2-s2.p1) == 0.0

    def isParallel(s1, s2):
        return (s1.p2-s1.p1).cross(s2.p2-s2.p1) == 0.0


class Line(Segment):
    pass


class Circle:
    def __init__(self, c, r):
        self.c = c
        self.r = r


class Polygon:
    def __init__(self, *points):
        self.points = points


def project(s, p):
    base = s.p2 - s.p1
    r = (p-s.p1).dot(base) / base.norm()
    return s.p1 + base * r



x1, y1, x2, y2 = map(int, input().split())
p1, p2 = Point(x1, y1), Point(x2, y2)
s = Segment(p1, p2)

q = int(input())
for i in range(q):
    p = Point(*map(int, input().split()))
    print(project(s, p))

Solution (Python):
import math


class Vector2():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, v):
        return Vector2(self.x+v.x, self.y+v.y)

    def __sub__(self, v):
        return Vector2(self.x-v.x, self.y-v.y)

    def __mul__(self, v):
        return Vector2(self.x*v, self.y*v)

    def __truediv__(self, v):
        return Vector2(self.x/v, self.y/v)

    def __abs__(self):
        return math.sqrt(float(self.x*self.x+self.y*self.y))

    def dot(self, v):
        return self.x*v.x+self.y*v.y

    def cross(self, v):
        return self.x*v.y-self.y*v.x

    def norm(self):
        d = abs(self)
        return Vector2(self.x/d, self.y/d)


x1, y1, x2, y2 = map(int, input().split())
v12 = Vector2(x2-x1, y2-y1).norm()
q = int(input())
for i in range(q):
    x, y = map(int, input().split())
    v = Vector2(x-x1, y-y1)
    d = v12.dot(v)
    ans = Vector2(x1+v12.x*d, y1+v12.y*d)
    print(f"{ans.x} {ans.y}")

Solution (Python):
from sys import stdin

class Vector:
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = 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 __mul__(self, k):
        return Vector(self.x * k, self.y * k)

    def __gt__(self, other):
        return self.x > other.x and self.y > other.y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    
    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

class Point(Vector):
    def __init__(self, *args, **kargs):
        return super().__init__(*args, **kargs)

class Segment:
    def __init__(self, p1=Point(0, 0), p2=Point(1, 1)):
        self.p1 = p1
        self.p2 = p2

def project(s, p):
    base = s.p2 - s.p1
    hypo = p - s.p1
    r = hypo.dot(base) / base.norm()
    return s.p1 + base * r

def read_and_print_results(s, n):
    for _ in range(n):
        line = stdin.readline().strip().split()
        p = Vector(int(line[0]), int(line[1]))
        x = project(s, p)
        print('{0:0.10f} {1:0.10f}'.format(x.x, x.y))

x1, y1, x2, y2 = input().split()
p1 = Point(int(x1), int(y1))
p2 = Point(int(x2), int(y2))
s = Segment(p1, p2)
n = int(input())
read_and_print_results(s, n)

Solution (Python):
xp1,yp1,xp2,yp2=map(int,input().split())

q=int(input())

if xp1==xp2:
    for i in range(q):
        x0,y0=map(int,input().split())
        print('{:.10f}'.format(xp1),'{:.10f}'.format(y0))
else:
    a=float((yp2-yp1)/(xp2-xp1))
    for i in range(q):
        x0,y0=map(int,input().split())
        x=a*((y0-yp1)-a*(x0-xp1))/(1+a**2)+x0
        y=(a*(a*y0+x0-xp1)+yp1)/(1+a**2)
        print('{:.10f}'.format(x),'{:.10f}'.format(y))

Solution (Python):
class Vector:
    __slots__ = ['x', 'y']

    def __init__(self, x, y):
        self.x, self.y = x, y

    def __add__(self, other):
        return self.__class__(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return self.__class__(self.x - other.x, self.y - other.y)

    def __mul__(self, x):
        return self.__class__(self.x * x, self.y * x)

    def __truediv__(self, x):
        return self.__class__(self.x / x, self.y / x)

    def norm(self):
        return (self.x ** 2 + self.y ** 2) ** 0.5


def dot(u, v):
    return u.x * v.x + u.y * v.y


x1, y1, x2, y2 = map(float, input().split())
p1, p2 = Vector(x1, y1), Vector(x2, y2)
n = (p2 - p1) / (p2 - p1).norm()

q = int(input())

for _ in range(q):
    p = Vector(*map(float, input().split()))
    p_new = p1 + n * dot(p - p1, n)
    print(p_new.x, p_new.y)

Solution (Python):
from typing import List
from math import sqrt

EPS = 1e-10


def float_equal(x: float, y: float) -> bool:
    return abs(x - y) < EPS


class Point:

    def __init__(self, x: float=0.0, y: float=0.0) -> None:
        self.x = x
        self.y = y

    def __repr__(self) -> str:
        return "Point({}, {})".format(self.x, self.y)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Point):
            
            return NotImplemented
        return float_equal(self.x, other.x) and \
            float_equal(self.y, other.y)

    def __add__(self, other: 'Point') -> 'Point':
        return Point(self.x + other.x, self.y + other.y)

    def __sub__(self, other: 'Point') -> 'Point':
        return Point(self.x - other.x, self.y - other.y)

    def __mul__(self, k: float) -> 'Point':
        return Point(self.x * k, self.y * k)

    def __rmul__(self, k: float) -> 'Point':
        return self * k

    def __truediv__(self, k: float) -> 'Point':
        return Point(self.x / k, self.y / k)

    def __lt__(self, other: 'Point') -> bool:
        return self.y < other.y \
            if abs(self.x - other.x) < EPS \
            else self.x < other.x

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return sqrt(self.norm())

    def dot(self, other: 'Point') -> float:
        return self.x * other.x + self.y * other.y

    def cross(self, other: 'Point') -> float:
        return self.x * other.y - self.y * other.x

    def is_orthogonal(self, other: 'Point') -> bool:
        return float_equal(self.dot(other), 0.0)

    def is_parallel(self, other: 'Point') -> bool:
        return float_equal(self.cross(other), 0.0)


Vector = Point


class Segment:

    def __init__(self, p1: Point = None, p2: Point = None) -> None:
        self.p1: Point = Point() if p1 is None else p1
        self.p2: Point = Point() if p2 is None else p2

    def __repr__(self) -> str:
        return "Segment({}, {})".format(self.p1, self.p2)

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Segment):
            
            return NotImplemented
        return self.p1 == other.p1 and self.p2 == other.p2

    def vector(self) -> Vector:
        return self.p2 - self.p1

    def is_orthogonal(self, other: 'Segment') -> bool:
        return self.vector().is_orthogonal(other.vector())

    def is_parallel(self, other: 'Segment') -> bool:
        return self.vector().is_parallel(other.vector())

    def projection(self, p: Point) -> Point:
        v = self.vector()
        vp = p - self.p1
        return v.dot(vp) / v.norm() * v + self.p1


Line = Segment


def main():
    x1, y1, x2, y2 = [int(x) for x in input().split()]
    p1 = Point(x1, y1)
    p2 = Point(x2, y2)
    l = Line(p1, p2)

    q = int(input())

    for _ in range(q):
        x, y = [int(x) for x in input().split()]
        p = Point(x, y)
        a = l.projection(p)
        print(a.x, a.y)


if __name__ == "__main__":
    main()

Solution (Python):
from math import hypot
x1, y1, x2, y2 = map(int, input().split())
dx, dy = x2-x1, y2-y1
vector_a = hypot(dx, dy)
q = int(input())

for x3, y3 in (map(int, input().split()) for _ in [0]*q):
    d = ((x3-x1)*dx + (y3-y1)*dy) / (vector_a**2)
    print(x1+dx*d, y1+dy*d)

Solution (Python):
pxylist = []
result  = []
xp1, yp1, xp2, yp2 = map(int, input ().split())

q = int(input())

def recieve():
    for i in range(q):
            pxy = list(map(int, input().split()))
            pxylist.append(pxy) 

if xp2 == xp1:
    recieve()

    for i in range(q):
        result.append([xp1, pxylist[i][1]])
elif yp1 == yp2:
    recieve()

    for i in range(q):
        result.append([pxylist[i][0], yp1])

else:
    a = (yp2 - yp1) / (xp2 - xp1)
    b = yp1 - a*xp1

    recieve()

    for i in range(q):
        pxi = pxylist[i][0]
        pyi = pxylist[i][1]
        x = (a * (pyi - b) + pxi) / (a*a + 1)
        y = a * x + b
        result.append([x, y])

for i in range(q):
    print(str(result[i][0]) + ' ' + str(result[i][1]))

Solution (Python):





import sys
input = sys.stdin.readline

from math import cos,sin,radians,sqrt

def Projection(p1,p2):
    (x1,y1,x2,y2) = p1
    if (x1*x1+y1*y1 > x2*x2 + y2*y2):
        (x1,y1,x2,y2) = (x2,y2,x1,y1)
    (x3,y3) = p2

    tx = x2 -x1
    ty = y2 -y1
    l = sqrt(tx*tx+ty*ty)

    nx = tx / l
    ny = ty / l
    pl = nx * (x3 - x1)  + ny * (y3 - y1)
    return (nx * pl + x1, ny * pl + y1 )


def main():
    (x1,y1,x2,y2) = map(int,input().split())
    for i in range(int(input())):
        (x3,y3) = map(int,input().split())
        print('{:.10f} {:.10f}'.format(*Projection((x1,y1,x2,y2),(x3,y3))))

    
if __name__ == '__main__':
    main()

Solution (Python):
xp1, yp1, xp2, yp2 = map(int, input().split())
q = int(input())

xp = complex(xp2 - xp1, yp2 - yp1)
x1 = complex(xp1, yp1)

for _ in range(q):
    x, y = map(int, input().split())
    xpi = complex(x - xp1, y - yp1)
    dot = xp.real * xpi.real + xp.imag * xpi.imag
    ans = x1 + dot * xp / (abs(xp) ** 2)
    print("{:.9f} {:.9f}".format(ans.real, ans.imag))

Solution (Python):




def proj(p1, p2, p):
    x1, y1 = p1
    x2, y2 = p2
    x, y = p

    if x1 == x2:
        return x1 * 1.0, y * 1.0
    elif y1 == y2:
        return x * 1.0, y1 * 1.0
    else:
        dx = x1 - x2
        dy = y1 - y2
        return (((dx*x + dy*y)*dx - (x1*y2 - x2*y1)*dy) / (dx*dx + dy*dy),
                ((dx*x + dy*y)*dy + (x1*y2 - x2*y1)*dx) / (dx*dx + dy*dy))


def run():
    px1, py1, px2, py2 = [int(v) for v in input().split()]
    q = int(input())

    for _ in range(q):
        x, y = [int(v) for v in input().split()]
        print("{:.10f} {:.10f}".format(*proj((px1, py1), (px2, py2), (x, y))))


if __name__ == '__main__':
    run()

Solution (Python):
import math


class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __sub__(self, other):
        return Point(self.x - other.x, self.y - other.y)

    def __repr__(self):
        return f"({self.x},{self.y})"


class Segment:
    def __init__(self, x: Point, y: Point):
        self.pt1 = x
        self.pt2 = y
        self.vector = self.pt2 - self.pt1
        self.norm = pow(self.vector.x, 2) + pow(self.vector.y, 2)
        self.abs = math.sqrt(self.norm)

    def dot(self, other):
        return self.vector.x * other.vector.x + self.vector.y * other.vector.y

    def cross(self, other):
        return self.vector.x * other.vector.y - self.vector.y * other.vector.x

    def projection(self, pt: Point)-> Point:
        vec_p1_to_pt = Segment(self.pt1, pt)
        t = self.dot(vec_p1_to_pt) / self.abs
        x = self.pt1.x + t / self.abs * self.vector.x
        y = self.pt1.y + t / self.abs * self.vector.y
        return Point(x, y)

    def __repr__(self):
        return f"{self.pt1},{self.pt2},{self.vector}"


def main():
    p0_x, p0_y, p1_x, p1_y = map(int, input().split())
    seg_1 = Segment(Point(p0_x, p0_y), Point(p1_x, p1_y))
    num_query = int(input())
    for i in range(num_query):
        pt_x , pt_y = map(int, input().split())
        proj = seg_1.projection(Point(pt_x, pt_y))

        print("{:.10f} {:.10f}".format(proj.x, proj.y))
    return

main()

Solution (Python):
a,b,c,d = map(float, input().split())


c -= a
d -= b

for _ in [0] * int(input()):
  
  x, y = map(float, input().split())

  
  x -= a
  y -= b

  
  z = (c*x + d*y) / (c*c + d*d)
  print(a+c*z, b+d*z)

Solution (Python):
sx, sy, ex, ey = (int(n) for n in input().split(" "))
trial = int(input())
for _ in range(trial):
    x, y = (int(n) for n in input().split(" "))
    if sx == ex:
        print(sx, y)
    elif sy == ey:
        print(x, sy)
    else:
        grad = (ey - sy) / (ex - sx)
        y_seg = sy - (grad * sx)
        per_grad = -1 / grad
        per_y_seg = y - (per_grad * x)
        ans_x = (y_seg - per_y_seg) / (-1 * (grad - per_grad))
        ans_y = per_grad * ans_x + per_y_seg
        print(ans_x, ans_y)

Solution (Python):
import math

def equals(a, b):
    return abs(a - b) < 1e-10


class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    def __add__(self, p):
        return Point(self.x + p.x, self.y + p.y)

    def __sub__(self, p):
        return Point(self.x - p.x, self.y - p.y)

    def __mul__(self, a):
        return Point(self.x * a, self.y * a)

    def __rmul__(self, a):
        return self * a

    def __truediv__(self, a):
        return Point(self.x / a, self.y / a)

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

    def __lt__(self, p):
        if self.x != p.x:
            return self. x < p.x
        else:
            return self.y < p.y

    def __eq__(self, p):
        return equals(self.x, p.x) and equals(self.y, p.y)


class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2


def dot(a, b):
    return a.x * b.x + a.y * b.y


def cross(a, b):
    return a.x * b.y - a.y * b.x


def project(s, p):
    base = s.p2 - s.p1
    r = dot(p - s.p1, base) / base.norm()
    return s.p1 + base * r


if __name__ == '__main__':
    x1, y1, x2, y2 = [int(v) for v in input().split()]
    s = Segment(Point(x1, y1), Point(x2, y2))
    q = int(input())
    ans = []
    for i in range(q):
        x, y = [int(v) for v in input().split()]
        p = Point(x, y)
        ans.append(project(s, p))

    for v in ans:
        print('{0:.10f} {1:.10f}'.format(v.x, v.y))

Solution (Python):
x,y,s,t = map(float, input().split())
a = int(input())
s-=x
t-=y
while a:
    a -= 1
    p,q = map(float, input().split())
    p-=x
    q-=y
    ans_x = s*(q*t+p*s)/(t*t+s*s)
    ans_y = t*(q*t+p*s)/(t*t+s*s)
    print(x+ans_x, y+ans_y)