Problem:
Problem A:
Strange String Manipulation
A linear congruential generator produces a series R(⋅) of pseudo-random numbers by the following for-
mulas:
where
S
,
A
,
C
, and
M
are all parameters. In this problem, 0 ≤
S
,
A
,
C
≤ 15 and
M
= 256.
Now suppose we have some input string
I
(⋅), where each character in the string is an integer between 0
and (
M
- 1). Then, using the pseudo-random number series
R
(⋅), we obtain another string
O
(⋅) as the
output by the following formula:
Your task is to write a program that shows the parameters
S
,
A
, and
C
such that the information entropy of the output string
O
(⋅) is minimized. Here, the information entropy
H
is given by the following formula:
where
N
is the length of the string and #(
x
) is the number of occurences of the alphabet
x
.
Input
The input consists of multiple datasets. Each dataset has the following format:
N
I
(1)
I
(2) ...
I
(
N
)
N
does not exceed 256.
The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed.
Output
For each dataset, print in a line the values of the three parameters
S
,
A
, and
C
separated by a single space. If more than one solution gives the same minimum entropy, choose the solution with the smallest
S
,
A
, and then
C
.
Sample Input
5
5 4 3 2 1
5
7 7 7 7 7
10
186 8 42 24 154 40 10 56 122 72
0
Output for the Sample Input
0 1 1
0 0 0
8 7 14

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

ll mod = 998244353;
const ll INF = 1e18;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if(argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    while(1) {
        ll n;
        cin >> n;
        if(n == 0) break;

        vector<ll> v(n);
        for(auto& x : v) cin >> x;

        ll m = 256;
        a3 ans = {0, 0, 0};
        using ld = long double;
        ld mn = INF;
        const ld eps = 1e-8;
        for(int s = 0; s <= 15; s++) {
            for(int a = 0; a <= 15; a++) {
                for(int c = 0; c <= 15; c++) {
                    vector<ll> o(256, 0);
                    ll r = s;
                    for(int i = 0; i < n; i++) {
                        r = (a * r + c) % m;
                        o[(r + v[i]) % m]++;
                    }
                    ld sum = 0;
                    for(auto& x : o) {
                        ld div = (ld)x / (ld)n;
                        if(div) sum -= div * log(div);
                    }
                    if(mn > sum + eps) {
                        ans = {s, a, c};
                        mn = sum;
                    }
                }
            }
        }
        cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 3584
final_rank: 12

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  const int mod = 256;
  const ld eps = 1e-9;
  while(1){
    int n;cin >> n;
    if(!n)break;
    vi l(n);cin >> l;
    tuple<int,int,int> res = {MOD,MOD,MOD};
    ld mn = MOD;
    rep(S,0,16)rep(A,0,16)rep(C,0,16){
      vi R(n+1);
      R[0] = S;
      rep(i,0,n)R[i+1] = (R[i]*A + C)%mod;
      R.erase(R.begin());
      vi cnt(256);
      rep(i,0,n)cnt[(l[i] + R[i])%mod]++;
      ld H = 0;
      rep(i,0,256)if(cnt[i])H -= 1.0l*cnt[i]/n*log10(1.0l*cnt[i]/n);
      if(H + eps <= mn){
        mn = H;
        auto &[s,a,c] = res;
        s = S;a = A;c = C;
      }
    }
    auto &[s,a,c] = res;
    cout << s << " " << a << " " << c << "\n";
  }

  

  return 0;
}
accuracy: 1
time_ms: 330
memory_kb: 3456
final_rank: 8

code_snippet: #include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>

using namespace std;

const int N = 333;
const int mod = 256;
const double eps = 1e-8;
int n;
int p[N], q[N];
int cnt[N];

void solve() {
	int s, a, c, x, y, z;
	double r = 1e10;
	for (s = 0; s <= 15; ++s) {
		for (a = 0; a <= 15; ++a) {
			for (c = 0; c <= 15; ++c) {
				memset(cnt, 0, sizeof(cnt));
				q[0] = s;
				for (int i = 1; i <= n; ++i) {
					q[i] = (q[i - 1] * a + c) % mod;
					++cnt[(p[i] + q[i]) % mod];
				}
				double h = 0;
				for (int i = 0; i < 256; ++i) {
					if (cnt[i]) {
						double u = (double)cnt[i] / (double)n * log((double)cnt[i] / (double)n);
						h -= u;
					}
				}
				if (h < r - eps) {
					r = h;
					x = s, y = a, z = c;
				}
			}
		}
	}
	printf("%d %d %d\n", x, y, z);
}

int main() {
	while (scanf("%d", &n) != EOF && n) {
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &p[i]);
		}
		solve();
	}
}
accuracy: 1
time_ms: 190
memory_kb: 3836
final_rank: 15

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
using namespace std;

double entropy(int N, const vector<int>& A) {
	vector<int> C(256);
	for (int i = 0; i < N; i++) {
		C[A[i]]++;
	}
	double res = 0.0;
	for (int i = 0; i < 256; i++) {
		if (C[i] != 0) {
			double p = double(C[i]) / N;
			res -= p * log2(p);
		}
	}
	return res;
}

int main() {
	while (true) {
		int N;
		cin >> N;
		if (N == 0) {
			break;
		}
		vector<int> I(N);
		for (int i = 0; i < N; i++) {
			cin >> I[i];
		}
		double opt = 1.0e+99;
		int OS = -1, OA = -1, OC = -1;
		for (int S = 0; S < 16; S++) {
			for (int A = 0; A < 16; A++) {
				for (int C = 0; C < 16; C++) {
					vector<int> R(N + 1);
					R[0] = S;
					for (int i = 0; i < N; i++) {
						R[i + 1] = (R[i] * A + C) % 256;
					}
					vector<int> O(N);
					for (int i = 0; i < N; i++) {
						O[i] = (R[i + 1] + I[i]) % 256;
					}
					double res = entropy(N, O);
					if (opt > res) {
						opt = res;
						OS = S;
						OA = A;
						OC = C;
					}
				}
			}
		}
		cout << OS << ' ' << OA << ' ' << OC << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 3540
final_rank: 9

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

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
while(1) {
    int N;
    cin >> N;
    if (N == 0) return 0;
    vector<int> V(N);
    rep(i,0,N) cin >> V[i];
    double MIN = inf;
    int AS, AA, AC;
    rep(S,0,16) {
        rep(A,0,16) {
            rep(C,0,16) {
                vector<int> COUNT(256,0);
                int R = S;
                rep(i,0,N) {
                    R = (A*R+C)%256;
                    COUNT[(V[i]+R)%256]++;
                }
                double SUM = 0.0;
                rep(i,0,256) {
                    if (COUNT[i] > 0) SUM -= ((double)COUNT[i]/(double)N) * log2((double)COUNT[i]/(double)N);
                }
                if (chmin(MIN,SUM)) AS=S,AA=A,AC=C;
            }
        }
    }
    cout << AS << ' ' << AA << ' ' << AC << endl;
}
}
accuracy: 1
time_ms: 170
memory_kb: 3400
final_rank: 3

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

const double eps = 1e-10;

int main(){
    while(true){
        int n; cin >> n;
        if(n == 0) break;
        vector<int> x(n);
        for(auto &it: x) cin >> it;

        double fent = 1e9;
        int fs, fa, fc;
        const int m = 256;
        for(int s = 0; s <= 15; s++){
            for(int a = 0; a <= 15; a++){
                for(int c = 0; c <= 15; c++){
                    vector<int> r(n+1);
                    r[0] = s;
                    for(int i = 1; i <= n; i++){
                        r[i] = (r[i-1]*a+c)%m;
                    }
                    vector<int> cnt(m, 0);
                    for(int i = 0; i < n; i++) cnt[(x[i]+r[i+1])%m]++;
                    double ent = 0.0;
                    for(int i = 0; i < m; i++){
                        if(cnt[i] == 0) continue;
                        ent += -1.0*log(1.0*cnt[i]/n)*cnt[i];
                    }
                    if(fent-eps > ent){
                        fent = ent;
                        fs = s; fa = a; fc = c;
                    }
                    // cerr << s << " " << a << " " << c << " " << ent << " # ";
                }
            }
        }
        cout << fs << " " << fa << " " << fc << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 3420
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#include <chrono>
#include <thread>
////#include <atcoder/all>

//using namespace atcoder;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

double EPS = 1e-9;
template<class T>
bool chmin(T& p, T q) {
    if (p > q + EPS) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}

vector<ll> fact, factinv, inv;
ll mod = 998244353;
void prenCkModp(ll n) {
    fact.resize(n + 5);
    factinv.resize(n + 5);
    inv.resize(n + 5);
    fact.at(0) = fact.at(1) = 1;
    factinv.at(0) = factinv.at(1) = 1;
    inv.at(1) = 1;
    for (ll i = 2; i < n + 5; i++) {
        fact.at(i) = (fact.at(i - 1) * i) % mod;
        inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
        factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
    }

}
ll nCk(ll n, ll k) {
    if (k < 0)return 0;
    if (n < k) return 0;
    return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    while (1) {
        ll N;
        cin >> N;
        if (N == 0)return 0;
        vll L(N);
        rep(i, N)cin >> L[i];
        ll M = 256;
        double an = 1e18;
        ll ans, ana, anc;
        double AN[16][16][16];
        rep(S, 16)rep(A, 16)rep(C, 16) {
            vll R(N + 1, S);
            map<ll, ll> MA;
            rep(i, N) {
                R[i + 1] = (A * R[i] + C) % M;
                MA[(R[i + 1] + L[i])%M]++;
            }
            double res = 0.0;
            for (auto p : MA) {
                double x = p.second;
                x /= double(N);
                res += -x * log2(x);
            }
            AN[S][A][C] = res;
            if (chmin(an, res)) {
                ans = S, ana = A, anc = C;
            }
        }
        cout << ans << " " << ana << " " << anc << endl;

    }
}
accuracy: 1
time_ms: 1200
memory_kb: 3608
final_rank: 19

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

// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solve(int n) {
  vector< int > cs(n);
  cin >> cs;

  constexpr int m = 256;
  long double min_h = infll;
  bool f = true;

  tuple<int, int, int> ans;
  range(s, 0, 16) range(a, 0, 16) range(c, 0, 16) {
    int r = s;
    vector< int > cnts(m);
    range(i, 0, n) {
      r = (a * r + c) % m;
      int o = (cs[i] + r) % m;
      cnts[o]++;
    }

    long double h = 0;
    for (auto &x : cnts) {
      if (x == 0) continue;
      h -= x * log(x);
    }

    constexpr long double e = 1e-9;
    if (f or (h - min_h) < -e) {
      f = false;
      min_h = h;
      ans = make_tuple(s, a, c);
    }
  }

  auto [s, a, c] = ans;
  cout << s << " " << a << " " << c << endl;
}

signed main() {
  int n;
  
  while (cin >> n, n) {
    solve(n);
  }
}
accuracy: 1
time_ms: 170
memory_kb: 3284
final_rank: 2

code_snippet: #include<bits/stdc++.h>
#define int ll
#define rep(i, N) for(int i = 0; i < (int)N; ++i)
#define rep1(i, N) for(int i = 1; i <= (int)N; ++i)
#define per(i, N) for(int i = N-1; i >= 0; --i)
#define per1(i, N) for(int i = N; i >= 1; --i)
#define FOR(i, f, t) for(int i = f; i < (int)t; ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bit(n) (1 << (n))
#define pcnt(n) (__builtin_popcount(n))
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define endl '\n'
#define fi first
#define se second
#define mkpr make_pair
#define mktpl make_tuple
#define eb emplace_back

using namespace std;
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
template<class T> using max_heap = priority_queue<T>;
template<class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vec<vec<T>>;
template<class T> using vvvec = vec<vec<vec<T>>>;
template<class T> using vvvvec = vec<vec<vec<vec<T>>>>;

constexpr ld EPS = 1e-10;
constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
//constexpr int MOD = 1e9+7;
constexpr ll MOD = 998244353;
constexpr int div2 = (MOD + 1) >> 1;
constexpr int NIL = -1;
constexpr int pm[2] = {1, -1};
constexpr int dy[4] = {0, 1, 0, -1};
constexpr int dx[4] = {1, 0, -1, 0};

ll cel(ll a, ll b){ return (a + b - 1) / b;}
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : a;}
ll powi(ll x, ll exp){
    return exp > 0 ? (exp & 1 ? x : 1) * powi(x * x, exp >> 1) : 1;
}
ll modpow(ll x, ll exp, ll mod){
    x %= mod;
    return exp > 0 ? (exp & 1 ? x : 1) * modpow(x * x, exp >> 1, mod) % mod : 1;
}
template<class T> bool chmin(T &a, T b){ return a > b ? (a = b, true) : 0;}
template<class T> bool chmax(T &a, T b){ return a < b ? (a = b, true) : 0;}

using P = pair<ll, ll>;
using Tpl = tuple<int, int, int, int>;

ld H(vec<int>& R){
    int num[256] = {}, N = R.size() - 1;
    rep1(i, N) num[R[i]]++;
    ld res = 0;
    rep(i, 256){
        if(num[i] != 0){
            res -= num[i] * (log2(ld(num[i])) - log2(ld(N)));
        }
    }
    return res;
}

void Main(){
    while(1){
        int N; cin >> N;
        if(N == 0) return;
        vec<int> I(N); rep(i, N) cin >> I[i];

        int S = 0, A = 0, C = 0, M = 256;
        ld mn = LINF;

        rep(i, 16)rep(j, 16)rep(k, 16){
            vec<int> R(N + 1, i);
            rep1(l, N){
                R[l] = (j * R[l - 1] + k) % M;
            }
            rep1(l, N){
                R[l] = (R[l] + I[l - 1]) % M;
                //if(i == 8 && j == 7 && k == 14) cout << R[l] << " ";
            }
            if(chmin(mn, H(R))){
                S = i, A = j, C = k;
                //rep1(l, N) cout << R[l] << " ";
                //cout << endl;
            }
        }
        cout << S << " " << A << " " << C << endl;
        //cout << mn << endl;
    }
}

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    Main();
    return 0;
}
accuracy: 1
time_ms: 630
memory_kb: 3408
final_rank: 11

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

const long double eps = 1e-9;

int main() {
    while(true) {
        int n;
        cin >> n;
        if(n == 0) {
            return 0;
        }
        vector<int>l(n);
        for(int i = 0; i < n; i++) {
            cin >> l[i];
        }
        double mx = 1000000;
        array<int,3>tmp = {0,0,0};
        for(int S = 0; S < 16; S++) {
            for(int A = 0; A < 16; A++) {
                for(int C = 0; C < 16; C++) {
                    array<int,3>res = {S,A,C};
                    vector<int>r(n+1);
                    r[0] = res[0];
                    for(int i = 1; i <= n; i++) {
                        r[i] = (A*r[i-1]+C)%256;
                    }
                    vector<int>o(n);
                    map<int,long double>di;
                    for(int i = 0; i < n; i++) {
                        o[i] = (l[i]+r[i+1])%256;
                        di[o[i]]++;
                    }
                    long double cnt = 0;
                    for(auto i:di) {
                        cnt -= (i.second/(long double)(n))*log(i.second/(long double)(n));
                    }
                    if(mx > cnt+eps) {
                        mx = cnt;
                        tmp = res;
                    }
                }
            }
        }
        cout << tmp[0] << " " << tmp[1] << " " << tmp[2] << endl;
    }
}
accuracy: 1
time_ms: 1200
memory_kb: 3436
final_rank: 18

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    int n;
    while(cin>>n){
        if(!n)break;
        vector<int> I(n);
        in(I);
        int M=256;
        double minv=INF;
        vector<int> ans(3);
        rep(S,16){
            rep(A,16){
                rep(C,16){
                    int R=S;
                    vector<int> t(256,0);
                    rep(i,n){
                        R=(A*R+C)%M;
                        t[(I[i]+R)%M]++;
                    }
                    double v=0;
                    rep(i,256){
                        if(!t[i])continue;
                        v-=(double)t[i]/n*(log((double)t[i]/n));
                    }
                    if(v+1e-9<minv){
                        minv=v,ans[0]=S,ans[1]=A,ans[2]=C;
                    }
                }
            }
        }
        out(ans);
    }
}
accuracy: 1
time_ms: 200
memory_kb: 3764
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
#define eps 1e-9
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 1000000007;
//const int mod = 998244353;

const int M = 256;

int main()
{
    while(true){
        int n;
        cin >> n;
        if(n == 0) return 0;
        vector<int> a(n);
        rep(i, 0, n) cin >> a[i];
        double H = INF;
        int mn_S = INF, mn_A = INF, mn_C = INF, idx;
        rep(S, 0, 16){
            rep(A, 0, 16){
                rep(C, 0, 16){
                    vector<int> tmp(M+1);
                    int r = S;
                    rep(i, 0, n){
                        r = (A*r + C)%M;
                        idx = (a[i] + r)%M;
                        tmp[idx]++;
                    }
                    double sum = 0;
                    rep(i, 0, M){
                        if(tmp[i] == 0) continue;
                        sum += ((-1)*(tmp[i]/(double)n)*(log2(tmp[i]/(double)n)));
                    }
                    //cout << sum << endl;
                    if(sum + eps < H){
                        H = sum + eps;
                        mn_A = A;
                        mn_S = S;
                        mn_C = C;
                    }
                }
            }
        }
        cout << mn_S << " " << mn_A << " " << mn_C << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3280
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n){
        if(n==0) break;
        vector<int> l(n);
        REP(i,n) cin >> l[i];
        double ent=inf;
        int S,A,C;
        REP(s,16){
            REP(a,16){
                REP(c,16){
                    vector<int> r(n+1);
                    r[0]=s;
                    REP(i,n) r[i+1]=(r[i]*a+c)%256;
                    vector<int> x(256);
                    REP(i,n) x[(l[i]+r[i+1])%256]++;
                    double res=0;
                    REP(i,256) if(x[i]!=0) res+=-x[i]/(double)n*log(x[i]/(double)n);
                    if(res+0.00000001<ent){
                        S=s,A=a,C=c;
                        ent=res;
                    }/*
                    if(s==0&&a==0&&c==0){
                        cout << res << endl;
                        REP(i,n) cout << (l[i]+r[i])%256 << " \n"[i==n-1];
                    }
                    if(s==1&&a==7&&c==12){
                        cout << res << endl;
                        REP(i,n) cout << (l[i]+r[i])%256 << " \n"[i==n-1];
                    }
                    if(s==8&&a==7&&c==14){
                        cout << res << endl;
                        REP(i,n) cout << (l[i]+r[i])%256 << " \n"[i==n-1];
                    }*/
                }
            }
        }
        cout << S << " " << A << " " << C << endl;
    }
}
accuracy: 1
time_ms: 220
memory_kb: 3660
final_rank: 13

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    while(true) {
        int N; cin >> N; if(N == 0) break;
        vector<int> l(N);
        rep(i,N) cin >> l[i];

        double mi = 1e9;
        tuple<int,int,int> ans;
        rep(s,16)rep(a,16)rep(c,16) {
            vector<int> R(N + 1, s);
            rep(i,N) R[i + 1] = (a * R[i] + c) % 256;
            vector<int> O(N);
            rep(i,N) O[i] = (l[i] + R[i + 1]) % 256;

            vector<int> cnt(256, 0);
            rep(i,N) cnt[O[i]]++;

            double H = 0;
            rep(i,256) {
                if(cnt[i]) {
                    double p = (double)cnt[i] / N;
                    H -= p * log(p);
                }
            }
            if(H < mi - 0.001) {
                mi = H;
                ans = {s, a, c};
            }
        }

        int s,a,c; tie(s, a, c) = ans;
        cout << s << " " << a << " " << c << endl;
    }
}
accuracy: 1
time_ms: 240
memory_kb: 3576
final_rank: 10

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

using ld=long double;
const ld EPS=1e-10;

int main(){
  int n;
  while(cin>>n,n){
    vector<int> v(n);
    REP(i,n)cin>>v[i];
    int S,A,C;
    ld mn=1e9;
    REP(s,16)REP(a,16)REP(c,16){
      map<int,int> mp;
      int pre=s;
      REP(i,n){
        int now=(a*pre+c)%256;
        mp[(v[i]+now)%256]++;
        pre=now;
      }
      ld e=0;
      for(auto p:mp){
        ld t=(ld)p.second/(ld)n;
        e-=t*log(t);
      }
      if(e+EPS<mn){
        mn=e;
        S=s,A=a,C=c;
      }
    }
    cout<<S<<" "<<A<<" "<<C<<endl;
  }
}
accuracy: 1
time_ms: 1150
memory_kb: 3380
final_rank: 16

code_snippet: #ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
 
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
 
#pragma region Macros
// rep macro
#define foa(v, a) for(auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int i = 0; i < (x); ++i)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define REPSname(a, b, c, ...) c
#define REPS(...) REPSname(__VA_ARGS__, REPS1, REPS0)(__VA_ARGS__)
#define REPS0(x) for(int i = 1; i <= (x); ++i)
#define REPS1(i, x) for(int i = 1; i <= (x); ++i)
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for(int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define RREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define RREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))
#define RREPSname(a, b, c, ...) c
#define RREPS(...) RREPSname(__VA_ARGS__, RREPS1, RREPS0)(__VA_ARGS__)
#define RREPS0(x) for(int i = (x); i >= 1; --i)
#define RREPS1(i, x) for(int i = (x); i >= 1; --i)
 
// name macro
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
template <class T = int>
using V = std::vector<T>;
template <class T = int>
using VV = std::vector<std::vector<T>>;
template <class T = int>
using VVV = std::vector<std::vector<std::vector<T>>>;
template <class T = int>
using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;
template <class T>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using int128 = __int128_t;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using Tp = tuple<ll,ll,ll>;
 
// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
	for(T &i : v) is >> i;
	return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
	std::string s;
	is >> s;
	__int128_t ret = 0;
	for(int i = 0; i < s.length(); i++)
		if('0' <= s[i] and s[i] <= '9')
			ret = 10 * ret + s[i] - '0';
	a = ret * (s[0] == '-' ? -1 : 1);
	return is;
}
namespace scanner {
void scan(int &a) { std::cin >> a; }
void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U>
void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T>
void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#define VEC(type, name, size)     \
	std::vector<type> name(size); \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                                    \
	std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)             \
	std::string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
 
// output-macro
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &a) {
	for(int i = 0; i < int(a.size()); ++i) {
		if(i) os << " ";
		os << a[i];
	}
	return os;
}
std::ostream &operator<<(std::ostream &dest, __int128_t &value) {
	std::ostream::sentry s(dest);
	if(s) {
		__uint128_t tmp = value < 0 ? -value : value;
		char buffer[128];
		char *d = std::end(buffer);
		do {
			--d;
			*d = "0123456789"[tmp % 10];
			tmp /= 10;
		} while(tmp != 0);
		if(value < 0) {
			--d;
			*d = '-';
		}
		int len = std::end(buffer) - d;
		if(dest.rdbuf()->sputn(d, len) != len) {
			dest.setstate(std::ios_base::badbit);
		}
	}
	return dest;
}
template <class T>
void print(const T a) { std::cout << a << '\n'; }
template <class Head, class... Tail>
void print(Head H, Tail... T) {
	std::cout << H << ' ';
	print(T...);
}
template <class T>
void printel(const T a) { std::cout << a << '\n'; }
template <class T>
void printel(const std::vector<T> &a) {
	for(const auto &v : a)
		std::cout << v << '\n';
}
template <class Head, class... Tail>
void printel(Head H, Tail... T) {
	std::cout << H << '\n';
	printel(T...);
}
void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "No\n"; }
void err(const bool b = true) {
	if(b) {
		std::cout << "-1\n", exit(0);
	}
}
 
//debug macro
namespace debugger {
template <class T>
void view(const std::vector<T> &a) {
	std::cerr << "{ ";
	for(const auto &v : a) {
		std::cerr << v << ", ";
	}
	std::cerr << "\b\b }";
}
template <class T>
void view(const std::vector<std::vector<T>> &a) {
	std::cerr << "{\n";
	for(const auto &v : a) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}
template <class T, class U>
void view(const std::vector<std::pair<T, U>> &a) {
	std::cerr << "{\n";
	for(const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::pair<T, U> &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; }
template <class T>
void view(const std::set<T> &s) {
	std::cerr << "{ ";
	for(auto &v : s) {
		view(v);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}
 
template <class T>
void view(const T &e) { std::cerr << e; }
}  // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	debugger::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(false)
#else
#define debug(...) (void(0))
#endif
 
// vector macro
template <class T>
int lb(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); }
template <class T>
int ub(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); }
template <class T>
void UNIQUE(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<T> press(std::vector<T> &a) {
	auto res = a;
	UNIQUE(res);
	for(auto &v : a)
		v = lb(res, v);
	return res;
}
#define SORTname(a, b, c, ...) c
#define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__)
#define SORT0(a) std::sort((a).begin(), (a).end())
#define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; })
template <class T>
void ADD(std::vector<T> &a, const T x) {
	for(auto &v : a) v += x;
}
template <class T>
void SUB(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v -= x;
}
template <class T>
void MUL(std::vector<T> &a, const T x) {
	for(auto &v : a) v *= x;
}
template <class T>
void DIV(std::vector<T> &a, const T x) {
	for(auto &v : a) v /= x;
}
 
// math macro
template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <class T, class U>
inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <class T>
T divup(T x, T y) { return (x + y - 1) / y; }
template <class T>
T POW(T a, long long n) {
	T ret = 1;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}

template<typename T>
T ADD(T a, T b){
	T res;
	return __builtin_add_overflow(a, b, &res) ? numeric_limits<T>::max() : res;
}

template<typename T>
T MUL(T a, T b){
	T res;
	return __builtin_mul_overflow(a, b, &res) ? numeric_limits<T>::max() : res;
}

// modpow
long long POW(long long a, long long n, const int mod) {
	long long ret = 1;
	while(n) {
		if(n & 1) (ret *= a) %= mod;
		(a *= a) %= mod;
		n >>= 1;
	}
	return ret;
}
 
// others
struct fast_io {
	fast_io() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} fast_io_;

#pragma endregion

using R = long double;
constexpr R EPS=1E-11;

// r の(誤差付きの)符号に従って, -1, 0, 1 を返す.
int sgn(const R& r){ return (r > EPS) - (r < -EPS); }
// a, b の(誤差付きの)大小比較の結果に従って, -1, 0, 1 を返す.
int sgn(const R& a, const R &b){ return sgn(a-b); }
// a > 0 は sgn(a) > 0
// a < b は sgn(a, b) < 0
// a >= b は sgn(a, b) >= 0
// のように書く.
// return s * 10^n

//https://atcoder.jp/contests/abc191/submissions/20028529
long long x10(const string& s, size_t n) {
    if (s.front() == '-') return -x10(s.substr(1), n);
    auto pos = s.find('.');
    if (pos == string::npos) return stoll(s + string(n, '0'));
    return stoll(s.substr(0, pos) + s.substr(pos + 1) + string(n + pos + 1 - s.size(), '0'));
}
 
long long ceildiv(long long a, long long b) {
    if (b < 0) a = -a, b = -b;
    if (a >= 0) return (a + b - 1) / b;
    else return a / b;
}
 
long long floordiv(long long a, long long b) {
    if (b < 0) a = -a, b = -b;
    if (a >= 0) return a / b;
    else return (a - b + 1) / b;
}
 
long long floorsqrt(long long x) {
    assert(x >= 0);
    long long ok = 0;
    long long ng = 1;
    while (ng * ng <= x) ng <<= 1;
    while (ng - ok > 1) {
        long long mid = (ng + ok) >> 1;
        if (mid * mid <= x) ok = mid;
        else ng = mid;
    }
    return ok;
}

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}

const int inf = 1e9;
const ll INF = 1e18;

const long double eps = 1e-9;

void main_() {
    ll N;
    cin >> N;
    while(N != 0){
        VEC(ll,P,N);
        ll M = 256;
        double ans = INF;
        ll S = 0,A = 0,C = 0;
        REP(s,16){
            REP(a,16){
                REP(c,16){
                    V<ll> cnt(256);
                    V<ll> R(N+1);
                    REP(i,N+1){
                        if(i == 0)R[i] = s;
                        else{
                            R[i] = (a * R[i-1] + c) % M;
                        }
                    }
                    REP(i,N){
                        cnt[(P[i] + R[i+1]) % M]++;
                    }
                    long double H = 0;
                    REP(i,256){
                        long double n = N;
                        long double val = cnt[i];
                        if(cnt[i])H -= (val/n)*log(val/n);
                        
                    }
                    
                    if(ans > H + eps){
                        S = s,A = a,C = c;
                        ans = H;
                        
                    }
                    
                }
            }
        }
        
        cout << S << " " << A << " " << C << endl;
        cin >> N;
    }
}

int main() {
	int t = 1;
	//cin >> t;
	while(t--) main_();
	return 0;
}
accuracy: 1
time_ms: 350
memory_kb: 3404
final_rank: 6

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

int m = 256;
static const double EPS = 1e-10;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;

    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l.at(i);

    double ansh = 1e9;
    int anss = -1, ansa = -1, ansc = -1;
    for (int s = 0; s <= 15; s++) {
      for (int a = 0; a <= 15; a++) {
        for (int c = 0; c <= 15; c++) {
          vector<int> r(n + 1), r2(256);
	  r.at(0) = s;
	  for (int i = 1; i <= n; i++) {
	    r.at(i) = (a * r.at(i - 1) + c) % m;
	  }
	  map<int, int> mp;
	  for (int i = 1; i <= n; i++) {
	    r2[(l.at(i - 1) + r.at(i)) % m]++;
	  }
	  double h = 0;
	  for (int i = 0; i < 256; i++) {
	    if (r2.at(i) > 0) h -= (double) r2.at(i) * log((double) r2.at(i));
	  }
	  if (ansh > h) {
	    ansh = h;
	    anss = s;
	    ansa = a;
	    ansc = c;
	  }
        }
      }
    }

    cout << anss << " " << ansa << " " << ansc << '\n';
  }
}
accuracy: 1
time_ms: 270
memory_kb: 3452
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int M = 256;
int N;
vector<int> I;

double entropy(vector<int> a){
    vector<int> cnt(M, 0);
    each(e, a) cnt[e]++;

    double ret = 0;
    each(e, cnt){
        if(e > 0) ret += e*log(e);
    }

    return ret;
}

double calc_score(int S, int A, int C){
    vector<int> R(N+1);
    R[0] = S;
    rep(i, N){
        R[i+1] = (A*R[i]+C)%M;
    }

    vector<int> a(N);
    rep(i, N) a[i] = (I[i]+R[i+1])%M;

    return entropy(a);
}

int main(){
    while(true){
        cin >> N;
        if(N == 0) break;

        I.resize(N);
        rep(i, N) cin >> I[i];

        double score = -1e9, EPS = 1e-9;
        int s, a, c;

        rep(S, 16){
            rep(A, 16){
                rep(C, 16){
                    double tmp = calc_score(S, A, C);
                    if(tmp > score + EPS){
                        score = tmp;
                        s = S, a = A, c = C;
                    }
                }
            }
        }

        cout << s << ' ' << a << ' ' << c << '\n';
    }
}
accuracy: 1
time_ms: 290
memory_kb: 3432
final_rank: 5

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

vector<int> make_R(int S, int A, int C, int N) {
    vector<int> ret(N + 1);
    ret[0] = S;
    for (int i = 0; i < N; i++) {
        ret[i + 1] = (A * ret[i] + C) % 256;
    }
    ret.erase(ret.begin());
    return ret;
}

long double calc_entropy(vector<int> I, vector<int> R) {
    int N = I.size();
    map<int, int> cnt;
    for (int i = 0; i < N; i++) {
        cnt[(I[i] + R[i]) % 256]++;
    }
    long double ret = 0;
    for (auto& [key, x] : cnt)
        ret += -1.0 * x / N * log(1.0 * x / N);
    return ret;
}

int main() {
    int N;
    while (cin >> N, N) {
        vector<int> I(N);
        for (int i = 0; i < N; i++) {
            cin >> I[i];
        }
        int S = 0, A = 0, C = 0;
        long double now = 1e10;
        for (int s = 0; s < 16; s++) {
            for (int a = 0; a < 16; a++) {
                for (int c = 0; c < 16; c++) {
                    auto R = make_R(s, a, c, N);
                    long double ento = calc_entropy(I, R);
                    if (ento < now) {
                        now = ento;
                        S = s;
                        A = a;
                        C = c;
                    }
                }
            }
        }
        cout << S << " " << A << " " << C << endl;
    }
}
accuracy: 1
time_ms: 1070
memory_kb: 3680
final_rank: 20

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

vector<int> make_R(int S, int A, int C, int N) {
    vector<int> ret(N + 1);
    ret[0] = S;
    for (int i = 0; i < N; i++) {
        ret[i + 1] = (A * ret[i] + C) % 256;
    }
    ret.erase(ret.begin());
    return ret;
}

double calc_entropy(vector<int> I, vector<int> R) {
    int N = I.size();
    map<int, int> cnt;
    for (int i = 0; i < N; i++) {
        cnt[(I[i] + R[i]) % 256]++;
    }
    double ret = 0;
    for (auto& [key, x] : cnt)
        ret += -1.0 * x / N * log(1.0 * x / N);
    return ret;
}

int main() {
    int N;
    while (cin >> N, N) {
        vector<int> I(N);
        for (int i = 0; i < N; i++) {
            cin >> I[i];
        }
        int S = 0, A = 0, C = 0;
        double now = 1e10;
        for (int s = 0; s < 16; s++) {
            for (int a = 0; a < 16; a++) {
                for (int c = 0; c < 16; c++) {
                    auto R = make_R(s, a, c, N);
                    double ento = calc_entropy(I, R);
                    if (ento + 1e-8 < now) {
                        now = ento;
                        S = s;
                        A = a;
                        C = c;
                    }
                }
            }
        }
        cout << S << " " << A << " " << C << endl;
    }
}
accuracy: 1
time_ms: 1090
memory_kb: 3452
final_rank: 17