International Odoo Programming Contest 2024
A. Potential Odoo Email
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You've just discovered Odoo, an awesome suite of web-based open-source business apps. Not only impressed by the idea and quality of the apps, you, as a member of the open-source community, loved the fact that Odoo is open source.

After hours reading the codebase and learning how Odoo works, you decide to check the commit history of the most fun app: Real State! But wait... you just realized... there is a pattern in some of the author emails! Of course! Odoo employees! There is also a whole team of developers making sure the codebase is clean and developing new features!

You realized that Odoo emails have the format S@odoo.com, where S is a string of lowercase letters with size 2, 3 or 4. Really excited by your own discovery, you decide to write a script to check if an email is a potential Odoo email. That is, if it follows the described format.

Input

The only line of the input contains a string $$$E$$$ ($$$1 \leq |E| \leq 50$$$, $$$|E|$$$ is the size of the string E).

Output

Print yes if $$$E$$$ follows the format in the statement and no otherwise.

Examples
Input
pf@odoo.com
Output
yes
Input
palm@odoocom
Output
no
Input
im_not_an_email
Output
no
Input
jcsc@odoo.net
Output
no
Input
nAsg@odoo.com
Output
no

B. Make it ODOO!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It's party time at Odoo! These Odooers... they sure know how to party! However, as any mortal human being, they are having trouble setting up the printer for decorations.

The printer was supposed to print a nice big ODOO strip, but, instead, it printed a scrambled sequence of O's and D's, even with more letters than needed. For instance, it just now printed ODODODODODO...

The party organization committee is now going to fix the strip, making it a proper ODOO, but following the operations bellow:

  • Removing a letter: Since it's a strip, they can only cut out a letter from the beginning or the end, not from the middle. They can't remove more than one letter at a time.
  • Transforming a letter: O's and D's are quite similar, so they can transform an O into a D and vice-versa.

Being the clever bunch they are, the Odooers want to fix the strip as quickly as possible. How many minutes will it take them at the least? Both operations above have the same cost of 1 minute to be done.

Input

The first line of the input contains an integer $$$T$$$ $$$(1 \leq T \leq 10)$$$ indicating the number of test cases.

Each of the following $$$T$$$ lines contains a string $$$S$$$ $$$(4 \leq |S| \leq 10^3)$$$ of upper-case O's and D's in any order.

Output

Print the minimum amount of minutes needed to transform $$$S$$$ into ODOO following the operations described in the statement.

Example
Input
6
ODOO
DODOOD
ODODO
DDDDDDDDD
DODODODO
OODO
Output
0
2
2
8
5
2

C. Viruses
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

We're trying to install $$$n$$$ Odoo modules from your local machine to the server.

Imagine that the path from your local machine to the server is a line where your machine is at position $$$0$$$ and the server is at position $$$k$$$ ($$$k = 10^{9}$$$, fixed).

Initially, each module has:

  • An initial position between $$$0$$$ and $$$k-1$$$
  • An initial capacity to resist viruses.

Each second, the module advances $$$1$$$ unit (its position advances by $$$1$$$).

You started the installation, and all your modules were moving to the server, but someone introduced $$$m$$$ viruses in different positions of the line in the opposite direction of the installation (right to left) (Viruses move with the same speed).

Each virus has different capacities to impact each module. It can have capacity $$$X$$$ against module $$$A$$$ and capacity $$$Y$$$ against module $$$B$$$.

When a module and a virus collide (touch each other at any part of the line):

  • If the virus does not have any capacity against this specific module, nothing happens (the module continues its path to the server, and the virus continues its path to the left looking for a module to kill).
  • If the virus does have capacity against this module, the one with lower capacity is removed. If the module survives, its capacity decreases by the virus capacity against it. Yes, you're right! If they both have the same capacity, they are both removed.
A module can only fight against a virus coming from its right, and a virus can only fight against a module coming from its left.
Input

The first line contains $$$3$$$ integers $$$n$$$, $$$m$$$, and $$$q$$$ $$$(1 \leq n \leq 10^{3}, 1\leq m \leq 5\cdot 10^{3}, 0 \leq q \leq 5\cdot 10^{5})$$$ denoting the number of modules, the number of viruses, and the number of the capacities of viruses against modules.

Each of the following $$$n$$$ lines contains $$$module_{i}$$$, $$$capacity_{i}$$$, and $$$modulePosition_{i}$$$ ($$$module_{i}$$$ is a string, $$$1\leq length(module_{i}) \leq 20$$$, $$$1 \leq capacity_{i} \leq 10^{5}$$$, $$$0 \leq modulePosition_{i} \leq k-1$$$) denoting the name of the $$$i_{th}$$$ module, its capacity, and its initial position. It's guaranteed that there is no space in the name of the module, and no two modules have the same name. It's also guaranteed that no two modules have the same position.

Each line in the $$$m$$$ following lines contains $$$virus_{i}$$$ and $$$virusPosition_{i}$$$ ($$$ 1 \leq virus_{i} \leq m$$$, $$$0 \leq virusPosition_{i} \leq k-1$$$) denoting the $$$ID$$$ of the virus followed by its initial position. It's guaranteed that no two viruses have the same $$$ID$$$. It's also guaranteed that no two viruses have the same position.

Each line in the $$$q$$$ following lines contains $$$virus_i$$$, $$$module_i$$$, $$$capacityAgainst_i$$$ $$$(1\leq virus_i \leq m, 1\leq capacityAgainst_i \leq 10^5)$$$ denoting the $$$ID$$$ of the virus followed by the name of the module and its capacity against that module. It's guaranteed that $$$module_i$$$ exists in the list of modules. It's guaranteed that every pair of virus and module pair appears at most one time.

If a module and virus exist in the same position at the beginning, they collide.

Output

Print the number of modules remaining in the first line. Print the names of the remaining modules sorted by arrival time in increasing order in the second line separated by spaces.

Example
Input
5 3 7
Project 5 0
Time-Off 1 70
To-do 80 4
Timesheets 10 10
Employees 2 40
1 15
2 50
3 60
1 Time-Off 100
1 Employees 200
2 To-do 84
2 Project 4
3 Employees 4
3 To-do 50
3 Project 2
Output
2
Time-Off Timesheets 

D. Tasks at Odoo
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

At Odoo, several tasks are processed daily on our dedicated servers. These tasks need to be inspected by a person who guarantees correct performance in all of them.

Natan is in charge this week, but he needs to finish all the tasks within the time limit set for him. However, to save more resources, Natan needs to find out the smallest amount of dedicated servers that will be needed to finish all tasks within the time limit or verify that this is impossible.

Each task takes a certain duration to perform. All the tasks need to be started in order (i.e., task $$$i$$$ just can start if task $$$i-1$$$ starts at the same time or at an earlier time).

Each dedicated server can only perform a maximum of one task at a time and it can start a new task as soon as it finishes the one it is currently doing.

As a new developer at Odoo, you were tasked with helping Natan solve this problem. Find out the smallest number of dedicated servers needed to perform these tasks or, if impossible, print the number -1.

Input

The first line contains two integers, $$$N$$$ and $$$T$$$ $$$(1 \leq N, T \leq 10^{5})$$$, representing the number of tasks and the time limit to do the tasks, respectively.

The second line contains $$$n$$$ integers $$$A_{i}$$$ $$$(1 \leq A_{i} \leq 10^{5})$$$, where $$$A_{i}$$$ represents the duration of the task $$$i$$$.

Output

Print a number $$$Q$$$ containing the smallest number of dedicated servers needed to perform these tasks or if it is impossible to do all the tasks within the time print the number -1.

Examples
Input
5 1
1 1 1 1 1
Output
5
Input
5 5
1 1 1 1 1
Output
1
Input
5 5
1 2 3 5 6
Output
-1

E. POS Kiosk
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Odoo has introduced its new POS Kiosk app, which allows restaurants to receive orders from clients in their shop and process them easily. So basically, there are 2 main functionalities of the POS kiosk: add order , mark order as done so it's removed from the screen.

For performance reasons, the updates in the database are made in batches. It means that for each batch of updates, there is only one query executed to remove/add records to the database.

To test the database performance, Odoo developers came up with the following process :

  • There will be a randomly generated array of operations $$$A$$$ of size $$$n$$$ based on analytics of real data where $$$A_{i}$$$ is the difference between the created and deleted records of that batch of updates. For example, if $$$A_{i}=3$$$ , it means there are 3 more created records than deleted records in that batch of operations.
  • Now for every integers $$$L$$$ to $$$R$$$ $$$(1 \leq L \leq R \leq n)$$$ they will calculate $$$f(A,L,R)$$$ which goes as follows, from $$$L$$$ to $$$R$$$, executes the queries one by one, and reports the maximum extra units of space needed from its initial state if we consider that each record needs $$$1$$$ unit of space. It means that if $$$A_{i} \gt 0$$$ we need extra $$$A_{i}$$$ units of space to be able to execute that query , otherwise we free $$$-A_{i}$$$ units of space from the database that can be filled later by some other updates. For example, for the sequence $$$2$$$ $$$3$$$ $$$-4$$$ $$$6$$$, the answer is $$$7$$$, and for $$$2$$$ $$$3$$$ $$$-4$$$ $$$3$$$, the answer is $$$5$$$.

Given the generated array $$$A$$$, can you simulate the experiment and find : $$$$$$\sum_{1\leq L \leq R\leq n}f(A,L,R)$$$$$$

Input

The first line contains an integer $$$T$$$ $$$(1 \leq T \leq 2 \cdot 10^{5})$$$, the number of testcases.

For each test case:

The first line contains an integer $$$n$$$ $$$(1 \leq n \leq 2 \cdot 10^{5})$$$, the size of the generated array of updates.

The second line contains $$$n$$$ integers $$$A_{i}$$$ $$$(-2 \cdot 10^3 \leq A_{i} \leq 2\cdot 10^{3})$$$, the data of the generated array.

The sum of $$$n$$$ over all test cases doesn't exceed $$$2\cdot 10^{5}$$$

Output

Print $$$T$$$ lines where the $$$i_{th}$$$ line contains the answer for the $$$i_{th}$$$ testcase.

Example
Input
2
3
-2 3 -5
7
1 -2 3 4 5 -10 223
Output
8
1672
Note

Explanation of the first test case:

  • for $$$[-2]$$$ the answer is $$$0$$$
  • for $$$[-2,3]$$$ the answer is $$$1$$$
  • for $$$[-2,3,-5]$$$ the answer is $$$1$$$
  • for $$$[3]$$$ the answer is $$$3$$$
  • for $$$[3,-5]$$$ the answer is $$$3$$$
  • for $$$[-5]$$$ the answer is $$$0$$$

The total sum is equal to $$$8$$$

F. Odoo Trees
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are $$$n$$$ employees at Odoo numbered from $$$1$$$ to $$$n$$$, each employee has exactly $$$1$$$ manager, except for the head with the number $$$1$$$ who has no manager. So they form a rooted tree.

We call employee $$$a$$$ a subordinate of another employee $$$b$$$ if either $$$b$$$ is the manager of $$$a$$$, or the manager of $$$a$$$ is a subordinate of employee $$$b$$$. In particular, subordinates of the head are all other employees of the company.

You will be given very sensitive information: An integer array $$$A$$$ of size $$$n$$$ where $$$A_i$$$ is the salary of the $$$i_{th}$$$ employee at Odoo $$$(1 \le i \le n)$$$.

For the following $$$q$$$ years, at the beginning of the year, one lucky employee $$$u$$$ is picked alongside an integer value denoted as $$$x$$$. For that employee, their salary will be multiplied by $$$x$$$. Also, for all subordinates of $$$u$$$ their salary will be multiplied by $$$x$$$ as well.

An employee is happy at some year if their salary was divisible by $$$k$$$ in that year. You will be given the value of $$$k$$$ and your goal is to print $$$n$$$ integers where the $$$i_{th}$$$ integer $$$(1 \leq i \leq n)$$$ is the first year at which employee number $$$i$$$ was happy.

If one employee was happy initially print $$$0$$$ and if they were never happy print $$$-1$$$.

Input

The first line contains $$$3$$$ integers $$$n$$$, $$$k$$$, $$$q$$$, $$$(1 \leq n, q \leq 2*10^{5})$$$ $$$(1 \leq k \leq 10^{9})$$$

The second line contains $$$n$$$ integers $$$A_1, A_2, .. , A_n$$$ $$$(1 \le A_i \le 10^{9})$$$

The third line contains $$$n - 1$$$ integers $$$P_2, P_3, .. , P_n$$$ where $$$P_i$$$ is the manager of employee number $$$i$$$. $$$(1 \le P_i \le n)$$$

Then $$$q$$$ lines follow, The $$$i_{th}$$$ line contains two integers $$$u_i$$$ and $$$x_i$$$ $$$(1 \le u_i \le n) (1 \le x_i \le 10^{9})$$$

Output

Print $$$n$$$ integers, the answer to the problem

Examples
Input
5 4 4
1 2 3 4 6
1 1 2 2
2 3
3 2
1 2
2 7
Output
-1 3 3 0 3 
Input
9 10 8
4 6 7 4 9 10 8 7 9
6 6 6 7 1 1 7 1
8 2
3 5
9 7
3 6
5 2
6 2
2 10
6 10
Output
-1 7 4 8 -1 0 -1 -1 -1 

G. Giant Community
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In Odoo, we foster a large open-source community offering a plethora of apps, all accessible for free. Kinho dedicates himself to developing and enhancing select apps within this ecosystem. While each app boasts a wealth of features, let's simplify our focus to four key attributes:

  • An App ID to uniquely identify each application.
  • The ID of its parent app (Pid). Odoo operates with an inherent mode, enabling one app to inherit properties from another.
  • A profit rate (PR), denoting the daily profit generated by the app.
  • A bonus, representing a fixed profit received throughout the day upon installing the app.

To compute the profit for app $$$i$$$ on a specific day $$$d$$$, we use the following formula:

$$$$$$profit_{i} = PR_{i} * d + bonus_{i}$$$$$$

It's noteworthy that when Kinho develops a new app, its profit rate is strictly greater than its parent app. This is because the primary motive behind developing a new app is to enhance an existing one.

Now Kinho is curious, given an app and considering all the apps from which it inherits, what is the highest profit for app for a given day?

Input

The first line contains two integers, $$$N$$$ and $$$Q$$$ $$$(1 \leq N, Q \leq 10^5)$$$, representing the number of installed apps and the number of queries, respectively.

The subsequent $$$N$$$ lines each contain four integers: $$$id$$$, $$$Pid$$$, $$$PR$$$, and $$$bonus$$$ $$$(1 \leq id \leq N, 0 \leq Pid \leq N, -10^9 \leq PR, bonus \leq 10^9)$$$, representing an app. It is guaranteed that all ids are unique, meaning no two apps share the same id. Additionally, there is exactly one app with $$$Pid$$$ equal to $$$0$$$, which serves as the dashboard app and has no parents.

The following $$$Q$$$ lines each contain two integers, $$$id$$$ and $$$D$$$ $$$(0 \leq D \leq 10^9)$$$, representing the id of the respective app and the day for which Kinho wants to determine the highest profit for each ancestor app, including itself.

Output

For each query, print an integer representing the highest profit for all apps that are ancestors of the given app, including itself.

Examples
Input
4 2
1 0 80 531
4 1 83 438
3 1 90 733
2 3 91 176
4 8
3 11
Output
1171
1723
Input
9 2
9 8 171 139
1 0 64 710
7 1 121 285
3 7 174 794
4 6 226 530
8 1 114 106
5 6 186 993
2 3 250 611
6 8 152 881
9 98
7 62
Output
16897
7787
Input
5 2
5 3 760 432
1 0 46 40
4 5 1558 846
2 1 705 390
3 1 53 36
4 34
4 3
Output
53818
5520

H. Views Testing
time limit per test
6 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

In the Odoo interface, you realize that it's all about views and smart buttons. Let's consider that Odoo has N distinct views and for each view, there are some smart buttons to take you to other views.

It's guaranteed that :

  • From every view, you can go to any other view using a series of clicks on smart buttons.
  • If there is a button that takes you from view $$$V_{1}$$$ to view $$$V_{2}$$$ , then there is a button that takes you from $$$V_{2}$$$ to $$$V_{1}$$$.
  • There is only one way to go from any view to any other view using the minimum number of clicks. (the views construct a tree like structure).

Since views are a very important part of Odoo, they should be tested carefully. That's where the Odoo tour test comes into play. The developers at Odoo developed an automatic testing program which will run infinitely. The test consists of a cyclic list of views of size $$$k$$$ (not necessarily distinct). At the start, the program starts from a view at some position $$$p$$$ in the list, then he goes to the next view at position $$$p+1$$$ using the minimum number of clicks, then to the view at position $$$p+2$$$ and so on (the view at position $$$1$$$ comes after the view at position $$$k$$$). A view is called tested if it is visited at least one time at some point during the test. You realized that some views might not get tested, so you introduced some updates to the original list of views and some other queries to collect analytics. The queries go as follows:

  • $$$1$$$ $$$p$$$ $$$u$$$: update the view at position $$$p$$$ by view with id $$$u$$$
  • $$$2$$$ $$$p$$$ $$$u$$$: find the minimum number of clicks needed for the view with id $$$u$$$ to be tested for the first time if the program starts running from position $$$p$$$ , print $$$-1$$$ if it's impossible to test that view.
Input

The first line of the input contains $$$2$$$ integers $$$n$$$ and $$$k$$$ $$$(1\leq n\leq 10^{5}, 1 \leq k \leq 10^{5})$$$, the number of views and the size of the list of views of the test.

The second line contains $$$k$$$ integers $$$v_{i}$$$ $$$(1\leq v_{i} \leq n)$$$, the ids of the views in the list of the test.

The next $$$n-1$$$ lines each contain $$$2$$$ integers $$$u$$$ and $$$v$$$ $$$(1\leq u, v \leq n, u \ne v)$$$, which means that views with id $$$u$$$ and $$$v$$$ have a smart button that connects them.

The next line contains an integer $$$q$$$ $$$(1\leq q\leq 10^{5})$$$, the number of queries to process.

The next $$$q$$$ lines each contain $$$3$$$ integers $$$t$$$, $$$p$$$, and $$$u$$$ $$$(1\leq t\leq 2, 1\leq p \leq k, 1\leq u\leq n)$$$, the description of the query.

Output

Print the answer for each query of the type $$$2$$$ in separate lines. It's guaranteed that there is at least one query of type $$$2$$$.

Example
Input
9 4
4 6 8 9
1 2
2 3
3 4
4 5
2 6
2 7
6 8
4 9
8
2 2 9
2 1 7
2 4 8
2 4 9
2 1 9
2 2 2
1 3 1
2 2 2
Output
6
-1
5
0
9
3
1