1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// KTO: Kto wygrał? [C] | 2024-03-11 | Solution by dkgl
// https://sio2.mimuw.edu.pl/c/pa-2024-1/p/kto/

#include <bits/stdc++.h>

using namespace std;

const int n = 18;
typedef array<int, n> Scores;
enum Result { A, B, Draw };

inline int sum(const Scores &scores) {
  int result = 0;
  for (auto score: scores) result += score;
  return result;
}

Result compare_sum(const Scores &scores_a, const Scores &scores_b) {
  int sum_a = sum(scores_a);
  int sum_b = sum(scores_b);
  if (sum_a > sum_b) return A;
  if (sum_a < sum_b) return B;
  return Draw;
}

typedef array<int, 11> Distribution;

inline Distribution score_distribution(const Scores &scores) {
  Distribution result;
  for (auto &count: result) count = 0;
  for (auto score: scores) result[score]++;
  return result;
}

Result compare_distribution(const Scores &scores_a, const Scores &scores_b) {
  Distribution distribution_a = score_distribution(scores_a);
  Distribution distribution_b = score_distribution(scores_b);
  int first_different = 10;
  while (first_different >= 0 && distribution_a[first_different] == distribution_b[first_different]) {
    --first_different;
  }
  if (first_different < 0) return Draw;
  if (distribution_a[first_different] > distribution_b[first_different]) return A;
  return B;
}

Result compare(const Scores &scores_a, const Scores &scores_b) {
  Result result = compare_sum(scores_a, scores_b);
  if (result == Draw) result = compare_distribution(scores_a, scores_b);
  return result;
}

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

  Scores scores_algosia, scores_bajtek;
  for (auto &score: scores_algosia) cin >> score;
  for (auto &score: scores_bajtek) cin >> score;

  auto result = compare(scores_algosia, scores_bajtek);
  if (result == A) cout << "Algosia" << endl;
  if (result == B) cout << "Bajtek" << endl;
  if (result == Draw) cout << "remis" << endl;

  return 0;
}