Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- typedef pair<LL, LL> PII;
- typedef vector<LL> VI;
- #define MP make_pair
- #define PB push_back
- #define X first
- #define Y second
- #define FOR(i, a, b) for(int i = (a); i < (b); ++i)
- #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
- #define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
- #define ALL(a) a.begin(), a.end()
- #define SZ(a) (int)((a).size())
- #define FILL(a, value) memset(a, value, sizeof(a))
- #define debug(a) cout << #a << " = " << a << endl;
- const double PI = acos(-1.0);
- const LL INF = 1000 * 1000 * 1000 + 47;
- const LL LINF = INF * INF;
- const int N = 10007;
- int a[N];
- int res[N];
- int u[10005];
- int cnt[8];
- int cnt2[8];
- int idx = 0;
- int q[8];
- int prefDob[8];
- int curHsh;
- int n;
- void go()
- {
- if(idx == n)
- {
- int xr = 0;
- for(int mask = 0; mask < (1 << n); mask++)
- {
- int hsh = 0;
- for(int i = 0; i < n; i++)
- {
- if(mask & (1 << i))
- hsh += cnt2[i] * prefDob[i];
- else
- hsh += (cnt[i] - cnt2[i] - 1) * prefDob[i];
- }
- xr ^= res[hsh];
- }
- u[xr] = 1;
- return ;
- }
- for(int i = 0; i <= cnt[idx] / 2; i++)
- {
- cnt2[idx] = i;
- curHsh += prefDob[idx];
- if(__gcd(i , cnt[idx]) > 1 && __gcd(cnt[idx] - i - 1 , cnt[idx]) > 1)
- continue;
- idx++;
- go();
- idx--;
- }
- cnt2[idx] = 0;
- for(int i = 0; i <= cnt[idx] / 2; i++)
- curHsh -= prefDob[idx];
- }
- int main()
- {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- //freopen("In.txt", "r", stdin);
- //freopen("Out.txt", "w", stdout);
- cin >> n;
- bool was1 = false;
- int dob = 1;
- for(int i = 0; i < n; i++)
- {
- cin >> a[i];
- prefDob[i] = dob;
- dob *= (a[i] + 1);
- was1 |= a[i] == 1;
- }
- if(was1)
- {
- cout << "Archie" << endl;
- return 0;
- }
- if(n == 1)
- {
- cout << ((a[0] % 2) ? "Archie" : "Barik");
- return 0;
- }
- for(int hsh = 0; hsh < dob; hsh++)
- {
- int hsh2 = hsh;
- bool was1 = false , was0 = false;
- for(int i = 0; i < n; i++)
- {
- cnt[i] = hsh2 % (a[i] + 1);
- hsh2 /= a[i] + 1;
- was1 |= cnt[i] == 1;
- was0 |= cnt[i] == 0;
- }
- if(was0)
- continue;
- if(was1)
- {
- res[hsh] = 1;
- continue;
- }
- memset(u , 0 , sizeof u);
- go();
- int kek = 0;
- while(u[kek])
- kek++;
- res[hsh] = kek;
- }
- cout << (res[dob - 1] ? "Archie" : "Barik");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement