#pragma once
template<typenameT>structLine{Ta,b;Line()=default;Line(Ta,Tb):a(a),b(b){}Line(std::pair<T,T>l):a(l.first),b(l.second){}Line(Tc):a(0),b(c){}Toperator()(constTx)const{returna*x+b;}Lineoperator()(constLine&l)const{returnLine(a*l.a,a*l.b+b);}booloperator==(constLine&l)const{returna==l.aandb==l.b;}booloperator!=(constLine&l)const{return!(*this==l);}booloperator<(constLine&l)const{return(a==l.a?a<l.a:b<l.b);}Line&operator+=(constLine&l){a+=l.a;b+=l.b;return*this;}Lineoperator+(constLine&l)const{returnLine(*this)+=l;}Line&operator-=(constLine&l){a-=l.a;b-=l.b;return*this;}Lineoperator-(constLine&l)const{returnLine(*this)-=l;}Lineoperator-()const{returnLine(-a,-b);}Line&operator+=(constT&c){b+=c;return*this;}Lineoperator+(constT&c)const{returnLine(*this)+=c;}Line&operator-=(constT&c){b-=c;return*this;}Lineoperator-(constT&c)const{returnLine(*this)-=c;}Line&operator*=(constT&c){a*=c;b*=c;return*this;}Lineoperator*(constT&c)const{returnLine(*this)*=c;}Line&operator/=(constT&c){a/=c;b/=c;return*this;}Lineoperator/(constT&c)const{returnLine(*this)/=c;}Lineinv()const{assert(a!=0);returnLine(T(1)/a,-b/a);}friendstd::istream&operator>>(std::istream&is,Line&l){is>>l.a>>l.b;returnis;}friendstd::ostream&operator<<(std::ostream&os,constLine&l){if(l.a==0andl.b==0)os<<0;elseif(l.a==0)os<<l.b;elseif(l.b==0)os<<l.a<<"x";elseif(l.b>0)os<<l.a<<"x+"<<l.b;elseos<<l.a<<"x-"<<-l.b;returnos;}};