A - Micromasters


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

The Department of Computer Engineering at Sharif University of Technology has recently initiated a professional education program known as Micromasters. This program offers a set of courses designed to empower students with specialized knowledge and skills in various domains of computer science and engineering. As an incentive to promote the program, the department has introduced a referral system wherein individuals who refer other students to the Micromasters program receive a 10%10\% discount for each referred student on their own course registrations.

Mina is a talented student who is passionate about spreading the benefits of the Micromasters program. With each referral, Mina’s list of discounts grows, and now the following question arises: given the number of students who are referred by Mina, how many courses can she enroll in for free?

ورودی🔗

The input consists of a single line containing a single integer nn, which represents the number of students that Mina has referred.

0n10000 \leq n \leq 1000

خروجی🔗

Print a single line, containing the number of courses Mina can enroll in for free using the discounts.

مثال‌ها🔗

ورودی نمونه ۱🔗

5
Plain text

خروجی نمونه ۱🔗

0
Plain text

ورودی نمونه ۲🔗

18
Plain text

خروجی نمونه ۲🔗

1
Plain text

B - Hezardastan’s Annual Report


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Hezardastan, a giant among Iranian IT holding groups, houses several innovative companies such as Cafebazaar, Divar, and Balad. The annual report of the holding consists of nn chapters, each dedicated to a company under Hezardastan’s umbrella. The chapters in the report vary in length and occupy a certain number of pages. We want to compile all nn chapters into a PDF document that will be printed double-sided on A4 paper sheets. However, for aesthetic reasons, we want to avoid having pages from two different chapters printed on the same paper sheet. To ensure each chapter begins on a fresh, odd-numbered page, we plan to strategically insert an extra blank page after each chapter that has an odd number of pages. Now, we need to know the minimum number of A4 paper sheets needed to print the entire holding company report?

ورودی🔗

The input consists of two lines. The first line contains a single integer nn, the number of chapters in the report. The second line contains nn space-separated integers, denoting the number of pages in each chapter. All numbers in the input are positive integers and are at most 100100.

1n1001 \leq n \leq 100

خروجی🔗

The output should consist of a single line containing the total number of A4 paper sheets needed to print the entire annual report.

مثال‌ها🔗

ورودی نمونه ۱🔗

5
1 1 2 1 2
Plain text

خروجی نمونه ۱🔗

5
Plain text

ورودی نمونه ۲🔗

8
1 2 3 2 2 5 4 2
Plain text

خروجی نمونه ۲🔗

12
Plain text

C - Moderation in all things


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Initially, we have an array of length 11 containing only the number 00. All natural numbers are listed in ascending order in the “reservation list” (the first number in the list is 11). The array undergoes qq operations. The ithi^{th} operation, is one of the following:

  • Insert(pp, xx): Insert the first xx numbers from the reservation list after the number pp in the array, in ascending order. These numbers are removed from the reservation list.
  • Remove(pp, xx): Remove the next xx numbers after number pp in the array. These numbers are not returned to the reservation list.

You are given information about qq operations, and you are asked to determine the number written in the middle of the array after each operation. If the length of the array after the ithi^{th} operation is nn, you should find the n2th\lceil \frac n 2 \rceil^{th} element of the array. Note that the indexing of the array starts from 11.

ورودی🔗

The first line contains an integer qq, which represents the number of operations. Each of the next qq lines contains two integers: pip_i, and kik_i.

If ki=+xk_i = +x, operation Insert(pip_i, xx) is executed. If ki=xk_i = -x, operation Remove(pip_i, xx) is executed.

It is guaranteed that all operations are valid, and no impossible operation is performed on the array.

Additionally, at most 2×1092 \times 10^9 numbers are moved from the reservation list into the array.

0pi,ki2×1090 \leq p_i, |k_i| \leq 2 \times 10^9 0q5×1050 \leq q \leq 5 \times 10^5

خروجی🔗

Output qq lines. In the ithi^{th} line, print the middle element of the array after performing the ithi^{th} operation.

مثال🔗

ورودی نمونه ۱🔗

10
0 3
0 2
5 -2
4 1
0 -2
5 2
7 3
3 2
10 5
12 20
Plain text

خروجی نمونه ۱🔗

1
5
4
6
5
7
9
10
16
22
Plain text

D - Cup of Tea


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Abolf lives in Aboland, a country consisting of nn cities and n1n - 1 two-way roads. In Aboland, one can travel from any city to any other city using these roads. Aboland’s cities are numbered from 11 to nn.

Abolbucks is a multinational chain of teahouses which serves the best tea in the world. When Abolf enters a city with an Abolbucks branch, he drinks a cup of tea and instantly reaches kk units of happiness. However, each time Abolf travels through the ithi^{th} road, he must pay cic_i coins as toll which causes him to lose cic_i units of happiness.

Abolf currently resides in city 11 and wants to plan his summer trip. If at any point during his trip Abolf’s happiness drops below zero, he would stops his trip immediately. For each city tt (for 2tn2 \leq t \leq n), Abolf wants to know what is the minimum amount of coins he should pay to reach city tt while making sure that his happiness remains non-negative at all time, including at the destination.

He has asked you to find this amount for each city except for his home city. Note that each destination should be considered separately. Also, he may visit a city multiple times during his trip.

ورودی🔗

The first line of input contains two integers nn and kk, the number of cities in Aboland and Abolf’s happiness after he drinks a cup of tea, respectively. Each of the next n1n -1 lines contains three space-separated integers viv_i, uiu_i, and cic_i

indicating that the ith{i^th} road connects city uiu_i and city viv_i, and Abolf should pay cic_i coins each time he travels through this road. The last line contains nn integers a1,a2,,ana_1, a_2, \dots , a_n (0ai10 \leq a_i \leq 1). If ai=1a_i = 1, there is an Abolbucks branch in city ii. It is guaranteed that a1=1a_1 = 1.

1ui,vin,uivi1 \leq u_i, v_i \leq n, u_i \neq v_i 1ci1091 \leq c_i \leq 10^9 2n3×1052 \leq n \leq 3 \times 10^5 1k1091 \leq k \leq 10^9

خروجی🔗

In the only line of the output, you should print n1n - 1 integers. The ithi^{th} number should be the minimum amount of coins it takes for Abolf to reach city i+1i + 1 from city 11. If there is no way to reach city i+1i + 1 such that Abolf’s happiness remains non-negative at all time, print 1-1 for that city.

مثال🔗

ورودی نمونه ۱🔗

6 3
1 2 4
1 3 3
1 4 2
4 5 1
4 6 2
1 1 0 0 1 0
Plain text

خروجی نمونه ۱🔗

-1 3 2 3 6
Plain text

E - Largest Triangle


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

A “terrain” is an xx-monotone polygon defined by the points p1,,pnp_1,\dots , p_n where each point pip_i has coordinates (xi,yi)(x_i, y_i), and the following three conditions hold:

  • y1=yn=0y_1 = y_n = 0
  • yi>0y_i > 0 for 1<i<n1 < i < n
  • xi<xi+1x_i < x_{i+1} for 1i<n1 \leq i < n

توضیح تصویر

Given a terrain defined by the points p1,,pnp_1, \dots , p_n, find the largest triangle that fits entirely within the terrain, and one of its three vertices is positioned at one of the terrain points p2p_2 through pn1p_{n-1}.

ورودی🔗

The first line of input contains an integer nn, representing the number of points in the terrain 3n1053 \leq n \leq 10^5. The ithi^{th} line in the following nn lines consists of two space-separated integers xix_i and yiy_i, representing the point pip_i of the terrain.

0xi,yi1090 \leq x_i, y_i \leq 10^9

خروجی🔗

Print the area of the largest triangle contained within the terrain. Your output will be considered correct if its absolute or relative error is at most 10610^{-6}.

مثال🔗

ورودی نمونه ۱🔗

11
0 0
2 10
4 5
6 7
8 8
10 4
12 6
14 4
15 4
16 7
17 0
Plain text

خروجی نمونه ۱🔗

53.666667
Plain text

F - Micromasters Certificates


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

The Department of Computer Engineering has provided several micromasters, each containing a curriculum. If a student successfully completes all the courses of a micromaster, he will receive the certificate of that micromaster. A course may be included in the curriculum of several micromasters.

Soroush, who only thinks about getting a certificate and doesn’t care about the type of certificate, wants to get 33 micromasters certificates by taking the minimum possible number of courses. The micromasters curriculums are posted on the bulletin board. Help Soroush reach his goal according to the micromasters curriculums.

ورودی🔗

The input represents a bulletin board. The board consists of at most 400400 rows and 400400 columns. Each micromasters curriculum is encapsulated in a rectangular box. The boundaries of the bulletin board and the curriculum boxes are represented by characters “+”, “-”, and “|” for corners, horizontal sides, and vertical sides, respectively. The curriculum boxes are disjoint (with no characters in common) and each has its own boundary. Each line inside a curriculum box contains at most one course name. Course names consist of alphanumeric and space characters. Course names are not case-sensitive, and spaces do not matter in them. For example, “General math1” and “generalMath 1” are the same. There are at most 5050 curriculum boxes and each box contains at most 3030 courses. It is guaranteed that there are at least 33 boxes on the board and there is at least 11 course in each box.

خروجی🔗

Print a single line containing the minimum number of courses that should be taken by Soroush to get at least 3 certificates.

مثال🔗

ورودی نمونه ۱🔗

+-------------------------------------------------+
|  +-------------------+                          |
|  |Algorithm Design   |   +-------------------+  |
|  |  Programming      |   |PROGRAMMING        |  |
|  |Discrete Structures|   |   Web Prgramming  |  |
|  |   Data Structures |   |                   |  |
|  +-------------------+   | DatabaseDesign    |  |
|                          |Software Test      |  |
|     +--------------+     |     Patterns      |  |
|     |    Python    |     +-------------------+  |
|     +--------------+                            |
|          +------------------------+             |
|          |Programming             |             |
|          |          AI            |             |
|          |    Algorithm     design|             |
|          |Database Design         |             |
|          +------------------------+             |
+-------------------------------------------------+
Plain text

خروجی نمونه ۱🔗

8
Plain text

G - Jackson House


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Jackson, after witnessing the advancements in the world of technology, decided to sell his small cozy house and enroll in the programming-and-algorithm micromaster. He came across an interesting algorithm that he needed to analyze and solve the problem related to it, in order to pass the exam at this stage of the course. The pseudocode of this algorithm is as follows:

توضیح تصویر

He wants to know for how many permutations π\pi of length nn from the possible n!n! ones, the final permutation will be sorted after running this algorithm.

ورودی🔗

The first line contains an integer tt, the number of test cases.

Each of the next tt lines contains an integer nin_i, representing the length of the permutation for the ithi^{th} test case.

1t1001 \leq t \leq 100 2ni1092 \leq n_i \leq 109

خروجی🔗

Output tt lines. On the ithi^{th} line, print the number of permutations of length nin_i which will be sorted after running the provided algorithm on it. Since the output could be very large, output the result modulo 109+710^9 + 7.

مثال🔗

ورودی نمونه ۱🔗

4
3
5
10
20
Plain text

خروجی نمونه ۱🔗

4
16
1728
23887872
Plain text

H - Star Wars


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Amirreza is playing the Star Wars game. This game is played on an n×mn \times m board where each cell is either empty (.), contains a white piece (W) or a black piece (B). At start of the game, Amirreza should choose exactly one white piece to play with. Afterwards he can move this piece multiple times to knock out as many black pieces as possible. Suppose the white piece is currently in cell (i,j)(i, j) of the board; In one move, this piece can go up-left (i1,j1)(i - 1, j - 1), up (i1,j)(i - 1, j) or up-right (i1,j+1)(i - 1, j + 1), provided that cell exists on the board and it does not contains another white piece. If the cell contains a black piece, it will be knocked out. Help Amireza figure out the maximum number of black pieces he can knock out.

ورودی🔗

The first line contains two integers nn and mm, the number of rows and columns in the board, respectively. This is followed by nn lines, each containing mm characters. The jthj^{th} character of the (i+1)th(i + 1)^{th} line represents cell (i,j)(i, j). Each character is ‘WW’, ‘BB’, or ‘.’, denoting a white piece, a black piece, or an empty cell, respectively.

1n,m501 \leq n, m \leq 50

خروجی🔗

Print a single integer, the maximum number of black pieces Amirreza can knock out.

مثال🔗

ورودی نمونه ۱🔗

8 10
.W... BB ...
W..B.WB ...
.B.WB ...W.
.B..B.....
..W... BB..
B.B..B.W.W
.WB.W...B.
..W..BW.B.
Plain text

خروجی نمونه ۱🔗

5
Plain text

I - Pistons


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Maryam, a famous mathematician, recently has bought an old vintage car. This car uses a combustion engine to generate the power needed to move the car. Inside the engine, there are nn cylinders of length mm and inside each cylinder, there is a piston constantly moving up and down. All pistons move independently and at the same speed. At any given time, the position of a piston inside a cylinder can be shown with an integer from 00 to mm, which also describes the area of the cylinder occupied by the piston. A piston instantly changes its direction when it reaches the top (position mm) or bottom (position 00) of its cylinder.

Maryam managed to determine the position and direction of all the pistons at a specific time. Now she is curious about the maximum total area occupied by all the pistons. Help Maryam find out this value

ورودی🔗

The first line of input contains two integers nn and mm, describing the number of pistons and the length of cylinders, respectively. Each of the next nn lines describe the position and direction of a single piston. The (i+1)th(i + 1)^{th} line of the input contains an integer pip_i and a character did_i , the initial position of the ithi^{th} piston and its direction (Up or Down), respectively.

1n1051 \leq n \leq 10^5 1m1061 \leq m \leq 10^6 0pim0 \leq p_i \leq m di{U,D}d_i \in \{ U, D \}

خروجی🔗

Print a single integer, the maximum total area occupied by all the pistons.

مثال‌ها🔗

ورودی نمونه ۱🔗

2 5
2 U
5 D
Plain text

خروجی نمونه ۱🔗

7
Plain text

ورودی نمونه ۲🔗

4 6
0 U
0 D
6 U
3 U
Plain text

خروجی نمونه ۲🔗

15
Plain text

J - Cafebazaar’s Applications


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

It’s the end of the year, and Cafebazaar has released a list, containing the number of users of each of its nn applications. Now, each application is eager to showcase its success through an advertisement image, which highlights a continuous subset of the application list containing the application itself. Also, for the image to be credible, it should contain at least kk applications, including itself.

توضیح تصویر

For each application in this list, we need to determine the minimum possible rank this application can achieve within any valid subset, according to the number of users. The rank of an application within a subset is defined by the number of applications in that subset that have more users than it, plus one.

ورودی🔗

The first line of input consists of two integers nn and kk, where nn represents the total number of applications and kk represents the minimum number of applications in an advertisement image.

The following nn lines contain information about each application: the ithi^{th} line contain cic_i, representing the number of users for the ithi^{th} application.

1kn1051 \leq k \leq n \leq 10^5 1ci1081 \leq c_i \leq 10^8

خروجی🔗

In the only line of output print nn space-separated integers. The ithi^{th} integer should be the minimum rank that ithi^{th} application can achieve within an advertisement image

مثال‌ها🔗

ورودی نمونه ۱🔗

7 3
15000000
10000000
30000000
20000000
200000
70000000
100000000
Plain text

خروجی نمونه ۱🔗

2 3 1 2 3 1 1
Plain text

ورودی نمونه ۲🔗

3 2
10
10
10
Plain text

خروجی نمونه ۲🔗

1 1 1
Plain text

K - Monster Warehouse


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Mike and Sally work in the warehouse of Monster Inc. as storekeepers. Their daily tasks are to process incoming requests and update the inventory of the Warehouse. Requests only include buying, selling, unpacking, and packing containers. The warehouse includes goods and containers and has unlimited space. A container may contain goods or other containers as sub-containers.

توضیح تصویر

The exact format of the requests is given below.

  • BUY <CONTAINER_DESCRIPTION>
  • SELL <CONTAINER_ID>
  • UNPACK <CONTAINER_ID>
  • PACK <CONTAINER_DESCRIPTION>

Each container which is not inside any other container is uniquely identified by a positive integer ID. Assigning IDs to containers is done sequentially and started from 11. An ID is valid if and only if its container exists in the warehouse, otherwise it is invalid.

A container description is enclosed in parentheses and lists the contents, which can be either goods or sub-containers. A good is identified exclusively by its name, which consists of non-case-sensitive English letters. Multiple units of a good may be available. To denote quantities, place a positive integer ‘NN’ before or after the good name (separated by one white space), where N<100N < 100 is the number of the good. For example, ((tomato, potato), 4 celery, (wood, (silk 3, banana 2))) describes a container with four units of celery and two sub-containers.

The description of each request is as follows:

  • BUY: A new container is transferred into the warehouse and an ID is assigned to it.
  • SELL: An existing container with the given ID is ship out and its ID becomes invalid.
  • UNPACK: All goods and sub-containers are extracted from the container and added to the ware- house. Moreover, the sub-containers become new containers and get their own ID. The assignment of IDs to the new containers is based on the order of their appearance in the container description (from left to right). For instance, considering the following two lines as the first requests, results in adding one unit of celery and adding three containers with IDs 22, 33, and 44 to the warehouse and ID 11 becomes invalid.
BUY (celery , (Banana), (Celery), (celery ))
UNPACK 1
Plain text
  • PACK: Goods specified in a PACK request are grouped into a new container, which is then assigned the next available ID.

Mike and Sulley process the requests in the order they are received. Any request with an invalid container ID must be discarded. Moreover, for PACK request they need to check if there exists enough units of each good in the warehouse.

Roz, the agent of Monster Inc. has told Mike once ”I’m watching you, Wazowski. Always watching. Always.”, She rolled her desk into their office and asked for requests and reports. She is looking for every detail. She is reviewing each request and might ask a few questions. Her questions might be each of the following types:

  • ? COUNT <good>: How many units of the given good exist outside of containers?
  • ? CONTAINS <good>: How many containers with ID have the given good, i.e. the good is in the container or there is a recursive sub-container which contains that good.
  • ? MIN <good>: At least how many containers should be unpacked to reach one unit of the good. If it is impossible, the answer should be -1.

Mike and Sully are expected to answer these queries using just one integer

Before helping Mike and Sully, read samples carefully.

ورودی🔗

The input consists of nn requests or queries from Roz while she is reviewing; each appears in a separated line. The name of each good is limited to 100 characters. Each container description might have at most 5000 characters and the input size is less than 10610^6 characters.

1n50001 \leq n \leq 5000

خروجی🔗

Each line of the report is associated with a request or Roz’s questions. After each BUY, SELL, PACK, UNPACK request, you should print OK, if the request is not discarded. Otherwise, print DISCARD. If the request is UNPACK, after printing OK, you should print the number of containers added to the warehouse (read samples for more details). For each Roz’s query, print just one integer in a line.

مثال‌ها🔗

ورودی نمونه ۱🔗

BUY (10 apple , 10 carrot , 10 banana , ())
UNPACK 1
UNPACK 2
PACK (3 apple , (5 cArrot , 2 banana))
PACK (3 apple , (5 carrOt , 1 banana))
PACK (5 apple , (3 banana))
? MIN apple
? MIN CaRRoT
? CONTAINS apple
Plain text

خروجی نمونه ۱🔗

OK
OK , 1 container added.
OK , No containers added.
OK
OK
DISCARD
0
2
2
Plain text

ورودی نمونه ۲🔗

BUY (apple , (banana , 3 carrot))
BUY (( banana , apple), (banana , carrot))
? MIN apple
UNPACK 1
? COUNT apple
? COUNT carrot
? CONTAINS banana
Plain text

خروجی نمونه ۲🔗

OK
OK
1
OK , 1 container added.
1
0
2
Plain text

ورودی نمونه ۳🔗

BUY (( duck 2, carrot ), 1 celery)
? MIN duck
? MIN carrot
? MIN celery
? MIN test
SELL 10
PACK (celery)
UNPACK 1
UNPACK 1
PACK (celery)
? COUNT celery
? COUNT carrot
? CONTAINS celery
? CONTAINS carrot
BUY (( duck 8, carrot ), ((7 duck), celery))
UNPACK 4
UNPACK 5
UNPACK 6
? COUNT DUCK
? MIN duck
Plain text

خروجی نمونه ۳🔗

OK
2
2
1
-1
DISCARD
DISCARD
OK , 1 container added.
DISCARD
OK
0
0
1
1
OK
OK , 2 containers added.
OK , No containers added.
OK , 1 container added.
8
0
Plain text

L - Rolling-Dice Puzzle


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Sarina and her brother, Soroush, are playing the rolling-dice game. The game is played on an n×mn \times m board. Initially, Soroush places a standard dice in one of the cells. It is place in a way that the number 6 is on the upper face, the number 4 is on the north face, and the number 2 is on the west face. In a standard dice, 6 is on the opposite side of 1, 2 is on the opposite side of 5, and 3 is on the opposite side of 4. Additionally, he selects some of the cells and writes arbitrary integers numbers from 1 to 6 in them.

توضیح تصویر

After that, Sarina have to move the dice on the board by rolling it multiple times. The act of rolling is defined as follows: Suppose two adjacent cells AA and BB share an edge e and the dice is on the cell AA; The dice can be rolled around its edge incident to e and moved from AA to BB. For example, consider the starting position of the dice. If the dice is rolled around the east, west, north, and south edges, the number appearing on the top face after rolling will be 22, 55, 33, and 44, respectively.

Whenever Sarina moves the dice to a a cell with a number in it in such a way that the number on the upper face of the dice matches the number in that cell, she gets a point. Note that Sarina can get a point from each cell at most one. The game is not that simple! There are obstacles in some of the cells and it is not possible to move the dice to the cells with an obstacle in it. Your task is to find out the maximum points that Sarina can get.

ورودی🔗

The first line of input contains two integers nn and mm, indicating the number of rows and columns of the board, respectively. Each of the next nn lines contain mm characters, describing the board. Empty cells are represented by . and obstacles are represented by x. The starting position of the dice is represented by s and the selected cells are represented by the integers written in them (from 1 to 6). It is guaranteed that there is only one s in the input.

1n,m1001 \leq n, m \leq 100

خروجی🔗

Output a line containing the maximum points Sarina can get.

مثال🔗

ورودی نمونه ۱🔗

3 4
.23s
4.2x
xx.1
Plain text

خروجی نمونه ۱🔗

5
Plain text

ورودی نمونه ۲🔗

2 2
4s
22
Plain text

خروجی نمونه ۲🔗

1
Plain text

M - Colorful Intervals


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

The Museum of Contemporary Art is holding a painting gallery focused on modern art, especially Monochromatic style paintings, which use only a single color. The gallery displays nn paintings arranged in a line.

The ICPC wants to bring students on an excursion to the gallery to spark their interest in art. However, the students are programmers, and everyone knows programmers only care about the colors of these modern paintings. They are also somewhat impatient. To keep their attention and to ensure they see every color without overwhelming them, the organizer decided to show them exactly two intervals of painting. This approach balances their short attention span and ensures all colors are represented. The task is to find two intervals of paintings such that each color appears at least once in at least one of the intervals, and the total number of paintings the students need to see is minimized.

ورودی🔗

The input consists of a single line containing a non-negative integer nn, indicating the number of paintings. This is followed by nn lines, each containing a string representing the color of a painting. Each color is represented by a non-empty lowercase string with a length of less than 20. It is guaranteed that there are at least 2 and at most 50 different colors in the input.

2n20002 \leq n \leq 2000

خروجی🔗

In the output, print the minimum number of paintings the ICPC students need to see, which is the sum of the lengths of the two intervals.

مثال‌ها🔗

ورودی نمونه ۱🔗

5
blue
red
blue
black
red
Plain text

خروجی نمونه ۱🔗

3
Plain text

ورودی نمونه ۲🔗

8
peachfuzz
livingcoral
livingcoral
teal
teal
livingcoral
livingcoral
coral
Plain text

خروجی نمونه ۲🔗

5
Plain text