CF1120B.Once in a casino

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.

A positive integer aa is initially on the screen. The player can put a coin into the machine and then add 11 to or subtract 11 from any two adjacent digits. All digits must remain from 00 to 99 after this operation, and the leading digit must not equal zero. In other words, it is forbidden to add 11 to 99 , to subtract 11 from 00 and to subtract 11 from the leading 11 . Once the number on the screen becomes equal to bb , the player wins the jackpot. aa and bb have the same number of digits.

Help the player to determine the minimal number of coins he needs to spend in order to win the jackpot and tell how to play.

输入格式

The first line contains a single integer nn ( 2n1052 \le n \le 10^5 ) standing for the length of numbers aa and bb .

The next two lines contain numbers aa and bb , each one on a separate line ( 10n1a,b<10n10^{n-1} \le a, b < 10^n ).

输出格式

If it is impossible to win the jackpot, print a single integer 1-1 .

Otherwise, the first line must contain the minimal possible number cc of coins the player has to spend.

min(c,105)\min(c, 10^5) lines should follow, ii -th of them containing two integers did_i and sis_i ( 1din11\le d_i\le n - 1 , si=±1s_i = \pm 1 ) denoting that on the ii -th step the player should add sis_i to the did_i -th and (di+1)(d_i + 1) -st digits from the left (e. g. di=1d_i = 1 means that two leading digits change while di=n1d_i = n - 1 means that there are two trailing digits which change).

Please notice that the answer may be very big and in case c>105c > 10^5 you should print only the first 10510^5 moves. Your answer is considered correct if it is possible to finish your printed moves to win the jackpot in the minimal possible number of coins. In particular, if there are multiple ways to do this, you can output any of them.

输入输出样例

  • 输入#1

    3
    223
    322
    

    输出#1

    2
    1 1
    2 -1
    
  • 输入#2

    2
    20
    42
    

    输出#2

    2
    1 1
    1 1
    
  • 输入#3

    2
    35
    44
    

    输出#3

    -1
    

说明/提示

In the first example, we can make a +1 operation on the two first digits, transforming number 223\textbf{22}3 into 333\textbf{33}3 , and then make a -1 operation on the last two digits, transforming 3333\textbf{33} into 3223\textbf{22} .

It's also possible to do these operations in reverse order, which makes another correct answer.

In the last example, one can show that it's impossible to transform 3535 into 4444 .

首页