XY

시간 제한0.5초메모리 제한1024 MB

요약
여러 쌍 X, Y에 대해 연속한 X개 항의 합은 양수, 연속한 Y개 항의 합은 음수가 되도록 하는 정수 수열의 최대 길이를 구하고, 첫 질의의 수열을 출력한다.
난이도

어려움10점 중 8점

유형
수학, 정수론, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Kaloyan was preparing an exam for his students and found the following problem to be pretty interesting. He wrote two numbers XX and YY and wants to find a sequence of integers where the sum of every XX consecutive elements (in the sequence) is strictly positive while the sum of every YY consecutive elements is strictly negative.

Kaloyan found out that this sequence cannot be infinitely long. He tried to find a sequence of maximum possible length with the described property. However, it turns out to be rather difficult problem for Kaloyan. Help him by writing a program XY that finds the maximum length of such a sequence. You should find the answers to QQ such pairs XX and YY. Additionally, you have to find a maximal sequence only for the first query.

입력

The only line of the standard input contains one number QQ - the number of queries. Each of the following QQ lines contains two numbers - XX and YY .

출력

On the first line of the standard output you should print QQ numbers - N_1,N_2,…,N_QN\_1, N\_2, \dots, N\_Q, separated with intervals, where N_iN\_i is the answer for the ithi^{th} query. On the second line you should print N_1N\_1 integers separated with intervals - a sequence with the desired property for the first query.

제한

  • 1≤X,Y≤100 0001 \leq X,Y \leq 100\ 000
  • 1≤Q≤100 0001 \leq Q \leq 100\ 000

예제1

  1. 예제 1

    입력
    3
    3 5
    1 5
    4 2
    
    예상 출력
    6 4 3
    5 -7 5 3 -7 5