Under construction

Still being built. Things may change

Checksum

Time limit2sMemory limit1024 MB

Summary
Find the length N (at most 1000) and the digits K_i of a hidden periodic weight sequence, using checksum queries that contain no digit 0.
Level

Medium5 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

A checksum detects errors that occur when data is transmitted or entered. Many algorithms have been invented for this purpose. This problem covers one of the simplest.

The checksum of a number sequence (A1,A2,…)(A_1, A_2, \ldots) is

(A1⋅K1+A2⋅K2+…+AN⋅KN+AN+1⋅K1+…) mod 10(A_1 \cdot K_1 + A_2 \cdot K_2 + \ldots + A_N \cdot K_N + A_{N+1} \cdot K_1 + \ldots) \bmod 10

where K1,K2,…,KNK_1, K_2, \ldots, K_N are fixed constants. The sequence KK is treated as periodic. If AA is longer than KK, the elements of KK are used again from the beginning. If AA is shorter, some elements of KK are not used.

Juku found a system that uses this checksum. He does not know the length NN of the sequence KK or the values KiK_i. He only knows that N≤1 000N \le 1\,000 and 1≤Ki≤91 \le K_i \le 9. Juku can send queries to the system. Each query is a number sequence, and the system returns its checksum. The 0 key on Juku's keyboard is slightly broken, so 0 is hard to type. For this reason, he wants to avoid the digit 0 in his queries.

Write a program that finds the length of the sequence KK and the values of its elements. Since KK is periodic, there are infinitely many possible answers. Output the shortest one.

Examples1

  1. Example 1

    Input
    
    3
    
    1
    
    0
    
    
    Expected output
    ? 7 1 6
    
    ? 5 6 4
    
    ? 1 2 3
    
    ! 3 4