question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k. Unfortunately, he doesn't know any such table. Y...
Solve the programming task below in a Python markdown code block. Little Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix. The dot product of two integer number vectors x and y of size n is the sum of the products of the corresponding components...
Solve the programming task below in a Python markdown code block. You have a string s = s1s2...s|s|, where |s| is the length of string s, and si its i-th character. Let's introduce several definitions: * A substring s[i..j] (1 ≀ i ≀ j ≀ |s|) of string s is string sisi + 1...sj. * The prefix of string s of leng...
Solve the programming task below in a Python markdown code block. Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single ste...
Solve the programming task below in a Python markdown code block. New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 Γ— n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People want...
Solve the programming task below in a Python markdown code block. Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '<image>', and the arguments and the...
Solve the programming task below in a Python markdown code block. There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine th...
Solve the programming task below in a Python markdown code block. Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people....
Solve the programming task below in a Python markdown code block. Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack eac...
Solve the programming task below in a Python markdown code block. Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as follows: in the morning he should leave the house and go to some post offi...
Solve the programming task below in a Python markdown code block. Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror refle...
Solve the programming task below in a Python markdown code block. ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length s...
Solve the programming task below in a Python markdown code block. A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in t...
Solve the programming task below in a Python markdown code block. Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row...
Solve the programming task below in a Python markdown code block. It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive n...
Solve the programming task below in a Python markdown code block. You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array. For some indices i (1 ≀ i ≀ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is not possible. You may perform any...
Solve the programming task below in a Python markdown code block. Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us deno...
Solve the programming task below in a Python markdown code block. Fatland is a town that started with N distinct empires, namely empires 1, 2, ..., N. But over time, the armies of some of these empires have taken over other ones. Each takeover occurred when the army of empire i invaded empire j. After each invasion, a...
Solve the programming task below in a Python markdown code block. A Magic Fraction for N is one that has the following properties: It is a proper fraction (The value is < 1) It cannot be reduced further (The GCD of the numerator and the denominator is 1) The product of the numerator and the denominator is factorial of...
Solve the programming task below in a Python markdown code block. Our hero - Maga is going to make a new contest for making the best teams. He is really excited about it. There will be S students in the contest. First N students in the final standings will be awarded. He has a list( favourite students list ) what co...
Solve the programming task below in a Python markdown code block. Recently Watson learned the concept of coprime numbers and now he wonders given an array A1, A2 . . . AN what is the size of the largest subset of the array such that the each pair of elements in the subset is coprime. Watson asks Sherlock for help and...
Solve the programming task below in a Python markdown code block. Xenny had a list of N strings of equal length. He wanted to sort them by the first M characters only. That means, while sorting the list of strings, he only wanted to consider the first M characters of each string. Help Xenny to find out the K^th string...
Solve the programming task below in a Python markdown code block. Given is a sequence of integers A_1, A_2, ..., A_N. If its elements are pairwise distinct, print `YES`; otherwise, print `NO`. Constraints * 2 ≀ N ≀ 200000 * 1 ≀ A_i ≀ 10^9 * All values in input are integers. Input Input is given from Standard Input...
Solve the programming task below in a Python markdown code block. Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m h...
Solve the programming task below in a Python markdown code block. You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y. Here, we would like to maximize the number of different letters contained in both X and Y. Find the largest p...
Solve the programming task below in a Python markdown code block. Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. H...
Solve the programming task below in a Python markdown code block. Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly pe...
Solve the programming task below in a Python markdown code block. Aizuwakamatsu City is known as the "City of History". About 400 years ago, the skeleton of the castle town was created by Gamo Ujisato, but after that, it became the central city of the Aizu clan 230,000 stones, whose ancestor was Hoshina Masayuki, the ...
Solve the programming task below in a Python markdown code block. In 40XX, the Earth was invaded by aliens! Already most of the Earth has been dominated by aliens, leaving Tsuruga Castle Fortress as the only remaining defense base. Suppression units are approaching the Tsuruga Castle Fortress one after another. <imag...
Solve the programming task below in a Python markdown code block. You are given a string and a number k. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to k times. Write a program to report the lexicographically smallest string among them. Input The input is ...
Solve the programming task below in a Python markdown code block. An art exhibition will be held in JOI. At the art exhibition, various works of art from all over the country will be exhibited. N works of art were collected as candidates for the works of art to be exhibited. These works of art are numbered 1, 2, ...,...
Solve the programming task below in a Python markdown code block. Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system. The letters "m", "c"...
Solve the programming task below in a Python markdown code block. Your task in this problem is to create a program that finds the shortest path between two given locations on a given street map, which is represented as a collection of line segments on a plane. <image> Figure 4 is an example of a street map, where so...
Solve the programming task below in a Python markdown code block. N people run a marathon. There are M resting places on the way. For each resting place, the i-th runner takes a break with probability P_i percent. When the i-th runner takes a break, he gets rest for T_i time. The i-th runner runs at constant speed V_...
Solve the programming task below in a Python markdown code block. You are a secret agent from the Intelligence Center of Peacemaking Committee. You've just sneaked into a secret laboratory of an evil company, Automated Crime Machines. Your mission is to get a confidential document kept in the laboratory. To reach the...
Solve the programming task below in a Python markdown code block. You received a card with an integer $S$ and a multiplication table of infinite size. All the elements in the table are integers, and an integer at the $i$-th row from the top and the $j$-th column from the left is $A_{i,j} = i \times j$ ($i,j \geq 1$). ...
Solve the programming task below in a Python markdown code block. For given two segments s1 and s2, print the distance between them. s1 is formed by end points p0 and p1, and s2 is formed by end points p2 and p3. Constraints * 1 ≀ q ≀ 1000 * -10000 ≀ xpi, ypi ≀ 10000 * p0 β‰  p1 and p2 β‰  p3. Input The entire input ...
Solve the programming task below in a Python markdown code block. Write a program which reads a sequence of integers $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and reverse specified elements by a list of the following operation: * reverse($b, e$): reverse the order of $a_b, a_{b+1}, ..., a_{e-1}$ Constraints * $1 \leq n \l...
Solve the programming task below in a Python markdown code block. You are looking at the floor plan of the Summer Informatics School's new building. You were tasked with SIS logistics, so you really care about travel time between different locations: it is important to know how long it would take to get from the lectu...
Solve the programming task below in a Python markdown code block. Acingel is a small town. There was only one doctor here β€” Miss Ada. She was very friendly and nobody has ever said something bad about her, so who could've expected that Ada will be found dead in her house? Mr Gawry, world-famous detective, is appointed...
Solve the programming task below in a Python markdown code block. Vova's house is an array consisting of n elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The i-th element of the array is 1 if there is a heater in the position i, ...
Solve the programming task below in a Python markdown code block. Vasya got really tired of these credits (from problem F) and now wants to earn the money himself! He decided to make a contest to gain a profit. Vasya has n problems to choose from. They are numbered from 1 to n. The difficulty of the i-th problem is d...
Solve the programming task below in a Python markdown code block. You are given an array a consisting of n integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-...
Solve the programming task below in a Python markdown code block. Alice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are n parties, numbered from 1 to n. The i-th party has received a_i seats in the parliament. Alice's party ...
Solve the programming task below in a Python markdown code block. Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and...
Solve the programming task below in a Python markdown code block. Polycarp is reading a book consisting of n pages numbered from 1 to n. Every time he finishes the page with the number divisible by m, he writes down the last digit of this page number. For example, if n=15 and m=5, pages divisible by m are 5, 10, 15. T...
Solve the programming task below in a Python markdown code block. Alice got a new doll these days. It can even walk! Alice has built a maze for the doll and wants to test it. The maze is a grid with n rows and m columns. There are k obstacles, the i-th of them is on the cell (x_i, y_i), which means the cell in the in...
Solve the programming task below in a Python markdown code block. This is the harder version of the problem. In this version, 1 ≀ n ≀ 10^6 and 0 ≀ a_i ≀ 10^6. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems Christmas is coming, and our protagonist, Bo...
Solve the programming task below in a Python markdown code block. You are given two integers a and b. You can perform a sequence of operations: during the first operation you choose one of these numbers and increase it by 1; during the second operation you choose one of these numbers and increase it by 2, and so on. Y...
Solve the programming task below in a Python markdown code block. You are given a string s consisting of lowercase Latin letters. Let the length of s be |s|. You may perform several operations on this string. In one operation, you can choose some index i and remove the i-th character of s (s_i) if at least one of its...
Solve the programming task below in a Python markdown code block. Denis, after buying flowers and sweets (you will learn about this story in the next task), went to a date with Nastya to ask her to become a couple. Now, they are sitting in the cafe and finally... Denis asks her to be together, but ... Nastya doesn't g...
Solve the programming task below in a Python markdown code block. Among Johnny's numerous hobbies, there are two seemingly harmless ones: applying bitwise operations and sneaking into his dad's office. As it is usually the case with small children, Johnny is unaware that combining these two activities can get him in a...
Solve the programming task below in a Python markdown code block. This is the hard version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings a and b of length...
Solve the programming task below in a Python markdown code block. You have given an array a of length n and an integer x to a brand new robot. What the robot does is the following: it iterates over the elements of the array, let the current element be q. If q is divisible by x, the robot adds x copies of the integer q...
Solve the programming task below in a Python markdown code block. You are given n rectangles, each of height 1. Each rectangle's width is a power of 2 (i. e. it can be represented as 2^x for some non-negative integer x). You are also given a two-dimensional box of width W. Note that W may or may not be a power of 2....
Solve the programming task below in a Python markdown code block. Polycarp has 26 tasks. Each task is designated by a capital letter of the Latin alphabet. The teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distracted b...
Solve the programming task below in a Python markdown code block. You are given an array of positive integers a = [a_0, a_1, ..., a_{n - 1}] (n β‰₯ 2). In one step, the array a is replaced with another array of length n, in which each element is the [greatest common divisor (GCD)](http://tiny.cc/tuy9uz) of two neighbor...
Solve the programming task below in a Python markdown code block. The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to...
Solve the programming task below in a Python markdown code block. Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network a...
Solve the programming task below in a Python markdown code block. Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing bal...
Solve the programming task below in a Python markdown code block. Xenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a. Namely, it takes se...
Solve the programming task below in a Python markdown code block. A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares...
Solve the programming task below in a Python markdown code block. Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest. Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it i...
Solve the programming task below in a Python markdown code block. One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (str...
Solve the programming task below in a Python markdown code block. There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules: * Red-green tower is consisting of some number of levels; * Let the red-green tower consist of n levels, then the first ...
Solve the programming task below in a Python markdown code block. Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit ...
Solve the programming task below in a Python markdown code block. You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes. Note that you should find only the time after a minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here <h...
Solve the programming task below in a Python markdown code block. The term of this problem is the same as the previous one, the only exception β€” increased restrictions. Input The first line contains two positive integers n and k (1 ≀ n ≀ 100 000, 1 ≀ k ≀ 109) β€” the number of ingredients and the number of grams of th...
Solve the programming task below in a Python markdown code block. R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "Th...
Solve the programming task below in a Python markdown code block. <image> Input The input consists of four lines, each line containing a single digit 0 or 1. Output Output a single digit, 0 or 1. Example Input 0 1 1 0 Output 0 The input will be give Read the inputs from stdin solve the problem and write th...
Solve the programming task below in a Python markdown code block. We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum nu...
Solve the programming task below in a Python markdown code block. It is known that passages in Singer house are complex and intertwined. Let's define a Singer k-house as a graph built by the following process: take complete binary tree of height k and add edges from each vertex to all its successors, if they are not y...
Solve the programming task below in a Python markdown code block. Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path...
Solve the programming task below in a Python markdown code block. Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that ever...
Solve the programming task below in a Python markdown code block. Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivi...
Solve the programming task below in a Python markdown code block. You are given an undirected graph consisting of n vertices and m edges. Your task is to find the number of connected components which are cycles. Here are some definitions of graph theory. An undirected graph consists of two sets: set of nodes (called...
Solve the programming task below in a Python markdown code block. Chandu has been appointed as the superintendent of a jail having N prisoners . Prisoner are numbered form 1 to N. Today he has been specially invited to execute the prisoners. All the prisoners are arranged in circle and he starts executing them in cl...
Solve the programming task below in a Python markdown code block. As the league stage of the world cup has come to its end, its time to calculate the highest points earned in the league stage by a team. There are many teams playing in the world cup. A team is awarded 3 points for a win, 1 point for a tie and it loses...
Solve the programming task below in a Python markdown code block. Ramesh is a hard-working employee.Seeing his dedication towards his work his boss decided to promote him. Ramesh was overjoyed on getting to know this.But soon he realized he needed to shift to another Town X. Ramesh needed to transport his n boxes to T...
Solve the programming task below in a Python markdown code block. There are N temples in a straight line and K monks who want to spread their enlightening power to the entire road of temples. All the monks have an enlightenment value, which denotes the range of enlightenment which they can spread in both the directio...
Solve the programming task below in a Python markdown code block. We have N boxes numbered 1 to N, and M balls numbered 1 to M. Currently, Ball i is in Box A_i. You can do the following operation: * Choose a box containing two or more balls, pick up one of the balls from that box, and put it into another box. Sin...
Solve the programming task below in a Python markdown code block. Raccoon is fighting with a monster. The health of the monster is H. Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i. There is no other way to decrease the monster's health. Raccoon wins when the mon...
Solve the programming task below in a Python markdown code block. Given is a permutation P of \\{1, 2, \ldots, N\\}. For a pair (L, R) (1 \le L \lt R \le N), let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R. Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R}. Constraints * 2 \le N...
Solve the programming task below in a Python markdown code block. You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beg...
Solve the programming task below in a Python markdown code block. N contestants participated in a competition. The total of N-1 matches were played in a knockout tournament. For some reasons, the tournament may not be "fair" for all the contestants. That is, the number of the matches that must be played in order to wi...
Solve the programming task below in a Python markdown code block. If the strings are consecutive, you can replace the characters with a rule to shorten the string. For example, for the string AAAA, the expression @ 4A will compress one character. Create a program that restores the character string compressed by this r...
Solve the programming task below in a Python markdown code block. Mr. A came to Aizu for sightseeing. You can overlook the Aizu Basin from the window of the hotel where you stayed. As I was looking at the scenery, I noticed a piece of the photo on the floor. Apparently I took the outside view from the window. "Which a...
Solve the programming task below in a Python markdown code block. Compute A + B. Constraints * -1000 ≀ A, B ≀ 1000 Input The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF. Output For each pair of input integers...
Solve the programming task below in a Python markdown code block. RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure B-1. <image> Figure B-1: Layout of the exchange lines A freight train consists of 2 ...
Solve the programming task below in a Python markdown code block. The mayor of Amida, the City of Miracle, is not elected like any other city. Once exhausted by long political struggles and catastrophes, the city has decided to leave the fate of all candidates to the lottery in order to choose all candidates fairly an...
Solve the programming task below in a Python markdown code block. Angry Birds is a mobile game of a big craze all over the world. You were convinced that it was a waste of time to play the game, so you decided to create an automatic solver. <image> You are describing a routine that optimizes the white bird's strateg...
Solve the programming task below in a Python markdown code block. In Manhattan, roads run where the x or y coordinate is an integer. Both Sunuke-kun's house and Sumeke-kun's house are on the road, and the straight line distance (Euclidean distance) is just d. Find the maximum value that can be considered as the shorte...
Solve the programming task below in a Python markdown code block. D: Sontaku (Surmise) Some twins like even numbers. Count how many even numbers are in $ N $ integers $ A_1, A_2, A_3, \ dots, A_N $. input The integer $ N $ is given on the first line. On the second line, $ N $ integers $ A_1, A_2, A_3, \ dots, A_N...
Solve the programming task below in a Python markdown code block. Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the...
Solve the programming task below in a Python markdown code block. A sequence a_1, a_2, ..., a_n is called good if, for each element a_i, there exists an element a_j (i β‰  j) such that a_i+a_j is a power of two (that is, 2^d for some non-negative integer d). For example, the following sequences are good: * [5, 3, 11...
Solve the programming task below in a Python markdown code block. You are given a string t consisting of n lowercase Latin letters and an integer number k. Let's define a substring of some string s with indices from l to r as s[l ... r]. Your task is to construct such string s of minimum possible length that there a...
Solve the programming task below in a Python markdown code block. In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely. Lesha knows that today he can s...
Solve the programming task below in a Python markdown code block. Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left. There were n classes of that subject during the se...
Solve the programming task below in a Python markdown code block. Let f_{x} = c^{2x-6} β‹… f_{x-1} β‹… f_{x-2} β‹… f_{x-3} for x β‰₯ 4. You have given integers n, f_{1}, f_{2}, f_{3}, and c. Find f_{n} mod (10^{9}+7). Input The only line contains five integers n, f_{1}, f_{2}, f_{3}, and c (4 ≀ n ≀ 10^{18}, 1 ≀ f_{1}, f_{2...
Solve the programming task below in a Python markdown code block. Jack has become a soldier now. Unfortunately, he has trouble with the drill. Instead of marching beginning with the left foot and then changing legs with each step, as ordered, he keeps repeating a sequence of steps, in which he sometimes makes the wron...