Problemset RPC11
Problemset RPC11
Nick has always struggled with maintaining habits. The problem is that he just can’t stop maintaining
them. If Nick does something K times in a row, he has to keep doing it forever.
Luckily, he has started visiting Dr Patternson, an expert in PBT (Pattern Breaking Therapy). The
principle of PBT is simple: Nick will visit Dr Patternson every day, and if he has done the same thing
K times in a row on a specific visit, the doctor will charge him money. This will motivate Nick to not
continue this habit.
PBT has worked out great for Nick, as he has now successfully quit all his habits. Except for one, the
habit of visiting Dr Patternson. The frequent visits are starting to take a toll on Nick’s economy, so your
task is to calculate how many times he has to pay the doctor for the next N days.
Formally, let s = s1 s2 s3 . . . sN be a string consisting of zeroes and ones. A one means that Nick has to
pay the doctor on the ith day. This string is generated one character at a time, in the following way:
1. si = 0 if i ≤ K.
2. If i > K, then si = 1 if the previous characters contains a pattern that repeats K times. More
specifically, let s0 = s1 s2 . . . si−1 . If there is a nonempty string t such that the last |t| · K characters
of s0 can be written as t + t + · · · + t, then si = 1. Otherwise si = 0.
You are given the numbers N and K, and your task is to calculate the number of ones in the string s.
The picture represents Example 1. An angry face means that Nick had to pay on the corresponding day.
Input
The input consists of one line with the integers N and K (1 ≤ N ≤ 109 , 2 ≤ K ≤ 109 ).
Output
Print one integer, the number of ones in the string s.
Example
Input Output
7 2 3
99 5 19
Input
The first line of the input contains a single positive integer N (1 ≤ N ≤ 104 ), the number of grass tiles
available. The second line of the input contains two positive integers a and b (1 ≤ a, b ≤ 104 ), the size of
the land the court can be made within.
Output
Print the number of valid ways to place the grass tiles to make up a baseball court. All n grass tiles must
be used. Since this number might be very large, print the answer modulo 109 + 7.
Example
Input Output
15 3
3 8
15 1
3 5
15 0
3 4
Input
The inputs starts with an integer 0 < n ≤ 103 . Then follow n lines, each containing up to 3 · 105 Roman
digits. The total number of Roman digits in the input is at most 3 · 105 .
Output
Output the corresponding Arabic numbers, one number per line.
Example
Input Output
5 499
CDXCIX 499
ID 4
IV 1
IIIIV -1
IIIIIIV
You are playing a new card game. In the game you have two decks
of cards each consisting of N · K cards labeled with an integer
from 1 to N , inclusive. Also, each type of card appears precisely
K times in each deck.
The rules of the game are simple. You shuffle both decks and place
them face up in front of you, so at each point in time you see the
top card in each deck. If the top cards are the same you can take
them both and get one point. Otherwise you must discard either
card. Your goal is to get as many points as possible. Image taken from wikimedia.org
You have just finished playing a round of this game and you want
to know what the maximum score was, knowing the layout of both decks.
Input
The first line of the input contains two integers N and K (1 ≤ N ≤ 104 , 1 ≤ K ≤ 15). The second and
third line of the input each contain N · K integers xi (1 ≤ xi ≤ N ), describing the layout of the decks.
The first number x1 is the topmost card in the deck, x2 is the second, and so on.
No integer in the second line and third line is repeated more than K times per line.
Output
Print a single integer, the maximum possible score.
Example
Input Output
3 2 4
3 1 2 3 1 2
2 1 3 1 3 2
5 3 8
2 3 4 5 3 5 2 2 4 3 5 1 1 1 4
5 2 3 2 3 1 4 5 1 4 5 1 4 3 2
Input
The first line of input contains the integer N (1 ≤ N ≤ 1000).
The following N lines each contain two integers fi and ti (1 ≤ fi ≤ 104 , 1 ≤ ti ≤ 109 ).
Output
Print one integer, the minimum time to place all components.
Example
Input Output
3 31
2 7
2 1
3 10
3 35
2 10
2 11
2 12
4 72
2 11
7 10
3 5
1 1
Input
The first line contains an integer F (3 ≤ F ≤ 1000), the number of fence
line segments. The next F lines contain four integers each, x1 , y1 , x2 , y2 (0 ≤ x1 , y1 , x2 , y2 ≤ 1000),
representing a straight-line fence section.
No two fence line segments intersect. Since fencing is both expensive and tedious, you may assume that
every fence line segment is necessary and serves to bound fields. All fences farmers have are connected.
In other words, the graph that consists of endpoints and fences is planar, connected, and has no bridges.
Output
Output a single line representing the sum of the squared areas of all the fields formed by the given fence
sections. Your answer will be correct if it has an absolute or relative error of at most 10−6 .
Example
Input Output
5 2.25
0 0 0 1
0 1 1 1
0 0 1 0
1 0 2 0
1 1 2 0
6 1.25
0 0 0 1
0 1 1 1
0 0 1 0
1 0 2 0
1 1 2 0
1 0 1 1
Explanation
The picture represents example 2. The areas of the two fields are 1 and 0.5, so the sum of their squares
is 1 + 0.25 = 1.25.
Welcome to the world of Heroes of Velmar, the critically acclaimed trading card game developed by Sidney
Games! After the tremendous success of the physical card game, Sidney Games has decided to take it to
the next level and transform it into an immersive video game experience.
As Sidney Games embarks on this ambitious video game project, they seek the expertise of talented
developers like you to bring this digital version to life. The challenge lies in coding the algorithm that
determines the winner in the virtual battles that unfold between players. The video game will need
to retain the same core mechanics as the original card game, where players compete on three distinct
locations over six turns, with abilities and power levels shaping the outcomes.
The full rules of the game are listed below. You are given the state of the locations after Setup and
Gameplay have finished and the End of the Game has been reached. Sidney Games has tasked you with
implementing the Location Resolution part of the game rules, including the application of Special Abilities,
to determine the winner.
The game designers have provided you with images of the cards as well as a JSON file with their specifi-
cations.
Objective
The objective of the two-player card game Heroes of Velmar is to win more locations than the opponent
over six turns. If there is a tie, the total power level across all locations acts as a tiebreaker.
Setup
1. Each player selects a deck of cards containing heroes with different abilities and power levels.
2. The players shuffle their decks and draw a starting hand of 7 cards each.
3. Designate three distinct locations for the battle. Each location will have its own separate battlefield.
Gameplay
1. Each player draws 1 card from the deck, to their hand, if possible. Maximum cards per hand is 7.
2. Players take turns playing cards from their hand on any of the three locations.
3. On each turn, players have energy equal to the turn number, for example, on Turn 3, they have 3
energy to spend.
4. Each card has a cost that must be paid using energy to play it on a location.
5. Players can play as many cards as they want as long as the following conditions are met:
6. The power level of each card represents its strength in the game.
1. The game ends after six turns, at which point locations are resolved, with each location having a
winner or a tie.
2. The player who wins the most locations is the overall winner.
3. If the players win an equal number of locations, the total power level across all locations is used as
a tiebreaker to determine the winner.
4. If the total power level across all locations is also tied, then the game results in a tie.
Location Resolution
2. Compare the total power levels of all cards played by each player at the location after applying
special abilities.
3. The player with the higher total power level wins the location.
Special Abilities
1. Some cards have special abilities that can affect the game. These abilities trigger at the end of the
game, before location resolution.
2. Abilities can buff the card’s power level, interact with other cards, or manipulate the game state.
3. Two cards that portray the same character are considered to portray distinct characters for the sake
of abilities.
The game Heroes of Velmar offers a mix of strategic card play, resource management, and tactical decision-
making. Players must choose their heroes wisely, coordinate their plays, and employ their unique abilities
to outwit their opponents and emerge victorious in the epic battle for control over Velmar!
Card design
Card Explanation:
• Top Left Corner: The energy cost required to play the card on the battlefield.
• Top Right Corner: The power level of the card, representing its strength.
• Text on the Bottom: The name of the card, identifying its character.
• Text Underneath: The card’s ability, describing its unique effect during gameplay.
Input
Input consists of six lines representing the state of the three locations after six turns of play. This means
that there will be at most 24 cards total listed in the input.
First the left location is described, then the center location is described, and finally the right location is
described. Each location is described by two lines, the first of which represents player 1’s cards and the
second of which represents player 2’s cards. Each line lists the number of cards in the line and then the
names of the cards played by the player, separated by spaces. There will be at most four cards in each
line.
Note that a player may leave a location empty. Each input is guaranteed to be a valid reachable final
game state according to the game rules.
Output
Output "Player 1" if player 1 won, "Player 2" if player 2 won, or "Tie" if there was no victor.
Example
Input Output
3 Shadow Seraphina Ironwood Player 1
2 Voidclaw Voidclaw
1 Vexia
0
1 Ranger
0
1 Guardian Tie
1 Anvil
2 Seraphina Seraphina
1 Ranger
2 Ironwood Ranger
1 Guardian
1 Guardian Player 2
1 Anvil
2 Seraphina Seraphina
1 Ranger
1 Ironwood
1 Guardian
Problem H. Hotfix
Source file name: Hotfix.c, Hotfix.cpp, Hotfix.java, Hotfix.py
Input: Standard
Output: Standard
Input
The input contains a single string of length at least 1 and at most 106 . It contains only ASCII upper and
lower case characters. This string is then followed by a single newline character.
Output
For each non-whitespace character that appears a non-zero number of times in the output of the problem
described above, print it along with its number of occurrences on a single line, separated by a space. Print
the lines ordered by ascending values of the ASCII characters.
Example
Input Output
ABC 1 6
A 3
B 4
C 3
aaaab 1 6
2 1
3 1
4 1
a 20
b 5
Input
The input has three lines, each containing the positive integers s, d, m respectively. They satisfy
1 ≤ s, d, m ≤ 21000 . As these payment details are for a computer science job the numbers are all
given in binary, naturally.
Output
Print the number of the day that Svalur wants to spend money, but has none. This should naturally also
be printed in binary. If he can support his spending habits indefinitely instead print Infinite money!.
Example
Input Output
101110101 10011
1010
10001110101010101
101110101 Infinite money!
1000
100011101
101110101 1001
1010
100011101
Problem J. Jamboree
Source file name: Jamboree.c, Jamboree.cpp, Jamboree.java, Jamboree.py
Input: Standard
Output: Standard
Input
The first line of input contains two positive integers N and M (1 ≤ N ≤ 2M , 1 ≤ M ≤ 100). N is the
number of useful items, and M is the number of scouts. The second line contains N positive integers ai
(1 ≤ ai ≤ 107 ) giving the sizes of the items.
Output
Print one integer, the smallest total size that any scout has to carry.
Example
Input Output
3 4 10
10 10 10
5 4 12
9 12 3 9 10
Input
The input contains two positive integers N , the length of Image by Linn Bryhn Jacobsen, from commons.wikimedia.org
the sweater, and P , the length of the pattern. They satisfy
1 ≤ P ≤ N ≤ 1018 and they have the same parity, as otherwise
the pattern could never be perfectly centered.
Output
Print a single integer, the amount of empty space left on the back of the sweater.
Example
Input Output
13 3 4
16 4 0
Explanation
In the first example the sweater is 13 loops in circumference. Thus the centered pattern is placed at loops
6, 7 and 8. There’s space for another pattern in either direction at loops 3, 4, 5 and 9, 10, 11. There’s
not enough space to place two more, and a single pattern would make things asymmetric. Thus loops 1,
2, 12 and 13 are empty, so the answer is 4.
In the second example the sweater is 16 loops in circumference. The first pattern is placed at loops 7, 8,
9 and 10. Two more are placed at 3, 4, 5, 6 and 11, 12, 13, 14. This leaves 1, 2, 15 and 16, which exactly
fits one more pattern that will be perfectly centered at the back of the sweater, creating no asymmetry.
Thus that pattern is placed, leaving no empty space.