AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

FPC22-022.Dale ‘n’ Chip

Easy · 2 s · 256 MB

  • icpc
  • fpc
  • 2022

Dale and Chip are preparing the annual Fantastic Party for Chipmunks (FPC). This year, they say, it's much more than a big feast of nuts. In fact, they have prepared a game for their fellow friends. Like any chipmunk, they want their game to be predictable. There is no room for surprises. Last thing you would want is an angry losing chipmunk. Therefore, they will secretly plan the game such that everyone will win and lose exactly one time.

The game goes like this: a group of chipmunks is arranged in a circle. One of them will start the game by turning to their right neighbour and play a round of Rock Paper Scissors. Afterwards, the right neighbour turns to its right neighbour and plays a round of Rock Paper Scissors, and so on. The game ends when everyone has played with their right neighbour exactly once.

Dale has a list of chipmunks that will attend the party, and Chip knows for each of them what power (Rock, Paper, or Scissors) they will always play— chipmunks are predictable, after all. Not everybody will be at the party at the same time, so they want to prepare the game for several sublists of the list of attendees. For every sublist, calculate the largest possible number of chipmunks picked from that sublist that can be arranged in a circle, such that everyone will be happy, no matter who starts the game.

A happy chipmunk is one that has won and lost exactly once.

Giriş formatı

The input consists of:

• One line containing a single integer nnn (1≤n≤1041\leq n\leq 10^41≤n≤104), the total number of chipmunks on the list of attendees.

• nnn lines, each line containing a string (“Rock”, “Paper” or “Scissors”), which represents for every attendee what power they will always play.

• One line containing a single integer qqq (1≤q≤1051\leq q\leq 10^51≤q≤105), the number of sublists Dale and Chip would like to organise games for.

• qqq lines, each containing two integers sss and eee (1≤s≤e≤n1 \leq s \leq e\leq n1≤s≤e≤n), representing a sublist of all chipmunks iii where s≤i≤es \leq i \leq es≤i≤e, for which Dale and Chip would like to organise a game.

Çıxış formatı

Output, for each of the qqq sublists, the largest number of chipmunks that can be arranged into a circle such that every chipmunk is happy.

Qeyd

Source: Freshmen Programming Contest 2022 · Author: Jeroen Op de Beek and Dragos-Paul Vecerdea · License: CC BY-SA 4.0 · Original: https://fpc.wisv.ch · Statement adapted for AlgoLens and shared under the same license. · 10 of the 35 original test cases (the largest) are omitted here to keep the problem lightweight.

Nümunələr

Giriş #1

3
Rock
Paper
Scissors
3
1 3
1 2
2 3

Çıxış #1

3
0
0

Giriş #2

8
Paper
Rock
Rock
Rock
Scissors
Paper
Scissors
Paper
4
3 8
4 6
1 6
2 7

Çıxış #2

6
3
3
3