問題一覧 > 通常問題

No.2593 Reorder and Mod 120

レベル : / AI推定難易度 : 925 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 64
作問者 : hiro1729 / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 10395 / 自分の提出
問題文最終更新日: 2023-12-21 06:20:05
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2023 (順位表) の他の問題:

Problem Statement

You are given a string $S$ of length $N$. Consider the strings obtained by freely rearranging it, each viewed as a positive integer. Find how many different values are possible as the remainder when such an integer is divided by $120$.

Constraints

  • $1 \leq N \leq 200000$
  • $N$ is an integer
  • $S$ is a string of length $N$ consisting only of digits between $1$ and $9$, inclusive

Input

$N$
$S$

Output

Print the answer on $1$ line. End the output with a newline.

Sample

Sample 1
Input
4
1221
Output
6
The strings obtainable by rearranging 1221 are 1122,1212,1221,2112,2121,2211, and their remainders when divided by $120$ are $42,12,21,72,81,51$, respectively, so there are $6$ possible values.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。