The seventh codeforces competition ended #258Div2

Source: Internet
Author: User
This time I had two questions: A, B, and C. Then I had one problem (n % 3) and I was able to ac Q ^ Q cry ...... If C adds that line, how handsome it is ...... A. Timeout

This time I had two questions: A, B, and C. Then I had one problem (n % 3) and I was able to ac Q ^ Q cry ...... If C adds that line, how handsome it is ...... A. Game With Sticks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output After winni

This time I had two questions: A, B, and C. Then I had one problem (n % 3) and I was able to ac Q ^ Q cry ......

If C adds that line, how handsome it is ......


A. Game With Sticks

Time limit per test

1 second

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid madeNHorizontal andMVertical sticks.

An interp point is any point on the grid which is formed by the interp of one horizontal stick and one vertical stick.

In the grid shown below,N? =? 3 andM? =? 3. There areN? +?M? =? 6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There areN·M? =? 9 interp points, numbered from 1 to 9.

The rules of the game are very simple. the players move in turns. akshat won gold, so he makes the first move. during his/her move, a player must choose any remaining interp point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (I. e. there are no interp points remaining on the grid at his/her move ).

Assume that both players play optimally. Who will win the game?

Input

The first line of input contains two space-separated integers,NAndM(1? ≤?N,?M? ≤? 100 ).

Output

Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.

Sample test (s)

Input

2 2

Output

Malvika

Input

2 3

Output

Malvika

Input

3 3

Output

Akshat

Note

Explanation of the first sample:

The grid has four interp points, numbered from 1 to 4.

If Akshat chooses interp point 1, then he will remove two sticks (1? -? 2 and 1? -? 3). The resulting grid will look like this.

Now there is only one remaining interp point (I. e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.

In the empty grid, Akshat cannot make any move, hence he will lose.

Since all 4 interp points of the grid are equivalent, Akshat will lose no matter which one he picks.



This question means that there are so many sticks in the form of a grid. One person chooses an intersection to take the two sticks at a time, and there is no intersection to lose.

Because an intersection is composed of one vertical and one horizontal, each time a vertical and one horizontal are eliminated, it is natural that one of the vertical and horizontal ends after it is completed:

Code:
#include 
 
  #include 
  
    #include 
   
     #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include using namespace std;#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))int cmp(const void *a, const void *b){return(*(int *)a-*(int *)b);}int main(){int n,m;cin>>n>>m;cout<< (min(n,m)%2==0?"Malvika":"Akshat");return 0;}
         
        
       
      
     
    
   
  
 

B. Sort the Array

Time limit per test

1 second

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

Being a programmer, you like arrays a lot. For your birthday, your friends have given you an arrayAConsistingNDistinct integers.

Unfortunately, the sizeAIs too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the arrayA(In increasing order) by reversing exactly one segmentA? See definitions of segment and reversing in the notes.

Input

The first line of the input contains an integerN(1? ≤?N? ≤? 105)-the size of arrayA.

The second line containsNDistinct space-separated integers:A[1],?A[2],?...,?A[N] (1? ≤?A[I]? ≤? 109 ).

Output

Print "yes" or "no" (without quotes), depending on the answer.

If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. if there are multiple ways of selecting these indices, print any of them.

Sample test (s)

Input

33 2 1

Output

yes1 3

Input

42 1 3 4

Output

yes1 2

Input

43 1 2 4

Output

no

Input

21 2

Output

yes1 1

Note

Sample 1. You can reverse the entire array to get [1 ,? 2 ,? 3], which is sorted.

Sample 3. No segment can be reversed such that the array will be sorted.

Definitions

A segment [L,?R] Of arrayAIs the sequenceA[L],?A[L? +? 1],?...,?A[R].

If you have an arrayAOf sizeNAnd you reverse its segment [L,?R], The array will become:

A[1],?A[2],?...,?A[L? -? 2],?A[L? -? 1],?A[R],?A[R? -? 1],?...,?A[L? +? 1],?A[L],?A[R? +? 1],?A[R? +? 2],?...,?A[N? -? 1],?A[N].



Question B: there is an array. We can only select one of the consecutive array sequences in reverse order and ask if the entire array can be sorted in ascending order after one operation.

Use dp as the marker to find a reverse sequence of continuous descending order, and then check the reverse sequence for strict ascending order from time to time:

Code:
# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         
           # Include using namespace std; # define Max (a, B) (a)> (B )? (A) :( B) # define Min (a, B) (a) <(B )? (A) :( B) int a [100001]; int dp [100001]; int cmp (const void * a, const void * B) {return (* (int *) a-* (int *) B);} void arr_rev (int s, int e) {int temp [100001]; for (int I = s; I <= e; I ++) {temp [I] = a [e + s-I] ;}for (int I = s; I <= e; I ++) {a [I] = temp [I] ;}} int main () {int n; cin> n; memset (a, 0, sizeof a); memset (dp, 0, sizeof dp); cin> a [0]; bool flag = true; int pos_start = 0; for (int ni = 1; ni
          
            > A [ni]; if (a [ni]> a [ni-1]) dp [ni] = dp [ni-1] + 1; else {dp [ni] = 0; flag = false; if (pos_start = 0) pos_start = ni ;}} if (flag) {cout <"yes" <
           
             C. Predict Outcome of the Game
            

Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

There areNGames in a football tournament. Three teams are participating in it. CurrentlyKGames had already been played.

You are an avid football fan, but recently you missed the wholeKGames. Fortunately, you remember a guess of your friend for theseKGames. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will beD1and that of between second and third team will beD2.

You don't want any of team win the tournament, that is each team shoshould have the same number of wins afterNGames. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?

Note that outcome of a match can not be a draw, it has to be either win or loss.

Input

The first line of the input contains a single integer corresponding to number of test casesT(1? ≤?T? ≤? 105 ).

Each of the nextTLines will contain four space-separated integersN,?K,?D1 ,?D2 (1? ≤?N? ≤? 1012; 0? ≤?K? ≤?N; 0? ≤?D1 ,?D2? ≤?K)-Data for the current test case.

Output

For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes ).

Sample test (s)

Input

53 0 0 03 3 0 06 4 1 06 3 3 03 3 3 2

Output

yesyesyesnono

Note

Sample 1. There has not been any match up to now (K? =? 0 ,?D1? =? 0 ,?D2? =? 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.

Sample 2. You missed all the games (K? =? 3).D1? =? 0 andD2? =? 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes ".

Sample 3. You missed 4 matches, andD1? =? 1 ,?D2? =? 0. these four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1 ). currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. two remaining matches can be: 1-2 (win 2), 1-3 (win 3 ). in the end all the teams have equal number of wins (2 wins ).



This question indicates that three teams have to play n games in total and k have already been played. The absolute score difference between one team and two teams is d1, the absolute score difference between the two and the three teams is d2. I wonder if it is possible that the three teams are flat after n matches.

After enumerative questions, this question has the following implicit conditions:

1. n can not be a multiple of 3, Test 4 n = 999999980, which is why my wa ...... I did not write (n % 3 = 0) cout <"no" <

2. Note indicates that it is not a loop attack, but two teams can be beaten to the ground ......

1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1), 1-2 (win 2 ), 1-3 (win 3 ).

3. The possibility that data of d1 and d2 cannot exist after k fields exists: Test 5 n = 1, k = 1, d1 = 0, d2 = 0

This question can be determined as follows:

1. Can n be fully divided by 3 (if no field count can be fully divided by 3, how can the last three persons share the same win count)

2. When d1 = d2 = 0, check whether n-k can be divisible by 3.

3. Absolute Value d1 and d2 symbols. four situations: ++, +-,-+ ,--

1) in this case, does the maximum team currently win more than n/3?

2) The three teams have already played and whether they exceed k according to the current situation.

3) check whether the remaining k matches are not negative after completing the three teams according to the largest match


Code:
# Include
             
              
# Include
              
               
# Include
               
                
# Include
                
                 
# Include
                 
                  
# Include
                  
                    # Include
                   
                     # Include using namespace std; typedef _ int64 ll; # define Max (a, B) (a)> (B )? (A) :( B) # define Min (a, B) (a) <(B )? (A) :( B) int cmp (const void * a, const void * B) {return (* (int *) a-* (int *) B );} int main () {int cases = 0; scanf ("% d", & cases); for (int _ case = 1; _ case <= cases; _ case ++) {ll n, k, d1, d2, rest = 0; cin> n> k> d1> d2; rest = n-k; if (n % 3! = 0) {cout <"no" <
                    
                      > If (d1 + d2)> (n/3) rest1 =-1; if (d1 + d2 + d2> k) rest1 =-1; ll rest2 = rest-max (d1, d2)-(max (d1, d2)-min (d1, d2); //> <if (max (d1, d2, d2)> (n/3) rest2 =-1; if (d1 + d2> k) rest2 =-1; ll rest3 = rest-d1-d2; // <> if (max (d1, d2)> (n/3) rest3 =-1; if (max (d1, d2) + max (d1, d2) -min (d1, d2)> k) rest3 =-1; ll rest4 = rest-d1-d2-d2; // <
                     
                       (N/3) rest4 =-1; if (d1 + d1 + d2> k) rest4 =-1; if (rest1> = 0 & rest1 % 3 = 0) cout <"yes" <
                      
                        = 0 & rest2 % 3 = 0) cout <"yes" <
                       
                         = 0 & rest3 % 3 = 0) cout <"yes" <
                        
                          = 0 & rest4 % 3 = 0) cout <"yes" <
                         
                           D. Count Good Substrings
                          

Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. for example, "aabba" is good, because after the merging step it will become "aba ".

Given a string, you have to find two values:

  1. The number of good substrings of even length;
  2. The number of good substrings of odd length.

Input

The first line of the input contains a single string of lengthN(1? ≤?N? ≤? 105). Each character of the string will be either 'A' or 'B '.

Output

Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length.

Sample test (s)

Input

bb

Output

1 2

Input

baab

Output

2 4

Input

babb

Output

2 5

Input

babaa

Output

2 7

Note

In example 1, there are three good substrings ("B", "B", and "bb"). One of them has even length and two of them have odd length.

In example 2, there are six good substrings (I. e. "B", "a", "a", "B", "aa", "baab "). two of them have even length and four of them have odd length.

In example 3, there are seven good substrings (I. e. "B", "a", "B", "B", "bb", "bab", "babb "). two of them have even length and five of them have odd length.

Definitions

A substringS[L,?R] (1? ≤?L? ≤?R? ≤?N) Of stringS? =?S1S2...SNIs stringSLSL? +? 1...SR.

A stringS? =?S1S2...SNIs a palindrome if it is equal to stringSNSN? -? 1...S1.


This question is a string that consists of only a and B, if any of the substrings is compressed (compression means that all consecutive a or continuous B is replaced by one a or B), it becomes a good substring, ask how many even substrings of an even length and how many even substrings of an odd length.

TIPS:

1. After compression, the string must be a and B, such as a \ AB \ aba \ abababababa \ bababa

2. If the compressed length is an odd number, it is a text return.

3. The length of a substring from an even number to an even number, from an odd number to an odd number, and from an odd number to an even number. The length of a substring from an even number to an odd number is an even number.

4. This is a mathematical problem.

Code:
#include 
                           
                            #include 
                            
                              #include 
                             
                               #include 
                              
                               #include 
                               
                                #include 
                                
                                 #include 
                                 
                                  #include 
                                  
                                   #include 
                                   
                                    #include using namespace std;const int maxn=1e5+5;string s;char str[maxn];int len,f[2][2];long long ans[2];int main(){ while(scanf("%s",str)==1){ len=strlen(str); memset(f,0,sizeof f); memset(ans,0,sizeof ans); for(int i=0;i
                                    
                                     









Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.