Dima worked all day and wrote down on a long paper strip his favorite number nn consisting of ll digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.

To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.

Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.

Input

The first line contains a single integer ll (2≤l≤1000002≤l≤100000) — the length of the Dima's favorite number.

The second line contains the positive integer nn initially written on the strip: the Dima's favorite number.

The integer nn consists of exactly ll digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.

Output

Print a single integer — the smallest number Dima can obtain.

Examples
input

Copy
7
1234567
output

Copy
1801
input

Copy
3
101
output

Copy
11
Note

In the first example Dima can split the number 12345671234567 into integers 12341234 and 567567. Their sum is 18011801.

In the second example Dima can split the number 101101 into integers 1010 and 11. Their sum is 1111. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.

题解:从中间往两边分出两个分支,取最优解即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string cal(string a,string b)//字符串加法,模拟数的加法即可
{
string ans="";
int pos1=a.size()-,pos2=b.size()-;
int last=,x=;
while(){
if(pos1<&&pos2<)break;
if(pos1<&&pos2>=){
while(pos2>=){
x=b[pos2--]-''+last;
if(x>=){
last=x/;
x%=;
}
else
last=;
ans+=x+'';
}
break;
}
if(pos2<&&pos1>=){
while(pos1>=){
x=a[pos1--]-''+last;
if(x>=){
last=x/;
x%=;
}
else
last=;
ans+=x+'';
}
break;
}
x=a[pos1--]-''+b[pos2--]-''+last;
if(x>=){
last=x/;
x%=;
}
else
last=;
ans+=x+'';
}
if(last)
ans+=last+'';
return ans;
}
int main()
{
int n;
cin>>n;
string s;
cin>>s;
int pos1=n/,pos2=n/+;
while(s[pos1]==''&&pos1>)pos1--;
while(s[pos2]==''&&pos2<n-)pos2++; string a=s.substr(,pos1);
string b=s.substr(pos1,s.size());
string ans=cal(a,b);
reverse(ans.begin(),ans.end());
string aa=s.substr(,pos2);
string bb=s.substr(pos2,s.size());
string anss=cal(aa,bb);
reverse(anss.begin(),anss.end());
if(s[pos2]=='')//特判后一部分不能分的情况,如果想到的话,这个题比赛的时候就能做出来了丫丫丫
return cout<<ans<<endl,;
if(ans.size()<anss.size())cout<<ans<<endl;
else if(ans.size()>anss.size())cout<<anss<<endl;
else{
if(ans<anss)
cout<<ans<<endl;
else
cout<<anss<<endl;
}
return ;
}

最新文章

  1. F#之旅4 - 小实践之快排
  2. struct与union字节大小的终极解释
  3. XUtils
  4. 在IIS服务器上部署svg/woff/woff2字体
  5. HTTP状态码206和416
  6. Android requires compiler compliance level 5.0 or 6.0. Found &#39;1.7&#39; instead
  7. codeforces B. Sereja and Stairs 解题报告
  8. bored
  9. 安装ie10慢的解决办法
  10. C# winform线程的使用 制作提醒休息小程序(长时间计算机工作者必备)
  11. iOS开发雕虫小技之傻瓜式定位神器-超简单方式解决iOS后台定时定位
  12. hdu 2111
  13. HDU1305 Immediate Decodability(水题字典树)
  14. vim 实用配置
  15. java获取本类路径
  16. linux audit审计(8)--开启audit对系统性能的影响
  17. Java 面试题 MD
  18. Linux运维之系统性能瓶颈工具vmstat分析
  19. 根据字体多少使UILabel自动调节尺寸
  20. javascript图形动画设计--以简单正弦波轨迹移动

热门文章

  1. 201771010123汪慧和《面向对象程序设计Java》第十二周实验总结
  2. [Qt5] QSlider设置步长
  3. CSS(3)之 less 和rem
  4. 实验吧web-易-what a fuck!这是什么鬼东西?
  5. 落地即王道,锁死企业智变CP——云+AI
  6. MySQL-TPS,QPS到底是什么
  7. TCP_Wrappers简介
  8. shell中sparksql语句调试、执行方式
  9. Eureka高可用环境搭建
  10. 黑马_13 Spring Boot:01.spring boot 介绍&amp;&amp;02.spring boot 入门