Save Energy And Lock Puzzle

因?yàn)樘脹](méi)有更新博客了,最近比較忙世落。抹竹。所以就把兩周簽EL-ROUND-TWO我AC的兩道題簡(jiǎn)單的講講,以后很多更新可能都直接貼一個(gè)github的賬號(hào)了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都超級(jí)大盏档,1?≤?k,?d?≤ 1018,所以我們需要用long long 來(lái)保存燥爷◎谀叮考慮到m和n之間的關(guān)系,有三種情況

n|m

此時(shí)一直都是高溫加熱的狀態(tài)前翎,所以時(shí)間就直接是t了

n<m或者n>m

此時(shí)勺拣,因?yàn)槊縩次都會(huì)去開(kāi)一次烤爐(如果關(guān)上了的話),所以我們可以考慮當(dāng)烤爐滅了的時(shí)間和n之間的關(guān)系鱼填,如果存在一個(gè)最小的數(shù)k药有,使得kn>m,那么我們就稱一個(gè)周期是kn苹丸,這個(gè)周期所做出的貢獻(xiàn)是(kn-m)*1/2 + m

后面就很簡(jiǎn)單了愤惰,下面看第二題。

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

本人認(rèn)為這題還是有點(diǎn)復(fù)雜的赘理,因?yàn)槲覀兇藭r(shí)不知道題目例子中給出的變化是不是通用的變換宦言,第二是通用的變換如果存在的話能不能在6100步以內(nèi)結(jié)束呢?注意到1?≤?n?≤?2?000商模,3*n 剛好是在6000以內(nèi)的數(shù)奠旺,這可能說(shuō)明了存在一個(gè)通用的變化,使得3步以內(nèi)歸位一個(gè)數(shù)施流?

經(jīng)過(guò)不斷嘗試响疚,我發(fā)現(xiàn)可以通過(guò)一下操作使得一個(gè)數(shù)從中間的某一位換到這一串?dāng)?shù)的最末尾,且不改變已經(jīng)排好的那段瞪醋。

A忿晕,D是任意的一個(gè)子串,B是已經(jīng)排好的子串银受,c是B后一位的字符践盼,用A/表示A的逆序,我們從t串的最后一位開(kāi)始排宾巍,假設(shè)現(xiàn)在是如下?tīng)顟B(tài) BDcA

BDcA →A/cD/B/

A/cD/B/→BDA/c

BDA/c→cBDA/→BDA/

這樣就解決了問(wèn)題咕幻,下面開(kāi)始code。
首先先判斷兩個(gè)string字母數(shù)是不是一樣的顶霞,如果不一樣直接return -1
如果是肄程,我們有一個(gè)循環(huán),在循環(huán)中要不斷地歸為原來(lái)的子串,考慮到我們最后把操作的步數(shù)和怎么操作的都列出來(lái)绷耍,所以我們需要用一個(gè)東西來(lái)存每一步的操作,用一個(gè)向量就行了鲜侥。最后只需要打印即可褂始!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市描函,隨后出現(xiàn)的幾起案子崎苗,更是在濱河造成了極大的恐慌,老刑警劉巖舀寓,帶你破解...
    沈念sama閱讀 211,376評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件胆数,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡互墓,警方通過(guò)查閱死者的電腦和手機(jī)必尼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,126評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)篡撵,“玉大人判莉,你說(shuō)我怎么就攤上這事∮” “怎么了券盅?”我有些...
    開(kāi)封第一講書(shū)人閱讀 156,966評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)膛檀。 經(jīng)常有香客問(wèn)我锰镀,道長(zhǎng),這世上最難降的妖魔是什么咖刃? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,432評(píng)論 1 283
  • 正文 為了忘掉前任泳炉,我火速辦了婚禮,結(jié)果婚禮上嚎杨,老公的妹妹穿的比我還像新娘胡桃。我一直安慰自己,他們只是感情好磕潮,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,519評(píng)論 6 385
  • 文/花漫 我一把揭開(kāi)白布翠胰。 她就那樣靜靜地躺著,像睡著了一般自脯。 火紅的嫁衣襯著肌膚如雪之景。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,792評(píng)論 1 290
  • 那天膏潮,我揣著相機(jī)與錄音锻狗,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛轻纪,可吹牛的內(nèi)容都是我干的油额。 我是一名探鬼主播,決...
    沈念sama閱讀 38,933評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼刻帚,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼潦嘶!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起崇众,我...
    開(kāi)封第一講書(shū)人閱讀 37,701評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤掂僵,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后顷歌,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體锰蓬,經(jīng)...
    沈念sama閱讀 44,143評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,488評(píng)論 2 327
  • 正文 我和宋清朗相戀三年眯漩,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了芹扭。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,626評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡赦抖,死狀恐怖冯勉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情摹芙,我是刑警寧澤灼狰,帶...
    沈念sama閱讀 34,292評(píng)論 4 329
  • 正文 年R本政府宣布,位于F島的核電站浮禾,受9級(jí)特大地震影響交胚,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜盈电,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,896評(píng)論 3 313
  • 文/蒙蒙 一蝴簇、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧匆帚,春花似錦熬词、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,742評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至嚎幸,卻和暖如春颜矿,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背嫉晶。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來(lái)泰國(guó)打工骑疆, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留田篇,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,324評(píng)論 2 360
  • 正文 我出身青樓箍铭,卻偏偏與公主長(zhǎng)得像泊柬,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子诈火,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,494評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,309評(píng)論 0 10
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,435評(píng)論 0 23
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    網(wǎng)事_79a3閱讀 11,940評(píng)論 3 20
  • 這是一場(chǎng)從來(lái)就沒(méi)有平等過(guò)的戰(zhàn)爭(zhēng)兽赁。剛剛一個(gè)剎那,細(xì)菌病毒的下一代已經(jīng)出生柄瑰。但他是否能成為一個(gè)傳染病,只取決于這么一點(diǎn)...
    PM從零單排閱讀 2,215評(píng)論 0 1
  • 無(wú)論做什么事剪况,我們都會(huì)聽(tīng)到專業(yè)二字教沾,做研究是否專業(yè),工作是否專業(yè)......專業(yè)體現(xiàn)在方方面面译断,但專業(yè)究竟是什么...
    enotwoz閱讀 603評(píng)論 0 2