Your friend has been hiking in Cabezón de cuadrícula (a small village); there, all the paths go from north to south or from east to west.
Your friend says he has walked a lot until he returned to where he started, but he doesn't know exactly how much. After a moment, he remembers that he has a notebook where he has noted down the path he has taken.
The description has the following format:
In the notebook, there are $$$n$$$ descriptions.
Unfortunately, some of the distances in the notebook have been lost due to the notebook getting wet in the rain.
Your friend asks you to find out what the minimum possible distance he has traveled is and what the maximum possible distance he has traveled is.
The first line contains an integer $$$T$$$, the number of cases.
Following are $$$T$$$ cases in the following format:
The first line contains an integer $$$n$$$.
The next $$$n$$$ lines contain the descriptions in order. Each description consists of two elements separated by a space:
The output consists of two integers separated by a space.
If the notes in the notebook cannot correspond to any path, print "-1 -1" (without quotes).
Otherwise, print the minimum and maximum distances separated by a space.
If the duration of the walk is possibly unlimited, print a $$$-1$$$ for the maximum duration.
42N 1S -12N -1S -11N -14N 1000000000S 1000000000N 1000000000S 1000000000
2 2 2 -1 -1 -1 4000000000 4000000000
Berta has a list of $$$n$$$ tasks. The $$$i$$$-th task requires $$$t_i$$$ seconds to be completed. Additionally, each task has a deadline $$$p_i$$$: the $$$i$$$-th task must be completed before more than $$$p_i + t_i$$$ seconds have passed since the start (therefore, it must be started at second $$$p_i$$$ or earlier).
Berta wants to perform the tasks strictly in the order they are written in her list, being able to skip some of them.
Help Berta determine the maximum number of tasks from her list that she can complete.
The first line contains an integer $$$T$$$, the number of cases to process.
Each case begins with a line containing an integer $$$n$$$, the number of tasks. This is followed by $$$n$$$ lines, the $$$i$$$-th of which contains the two integers $$$t_i$$$ and $$$p_i$$$.
For each case, print a line with the maximum number of tasks that can be completed.
352 01 11 12 23 4210000 1000000001 9999108 255 127 1011 283 186 3210 455 347 286 42
4 1 7
Encodelia quiere enviar un mensaje a Decodelio. El mensaje consiste en una cadena binaria de bits. Por desgracia, la malvada Errorlina interferirá en la comunicación. Errorlina seleccionará aleatoriamente un intervalo de bits contiguos de la cadena enviada por Encodelia y lo invertirá, es decir, cambiará los unos a ceros y los ceros a unos.
Por ejemplo, si Encodelia envía el mensaje 01011001, Errorlina puede seleccionar el intervalo
, de forma que Decodelio recibirá el mensaje 01100111.
Ayuda a Encodelia y a Decodelio a comunicarse pese a la interferencia de Errorlina. Tu programa se ejecutará tanto desde el punto de vista de Encodelia como de Decodelio: en el primer caso se te dará el mensaje que Encodelia quiere transmitir y debes imprimir una codificación del mensaje que enviar a Decodelio, y en el segundo recibirás la codificación tras la interferencia de Errorlina y debes recuperar el mensaje original.
Una posible secuencia de ejecuciones sería la siguiente. En la primera ejecución, la entrada es:
ENC 011
Y la salida que imprime el programa es:
01011001
En la segunda ejecución, la entrada es:
DEC 01100111
Nótese que se ha invertido un intervalo, como se ha explicado antes en el enunciado. La salida debería ser:
011
Este es un problema de ejecución múltiple. Por cada caso de prueba, tu programa se ejecutará dos veces seguidas de forma independiente.
En la primera ejecución, la entrada consistirá en una línea con la palabra ENC seguida de una cadena binaria, el mensaje que se quiere enviar. La palabra ENC y la cadena binaria están separadas por un espacio. Tu programa debe imprimir una línea con una cadena binaria, la codificación que se desea enviar.
En la segunda ejecución, la entrada consistirá en una línea con la palabra DEC seguida de una cadena binaria, el mensaje codificado recibido. La palabra DEC y la cadena binaria están separadas por un espacio. Tu programa debe imprimir una línea con una cadena binaria correspondiente al mensaje original.
Adicionalmente, la puntuación que obtienes depende de la longitud del mensaje codificado: para obtener una puntuación completa la longitud debe ser como máximo 2·104 bits y para obtener una puntuación positiva la longitud debe ser como máximo 105 bits. La puntuación de cada subtarea es multiplicada por un multiplicador
, donde
es la máxima longitud en bits de una de las codificaciones producidas en los casos de esa subtarea. El valor de
viene dado por:

La longitud del mensaje a codificar será de como mucho 104 bits.
La longitud de la codificación debe ser de como mucho 105 bits.
Tu programa será probado en un número limitado de casos de prueba. El intervalo de la codificación que se invertirá se seleccionará (pseudo)aleatoriamente de forma independiente en cada caso, con una distribución uniforme sobre todos los
intervalos posibles (donde
es la longitud de la codificación).
You are given a list $$$a = (a_1, \ldots, a_n)$$$ of $$$n$$$ non-negative integers, and you must answer $$$p$$$ queries of the form: given $$$k$$$, print the sum of values of $$$a$$$ at positions that are coprime to $$$k$$$. In other words, return the sum of values of $$$a_i$$$ for those $$$i$$$ such that $$$\text{gcd}(k, i) = 1$$$, where $$$\text{gcd}(k, i)$$$ is the greatest common divisor of $$$k$$$ and $$$i$$$.
The first line of the input contains the number of cases $$$T$$$.
Each case starts with a line of input with two integers $$$n$$$ and $$$p$$$, the size of $$$a$$$ and the number of queries.
The following line of each case contains $$$n$$$ integers $$$a_1, \ldots, a_n$$$.
The next line of each case contains $$$p$$$ integers, the values of $$$k$$$ for each of the queries.
For each case, you must print a line with $$$p$$$ integers, the answers to each of the queries.
34 41 1 1 11 2 3 410 43 9 2 3 4 5 5 0 2 17 1 3 28 11000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000000001
4 2 3 2 29 34 25 16 8000000000
Te has perdido por el instituto, y después de dar muchas vueltas acabas en una clase vacía, que contiene solamente un cartel y una pizarra con los números enteros a1, ..., an escritos en ella. En el cartel hay una lista de precios:
La primera línea contiene un entero T, el número de casos. Siguen T casos, cada uno con 3 líneas:
Para cada caso imprime en una línea un solo entero, el mínimo dinero que necesitas para que todos tus números favoritos aparezcan en la pizarra.
14 3 1 21 7 1 102 5 8
6
Tomorrow is Manuel's birthday, and you are preparing a surprise party for him. You are in charge of the decorations, but you are too lazy to go to the store. Fortunately, you already have a row of balloons left over from another birthday. To make it less obvious that they are the same, you plan to remove the balloons of a certain color and keep the rest. You have $$$n$$$ balloons arranged in a row, each of one of $$$2 \le k \le n$$$ colors. The color of the $$$i$$$-th balloon will be $$$1 \le a_i \le k$$$.
We will choose a color $$$c$$$ and pop all the balloons of that color. After popping them, there will be a new row of balloons that contains all the balloons that were not of color $$$c$$$, in the same order they were before the popping.
Manuel really likes consecutive segments of balloons of the same color. Therefore, you are interested in knowing for each color $$$c$$$ to pop what the maximum number of consecutive balloons of any color will remain after popping those of color $$$c$$$.
The first line contains an integer $$$T$$$, the number of cases. There are $$$T$$$ cases, each with $$$2$$$ lines:
For each case, you must print $$$k$$$ numbers in one line: The $$$i$$$-th is the answer when you remove color $$$i$$$.
17 31 1 2 1 2 3 1
2 3 2