Skip to main content
Back to problems
Codeforces
Easy
Arrays
Array

Split nn integers into three groups based on their remainder modulo 3 so that every group sum is divisible by 3.

Acceptance 0%
Problem Statement

You are given an array of integers. Reorder or redistribute the elements into three groups according to their remainder when divided by 3, and determine whether it is possible to make each group have a sum divisible by 3 using the available elements.

A valid arrangement must satisfy the divisibility condition for every group. Your task is to work with the counts of numbers in each remainder class and decide the outcome requested by the problem.

Input Format

  • The first line contains an integer nn.
  • The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n.

Notes

  • The exact operation is based on grouping by remainder modulo 3.

Output Format

  • Print the required result for the grouping/divisibility condition.
  • The answer is typically a single word such as YES or NO, depending on whether the condition can be satisfied.

Constraints

  • 1n1 \le n
  • Array values fit in standard 32-bit signed integers.
  • Time limit-friendly solutions should run in linear time.
Examples
Sample cases returned by the problem API.

Example 1

Input

6
1 2 3 4 5 6

Output

YES

Explanation

The numbers can be grouped so that each group has sum divisible by 3; for example, pairs like (1,2), (3), (4,5), and (6) each contribute sums divisible by 3.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.