Save Energy And Lock Puzzle

因为太久没有更新博客了,最近比较忙。。所以就把两周签EL-ROUND-TWO我AC的两道题简单的讲讲,以后很多更新可能都直接贴一个github的账号了quq
pppppkun · GitHub
↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑


A – Save Energy

Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after kminutes after turning on.

During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.

It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.

Input

The single line contains three integers k, d and t (1 ≤ k, d, t ≤ 1018).

Output

Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9.

Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if

image.png

.

Examples

Input

3 2 6

Output

6.5

Input

4 2 20

Output

20.0

Note

In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for
image.png

. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for
image.png

. Thus, after four minutes the chicken will be cooked for
image.png

. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready
image.png

.

In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.

首先先注意到m和n都超级大,1 ≤ k, d ≤ 1018,所以我们需要用long long 来保存。考虑到m和n之间的关系,有三种情况

n|m

此时一直都是高温加热的状态,所以时间就直接是t了

n<m或者n>m

此时,因为每n次都会去开一次烤炉(如果关上了的话),所以我们可以考虑当烤炉灭了的时间和n之间的关系,如果存在一个最小的数k,使得kn>m,那么我们就称一个周期是kn,这个周期所做出的贡献是(kn-m)*1/2 + m

后面就很简单了,下面看第二题。

C-Lock Puzzle

Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm!

Of course, there is a code lock is installed on the safe. The lock has a screen that displays a string of n lowercase Latin letters. Initially, the screen displays string s. Whitfield and Martin found out that the safe will open when string t will be displayed on the screen.

The string on the screen can be changed using the operation «shiftx». In order to apply this operation, explorers choose an integer xfrom 0 to n inclusive. After that, the current string p = αβ changes to βRα, where the length of β is x, and the length of α is n - x. In other words, the suffix of the length x of string p is reversed and moved to the beginning of the string. For example, after the operation «shift 4» the string «abcacb» will be changed with string «bcacab », since α = ab, β = cacb, βR = bcac.

Explorers are afraid that if they apply too many operations «shift», the lock will be locked forever. They ask you to find a way to get the string t on the screen, using no more than 6100 operations.

Input

The first line contains an integer n, the length of the strings s and t (1 ≤ n ≤ 2 000).

After that, there are two strings s and t, consisting of n lowercase Latin letters each.

Output

If it is impossible to get string t from string s using no more than 6100 operations «shift», print a single number  - 1.

Otherwise, in the first line output the number of operations k (0 ≤ k ≤ 6100). In the next line output k numbers xi corresponding to the operations «shift xi» (0 ≤ xi ≤ n) in the order in which they should be applied.

Examples

Input

6
abacbb
babcba

Output

4
6 3 2 3

Input

3
aba
bba

Output

-1

In the first example, after applying the operations, the string on the screen will change as follows:

  1. abacbb→bbcaba

  2. bbcaba→ababbc

  3. ababbc→cbabab

  4. cbabab→babcba

本人认为这题还是有点复杂的,因为我们此时不知道题目例子中给出的变化是不是通用的变换,第二是通用的变换如果存在的话能不能在6100步以内结束呢?注意到1 ≤ n ≤ 2 000,3*n 刚好是在6000以内的数,这可能说明了存在一个通用的变化,使得3步以内归位一个数?

经过不断尝试,我发现可以通过一下操作使得一个数从中间的某一位换到这一串数的最末尾,且不改变已经排好的那段。

A,D是任意的一个子串,B是已经排好的子串,c是B后一位的字符,用A/表示A的逆序,我们从t串的最后一位开始排,假设现在是如下状态 BDcA

BDcA →A/cD/B/

A/cD/B/→BDA/c

BDA/c→cBDA/→BDA/

这样就解决了问题,下面开始code。
首先先判断两个string字母数是不是一样的,如果不一样直接return -1
如果是,我们有一个循环,在循环中要不断地归为原来的子串,考虑到我们最后把操作的步数和怎么操作的都列出来,所以我们需要用一个东西来存每一步的操作,用一个向量就行了。最后只需要打印即可!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,542评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,596评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,021评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,682评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,792评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,985评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,107评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,845评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,299评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,612评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,747评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,441评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,072评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,828评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,069评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,545评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,658评论 2 350

推荐阅读更多精彩内容