#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke  
            
            
            int n,k;
            cin >> n >> k;
            int a[n];
            vector<int> pos,neg;
            int const mod = 1e9 + 7;
            for(int i = 0; i < n; i++)
            {
                cin >> a[i];
                if(a[i] >= 0)
                    pos.push_back(a[i]);
                else
                    neg.push_back(-a[i]);
            }

            int ans = 1;
            if(n == k)
            {
                for(int i = 0; i < n; i++)
                {
                    ans = (ans * a[i]) % mod;
                    ans += mod;
                    ans %= mod;
                    // cout << ans << endl;
                }
                cout << ans << '\n';
            }
            else if(pos.size() == 0)
            {
                if(k%2==1)
                {
                    sort(neg.begin(), neg.end());
                    for(int i = 0; i < k; i++)
                    {
                        ans = (ans * neg[i]) % mod;
                        ans += mod;
                        ans %= mod;
                    }
                    cout << (ans*-1 + mod)%mod << '\n';
                }
                else
                {
                    sort(neg.begin(), neg.end());
                    for(int i = 0; i < k; i++)
                    {
                        ans = (ans * neg[n - 1 - i]) % mod;
                        ans += mod;
                        ans %= mod;
                    }
                    cout << ans << '\n';
                }
            }
            else
            {
                sort(neg.begin(), neg.end(), greater<int>());
                sort(pos.begin(), pos.end(), greater<int>());
                if(k%2==1)
                {
                    // odd -> even (negs) + odd (pos)

                    ans = (ans * pos[0]) % mod;
                    vector<int> final;
                    for(int i = 2; i < pos.size(); i+=2)
                    {
                        final.push_back(pos[i] * pos[i-1]);
                    }
                    for(int i = 1; i < neg.size(); i+=2)
                        final.push_back(neg[i] * neg[i-1]);

                    sort(final.begin(), final.end(), greater<int>());
                    k--;
                    for(int i = 0; i < k/2; i++)
                        ans = (ans * (final[i]%mod)) % mod;
                    cout << ans << '\n';
                }
                else
                {
                    // even -> even (negs) + even (pos)
                    vector<int> final;
                    for(int i = 1; i < pos.size(); i+=2)
                    {
                        final.push_back(pos[i] * pos[i-1]);
                    }
                    for(int i = 1; i < neg.size(); i+=2)
                        final.push_back(neg[i] * neg[i-1]);

                    sort(final.begin(), final.end(), greater<int>());
                   
                    for(int i = 0; i < k/2; i++)
                        ans = (ans * (final[i]%mod)) % mod;
                    cout << ans << '\n';

                }

            }






           return 0;
        }
          

Measured memory_bytes: 8144