题干:

You are given a positive integer nn.

Let S(x)S(x) be sum of digits in base 10 representation of xx, for example, S(123)=1+2+3=6S(123)=1+2+3=6, S(0)=0S(0)=0.

Your task is to find two integers a,ba,b, such that 0≤a,b≤n0≤a,b≤n, a+b=na+b=n and S(a)+S(b)S(a)+S(b) is the largest possible among all such pairs.

Input

The only line of input contains an integer nn (1≤n≤1012)(1≤n≤1012).

Output

Print largest S(a)+S(b)S(a)+S(b) among all pairs of integers a,ba,b, such that 0≤a,b≤n0≤a,b≤n and a+b=na+b=n.

Examples

Input

35

Output

17

Input

10000000000

Output

91

Note

In the first example, you can choose, for example, a=17a=17 and b=18b=18, so that S(17)+S(18)=1+7+1+8=17S(17)+S(18)=1+7+1+8=17. It can be shown that it is impossible to get a larger answer.

In the second test example, you can choose, for example, a=5000000001a=5000000001 and b=4999999999b=4999999999, with S(5000000001)+S(4999999999)=91S(5000000001)+S(4999999999)=91. It can be shown that it is impossible to get a larger answer.

题目大意:

给一个n,找两个数a,b,使得在满足a+b=n的前提下,a和b的各位数的和最大。

解题报告:

这题有点小坑啊,但是这么想啊,肯定是9越多越好,所以先找出最多的9999之类的,剩下的再随便挑。(因为不难想到,肯定没有比这个的和  更大的了)所以就这么构造就行,反正是SJ题。

给一个错误的想法,up=1,然后每次都*10+9,找到最大的满足的,这样就大错特错了。对于123这个样例,输出为15,但正确答案为24(99+24)。所以啊要先凑9,因为可以证明其他的任何最大组合,都可以由这个a来借给b。

AC代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;int main()
{ll n,a,b;cin>>n;ll up=1;while(n>=up) {up=up*10;}up/=10;up--;
//  cout<<up<<endl;a=up;b=n-up;ll sum=0;while(a) {sum+=a%10;a/=10;}while(b) {sum+=b%10;b/=10;}printf("%d\n",sum);return 0;
}

其实写成更赏心悦目,思路清晰。

while(1){temp1*=10;if(temp1*10>=n)break;}temp1--;

【 CodeForces - 1060B 】Maximum Sum of Digits(思维,构造)相关推荐

  1. codeforces 1060b Maximum Sum of Digits(思维题)

    You are given a positive integer n Let S(x) be sum of digits in base 10 representation of x, for exa ...

  2. Educational Codeforces Round 108 (Rated for Div. 2) D. Maximum Sum of Products 思维 + dp

    传送门 文章目录 题意: 思路: 题意: 给你两个长度为nnn的数组a,ba,ba,b,你可以至多反转一段连续区间,求∑i=1nai∗bi\sum _{i=1}^n a_i*b_i∑i=1n​ai​∗ ...

  3. CodeForces - 1373D Maximum Sum on Even Positions(最大连续子段和)

    题目链接:点击查看 题目大意:给出一个长度为 n 的数列 a ,允许选择一个子串进行翻转,问最后可以得到的,偶数位置的数字之和的最大值是多少 题目分析:模拟几次不难发现,我们翻转的长度必须是偶数才能有 ...

  4. CodeForces - 715A Plus and Square Root(思维+构造)

    题目链接:点击查看 题目大意:我们在玩一个游戏,屏幕上有一个数字,我们设这个数字为x,初始值为2,我们一开始的等级是k,我们每一次可以有两种操作: 加法:可以让x加上k 开根号:可以让x开根号,并且等 ...

  5. 【CodeForces - 483C】Diverse Permutation(思维构造)

    题干: Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of ndistinct posit ...

  6. 51nod 1574 || Codeforces 584 E. Anton and Ira 思维+构造+贪心

    传送门:E. Anton and Ira 题意:给定两个1-n的全排列p和s,假设交换pi和pj的代价是abs(i-j),问怎样将p交换成s才能使代价最小. 思路:先将s映射成1-n的顺序排列,再将p ...

  7. CodeForces - 1270C Make Good(思维+构造)

    题目链接:点击查看 题目大意:给出一个由n个数字构成的数列,现在已知其累加和为sum,异或和为xor,现在允许我们向数列中添加0~3个数,以满足sum=2*xor,构造出任意一种方案 题目分析:一开始 ...

  8. 【CodeForces 332B --- Maximum Absurdity】递推

    [CodeForces 332B --- Maximum Absurdity]递推 题目来源:点击进入[CodeForces 332B - Maximum Absurdity] Description ...

  9. [CodeForces 332B]Maximum Absurdity[DP]

    题目链接: [CodeForces 332B]Maximum Absurdity[DP] 题意分析: 寻找两个不重叠的长度为k的子串,使得它们之和最大. 解题思路: 第一想法是,处理出从这个点开始,长 ...

最新文章

  1. mysql 中文截取_mysql 截取中文字符
  2. AWS上创建的notebook实例提示没有导入pytorch模块的解决办法 直接在编辑块中执行如下命令,最后重启kernel问题解决
  3. springmvc-配置文件
  4. BestCoder Round #84
  5. [云炬创业学笔记]第一章创业是什么测试5
  6. ITK:计算Sigmoid
  7. centos6.4 卸载mysql_彻底删除MYSQL-CENTOS
  8. leetcode214. 最短回文串
  9. matlab中英文对照表,Matlab工具箱中英文对照
  10. linux nfs4 超时,Linux文件服务器NFS详解【4】
  11. xampp 中mysql中文乱码
  12. 《腾讯Android自动化测试实战》— Android 书籍
  13. Aspose.Cell 导出和导入Excel
  14. 戴尔N5110装WIN10的体验
  15. [SQLITE_BUSY]问题简析与解决
  16. 计算机程序ui设计员工资,ui设计师工资一般多少,发展前景怎么样
  17. linux桌面支持hdpi,用于HiDPI显示器的最佳Linux桌面环境 | MOS86
  18. 鸿蒙系统运行内存为啥只有8g,明明8G内存,系统却显示只有4G!为啥会这样?
  19. 用Python写一个简单的api接口
  20. PHP连接操作sqlserver

热门文章

  1. N元语法模型的数据稀疏问题解决方法之一:Good-Turing平滑
  2. [密码学基础][每个信息安全博士生应该知道的52件事][Bristol52]43 为AES 对抗侧信道攻击的防御
  3. [剑指offer][JAVA][第62题][约瑟夫环][LinkedList vs ArrayList]
  4. wifi 信道_说了这么久的信道和频宽,这回总算能弄明白啦
  5. 微星主板超频_内存超频能力依旧拔群!微星MEG Z490 ACE主板评测
  6. html 微信发送给朋友,H5链接分享给微信好友,显示标题、描述、缩略图
  7. 数据结构c语言版第四章题库,数据结构(C语言版)(第4版)习题
  8. 基于半同步/半反应堆线程池实现的HTTP解析服务端程序
  9. Linux之V4L2基础编程
  10. C++结构体实例和类实例的初始化