A. Fair Game

Codeforces
IDCF864A
Time1000ms
Memory256MB
Difficulty
implementationsortings
English · Original
Chinese · Translation
Formal · Original
Petya and Vasya decided to play a game. They have _n_ cards (_n_ is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (**different** from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written. The game is considered fair if Petya and Vasya can take all _n_ cards, and the number of cards each player gets is the same. Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair. ## Input The first line contains a single integer _n_ (2 ≤ _n_ ≤ 100) — number of cards. It is guaranteed that _n_ is an even number. The following _n_ lines contain a sequence of integers _a_1, _a_2, ..., _a__n_ (one integer per line, 1 ≤ _a__i_ ≤ 100) — numbers written on the _n_ cards. ## Output If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "_NO_" (without quotes) in the first line. In this case you should not print anything more. In the other case print "_YES_" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them. [samples] ## Note In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards. In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct. In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.
Petya 和 Vasya 决定玩一个游戏。他们有 #cf_span[n] 张卡片(#cf_span[n] 是偶数)。每张卡片上写有一个整数。 游戏开始前,Petya 会选择一个整数,之后 Vasya 会选择另一个整数(与 Petya 选择的数不同)。在游戏中,每个玩家拿走所有写有自己所选数字的卡片。例如,如果 Petya 在游戏前选择了数字 #cf_span[5],他会拿走所有写有 #cf_span[5] 的卡片;如果 Vasya 选择了数字 #cf_span[10],他会拿走所有写有 #cf_span[10] 的卡片。 如果 Petya 和 Vasya 能拿走全部 #cf_span[n] 张卡片,且每人拿到的卡片数量相同,则该游戏被认为是公平的。 判断 Petya 和 Vasya 是否能在游戏开始前选择整数,使得游戏公平。 第一行包含一个整数 #cf_span[n](#cf_span[2 ≤ n ≤ 100])——卡片数量。保证 #cf_span[n] 是偶数。 接下来的 #cf_span[n] 行包含一个整数序列 #cf_span[a1, a2, ..., an](每行一个整数,#cf_span[1 ≤ ai ≤ 100])——写在 #cf_span[n] 张卡片上的数字。 如果不可能选择整数使得游戏公平,请在第一行输出 "_NO_"(不含引号),此时无需输出其他内容。 否则,在第一行输出 "_YES_"(不含引号),在第二行输出两个不同的整数——Petya 应选择的数字和 Vasya 应选择的数字,以使游戏公平。如果有多个解,输出任意一个即可。 在第一个例子中,如果 Petya 选择数字 #cf_span[11],Vasya 选择数字 #cf_span[27],则游戏是公平的。他们会拿走所有卡片——Petya 拿走第 #cf_span[1] 和 #cf_span[4] 张卡片,Vasya 拿走第 #cf_span[2] 和 #cf_span[3] 张卡片。因此,每人恰好拿到两张卡片。 在第二个例子中,公平游戏是不可能的,因为卡片上的数字相同,但 Petya 和 Vasya 应选择的数字必须不同。 在第三个例子中,不可能拿走所有卡片。Petya 和 Vasya 最多只能拿走五张卡片——例如,Petya 选择数字 #cf_span[10],Vasya 选择数字 #cf_span[20]。但要使游戏公平,必须拿走 #cf_span[6] 张卡片。 ## Input 第一行包含一个整数 #cf_span[n](#cf_span[2 ≤ n ≤ 100])——卡片数量。保证 #cf_span[n] 是偶数。接下来的 #cf_span[n] 行包含一个整数序列 #cf_span[a1, a2, ..., an](每行一个整数,#cf_span[1 ≤ ai ≤ 100])——写在 #cf_span[n] 张卡片上的数字。 ## Output 如果不可能选择整数使得游戏公平,请在第一行输出 "_NO_"(不含引号),此时无需输出其他内容。否则,在第一行输出 "_YES_"(不含引号),在第二行输出两个不同的整数——Petya 应选择的数字和 Vasya 应选择的数字,以使游戏公平。如果有多个解,输出任意一个即可。 [samples] ## Note 在第一个例子中,如果 Petya 选择数字 #cf_span[11],Vasya 选择数字 #cf_span[27],则游戏是公平的。他们会拿走所有卡片——Petya 拿走第 #cf_span[1] 和 #cf_span[4] 张卡片,Vasya 拿走第 #cf_span[2] 和 #cf_span[3] 张卡片。因此,每人恰好拿到两张卡片。 在第二个例子中,公平游戏是不可能的,因为卡片上的数字相同,但 Petya 和 Vasya 应选择的数字必须不同。 在第三个例子中,不可能拿走所有卡片。Petya 和 Vasya 最多只能拿走五张卡片——例如,Petya 选择数字 #cf_span[10],Vasya 选择数字 #cf_span[20]。但要使游戏公平,必须拿走 #cf_span[6] 张卡片。
**Given:** * An even integer $n$ such that $2 \le n \le 100$. * A sequence of integers $A = (a_1, a_2, \dots, a_n)$ where $1 \le a_i \le 100$. **Definitions:** * Let $I = \{1, 2, \dots, n\}$ be the set of indices. * For any integer $v$, let $S_v = \{i \in I \mid a_i = v\}$ be the set of indices where the sequence value equals $v$. **Objective:** Determine if there exist integers $x$ and $y$ satisfying the following system of constraints: 1. $x \neq y$ 2. $\bigcup_{i \in I} \{a_i\} \subseteq \{x, y\}$ 3. $|S_x| = |S_y|$ **Output:** * If such $x$ and $y$ exist: Output "YES" followed by $x$ and $y$. * Otherwise: Output "NO".
Samples
Input #1
4
11
27
27
11
Output #1
YES
11 27
Input #2
2
6
6
Output #2
NO
Input #3
6
10
20
30
20
10
20
Output #3
NO
Input #4
6
1
1
2
2
3
3
Output #4
NO
API Response (JSON)
{
  "problem": {
    "name": "A. Fair Game",
    "description": {
      "content": "Petya and Vasya decided to play a game. They have _n_ cards (_n_ is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will c",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF864A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Petya and Vasya decided to play a game. They have _n_ cards (_n_ is an even number). A single integer is written on each card.\n\nBefore the game Petya will choose an integer and after that Vasya will c...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Petya 和 Vasya 决定玩一个游戏。他们有 #cf_span[n] 张卡片(#cf_span[n] 是偶数)。每张卡片上写有一个整数。\n\n游戏开始前,Petya 会选择一个整数,之后 Vasya 会选择另一个整数(与 Petya 选择的数不同)。在游戏中,每个玩家拿走所有写有自己所选数字的卡片。例如,如果 Petya 在游戏前选择了数字 #cf_span[5],他会拿走所有写有 #cf_s...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Given:**\n*   An even integer $n$ such that $2 \\le n \\le 100$.\n*   A sequence of integers $A = (a_1, a_2, \\dots, a_n)$ where $1 \\le a_i \\le 100$.\n\n**Definitions:**\n*   Let $I = \\{1, 2, \\dots, n\\}$ be...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments