第 3 题 数页码
源程序名 count.pas|c|cpp
输入文件名 count.in
输出文件名 count.out
时间限制 1s/testcase
空间限制 32MB
问题描述
一本书的页码是从 1-n 编号的连续整数:1, 2, 3, ... , n。请你求出全部页码中
所有单个数字的和,例如第 123 页,它的和就是 1+2+3=6。
输入数据
一行为 n(1 <= n <= 10^9)。
输出数据
一行,代表所有单个数字的和。
样例输入
3456789
样例输出
源程序名 count.pas|c|cpp
输入文件名 count.in
输出文件名 count.out
时间限制 1s/testcase
空间限制 32MB
问题描述
一本书的页码是从 1-n 编号的连续整数:1, 2, 3, ... , n。请你求出全部页码中
所有单个数字的和,例如第 123 页,它的和就是 1+2+3=6。
输入数据
一行为 n(1 <= n <= 10^9)。
输出数据
一行,代表所有单个数字的和。
样例输入
3456789
样例输出
96342015
部分打表,不说了。
#include <cstdio>
#include <iostream>
using std::cout;
const long long table[] = {0ll,12250005ll,27000001ll,39750006ll,55000002ll,68250007ll,84000003ll,97750008ll,114000004ll,128250009ll,145000005ll,159750010ll,177000006ll,192250011ll,210000007ll,225750012ll,244000008ll,260250013ll,279000009ll,295750014ll,315000001ll,327750006ll,343000002ll,356250007ll,372000003ll,385750008ll,402000004ll,416250009ll,433000005ll,447750010ll,465000006ll,480250011ll,498000007ll,513750012ll,532000008ll,548250013ll,567000009ll,583750014ll,603000010ll,620250015ll,640000002ll,653250007ll,669000003ll,682750008ll,699000004ll,713250009ll,730000005ll,744750010ll,762000006ll,777250011ll,795000007ll,810750012ll,829000008ll,845250013ll,864000009ll,880750014ll,900000010ll,917250015ll,937000011ll,954750016ll,975000003ll,988750008ll,1005000004ll,1019250009ll,1036000005ll,1050750010ll,1068000006ll,1083250011ll,1101000007ll,1116750012ll,1135000008ll,1151250013ll,1170000009ll,1186750014ll,1206000010ll,1223250015ll,1243000011ll,1260750016ll,1281000012ll,1299250017ll,1320000004ll,1334250009ll,1351000005ll,1365750010ll,1383000006ll,1398250011ll,1416000007ll,1431750012ll,1450000008ll,1466250013ll,1485000009ll,1501750014ll,1521000010ll,1538250015ll,1558000011ll,1575750016ll,1596000012ll,1614250017ll,1635000013ll,1653750018ll,1675000005ll,1689750010ll,1707000006ll,1722250011ll,1740000007ll,1755750012ll,1774000008ll,1790250013ll,1809000009ll,1825750014ll,1845000010ll,1862250015ll,1882000011ll,1899750016ll,1920000012ll,1938250017ll,1959000013ll,1977750018ll,1999000014ll,2018250019ll,2040000006ll,2055250011ll,2073000007ll,2088750012ll,2107000008ll,2123250013ll,2142000009ll,2158750014ll,2178000010ll,2195250015ll,2215000011ll,2232750016ll,2253000012ll,2271250017ll,2292000013ll,2310750018ll,2332000014ll,2351250019ll,2373000015ll,2392750020ll,2415000007ll,2430750012ll,2449000008ll,2465250013ll,2484000009ll,2500750014ll,2520000010ll,2537250015ll,2557000011ll,2574750016ll,2595000012ll,2613250017ll,2634000013ll,2652750018ll,2674000014ll,2693250019ll,2715000015ll,2734750020ll,2757000016ll,2777250021ll,2800000008ll,2816250013ll,2835000009ll,2851750014ll,2871000010ll,2888250015ll,2908000011ll,2925750016ll,2946000012ll,2964250017ll,2985000013ll,3003750018ll,3025000014ll,3044250019ll,3066000015ll,3085750020ll,3108000016ll,3128250021ll,3151000017ll,3171750022ll,3195000009ll,3211750014ll,3231000010ll,3248250015ll,3268000011ll,3285750016ll,3306000012ll,3324250017ll,3345000013ll,3363750018ll,3385000014ll,3404250019ll,3426000015ll,3445750020ll,3468000016ll,3488250021ll,3511000017ll,3531750022ll,3555000018ll,3576250023ll,3600000001ll,3612750006ll,3628000002ll,3641250007ll,3657000003ll,3670750008ll,3687000004ll,3701250009ll,3718000005ll,3732750010ll,3750000006ll,3765250011ll,3783000007ll,3798750012ll,3817000008ll,3833250013ll,3852000009ll,3868750014ll,3888000010ll,3905250015ll,3925000002ll,3938250007ll,3954000003ll,3967750008ll,3984000004ll,3998250009ll,4015000005ll,4029750010ll,4047000006ll,4062250011ll,4080000007ll,4095750012ll,4114000008ll,4130250013ll,4149000009ll,4165750014ll,4185000010ll,4202250015ll,4222000011ll,4239750016ll,4260000003ll,4273750008ll,4290000004ll,4304250009ll,4321000005ll,4335750010ll,4353000006ll,4368250011ll,4386000007ll,4401750012ll,4420000008ll,4436250013ll,4455000009ll,4471750014ll,4491000010ll,4508250015ll,4528000011ll,4545750016ll,4566000012ll,4584250017ll,4605000004ll,4619250009ll,4636000005ll,4650750010ll,4668000006ll,4683250011ll,4701000007ll,4716750012ll,4735000008ll,4751250013ll,4770000009ll,4786750014ll,4806000010ll,4823250015ll,4843000011ll,4860750016ll,4881000012ll,4899250017ll,4920000013ll,4938750018ll,4960000005ll,4974750010ll,4992000006ll,5007250011ll,5025000007ll,5040750012ll,5059000008ll,5075250013ll,5094000009ll,5110750014ll,5130000010ll,5147250015ll,5167000011ll,5184750016ll,5205000012ll,5223250017ll,5244000013ll,5262750018ll,5284000014ll,5303250019ll,5325000006ll,5340250011ll,5358000007ll,5373750012ll,5392000008ll,5408250013ll,5427000009ll,5443750014ll,5463000010ll,5480250015ll,5500000011ll,5517750016ll,5538000012ll,5556250017ll,5577000013ll,5595750018ll,5617000014ll,5636250019ll,5658000015ll,5677750020ll,5700000007ll,5715750012ll,5734000008ll,5750250013ll,5769000009ll,5785750014ll,5805000010ll,5822250015ll,5842000011ll,5859750016ll,5880000012ll,5898250017ll,5919000013ll,5937750018ll,5959000014ll,5978250019ll,6000000015ll,6019750020ll,6042000016ll,6062250021ll,6085000008ll,6101250013ll,6120000009ll,6136750014ll,6156000010ll,6173250015ll,6193000011ll,6210750016ll,6231000012ll,6249250017ll,6270000013ll,6288750018ll,6310000014ll,6329250019ll,6351000015ll,6370750020ll,6393000016ll,6413250021ll,6436000017ll,6456750022ll,6480000009ll,6496750014ll,6516000010ll,6533250015ll,6553000011ll,6570750016ll,6591000012ll,6609250017ll,6630000013ll,6648750018ll,6670000014ll,6689250019ll,6711000015ll,6730750020ll,6753000016ll,6773250021ll,6796000017ll,6816750022ll,6840000018ll,6861250023ll,6885000010ll,6902250015ll,6922000011ll,6939750016ll,6960000012ll,6978250017ll,6999000013ll,7017750018ll,7039000014ll,7058250019ll,7080000015ll,7099750020ll,7122000016ll,7142250021ll,7165000017ll,7185750022ll,7209000018ll,7230250023ll,7254000019ll,7275750024ll,7300000002ll,7313250007ll,7329000003ll,7342750008ll,7359000004ll,7373250009ll,7390000005ll,7404750010ll,7422000006ll,7437250011ll,7455000007ll,7470750012ll,7489000008ll,7505250013ll,7524000009ll,7540750014ll,7560000010ll,7577250015ll,7597000011ll,7614750016ll,7635000003ll,7648750008ll,7665000004ll,7679250009ll,7696000005ll,7710750010ll,7728000006ll,7743250011ll,7761000007ll,7776750012ll,7795000008ll,7811250013ll,7830000009ll,7846750014ll,7866000010ll,7883250015ll,7903000011ll,7920750016ll,7941000012ll,7959250017ll,7980000004ll,7994250009ll,8011000005ll,8025750010ll,8043000006ll,8058250011ll,8076000007ll,8091750012ll,8110000008ll,8126250013ll,8145000009ll,8161750014ll,8181000010ll,8198250015ll,8218000011ll,8235750016ll,8256000012ll,8274250017ll,8295000013ll,8313750018ll,8335000005ll,8349750010ll,8367000006ll,8382250011ll,8400000007ll,8415750012ll,8434000008ll,8450250013ll,8469000009ll,8485750014ll,8505000010ll,8522250015ll,8542000011ll,8559750016ll,8580000012ll,8598250017ll,8619000013ll,8637750018ll,8659000014ll,8678250019ll,8700000006ll,8715250011ll,8733000007ll,8748750012ll,8767000008ll,8783250013ll,8802000009ll,8818750014ll,8838000010ll,8855250015ll,8875000011ll,8892750016ll,8913000012ll,8931250017ll,8952000013ll,8970750018ll,8992000014ll,9011250019ll,9033000015ll,9052750020ll,9075000007ll,9090750012ll,9109000008ll,9125250013ll,9144000009ll,9160750014ll,9180000010ll,9197250015ll,9217000011ll,9234750016ll,9255000012ll,9273250017ll,9294000013ll,9312750018ll,9334000014ll,9353250019ll,9375000015ll,9394750020ll,9417000016ll,9437250021ll,9460000008ll,9476250013ll,9495000009ll,9511750014ll,9531000010ll,9548250015ll,9568000011ll,9585750016ll,9606000012ll,9624250017ll,9645000013ll,9663750018ll,9685000014ll,9704250019ll,9726000015ll,9745750020ll,9768000016ll,9788250021ll,9811000017ll,9831750022ll,9855000009ll,9871750014ll,9891000010ll,9908250015ll,9928000011ll,9945750016ll,9966000012ll,9984250017ll,10005000013ll,10023750018ll,10045000014ll,10064250019ll,10086000015ll,10105750020ll,10128000016ll,10148250021ll,10171000017ll,10191750022ll,10215000018ll,10236250023ll,10260000010ll,10277250015ll,10297000011ll,10314750016ll,10335000012ll,10353250017ll,10374000013ll,10392750018ll,10414000014ll,10433250019ll,10455000015ll,10474750020ll,10497000016ll,10517250021ll,10540000017ll,10560750022ll,10584000018ll,10605250023ll,10629000019ll,10650750024ll,10675000011ll,10692750016ll,10713000012ll,10731250017ll,10752000013ll,10770750018ll,10792000014ll,10811250019ll,10833000015ll,10852750020ll,10875000016ll,10895250021ll,10918000017ll,10938750022ll,10962000018ll,10983250023ll,11007000019ll,11028750024ll,11053000020ll,11075250025ll,11100000003ll,11113750008ll,11130000004ll,11144250009ll,11161000005ll,11175750010ll,11193000006ll,11208250011ll,11226000007ll,11241750012ll,11260000008ll,11276250013ll,11295000009ll,11311750014ll,11331000010ll,11348250015ll,11368000011ll,11385750016ll,11406000012ll,11424250017ll,11445000004ll,11459250009ll,11476000005ll,11490750010ll,11508000006ll,11523250011ll,11541000007ll,11556750012ll,11575000008ll,11591250013ll,11610000009ll,11626750014ll,11646000010ll,11663250015ll,11683000011ll,11700750016ll,11721000012ll,11739250017ll,11760000013ll,11778750018ll,11800000005ll,11814750010ll,11832000006ll,11847250011ll,11865000007ll,11880750012ll,11899000008ll,11915250013ll,11934000009ll,11950750014ll,11970000010ll,11987250015ll,12007000011ll,12024750016ll,12045000012ll,12063250017ll,12084000013ll,12102750018ll,12124000014ll,12143250019ll,12165000006ll,12180250011ll,12198000007ll,12213750012ll,12232000008ll,12248250013ll,12267000009ll,12283750014ll,12303000010ll,12320250015ll,12340000011ll,12357750016ll,12378000012ll,12396250017ll,12417000013ll,12435750018ll,12457000014ll,12476250019ll,12498000015ll,12517750020ll,12540000007ll,12555750012ll,12574000008ll,12590250013ll,12609000009ll,12625750014ll,12645000010ll,12662250015ll,12682000011ll,12699750016ll,12720000012ll,12738250017ll,12759000013ll,12777750018ll,12799000014ll,12818250019ll,12840000015ll,12859750020ll,12882000016ll,12902250021ll,12925000008ll,12941250013ll,12960000009ll,12976750014ll,12996000010ll,13013250015ll,13033000011ll,13050750016ll,13071000012ll,13089250017ll,13110000013ll,13128750018ll,13150000014ll,13169250019ll,13191000015ll,13210750020ll,13233000016ll,13253250021ll,13276000017ll,13296750022ll,13320000009ll,13336750014ll,13356000010ll,13373250015ll,13393000011ll,13410750016ll,13431000012ll,13449250017ll,13470000013ll,13488750018ll,13510000014ll,13529250019ll,13551000015ll,13570750020ll,13593000016ll,13613250021ll,13636000017ll,13656750022ll,13680000018ll,13701250023ll,13725000010ll,13742250015ll,13762000011ll,13779750016ll,13800000012ll,13818250017ll,13839000013ll,13857750018ll,13879000014ll,13898250019ll,13920000015ll,13939750020ll,13962000016ll,13982250021ll,14005000017ll,14025750022ll,14049000018ll,14070250023ll,14094000019ll,14115750024ll,14140000011ll,14157750016ll,14178000012ll,14196250017ll,14217000013ll,14235750018ll,14257000014ll,14276250019ll,14298000015ll,14317750020ll,14340000016ll,14360250021ll,14383000017ll,14403750022ll,14427000018ll,14448250023ll,14472000019ll,14493750024ll,14518000020ll,14540250025ll,14565000012ll,14583250017ll,14604000013ll,14622750018ll,14644000014ll,14663250019ll,14685000015ll,14704750020ll,14727000016ll,14747250021ll,14770000017ll,14790750022ll,14814000018ll,14835250023ll,14859000019ll,14880750024ll,14905000020ll,14927250025ll,14952000021ll,14974750026ll,15000000004ll,15014250009ll,15031000005ll,15045750010ll,15063000006ll,15078250011ll,15096000007ll,15111750012ll,15130000008ll,15146250013ll,15165000009ll,15181750014ll,15201000010ll,15218250015ll,15238000011ll,15255750016ll,15276000012ll,15294250017ll,15315000013ll,15333750018ll,15355000005ll,15369750010ll,15387000006ll,15402250011ll,15420000007ll,15435750012ll,15454000008ll,15470250013ll,15489000009ll,15505750014ll,15525000010ll,15542250015ll,15562000011ll,15579750016ll,15600000012ll,15618250017ll,15639000013ll,15657750018ll,15679000014ll,15698250019ll,15720000006ll,15735250011ll,15753000007ll,15768750012ll,15787000008ll,15803250013ll,15822000009ll,15838750014ll,15858000010ll,15875250015ll,15895000011ll,15912750016ll,15933000012ll,15951250017ll,15972000013ll,15990750018ll,16012000014ll,16031250019ll,16053000015ll,16072750020ll,16095000007ll,16110750012ll,16129000008ll,16145250013ll,16164000009ll,16180750014ll,16200000010ll,16217250015ll,16237000011ll,16254750016ll,16275000012ll,16293250017ll,16314000013ll,16332750018ll,16354000014ll,16373250019ll,16395000015ll,16414750020ll,16437000016ll,16457250021ll,16480000008ll,16496250013ll,16515000009ll,16531750014ll,16551000010ll,16568250015ll,16588000011ll,16605750016ll,16626000012ll,16644250017ll,16665000013ll,16683750018ll,16705000014ll,16724250019ll,16746000015ll,16765750020ll,16788000016ll,16808250021ll,16831000017ll,16851750022ll,16875000009ll,16891750014ll,16911000010ll,16928250015ll,16948000011ll,16965750016ll,16986000012ll,17004250017ll,17025000013ll,17043750018ll,17065000014ll,17084250019ll,17106000015ll,17125750020ll,17148000016ll,17168250021ll,17191000017ll,17211750022ll,17235000018ll,17256250023ll,17280000010ll,17297250015ll,17317000011ll,17334750016ll,17355000012ll,17373250017ll,17394000013ll,17412750018ll,17434000014ll,17453250019ll,17475000015ll,17494750020ll,17517000016ll,17537250021ll,17560000017ll,17580750022ll,17604000018ll,17625250023ll,17649000019ll,17670750024ll,17695000011ll,17712750016ll,17733000012ll,17751250017ll,17772000013ll,17790750018ll,17812000014ll,17831250019ll,17853000015ll,17872750020ll,17895000016ll,17915250021ll,17938000017ll,17958750022ll,17982000018ll,18003250023ll,18027000019ll,18048750024ll,18073000020ll,18095250025ll,18120000012ll,18138250017ll,18159000013ll,18177750018ll,18199000014ll,18218250019ll,18240000015ll,18259750020ll,18282000016ll,18302250021ll,18325000017ll,18345750022ll,18369000018ll,18390250023ll,18414000019ll,18435750024ll,18460000020ll,18482250025ll,18507000021ll,18529750026ll,18555000013ll,18573750018ll,18595000014ll,18614250019ll,18636000015ll,18655750020ll,18678000016ll,18698250021ll,18721000017ll,18741750022ll,18765000018ll,18786250023ll,18810000019ll,18831750024ll,18856000020ll,18878250025ll,18903000021ll,18925750026ll,18951000022ll,18974250027ll,19000000005ll,19014750010ll,19032000006ll,19047250011ll,19065000007ll,19080750012ll,19099000008ll,19115250013ll,19134000009ll,19150750014ll,19170000010ll,19187250015ll,19207000011ll,19224750016ll,19245000012ll,19263250017ll,19284000013ll,19302750018ll,19324000014ll,19343250019ll,19365000006ll,19380250011ll,19398000007ll,19413750012ll,19432000008ll,19448250013ll,19467000009ll,19483750014ll,19503000010ll,19520250015ll,19540000011ll,19557750016ll,19578000012ll,19596250017ll,19617000013ll,19635750018ll,19657000014ll,19676250019ll,19698000015ll,19717750020ll,19740000007ll,19755750012ll,19774000008ll,19790250013ll,19809000009ll,19825750014ll,19845000010ll,19862250015ll,19882000011ll,19899750016ll,19920000012ll,19938250017ll,19959000013ll,19977750018ll,19999000014ll,20018250019ll,20040000015ll,20059750020ll,20082000016ll,20102250021ll,20125000008ll,20141250013ll,20160000009ll,20176750014ll,20196000010ll,20213250015ll,20233000011ll,20250750016ll,20271000012ll,20289250017ll,20310000013ll,20328750018ll,20350000014ll,20369250019ll,20391000015ll,20410750020ll,20433000016ll,20453250021ll,20476000017ll,20496750022ll,20520000009ll,20536750014ll,20556000010ll,20573250015ll,20593000011ll,20610750016ll,20631000012ll,20649250017ll,20670000013ll,20688750018ll,20710000014ll,20729250019ll,20751000015ll,20770750020ll,20793000016ll,20813250021ll,20836000017ll,20856750022ll,20880000018ll,20901250023ll,20925000010ll,20942250015ll,20962000011ll,20979750016ll,21000000012ll,21018250017ll,21039000013ll,21057750018ll,21079000014ll,21098250019ll,21120000015ll,21139750020ll,21162000016ll,21182250021ll,21205000017ll,21225750022ll,21249000018ll,21270250023ll,21294000019ll,21315750024ll,21340000011ll,21357750016ll,21378000012ll,21396250017ll,21417000013ll,21435750018ll,21457000014ll,21476250019ll,21498000015ll,21517750020ll,21540000016ll,21560250021ll,21583000017ll,21603750022ll,21627000018ll,21648250023ll,21672000019ll,21693750024ll,21718000020ll,21740250025ll,21765000012ll,21783250017ll,21804000013ll,21822750018ll,21844000014ll,21863250019ll,21885000015ll,21904750020ll,21927000016ll,21947250021ll,21970000017ll,21990750022ll,22014000018ll,22035250023ll,22059000019ll,22080750024ll,22105000020ll,22127250025ll,22152000021ll,22174750026ll,22200000013ll,22218750018ll,22240000014ll,22259250019ll,22281000015ll,22300750020ll,22323000016ll,22343250021ll,22366000017ll,22386750022ll,22410000018ll,22431250023ll,22455000019ll,22476750024ll,22501000020ll,22523250025ll,22548000021ll,22570750026ll,22596000022ll,22619250027ll,22645000014ll,22664250019ll,22686000015ll,22705750020ll,22728000016ll,22748250021ll,22771000017ll,22791750022ll,22815000018ll,22836250023ll,22860000019ll,22881750024ll,22906000020ll,22928250025ll,22953000021ll,22975750026ll,23001000022ll,23024250027ll,23050000023ll,23073750028ll,23100000006ll,23115250011ll,23133000007ll,23148750012ll,23167000008ll,23183250013ll,23202000009ll,23218750014ll,23238000010ll,23255250015ll,23275000011ll,23292750016ll,23313000012ll,23331250017ll,23352000013ll,23370750018ll,23392000014ll,23411250019ll,23433000015ll,23452750020ll,23475000007ll,23490750012ll,23509000008ll,23525250013ll,23544000009ll,23560750014ll,23580000010ll,23597250015ll,23617000011ll,23634750016ll,23655000012ll,23673250017ll,23694000013ll,23712750018ll,23734000014ll,23753250019ll,23775000015ll,23794750020ll,23817000016ll,23837250021ll,23860000008ll,23876250013ll,23895000009ll,23911750014ll,23931000010ll,23948250015ll,23968000011ll,23985750016ll,24006000012ll,24024250017ll,24045000013ll,24063750018ll,24085000014ll,24104250019ll,24126000015ll,24145750020ll,24168000016ll,24188250021ll,24211000017ll,24231750022ll,24255000009ll,24271750014ll,24291000010ll,24308250015ll,24328000011ll,24345750016ll,24366000012ll,24384250017ll,24405000013ll,24423750018ll,24445000014ll,24464250019ll,24486000015ll,24505750020ll,24528000016ll,24548250021ll,24571000017ll,24591750022ll,24615000018ll,24636250023ll,24660000010ll,24677250015ll,24697000011ll,24714750016ll,24735000012ll,24753250017ll,24774000013ll,24792750018ll,24814000014ll,24833250019ll,24855000015ll,24874750020ll,24897000016ll,24917250021ll,24940000017ll,24960750022ll,24984000018ll,25005250023ll,25029000019ll,25050750024ll,25075000011ll,25092750016ll,25113000012ll,25131250017ll,25152000013ll,25170750018ll,25192000014ll,25211250019ll,25233000015ll,25252750020ll,25275000016ll,25295250021ll,25318000017ll,25338750022ll,25362000018ll,25383250023ll,25407000019ll,25428750024ll,25453000020ll,25475250025ll,25500000012ll,25518250017ll,25539000013ll,25557750018ll,25579000014ll,25598250019ll,25620000015ll,25639750020ll,25662000016ll,25682250021ll,25705000017ll,25725750022ll,25749000018ll,25770250023ll,25794000019ll,25815750024ll,25840000020ll,25862250025ll,25887000021ll,25909750026ll,25935000013ll,25953750018ll,25975000014ll,25994250019ll,26016000015ll,26035750020ll,26058000016ll,26078250021ll,26101000017ll,26121750022ll,26145000018ll,26166250023ll,26190000019ll,26211750024ll,26236000020ll,26258250025ll,26283000021ll,26305750026ll,26331000022ll,26354250027ll,26380000014ll,26399250019ll,26421000015ll,26440750020ll,26463000016ll,26483250021ll,26506000017ll,26526750022ll,26550000018ll,26571250023ll,26595000019ll,26616750024ll,26641000020ll,26663250025ll,26688000021ll,26710750026ll,26736000022ll,26759250027ll,26785000023ll,26808750028ll,26835000015ll,26854750020ll,26877000016ll,26897250021ll,26920000017ll,26940750022ll,26964000018ll,26985250023ll,27009000019ll,27030750024ll,27055000020ll,27077250025ll,27102000021ll,27124750026ll,27150000022ll,27173250027ll,27199000023ll,27222750028ll,27249000024ll,27273250029ll,27300000007ll,27315750012ll,27334000008ll,27350250013ll,27369000009ll,27385750014ll,27405000010ll,27422250015ll,27442000011ll,27459750016ll,27480000012ll,27498250017ll,27519000013ll,27537750018ll,27559000014ll,27578250019ll,27600000015ll,27619750020ll,27642000016ll,27662250021ll,27685000008ll,27701250013ll,27720000009ll,27736750014ll,27756000010ll,27773250015ll,27793000011ll,27810750016ll,27831000012ll,27849250017ll,27870000013ll,27888750018ll,27910000014ll,27929250019ll,27951000015ll,27970750020ll,27993000016ll,28013250021ll,28036000017ll,28056750022ll,28080000009ll,28096750014ll,28116000010ll,28133250015ll,28153000011ll,28170750016ll,28191000012ll,28209250017ll,28230000013ll,28248750018ll,28270000014ll,28289250019ll,28311000015ll,28330750020ll,28353000016ll,28373250021ll,28396000017ll,28416750022ll,28440000018ll,28461250023ll,28485000010ll,28502250015ll,28522000011ll,28539750016ll,28560000012ll,28578250017ll,28599000013ll,28617750018ll,28639000014ll,28658250019ll,28680000015ll,28699750020ll,28722000016ll,28742250021ll,28765000017ll,28785750022ll,28809000018ll,28830250023ll,28854000019ll,28875750024ll,28900000011ll,28917750016ll,28938000012ll,28956250017ll,28977000013ll,28995750018ll,29017000014ll,29036250019ll,29058000015ll,29077750020ll,29100000016ll,29120250021ll,29143000017ll,29163750022ll,29187000018ll,29208250023ll,29232000019ll,29253750024ll,29278000020ll,29300250025ll,29325000012ll,29343250017ll,29364000013ll,29382750018ll,29404000014ll,29423250019ll,29445000015ll,29464750020ll,29487000016ll,29507250021ll,29530000017ll,29550750022ll,29574000018ll,29595250023ll,29619000019ll,29640750024ll,29665000020ll,29687250025ll,29712000021ll,29734750026ll,29760000013ll,29778750018ll,29800000014ll,29819250019ll,29841000015ll,29860750020ll,29883000016ll,29903250021ll,29926000017ll,29946750022ll,29970000018ll,29991250023ll,30015000019ll,30036750024ll,30061000020ll,30083250025ll,30108000021ll,30130750026ll,30156000022ll,30179250027ll,30205000014ll,30224250019ll,30246000015ll,30265750020ll,30288000016ll,30308250021ll,30331000017ll,30351750022ll,30375000018ll,30396250023ll,30420000019ll,30441750024ll,30466000020ll,30488250025ll,30513000021ll,30535750026ll,30561000022ll,30584250027ll,30610000023ll,30633750028ll,30660000015ll,30679750020ll,30702000016ll,30722250021ll,30745000017ll,30765750022ll,30789000018ll,30810250023ll,30834000019ll,30855750024ll,30880000020ll,30902250025ll,30927000021ll,30949750026ll,30975000022ll,30998250027ll,31024000023ll,31047750028ll,31074000024ll,31098250029ll,31125000016ll,31145250021ll,31168000017ll,31188750022ll,31212000018ll,31233250023ll,31257000019ll,31278750024ll,31303000020ll,31325250025ll,31350000021ll,31372750026ll,31398000022ll,31421250027ll,31447000023ll,31470750028ll,31497000024ll,31521250029ll,31548000025ll,31572750030ll,31600000008ll,31616250013ll,31635000009ll,31651750014ll,31671000010ll,31688250015ll,31708000011ll,31725750016ll,31746000012ll,31764250017ll,31785000013ll,31803750018ll,31825000014ll,31844250019ll,31866000015ll,31885750020ll,31908000016ll,31928250021ll,31951000017ll,31971750022ll,31995000009ll,32011750014ll,32031000010ll,32048250015ll,32068000011ll,32085750016ll,32106000012ll,32124250017ll,32145000013ll,32163750018ll,32185000014ll,32204250019ll,32226000015ll,32245750020ll,32268000016ll,32288250021ll,32311000017ll,32331750022ll,32355000018ll,32376250023ll,32400000010ll,32417250015ll,32437000011ll,32454750016ll,32475000012ll,32493250017ll,32514000013ll,32532750018ll,32554000014ll,32573250019ll,32595000015ll,32614750020ll,32637000016ll,32657250021ll,32680000017ll,32700750022ll,32724000018ll,32745250023ll,32769000019ll,32790750024ll,32815000011ll,32832750016ll,32853000012ll,32871250017ll,32892000013ll,32910750018ll,32932000014ll,32951250019ll,32973000015ll,32992750020ll,33015000016ll,33035250021ll,33058000017ll,33078750022ll,33102000018ll,33123250023ll,33147000019ll,33168750024ll,33193000020ll,33215250025ll,33240000012ll,33258250017ll,33279000013ll,33297750018ll,33319000014ll,33338250019ll,33360000015ll,33379750020ll,33402000016ll,33422250021ll,33445000017ll,33465750022ll,33489000018ll,33510250023ll,33534000019ll,33555750024ll,33580000020ll,33602250025ll,33627000021ll,33649750026ll,33675000013ll,33693750018ll,33715000014ll,33734250019ll,33756000015ll,33775750020ll,33798000016ll,33818250021ll,33841000017ll,33861750022ll,33885000018ll,33906250023ll,33930000019ll,33951750024ll,33976000020ll,33998250025ll,34023000021ll,34045750026ll,34071000022ll,34094250027ll,34120000014ll,34139250019ll,34161000015ll,34180750020ll,34203000016ll,34223250021ll,34246000017ll,34266750022ll,34290000018ll,34311250023ll,34335000019ll,34356750024ll,34381000020ll,34403250025ll,34428000021ll,34450750026ll,34476000022ll,34499250027ll,34525000023ll,34548750028ll,34575000015ll,34594750020ll,34617000016ll,34637250021ll,34660000017ll,34680750022ll,34704000018ll,34725250023ll,34749000019ll,34770750024ll,34795000020ll,34817250025ll,34842000021ll,34864750026ll,34890000022ll,34913250027ll,34939000023ll,34962750028ll,34989000024ll,35013250029ll,35040000016ll,35060250021ll,35083000017ll,35103750022ll,35127000018ll,35148250023ll,35172000019ll,35193750024ll,35218000020ll,35240250025ll,35265000021ll,35287750026ll,35313000022ll,35336250027ll,35362000023ll,35385750028ll,35412000024ll,35436250029ll,35463000025ll,35487750030ll,35515000017ll,35535750022ll,35559000018ll,35580250023ll,35604000019ll,35625750024ll,35650000020ll,35672250025ll,35697000021ll,35719750026ll,35745000022ll,35768250027ll,35794000023ll,35817750028ll,35844000024ll,35868250029ll,35895000025ll,35919750030ll,35947000026ll,35972250031ll,36000000009ll,36016750014ll,36036000010ll,36053250015ll,36073000011ll,36090750016ll,36111000012ll,36129250017ll,36150000013ll,36168750018ll,36190000014ll,36209250019ll,36231000015ll,36250750020ll,36273000016ll,36293250021ll,36316000017ll,36336750022ll,36360000018ll,36381250023ll,36405000010ll,36422250015ll,36442000011ll,36459750016ll,36480000012ll,36498250017ll,36519000013ll,36537750018ll,36559000014ll,36578250019ll,36600000015ll,36619750020ll,36642000016ll,36662250021ll,36685000017ll,36705750022ll,36729000018ll,36750250023ll,36774000019ll,36795750024ll,36820000011ll,36837750016ll,36858000012ll,36876250017ll,36897000013ll,36915750018ll,36937000014ll,36956250019ll,36978000015ll,36997750020ll,37020000016ll,37040250021ll,37063000017ll,37083750022ll,37107000018ll,37128250023ll,37152000019ll,37173750024ll,37198000020ll,37220250025ll,37245000012ll,37263250017ll,37284000013ll,37302750018ll,37324000014ll,37343250019ll,37365000015ll,37384750020ll,37407000016ll,37427250021ll,37450000017ll,37470750022ll,37494000018ll,37515250023ll,37539000019ll,37560750024ll,37585000020ll,37607250025ll,37632000021ll,37654750026ll,37680000013ll,37698750018ll,37720000014ll,37739250019ll,37761000015ll,37780750020ll,37803000016ll,37823250021ll,37846000017ll,37866750022ll,37890000018ll,37911250023ll,37935000019ll,37956750024ll,37981000020ll,38003250025ll,38028000021ll,38050750026ll,38076000022ll,38099250027ll,38125000014ll,38144250019ll,38166000015ll,38185750020ll,38208000016ll,38228250021ll,38251000017ll,38271750022ll,38295000018ll,38316250023ll,38340000019ll,38361750024ll,38386000020ll,38408250025ll,38433000021ll,38455750026ll,38481000022ll,38504250027ll,38530000023ll,38553750028ll,38580000015ll,38599750020ll,38622000016ll,38642250021ll,38665000017ll,38685750022ll,38709000018ll,38730250023ll,38754000019ll,38775750024ll,38800000020ll,38822250025ll,38847000021ll,38869750026ll,38895000022ll,38918250027ll,38944000023ll,38967750028ll,38994000024ll,39018250029ll,39045000016ll,39065250021ll,39088000017ll,39108750022ll,39132000018ll,39153250023ll,39177000019ll,39198750024ll,39223000020ll,39245250025ll,39270000021ll,39292750026ll,39318000022ll,39341250027ll,39367000023ll,39390750028ll,39417000024ll,39441250029ll,39468000025ll,39492750030ll,39520000017ll,39540750022ll,39564000018ll,39585250023ll,39609000019ll,39630750024ll,39655000020ll,39677250025ll,39702000021ll,39724750026ll,39750000022ll,39773250027ll,39799000023ll,39822750028ll,39849000024ll,39873250029ll,39900000025ll,39924750030ll,39952000026ll,39977250031ll,40005000018ll,40026250023ll,40050000019ll,40071750024ll,40096000020ll,40118250025ll,40143000021ll,40165750026ll,40191000022ll,40214250027ll,40240000023ll,40263750028ll,40290000024ll,40314250029ll,40341000025ll,40365750030ll,40393000026ll,40418250031ll,40446000027ll,40471750032ll,40500000001ll};
int main()
{
freopen("count.in","r",stdin);
freopen("count.out","w",stdout);
long n;
scanf("%ld",&n);
//cout << sizeof(table)/sizeof(long long) << std::endl;
long shang = n/500000;
long long f = table[shang];
long r = n % 500000;
long a = shang*500000;
for (long i=1;i<r+1;i++)
{
long tmp = a+i;
while (tmp)
{
f += tmp % 10;
tmp /= 10;
}
}
cout << f;
return 0;
}