Lunatic Never Content Solution Codeforces

You have an array a� of n� non-negative integers. Let’s define f(a,x)=[a1modx,a2modx,…,anmodx]�(�,�)=[�1mod�,�2mod�,…,��mod�] for some positive integer x�. Find the biggest x�, such that f(a,x)�(�,�) is a palindrome. Here, amodx�mod� is the remainder of the integer division of a� by x�. An array is a palindrome if it reads the same backward as forward. More formally, an array a� of length n� is a palindrome if for every i� (1≤i≤n1≤�≤�) ai=an−i+1��=��−�+1. Lunatic Never Content Solution Codeforces The first … Read more

Dreaming of Freedom Solution Codeforces

There are n� programmers choosing their favorite algorithm amongst m� different choice options. Before the first round, all m� options are available. In each round, every programmer makes a vote for one of the remaining algorithms. After the round, only the algorithms with the maximum number of votes remain. The voting process ends when there is only one option left. Determine … Read more

Running Miles solution codeforces

There is a street with n� sights, with sight number i� being i� miles from the beginning of the street. Sight number i� has beauty bi��. You want to start your morning jog l� miles and end it r� miles from the beginning of the street. By the time you run, you will see sights you run by (including sights at l� and r� miles from the start). You are interested in … Read more

Walk the Runway Solution Codeforces

A fashion tour consists of m� identical runway shows in different cities. There are n� models willing to participate in the tour, numbered from 11 to n�. People in different cities have different views on the fashion industry, so they rate each model differently. In particular, people in city i� rate model j� with rating ri,j��,�. You are to choose some number of k� models, and their order, let … Read more

Fading into Fog Solution Codeforces

This is an interactive problem. There are n� distinct hidden points with real coordinates on a two-dimensional Euclidean plane. In one query, you can ask some line ax+by+c=0��+��+�=0 and get the projections of all n� points to this line in some order. The given projections are not exact, please read the interaction section for more clarity. Using the minimum number of … Read more

TubeTube Feed solution codeforces

Mushroom Filippov cooked himself a meal and while having his lunch, he decided to watch a video on TubeTube. He can not spend more than t� seconds for lunch, so he asks you for help with the selection of video. The TubeTube feed is a list of n� videos, indexed from 11 to n�. The i�-th video lasts ai�� seconds and has an entertainment value bi��. Initially, the feed … Read more

Karina and Array solution codeforces

Karina has an array of n� integers a1,a2,a3,…,an�1,�2,�3,…,��. She loves multiplying numbers, so she decided that the beauty of a pair of numbers is their product. And the beauty of an array is the maximum beauty of a pair of adjacent elements in the array. For example, for n=4�=4, a=[3,5,7,4]�=[3,5,7,4], the beauty of the array is maxmax(3⋅53⋅5, 5⋅75⋅7, 7⋅47⋅4) = maxmax(1515, 3535, 2828) = 3535. Karina wants her array to be as beautiful as possible. In order to achieve … Read more

Bun Lover solution codeforces

Tema loves cinnabon rolls — buns with cinnabon and chocolate in the shape of a “snail”. Cinnabon rolls come in different sizes and are square when viewed from above. The most delicious part of a roll is the chocolate, which is poured in a thin layer over the cinnabon roll in the form of a … Read more

Super-Permutation solution codeforces

A permutation is a sequence n� integers, where each integer from 11 to n� appears exactly once. For example, [1][1], [3,5,2,1,4][3,5,2,1,4], [1,3,2][1,3,2] are permutations, while [2,3,2][2,3,2], [4,3,1][4,3,1], [0][0] are not. Given a permutation a�, we construct an array b�, where bi=(a1+a2+ … +ai)modn��=(�1+�2+ … +��)mod�. A permutation of numbers [a1,a2,…,an][�1,�2,…,��] is called a super-permutation if [b1+1,b2+1,…,bn+1][�1+1,�2+1,…,��+1] is also a permutation of length n�. Grisha became interested whether a super-permutation of length n� exists. Help him solve this non-trivial problem. Output any super-permutation of length n�, if it exists. Otherwise, output −1−1. … Read more

Making Anti-Palindromes solution codeforces

You are given a string s�, consisting of lowercase English letters. In one operation, you are allowed to swap any two characters of the string s�. A string s� of length n� is called an anti-palindrome, if s[i]≠s[n−i+1]�[�]≠�[�−�+1] for every i� (1≤i≤n1≤�≤�). For example, the strings “codeforces”, “string” are anti-palindromes, but the strings “abacaba”, “abc”, “test” are not. Determine the minimum number of operations required to make the string s� an anti-palindrome, or output −1−1, if this is … Read more