Problem:
E: ヘクト問題
あなたのもとに、農工大OBのヘクトさんから次のような連絡が来ました。
「\(1 \le M \le 10^3\) と \(2 \le P \le 10^5\) を満たせば正の整数 \(M\) と素数 \(P\) はあなたが選んで良いので、次の条件をすべて満たす長さ \(M\) の数列が \(N\) 個欲しい」
\(N\) 個の数列は全て異なる。
各数列の \(M\) 個の要素はすべて整数で、それぞれ \(1\) 以上 \(P\) 未満である。
各数列の \(M\) 個の数は全て異なる。
\(i\) 番目の数列の \(j\) 個目の要素を \(A_{i, j}\) と表すと、\(1 \le i,\ j \le N\) に対して、\(\sum_{k = 1}^{M}A_{i, k}A_{j, k} \equiv 0 \pmod{P}\) が成り立つ。
上記の条件をすべて満たす長さ \(M\) の数列を \(N\) 個出力してください。
制約
\(1 \le N \le 300\)
\(P\) は素数でなくてはならない
入力はすべて整数である
入力
N
出力
M\ P
A_{1, 1}, A_{1, 2}, ..., A_{1, M}
A_{2, 1}, A_{2, 2}, ..., A_{2, M}
︙
A_{N, 1}, A_{N, 2}, ..., A_{N, M}
入力例1
2
出力例1
2 5
3 4
2 1
\(1 \le i, j \le N\) に対して、 \(\sum_{k = 1}^{M}A_{i, k}A_{j, k} \equiv 0 \pmod{P}\) かどうかを確認します。
\((i, j) = (1, 1)\) のとき、\(\sum_{k = 1}^2 A_{1, k}A_{1, k} = 9 + 16 = 25 \equiv 0 \pmod{5}\) です。
\((i, j) = (2, 2)\) のとき、\(\sum_{k = 1}^2 A_{2, k}A_{2, k} = 4 + 1 = 5 \equiv 0 \pmod{5}\) です。
\((i, j) = (1, 2)\) のとき、\(\sum_{k = 1}^2 A_{1, k}A_{2, k} = 6 + 4 = 10 \equiv 0 \pmod{5}\) です。
また、他のすべての条件も満たしています。
入力例2
4
出力例2
4\ 5
2\ 1\ 3\ 4
4\ 2\ 1\ 3
3\ 4\ 2\ 1
1\ 3\ 4\ 2

Submitted solutions:

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

using namespace std;

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

    #ifdef BACKER
        freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    #endif

    int n, p = 997;
    cin >> n;
    cout << p - 1 << " " << p << "\n";
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= p - 1; j++) cout << i * j % p << " ";
        cout << "\n";
    }
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3452
final_rank: 2

code_snippet: #include <bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

ll mod = 1e9 + 7;


int main() {
	ll N;
	cin >> N;
	ll M, P;
	P =997;
	M = 996;
	vector<vll> A(N+1, vll(M));
	rep(i, M)A[0][i] = i + 1;
	
	ll n=1;
	set<ll> S;
    rep(a,P){
        if(S.count(a))continue;
        rep(b,a){
            if(S.count(b))continue;
            rep(c,b){
                if(S.count(c))continue;
                if(a*b*c==0)continue;
                if(((a-b)*(a-b)+(b-c)*(b-c)+(c-a)*(c-a))%P==0){
                    
                    S.insert(a);
                    S.insert(b);
                    S.insert(c);

                    rep(m,M){
						if(m==a){
							A[n][m]=A[0][b];
						}
						else if(m==b){
							A[n][m]=A[0][c];
						}
						else if(m==c){
							A[n][m]=A[0][a];
						}
						else{
							A[n][m]=A[0][m];
						}
					}
					n++;
					if(n==N)break;
                }
				if(n==N)break;
            }
			if(n==N)break;
        }
		if(n==N)break;
    }

	cout<<M<<" "<<P<<endl;
	rep(i, N) {
		rep(m, M) {
			cout << A[i][m] << " ";
		}
		cout << endl;
	}

	


}
accuracy: 1
time_ms: 180
memory_kb: 5732
final_rank: 12

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

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

    int M = 996;
    int P = 997;
    int N;
    cin >> N;
    --N;
    cout << M << " " << P << endl;
    for (int i = 1; i <= M; ++i) {
        cout << i << (i < M ? " " : "\n");
    }
    if (N == 0) return 0;
    set<int> used;
    for (int i = 1; i <= M; ++i) {
        for (int j = i + 1; j <= M; ++j) {
            for (int k = j + 1; k <= M; ++k) {
                if (used.count(i) || used.count(j) || used.count(k)) continue;
                if ((i*i + j*j + k*k)%P == (i*j+j*k+k*i)%P) {
                    --N;
                    for (int l = 1; l <= M; ++l) {
                        if (l == i) cout << j;
                        else if (l == j) cout << k;
                        else if (l == k) cout << i;
                        else cout << l;
                        cout << (l < M ? " " : "\n");
                    }
                    used.insert(i);
                    used.insert(j);
                    used.insert(k);
                    if (N == 0) return 0;
                }
            }
        }
    }
}
accuracy: 1
time_ms: 950
memory_kb: 3484
final_rank: 13

code_snippet: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#include <unordered_set>
#include <unordered_map>
#define rep(x, s, t) for(ll x = (s); (x) <= (t); (x)++)
#define per(x, s, t) for(ll x = (s); (x) >= (t); (x)--)
#define reps(x, s) for(ll x = 0; (x) < (ll)(s).size(); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define outl(...) dump_func(__VA_ARGS__)
#define outf(x) cout << fixed << setprecision(16) << (x) << endl
#define inf 2e18
#define eps 1e-9
const double PI = 3.1415926535897932384626433;

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<ll, ll> P;

struct edge{
	ll to, cost;
	edge(){}
	edge(ll a, ll b){ to = a, cost = b;}
};
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

//int mod = 1000000007;
//int mod = 998244353;
int mod = 997;

struct mint{
	int x;
	mint(ll y = 0){if(y < 0 || y >= mod) y = (y%mod+mod)%mod; x = y;}
	mint(const mint &ope) {x = ope.x;}
	
	mint operator-(){return mint(-x);}
	mint operator+(const mint &ope){return mint(x) += ope;}
	mint operator-(const mint &ope){return mint(x) -= ope;}
	mint operator*(const mint &ope){return mint(x) *= ope;}
	mint operator/(const mint &ope){return mint(x) /= ope;}
	mint& operator+=(const mint &ope){
		x += ope.x;
		if(x >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint &ope){
		x += mod - ope.x;
		if(x >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint &ope){
		ll tmp = x;
		tmp *= ope.x, tmp %= mod;
		x = tmp;
		return *this;
	}
	mint& operator/=(const mint &ope){
		ll n = mod-2; mint mul = ope;
		while(n){
			if(n & 1) *this *= mul;
			mul *= mul;
			n >>= 1;
		}
		return *this;
	}
	mint inverse(){return mint(1) / *this;}
	bool operator ==(const mint &ope){return x == ope.x;}
	bool operator !=(const mint &ope){return x != ope.x;}
	bool operator <(const mint &ope){return x < ope.x;}
};
mint modpow(mint a, ll n){
	if(n == 0) return mint(1);
	if(n % 2) return a * modpow(a, n-1);
	else return modpow(a*a, n/2);
}
istream& operator >>(istream &is, mint &ope){
	ll t; is >> t, ope.x = t;
	return is;
}
ostream& operator <<(ostream &os, mint &ope){return os << ope.x;}
ostream& operator <<(ostream &os, const mint &ope){return os << ope.x;}

vector<mint> fact, fact_inv;
void make_fact(int n){
	fact.resize(n+1), fact_inv.resize(n+1);
	fact[0] = mint(1); rep(i, 1, n) fact[i] = fact[i-1] * mint(i);
	fact_inv[n] = fact[n].inverse(); per(i, n-1, 0) fact_inv[i] = fact_inv[i+1] * mint(i+1);
}
mint comb(int n, int k){ if(n < 0 || k < 0 || n < k) return mint(0); return fact[n] * fact_inv[k] * fact_inv[n-k];}
mint perm(int n, int k){ return comb(n, k) * fact[k]; }

vector<int> prime, pvec;
void make_prime(int n){
	prime.resize(n+1);
	rep(i, 2, n){
		if(prime[i]) continue;
		for(int j = i; j <= n; j+=i) prime[j] = i;
	}
	rep(i, 2, n) if(prime[i] == i) pvec.push_back(i);
}

bool exceed(ll x, ll y, ll m){return x >= m / y + 1;}
void mark(){ cout << "*" << endl; }
void yes(){ cout << "YES" << endl; }
void no(){ cout << "NO" << endl; }
ll floor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a >= 0) return a/b; else return -((-a+b-1)/b); }
ll ceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a >= 0) return (a+b-1)/b; else return -((-a)/b); }
ll modulo(ll a, ll b){ b = abs(b); return a - floor(a, b) * b; }
ll sgn(ll x){ if(x > 0) return 1; if(x < 0) return -1; return 0;}
ll gcd(ll a, ll b){if(b == 0) return a; return gcd(b, a%b);}
ll lcm(ll a, ll b){return a/gcd(a, b)*b;}
ll digitnum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret++; return ret;}
ll digitsum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret += x % b; return ret;}
string lltos(ll x){string ret; for(;x;x/=10) ret += x % 10 + '0'; reverse(ret.begin(), ret.end()); return ret;}
ll stoll(string &s){ll ret = 0; for(auto c : s) ret *= 10, ret += c - '0'; return ret;}
template<typename T>
void uniq(T &vec){ sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end());}

template<class S, class T> pair<S, T>& operator+=(pair<S,T> &s, const pair<S,T> &t){
	s.first += t.first, s.second += t.second;
	return s;
}
template<class S, class T> pair<S, T>& operator-=(pair<S,T> &s, const pair<S,T> &t){
	s.first -= t.first, s.second -= t.second;
	return s;
}
template<class S, class T> pair<S, T> operator+(const pair<S,T> &s, const pair<S,T> &t){
	return pair<S,T>(s.first+t.first, s.second+t.second);
}
template<class S, class T> pair<S, T> operator-(const pair<S,T> &s, const pair<S,T> &t){
	return pair<S,T>(s.first-t.first, s.second-t.second);
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	reps(i, vec) os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os;
}
template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	reps(i, vec) os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os;
}
template<typename T>
ostream& operator << (ostream& os, deque<T>& deq) {
	reps(i,  deq) os << deq[i] << (i + 1 == deq.size() ? "" : " "); return os;
}
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
template<typename T, typename U>
ostream& operator << (ostream& os, const pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
	for(typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end(); itr++) {
		os << "(" << itr->first << ", " << itr->second << ")";
		itr++; if(itr != map_var.end()) os << ","; itr--;
	}
	return os;
}
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
	for(typename set<T>::iterator itr = set_var.begin(); itr != set_var.end(); itr++) {
		os << *itr; ++itr; if(itr != set_var.end()) os << " "; itr--;
	}
	return os;
}
template<typename T>
ostream& operator << (ostream& os, multiset<T>& set_var) {
	for(typename multiset<T>::iterator itr = set_var.begin(); itr != set_var.end(); itr++) {
		os << *itr; ++itr; if(itr != set_var.end()) os << " "; itr--;
	}
	return os;
}
template<typename T>
void outa(T a[], ll s, ll t){rep(i, s, t){ cout << a[i]; if(i < t) cout << " ";}cout << endl;}
void dump_func(){cout << endl;}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
	cout << head;
	if(sizeof...(Tail) > 0) cout << " ";
	dump_func(std::move(tail)...);
}

ll n;
ll p = 997, m = p-1;
mint a[1005][1005];

ll find(ll p)
{
	rep(i, 2, inf){
		bool flag = true;
		rep(j, 1, p-2){
			if((p-1) % j) continue;
			flag &= (modpow(i, j) != mint(1));
		}
		if(flag) return i;
	}
	return 0;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll r = find(p);
	cin >> n;
	
	rep(i, 1, n){
		rep(j, 0, m-1) a[i][j] = modpow(mint(r), (i+j)%m);
	}
	
	outl(m, p);
	rep(i, 1, n){
		rep(j, 0, m-1){
			cout << a[i][j];
			if(j < m-1) cout << " ";
		}
		cout << endl;
	}
	
	/*rep(i, 1, n){
		rep(j, 0, m-1) assert(a[i][j].x >= 1 && a[i][j].x < p);
		
		set<ll> S;
		rep(j, 0, m-1) S.insert(a[i][j].x);
	}
	rep(i, 1, n){
		rep(j, 1, n){
			bool flag = false;
			rep(k, 0, m-1) flag |= (a[i][k] != a[j][k]);
			assert(i == j || flag);
			
			mint sum = 0;
			rep(k, 0, m-1) sum += a[i][k] * a[j][k];
			assert(sum == 0);
		}
	}*/
	
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 7392
final_rank: 14

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

#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define uniq(a) (a).erase(unique(all(a)), (a).end())
#define SZ(x) ((int)(x).size())
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define vsum(x) reduce(all(x))
#define vmax(a) *max_element(all(a))
#define vmin(a) *min_element(all(a))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define mp make_pair
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vc = vector<char>;
using VVi = vector<vector<int>>;
using VVl = vector<vector<ll>>;
using VVc = vector<vector<char>>;
template <typename T, typename U> using P = pair<T, U>;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
constexpr ll inf = 1000000000ll;
constexpr ll INF = 4000000004000000000LL;
constexpr ld eps = 1e-15;
constexpr ld PI = 3.141592653589793;
constexpr int popcnt(ull x) { return __builtin_popcountll(x); }
template <typename T> using mat = vector<vector<T>>;
constexpr ll dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr ll dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
constexpr ll sign(ll a) { return (a > 0) - (a < 0); }
constexpr ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
constexpr ll cdiv(ll a, ll b) { return -fdiv(-a, b); }
constexpr ull bit(int n) { return 1ull << n; }
template <typename T> constexpr T mypow(T x, ll n) {
    T ret = 1;
    while (n) {
        if (n & 1) ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}
constexpr ll modpow(ll x, ll n, ll mod) {
    ll ret = 1;
    while (n) {
        if (n & 1) ret *= x;
        x *= x;
        n >>= 1;
        x %= mod;
        ret %= mod;
    }
    return ret;
}
template <typename T> T xor64(T lb, T ub) {
    static ull x = 88172645463325252ull;
    x ^= x << 7;
    return lb + (x ^= x >> 9) % (ub - lb);
}
constexpr ll safemod(ll x, ll mod) { return (x % mod + mod) % mod; }
template <typename T> constexpr T sq(const T &a) { return a * a; }
template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename U> bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <typename T, typename U> bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) {
    os << "(" << a.first << ", " << a.second << ")";
    return os;
}
template <typename T, typename U, typename V> ostream &operator<<(ostream &os, const tuple<T, U, V> &a) {
    os << "(" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); ++itr) os << *itr << (next(itr) != a.end() ? ", " : "");
    os << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); ++itr) os << *itr << (next(itr) != a.end() ? ", " : "");
    os << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); ++itr) os << *itr << (next(itr) != a.end() ? ", " : "");
    os << ")";
    return os;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); ++itr) os << *itr << (next(itr) != a.end() ? ", " : "");
    os << ")";
    return os;
}
template <typename T> void print(const T &a) { cout << a << endl; }
template <typename T> void print(const vector<T> &v) {
    for (auto &e : v) cout << e << " ";
    cout << endl;
}
template <typename T> void scan(vector<T> &a) {
    for (auto &i : a) cin >> i;
}
struct timer {
    clock_t start_time;
    void start() { start_time = clock(); }
    int lap() {
        // return x ms.
        return (clock() - start_time) * 1000 / CLOCKS_PER_SEC;
    }
};
template <typename T = int> struct Edge {
    int from, to;
    T cost;
    int idx;

    Edge() = default;

    Edge(int from, int to, T cost = 1, int idx = -1) : from(from), to(to), cost(cost), idx(idx) {}

    operator int() const { return to; }
};
template <typename T = int> struct Graph {
    vector<vector<Edge<T>>> g;
    int es;

    Graph() = default;

    explicit Graph(int n) : g(n), es(0) {}

    size_t size() const { return g.size(); }

    void add_directed_edge(int from, int to, T cost = 1) { g[from].emplace_back(from, to, cost, es++); }

    void add_edge(int from, int to, T cost = 1) {
        g[from].emplace_back(from, to, cost, es);
        g[to].emplace_back(to, from, cost, es++);
    }

    void read(int M, int padding = -1, bool weighted = false, bool directed = false) {
        for (int i = 0; i < M; i++) {
            int a, b;
            cin >> a >> b;
            a += padding;
            b += padding;
            T c = T(1);
            if (weighted) cin >> c;
            if (directed)
                add_directed_edge(a, b, c);
            else
                add_edge(a, b, c);
        }
    }
};
#ifdef ONLINE_JUDGE
#define dump(...) (void(0))
#else
void debug() { cerr << endl; }
template <typename Head, typename... Tail> void debug(Head &&head, Tail &&... tail) {
    cerr << head;
    if (sizeof...(Tail)) cerr << ", ";
    debug(tail...);
}
#define dump(...) cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ", debug(__VA_ARGS__)
#endif
struct rep {
    struct itr {
        ll v;
        itr(ll v) : v(v) {}
        void operator++() { ++v; }
        ll operator*() const { return v; }
        bool operator!=(itr i) const { return v < *i; }
    };
    ll l, r;
    rep(ll l, ll r) : l(l), r(r) {}
    rep(ll r) : rep(0, r) {}
    itr begin() const { return l; };
    itr end() const { return r; };
};
struct per {
    struct itr {
        ll v;
        itr(ll v) : v(v) {}
        void operator++() { --v; }
        ll operator*() const { return v; }
        bool operator!=(itr i) const { return v > *i; }
    };
    ll l, r;
    per(ll l, ll r) : l(l), r(r) {}
    per(ll r) : per(0, r) {}
    itr begin() const { return r - 1; };
    itr end() const { return l - 1; };
};
struct io_setup {
    static constexpr int PREC = 20;
    io_setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} iOS;
template <ll MOD = 1000000007> struct modint {
    ll val;
    modint(ll val = 0) : val(val >= 0 ? val % MOD : (MOD - (-val) % MOD) % MOD) {}
    static ll mod() { return MOD; }
    modint inv() const {
        ll a = val, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return modint(u);
    }
    modint pow(ll k) const {
        modint ret = 1, mul = val;
        while (k) {
            if (k & 1) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }
    modint &operator+=(const modint &a) {
        if ((val += a.val) >= MOD) val -= MOD;
        return *this;
    }
    modint &operator-=(const modint &a) {
        if ((val += MOD - a.val) >= MOD) val -= MOD;
        return *this;
    }
    modint &operator*=(const modint &a) {
        (val *= a.val) %= MOD;
        return *this;
    }
    modint &operator/=(const modint &a) { return *this *= a.inv(); }
    bool operator==(const modint &a) const { return val == a.val; }
    bool operator!=(const modint &a) const { return rel_ops::operator!=(*this, a); }
    modint operator+() const { return *this; }
    modint operator-() const { return modint(-val); }
    friend modint operator+(const modint &a, const modint &b) { return modint(a) += b; }
    friend modint operator-(const modint &a, const modint &b) { return modint(a) -= b; }
    friend modint operator*(const modint &a, const modint &b) { return modint(a) *= b; }
    friend modint operator/(const modint &a, const modint &b) { return modint(a) /= b; }
    friend istream &operator>>(istream &is, modint &a) {
        ll val;
        is >> val;
        a = modint(val);
        return is;
    }
    friend ostream &operator<<(ostream &os, const modint &a) { return os << a.val; }
};

constexpr uint32_t PrimitiveRoot(uint32_t mod) {
    using u64 = uint64_t;
    if (mod == 2) return 1;
    u64 ds[32] = {};
    int idx = 0;
    u64 m = mod - 1;
    for (u64 i = 2; i * i <= m; ++i) {
        if (m % i == 0) {
            ds[idx++] = i;
            while (m % i == 0) m /= i;
        }
    }
    if (m != 1) ds[idx++] = m;

    uint32_t pr = 2;
    while (1) {
        int flg = 1;
        for (int i = 0; i < idx; ++i) {
            u64 a = pr, b = (mod - 1) / ds[i], r = 1;
            while (b) {
                if (b & 1) r = r * a % mod;
                a = a * a % mod;
                b >>= 1;
            }
            if (r == 1) {
                flg = 0;
                break;
            }
        }
        if (flg == 1) break;
        ++pr;
    }
    return pr;
}
using mint = modint<1999>;
int main() {
    ll n;
    cin >> n;
    ll p = 1999, m = 999;
    mint a = mint(PrimitiveRoot(p));
    cout << m << " " << p << endl;
    VV<mint> ans(n, V<mint>(m));
    for (ll i : rep(n)) {
        for (ll j : rep(m)) { ans[i][j] = a.pow(i + j); }
    }
    for (ll i : rep(n)) {
        for (ll j : rep(m)) cout << ans[i][j] << " ";
        cout << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 5364
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll MOD=1000000007;
// ll MOD=998244353;
constexpr ll mod=998244353;
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};


int main() {
    int n;
    cin >> n;
    int p=100000;
    while(true){
        bool t=true;
        for (int i=2;i*i<=p;i++){
            if (p%i==0) t=false;
        }
        if (t) break;
        p--;
    }
    int u=1;
    vector<int> ans;
    while(true){
        vector<int> aans;
        int c=u;
        ll k=rand()%(p-1)+1;
        ll y=0;
        while(true){
            if (c%2==1) {
                y+=k*k;
                aans.push_back(k);
            }
            k=rand()%(p-1)+1;
            c/=2;
            if (c==0) break;
        }
        if (y%p==0) {
            ans=aans;
            break;
        }
        u++;
    }
    vector<int> r;
    cout << ans.size() << " " << p << endl;
    rep(i,n){
        rep(j,ans.size()-1) cout << ans[j] << " ";
        cout << ans[ans.size()-1] << endl;
        rep(j,ans.size()){
            ans[j]=(ans[j]*2)%p;
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3424
final_rank: 1

code_snippet: // expand bits/stdc++.h
// C
#include <cassert>
#include <ccomplex>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <cinttypes>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctgmath>
#include <ctime>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <chrono>
#include <codecvt>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(42);
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 20;
const ll MOD = 99991;
ll M = 301;
uniform_int_distribution<> myrand(1, MOD - 1);

vector<ll> inv(MOD + 1);

ll mpow(ll base, ll exp)
{
    if (exp == 0)
        return 1ll;
    ll prev = mpow(base, exp / 2);
    if (exp % 2 == 0)
    {
        return (prev * prev) % MOD;
    }
    else
    {
        return (((prev * prev) % MOD) * base) % MOD;
    }
}

ll dot(vector<ll> &a, vector<ll> &b)
{
    assert(a.size() == b.size());
    int n = a.size();
    ll ret = 0;
    rep(i, M)
    {
        ret += a[i] * b[i];
        ret %= MOD;
    }
    return ret;
}

bool check_row(vector<ll> &v, int m)
{
    map<ll, bool> used;
    rep(i, m)
    {
        if (used[v[i]] || v[i] < 1 || v[i] >= MOD)
        {
            return false;
        }
        used[v[i]] = true;
    }
    return true;
}

void check(vector<vector<ll>> &mat, int n, int m)
{
    rep(i, n) rep(j, i + 1, n)
    {
        // //cerr << mat[i][0] << " " << mat[j][0] << endl;

        if (dot(mat[i], mat[j]) != 0 || mat[i] == mat[j])
        {
            //cerr << i << " " << j << endl;
            //cerr << "ERROR!!!!!" << endl;
            exit(1);
        }
    }
    rep(i, n)
    {
        map<ll, bool> used;
        // //cerr << "line " << i << endl;
        rep(j, m)
        {
            if (used[mat[i][j]] || mat[i][j] < 1 || mat[i][j] >= MOD)
            {
                //cerr << i << endl;
                //cerr << "2 ERROR!!!!!" << endl;
                //cerr << mat[i][j] << endl;
                //cerr << used[mat[i][j]] << endl;
                exit(1);
            }
            used[mat[i][j]] = true;
        }
    }
}

void init_row(vector<ll> &v, int m)
{
    map<ll, bool> used;
    rep(i, m)
    {
        v[i] = myrand(mt);
    }
}

void Orthogonalize(vector<ll> &v, int cur, vector<vector<ll>> &mat, int m, vector<ll> &ys)
{
    auto old = v;
    rep(i, cur)
    {
        ll x = dot(mat[i], old);
        ll y = ys[i];
        ll z = (x * inv.at(y)) % MOD;
        rep(j, m)
        {

            v[j] -= z * mat[i][j];
            while (v[j] < 0)
                v[j] += MOD;
            v[j] %= MOD;
        }
    }
}

void GramSchmidt(vector<vector<ll>> &mat, int n, int m)
{
    rep(i, 1, n)
    {
        auto old = mat[i];
        rep(k, i)
        {
            ll x = dot(mat[k], old);
            ll y = dot(mat[k], mat[k]);
            ll z = (x * inv.at(y)) % MOD;
            rep(j, m)
            {

                mat[i][j] -= z * mat[k][j];
                while (mat[i][j] < 0)
                    mat[i][j] += MOD;
                mat[i][j] %= MOD;
            }
        }
    }
}

int main()
{

    inv[0] = -1;
    rep(i, 1, MOD)
    {
        inv[i] = mpow(i, MOD - 2);
        assert((inv[i] * i) % MOD == 1);
    }

    int N;
    cin >> N;
    if (N == 2)
    {
        cout << 2 << " " << 5 << endl;
        cout << 3 << " " << 4 << endl;
        cout << 2 << " " << 1 << endl;
        return 0;
    }
    cout << M << " " << MOD << endl;
    vector<vector<ll>> mat(N, vector<ll>(M));
    vector<ll> ys(N);
    ll cur = 1;
    rep(i, N)
    {
        //cerr << i << endl;
        do
        {
            init_row(mat[i], M);
            Orthogonalize(mat[i], i, mat, M, ys);
        } while (check_row(mat[i], M) == false);
        ys[i] = dot(mat[i], mat[i]);
    }
    //GramSchmidt(mat, N, M);
    rep(i, N)
    {
        rep(j, M)
        {
            cout << mat[i][j];
            if (j == M - 1)
                cout << '\n';
            else
                cout << " ";
        }
    }
    // check(mat, N, M);
    return 0;
}
accuracy: 0.041666666666666664
time_ms: 10
memory_kb: 3692
final_rank: 16

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

#include <utility>

#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {

namespace internal {

constexpr long long safe_mod(long long x, long long m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}

struct barrett {
    unsigned int _m;
    unsigned long long im;

    explicit barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}

    unsigned int umod() const { return _m; }

    unsigned int mul(unsigned int a, unsigned int b) const {

        unsigned long long z = a;
        z *= b;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(z, im, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
        unsigned int v = (unsigned int)(z - x * _m);
        if (_m <= v) v += _m;
        return v;
    }
};

constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
    if (m == 1) return 0;
    unsigned int _m = (unsigned int)(m);
    unsigned long long r = 1;
    unsigned long long y = safe_mod(x, m);
    while (n) {
        if (n & 1) r = (r * y) % _m;
        y = (y * y) % _m;
        n >>= 1;
    }
    return r;
}

constexpr bool is_prime_constexpr(int n) {
    if (n <= 1) return false;
    if (n == 2 || n == 7 || n == 61) return true;
    if (n % 2 == 0) return false;
    long long d = n - 1;
    while (d % 2 == 0) d /= 2;
    constexpr long long bases[3] = {2, 7, 61};
    for (long long a : bases) {
        long long t = d;
        long long y = pow_mod_constexpr(a, t, n);
        while (t != n - 1 && y != 1 && y != n - 1) {
            y = y * y % n;
            t <<= 1;
        }
        if (y != n - 1 && t % 2 == 0) {
            return false;
        }
    }
    return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);

constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};

    long long s = b, t = a;
    long long m0 = 0, m1 = 1;

    while (t) {
        long long u = s / t;
        s -= t * u;
        m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b


        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}

constexpr int primitive_root_constexpr(int m) {
    if (m == 2) return 1;
    if (m == 167772161) return 3;
    if (m == 469762049) return 3;
    if (m == 754974721) return 11;
    if (m == 998244353) return 3;
    int divs[20] = {};
    divs[0] = 2;
    int cnt = 1;
    int x = (m - 1) / 2;
    while (x % 2 == 0) x /= 2;
    for (int i = 3; (long long)(i)*i <= x; i += 2) {
        if (x % i == 0) {
            divs[cnt++] = i;
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    if (x > 1) {
        divs[cnt++] = x;
    }
    for (int g = 2;; g++) {
        bool ok = true;
        for (int i = 0; i < cnt; i++) {
            if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
                ok = false;
                break;
            }
        }
        if (ok) return g;
    }
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);

unsigned long long floor_sum_unsigned(unsigned long long n,
                                      unsigned long long m,
                                      unsigned long long a,
                                      unsigned long long b) {
    unsigned long long ans = 0;
    while (true) {
        if (a >= m) {
            ans += n * (n - 1) / 2 * (a / m);
            a %= m;
        }
        if (b >= m) {
            ans += n * (b / m);
            b %= m;
        }

        unsigned long long y_max = a * n + b;
        if (y_max < m) break;
        n = (unsigned long long)(y_max / m);
        b = (unsigned long long)(y_max % m);
        std::swap(m, a);
    }
    return ans;
}

}  // namespace internal

}  // namespace atcoder

using namespace std;
using namespace atcoder::internal;
#define rep(i,n) for(int i = 0; i < int(n); ++i)
#define rrep(i,n) for(int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;


#include <cassert>
#include <numeric>
#include <type_traits>

#ifdef _MSC_VER
#include <intrin.h>
#endif


#include <cassert>
#include <numeric>
#include <type_traits>

namespace atcoder {

namespace internal {

#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;

template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;

template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;

#else

template <class T> using is_integral = typename std::is_integral<T>;

template <class T>
using is_signed_int =
    typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<is_integral<T>::value &&
                                  std::is_unsigned<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
                                              std::make_unsigned<T>,
                                              std::common_type<T>>::type;

#endif

template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;

template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;

template <class T> using to_unsigned_t = typename to_unsigned<T>::type;

}  // namespace internal

}  // namespace atcoder


namespace atcoder {

namespace internal {

struct modint_base {};
struct static_modint_base : modint_base {};

template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;

}  // namespace internal

template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
    using mint = static_modint;

  public:
    static constexpr int mod() { return m; }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }

    static_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    static_modint(T v) {
        long long x = (long long)(v % (long long)(umod()));
        if (x < 0) x += umod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    static_modint(T v) {
        _v = (unsigned int)(v % umod());
    }

    unsigned int val() const { return _v; }

    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }

    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v -= rhs._v;
        if (_v >= umod()) _v += umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        unsigned long long z = _v;
        z *= rhs._v;
        _v = (unsigned int)(z % umod());
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }

    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }

    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        if (prime) {
            assert(_v);
            return pow(umod() - 2);
        } else {
            auto eg = internal::inv_gcd(_v, m);
            assert(eg.first == 1);
            return eg.second;
        }
    }

    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }

  private:
    unsigned int _v;
    static constexpr unsigned int umod() { return m; }
    static constexpr bool prime = internal::is_prime<m>;
};

template <int id> struct dynamic_modint : internal::modint_base {
    using mint = dynamic_modint;

  public:
    static int mod() { return (int)(bt.umod()); }
    static void set_mod(int m) {
        assert(1 <= m);
        bt = internal::barrett(m);
    }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }

    dynamic_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        long long x = (long long)(v % (long long)(mod()));
        if (x < 0) x += mod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        _v = (unsigned int)(v % mod());
    }

    unsigned int val() const { return _v; }

    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }

    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v += mod() - rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        _v = bt.mul(_v, rhs._v);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }

    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }

    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        auto eg = internal::inv_gcd(_v, mod());
        assert(eg.first == 1);
        return eg.second;
    }

    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }

  private:
    unsigned int _v;
    static internal::barrett bt;
    static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt(998244353);

using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;

namespace internal {

template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;

template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;

template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};

template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;

}  // namespace internal

}  // namespace atcoder

using namespace atcoder;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    constexpr int p = 607;
    constexpr int r = primitive_root<p>;
    constexpr int m = 606;
    int n;
    cin >> n;
    using mint = static_modint<p>;
    vector<vector<mint>> a(n, vector<mint>(m));
    cout << m << ' ' << p << '\n';
    rep(i, n) rep(j, m) a[i][j] = mint::raw(r).pow(i + j);
    rep(i, n) rep(j, m) cout << a[i][j].val() << " \n"[j + 1 == m];
}
accuracy: 1
time_ms: 10
memory_kb: 3696
final_rank: 3

code_snippet: #include <algorithm>
#include <cassert>
#include <iostream>
using namespace std;

#include <iostream>
#include <vector>
using namespace std;

bool check(const vector<vector<int>> &A, int p){
  const int n = A.size();
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      int t = 0;
      for(size_t k = 0; k < A[i].size(); ++k){
        t += A[i][k]*A[j][k]%p;
        t %= p;
      }
      if(t) return false;
    }
  }
  return true;
}

#include <iostream>
#include <vector>
using namespace std;

template<typename T>
T power(T x, long long k, long long mod){
  T ret{1};
  x %= mod;
  while(k > 0){
    if(k&1) ret *= x, ret %= mod;
    x *= x, x %= mod;
    k /= 2;
  }
  return ret;
}

long long primitive_root(long long prime){
  vector<long long> fac;
  long long v = prime-1;
  for(long long pp = 2; pp*pp <= v; ++pp){
    long long e = 0;
    while(v%pp == 0){
      ++e;
      v /= pp;
    }
    if(e)
      fac.emplace_back(pp);
  }
  if(v > 1)
    fac.emplace_back(v);

  for(long long g = 2; g < prime; ++g){
    if(power(g,(prime-1),prime) != 1){
      return -1;
    }
    bool ok = true;
    for(long long pp : fac){
      if(power(g,(prime-1)/pp,prime) == 1){
        ok = false;
        break;
      }
    }
    if(ok)
      return g;
  }
  return -1;
}


int main(){
  int n;
  cin >> n;
  const int p = 997, r = primitive_root(p);
  assert(p <= 100000);
  const int m = p-1;
  assert(m <= 1000);

  vector<vector<int>> A(n,vector<int>(m));
  A[0][0] = 1;
  for(int i = 1; i < m; ++i)
    A[0][i] = (A[0][i-1]*r)%p;

  for(int i = 1; i < n; ++i){
    for(int j = 0; j < m; ++j){
      A[i][j] = A[0][(j+i)%m];
    }
  }

  assert(check(A,p));
  for(auto v : A){
    for(auto e : v){
      assert(e < p and e > 0);
    }
  }

  auto B = A;
  sort(B.begin(),B.end());
  B.erase(unique(B.begin(),B.end()),B.end());
  assert(B.size() == n);

  for(auto v : B){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    assert(v.size() == m);
  }

  cout << m << " " << p << "\n";
  for(auto v : A){
    for(int i = 0; i < m; ++i)
      cout << v[i] << (i+1 < m ? " " : "\n");
  }
}
accuracy: 1
time_ms: 550
memory_kb: 5724
final_rank: 15

code_snippet: #include <bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

ll mod = 1e9 + 7;


int main() {
	ll N;
	cin >> N;
	ll M, P;
	P =997;
	M = 996;
	vector<vll> A(N+1, vll(M));
	rep(i, M)A[0][i] = i + 1;
	
	ll n=1;
	set<ll> S;
    rep(a,P){
        if(S.count(a))continue;
        rep(b,a){
            if(S.count(b))continue;
            rep(c,b){
                if(S.count(c))continue;
                if(a*b*c==0)continue;
                if(((a-b)*(a-b)+(b-c)*(b-c)+(c-a)*(c-a))%P==0){
                    
                    S.insert(a);
                    S.insert(b);
                    S.insert(c);

                    rep(m,M){
						if(m==a){
							A[n][m]=A[0][b];
						}
						else if(m==b){
							A[n][m]=A[0][c];
						}
						else if(m==c){
							A[n][m]=A[0][a];
						}
						else{
							A[n][m]=A[0][m];
						}
					}
					n++;
					if(n==N)break;
                }
				if(n==N)break;
            }
			if(n==N)break;
        }
		if(n==N)break;
    }

	cout<<M<<" "<<P<<endl;
	rep(i, N) {
		rep(m, M) {
			cout << A[i][m] << " ";
		}
		cout << endl;
	}

	//cout<<A[1][0]<<" "<<A[1][1]<<" "<<A[1][1007]<<A[1][1006]<<endl;
	/*rep(i,N)rep(j,N){
		ll S=0;
		bool C=(i==j);
		rep(m,M){
			S+=A[i][m]*A[j][m];
			if(A[i][m]!=A[j][m])C=true;
		}
		if(!C||S%P!=0){
			cout<<i<<" "<<j<<endl;
			cout<<"CC"<<endl;
			return 0;
		}
	}
	rep(i,N){
		set<ll> T;
		rep(m,M){
			if(T.count(A[i][m])){
				cout<<i<<"ER"<<endl;
				return 0;
			}
			T.insert(A[i][m]);
		}
	}
	*/


}
accuracy: 1
time_ms: 170
memory_kb: 5712
final_rank: 11

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
ll mod=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}



//  rainy ~ 雨に打たれて ~
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll P=3001;
	ll g=2744;
	ll M=1000;
	vector<ll> p(M,1);
	rep(i,M-1) p[i+1]=(p[i]*g)%P;
	int N;
	cin>>N;
	vector<vector<ll>> ans(N,vector<ll>(M));
	rep(i,N) rep(j,M) ans[i][j]=(p[(i+j)%M]);
	rep(i,N) rep(j,N){
		ll X=0;
		rep(k,M) X+=(ans[i][k]*ans[j][k])%P;
		X%=P;
		assert(X==0);
	}
	cout<<M<<" "<<P<<"\n";
	rep(i,N){
		rep(j,M){
			if(j!=0) cout<<" ";
			cout<<ans[i][j];
		}
		cout<<"\n";
	}
}
accuracy: 1
time_ms: 100
memory_kb: 5304
final_rank: 10

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

using namespace std;

// using mint = long double;
// using mint = atcoder::modint998244353;
// using mint = atcoder::modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;
typedef pair<ll, vector<ll>> Pd;

const ll INF = 3e18;
const ll fact_table = 8000050;

/*
priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
// priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
*/

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};

//↓,→,↑,←

#define p(x) cout << x << "\n";
#define el cout << "\n";
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)
#define sorti(v) sort(all(v))
#define sortd(v)                                                               \
    sort(all(v));                                                              \
    reverse(all(v));
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言

const ll mod = 1000000007ll;
// const ll mod = 998244353ll;

ll mypow(ll a, ll b, ll m = mod) {
    ll x = 1;
    while (b) {
        while (!(b & 1)) {
            (a *= a) %= m;
            b >>= 1;
        }
        (x *= a) %= m;
        b--;
    }
    return x;
}
vec rv(ll read) {
    vec res(read);
    for (int i = 0; i < read; i++) {
        cin >> res[i];
    }
    return res;
}

vec fact, rfact;

void c3_init() {
    fact.resize(fact_table + 5);
    rfact.resize(fact_table + 5);
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}

ll c3(ll n, ll r) {
    if (n < r) return 0ll;
    return fact[n] * rfact[r] % mod * rfact[n - r] % mod;
}

bool icpc = false;
bool multicase = false;

// 配列の長さ足りてますか？
ll n, k, x, y;
string s, t;

const ll m = 512;

bool solve() {
    cin >> n;
    ll m = 300;
    ll p = 601;
    mat a(m, vec(m));
    rep(i, m) {
        rep(j, m) {
            a[i][j] = (i + 1) * (j + 1) % p;
        }
    }
    bool valid = true;
    rep(i, m) {
        rep(j, m) {
            ll sum = 0;
            rep(k, m) {
                sum += (a[i][k] * a[j][k]) % p;
                sum %= p;
            }
            if (sum > 0) valid = false;
        }
    }
    rep(i, n) {
        rep(j, n) {
            ll sum = 0;
            rep(k, m) {
                sum += a[i][k] * a[j][k] % p;
                sum %= p;
            }
            assert(sum == 0);
        }
    }
    pe(m);
    p(p);
    rep(i, n) {
        rep(j, m) {
            pe(a[i][j]);
        }
        el;
    }

    return true;
}

/*







*/

int main() {

    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);

    if (icpc) {
        while (solve())
            ;
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // cout << "Case #" << testcase << ": ";
        solve();
        testcase++;
    }

    // solve();
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 4144
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
//const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T,typename U>T & chmax(T &a,const U &b){if(a<b){a=b;} return a;}
template<typename T,typename U>T & chmin(T &a,const U &b){if(b<a){a=b;} return a;}

const ll MOD=983;
const ll SZ=MOD-1;

ll mod_pow(ll a,ll x){
  ll ret=1;
  while(x>0){
    if(x&1){ret*=a; ret%=MOD;}
    (a*=a)%=MOD;
    x>>=1;
  }
  return ret;
}

bool prm_root(ll a){
  if(a==0 || mod_pow(a,SZ/2)==1 || mod_pow(a,SZ/491)==1){return false;}
  return true;
}

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

  ll N;
  cin>>N;
  vector<vector<ll>> A;
  vector<ll> tmp(SZ);
  
  int k=5,l=0;
  
  while((int)A.size()<N){
    tmp[0]=mod_pow(k,l);
    for(int i=1;i<SZ;i++){tmp[i]=tmp[i-1]*k; tmp[i]%=MOD;}
    A.push_back(tmp);
    l++;
  }

  cout<<SZ<<" "<<MOD<<endl;
  for(auto &I:A){cout<<I<<endl;}
  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5380
final_rank: 7

code_snippet: #include "bits/stdc++.h"

using namespace std;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

int p[100000] = {};

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

	for (int i = 2; i < 100000; i++) {
		if (p[i] == 0) {
			p[i] = i;
			for (int j = i * 2; j < 100000; j += i) {
				p[j] = i;
			}
		}
	}
	int M = 0, P = 0;
	for (int i = 2; i < 100000; i++) {
		if (p[i - 1] > 600 && p[i] == i) {
			M = p[i - 1];
			P = i;
			break;
		}
	}
	cout << M << " " << P << endl;
	int g = 0;
	for (int i = 2; i < P; i++) {
		set<int>s;
		for (int j = 0; j < P - 1; j++) {
			s.insert(power(i, j, P));
		}
		if (s.size() == P - 1) {
			g = i;
			break;
		}
	}
	long long phi = power(g, (P - 1) / M, P);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cout << power(phi, (i + 1) * j, P) << " ";
		}
		cout << endl;
	}
}
accuracy: 1
time_ms: 40
memory_kb: 3896
final_rank: 4

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

using namespace std;

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;
    u64 a;

    public:

    template <class INT>
    constexpr modint(const INT x = 0) noexcept : a(x >= 0 ? x % Modulus : x % int_fast64_t(Modulus) + Modulus) {}
    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
        rhs *= rhs;
        exp /= 2;
        }
        return *this;
    }

    constexpr bool operator<(const modint& rhs) const noexcept {return this->a < rhs.a;}
    constexpr bool operator>(const modint& rhs) const noexcept {return rhs < *this;}
    constexpr bool operator<=(const modint& rhs) const noexcept {return !(*this > rhs);}
    constexpr bool operator>=(const modint& rhs) const noexcept {return !(*this < rhs);}
    constexpr bool operator==(const modint& rhs) const noexcept {return this->a == rhs.a;}
    constexpr bool operator!=(const modint& rhs) const noexcept {return !(*this == rhs);}

    constexpr modint& operator++() noexcept {
        *this += modint(1);
        return *this;
    }
    constexpr modint operator++(int) noexcept {
        modint tmp(*this);
        ++(*this);
        return tmp;
    }
    constexpr modint& operator--() noexcept {
        *this -= modint(1);
        return *this;
    }
    constexpr modint operator--(int) noexcept {
        modint tmp(*this);
        --(*this);
        return tmp;
    }
    constexpr modint operator-() const noexcept {
        return modint(0) - *this;
    }

    template <std::uint_fast64_t M>
    friend constexpr std::ostream& operator<<(std::ostream& os, const modint<M>& rhs) noexcept {
        os << rhs.a;
        return os;
    }
    template <std::uint_fast64_t M>
    friend constexpr std::istream& operator>>(std::istream& is, modint<M>& rhs) noexcept {
        int64_t tmp;
        is >> tmp;
        rhs = modint(tmp);
        return is;
    }

    constexpr modint pow(const u64 k) const noexcept {
        if (k == 0)
            return 1;
        if (k % 2 == 0){
            modint res = pow(k / 2);
            return res * res;
        }
        return pow(k - 1) * modint(*this);
    }

    template <typename T>
    operator const T (){return a;}

};

int main(){
    constexpr int64_t p = 95713;
    constexpr int64_t m = 997;  // m is prime
    constexpr int64_t g = 5;
    using mint = modint<p>;

    mint phi = mint(g).pow((p - 1) / m);

    int n;
    cin >> n;
    vector<vector<mint>> V(n, vector<mint>(m));
    for (int i = 1; i <= n; i++){
        for (int j = 0; j < m; j++)
            V[i - 1][j] = phi.pow(i * j);
    }

    cout << m << " " << p << endl;
    for (const auto &v: V){
        for (const auto &u: v)
            cout << u << " " ;
        cout << endl;
    }
}
accuracy: 1
time_ms: 40
memory_kb: 5484
final_rank: 9

code_snippet: #include "bits/stdc++.h"

using namespace std;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

int p[100000] = {};

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

	for (int i = 2; i < 100000; i++) {
		if (p[i] == 0) {
			p[i] = i;
			for (int j = i * 2; j < 100000; j += i) {
				p[j] = i;
			}
		}
	}
	int M = 0, P = 0;
	for (int i = 2; i < 100000; i++) {
		if (p[i - 1] > 650 && p[i] == i) {
			M = p[i - 1];
			P = i;
			break;
		}
	}
	cout << M << " " << P << endl;
	int g = 0;
	for (int i = 2; i < P; i++) {
		set<int>s;
		for (int j = 0; j < P - 1; j++) {
			s.insert(power(i, j, P));
		}
		if (s.size() == P - 1) {
			g = i;
			break;
		}
	}
	long long phi = power(g, (P - 1) / M, P);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cout << power(phi, (i + 1) * j, P) << " ";
		}
		cout << endl;
	}
}
accuracy: 1
time_ms: 40
memory_kb: 3932
final_rank: 5