AlgoChief Sprint Round 1
A. Biggest Field
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are a farmer and you want to create the biggest field possible to make your farm.

You are given certain side lengths, you need to find what is the largest square field and the largest rectangle field you can make using the side lengths.

Print $$$-1$$$ if making a particular field is not possible.

A Square field cannot be a Rectangular Field

Input

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 500$$$) — the number of testcases

  • The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2*10^5$$$) — the size of the array.
  • The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the initial values of the array.

It is guaranteed that the sum of all $$$n$$$ across all test cases does not exceed $$$2*10^5$$$.

Output

For each test, print two integers, the biggest square area and biggest rectangle area possible

Example
Input
3
8
1 1 1 1 2 2 2 2
8
1 1 2 2 2 2 3 3
8
1 2 3 4 5 5 5 5
Output
4 2
4 6
25 -1

B. Step Gambling
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Sensible gambling is crucial to ensure that the activity remains enjoyable and does not spiral into harmful behavior. It involves setting limits on time and money spent, understanding the risks, and knowing when to walk away. By practicing self-control and being aware of the potential consequences, individuals can avoid the dangers of addiction and financial strain. Responsible gambling encourages balance, helping players enjoy the experience without it negatively impacting their lives or well-being.

You have $$$k$$$ amount of money which u are ready to risk for gambling and your goal is to have the most amount of money in the end

You are given an array of n integers which determine the money gained or lost playing the ith game.

Here's the description of the game, you can start playing from any index you want. Note that you can back out at any time

If you are currently playing game $$$i$$$, and this is your $$$j$$$'th game so far; Then the next game that you will be playing is game $$$i + j$$$

Input

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 500$$$) — the number of testcases

  • The first line contains two integers $$$n$$$ ($$$1 \leq n \leq 2*10^5$$$) — the size of the array and $$$k$$$ ($$$1 \leq k \leq 10^9$$$) — the initial money you hold
  • The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \leq a_i \leq 10^9$$$) — the game.
It is guaranteed that the sum of all $$$n$$$ across all test cases does not exceed $$$2 * 10^5$$$.
Output

For each test, print the maximum amount of money u can hold after playing the most desirable situation

Example
Input
3
5 5
-1 -1 -1 -1 -1
4 1
100 -500 -200 100
4 3
1 2 3 4
Output
5
101
10

C. Biggest Field (Hard Version)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are a farmer and you want to create the biggest field possible to make your farm.

You are given certain side lengths, you need to find what is the largest square field and the largest rectangle field you can make using the side lengths.

You have q queries to answer

  • Type 1: val; Add val to your dataset of side lengths
  • Type 2: val; Remove val from your dataset of side lengths if it is present in your data, else do nothing
  • Type 3: Calculate the biggest square field and biggest rectangle field you can create.

Print $$$-1$$$ if making a particular field is not possible.

A Square field cannot be a Rectangular Field

Input

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 500$$$) — the number of testcases

  • The first line contains two integers $$$n$$$ ($$$1 \leq n \leq 2*10^5$$$) — the size of the array and $$$q$$$ ($$$1 \leq q \leq 2*10^5$$$) — the number of queries
  • The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the initial values of the array.
  • Then comes $$$q$$$ lines, describing the queries
It is guaranteed that the sum of all $$$n + q$$$ across all test cases does not exceed $$$4 * 10^5$$$.
Output

For each type 3 query, print two integers, the biggest square area and biggest rectangle area possible

Example
Input
1
5 9
1 1 2 2 3
3
1 3
3
2 3
2 2
3
2 1
2 1
3
Output
-1 2
-1 6
-1 -1
-1 -1

D. Fat Burner
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are looking to lose weight and feel the most healthiest form of yourself. You promise to yourself that you will workout regularly and very intensely.

But its not so easy, balancing work and rest is very difficult task, especially when you dont have proper knowledge about working out.

Balancing workouts and rest is essential for optimal muscle health and growth. While regular exercise strengthens muscles and improves endurance, rest allows them to recover, repair, and grow stronger. Overworking muscles without adequate recovery can lead to fatigue, injuries, and hindered progress. On the other hand, too much rest can stall fitness goals. Striking a balance by alternating intense workouts with rest days or lighter activities ensures steady improvement while reducing the risk of burnout or strain.

You are given n integers, ith of them determine the number of fats you can burn of on ith day

Here's the tradeoff between working out and rest if you are planning to work out on day i

  • If you worked the previous 2 days, you will burn $$$a[i]$$$ fats
  • If you have rested the previous 2 days, you will burn $$$4 * a[i]$$$ fats
  • If you have rested yesterday but not day before, you will burn $$$3 * a[i]$$$ fats
  • If you have rested day before but not yesterday, you will burn $$$2 * a[i]$$$ fats

Your job is choose certain days to work such that you can burn the maximum fat molecules that u can

Input

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 500$$$) — the number of testcases

  • The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2*10^5$$$) — the number of days.
  • The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the fat burned on each day.

It is guaranteed that the sum of all $$$n$$$ across all test cases does not exceed $$$2*10^5$$$.

Output

For each test, print the maximum fat you can burn

Example
Input
3
5
1 2 3 100 5
5
1 2 3 5 100
5
1 100 2 3 4
Output
414
408
417