Problem:
Points on a Straight Line
The university of A stages a programming contest this year as has been the case in the past. As a member of the team in charge of devising the problems, you have worked out a set of input data for a problem, which is an arrangement of points on a 2D plane in the coordinate system. The problem requires that any combination of these points greater than or equal to $K$ in number must not align on a line. You want to confirm that your data satisfies this requirement.
Given the number of points $K$ and their respective 2D coordinates, make a program to check if any combination of points greater or equal to $K$ align on a line.
Input
The input is given in the following format.
$N$ $K$
$x_1$ $y_1$
$x_2$ $y_2$
$...$
$x_N$ $y_N$
The first line provides the number of points $N$ ($3 \leq N \leq 3000$) on the 2D coordinate system and an integer $K$ ($3 \leq K \leq N$). Each of the subsequent lines provides the $i$-th coordinate $x_i,y_i$ ($0 \leq x_i,y_i \leq 10000$) as integers. None of these coordinates coincide, i.e., if $i \ne j$, then $x_i \ne x_j$ or $y_i \ne y_j$.
Output
Output
1
if any combination of points greater or equal to $K$ aligns on a line, or
0
otherwise.
Sample Input 1
5 4
0 0
1 0
1 1
0 1
2 2
Sample Output 1
0
Sample Input 2
7 5
0 0
1 0
1 1
0 1
2 0
3 0
4 0
Sample Output 2
1

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
int f(int a, int b){
    if(a < b) swap(a,b);
    int x,y;
    if(b == 0){
        return a;
    }
    else{
        return f(b,a%b);
    }
}
signed main(){
    int N,K;
    cin>>N>>K;
    vector<int> X(N), Y(N);
    for(int i=0;i<N;i++) cin>>X[i]>>Y[i];
    int bs = 4000000;
    for(int i=0;i<N;i++){
        unordered_map<int,int> m;
        for(int j=0;j<N;j++)if(i != j){
            int a = X[j]-X[i], b = Y[j]-Y[i];
            if(a == 0) b = 1;
            else if(b == 0) a = 1;
            else{
                if(a < 0){
                    a = -a;
                    b = -b;
                }
                int t = f(abs(a),abs(b));
                a /= t;
                b /= t;
            }
            m[a*bs+b]++;
        }
        for(auto [a,b]:m)if(b >= K-1){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
}
accuracy: 1
time_ms: 1380
memory_kb: 3612
final_rank: 7

code_snippet: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)

#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)

using namespace std;

using ll = long long;
using PLL = pair<ll, ll>;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

constexpr int MOD = 1000000007;

int main() {
    int N, K; scanf("%d%d", &N, &K);
    vector<PLL> A(N);
    rep (i, N) scanf("%lld%lld", &A[i].first, &A[i].second);
    rep (i, N) {
        vector<PLL> B;
        rep (j, i) B.emplace_back(A[j].first - A[i].first, A[j].second - A[i].second);
        for (auto& [x, y] : B) {
            if (x < 0) {
                x = -x;
                y = -y;
            }
            if (x == 0 && y < 0) y = -y;
        }
        sort(all(B), [&](PLL a, PLL b) { return a.first * b.second - a.second * b.first > 0; });
        rep (l, B.size()) {
            int r = l + 1;
            while (r < B.size() && B[l].first * B[r].second - B[r].first * B[l].second == 0) ++r;
            if (r - l >= K - 1) {
                puts("1");
                return 0;
            }
            l = r - 1;
        }
    }
    puts("0");
}
accuracy: 1
time_ms: 170
memory_kb: 3616
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
// #include<atcoder/all>
// using mint = atcoder::modint998244353;
using ld = long double;
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N,K;
    cin>>N>>K;
    vector<int> X(N),Y(N);
    rep(i,N)cin>>X[i]>>Y[i];
    vector<array<int,3>> A;
    rep(i,N){
        rep(j,i){
            int a=Y[i]-Y[j];
            int b=X[j]-X[i];
            int c=-(X[i]*a+Y[i]*b);

            int g=gcd(gcd(a,b),c);
            a/=g;
            b/=g;
            c/=g;
            if(a<0) a*=-1,b*=-1,c*=-1;
            A.push_back({a,b,c});
        }
    }
    sort(all(A));
    int c=0;
    array<int,3> mae={-1,-1,-1};
    for(auto e: A){
        if(mae==e) c++;
        else c=1;
        mae=e;
        if(c>=K*(K-1)/2){
            cout<<1<<"\n";
            return 0;
        }
    }
    cout<<0<<"\n";
    return 0;
}
accuracy: 1
time_ms: 640
memory_kb: 103204
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(ll i=0;i<(ll)N;i++)
#define all(X) X.begin(),X.end()
#define pb push_back
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    int N,K;cin>>N>>K;
    unordered_map<ll,int>S;
    vector<int>X(N),Y(N);
    rep(i,N)cin>>X[i]>>Y[i];
    rep(i,N)for(int j = i+1;j<N;j++){
        ll dx = X[i]-X[j];
        ll dy = Y[i]-Y[j];
        int d = gcd(abs(dx),abs(dy));
        dx/=d;dy/=d;
        if(dx<0)dx*=-1,dy*=-1;
        if(dx==0&&dy<0)dy*=-1;
        ll c = Y[i]*dx-X[i]*dy;
        S[dx+dy*20000+c*400000000]++;
        if(K*(K-1)<=S[dx+dy*20000+c*400000000]*2){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
}
accuracy: 1
time_ms: 1520
memory_kb: 190524
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
struct frac {
    ll a, b;
    frac(ll _a, ll _b) : a(_a), b(_b) {
        if (b == 0) a = 1;
        else {
            if (b < 0) {
                a *= -1;
                b *= -1;
            }
            ll GCD = gcd(a, b);
            a /= GCD;
            b /= GCD;
        }
    }
    bool operator<(const frac& other) const {
        return a * other.b < other.a * b;
    }
};
int main() {
    int n, k; cin >> n >> k;
    vector<pll> ps(n);
    rep(i, n) cin >> ps[i].first >> ps[i].second;
    rep(i, n - 1){
        map<frac, int> mp;
        for (int j = i + 1; j < n; ++j) {
            frac a = frac(ps[j].second - ps[i].second, ps[j].first - ps[i].first);
            if (!mp.count(a))mp[a] = 1;
            mp[a]++;
        }
        for (auto& p : mp) {
            if (p.second >= k) {
                cout << 1 << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}
accuracy: 1
time_ms: 920
memory_kb: 3712
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
struct frac {
    ll a, b;
    frac(ll _a, ll _b) : a(_a), b(_b) {
        if (b == 0) a = 1;
        else {
            if (b < 0) {
                a *= -1;
                b *= -1;
            }
            ll GCD = gcd(a, b);
            a /= GCD;
            b /= GCD;
        }
    }
    bool operator<(const frac& other) const {
        return a * other.b < other.a * b;
    }
};
int main() {
    int n, k; cin >> n >> k;
    vector<pll> ps(n);
    rep(i, n) cin >> ps[i].first >> ps[i].second;
    rep(i, n - 1){
        map<pair<frac, frac>, int> mp;
        for (int j = i + 1; j < n; ++j) {
            frac a = frac(ps[j].second - ps[i].second, ps[j].first - ps[i].first);
            frac b = a.b == 0 ? frac(ps[i].first, 1) : frac(ps[i].second * a.b - a.a * ps[i].first, a.b);
            if (!mp.count({ a,b }))mp[{a, b}] = 1;
            mp[{a, b}]++;
        }
        for (auto& p : mp) {
            if (p.second >= k) {
                cout << 1 << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}
accuracy: 1
time_ms: 1190
memory_kb: 3840
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
struct frac {
    ll a, b;
    frac(ll _a, ll _b) : a(_a), b(_b) {
        if (b == 0) a = 1;
        else {
            if (b < 0) {
                a *= -1;
                b *= -1;
            }
            ll GCD = gcd(a, b);
            a /= GCD;
            b /= GCD;
        }
    }
    bool operator<(const frac& other) const {
        return a * other.b < other.a * b;
    }
};
int main() {
    int n, k; cin >> n >> k;
    vector<pll> ps(n);
    rep(i, n) cin >> ps[i].first >> ps[i].second;
    map<pair<frac, frac>, int> mp;
    rep(i, n - 1){
        map<pair<frac, frac>, int> nmp;
        for (int j = i + 1; j < n; ++j) {
            frac a = frac(ps[j].second - ps[i].second, ps[j].first - ps[i].first);
            frac b = frac(ps[i].second * a.b - a.a * ps[i].first, a.b);
            if (!nmp.count({ a,b }))nmp[{a, b}] = 1;
            nmp[{a, b}]++;
        }
        for (auto& p : nmp) {
            if (!mp.count(p.first))mp[p.first] = p.second;
        }
    }
    for (auto& p : mp) {
        if (p.second >= k) {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}
accuracy: 0.65
time_ms: 320
memory_kb: 42240
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----

偏角ソート+Xの部分をライブラリにしたい

----解説ここまで---- */



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N, K; cin >> N >> K;
	vector<double> x(N), y(N);

	FOR(i, 0, N) {
		cin >> x[i] >> y[i];
	}
	// O(N^2logN) ?
	bool exist = 0;
	const double EPS = 1e-7;
	FOR(i, 0, N) {
		vector<double>args;
		FOR(j, 0, N) {
			if (i == j)continue;
			args.push_back(atan2(y[i] - y[j], x[i] - x[j]));
		}
		SORT(args);
		FOR(j, 0, N - 1) {
			args.push_back(args[j] + 2 * PI);
		}
		FOR(j, 0, N - 1) {
			int cnt = upper_bound(ALL(args), args[j] + EPS) - lower_bound(ALL(args), args[j] - EPS);
			cnt += upper_bound(ALL(args), args[j] + PI + EPS) - lower_bound(ALL(args), args[j] + PI - EPS);
			cnt++;
			exist |= cnt >= K;
		}

	}
	cout << exist << endl;

	return 0;
}
accuracy: 1
time_ms: 1490
memory_kb: 4080
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

template <typename T>
using vc = vector<T>;
template <typename T>
using vv = vc<vc<T>>;

//-------------1.型系---------------
using ll = long long;
ll INF = 2e18;

using ld = long double;
using bl = bool;
// using mint = modint998244353;
using mint = modint1000000007;
//   using mint = modint;
//   mint::set_mod(m);

template <class T>
using pq = priority_queue<T, vc<T>>;
template <class T>
using pq_g = priority_queue<T, vc<T>, greater<T>>;
//-----------------------------------

//-------------2.配列系--------------

using pii = pair<int, int>;
using pll = pair<long long, long long>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
template <class T>
istream &operator>>(istream &i, vc<T> &v)
{
    rep(j, size(v)) i >> v[j];
    return i;
}

using ar2 = array<ll, 2>;

//----------------------------------

//--------3.コード短縮化とか---------
const double PI = 3.141592653589793238;
const int inf = 1073741823;
const ll infl = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define drep(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define nfor(i, s, n) for (ll i = s; i < n; i++)
#define dfor(i, s, n) for (ll i = (s) - 1; i >= n; i--)

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YN                     \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    } // if(a==b)YN;

#define vc_unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define vc_rotate(v) rotate(v.begin(), v.begin() + 1, v.end());

#define pop_cnt(s) ll(popcount(uint64_t(s)))

#define next_p(v) next_permutation(v.begin(), v.end())

//-------------------------------

//---------4.グリッド系----------
vector<int> dx = {1, 0, -1, 0}; //  dx={1,1,0,-1,-1,-1,0,1};
vector<int> dy = {0, 1, 0, -1}; //  dy={0,1,1,1,0,-1,-1,-1};

bool out_grid(ll i, ll j, ll h, ll w = -1)
{
    if (w == -1)
    {
        w = h;
    }
    return (!(0 <= i && i < h && 0 <= j && j < w));
}

#define vvl_rotate(v)                                   \
    {                                                   \
        ll n = size(v);                                 \
        vvl nx(n, vl(n));                               \
        rep(i, n) rep(j, n) nx[j][n - i - 1] = v[i][j]; \
        swap(nx, v);                                    \
    } // 時計回りに90°回転
// #define vvl_rotate(v) {ll n = size(v);vvl
// nx(n,vl(n));rep(i,n)rep(j,n)nx[n-j-1][i]=v[i][j];swap(nx,v);}//反時計周りに90°回転

#define vs_rotate(v)                                    \
    {                                                   \
        ll n = size(v);                                 \
        vs nx(n, string(n, '.'));                       \
        rep(i, n) rep(j, n) nx[j][n - i - 1] = v[i][j]; \
        swap(nx, v);                                    \
    } // 文字列版 時計回りに90°回転
// #define vs_rotate(v) {ll n = size(v);vs
// nx(n,string(n,'.'));rep(i,n)rep(j,n)nx[n-j-1][i]=v[i][j];swap(nx,v);}//文字列版　反時計周りに90°回転

#define vvl_transpos(v)                         \
    {                                           \
        ll n = size(v);                         \
        vvl nx(n, vl(n));                       \
        rep(i, n) rep(j, n) nx[j][i] = v[i][j]; \
        swap(nx, v);                            \
    }
#define vs_transpos(v)                          \
    {                                           \
        ll n = size(v);                         \
        vs nx(n, string(n, '.'));               \
        rep(i, n) rep(j, n) nx[j][i] = v[i][j]; \
        swap(nx, v);                            \
    }

//--------------------------------

//-----------5.数学系--------------
#define euclid(x, y) ((x) * (x) + (y) * (y)) // ユークリッド距離 2乗のまま
#define manhattan(x1, x2, y1, y2) \
    (abs(x1 - x2) + abs(y1 - y2)) // マンハッタン距離 = |x1-x2|+|y1-y2|

template <class T>
T tousa_sum1(T l, T d, T r)
{ // 初項,公差,末項 で総和を求める
    T wide = (r - l) / d + 1;
    return (l + r) * wide / 2;
}
template <class T>
T tousa_sum2(T a, T d, T n)
{ // 初項,交差,項数 で総和を求める
    return (a * 2 + d * (n - 1)) * n / 2;
}
ll kousa_kousuu(ll l, ll r, ll d)
{ // 初項,末項,交差 で等差数列の項数を求める
    return (r - l) / d + 1;
}
mint touhi_sum(mint a, mint r,
               ll n)
{ // 初項,公比,項数で等比数列の総和を求める
    if (r == 1)
    {
        return a * n;
    }
    mint bunsi = a * (r.pow(n) - mint(1));
    mint bunbo = r - 1;
    return bunsi / bunbo;
}

ll nc2(ll x) { return x * (x - 1) / 2; }
ll nc3(ll x) { return x * (x - 1) * (x - 2) / 6; }

//----------------------------------------------

//-----------6.デバックや出力系------------------
void print(ld x) { printf("%.20Lf\n", x); }

#define print_vec(v)                   \
    {                                  \
        ll n = size(v);                \
        rep(i, n) cout << v[i] << " "; \
        cout << endl;                  \
    } // 一次元配列を出力する(改行なし)

#define vc_cout(v)                      \
    {                                   \
        ll n = size(v);                 \
        rep(i, n) cout << v[i] << endl; \
    } // 一次元配列を出力する(改行あり)
#define vv_cout(v)                                         \
    {                                                      \
        ll n = size(v);                                    \
        rep(i, n)                                          \
        {                                                  \
            rep(j, size(v[i])) { cout << v[i][j] << ' '; } \
            cout << endl;                                  \
        }                                                  \
    } // 二次元配列を出力する
//----------------------------------------------

int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);

    int n, k;
    cin >> n >> k;
    vector<int> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    vector<tuple<int, int, int, int>> m;
    rep(i, n)
    {
        nfor(j, i + 1, n)
        {
            int ax = x[i], ay = y[i], bx = x[j], by = y[j];
            if (ax > bx)
                swap(ax, bx), swap(ay, by);
            if (ax == bx && ay > by)
                swap(ay, by);

            int g = gcd(bx - ax, by - ay);

            int nx = (bx - ax) / g, ny = (by - ay) / g;

            int k = nx, w = ny;
            if (nx == 0)
                k = ax, w = 0;
            else if (ny == 0)
                k = ay, w = 0;
            else
            {
                w = ay * nx - ny * ax;
                int ng = gcd(k, w);
                k /= ng, w /= ng;
            }
            m.push_back({nx, ny, k, w});
        }
    }
    sort(all(m));

    int l = 0;
    auto b = m[0];
    bool f = false;
    rep(i, m.size())
    {
        if (b == m[i])
            continue;

        if ((i - l) >= nc2(k))
        {
            f = true;
        }
        b = m[i];
        l = i;
    }
    if (int(m.size()) - l >= nc2(k))
        f = true;

    cout << f << endl;
    return 0;
}
accuracy: 1
time_ms: 730
memory_kb: 135716
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, K;
    cin >> N >> K;

    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];

    vector<pair<pii, pii>> A;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int dx = X[j] - X[i], dy = Y[j] - Y[i];
            int c = X[j] * Y[i] - X[i] * Y[j];
            if (dx < 0) {
                dx = -dx;
                dy = -dy;
                c = -c;
            }

            int gcd1 = gcd(dx, dy), gcd2 = gcd(dx, c);

            if (dx == 0) {
                dy = 1;
                c = X[i];
                gcd1 = 1;
                gcd2 = 1;
            }

            if (dy == 0) {
                dx = 1;
                c = Y[i];
                gcd1 = 1;
                gcd2 = 1;
            }

            A.emplace_back(make_pair(dx / gcd1, dy / gcd1), make_pair(dx / gcd2, c / gcd2));
        }
    }

    sort(A.begin(), A.end());

    int mCnt = 0;
    for (int i = 0; i < (int) A.size(); i++) {
        int cnt = 1;
        while (i + 1 < (int) A.size() && A[i] == A[i + 1]) {
            i++;
            cnt++;
        }

        mCnt = max(mCnt, cnt);
    }

    cout << ((mCnt >= K * (K - 1) / 2) ? 1 : 0) << endl;
}
accuracy: 1
time_ms: 890
memory_kb: 135832
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;

using i64 = long long;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repi(i, a, b) for (int i = (a) - 1; i >= (b); --i)

struct Point {
    i64 x, y;
    Point(i64 x_ = 0, i64 y_ = 0) : x(x_), y(y_) {}

    Point &operator+=(const Point &p) {
        x += p.x;
        y += p.y;
        return *this;
    }

    Point &operator-=(const Point &p) {
        x -= p.x;
        y -= p.y;
        return *this;
    }

    Point operator-(const Point &p) const { return Point(*this) -= p; }

    i64 cross(const Point &p) const { return x * p.y - y * p.x; }
    friend i64 cross(const Point &p, const Point &q) { return p.cross(q); }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<Point> ps(n);
    rep (i, 0, n) cin >> ps[i].x >> ps[i].y;
    rep (i, 0, n) {
        map<pair<i64, i64>, int> cnt;
        rep (j, 0, n) if (j != i) {
            Point v = ps[j] - ps[i];
            pair<i64, i64> co = {v.x, v.y};
            if (co.first == 0) {
                co.second = 1;
            }
            else if (co.second == 0) {
                co.first = 1;
            }
            else {
                i64 g = gcd(co.first, co.second);
                co.first /= g;
                co.second /= g;
                if (co.first < 0) {
                    co.first *= -1;
                    co.second *= -1;
                }
            }
            // cout << i << " " << j << " " << co.first << " " << co.second << endl;
            cnt[co]++;
            if (cnt[co] >= k - 1) {
                cout << 1 << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;


    return 0;
}
accuracy: 1
time_ms: 1820
memory_kb: 3584
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif

int solve(int N, int K, vector<int>& x, vector<int>& y) {
    for (int i = 0; i < N; i++) {
        // i を通る直線 f と f を通る点の個数を計算
        // f を通る直線が K - 1 本以上ある場合、 K 個以上の点を通る直線が存在する
        map<pair<double, double>, int> cnt;
        for (int j = i + 1; j < N; j++) {
            double a = (y[j] - y[i]) / (double)(x[j] - x[i]);
            double b = y[i] - a * x[i];
            if (a == numeric_limits<double>::infinity()) {
                // a が inf の場合, 関数 f := x = x[i] として扱う
                cnt[{a, x[i]}]++;
            } else {
                // それ以外の場合, 関数 f := y = ax + b として扱う
                cnt[{a, b}]++;
            }
        }
        for (auto&& [key, value]: cnt) {
            if (value >= K - 1) return 1;
        }
    }
    return 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N, K;
    cin >> N >> K;
    vector<int> x(N), y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    cout << solve(N, K, x, y) << '\n';
}
accuracy: 1
time_ms: 480
memory_kb: 3656
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif

int naive(int N, int K, vector<int> x, vector<int> y) {
    int res = 0;
    map<pair<double, double>, int> debug_cnt;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int cnt = 0;
            double a = (y[j] - y[i]) / double(x[j] - x[i]);
            double b = y[i] - a * x[i];
            if (b == 1) debug(a, b, i, j);
            for (int k = 0; k < N; k++) {
                if (a == numeric_limits<double>::infinity()) {
                    if (x[k] == x[i]) {
                        cnt++;
                    }
                } else {
                    if (a * x[k] + b == y[k]) {
                        cnt++;
                    }
                }
            }
            debug_cnt[{a, b}] = cnt;
            if (cnt >= K) {
                res = 1;
                break;
            }
        }
    }

    debug(debug_cnt);
    return res;
}

int solve(int N, int K, vector<int>& x, vector<int>& y) {
    vector<pair<double, double>> f;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            double a = (y[j] - y[i]) / double(x[j] - x[i]);
            double b = y[i] - a * x[i];
            // a が inf の場合
            if (a == numeric_limits<double>::infinity()) {
                f.emplace_back(a, x[i]);
            } else {
                f.emplace_back(a, b);
            }
        }
    }

    sort(f.begin(), f.end());
    int streak = 1, res = 0;
    for (int i = 0; i < int(f.size()); i++) {
        if (i == int(f.size()) - 1) {
            if (2 * streak >= K * (K - 1)) res = 1;
            break;
        }
        if (f[i] == f[i + 1]) {
            streak++;
        } else {
            if (2 * streak >= K * (K - 1)) res = 1;
            streak = 1;
        }
    }

    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N, K;
    cin >> N >> K;
    vector<int> x(N), y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    cout << solve(N, K, x, y) << '\n';
}
accuracy: 1
time_ms: 330
memory_kb: 136136
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Point = complex<double>;
Point unitVector(const Point &a) { return a / abs(a); }
int main(){
	#define int long long
	int n,k;
	cin >>n>>k;
	k--;
	Point x[n];
	for(int i = 0;i < n;i++){
		int y,z;
		cin >>y>>z;
		x[i] = Point(y,z);
	}
	if(true){
		for(int i = 0;i < n;i++){
			map<pair<double,double>,int>a;
			for(int j = 0;j < n;j++){
				if(i != j&&x[i].real() <= x[j].real()&&x[i].imag() >= x[j].imag()){
					Point y = unitVector(x[i]-x[j]);
					y = Point(ceil(y.real()*100000)/100000,ceil(y.imag()*100000)/100000);
					a[{y.real(),y.imag()}]++;
					if(a[{y.real(),y.imag()}] == k){
						cout <<1<<"\n";
						return 0;
					}
				}
			}
		}
	}
	if(true){
		for(int i = 0;i < n;i++){
			map<pair<double,double>,int>a;
			for(int j = 0;j < n;j++){
				if(i != j&&x[i].real() >= x[j].real()&&x[i].imag() >= x[j].imag()){
					Point y = unitVector(x[i]-x[j]);
					y = Point(ceil(y.real()*100000)/100000,ceil(y.imag()*100000)/100000);
					a[{y.real(),y.imag()}]++;
					if(a[{y.real(),y.imag()}] == k){
						cout <<1<<"\n";
						return 0;
					}
				}
			}
			// if(x[i] == Point(10,10)){
			// 	for(auto i:a)cout <<"("<<i.first.first<<","<<i.first.second<<"):"<<i.second<<"\n";
			// }
		}
	}
	cout <<0<<"\n";
	return 0;
}
accuracy: 1
time_ms: 710
memory_kb: 3584
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Point = complex<double>;
Point unitVector(const Point &a) { return a / abs(a); }
int main(){
	#define int long long
	int n,k;
	cin >>n>>k;
	k--;
	Point x[n];
	for(int i = 0;i < n;i++){
		int y,z;
		cin >>y>>z;
		x[i] = Point(y,z);
	}
	if(true){
		for(int i = 0;i < n;i++){
			map<pair<double,double>,int>a;
			for(int j = 0;j < n;j++){
				if(i != j&&x[i].real() <= x[j].real()&&x[i].imag() >= x[j].imag()){
					Point y = unitVector(x[i]-x[j]);
					y = Point(ceil(y.real()*10000)/10000,ceil(y.imag()*10000)/10000);
					a[{y.real(),y.imag()}]++;
					if(a[{y.real(),y.imag()}] == k){
						cout <<1<<"\n";
						return 0;
					}
				}
			}
		}
	}
	if(true){
		for(int i = 0;i < n;i++){
			map<pair<double,double>,int>a;
			for(int j = 0;j < n;j++){
				if(i != j&&x[i].real() >= x[j].real()&&x[i].imag() >= x[j].imag()){
					Point y = unitVector(x[i]-x[j]);
					y = Point(ceil(y.real()*10000)/10000,ceil(y.imag()*10000)/10000);
					a[{y.real(),y.imag()}]++;
					if(a[{y.real(),y.imag()}] == k){
						cout <<1<<"\n";
						return 0;
					}
				}
			}
			// if(x[i] == Point(10,10)){
			// 	for(auto i:a)cout <<"("<<i.first.first<<","<<i.first.second<<"):"<<i.second<<"\n";
			// }
		}
	}
	cout <<0<<"\n";
	return 0;
}
accuracy: 0.825
time_ms: 260
memory_kb: 3464
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N, K;
    cin >> N >> K;
    vector<int> x(N), y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

    // 2 点間の一次関数を求める
    // {a, b} := ax + b で表せる直線の個数
    map<pair<double, double>, int> id;
    // {a, b, id} := ax + b で表せる直線と基準となる点の id の個数
    map<tuple<double, double, int>, int> cnt;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            double a = (y[j] - y[i]) / (double)(x[j] - x[i]);
            double b = y[i] - a * x[i];
            if (id.count({a, b})) {
                if (i == id[{a, b}] || j == id[{a, b}]) {
                    cnt[{a, b, id[{a, b}]}] += 1;
                }
            } else {
                id[{a, b}] = i;
                cnt[{a, b, i}] += 2;
            }
        }
    }

    bool flag = false;
    for (auto [key, value] : cnt) {
        if (value >= K) {
            flag = true;
            break;
        }
    }

    cout << (flag ? 1 : 0) << '\n';
}
accuracy: 0.65
time_ms: 440
memory_kb: 73204
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;

// #define int long long

/*
17:29~17:43
6:25~
*/

signed main(){
	int n,k;cin>>n>>k;
	vector<int> x(n),y(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}

	for(int i=0;i<n;i++){
		map<array<int,3>,int> cnt;
		for(int j=i+1;j<n;j++){
			int a=x[i]-x[j];
			int b=y[i]-y[j];
			int c=x[i]*y[j]-x[j]*y[i];

			int g=gcd(abs(a),gcd(abs(b),abs(c)));
			a/=g,b/=g,c/=g;
			if(a<0){
				a=-a,b=-b,c=-c;
			}
			if(a==0&&b<0){
				b=-b,c=-c;
			}
			// cout<<i<<" "<<j<<" : "<<a<<" "<<b<<" "<<c<<endl;
			cnt[{a,b,c}]++;
			if(cnt[{a,b,c}]>=k-1){
				cout<<1<<endl;
				return 0;
			}
		}
	}
	cout<<0<<endl;
}
accuracy: 1
time_ms: 770
memory_kb: 3580
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;


vector<int> x(3000),y(3000);
pair<pair<int,int>,int> gf(int i,int j){
    int dx = (x[i]-x[j]);
    int dy = (y[i]-y[j]);
    
    if(dx==0){
        return make_pair(make_pair(1,0),x[i]);
    }
    if(dy==0){
        return make_pair(make_pair(0,0),y[i]);
    }
    
    int gcd = __gcd(dx,dy);
    dx/=gcd;
    dy/=gcd;

    if(dx*dy<0){
        if(dx<0) dx*=-1,dy*=-1;
    }
    else{
        if(dx<0) dx*=-1,dy*=-1;
    }


    return make_pair(make_pair(dx,dy),y[i]-(x[i]/dx)*dy);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,k;
    cin >> n >> k;
    rep(i,n) cin >> x[i] >> y[i];

    vector<pair<pair<int,int>,int>> v;

    rep(i,n){
        rep(j,i){
            v.push_back(gf(i,j));
        }
    }
    sort(v.begin(),v.end());
    int c=1;
    int ma = 0;
    rep(i,(int)v.size()-1){
        if(v[i]==v[i+1]) c++;
        else c=1;
        ma = max(ma,c);
    }

    if(ma>=(k*(k-1)/2)) cout << 1 << endl;
    else cout << 0 << endl;
}
accuracy: 1
time_ms: 650
memory_kb: 102820
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

constexpr int N = 3005;

int x[N], y[N];

int main() {
    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; ++i)
        cin >> x[i] >> y[i];

    for (int i = 0; i < n; ++i) {
        map<pair<int, int>, int> mp;
        for (int j = 0; j < n; ++j) {
            int cx = x[j] - x[i];
            int cy = y[j] - y[i];

            if (!cx && !cy)
                continue;

            tie(cx, cy) = make_pair(cx / gcd(cx, cy), cy / gcd(cx, cy));

            if (cx < 0 || (cx == 0 && cy < 0))
                cx = -cx, cy = -cy;

            if (++mp[{cx, cy}] + 1 >= k)
                return cout << 1 << '\n', 0;
        }
    }

    cout << 0 << '\n';
}
accuracy: 1
time_ms: 1600
memory_kb: 3644
final_rank: 12

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
MLE => map
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const double INF = 1e18;
const double EPS = 1e-5;
//----------------------------------------------make -f ../makefile SRC=--------------------------------
struct Point
{
    double x, y;
    Point(): x(0), y(0) {}
    Point(double x1, double x2): x(x1), y(x2) {}
    void debug() const { printf("%lf, %lf\n", x, y); }
};
typedef vector<Point> Points;

struct Line
{
    double m, k;
    Line(): m(0), k(0) {}
    Line(double v1, double v2): m(v1), k(v2) {}
    bool operator<(const Line& L1) const
    {
        if (fabs(m-L1.m) < EPS) return k < L1.k;
        return m < L1.m;
    }
    bool operator==(const Line& L1) const
    {
        return fabs(m-L1.m) < EPS && fabs(k-L1.k) < EPS;
    }
    void Debug() const { printf("%lf, %lf: ", m, k); }
    void debug() const { printf("%lf, %lf\n", m, k); }
};

typedef vector<Line> Lines;

double dist2(const Point& A, const Point& B)
{
    return (A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y);
}


double dist(double x1, double y1, double x2, double y2)
{
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

Line eqt_of_line(double x1, double y1, double x2, double y2)
{
    if (fabs(x1-x2) < EPS) return Line(INF, x1);
    else if (fabs(y1-y2) < EPS) return Line(0, y1);

    double a = y2-y1;
    double b = x1-x2;
    double c = x1*(y1-y2) + y1*(x2-x1);
    return Line(-a/b, -c/b);
}
//------------------------------------------------------------------------------
//return true if no. of collinear points >= K
/*
bool solve(int N, const Points& P, int K)
{
    //--------------------------------------------------------------------------
    // base cases:
    //--------------------------------------------------------------------------
    // init:
    map<Line, unordered_set<int> > S;
    //--------------------------------------------------------------------------
    // compute:
    for (int i=0; i<N-1; ++i)
        for (int j=i+1; j<N; ++j)
            {
                Line L1 = eqt_of_line(P[i].x, P[i].y, P[j].x, P[j].y);
                S[ L1 ].insert( i );
                S[ L1 ].insert( j );
                if (S[ L1 ].size() >= K) return true;
            }
    return false;
}
*/
//return true if no. of collinear points >= K
bool solve(int N, const Points& P, int K)
{
    //--------------------------------------------------------------------------
    // base cases:
    //--------------------------------------------------------------------------
    // init:
    Lines R;
    //--------------------------------------------------------------------------
    // compute:
    for (int i=0; i<N-1; ++i)
        for (int j=i+1; j<N; ++j)
            {
                Line L1 = eqt_of_line(P[i].x, P[i].y, P[j].x, P[j].y);
                R.push_back(L1);
            }

    sort(R.begin(), R.end());
    if (DEBUG) { for (Line L1: R) L1.debug(); }
    int max_lines = 0;
    int M = R.size();
    int start = 0;
    while (start < M)
    {
        int end = start;
        while (end < M && R[end] == R[start]) end++;
        if (R[end] == R[start])
        {
            max_lines = max(max_lines, end-start+1);
            break;
        }

        max_lines = max(max_lines, end-start);
        start = end;
    }
    if (DEBUG) printf("M=%d, max_lines=%d\n", M, max_lines);
    return K*(K-1)/2 <= max_lines;
}

//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, num;
    int K;
    double x, y;
    num = scanf("%d %d ", &N, &K);
    Points P(N);
    for (int i=0; i<N; ++i)
    {
        num = scanf("%lf %lf ", &x, &y);
        P[i] = Point(x, y);
    }
    if (solve(N, P, K)) printf("1\n");
    else printf("0\n");
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 490
memory_kb: 136252
final_rank: 13