把博客从 WordPress 转移到了 Hexo

虽然WordPress是也很优秀的,不过我想换一换口味,便选择了 Hexo,它简单纯粹,静态网页还可以托管在 github page 上。
迁移也是方便,用插件几条命令就搞定了,找了个自认为不错的主题,匆匆忙忙就完工了。
还有顺手把图片啥的都放在的七牛上,感觉不错。

拿51单片机做了个表

基于STC12C5A60S2单片机,共使用6个按键、12位共阳数码管、4LED灯加一有源头蜂鸣器,按键占用一组I/O口,数码管、LED灯与蜂鸣器公用三组IO口。分两个板子,其实设计的也不怎么好,还有一些飞线,电路图和pcb图如下:



代码如下

main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430

#include"ch1.h";
#define uint unsigned int
#define uchar unsigned char
#define Pa P0//1-8
#define Pb P3//tx,rx,6keys
#define Pc P2//a-h
#define Pd P1//9-12,led,beep..

sbit bk0=Pb^0;sbit bk1=Pb^1;sbit bk2=Pb^2;sbit bk3=Pb^3;sbit bk4=Pb^4;sbit bk5=Pb^5;sbit bk6=Pb^6;sbit bk7=Pb^7;//bk:Pb's Keys
sbit led=Pd^4;sbit beep=Pd^5;
uint i,t,p,num0=0,sec=0,minu=0,hour=0,day=1,mon=1,year=2015,num[12]={0},k=0,kl=0,s=0,ii=0,in[7]={0};
xdata uint ahour=18,aminu=0,ring=0,alarm=0,ka=0;
code uint map[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x98,0xBF,0xFF,0xA3,0xAB,0x8E},dm[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//map:0123456789-(null)onf

uint md(){
/*
if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12)return(31);
else if(mon==4||mon==6||mon==9||mon==11)return(30);
else if(mon==2&&year%4==0&&(year%100!=0||year%400==0))return(29);
else return(28);
*/


if(mon==2&&year%4==0&&(year%100!=0||year%400==0)){return(29);}
else return(dm[mon]);
}
void st(uint x){

/////////
SBUF=x;
while(!TI) ;
TI=0;
delay(10);
}

void main(){
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
ET0=1;
TR0=1;

TMOD=0x21;

SCON = 0x50;
TH1 = 0xFD;
TL1 = 0xFD;
TR1 = 1;
ES = 1;

i=9;
Pa=Pd=Pc=0x00;
delay(500);while(bk5==0);ka=0;
Pa=Pd=Pc=0xFF;

while(i++){
delay(20);
//Pb=0x00;//Pb=Pb*0x10;
if(i>0x7FF)i=9;
t=i%12;p=0x01;
while(t--){
p*=2;
}
Pc=0xFF;//0
if(p<0xFF){
Pa=0xFF-p;
Pd=0xFF;
if(ring&&num0/2%2&&num0>3)beep=0;
if(k==0){
if(ka==1)led=0;
else if(num0/5%2){

led=0;

}
}

}
else {
Pa=0xFF;Pd=0xFF-p/0x100;
if(ring&&num0/2%2&&num0>3)beep=0;
if(k==0){
if(ka==1)led=0;
else if(num0/5%2){

led=0;

}
}
// if(num0/5%2&&k==0){

// Pd-=0x10;

// }
}

Pc=map[num[(i)%12]];
/*//
switch(num[(i)%12]){
case 0:Pc=0xC0;break;
case 1:Pc=0xF9;break;
case 2:Pc=0xA4;break;
case 3:Pc=0xB0;break;
case 4:Pc=0x99;break;
case 5:Pc=0x92;break;
case 6:Pc=0x82;break;
case 7:Pc=0xF8;break;
case 8:Pc=0x80;break;
case 9:Pc=0x98;break;
case 10:Pc=0xBF;break;
case 11:Pc=0xFF;break;

}
*///

if(in[6]==1){
in[6]=0;
year=in[0];
mon=in[1];
day=in[2];
hour=in[3];
minu=in[4];
sec=in[5];

}
if(in[6]==2){
in[6]=0;
st(year);
st(mon);
st(day);
st(hour);
st(minu);
st(sec);
st(1);
}
//
if(k){
num[0]=year/1000;//k;//
num[1]=year/100%10;//s;//
num[2]=year/10%10;//kl;//
num[3]=year%10;
num[4]=10;
num[5]=mon/10;
num[6]=mon%10;
num[7]=10;
num[8]=day/10;
num[9]=day%10;
num[10]=11;
num[11]=11;

if(num0/5%2&&s!=0){

//if(){

if(s==1)num[0]=num[1]=num[2]=num[3]=11;
if(s==2)num[5]=num[6]=11;
if(s==3)num[8]=num[9]=11;
// }

}

}

else{
if(ka==0){
num[0]=11;//beep;//Pb/100;//k;//
num[1]=hour/10;//Pb/10%10;//s;//
num[2]=hour%10;//Pb%10;//kl;//
num[3]=11;//led;//
num[4]=11;
num[5]=minu/10;//Pd/100;//
num[6]=minu%10;//Pd/10%10;//
num[7]=11;//Pd%10;//
num[8]=11;
num[9]=sec/10;
num[10]=sec%10;
num[11]=11;

if(num0/5%2&&s!=0){

// if(){
if(s==1)num[1]=num[2]=11;
if(s==2)num[5]=num[6]=11;
if(s==3)num[9]=num[10]=11;
// }

}
}
else{
num[0]=11;//k;//Pb/100;//
num[1]=ahour/10;//s;//Pb/10%10;//
num[2]=ahour%10;//kl;//Pb%10;//
num[3]=11;
num[4]=11;
num[5]=aminu/10;
num[6]=aminu%10;
num[7]=11;
num[8]=11;
if(alarm){
num[9]=12;
num[10]=13;
num[11]=11;
}
else{
num[9]=12;
num[10]=14;
num[11]=14;
}

if(num0/5%2&&s!=0){
if(s==1)num[1]=num[2]=11;
if(s==2)num[5]=num[6]=11;

}
}

}

//alarm----
if(alarm==1){
if(hour==ahour&&minu==aminu&&sec==0)ring=1;
if(minu-aminu>=10&&minu-aminu<=65505) ring=0;
}
else ring=0;

}

}
void time0() interrupt 1{ //1s
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num0++;
if(num0==20){
num0=0;
sec++;

if(sec==60){
sec=0;minu++;
if(minu==60){
minu=0;hour++;
if(hour==24){
hour=0;day++;
if(day>md()){
day=1;mon++;
if(mon==13){
mon=1;year++;
if(year>=10000){
year=0;
}
}
}
}
}
}
}

//key----

if(Pb==0xFF||Pb==0xFF-0x04||Pb==0xFF-0x08||Pb==0xFF-0x04-0x08){
delay(1);
if(Pb==0xFF||Pb==0xFF-0x04||Pb==0xFF-0x08||Pb==0xFF-0x04-0x08){
kl=0;
if(s==0){
if(bk2==0){
k=1;
}
else k=0;
}
if(bk3==0){
alarm=1;
}
else alarm=0;
}
}
/* if(Pb==0xFF-0x04&&kl==0&&s==0){
delay(1);
if(Pb==0xFF-0x04){
kl=1;
k=k==0?1:0;
}
}*/


//

if(bk7==0&&kl==0){
delay(1);
if(bk7==0){
kl=1;
s=((s==0)?1:((s==1)?2:((s==2)&&(k==1)?3:0)));
/*
if(s==0)s=1;
else if(s==1)s=2;
else if(s==2&&k==1)s=3;
else s=0;
*/

}
}
if(bk5==0&&kl==0){
delay(1);
if(bk5==0){
kl=1;
if(s==0)ka=((ka==0)?1:0);
/*
if(s==0)s=1;
else if(s==1)s=2;
else if(s==2&&k==1)s=3;
else s=0;
*/

}
}
//
if((bk4==0||bk6==0)&&kl==0&&s!=0){
delay(1);
if(bk4==0||bk6==0){
kl=1;
if(k){
if(s==1){

if(bk4==0&&year<9999)year++;
if(bk6==0&&year>0) year--;

}
if(s==2){
if(bk4==0)mon++;
else mon--;
if(mon<1)mon=12;
if(mon>12)mon=1;
}
if(s==3){
if(bk4==0){day++;}
// if(((day<31)&&(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12))||((day<30)&&(mon==4||mon==6||mon==9||mon==11))||(((day<29)&&(mon==2&&year%4==0&&(year%100!=0||year%400==0))))||((day<28)&&(mon==2)));
// else day=0;
if(day>md())day=1;
if(bk6==0)day--;
if(day<1){day=md();
// if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12)day=31;
// else if(mon==4||mon==6||mon==9||mon==11)day=30;
// else if(mon==2&&year%4==0&&(year%100!=0||year%400==0))day=29;
// else day=28;////

}

/*if(day<1){
if(mon==2){
if(year%4!=0){
day=28;

}
if(year%100==0&&year%400!=0){
day=28;
}
else day=29;
}
if(mon==2||mon==4||mon==6||mon==9||mon==11)day=30;
else day=31;
}
}
if(day>=29){
if(day==29&&mon==2&&(year%4!=0||(year%100==0&&year%400!=0))){
day=0;
}
if(day==30&&mon==2){
day=0;
}
if((day==31&&(mon==2||mon==4||mon==6||mon==9||mon==11))||day==32){
day=0;
}
}*/

}
}
else{
if(ka==0){
if(s==1){

if(bk4==0)if(hour<23)hour++;else hour=0;
if(bk6==0)if(hour>0)hour--;else hour=23;

}
if(s==2){
if(bk4==0)if(minu<59)minu++;else minu=0;
if(bk6==0)if(minu>0) minu--;else minu=59;

sec=0;
}
}
else{
if(s==1){

if(bk4==0)if(ahour<23)ahour++;else ahour=0;
if(bk6==0)if(ahour>0)ahour--;else ahour=23;

}
if(s==2){
if(bk4==0)if(aminu<59)aminu++;else aminu=0;
if(bk6==0)if(aminu>0) aminu--;else aminu=59;

}

}

}
}
if((Pb==0xFF-0x10||Pb==0xFF-0x40)&&kl==0&&s==0){
delay(1);
if(Pb==0xFF-0x10){
kl=1;
in[6]=2;
}
if(Pb==0xFF-0x40){
kl=1;ii=7;
while(ii--)st(2);
}

}

}

}

void ser() interrupt 4
{

if(RI == 1) {
RI = 0;

in[ii] = SBUF;

}

ii++;
ii=ii==7?0:ii;
}

头文件

ch1.h

1
2
3
4
5
6
7
8
9
10

#define uint unsigned int
#define uchar unsigned char

void delay(uint z)
{

uint zz;
while(z--){zz=z;while(zz--);}

}

 
源文件下载 c51clock.zip

把域名从 Godaddy 转到了 NameSilo

域名还不到一个月过期,发现续费好贵,也没有好用的优惠码,再加上朋友的域名被盗事件,便不想继续放在 Godaddy 那儿了。近日发现 NameSilo 价格尚可,送隐私保护,那就选它了,开工。

NameSilo1

给 Godaddy 要转移码

namesilo1 JR)L4T4Y20WM51U8F0)DXVE

 

收到邮件

namesilo2

该付款了,有优惠码可省1刀

G0AU06SBT)F9}RW~FO5A1O2

 

价格还可以

namesilo5

钱支付了,namesilo 这边还是订单待完成,Q_Q,先去写会代码等等吧


 

写~


 

代~


 

码~



 


收到客服回信


namesilo6


 
继续继续


 
PT`9O93L(_5AW938L$OE7QH


 

在 Godaddy 域名状态已经变成了这样


 
namesilo8

 
手动确认

 

namesilo3 namesilo4


 
这样就不用等待了


 
~3}X_R91XA7R1PE7JAMK5IW



 
在 NameSilo 的状态

 

])05@LQDY8BGFUNQBI7VH(M


 
OK


@THA2NY7XGOOXUZ`DX~2}@8


 

WHOIS 信息已经变了


 
20150417121552


 

大功告成

 

用C写了个一个支持长数字输入输出计算器

市面上竟然没找到一个支持几千位数字输入的计算器软件,只好自己动手搞了一个。

目前暂时只支持非负整数的加减法运算,我毕竟还是很菜,代码又丑又烂。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int a[10001],b[10001],o,oo,i,j;
char c[20002],d;
cout<<"Input equation like '1+1', only support + and - ."<<endl;
gets(c);
for(i=0;c[i+1]<'9'&&c[i+1]>'0'&&i<20001;i++){
a[i]=c[i]-'0';
}
if(i==20001||i==0){cout<<"INPUT ERROR "; return 0;}
i++;a[i]='/0';o=i;
cin>>d;
for(i=o,j=0;c[i+1]!='0'&&i<20002;i++,j++){
b[j]=c[i]-'0';
}
if(i==20002){cout<<"INPUT ERROR "; return 0;}
oo=j+1;
if(d!='+'||d!='-'){cout<<"INPUT ERROR "; return 0;}
if(d=='+'){
if(o>=oo){
for(i=o-1,j=oo-1;j>=0;i--,j--){
a[i]+=b[j];
if(a[i]>9&&i!=0){a[i]-=10;a[i-1]++;}
}
for(i=0;i<o;i++){cout<<a[i];}
}
else{
for(i=o-1,j=oo-1;i>=0;i--,j--){
b[j]+=a[i];
if(b[j]>9&&j!=0){b[j]-=10;b[j-1]++;}
}
for(i=0;i<oo;i++){cout<<b[i];}
}

}
else{
if(o>=oo){
for(i=o-1,j=oo-1;j>=0;i--,j--){
a[i]-=b[j];
if(a[i]<0&&i!=0){a[i]+=10;a[i-1]--;}
}
for(i=0;i<o;i++){cout<<a[i];}
}
else{
cout<<"INPUT ERROR "; return 0;
}

}

}

 

开始搞ACM

上个月开始搞ACM(ICPC),虽然只是做一些水题。一道题苦想半天调试N遍最后AC,这感觉 特别爽哟。

随手拿最近的一些水题放上来吧,当做纪念,可能几年后我成为了大神,人们来嘲笑我说,这么烂的代码竟然是他曾经写的。


Codeforces Round #237 (Div. 2) - Valera and Fruits

Description

Valera loves his garden, where n fruit trees grow.

This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days, become unfit to eat).

Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more thanv fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?


Input

The first line contains two space-separated integers n and v(1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day.

Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi(1 ≤ ai, bi ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree.


Output

Print a single integer — the maximum number of fruit that Valera can collect.


Sample Input

Input

2 3
1 5
2 3

Output

8

Input

5 10
3 20
2 20
1 20
4 20
5 20

Output

60



Hint

In the first sample, in order to obtain the optimal answer, you should act as follows.

  • On the first day collect 3 fruits from the 1-st tree.
  • On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree.
  • On the third day collect the remaining fruits from the 2-nd tree.
    In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<stdio.h>
#include<string.h>
#include <algorithm>
using namespace std;
int main()
{

long int n,v,vv,a[3008],b[3008] ,i,ii,t,o,y,iy;
while (scanf("%d%d", &n, &v) != EOF)
{
o = 0; vv = v; y = 0;
for (i = 0; i < n; i++)
{
cin >> a[i]>>b[i];
}
for (i = 0; i < n; i++)
for (ii = i + 1; ii < n; ii++)
{
if (a[i]>a[ii])
{
t = a[i]; a[i] = a[ii]; a[ii] = t;
t = b[i]; b[i] = b[ii]; b[ii] = t;
}

}

//
//
//

for (i = 0; i < n; i++)
{
if (i != 0)
{
if (a[i] != a[i - 1]) { v = vv; }

}
if (v != 0 && i != 0)
{
for (iy = y; iy < i; iy++)
{
if (b[iy] != 0)
{
if (v <= b[iy])
{
o += v; b[iy] -= v; v = 0;
}
else { o += b[iy]; v -= b[iy]; b[iy] = 0; }
}
}
}
if (a[i] - a[i - 1] > 1) v = vv;
if (v != 0)
{
if (v <= b[i])
{
o += v; b[i] -= v; v = 0;
}
else { o += b[i]; v -= b[i]; b[i] = 0; }
}
if (a[i - 1] != a[i]&&i!=0) y = i;

}

//
//
//

v = vv;

for (iy = y; iy < i; iy++)
{
if (b[iy] != 0)
{
if (v <= b[iy])
{
o += v; b[iy] -= v; v = 0;
}
else { o += b[iy]; v -= b[iy]; b[iy] = 0; }
}
}

cout << o << endl;

}
return(0);
}

 


Codefoces 436B-Om Nom and Spiders

Description

Om Nom really likes candies and doesn’t like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn’t want to see them at all.

The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.

Om Nom isn’t yet sure where to start his walk from but he definitely wants:

  • to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders);
  • to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park).
    We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.

Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That’s why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell.


Input

The first line contains three integers n, m, k(2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)).

Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals “.“, that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: “L“ (meaning that this cell has a spider at time 0, moving left), “R“ (a spider moving right), “U“ (a spider moving up), “D“ (a spider moving down).

It is guaranteed that the first row doesn’t contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders.


Output

Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right.


Sample Input

Input

3 3 4

R.L
R.U

Output

0 2 2

Input

2 2 2
..
RL

Output

1 1

Input

2 2 2
..
LR

Output

0 0

Input

3 4 8
….
RRLL
UUUU

Output

1 3 3 1

Input

2 2 2
..
UU

Output

0 0



Hint

Consider the first sample. The notes below show how the spider arrangement changes on the field over time:

…        …        ..U       …
R.L -> .*U -> L.R -> …
R.U .R. ..R …


Character “*“ represents a cell that contains two spiders at the same time.

  • If Om Nom starts from the first cell of the first row, he won’t see any spiders.
  • If he starts from the second cell, he will see two spiders at time 1.
  • If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{

int n, m, k,i,j,fuck;
char in[2002][2002];
while (scanf("%d%d%d", &n,&m,&k) != EOF)
{
fuck = 0;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
{
cin >> in[i][j];
}

for (j = 0; j < m; j++)
{
for (i = 1; i < n; i++)
{
if(i+i<n)if (in[i + i][j] == 'U')fuck++;
if (j - i>=0&&j-i<m)if (in[i][j - i] == 'R')fuck++;
if (j + i<m)if (in[i][j + i] == 'L')fuck++;
}
cout << fuck << ' '; fuck = 0;
}
cout<<endl;

}
return(0);
}

 


Codeforces 435B Pasha Maximizes

Description

Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.

Help Pasha count the maximum number he can get if he has the time to make at most k swaps.


Input

The single line contains two integers a and k(1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).


Output

Print the maximum number that Pasha can get if he makes at most k swaps.


Sample Input

Input

1990 1

Output

9190

Input

300 0

Output

300

Input

1034 2

Output

3104

Input

9090000078001234 6

Output

9907000008001234




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cstring>
using namespace std;
int main()
{

long int n, x[100008], y[100008], i = 0, j,xxx[100008],yyy[100008],u;
while (scanf("%d", &n) != EOF)
{

memset(xxx, 0, sizeof(xxx));
memset(yyy, 0, sizeof(yyy));
for (i = 0; i < n; i++)
{
cin >> x[i] >> y[i];

xxx[x[i]]++;
yyy[y[i]]++;
}
for (i = 0; i < n; i++)
{
u = n - xxx[y[i]] - 1;
cout << 2*n - 2 - u << ' ' << u << endl;
}

}
return(0);
}

 


codeforce 432B - Football Kit

Description

Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi(xi ≠ yi).

In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.

Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.


Input

The first line contains a single integer n(2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi(1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of thei-th team.


Output

For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.


Sample Input

Input

2
1 2
2 1

Output

2 0
2 0

Input

3
1 2
2 1
1 3

Output

3 1
4 0
2 2




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cstring>
using namespace std;
int main()
{

long int n, x[100008], y[100008], i = 0, j,xxx[100008],yyy[100008],u;
while (scanf("%d", &n) != EOF)
{

memset(xxx, 0, sizeof(xxx));
memset(yyy, 0, sizeof(yyy));
for (i = 0; i < n; i++)
{
cin >> x[i] >> y[i];

xxx[x[i]]++;
yyy[y[i]]++;
}
for (i = 0; i < n; i++)
{
u = n - xxx[y[i]] - 1;
cout << 2*n - 2 - u << ' ' << u << endl;
}

}
return(0);
}

 


Codeforces 431B Shower Line

Description

Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.

There is only one shower and there are multiple students who wish to have a shower in the morning. That’s why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.

Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the(2i - 1)-th man in the line (for the current moment) talks with the (2i)-th one.

Let’s look at this process in more detail. Let’s number the people from 1 to 5. Let’s assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn’t talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn’t talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.

We know that if students i and j talk, then the i-th student’s happiness increases by gij and the j-th student’s happiness increases by gji. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.


Input

The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows gij (0 ≤ gij ≤ 105). It is guaranteed that gii = 0 for all i.

Assume that the students are numbered from 1 to 5.


Output

Print a single integer — the maximum possible total happiness of the students.


Sample Input

Input

0 0 0 0 9
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
7 0 0 0 0

Output

32

Input

0 43 21 18 2
3 0 21 11 65
5 2 0 1 4
54 62 12 0 99
87 64 81 33 0

Output

620




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cstring>
using namespace std;
int main()
{

long int o[5][5], i,j, ii, iii, a, b, c, d, e,m=0,max=0;
while (scanf("%d", &o[0][0]) != EOF)
{
for (i = 0; i < 5; i++)
for (j = 0; j < 5; j++)
{
if (i == 0 && j == 0)j++;
cin >> o[i][j];
}
for (a = 0; a < 5; a++)
for (b = 0; b < 5;b++)
for (c = 0; c < 5; c++)
for (d = 0; d < 5; d++)
for (e = 0; e < 5; e++)
{
if(a!=b&&a!=c&&a!=d&&a!=e&&b!=c&&b!=d&&b!=e&&c!=d&&c!=e&&d!=e)
m = o[a][b] + o[b][a] + o[b][c] + o[c][b] + (o[c][d] + o[d][c]) * 2 + (o[d][e] + o[e][d]) * 2;
if (m>max) max = m;
}
cout << max<<endl;
}
return(0);
}