question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of ...
Solve the programming task below in a Python markdown code block. Drazil is playing a math game with Varda. Let's define <image> for positive integer x as a product of factorials of its digits. For example, <image>. First, they choose a decimal number a consisting of n digits that contains at least one digit larger ...
Solve the programming task below in a Python markdown code block. The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided tha...
Solve the programming task below in a Python markdown code block. HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order. One of the problems of HDD hard drives is the following:...
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi. The way to split up game pieces is split into several steps: 1. First, Alice will split the pieces...
Solve the programming task below in a Python markdown code block. For a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct subsequences of a (including the empty subsequence). You are given two positive integers n and m. Let S be the set of all sequences of length n consisting ...
Solve the programming task below in a Python markdown code block. Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to tripl...
Solve the programming task below in a Python markdown code block. Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, b2,...
Solve the programming task below in a Python markdown code block. Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level. Ivan decided that there should be exactly ni vertices in the graph r...
Solve the programming task below in a Python markdown code block. You are given n Γ— m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 2. Every two cells in a set share row or column. Input The first line ...
Solve the programming task below in a Python markdown code block. Programmer Vasya is studying a new programming language &K*. The &K* language resembles the languages of the C family in its syntax. However, it is more powerful, which is why the rules of the actual C-like languages are unapplicable to it. To fully und...
Solve the programming task below in a Python markdown code block. Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex u is called a child of vertex v and vertex v is called a parent of vertex u if there exists a directed edge from v to u. A vertex ...
Solve the programming task below in a Python markdown code block. Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The world can be represented by the first ...
Solve the programming task below in a Python markdown code block. You are given a following process. There is a platform with n columns. 1 Γ— 1 squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will ...
Solve the programming task below in a Python markdown code block. Polycarp lives on a coordinate line at the point x = 0. He goes to his friend that lives at the point x = a. Polycarp can move only from left to right, he can pass one unit of length each second. Now it's raining, so some segments of his way are in the...
Solve the programming task below in a Python markdown code block. The Monk learned about priority queues recently and asked his teacher for an interesting problem. So his teacher came up with a simple problem. He now has an integer array A. For each index i, he wants to find the product of the largest, second largest ...
Solve the programming task below in a Python markdown code block. Recently in a class of Computer Networks, little Roy learned to calculate Hamming Distance between two strings of equal length. During practical session, Roy's teacher gave him a string of length L with all distinct characters. Teacher asked him to fin...
Solve the programming task below in a Python markdown code block. We have N logs of lengths A_1,A_2,\cdots A_N. We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t. Find the shortest poss...
Solve the programming task below in a Python markdown code block. We have N+M balls, each of which has an integer written on it. It is known that: * The numbers written on N of the balls are even. * The numbers written on M of the balls are odd. Find the number of ways to choose two of the N+M balls (disregarding ...
Solve the programming task below in a Python markdown code block. There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid. When the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1). In how many ways can the knight reach the square (X, Y)? Find the number...
Solve the programming task below in a Python markdown code block. Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs. Let the current time be time 0. Kizahashi has N jobs numbered 1 to N. It takes A_i units of tim...
Solve the programming task below in a Python markdown code block. We will play a one-player game using a number line and N pieces. First, we place each of these pieces at some integer coordinate. Here, multiple pieces can be placed at the same coordinate. Our objective is to visit all of the M coordinates X_1, X_2,...
Solve the programming task below in a Python markdown code block. Mr. Infinity has a string S consisting of digits from `1` to `9`. Each time the date changes, this string changes as follows: * Each occurrence of `2` in S is replaced with `22`. Similarly, each `3` becomes `333`, `4` becomes `4444`, `5` becomes `55555...
Solve the programming task below in a Python markdown code block. Write a program which replace all the lower-case letters of a given text with the corresponding captital letters. Input A text including lower-case letters, periods, and space is given in a line. The number of characters in the text is less than or ...
Solve the programming task below in a Python markdown code block. problem You are a traveler traveling on the JOI Highway. The JOI Highway is a road that extends straight from east to west, and there are n post towns on the JOI Highway. Numbered. The westernmost post town on the JOI highway is post town 1, and the ea...
Solve the programming task below in a Python markdown code block. Cosmic market, commonly known as Kozumike, is the largest coterie spot sale in the universe. Doujin lovers of all genres gather at Kozumike. In recent years, the number of visitors to Kozumike has been increasing. If everyone can enter from the beginnin...
Solve the programming task below in a Python markdown code block. Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many cats in his garden. The cats were so cute that people in the village also loved them. One day, an evil witch visited the village. She envied the cats for being loved by ever...
Solve the programming task below in a Python markdown code block. Problem Statement You are now participating in the Summer Training Camp for Programming Contests with your friend Jiro, who is an enthusiast of the ramen chain SIRO. Since every SIRO restaurant has its own tasteful ramen, he wants to try them at as man...
Solve the programming task below in a Python markdown code block. Points:10 The Indian Heights School believes that learning with the aid of technology is the fastest way to do so. It is a pioneer in innovation and virtual classrooms in the country. Keeping in accordance with its practices, the school wants to integra...
Solve the programming task below in a Python markdown code block. There are n points on the plane, (x_1,y_1), (x_2,y_2), …, (x_n,y_n). You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). C...
Solve the programming task below in a Python markdown code block. Polycarp took n videos, the duration of the i-th video is a_i seconds. The videos are listed in the chronological order, i.e. the 1-st video is the earliest, the 2-nd video is the next, ..., the n-th video is the last. Now Polycarp wants to publish exa...
Solve the programming task below in a Python markdown code block. You are given a tree consisting exactly of n vertices. Tree is a connected undirected graph with n-1 edges. Each vertex v of this tree has a value a_v assigned to it. Let dist(x, y) be the distance between the vertices x and y. The distance between the...
Solve the programming task below in a Python markdown code block. An array of integers p_1, p_2, ..., p_n is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3, 1, 2], [1], [1, 2, 3, 4, 5] and [4, 3, 1, 2]. The following arrays are not permu...
Solve the programming task below in a Python markdown code block. You have a garden consisting entirely of grass and weeds. Your garden is described by an n Γ— m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell ...
Solve the programming task below in a Python markdown code block. You have a given picture with size w Γ— h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: * A "+" shape has one center nonempty cell. * There should be some (at least one) consecutive non-empty cells i...
Solve the programming task below in a Python markdown code block. Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exac...
Solve the programming task below in a Python markdown code block. Let's define a balanced multiset the following way. Write down the sum of all elements of the multiset in its decimal representation. For each position of that number check if the multiset includes at least one element such that the digit of the element...
Solve the programming task below in a Python markdown code block. You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor. You must paint a fence which consists of 10^{100} planks in...
Solve the programming task below in a Python markdown code block. Petya has come to the math exam and wants to solve as many problems as possible. He prepared and carefully studied the rules by which the exam passes. The exam consists of n problems that can be solved in T minutes. Thus, the exam begins at time 0 and ...
Solve the programming task below in a Python markdown code block. This is the easy version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task. You are given a string s, consisting of lowercase E...
Solve the programming task below in a Python markdown code block. Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly o...
Solve the programming task below in a Python markdown code block. You are given an array a[0 … n-1] of length n which consists of non-negative integers. Note that array indices start from zero. An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array...
Solve the programming task below in a Python markdown code block. Captain Flint and his crew keep heading to a savage shore of Byteland for several months already, drinking rum and telling stories. In such moments uncle Bogdan often remembers his nephew Denis. Today, he has told a story about how Denis helped him to c...
Solve the programming task below in a Python markdown code block. Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for...
Solve the programming task below in a Python markdown code block. This is an interactive problem. Alice and Bob are playing a game. There is nΓ— n grid, initially empty. We refer to the cell in row i and column j by (i, j) for 1≀ i, j≀ n. There is an infinite supply of tokens that come in 3 colors labelled 1, 2, and 3...
Solve the programming task below in a Python markdown code block. The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are...
Solve the programming task below in a Python markdown code block. Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are n drinks in his fridge, the volume fraction of orange juice in the i-th drink equals pi percent. One day Vasya decided ...
Solve the programming task below in a Python markdown code block. A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given cons...
Solve the programming task below in a Python markdown code block. In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the Donkey'...
Solve the programming task below in a Python markdown code block. It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≀ w2 ≀ ... ≀ wk holds. P...
Solve the programming task below in a Python markdown code block. There is a new TV game on BerTV. In this game two players get a number A consisting of 2n digits. Before each turn players determine who will make the next move. Each player should make exactly n moves. On it's turn i-th player takes the leftmost digit ...
Solve the programming task below in a Python markdown code block. Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, ..., lm (1 ≀ li ≀ n). For each number li he wants to know how...
Solve the programming task below in a Python markdown code block. Inna loves sweets very much. She has n closed present boxes lines up in a row in front of her. Each of these boxes contains either a candy (Dima's work) or nothing (Sereja's work). Let's assume that the boxes are numbered from 1 to n, from left to right...
Solve the programming task below in a Python markdown code block. The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of...
Solve the programming task below in a Python markdown code block. Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother. As Devu is really a naughty kid, he wants th...
Solve the programming task below in a Python markdown code block. Notice that the memory limit is non-standard. Recently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about correct bracket sequences, so he even got himself a favorite correct brack...
Solve the programming task below in a Python markdown code block. One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior. We will call perso...
Solve the programming task below in a Python markdown code block. You are given an array of positive integers a1, a2, ..., an Γ— T of length n Γ— T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array. Input The first line contains two space...
Solve the programming task below in a Python markdown code block. Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction <image> as a sum of three distinct positive fractions in form <image>. Help Vladik with that, i.e for a given ...
Solve the programming task below in a Python markdown code block. A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them. The playing area in the game is split into congruent cells that are regular hexagons. The side of each ce...
Solve the programming task below in a Python markdown code block. At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Vale...
Solve the programming task below in a Python markdown code block. One very important person has a piece of paper in the form of a rectangle a Γ— b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi Γ— yi. Each impression must be parallel to the sides of the piec...
Solve the programming task below in a Python markdown code block. Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden. The game consists of several turns. At each turn the participant te...
Solve the programming task below in a Python markdown code block. A flower shop has got n bouquets, and the i-th bouquet consists of ai flowers. Vasya, the manager of the shop, decided to make large bouquets from these bouquets. Vasya thinks that a bouquet is large if it is made of two or more initial bouquets, and ...
Solve the programming task below in a Python markdown code block. Aarav has just graduated from the university. Now he is going to travel along his country. More precisely: there are N cities with integer coordinates. His plan is to travel between each pair of the cities. The distance between city A with coordinates...
Solve the programming task below in a Python markdown code block. Each digit of a number is represented by a cluster of adjacent X, with spaces between neighboring clusters. The digit is determined by the number of X in the cluster. For example, the number 243 would be represented by the following pattern -XX-XXX...
Solve the programming task below in a Python markdown code block. There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points? Here, the Manhattan distance between t...
Solve the programming task below in a Python markdown code block. Given is an integer N. Find the number of positive integers less than or equal to N that have an odd number of digits (in base ten without leading zeros). Constraints * 1 \leq N \leq 10^5 Input Input is given from Standard Input in the following for...
Solve the programming task below in a Python markdown code block. You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * Th...
Solve the programming task below in a Python markdown code block. We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i. In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weig...
Solve the programming task below in a Python markdown code block. We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, a...
Solve the programming task below in a Python markdown code block. There is a frequency operation in the conversion operation of a finite number sequence. The conversion result of the sequence $ S = \\ {s_1, s_2, ... s_n \\} $ is a sequence of the same length. If the result is $ C = \\ {c_1, c_2, ..., c_n \\} $, then $...
Solve the programming task below in a Python markdown code block. Mobile phones are equipped with a function that displays input candidates in order to efficiently input texts such as emails. This records frequently used words and presents words that have the entered letters as initial letters as input candidates. For...
Solve the programming task below in a Python markdown code block. Two players, A and B, play the game using cards with numbers from 0 to 9. First, the two arrange the given n cards face down in a horizontal row. After that, the two players turn their cards face up one by one from the left, and the owner of the card wi...
Solve the programming task below in a Python markdown code block. Professor Random, known for his research on randomized algorithms, is now conducting an experiment on biased dice. His experiment consists of dropping a number of dice onto a plane, one after another from a fixed position above the plane. The dice fall ...
Solve the programming task below in a Python markdown code block. The goddess of programming is reviewing a thick logbook, which is a yearly record of visitors to her holy altar of programming. The logbook also records her visits at the altar. The altar attracts programmers from all over the world because one visitor...
Solve the programming task below in a Python markdown code block. Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams from outside of the screen. A laser beam is a straight line with a certain thickness. Nathan moves a circular-shaped machine within the screen, in such a way i...
Solve the programming task below in a Python markdown code block. The range search problem consists of a set of attributed records S to determine which records from S intersect with a given range. For n points on a plane, report a set of points which are within in a given range. Note that you do not need to consider ...
Solve the programming task below in a Python markdown code block. Vasya has got a magic matrix a of size n Γ— m. The rows of the matrix are numbered from 1 to n from top to bottom, the columns are numbered from 1 to m from left to right. Let a_{ij} be the element in the intersection of the i-th row and the j-th column....
Solve the programming task below in a Python markdown code block. You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily 8 Γ— 8, but it still is N Γ— N. Each square has some number written on it, all the numbers are from 1 to N^2 and all the numbers are pairwise distinct. The j-th...
Solve the programming task below in a Python markdown code block. You're given an array a. You should repeat the following operation k times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0. Input The...
Solve the programming task below in a Python markdown code block. Today at the lesson of mathematics, Petya learns about the digital root. The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous itera...
Solve the programming task below in a Python markdown code block. Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible. There are n manholes in the room which are...
Solve the programming task below in a Python markdown code block. There are n shovels in the nearby shop. The i-th shovel costs a_i bourles. Misha has to buy exactly k shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of rem...
Solve the programming task below in a Python markdown code block. Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 β‹… 10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations: 1. Firstly, le...
Solve the programming task below in a Python markdown code block. Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. 2 β‹… n students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly n people in each...
Solve the programming task below in a Python markdown code block. You're given an undirected graph with n nodes and m edges. Nodes are numbered from 1 to n. The graph is considered harmonious if and only if the following property holds: * For every triple of integers (l, m, r) such that 1 ≀ l < m < r ≀ n, if there...
Solve the programming task below in a Python markdown code block. You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other w...
Solve the programming task below in a Python markdown code block. In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string s starting f...
Solve the programming task below in a Python markdown code block. Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary program...
Solve the programming task below in a Python markdown code block. There is an undirected tree of n vertices, connected by n-1 bidirectional edges. There is also a snake stuck inside of this tree. Its head is at vertex a and its tail is at vertex b. The snake's body occupies all vertices on the unique simple path betwe...
Solve the programming task below in a Python markdown code block. There is a square of size 10^6 Γ— 10^6 on the coordinate plane with four points (0, 0), (0, 10^6), (10^6, 0), and (10^6, 10^6) as its vertices. You are going to draw segments on the plane. All segments are either horizontal or vertical and intersect wit...
Solve the programming task below in a Python markdown code block. For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way: * Consider a graph on k nodes, with numbers from b_1 to b_k written on them. * For every i from 1 to k: find such j (1 ≀ j ...
Solve the programming task below in a Python markdown code block. You are given an array a_1, a_2, …, a_n consisting of n positive integers and a positive integer m. You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want. Let's call an array m-divisible if...
Solve the programming task below in a Python markdown code block. There are three cells on an infinite 2-dimensional grid, labeled A, B, and F. Find the length of the shortest path from A to B if: * in one move you can go to any of the four adjacent cells sharing a side; * visiting the cell F is forbidden (it i...
Solve the programming task below in a Python markdown code block. Polycarpus is an amateur programmer. Now he is analyzing a friend's program. He has already found there the function rangeIncrement(l, r), that adds 1 to each element of some array a for all indexes in the segment [l, r]. In other words, this function d...
Solve the programming task below in a Python markdown code block. Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody ...
Solve the programming task below in a Python markdown code block. You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes touched with the sides that had the same number o...
Solve the programming task below in a Python markdown code block. Special Agent Smart Beaver works in a secret research department of ABBYY. He's been working there for a long time and is satisfied with his job, as it allows him to eat out in the best restaurants and order the most expensive and exotic wood types ther...
Solve the programming task below in a Python markdown code block. Consider a table G of size n Γ— m such that G(i, j) = GCD(i, j) for all 1 ≀ i ≀ n, 1 ≀ j ≀ m. GCD(a, b) is the greatest common divisor of numbers a and b. You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs ...