├── .gitignore ├── LICENSE.md ├── README.md ├── acmp.ru ├── 0007.cpp ├── 0011.py ├── 0026.cpp ├── 0038.cpp ├── 0040.cpp ├── 0060.cpp ├── 0071.cpp ├── 0072.cpp ├── 0091.cpp ├── 0103.cpp ├── 0107.cpp ├── 0114.cpp ├── 0117.cpp ├── 0123.cpp ├── 0136.cpp ├── 0138.cpp ├── 0142.cpp ├── 0143.cpp ├── 0144.cpp ├── 0145.cpp ├── 0150.cpp ├── 0152.cpp ├── 0172.cpp ├── 0175.cpp ├── 0177.cpp ├── 0179.py ├── 0181.cpp ├── 0192.cpp ├── 0201.cpp ├── 0206.cpp ├── 0219.cpp ├── 0223.cpp ├── 0226.cpp ├── 0249.cpp ├── 0267.cpp ├── 0269.cpp ├── 0275.cpp ├── 0288.cpp ├── 0300.cpp ├── 0329.cpp ├── 0350.cpp ├── 0380.cpp ├── 0425.cpp ├── 0445.cpp ├── 0458.cpp ├── 0470.cpp ├── 0473.cpp ├── 0483.cpp ├── 0486.cpp ├── 0500.cpp ├── 0501.cpp ├── 0502.cpp ├── 0505.cpp ├── 0506.py ├── 0507.cpp ├── 0508.cpp ├── 0510.cpp ├── 0523.py ├── 0525.cpp ├── 0527.cpp ├── 0532.cpp ├── 0533.cpp ├── 0536.cpp ├── 0537.cpp ├── 0541.cpp ├── 0544.py ├── 0545.cpp ├── 0549.py ├── 0552.cpp ├── 0553.cpp ├── 0556.cpp ├── 0557.cpp ├── 0559.cpp ├── 0562.cpp ├── 0565.cpp ├── 0569.cpp ├── 0570.cpp ├── 0572.cpp ├── 0573.cpp ├── 0575.cpp ├── 0578.cpp ├── 0582.cpp ├── 0584.cpp ├── 0588.cpp ├── 0593.cpp ├── 0594.cpp ├── 0595-hash.cpp ├── 0595-pref.cpp ├── 0598.cpp ├── 0601.cpp ├── 0603.cpp ├── 0605.cpp ├── 0611.cpp ├── 0612.cpp ├── 0614.cpp ├── 0616.cpp ├── 0619.cpp ├── 0621-bfs.cpp ├── 0621-dp.cpp ├── 0621.cpp ├── 0622.cpp ├── 0624.cpp ├── 0625.cpp ├── 0626.cpp ├── 0627.cpp ├── 0628.cpp ├── 0629.cpp ├── 0630.cpp ├── 0631a.cpp ├── 0631b.cpp ├── 0632.cpp ├── 0634.cpp ├── 0636.cpp ├── 0638.cpp ├── 0640.cpp ├── 0644.cpp ├── 0646.cpp ├── 0649.cpp ├── 0653.cpp ├── 0655.cpp ├── 0659.cpp ├── 0660.cpp ├── 0661.cpp ├── 0668.cpp ├── 0673.cpp ├── 0681.cpp ├── 0683.cpp ├── 0687.cpp ├── 0688.cpp ├── 0695.cpp ├── 0703.cpp ├── 0704.cpp ├── 0705.cpp ├── 0708.cpp ├── 0709.cpp ├── 0710.cpp ├── 0713.cpp ├── 0714.cpp ├── 0717.cpp ├── 0719.cpp ├── 0722.py ├── 0724.cpp ├── 0726.cpp ├── 0728.cpp ├── 0730.cpp ├── 0731.cpp ├── 0732.cpp ├── 0735.cpp ├── 0736a.cpp ├── 0736b.cpp ├── 0736c.cpp ├── 0736d.cpp ├── 0737.cpp ├── 0739.cpp ├── 0741.cpp ├── 0744.cpp ├── 0745.cpp ├── 0746.cpp ├── 0747.cpp ├── 0749.cpp ├── 0752.cpp ├── 0753.cpp ├── 0758.cpp ├── 0765.cpp ├── 0770.cpp ├── 0774.cpp ├── 0776.cpp ├── 0779.cpp ├── 0781.cpp ├── 0788.cpp ├── 0789.cpp ├── 0796.cpp ├── 0805.cpp ├── 0806.cpp ├── 0810.cpp ├── 0813.cpp ├── 0815.cpp ├── 0823.cpp ├── 0826.cpp ├── 0828.py ├── 0829.cpp ├── 0832.cpp ├── 0835.cpp ├── 0836.cpp ├── 0840.cpp ├── 0848.cpp ├── 0849.cpp ├── 0856.cpp ├── 0857.cpp ├── 0858.cpp ├── 0862.cpp ├── 0863a.cpp ├── 0865.cpp ├── 0867.cpp ├── 0870.cpp ├── 0873.cpp ├── 0874.cpp ├── 0881.cpp ├── 0883.cpp ├── 0884.cpp ├── 0886a.cpp ├── 0886b.cpp ├── 0886c.cpp ├── 0887.cpp ├── 0898.cpp ├── 0899.cpp ├── 0902.cpp ├── 0904.cpp ├── 0906.cpp ├── 0911.cpp ├── 0913.cpp ├── 0915.cpp ├── 0918.cpp ├── 0921.cpp ├── 0923.cpp ├── 0927.cpp ├── 0928.cpp ├── 0931.cpp ├── 0934.cpp ├── 0936.cpp ├── 0939.cpp ├── 0944.cpp ├── 0945.cpp ├── 0946.cpp ├── 0953.cpp ├── 0954.cpp ├── 0955.cpp ├── 0956.cpp ├── 0957.cpp ├── 0960.cpp ├── 0963.cpp ├── 0964.cpp ├── 0965.cpp ├── 0968.cpp ├── 0969a.cpp ├── 0969b.cpp ├── 0974.cpp ├── 0979.cpp ├── 0982.cpp ├── 0983.cpp ├── 0985.cpp ├── 0987.cpp ├── 0988.cpp ├── 0989.cpp ├── 0991.cpp ├── 0992.cpp ├── 0993.cpp ├── 0994.cpp ├── 0995.cpp ├── 1011.cpp ├── 1029.cpp ├── 1030.cpp ├── 1035.cpp ├── 1047.cpp ├── 1081.cpp ├── 1082.cpp ├── 1083.cpp ├── 1084.cpp ├── 1130.py ├── 1131.cpp ├── 1155.cpp ├── 1156.cpp ├── 1157a.cpp ├── 1157b.cpp ├── 1158.cpp ├── 1160.cpp ├── 1172.cpp ├── 1173.cpp ├── 1174.cpp ├── 1175.cpp ├── 1176.cpp ├── 1176b.cpp ├── 1177a.cpp ├── 1178.cpp ├── 1178a.cpp ├── 1179.cpp ├── 1180.cpp ├── 1180b.cpp ├── 1181.cpp ├── 1182.cpp ├── 1183.cpp ├── 1184.cpp ├── 1185.cpp ├── 1185a.cpp ├── 1186.cpp ├── 1187.cpp ├── 1188.cpp ├── 1197.cpp ├── 1211.cpp ├── 1211.py ├── 1241.cpp ├── 1243.cpp ├── 1244.cpp ├── 1245.cpp ├── 1246.cpp ├── 1247.cpp ├── 1248.cpp ├── 1249.cpp ├── 1250.cpp ├── 1298.cpp ├── 1298b.cpp ├── 1320.cpp ├── 1325.cpp ├── 1327.cpp ├── 1333.cpp ├── 1334.cpp ├── 1339.cpp ├── 1340.cpp ├── 1346.cpp ├── 1364.cpp ├── 1385.cpp ├── 1386.cpp ├── 1387.cpp ├── 1388.cpp ├── 1389.cpp ├── 1390.cpp ├── 1391.cpp ├── 1397.cpp ├── 1404.cpp ├── 1405.cpp ├── 1406.cpp ├── 1407.cpp ├── 1410.cpp ├── 1411a.cpp ├── 1411b.cpp ├── 1411c.cpp ├── 1412.cpp ├── 1413.cpp ├── 1414.cpp ├── 1414a.cpp ├── 1414b.cpp ├── 1415.cpp ├── 1438.cpp ├── 1440.cpp ├── 1462.cpp ├── 1463.cpp ├── 1468.cpp ├── 1469.cpp ├── 1470.cpp ├── 1472.cpp ├── 1473.cpp ├── 1474.cpp ├── 1475.cpp ├── 1477.cpp ├── 1565.cpp ├── 1566.cpp ├── 1567.cpp ├── 1568.cpp ├── 1569.cpp ├── 1571.cpp ├── 1572.cpp ├── 1573.cpp └── 1648.cpp ├── algos ├── Algebra │ ├── Algebra.hpp │ └── examples │ │ ├── 1778D.cpp │ │ └── eolymp-4508-max-xor.cpp ├── Allocator.hpp ├── Brute.hpp ├── Convex-Hull-Trick │ ├── ConvexHullTrick.hpp │ └── examples │ │ └── codeforces-gym-101341-L.cpp ├── Data-Structures │ ├── Bitset.hpp │ ├── DSU.hpp │ ├── DynamicLazySegmentTree.hpp │ ├── Fenwick.hpp │ ├── MapOff.hpp │ ├── OrderedSet.hpp │ ├── PrefSums.hpp │ ├── SegmentTree.hpp │ ├── SegmentTreeLazy.hpp │ ├── SegmentTreeLazyTraits.hpp │ ├── SparseTable.hpp │ ├── examples-Fenwick │ │ └── 1354D.cpp │ ├── examples-MapOff │ │ └── 1783D.cpp │ ├── examples-OrderedSet │ │ └── 1354D.cpp │ ├── examples-SegmentTree │ │ ├── acmp-1183-gcd.cpp │ │ ├── acmp-1184-maxpos.cpp │ │ ├── acmp-1185-max-set.cpp │ │ ├── acmp-1186-sum-set.cpp │ │ ├── acmp-1187-gcd-set.cpp │ │ └── dynamic_segment_tree.cpp │ └── examples-SparseTable │ │ ├── 0818E.cpp │ │ ├── 1731D.cpp │ │ └── 1783E.cpp ├── Fast-Input-Output │ ├── FastIO.hpp │ └── examples │ │ ├── codeforces-0600D.cpp │ │ ├── codeforces-1076C.cpp │ │ ├── codeforces-1141A.cpp │ │ ├── codeforces-1141B.cpp │ │ ├── codeforces-1141C.cpp │ │ ├── codeforces-1141D.cpp │ │ ├── codeforces-1141E.cpp │ │ ├── codeforces-1141F1.cpp │ │ ├── codeforces-1141F2.cpp │ │ ├── codeforces-1141G.cpp │ │ └── timus-1001.cpp ├── FastRand32.hpp ├── FindHeaders.ps1 ├── Geometry │ ├── Examples │ │ └── RuCode-7.0-Qual-H.cpp │ ├── geoma.hpp │ └── triangulate.hpp ├── Hash │ └── hash.hpp ├── Numeric │ ├── Factor.hpp │ └── numeric.hpp ├── Testing │ └── brute.cpp ├── Tree │ ├── BinaryJumps.hpp │ ├── EulerTour.hpp │ ├── HLD.hpp │ ├── LCA.hpp │ ├── Tree.hpp │ └── examples │ │ ├── 1778E.cpp │ │ ├── 1794E.cpp │ │ └── 1806E_hld.cpp ├── algos.bash_aliases.rc ├── debug.hpp ├── libexpand-codeblocks.cpp ├── libexpand.cpp ├── template.hpp ├── test.cpp └── timer.hpp ├── codeforces-parser ├── README.md ├── build.sh ├── cf-common.hpp ├── contest-status.cpp ├── get-link.cpp ├── get-rating.sh ├── group-contests.cpp ├── list-of-users.cpp ├── process-rating.cpp ├── search-in-file.cpp ├── submission.hpp └── user-status.cpp ├── codeforces.com ├── 0008C.cpp ├── 0020C.cpp ├── 0051C.cpp ├── 0065C.cpp ├── 0068B.cpp ├── 0083B.cpp ├── 0180E.cpp ├── 0186C.cpp ├── 0246E.cpp ├── 0271D.cpp ├── 0375D.cpp ├── 0474B.cpp ├── 0514D-1.cpp ├── 0514D-2.cpp ├── 0519E.cpp ├── 0522D.cpp ├── 0567C.cpp ├── 0590B.cpp ├── 0914D.cpp ├── 0996E.cpp ├── 1000F.cpp ├── 1003A.cpp ├── 1003B.cpp ├── 1003C.cpp ├── 1003D.cpp ├── 1003E.cpp ├── 1003F.cpp ├── 1111D.cpp ├── 1118F2.cpp ├── 1119D.cpp ├── 1119E.cpp ├── 1137B.cpp ├── 1151E.cpp ├── 1153D.cpp ├── 1157G.cpp ├── 1163D.cpp ├── 1187E.cpp ├── 1188B.cpp ├── 1201D.cpp ├── 1202C.cpp ├── 1264C.cpp ├── 1265E-2.cpp ├── 1265E.cpp ├── 1299B.cpp ├── 1299C.cpp ├── 1305F.cpp ├── 1416D.cpp ├── 1771C.cpp ├── 1794D.cpp ├── 1794E.cpp ├── 1859E.cpp ├── 1864E.cpp ├── Codeforces Ladder 1500-1599 (extra) │ ├── 0034C.cpp │ ├── 0034D.cpp │ ├── 0053C.cpp │ ├── 0063A.cpp │ ├── 0091B.cpp │ ├── 0092B.cpp │ ├── 0103B.cpp │ ├── 0106C.cpp │ ├── 0107A.cpp │ ├── 0108A.cpp │ ├── 0114A.cpp │ ├── 0122B.cpp │ ├── 0127A.cpp │ ├── 0127B.cpp │ ├── 0129B.cpp │ ├── 0133B.cpp │ ├── 0135A.cpp │ ├── 0137A.cpp │ ├── 0137C.cpp │ ├── 0144C.cpp │ ├── 0145A.cpp │ ├── 0146A.cpp │ ├── 0148C.cpp │ ├── 0149C.cpp │ ├── 0150A.cpp │ ├── 0157A.cpp │ ├── 0157B.cpp │ ├── 0160C.cpp │ ├── 0165B.cpp │ ├── 0185A.cpp │ ├── 0202A.cpp │ ├── 0203C.cpp │ ├── 0208D.cpp │ ├── 0216A.cpp │ ├── 0221B.cpp │ ├── 0231D.cpp │ ├── 0233B.cpp │ ├── 0237C.cpp │ ├── 0244B.cpp │ ├── 0246A.cpp │ ├── 0246C.cpp │ ├── 0246E.cpp │ ├── 0248B.cpp │ ├── 0255A.cpp │ ├── 0255B.cpp │ ├── 0259B.cpp │ ├── 0260C.cpp │ ├── 0261A.cpp │ ├── 0262A.cpp │ ├── 0263B.cpp │ ├── 0263D.cpp │ ├── 0265A.cpp │ ├── 0265B.cpp │ ├── 0268A.cpp │ ├── 0268B.cpp │ ├── 0272B.cpp │ ├── 0274A.cpp │ ├── 0278A.cpp │ ├── 0281B.cpp │ ├── 0284A.cpp │ ├── 0284B.cpp │ ├── 0288A.cpp │ ├── 0289A.cpp │ ├── 0294A.cpp │ ├── 0302B.cpp │ ├── 0312A.cpp │ ├── 0317A.cpp │ ├── 0318B.cpp │ ├── 0322A.cpp │ ├── 0334B.cpp │ ├── 0336C.cpp │ ├── 0337C.cpp │ ├── 0340A.cpp │ ├── 0343A.cpp │ ├── 0346A.cpp │ ├── 0353B.cpp │ ├── 0355A.cpp │ ├── 0358B.cpp │ ├── 0359A.cpp │ ├── 0359B.cpp │ ├── 0362B.cpp │ ├── 0363A.cpp │ ├── 0365A.cpp │ ├── 0366A.cpp │ ├── 0367A.cpp │ ├── 0369A.cpp │ ├── 0369B.cpp │ ├── 0370A.cpp │ ├── 0376A.cpp │ ├── 0381B.cpp │ ├── 0382A.cpp │ ├── 0383A.cpp │ ├── 0385B.cpp │ ├── 0389A.cpp │ ├── 0400A.cpp │ ├── 0400C.cpp │ ├── 0404A.cpp │ ├── 0405B.cpp │ ├── 0414A.cpp │ ├── 0415A.cpp │ ├── 0416A.cpp │ ├── 0416B.cpp │ ├── 0424A.cpp │ ├── 0424B.cpp │ ├── 0424C.cpp │ ├── 0427A.cpp │ ├── 0427B.cpp │ ├── 0429A.cpp │ ├── 0430A.cpp │ ├── 0432B.cpp │ ├── 0432C.cpp │ ├── 0435B.cpp │ ├── 0435C.cpp │ ├── 0437A.cpp │ ├── 0437B.cpp │ ├── 0439A.cpp │ ├── 0439B.cpp │ ├── 0441A.cpp │ ├── 0445B.cpp │ ├── 0448A.cpp │ ├── 0451A.cpp │ ├── 0467B.cpp │ ├── 0468A.cpp │ ├── 0469B.cpp │ ├── 0471A.cpp │ ├── 0471B.cpp │ ├── 0471C.cpp │ ├── 0476C.cpp │ ├── 0476D.cpp │ ├── 0478B.cpp │ ├── 0484A.cpp │ ├── 0485B.cpp │ ├── 0486A.cpp │ ├── 0486B.cpp │ ├── 0488B.cpp │ ├── 0493A.cpp │ ├── 0493B.cpp │ ├── 0495A.cpp │ ├── 0496B.cpp │ ├── 0501B.cpp │ ├── 0507B.cpp │ ├── 0507C.cpp │ ├── 0508B.cpp │ ├── 0514B.cpp │ ├── 0515A.cpp │ ├── 0515C.cpp │ ├── 0519A.cpp │ ├── 0519B.cpp │ ├── 0519C.cpp │ ├── 0525A.cpp │ ├── 0525B.cpp │ ├── 0525C.cpp │ ├── 0535C.cpp │ ├── 0545C.cpp │ ├── 0545D.cpp │ ├── 0545E.cpp │ ├── 0546B.cpp │ ├── 0546C.cpp │ ├── 0550A.cpp │ ├── 0550B.cpp │ ├── 0551B.cpp │ ├── 0552D.cpp │ ├── 0554A.cpp │ ├── 0554B.cpp │ ├── 0556A.cpp │ ├── 0557B.cpp │ ├── 0557C.cpp │ ├── 0558C.cpp │ ├── 0559A.cpp │ ├── 0560B.cpp │ ├── 0570C.cpp │ ├── 0573A.cpp │ ├── 0574A.cpp │ ├── 0574B.cpp │ ├── 0576A.cpp │ ├── 0577B.cpp │ ├── 0580B.cpp │ ├── 0580C.cpp │ ├── 0580D.cpp │ ├── 0582A.cpp │ ├── 0584D.cpp │ ├── 0592C.cpp │ ├── 0601A.cpp │ ├── 0602B.cpp │ ├── 0603A.cpp │ ├── 0604B.cpp │ ├── 0617C.cpp │ ├── 0625A.cpp │ ├── 0629D.cpp │ ├── 0650A.cpp │ ├── 0671A.cpp │ ├── 0675C.cpp │ ├── 0675D.cpp │ ├── 0681C.cpp │ ├── 0682D.cpp │ ├── 0706C.cpp │ ├── 0706D.cpp │ ├── 0707C.cpp │ ├── 0711C.cpp │ ├── 0712C.cpp │ └── 0721C.cpp ├── Codeforces Ladder 1500-1599 │ ├── 0058A.cpp │ ├── 0061A.cpp │ ├── 0071A.cpp │ ├── 0096A.cpp │ ├── 0110A.cpp │ ├── 0112A.cpp │ ├── 0115A.cpp │ ├── 0116A.cpp │ ├── 0118A.cpp │ ├── 0118B.cpp │ ├── 0118D.cpp │ ├── 0136A.cpp │ ├── 0141A.cpp │ ├── 0152C.cpp │ ├── 0160A.cpp │ ├── 0165C.cpp │ ├── 0166A.cpp │ ├── 0166E.cpp │ ├── 0189A.cpp │ ├── 0217A.cpp │ ├── 0219A.cpp │ ├── 0219C.cpp │ ├── 0220A.cpp │ ├── 0224B.cpp │ ├── 0225C.cpp │ ├── 0230B.cpp │ ├── 0231C.cpp │ ├── 0246D.cpp │ ├── 0253B.cpp │ ├── 0257C.cpp │ ├── 0258A.cpp │ ├── 0264A.cpp │ ├── 0268C.cpp │ ├── 0270A.cpp │ ├── 0272C.cpp │ ├── 0275B.cpp │ ├── 0276C.cpp │ ├── 0276D.cpp │ ├── 0279C.cpp │ ├── 0285A.cpp │ ├── 0285C.cpp │ ├── 0289B.cpp │ ├── 0300C.cpp │ ├── 0313B.cpp │ ├── 0322B.cpp │ ├── 0327A.cpp │ ├── 0332B.cpp │ ├── 0337A.cpp │ ├── 0339B.cpp │ ├── 0339C.cpp │ ├── 0339D.cpp │ ├── 0349A.cpp │ ├── 0349B.cpp │ ├── 0363B.cpp │ ├── 0369C.cpp │ ├── 0371C.cpp │ ├── 0377A.cpp │ ├── 0382C.cpp │ ├── 0385C.cpp │ ├── 0388A.cpp │ ├── 0404C.cpp │ ├── 0414B.cpp │ ├── 0416C.cpp │ ├── 0427C.cpp │ ├── 0431C.cpp │ ├── 0433B.cpp │ ├── 0437C.cpp │ ├── 0439C.cpp │ ├── 0441C.cpp │ ├── 0443B.cpp │ ├── 0448C.cpp │ ├── 0448D.cpp │ ├── 0455A.cpp │ ├── 0456A.cpp │ ├── 0460B.cpp │ ├── 0460C.cpp │ ├── 0463B.cpp │ ├── 0463C.cpp │ ├── 0466B.cpp │ ├── 0466C.cpp │ ├── 0467C.cpp │ ├── 0478C.cpp │ ├── 0479C.cpp │ ├── 0479D.cpp │ ├── 0483B.cpp │ ├── 0486D-2.cpp │ ├── 0486D.cpp │ ├── 0493C.cpp │ ├── 0493D.cpp │ ├── 0496C.cpp │ ├── 0501A.cpp │ ├── 0501C.cpp │ ├── 0505C.cpp │ ├── 0508C.cpp │ ├── 0510B.cpp │ ├── 0510C.cpp │ ├── 0519D.cpp │ └── 0550C.cpp ├── Codeforces Ladder 1600-1699 (extra) │ ├── 0027E.cpp │ ├── 0031A.cpp │ ├── 0031B.cpp │ ├── 0041B.cpp │ ├── 0041C.cpp │ ├── 0069E.cpp │ ├── 0083A.cpp │ ├── 0084A.cpp │ ├── 0091A.cpp │ ├── 0095C.cpp │ ├── 0103A.cpp │ ├── 0107B.cpp │ ├── 0111A.cpp │ ├── 0150B.cpp │ ├── 0156A.cpp │ ├── 0190C.cpp │ ├── 0190D.cpp │ ├── 0191A.cpp │ ├── 0194A.cpp │ ├── 0208C.cpp │ ├── 0216B.cpp │ ├── 0222D.cpp │ ├── 0222E.cpp │ ├── 0229B.cpp │ ├── 0252A.cpp │ ├── 0260D.cpp │ ├── 0263C.cpp │ ├── 0269A.cpp │ ├── 0270B.cpp │ ├── 0272D.cpp │ ├── 0282D.cpp │ ├── 0286A.cpp │ ├── 0288B.cpp │ ├── 0294C.cpp │ ├── 0297B.cpp │ ├── 0305C.cpp │ ├── 0313D.cpp │ ├── 0327C.cpp │ ├── 0327D.cpp │ ├── 0329A.cpp │ ├── 0329B.cpp │ ├── 0342B.cpp │ ├── 0343B.cpp │ ├── 0350A.cpp │ ├── 0353C.cpp │ ├── 0353D.cpp │ ├── 0361B.cpp │ ├── 0368A.cpp │ ├── 0375A.cpp │ ├── 0402B.cpp │ ├── 0404D.cpp │ ├── 0405D.cpp │ ├── 0425A.cpp │ ├── 0427E.cpp │ ├── 0431D.cpp │ ├── 0437D.cpp │ ├── 0451C.cpp │ ├── 0467A.cpp │ ├── 0495B.cpp │ ├── 0499B.cpp │ ├── 0510D.cpp │ ├── 0520C.cpp │ ├── 0525E.cpp │ ├── 0535B.cpp │ ├── 0540B.cpp │ ├── 0548B.cpp │ ├── 0557D.cpp │ ├── 0573B.cpp │ ├── 0584C.cpp │ ├── 0599D.cpp │ ├── 0610C.cpp │ ├── 0615B.cpp │ ├── 0615C.cpp │ ├── 0631C.cpp │ ├── 0650B.cpp │ ├── 0676C.cpp │ ├── 0682C.cpp │ ├── 0689C.cpp │ ├── 0703D-1.cpp │ ├── 0703D-2.cpp │ ├── 0707D.cpp │ ├── 0711D.cpp │ ├── 0743D.cpp │ ├── 0749C.cpp │ └── 0777D.cpp ├── Codeforces Ladder 1600-1699 │ ├── 0069A.cpp │ ├── 0075C.cpp │ ├── 0122A.cpp │ ├── 0126B.cpp │ ├── 0148D.cpp │ ├── 0182D.cpp │ ├── 0208A.cpp │ ├── 0214A.cpp │ ├── 0214B.cpp │ ├── 0219D.cpp │ ├── 0230A.cpp │ ├── 0231A.cpp │ ├── 0236A.cpp │ ├── 0242E.cpp │ ├── 0255C.cpp │ ├── 0263A.cpp │ ├── 0264B.cpp │ ├── 0269B.cpp │ ├── 0274B.cpp │ ├── 0277A.cpp │ ├── 0281A.cpp │ ├── 0282A.cpp │ ├── 0282C.cpp │ ├── 0283A.cpp │ ├── 0287B.cpp │ ├── 0294B.cpp │ ├── 0295A.cpp │ ├── 0295B.cpp │ ├── 0313C.cpp │ ├── 0318A.cpp │ ├── 0340D.cpp │ ├── 0344A.cpp │ ├── 0348A.cpp │ ├── 0350C.cpp │ ├── 0358D.cpp │ ├── 0359D-1.cpp │ ├── 0359D-2.cpp │ ├── 0363C.cpp │ ├── 0371D.cpp │ ├── 0400D.cpp │ ├── 0401D.cpp │ ├── 0439D.cpp │ ├── 0446A.cpp │ ├── 0451D.cpp │ ├── 0459C.cpp │ ├── 0459D-1.cpp │ ├── 0459D-2.cpp │ ├── 0463D.cpp │ ├── 0471D.cpp │ ├── 0476B.cpp │ ├── 0478D.cpp │ ├── 0479E.cpp │ ├── 0486C.cpp │ ├── 0514C.cpp │ ├── 0540C.cpp │ └── 0540D.cpp ├── Codeforces Ladder 1700-1799 (extra) │ ├── 0027C.cpp │ ├── 0027D.cpp │ ├── 0035C.cpp │ ├── 0041D.cpp │ ├── 0041E.cpp │ ├── 0043C.cpp │ ├── 0056A.cpp │ ├── 0056E.cpp │ ├── 0059B.cpp │ ├── 0077B.cpp │ ├── 0094A.cpp │ ├── 0137E.cpp │ ├── 0154A.cpp │ ├── 0154B.cpp │ ├── 0156C.cpp │ ├── 0160D.cpp │ ├── 0165E.cpp │ ├── 0196A.cpp │ ├── 0197A.cpp │ ├── 0198A.cpp │ ├── 0201A.cpp │ ├── 0213B.cpp │ ├── 0213C.cpp │ ├── 0222C.cpp │ ├── 0223A.cpp │ ├── 0223B.cpp │ ├── 0228E.cpp │ ├── 0229C.cpp │ ├── 0242D.cpp │ ├── 0243B.cpp │ ├── 0257D.cpp │ ├── 0258C.cpp │ ├── 0269C.cpp │ ├── 0271C.cpp │ ├── 0285D.cpp │ ├── 0288C.cpp │ ├── 0303A.cpp │ ├── 0314A.cpp │ ├── 0314B.cpp │ ├── 0327E.cpp │ ├── 0333B.cpp │ ├── 0336D.cpp │ ├── 0348B.cpp │ ├── 0358C.cpp │ ├── 0378A.cpp │ ├── 0387C.cpp │ ├── 0451E.cpp │ ├── 0460D.cpp │ ├── 0508E.cpp │ ├── 0545A.cpp │ ├── 0552E.cpp │ ├── 0553A.cpp │ ├── 0555A.cpp │ ├── 0556B.cpp │ ├── 0560A.cpp │ ├── 0576C.cpp │ ├── 0577A.cpp │ ├── 0580A.cpp │ ├── 0599B.cpp │ ├── 0599C.cpp │ ├── 0605B.cpp │ ├── 0607B.cpp │ ├── 0614B.cpp │ ├── 0617D.cpp │ ├── 0621C.cpp │ ├── 0625B.cpp │ ├── 0629C.cpp │ ├── 0631D.cpp │ ├── 0651A.cpp │ ├── 0681D.cpp │ ├── 0687C.cpp │ └── 0689D.cpp ├── Codeforces Ladder 1700-1799 │ ├── 0059A.cpp │ ├── 0061D.cpp │ ├── 0061E.cpp │ ├── 0109C.cpp │ ├── 0111B.cpp │ ├── 0113B.cpp │ ├── 0144D.cpp │ ├── 0148E.cpp │ ├── 0204A.cpp │ ├── 0204B.cpp │ ├── 0242C.cpp │ ├── 0243A.cpp │ ├── 0276E.cpp │ ├── 0319B.cpp │ ├── 0321A.cpp │ ├── 0321C.cpp │ ├── 0334A.cpp │ ├── 0337D.cpp │ ├── 0346B.cpp │ ├── 0354C.cpp │ ├── 0363D.cpp │ ├── 0364A.cpp │ ├── 0367B.cpp │ ├── 0367C.cpp │ ├── 0372B.cpp │ ├── 0378B.cpp │ ├── 0380C.cpp │ ├── 0383C.cpp │ ├── 0383D.cpp │ ├── 0432D.cpp │ ├── 0438D.cpp │ ├── 0442B.cpp │ ├── 0453B.cpp │ ├── 0455B.cpp │ ├── 0455C.cpp │ ├── 0459E.cpp │ ├── 0461B.cpp │ ├── 0476A.cpp │ ├── 0482B.cpp │ ├── 0494A.cpp │ ├── 0494B.cpp │ ├── 0546D.cpp │ ├── 0547B.cpp │ ├── 0550D.cpp │ ├── 0551C.cpp │ ├── 0559B.cpp │ └── 0570D.cpp ├── Codeforces Ladder 1800-1899 (extra) │ ├── 0029A.cpp │ ├── 0078A.cpp │ ├── 0080B.cpp │ ├── 0357A.cpp │ ├── 0385A.cpp │ └── 0426A.cpp ├── Codeforces Ladder 1800-1899 │ ├── 0071C.cpp │ ├── 0191C.cpp │ ├── 0220B.cpp │ ├── 0235A.cpp │ ├── 0283B.cpp │ ├── 0295C.cpp │ ├── 0312B.cpp │ ├── 0314C.cpp │ ├── 0319C.cpp │ ├── 0321B.cpp │ ├── 0343C.cpp │ ├── 0354A.cpp │ ├── 0359C.cpp │ ├── 0360B.cpp │ ├── 0366C.cpp │ ├── 0368B.cpp │ ├── 0372A.cpp │ ├── 0372C.cpp │ ├── 0373A.cpp │ ├── 0374C.cpp │ ├── 0384A.cpp │ ├── 0388B.cpp │ ├── 0389B.cpp │ ├── 0429B.cpp │ ├── 0443A.cpp │ ├── 0449B.cpp │ ├── 0464A.cpp │ ├── 0466D.cpp │ ├── 0484B.cpp │ ├── 0486E.cpp │ ├── 0487B.cpp │ ├── 0498C.cpp │ ├── 0507E.cpp │ └── 0592D.cpp ├── Div 3 Rounds │ ├── 1092C.cpp │ ├── 1092D1.cpp │ ├── 1092D2.cpp │ ├── 1102A.cpp │ ├── 1102B.cpp │ ├── 1102C.cpp │ ├── 1102D.cpp │ ├── 1102E.cpp │ ├── 1102F-dp.cpp │ ├── 1102F.cpp │ ├── 1154A.cpp │ ├── 1154B.cpp │ ├── 1154C.cpp │ └── 1154E.cpp ├── Div3-1009 │ ├── a.cpp │ ├── b.cpp │ ├── c.cpp │ ├── d.cpp │ └── e.cpp └── Educational Codeforces Rounds │ ├── 01-A.cpp │ ├── 01-B.cpp │ ├── 01-C.cpp │ ├── 01-D.cpp │ ├── 01-E.cpp │ ├── 02-A.cpp │ ├── 02-B.cpp │ ├── 02-C.cpp │ ├── 02-D.cpp │ ├── 02-E.cpp │ ├── 03-A.cpp │ ├── 03-B.cpp │ ├── 03-C.cpp │ ├── 03-D.cpp │ ├── 03-E.cpp │ ├── 04-A.cpp │ ├── 04-B.cpp │ ├── 04-C.cpp │ ├── 04-D.cpp │ ├── 05-A.cpp │ ├── 05-B.cpp │ ├── 05-C.cpp │ ├── 05-D.cpp │ ├── 05-E.cpp │ ├── 06-A.cpp │ ├── 06-B.cpp │ ├── 06-C.cpp │ ├── 06-D.cpp │ ├── 06-E.cpp │ ├── 07-A.cpp │ ├── 07-B.cpp │ ├── 07-C.cpp │ ├── 07-D.cpp │ ├── 07-E.cpp │ ├── 08-A.cpp │ ├── 08-B.cpp │ ├── 08-C.cpp │ ├── 08-E.cpp │ ├── 09-A.cpp │ ├── 09-B.cpp │ ├── 09-C.cpp │ ├── 09-D.cpp │ ├── 09-E.cpp │ ├── 10-A.cpp │ ├── 10-B.cpp │ ├── 10-C.cpp │ ├── 10-D.cpp │ ├── 10-E.cpp │ ├── 11-A.cpp │ ├── 11-B.cpp │ ├── 11-C.cpp │ ├── 11-D.cpp │ ├── 12-A.cpp │ ├── 12-B.cpp │ ├── 12-C.cpp │ ├── 12-D.cpp │ ├── 12-E.cpp │ ├── 13-A.cpp │ ├── 13-B.cpp │ ├── 13-C.cpp │ ├── 13-D.cpp │ ├── 14-A.cpp │ ├── 14-B.cpp │ ├── 14-C.cpp │ ├── 14-D.cpp │ ├── 14-E.cpp │ ├── 15-A.cpp │ ├── 15-B.cpp │ ├── 15-C.cpp │ ├── 15-D.cpp │ ├── 15-E.cpp │ ├── 16-A.cpp │ ├── 16-B.cpp │ ├── 16-C.cpp │ ├── 16-D.cpp │ ├── 16-E.cpp │ ├── 17-A.cpp │ ├── 17-B.cpp │ ├── 17-C.cpp │ ├── 17-D.cpp │ ├── 18-A.cpp │ ├── 18-B.cpp │ ├── 18-C.cpp │ ├── 18-D.cpp │ ├── 19-A.cpp │ ├── 19-B.cpp │ ├── 19-C.cpp │ ├── 19-D.cpp │ ├── 19-E.cpp │ ├── 20-A.cpp │ ├── 20-B.cpp │ ├── 20-C.cpp │ ├── 20-D.cpp │ ├── 21-A.cpp │ ├── 21-B.cpp │ ├── 21-C.cpp │ ├── 21-D.cpp │ ├── 21-E.cpp │ ├── 22-A.cpp │ ├── 22-B.cpp │ ├── 22-C.cpp │ ├── 22-E.cpp │ ├── 23-A.cpp │ ├── 23-B.cpp │ ├── 23-C.cpp │ ├── 23-D.cpp │ ├── 23-E.cpp │ ├── 24-A.cpp │ ├── 24-B.cpp │ ├── 24-C.cpp │ ├── 24-D.cpp │ ├── 24-E.cpp │ ├── 25-A.cpp │ ├── 25-B.cpp │ ├── 25-C.cpp │ ├── 25-D.cpp │ ├── 25-E.cpp │ ├── 26-A.cpp │ ├── 26-B.cpp │ ├── 26-C.cpp │ ├── 26-D.cpp │ ├── 27-A.cpp │ ├── 27-B.cpp │ ├── 27-C.cpp │ ├── 27-D.cpp │ ├── 27-E.cpp │ ├── 28-A.cpp │ ├── 28-B.cpp │ ├── 28-C.cpp │ ├── 28-D.cpp │ ├── 44-A.cpp │ ├── 44-B.cpp │ ├── 44-C.cpp │ ├── 44-D.cpp │ └── 44-E.cpp ├── contests ├── Advent-of-Code-2022 │ ├── 01.cpp │ ├── 02.cpp │ ├── 03.cpp │ ├── 04.cpp │ ├── 05.cpp │ ├── 06.cpp │ ├── 07.cpp │ ├── 08.cpp │ ├── 09.cpp │ ├── 10.cpp │ ├── 11.cpp │ ├── 12.cpp │ ├── 13.cpp │ ├── 14.cpp │ ├── 15.cpp │ ├── 16.cpp │ ├── 17.cpp │ ├── 18.cpp │ ├── 19.cpp │ ├── 20.cpp │ ├── 21.cpp │ ├── 22.cpp │ ├── 23.cpp │ ├── 24.cpp │ └── 25.cpp ├── Advent-of-Code-2024 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I.cpp │ ├── J.cpp │ ├── K.cpp │ ├── L.cpp │ ├── day13.cpp │ ├── day14.cpp │ ├── day15.cpp │ ├── day16.cpp │ ├── day17.cpp │ ├── day18.cpp │ ├── day19.cpp │ ├── day20.cpp │ ├── day21.cpp │ ├── day22.cpp │ ├── day23.cpp │ ├── day24.cpp │ └── day25.cpp ├── BSUIR-2023-Semifinals │ ├── B.cpp │ ├── B.py │ ├── C.cpp │ ├── D_Denis_dp_OK.cpp │ ├── D_dmkozyrev_dp_OK.cpp │ ├── D_dmkozyrev_segmenttree_TLE.cpp │ ├── E.py │ ├── F.cpp │ ├── H_dp_OK_750ms.cpp │ ├── I.cpp │ └── J.cpp ├── Foncode-2024 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── MRC-Qual-2023 │ ├── A.py │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I.cpp │ └── J.cpp ├── MRC-Qual-2024 │ ├── A.py │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I.cpp │ ├── K.cpp │ └── analysis-v05.pdf ├── MTC-TTC-Final-2024 │ ├── d.cpp │ └── e.cpp ├── Moscow Regional Contest 2021 │ ├── a.cpp │ ├── d.cpp │ ├── e.cpp │ ├── f.cpp │ ├── g.cpp │ ├── h.cpp │ ├── j.cpp │ ├── m.cpp │ └── n.cpp ├── NERC-2020-21 │ ├── D-integers.cpp │ ├── D-log2.cpp │ ├── G.cpp │ └── K.cpp ├── NWERC-2023 │ ├── A.cpp │ ├── D.cpp │ ├── F.cpp │ ├── H.cpp │ ├── J.cpp │ ├── K.cpp │ └── L.cpp ├── RuCode-2024-Final-CD │ ├── A.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I.cpp │ ├── J.cpp │ ├── K.cpp │ └── L.cpp ├── RuCode-2024-Final-EF │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I.cpp │ ├── J.cpp │ ├── K.cpp │ ├── L.cpp │ └── M.cpp ├── RuCode-6.0-Final-CD │ ├── A.cpp │ ├── B.cpp │ ├── C.py │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I.cpp │ ├── J.py │ ├── L.cpp │ └── M.cpp ├── RuCode-6.0-Qual │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I - bitsets.cpp │ ├── J.cpp │ └── K.cpp ├── RuCode-7.0-Final-CD │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I.cpp │ ├── K.cpp │ ├── M1.cpp │ ├── M2.cpp │ ├── N-fenwick-gp.cpp │ ├── N-fenwick.cpp │ ├── N-ordered-set.cpp │ └── RuCode-7.0-CD.pdf ├── RuCode-7.0-Final-EF │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H.cpp │ ├── I.cpp │ ├── K.cpp │ ├── L.cpp │ ├── M1.cpp │ ├── M2.cpp │ ├── N.cpp │ └── RuCode-7.0-EF.pdf ├── RuCode-7.0-Qual │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── H-linear-solution.cpp │ ├── H.cpp │ ├── I.cpp │ ├── J.cpp │ ├── K.cpp │ └── L.cpp ├── Ural-Qual-2022 │ ├── H.cpp │ ├── J - dynamic programming.cpp │ └── J_binary_search.cpp ├── WPS2009 │ └── Day 1 │ │ ├── A. chieftain.cpp │ │ ├── B. poker.cpp │ │ ├── C. inn.cpp │ │ ├── D. redist.cpp │ │ ├── E. graveyard.cpp │ │ └── F. foodprod.cpp └── Yandex-Cup-2023-Qual │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── E.cpp ├── documents ├── 2016-11-03 - бинарный поиск, немного про битовые операции.pdf ├── 2016-11-14 - более продвинутые применения бфса и дфса + LCA.pdf ├── 2016-11-28 - sqrt-декомпозиция в задачах на запросы к массиву.pdf ├── 2016-12-01 - sparse table, fenwick tree.pdf ├── 2016-12-12 - примеры задач на динамическое программирование.pdf ├── WPS2008.pdf ├── WPS2009.pdf ├── WPS2010.pdf ├── WPS2011.pdf ├── WPS2012.pdf ├── WPS2013.pdf ├── WPS2014.pdf ├── wps-content.html └── Конспект лекции по динамике.pdf ├── e-olymp.com ├── 0317.cpp ├── 4146.cpp ├── 4147.cpp ├── 4498.cpp ├── 4500.cpp ├── 4774.cpp ├── 5741.cpp ├── 6479 - Blizzard.cpp ├── 7261 - difficult path.cpp ├── 7262 - a coincidence.cpp ├── 7263 - a full set.cpp ├── 7264 - a fish lunch.cpp ├── 7265 - the secret code.cpp ├── 7266 - Dura Lex.cpp ├── 7267 - A path to knowledge.cpp ├── 7268 - A granite of science.cpp ├── 7269 - Probable diagnosis.cpp ├── 7270 - Zoological experiment.cpp └── 7271 - A game.cpp ├── mirea ├── awards-2023-24 │ ├── 2024-ICPC Moscow Qualification-PLACE.pdf │ ├── 2024-ICPC-Qual-2-Barinov-Chikunov-Eroshev.pdf │ ├── 2024-ICPC-Qual-2-Isakov-Kiriakov-Kobetz.pdf │ └── 2024-ICPC-Qual-3-Bekaldiev-Ivanitskii-Semenov.pdf ├── contests │ ├── 2021-07-11 MIREA Goodbye Стипендия 2021 │ │ └── dmkozyrev │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ ├── F.cpp │ │ │ ├── G.cpp │ │ │ ├── H.cpp │ │ │ └── J.cpp │ ├── 2021-09-26 MIREA Welcome Contest 2021 │ │ ├── NoPoint C++ │ │ │ ├── Задача A.cpp │ │ │ ├── Задача B.cpp │ │ │ ├── Задача C.cpp │ │ │ ├── Задача D.cpp │ │ │ ├── Задача E O(n^2).cpp │ │ │ ├── Задача F.cpp │ │ │ ├── Задача G.cpp │ │ │ ├── Задача H O(1).cpp │ │ │ └── Задача I Преподсчёт.cpp │ │ ├── NoPoint Python │ │ │ ├── Задача A.py │ │ │ ├── Задача B.py │ │ │ ├── Задача C.py │ │ │ ├── Задача D.py │ │ │ ├── Задача E O(n^2).py │ │ │ ├── Задача F.py │ │ │ ├── Задача G.py │ │ │ ├── Задача H O(1).py │ │ │ └── Задача I Преподсчёт.py │ │ └── dmkozyrev C++ │ │ │ ├── Задача A.cpp │ │ │ ├── Задача B через геометрическую прогрессию.cpp │ │ │ ├── Задача C.cpp │ │ │ ├── Задача D.cpp │ │ │ ├── Задача E - через бинпоиск.cpp │ │ │ ├── Задача F.cpp │ │ │ ├── Задача G.cpp │ │ │ ├── Задача H - Через бинарный поиск.cpp │ │ │ ├── Задача H - Через пересечение прямых.cpp │ │ │ └── Задача I.cpp │ ├── 2023-01-01 MIREA Happy New Year 2022-23 │ │ ├── A.cpp │ │ ├── B_linear.cpp │ │ ├── B_multiset.cpp │ │ ├── C.cpp │ │ ├── D_dynamic_programming.cpp │ │ ├── D_smart_win_condition.cpp │ │ ├── E.cpp │ │ ├── E_Eduard.cpp │ │ ├── E_python_formula.py │ │ ├── F.cpp │ │ ├── G.cpp │ │ ├── G_Anatoly.ig.cpp │ │ ├── H_dynamic.cpp │ │ └── H_formula.py │ ├── 2023-05-14 MIREA Goodbye Стипендия 2023 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ └── G.cpp │ ├── 2023-09-24-MIREA-Welcome-Contest-2023 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ ├── G.cpp │ │ ├── G2.cpp │ │ ├── H.cpp │ │ ├── I.cpp │ │ ├── J.cpp │ │ └── K.cpp │ ├── 2024-06-23-MIREA-Code-June-2024 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── FI.cpp │ │ ├── G.cpp │ │ └── H.cpp │ └── 2024-09-22-MIREA-Welcome-Contest-2024 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ └── J.cpp ├── cources │ ├── beginner │ │ ├── 2023 │ │ │ ├── 2d-arrays-level-2 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ ├── E.cpp │ │ │ │ └── F.cpp │ │ │ ├── binary-search-by-an-answer-level-4 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d.cpp │ │ │ │ └── e.cpp │ │ │ ├── combinatorics-level-2 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ ├── E.cpp │ │ │ │ └── E_Anatoly.cpp │ │ │ ├── constructive-and-operations-level-3 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ └── E.cpp │ │ │ ├── divisors-level-2 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ └── E.cpp │ │ │ ├── formulas-level-1 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D_binary_search.cpp │ │ │ │ ├── D_cycle_while.cpp │ │ │ │ ├── D_square_equation.cpp │ │ │ │ └── E.cpp │ │ │ ├── geometry-level-2 │ │ │ │ ├── A.cpp │ │ │ │ ├── B - Picture.png │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D - atan2.cpp │ │ │ │ ├── D - complex.cpp │ │ │ │ ├── D - cross.cpp │ │ │ │ ├── E.cpp │ │ │ │ ├── F.cpp │ │ │ │ ├── G - Picture.png │ │ │ │ └── G.cpp │ │ │ ├── implementation-level-1 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ └── E.cpp │ │ │ ├── implementation-of-some-operations │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ └── E.cpp │ │ │ ├── linear-algorithms-level-1 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ ├── E_bitset.cpp │ │ │ │ └── E_linear.cpp │ │ │ ├── modular-math-level-2 │ │ │ │ ├── A-with-classes.cpp │ │ │ │ ├── A.py │ │ │ │ ├── B-with-classes.cpp │ │ │ │ ├── B.py │ │ │ │ ├── C-with-classes.cpp │ │ │ │ ├── C.py │ │ │ │ ├── D-with-classes.cpp │ │ │ │ ├── D.py │ │ │ │ ├── E-with-classes.cpp │ │ │ │ ├── E.py │ │ │ │ ├── F-with-classes.cpp │ │ │ │ ├── F.py │ │ │ │ ├── G-with-classes.cpp │ │ │ │ ├── G.cpp │ │ │ │ ├── H-with-classes.cpp │ │ │ │ └── H.cpp │ │ │ ├── rofl-level-2 │ │ │ │ ├── A.cpp │ │ │ │ ├── B - random.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ ├── E.cpp │ │ │ │ └── F.cpp │ │ │ ├── sortings-and-grouping-level-2 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ ├── E.cpp │ │ │ │ ├── F.cpp │ │ │ │ └── G.cpp │ │ │ ├── steps-on-a-plane-level-1 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D-ChatGPT.cpp │ │ │ │ ├── D.cpp │ │ │ │ └── E.cpp │ │ │ ├── strings-level-1 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ └── E.cpp │ │ │ └── time-and-segments-level-1 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ ├── E.cpp │ │ │ │ ├── F.cpp │ │ │ │ └── G.cpp │ │ ├── 2024 │ │ │ ├── 2024-02-25 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ ├── E.cpp │ │ │ │ └── F.cpp │ │ │ ├── 2024-03-03 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d.cpp │ │ │ │ ├── e.cpp │ │ │ │ └── f.cpp │ │ │ ├── 2024-03-17 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d.cpp │ │ │ │ └── e.cpp │ │ │ ├── 2024-03-24 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d.cpp │ │ │ │ ├── e.cpp │ │ │ │ └── f.cpp │ │ │ └── 2024-03-31 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d.cpp │ │ │ │ └── e.cpp │ │ ├── 2021-08-22 Применение Дерева Отрезков - 1 │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ └── E.cpp │ │ ├── 2023-2024 │ │ │ ├── 479446 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ ├── E.cpp │ │ │ │ ├── F.cpp │ │ │ │ └── G.cpp │ │ │ ├── 483592 │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ └── E.cpp │ │ │ └── constructives │ │ │ │ ├── A.cpp │ │ │ │ ├── B.cpp │ │ │ │ ├── C.cpp │ │ │ │ ├── D.cpp │ │ │ │ ├── E.cpp │ │ │ │ ├── F.cpp │ │ │ │ ├── G.cpp │ │ │ │ ├── H.cpp │ │ │ │ └── Условия-задач.pdf │ │ ├── binary-search │ │ │ ├── A.cpp │ │ │ ├── B-own-binary-search.cpp │ │ │ ├── B-upper-bound.cpp │ │ │ ├── C-upper_bound.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E-1.cpp │ │ │ ├── E-2.cpp │ │ │ ├── F.cpp │ │ │ ├── G.cpp │ │ │ └── H.cpp │ │ ├── bitset-lecture │ │ │ ├── example-1.cpp │ │ │ ├── example-10.cpp │ │ │ ├── example-11.cpp │ │ │ ├── example-12.cpp │ │ │ ├── example-2.cpp │ │ │ ├── example-3.cpp │ │ │ ├── example-4.cpp │ │ │ ├── example-5.cpp │ │ │ ├── example-6.cpp │ │ │ ├── example-7.cpp │ │ │ ├── example-8.cpp │ │ │ └── example-9.cpp │ │ ├── connected-components-1 │ │ │ ├── A-bfs.cpp │ │ │ ├── A-dfs.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ └── F.cpp │ │ ├── connected-components-2 │ │ │ ├── a.cpp │ │ │ ├── b-dsu.cpp │ │ │ ├── b.cpp │ │ │ ├── c.cpp │ │ │ ├── d.cpp │ │ │ ├── e.cpp │ │ │ ├── f.cpp │ │ │ └── g.cpp │ │ ├── connected-components-3 │ │ │ ├── a.cpp │ │ │ ├── a.py │ │ │ ├── b.cpp │ │ │ ├── b.py │ │ │ ├── c-binpow.cpp │ │ │ ├── c.cpp │ │ │ ├── c.py │ │ │ ├── d.cpp │ │ │ ├── d.py │ │ │ ├── e.cpp │ │ │ ├── e.py │ │ │ ├── f.cpp │ │ │ └── f.py │ │ ├── contest-401412 │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ ├── F.cpp │ │ │ ├── G.cpp │ │ │ ├── H.cpp │ │ │ ├── I.cpp │ │ │ └── J.cpp │ │ ├── contest-473112 │ │ │ ├── A-difference-array.cpp │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D-linear-solution.cpp │ │ │ ├── D.cpp │ │ │ ├── E-difference-array.cpp │ │ │ ├── E.cpp │ │ │ ├── F.cpp │ │ │ ├── G.cpp │ │ │ ├── H.cpp │ │ │ └── I.cpp │ │ ├── gready-constructive-easy-403329 │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ ├── F.cpp │ │ │ ├── G binsearch.cpp │ │ │ ├── G map search.cpp │ │ │ ├── H.cpp │ │ │ ├── I.cpp │ │ │ └── J.cpp │ │ └── set-map-lower_bound-403337 │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── C_xor.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ ├── F.cpp │ │ │ ├── G.cpp │ │ │ ├── H.cpp │ │ │ └── I.cpp │ ├── middle │ │ ├── 2021-10-03 BFS, 0-1-BFS, Дейкстра │ │ │ ├── A - Игорь в музее.cpp │ │ │ ├── B - Лабиринт.cpp │ │ │ ├── C - Безопасный путь.cpp │ │ │ ├── D - Рождественские деревья.cpp │ │ │ ├── E - Игорь и путь на работу.cpp │ │ │ ├── F - Лабиринт.cpp │ │ │ ├── G - Алгоритм Дейкстры.cpp │ │ │ ├── H - Лунный новый год и прогулка.cpp │ │ │ └── I - Оля и энергетики.cpp │ │ ├── DSU и small-to-large │ │ │ ├── A1.cpp │ │ │ ├── A2.cpp │ │ │ ├── A3.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ ├── F.cpp │ │ │ ├── G.cpp │ │ │ ├── H.cpp │ │ │ ├── I.cpp │ │ │ └── J.cpp │ │ ├── EDU │ │ │ └── DSU │ │ │ │ ├── practice-1 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d.cpp │ │ │ │ └── e.cpp │ │ │ │ ├── practice-2 │ │ │ │ ├── D-black-magic.cpp │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d.cpp │ │ │ │ ├── e.cpp │ │ │ │ ├── f.cpp │ │ │ │ ├── g.cpp │ │ │ │ ├── h.cpp │ │ │ │ ├── i.cpp │ │ │ │ └── j.cpp │ │ │ │ └── practice-3 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ └── c.cpp │ │ ├── LCA │ │ │ ├── A.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E_2182_ms.cpp │ │ │ └── E_3960_ms.cpp │ │ ├── acmp-dp │ │ │ ├── dp-1 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d-1.cpp │ │ │ │ ├── d-2.cpp │ │ │ │ ├── e.cpp │ │ │ │ └── f.py │ │ │ ├── dp-2 │ │ │ │ ├── a.cpp │ │ │ │ ├── b-1.cpp │ │ │ │ ├── b-2.cpp │ │ │ │ ├── c-2.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d-2.cpp │ │ │ │ ├── d.cpp │ │ │ │ └── e.cpp │ │ │ ├── dp-3 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ └── d.cpp │ │ │ ├── dp-4 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c-linear.cpp │ │ │ │ ├── c-matrix.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d-bitset.cpp │ │ │ │ └── d.cpp │ │ │ ├── dp-5 │ │ │ │ ├── a-matrix.cpp │ │ │ │ ├── a-optimized.cpp │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d-2.cpp │ │ │ │ └── d.cpp │ │ │ ├── dp-6 │ │ │ │ ├── a-2017.cpp │ │ │ │ ├── a.cpp │ │ │ │ ├── a.py │ │ │ │ ├── c-formula.cpp │ │ │ │ └── c.cpp │ │ │ └── dp-final-1 │ │ │ │ ├── a.cpp │ │ │ │ ├── b.cpp │ │ │ │ ├── c.cpp │ │ │ │ ├── d.cpp │ │ │ │ └── e.cpp │ │ ├── attack-on-graphs │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ ├── F.cpp │ │ │ ├── G.cpp │ │ │ └── H.cpp │ │ ├── bit-xor │ │ │ ├── 1006F.cpp │ │ │ ├── 1285D.cpp │ │ │ ├── 1416C.cpp │ │ │ ├── 282E.cpp │ │ │ ├── 431D.cpp │ │ │ ├── 484A-bitset.cpp │ │ │ ├── 484A-long-long.cpp │ │ │ ├── abc201_e.cpp │ │ │ └── arun-sir-and-his-girlfriend.cpp │ │ ├── blitz-1 │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ └── D.cpp │ │ ├── blitz-2 │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D-Ed-half-invariant.cpp │ │ │ └── D.cpp │ │ ├── blitz-3 │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ ├── a.cpp │ │ │ ├── b-1.cpp │ │ │ └── b-2.cpp │ │ ├── combinatorics │ │ │ ├── level 1 - 402280 │ │ │ │ ├── A.cpp │ │ │ │ ├── E1.cpp │ │ │ │ ├── E2.cpp │ │ │ │ ├── H.cpp │ │ │ │ ├── I.cpp │ │ │ │ └── J.cpp │ │ │ └── level 2 - 402801 │ │ │ │ ├── F.cpp │ │ │ │ ├── G.cpp │ │ │ │ └── H.cpp │ │ ├── greedy-1 │ │ │ ├── a.cpp │ │ │ ├── b.cpp │ │ │ ├── c.cpp │ │ │ ├── d.cpp │ │ │ ├── e.cpp │ │ │ ├── f.cpp │ │ │ ├── g.cpp │ │ │ └── h.cpp │ │ ├── multi-threading │ │ │ ├── factorization.cpp │ │ │ ├── helloworld.cpp │ │ │ ├── test-1-B.cpp │ │ │ ├── test-1-C.cpp │ │ │ ├── test-1-D.cpp │ │ │ ├── test-1.cpp │ │ │ ├── test-2.cpp │ │ │ ├── test-4.cpp │ │ │ ├── test-5.cpp │ │ │ └── test.cpp │ │ ├── number-theory │ │ │ └── H.cpp │ │ └── СПбГУ Динамика │ │ │ ├── a.cpp │ │ │ ├── b.cpp │ │ │ ├── c.cpp │ │ │ ├── d.cpp │ │ │ ├── e.cpp │ │ │ ├── f.cpp │ │ │ ├── g.cpp │ │ │ ├── h.cpp │ │ │ ├── i.cpp │ │ │ ├── j.cpp │ │ │ └── k.cpp │ └── mirea-training-contest-01 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D-bfs.cpp │ │ ├── D-math.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ ├── G.cpp │ │ └── H.cpp └── gifts │ ├── Readme.md │ ├── geometry │ ├── example.png │ ├── geoma-jacket-front.png │ ├── jacket-back(2).png │ ├── jacket-back.psd │ ├── jacket-front.psd │ ├── kisspng-sacred-geometry-cube-geometric-shape-penrose-trian-5ce14568023222.353217011558267240009.png │ └── png-clipart-geometry-triangle-animal-tiger-polygon-triangle-angle-leaf.png │ ├── just-mirea │ └── example.png │ ├── mirea-competitive-programming │ ├── example.png │ └── want-problems(4).psd │ ├── mirea-industries │ ├── 201-2019912_stark-industries-logo-png.png │ ├── arc-reactor(1).psd │ ├── back-2(1).png │ ├── front(1).png │ ├── mirea-t-shirt(1).psd │ └── photo1699995862.jpeg │ ├── mirea-logo │ ├── example.png │ ├── mirea-black-tiny.png │ ├── mirea-black.png │ ├── mirea-white-big.png │ └── want-problems(3).psd │ ├── summary.png │ ├── undefined-behavior │ ├── code.png │ ├── example-1.png │ ├── example-2.png │ ├── hearth.png │ ├── undef.png │ └── want-problems(5).psd │ └── want-problems │ ├── codeforces_logo.0113e4ab.png │ ├── example-black.png │ ├── example-blue.png │ ├── example.png │ ├── want-problems(1).png │ ├── want-problems(1).psd │ └── want-problems(2).psd ├── other ├── LCP.cpp └── implicit_prefix_tree.cpp ├── sortme └── 1032.cpp ├── spoj ├── ADAPHOTO.cpp ├── NOVICE55.cpp └── TPGA.cpp └── timus ├── 1022.cpp ├── 1025.cpp ├── 1028.cpp ├── 1056a.cpp ├── 1056b.cpp ├── 1090.cpp ├── 1109.cpp ├── 1133.cpp ├── 1184.cpp ├── 1316.cpp ├── 1329.cpp ├── 1389.cpp ├── 1439.cpp ├── 1470.cpp ├── 1471.cpp ├── 1517.cpp ├── 1521.cpp ├── 1872a.cpp ├── 1872b.cpp ├── 1930.cpp ├── 1934.cpp ├── 2109-a.cpp └── 2109-b.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | *.stackdump 30 | 31 | # Simple text 32 | *.txt 33 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Copyright (C) 2018 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | olymp 2 | -------------------------------------------------------------------------------- /acmp.ru/0007.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | std::string a, b, c; 7 | std::cin >> a >> b >> c; 8 | std::cout << std::max({a, b, c}, [](auto l, auto r) { 9 | return l.size() != r.size() ? l.size() < r.size() : l < r; 10 | }) << std::endl; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /acmp.ru/0011.py: -------------------------------------------------------------------------------- 1 | k, n = (int(x) for x in input().split()) 2 | a = [0]*(n+1); a[0] = 1 3 | for i in range(0, n): 4 | limit = min(n-i, k) 5 | for j in range(1, limit+1): 6 | a[i+j] += a[i] 7 | print(a[n]) -------------------------------------------------------------------------------- /acmp.ru/0026.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool solve(int x1, int y1, int r1, int x2, int y2, int r2) { 4 | int dist2 = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2); 5 | if (dist2 > (r1+r2)*(r1+r2)) { 6 | return false; 7 | } 8 | if (dist2 < (r1-r2)*(r1-r2)) { 9 | return false; 10 | } 11 | return true; 12 | } 13 | 14 | int main() { 15 | int x1, y1, r1, x2, y2, r2; 16 | std::cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2; 17 | if (r1 < r2) { 18 | std::swap(r1, r2); 19 | std::swap(x1, x2); 20 | std::swap(y1, y2); 21 | } 22 | std::cout << (solve(x1, y1, r1, x2, y2, r2) ? "YES" : "NO") << std::endl; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /acmp.ru/0040.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | int n; 7 | std::cin >> n; 8 | std::cout << std::fixed << std::setprecision(0) 9 | << std::pow(2., n) << std::endl; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /acmp.ru/0071.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void rec(int pos, const std::vector& v, int sum, int& answ) { 7 | if (pos == (int)v.size()) { 8 | answ = std::min(answ, std::abs(sum)); 9 | return; 10 | } 11 | assert(pos < (int)v.size()); 12 | rec(pos+1, v, sum+v[pos], answ); 13 | rec(pos+1, v, sum-v[pos], answ); 14 | } 15 | 16 | int main() { 17 | int n; scanf("%d", &n); 18 | std::vector arr(n); 19 | for (auto& it : arr) { 20 | scanf("%d", &it); 21 | } 22 | int answ = 1e9; 23 | printf("%d", (rec(1, arr, arr[0], answ), answ)); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /acmp.ru/0072.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC diagnostic ignored "-Wunused-result" 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | std::string s; 8 | std::cin >> s; 9 | std::next_permutation(s.begin(), s.end()); 10 | std::cout << s << std::endl; 11 | return 0; 12 | } -------------------------------------------------------------------------------- /acmp.ru/0091.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC diagnostic ignored "-Wunused-result" 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | int n; scanf("%d", &n); --n; 8 | std::vector a{2, 3, 4, 7, 13, 15}, b{1, 5, 6, 8, 9, 10}; 9 | a.reserve(n+1); b.reserve(n+1); 10 | int top = 4; 11 | for (int i = (int)a.size()-1; i <= n; ++i) { 12 | a.push_back(b[i] + b[i-2]); 13 | b.push_back(b[i]+1); 14 | while (b.back() == a[top]) { 15 | b.back()++; 16 | top++; 17 | } 18 | } 19 | printf("%d\n%d\n", a[n], b[n]); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /acmp.ru/0114.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC diagnostic ignored "-Wunused-result" 2 | #include 3 | #include 4 | 5 | typedef long long ll; 6 | 7 | int main() { 8 | ll n, k; std::cin >> n >> k; assert(n > 1); 9 | 10 | std::vector count(1+n, 0); 11 | count[1] = (k-1); 12 | count[2] = (k-1) * k; 13 | for (int i = 3; i <= n; ++i) { 14 | count[i] = (k-1) * (count[i-1] + count[i-2]); 15 | } 16 | std::cout << count[n] << std::endl; 17 | return 0; 18 | } -------------------------------------------------------------------------------- /acmp.ru/0123.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | std::string s; std::cin >> s; 6 | static int count[81][81]; // [len][balance] 7 | count[0][0] = 1; 8 | for (int n = 0; n < (int)s.size(); ++n) { 9 | for (int b = 0; b <= (int)s.size(); ++b) { 10 | if (s[n] == '?' || s[n] == '(') count[n+1][b+1] += count[n][b]; 11 | if ((s[n] == '?' || s[n] == ')') && b > 0) count[n+1][b-1] += count[n][b]; 12 | } 13 | } 14 | std::cout << count[s.size()][0]; 15 | return 0; 16 | } -------------------------------------------------------------------------------- /acmp.ru/0179.py: -------------------------------------------------------------------------------- 1 | last = int(input()) 2 | sum = [0 for _ in range(0, last+1)] 3 | for i in range(1, last+1): 4 | sum[i] = 3 * sum[i-1] + 2; 5 | print(sum[last]+2); -------------------------------------------------------------------------------- /acmp.ru/0192.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC diagnostic ignored "-Wunused-result" 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | int n; scanf("%d", &n); 8 | 9 | std::vector a(n); 10 | for (auto& it : a) scanf("%d", &it); 11 | 12 | if (!std::next_permutation(a.begin(), a.end())) { 13 | std::reverse(a.begin(), a.end()); 14 | } 15 | 16 | for (auto& it : a) { 17 | printf("%d ", it); 18 | } 19 | printf("\n"); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /acmp.ru/0275.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | int n; 7 | scanf("%d", &n); 8 | while (n--) { 9 | char buf[1000+1]; 10 | scanf("%1000s", buf); 11 | std::string s(buf); 12 | std::reverse(s.begin(), s.end()); 13 | int mod = 0; 14 | int pow = 1; 15 | for (auto& it : s) { 16 | (mod += pow * (it - '0')) %= 7; 17 | (pow *= 2) %= 7; 18 | } 19 | printf(mod ? "No\n" : "Yes\n"); 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /acmp.ru/0350.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC diagnostic ignored "-Wunused-result" 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | std::string s; std::cin >> s; std::sort(s.begin(), s.end()); 8 | do { 9 | printf("%s\n", s.c_str()); 10 | } while (std::next_permutation(s.begin(), s.end())); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /acmp.ru/0506.py: -------------------------------------------------------------------------------- 1 | n, k1, k2, s = (int(x) for x in input().split()) 2 | count = [[0 for _ in range(n+1)] for _ in range(n+1)] 3 | count[k1][k2] = 2**100 4 | for i1 in range(k1, n): 5 | for i2 in range(k2, n): 6 | count[i1+1][i2] += count[i1][i2] // 2 7 | count[i1][i2+1] += count[i1][i2] // 2 8 | 9 | s1 = 0; s2 = 0; 10 | for i in range(n+1): s1 += count[i][n]; 11 | for i in range(n+1): s2 += count[n][i]; 12 | assert(s1+s2 == 2**100) 13 | s1 = s * s1 // 2**100 14 | s2 = s * s2 // 2**100 15 | print(s2, s1, end = ' ') 16 | -------------------------------------------------------------------------------- /acmp.ru/0508.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | "Клеверный лист": математическое моделирование 3 | */ 4 | 5 | #include 6 | 7 | typedef long long ll; 8 | 9 | int main() { 10 | ll n, all = 0; 11 | std::cin >> n; 12 | while (n--) { 13 | char t; ll in_l, in_r, out_l, out_r; 14 | std::cin >> t >> out_l >> out_r >> in_l >> in_r; 15 | all -= out_l + out_r; 16 | ll answ = out_l + in_l + all; 17 | all += in_l + in_r; 18 | std::cout << (t == 'L' ? -1 : answ) << ' '; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /acmp.ru/0544.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | arr = [0 for x in range(0, n+1)] 3 | arr[0] = 1 4 | arr[1] = 1 5 | if (n >= 2): arr[2] = 2 6 | if (n >= 3): arr[3] = 4 7 | for i in range(4, n+1): 8 | arr[i] += arr[i-1] + arr[i-2] + arr[i-3] 9 | print(arr[n]) -------------------------------------------------------------------------------- /acmp.ru/0556.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int n; scanf("%d", &n); 6 | double p = 1, q = 0; 7 | while (n--) { 8 | double cur; 9 | scanf("%lf", &cur); 10 | std::tie(p, q) = std::make_tuple( 11 | p * cur + q * (1-cur), 12 | p * (1-cur) + q * cur 13 | ); 14 | } 15 | printf("%0.6f", p); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /acmp.ru/0631b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int solve(int n) { 7 | // Генерируем числа Фибоначчи: 8 | std::vector fib{1,1,2}; 9 | for (int i = 3; fib.back() < n; ++i) { 10 | fib.push_back(fib[i-1]+fib[i-2]); 11 | } 12 | // Находим номер нужного: 13 | return int(std::lower_bound(fib.begin(), fib.end(), n) - fib.begin()); 14 | } 15 | 16 | int main() { 17 | int n; 18 | scanf("%d", &n); 19 | 20 | if (n == 0 || n == 1) { 21 | printf("0"); 22 | return 0; 23 | } 24 | 25 | printf("%d\n", solve(n)); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /acmp.ru/0649.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | int n, k; 7 | scanf("%d %d", &n, &k); 8 | static char s[1000000+1]; 9 | scanf("%1000000s", s); 10 | static int count[256]; 11 | int left = 0, right = 0; 12 | long long answ = 0; 13 | while (right < n) { 14 | const char cur = s[right]; 15 | count[cur]++; 16 | while (count[cur] > k) { 17 | count[s[left]]--; 18 | ++left; 19 | } 20 | answ += right-left+1; 21 | ++right; 22 | } 23 | std::cout << answ; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /acmp.ru/0681.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Находим ближайший полный квадрат больший n, вырезаем из него лишние квадратики. 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | typedef long long Int; 10 | 11 | int main() { 12 | Int n; 13 | std::cin >> n; 14 | Int side = (Int)std::ceil(std::sqrt(n)); 15 | Int del = side*side-n; 16 | Int answ = side*side*2+2*side; 17 | if (del < side) { 18 | answ -= 2*del; 19 | } 20 | if (del >= side) { 21 | answ -= 2*del+1; 22 | } 23 | std::cout << answ; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /acmp.ru/0688.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x1, y1, x2, y2; 5 | scanf("%d %d %d %d", &x1, &y1, &x2, &y2); 6 | 7 | int n; 8 | scanf("%d", &n); 9 | 10 | for (int i = 1; i <= n; ++i) { 11 | int x, y; 12 | scanf("%d %d", &x, &y); 13 | // assert(4*((x1-x)*(x1-x)+(y1-y)*(y1-y)) != (x2-x)*(x2-x)+(y2-y)*(y2-y)); RE 11 14 | if (4*(1LL*(x1-x)*(x1-x)+1LL*(y1-y)*(y1-y)) <= 1LL*(x2-x)*(x2-x)+1LL*(y2-y)*(y2-y)) { 15 | printf("%d\n", i); 16 | return 0; 17 | } 18 | } 19 | printf("NO\n"); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /acmp.ru/0722.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Задача: 722. Шоколадки 3 | # Решение: динамическое программирование, исследование, длинная арифметика, O(n+m) 4 | # Автор: Дмитрий Козырев, github: dmkz, e-mail: dmkozyrev@rambler.ru 5 | 6 | cnt = [[1] * 2 + [0] * 999 for x in range(2)] #[last][len] -> numbre of sequences 7 | for len in range(2, 1001): 8 | cnt[0][len] = cnt[1][len-1] + cnt[1][len-2]; 9 | cnt[1][len] = cnt[0][len-1] + cnt[0][len-2]; 10 | 11 | r, c = (int(x) for x in input().split()) 12 | res = cnt[0][r] + cnt[1][r] 13 | for i in range(1, min(c,3)): res += 2; 14 | prev = 2; curr = 2; 15 | for i in range(3,c): 16 | next = curr + prev; 17 | prev = curr; 18 | curr = next; 19 | res += curr; 20 | print(res) -------------------------------------------------------------------------------- /acmp.ru/0781.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int solve(int len) { 4 | static int prepared = false; 5 | static int count[2][1+30]; // count[last][len] 6 | if (!prepared) { 7 | prepared = true; 8 | count[0][1] = count[1][1] = 1; 9 | count[0][2] = count[1][2] = 2; 10 | count[0][3] = count[1][3] = 3; 11 | for (int len = 4; len <= 30; ++len) { 12 | for (int last = 0; last < 2; ++last) { 13 | count[last][len] = count[0][len-1]+count[1][len-1]-count[1-last][len-3]; 14 | } 15 | } 16 | } 17 | return count[0][len] + count[1][len]; 18 | } 19 | 20 | int main() { 21 | int n; 22 | scanf("%d", &n); 23 | printf("%d", solve(n)); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /acmp.ru/0789.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | typedef unsigned long long Int; 7 | 8 | int main() { 9 | std::vector numbers; 10 | for (Int pow2 = 1; pow2 <= 1e18; pow2 *= 2) { 11 | for (Int pow3 = 1; pow2 * pow3 <= 1e18; pow3 *= 3) { 12 | for (Int pow5 = 1; pow2 * pow3 * pow5 <= 1e18; pow5 *= 5) { 13 | numbers.push_back(pow2 * pow3 * pow5); 14 | } 15 | } 16 | } 17 | std::sort(numbers.begin(), numbers.end()); 18 | 19 | int n; std::cin >> n; 20 | assert((int)numbers.size() > n); 21 | std::cout << numbers[n-1]; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /acmp.ru/0828.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Задача: 828. Красивые последовательности 3 | # Решение: длинная арифметика, динамическое программирование, двумерное дп, O(n^2) 4 | # Автор: Дмитрий Козырев, github: dmkz, e-mail: dmkozyrev@rambler.ru 5 | n,k=(int(x) for x in input().split()) 6 | count = [0] * ((n+1) * (k+3)) 7 | count[1*(k+2)+1] = 1; 8 | for len in range(1,n): 9 | for mx in range(1,k+1): 10 | count[(len+1)*(k+2)+mx] += mx * count[len*(k+2)+mx]; 11 | count[(len+1)*(k+2)+mx+1] += count[len*(k+2)+mx]; 12 | res = 0; 13 | for mx in range(1,k+1): 14 | res += count[n*(k+2)+mx] 15 | print(res) -------------------------------------------------------------------------------- /acmp.ru/0873.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Задача: 873. Шифр "Решетка" 3 | 4 | Решение: быстрое возведение в степень, комбинаторика, O(log(n)) 5 | 6 | Автор: Дмитрий Козырев, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | typedef long long ll; 12 | 13 | int pow(int a, ll k, int mod) { 14 | int ret = 1 % mod; 15 | while (k > 0) { 16 | if (k & 1) { 17 | ret = int(1LL * ret * a % mod); 18 | } 19 | k >>= 1; 20 | a = int (1LL * a * a % mod); 21 | } 22 | return ret; 23 | } 24 | 25 | int main() { 26 | int n, m; 27 | std::cin >> n >> m; 28 | std::cout << pow(4 % m, ll(n) * n / 4, m) << std::endl; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /acmp.ru/0883.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | "Самое экстравагантное дупло": геометрия, конструктив, O(n) 3 | 4 | Главный подвох: радиусы даны в метрах, а расстояние определяется в сантиметрах. 5 | 6 | Можно пересечь все окружности. 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int n; 13 | scanf("%d", &n); 14 | for (double x = 0; n > 0 && x < 1; x += 0.01) { 15 | for (double y = 0; n > 0 && y < 1; y += 0.01) { 16 | printf("%.2f %.2f", x, y); 17 | --n; 18 | } 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /acmp.ru/0923.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef long long Int; 5 | 6 | std::map answer; 7 | 8 | Int solve(Int n) { 9 | if (n < 3) { 10 | return 0; 11 | } 12 | if (n == 3) { 13 | return 1; 14 | } 15 | if (answer.find(n) == answer.end()) { 16 | answer[n] = solve((n+1) / 2) + solve(n / 2); 17 | } 18 | return answer[n]; 19 | } 20 | 21 | 22 | int main() { 23 | Int n; 24 | std::cin >> n; 25 | std::cout << solve(n) << std::endl; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /acmp.ru/0944.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | int n; scanf("%d", &n); 7 | std::vector coin(n); 8 | for (auto& it : coin) { 9 | scanf("%d", &it); 10 | } 11 | std::vector possible(1+1000, false); 12 | possible[0] = true; 13 | for (int i = 1; i <= 1000; ++i) { 14 | for (auto c : coin) { 15 | if (i-c >= 0 && possible[i-c]) { 16 | possible[i] = true; 17 | } 18 | } 19 | } 20 | int nQ; 21 | scanf("%d", &nQ); 22 | while (nQ--) { 23 | int sum; scanf("%d", &sum); 24 | printf("%d ", (int)possible[sum]); 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /acmp.ru/0945.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | "Баллы": бинарный поиск в массиве, O(n log(n)) 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | typedef long long ll; 10 | 11 | int main() { 12 | std::ios_base::sync_with_stdio(false); 13 | std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); 14 | 15 | int n, q; 16 | std::cin >> n >> q; 17 | 18 | std::vector a(n); 19 | for (auto& it : a) { 20 | std::cin >> it; 21 | } 22 | 23 | while (q--) { 24 | ll value; 25 | std::cin >> value; 26 | std::cout << (std::binary_search(a.begin(), a.end(), value) ? "YES " : "NO "); 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /acmp.ru/0954.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int height; 6 | std::cin >> height; 7 | std::vector count(height+1, 0); 8 | count[0] = 1; 9 | const int mod = 1000*1000; 10 | for (int i = 1; i <= height; ++i) { 11 | if (i-10 >= 0) { 12 | count[i] += count[i-10]; 13 | } 14 | if (i-11 >= 0) { 15 | count[i] += count[i-11]; 16 | } 17 | if (i-12 >= 0) { 18 | count[i] += count[i-12]; 19 | } 20 | count[i] %= mod; 21 | } 22 | printf("%d\n", 2*count[height] % mod); 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /acmp.ru/0969a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n, mod; 5 | std::cin >> n >> mod; 6 | int answ = 2 % mod; 7 | for (int i = 1; i <= n; ++i) { 8 | answ = answ * answ % mod; 9 | } 10 | std::cout << answ; 11 | return 0; 12 | } -------------------------------------------------------------------------------- /acmp.ru/0974.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Задача: 974. Странный ним 3 | 4 | Решение: теория игр, ним, исследование, O(t) 5 | 6 | Автор: Дмитрий Козырев, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | #include 9 | int main() { 10 | for (int a, b, c; std::cin >> a >> b >> c, a; ) { 11 | printf("%s wins the game.\n", (a+1)^(b+1)^(c+1) ? "Alice" : "Bob"); 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /acmp.ru/1030.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef long double Real; 6 | typedef long long Int; 7 | 8 | int main() { 9 | Real n1, n2, n3, n4; 10 | std::cin >> n1 >> n2 >> n3 >> n4; 11 | Int answ = (Int)std::floor(std::sqrt(std::min(n1, n2) + std::min(n3, n4))); 12 | std::cout << answ << std::endl; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /acmp.ru/1081.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | typedef long long ll; 4 | int main() { 5 | int n; 6 | scanf("%d", &n); 7 | std::vector sum(1+n); 8 | for (int i = 1; i <= n; ++i) { 9 | int value; 10 | scanf("%d", &value); 11 | sum[i] = sum[i-1] + value; 12 | } 13 | int nQueries; 14 | scanf("%d", &nQueries); 15 | while (nQueries--) { 16 | int l, r; 17 | scanf("%d %d", &l, &r); 18 | printf("%I64d\n", sum[r] - sum[l-1]); 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /acmp.ru/1082.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | typedef long long ll; 3 | int main() { 4 | int n, m, q; 5 | scanf("%d %d %d", &n, &m, &q); 6 | static ll sum[1+1000][1+1000]; 7 | for (int i = 1; i <= n; ++i) { 8 | for (int j = 1; j <= m; ++j) { 9 | int value; 10 | scanf("%d", &value); 11 | sum[i][j] = value + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1]; 12 | } 13 | } 14 | while (q--) { 15 | int i1, j1, i2, j2; 16 | scanf("%d %d %d %d", &i1, &j1, &i2, &j2); 17 | printf("%I64d\n", sum[i2][j2]-sum[i1-1][j2]-sum[i2][j1-1]+sum[i1-1][j1-1]); 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /acmp.ru/1130.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | k = 0 3 | while n > 1: 4 | n = n - n // 2 5 | k += 1 6 | print(k) -------------------------------------------------------------------------------- /acmp.ru/1178a.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/acmp.ru/1178a.cpp -------------------------------------------------------------------------------- /acmp.ru/1241.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | bool solve(int x) { 6 | int root = std::sqrt(x); 7 | return root * root == x; 8 | } 9 | 10 | int main() { 11 | int x; scanf("%d", &x); 12 | printf(solve(x) ? "YES" : "NO"); 13 | return 0; 14 | } -------------------------------------------------------------------------------- /acmp.ru/1243.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int a, b, n; 5 | scanf("%d %d %d", &a, &b, &n); 6 | b += 100 * a; 7 | b *= n; 8 | a = b / 100; 9 | b %= 100; 10 | printf("%d %d", a, b); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /acmp.ru/1404.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | std::string s; 6 | std::cin >> s; 7 | for (auto& it : s) { 8 | it = (it - 'a' + 1) % 26 + 'a'; 9 | } 10 | std::cout << s; 11 | return 0; 12 | } -------------------------------------------------------------------------------- /acmp.ru/1415.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int k, a, b; 4 | std::cin >> k >> a >> b; 5 | std::cout << ((a+b) == 0 ? 1 : k+1); 6 | return 0; 7 | } -------------------------------------------------------------------------------- /acmp.ru/1468.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x; std::cin >> x; 5 | auto a = std::to_string(x-1); 6 | auto b = std::to_string(x+1); 7 | std::cout << (a.size() > b.size() ? b : a); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /acmp.ru/1474.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | int a, b, h; 7 | std::cin >> a >> b >> h; 8 | std::cout << std::fixed << std::setprecision(6) 9 | << 2 * b * std::sqrt(h*h+a*a/4.0) << ' '; 10 | std::cout << std::fixed << std::setprecision(6) 11 | << std::sqrt(h*h+a*a/4.0) * b + std::sqrt(h*h+b*b/4.0) * a; 12 | return 0; 13 | } -------------------------------------------------------------------------------- /acmp.ru/1567.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef long long Int; 4 | 5 | int main() { 6 | Int n, a; 7 | std::cin >> n >> a; 8 | while (n > 1) { 9 | if (a % 2 == 1) { 10 | n = (n+1)/2; 11 | a = (a+1)/2; 12 | printf("0 "); 13 | } else { 14 | n /= 2; 15 | a /= 2; 16 | printf("1 "); 17 | } 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /acmp.ru/1568.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int nRes, nUnits; 6 | scanf("%d %d", &nRes, &nUnits); 7 | std::vector res(nRes); 8 | for (auto& it : res) { 9 | scanf("%d", &it); 10 | } 11 | while (nUnits--) { 12 | bool flag = true; 13 | for (int i = 0; i < nRes; ++i) { 14 | int value; scanf("%d", &value); 15 | if (res[i] < value) { 16 | flag = false; 17 | } 18 | } 19 | printf("%c ", flag ? '1' : '0'); 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /algos/Algebra/examples/eolymp-4508-max-xor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | problem: 4508. maximum xor (hard) 3 | solution: xor, basis, linear algebra, maximum xor, O(n log(A)) 4 | */ 5 | #include "template.hpp" 6 | #include "algebra.hpp" 7 | int main() { 8 | using namespace algos::algebra; 9 | int n; std::cin >> n; 10 | XorBasis basis; 11 | for (int i = 0, x; i < n; i++) { 12 | std::cin >> x; 13 | basis += x; 14 | } 15 | std::cout << basis.max() << std::endl; 16 | } 17 | -------------------------------------------------------------------------------- /algos/Data-Structures/examples-SparseTable/0818E.cpp: -------------------------------------------------------------------------------- 1 | // problem: 818E 2 | #include 3 | #include "../SparseTable.hpp" 4 | 5 | int main() { 6 | std::ios::sync_with_stdio(false); 7 | int n, k; std::cin >> n >> k; 8 | std::vector a(n); 9 | for (int i = 0; i < n; i++) { 10 | std::cin >> a[i]; 11 | a[i] %= k; 12 | } 13 | SparseTable st(a, MultByModulo(k)); 14 | int64_t answ{}; 15 | for (int L = 0; L < n; L++) { 16 | int R = st.binary_lifting(L, extendIfNonZero); 17 | answ += n - R; 18 | } 19 | std::cout << answ << std::endl; 20 | } -------------------------------------------------------------------------------- /algos/FindHeaders.ps1: -------------------------------------------------------------------------------- 1 | $FileName = "headers.txt" 2 | if (Test-Path $FileName) { 3 | Remove-Item $FileName; 4 | } 5 | Get-ChildItem -Path .\ -Filter *.hpp -Recurse -File -Name| ForEach-Object { 6 | Write-Output "$_" | Out-File -encoding ASCII -FilePath $FileName -Append; 7 | } -------------------------------------------------------------------------------- /algos/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "template.hpp" 3 | #include "debug.hpp" 4 | #include "sparsetable.hpp" 5 | int main() { 6 | std::vector a = {1,2,3,4}; 7 | SparseTable::SparseTable> st(a); 8 | for (int i = 0; i < isz(a); i++) { 9 | for (int j = i; j < isz(a); j++) { 10 | std::cout << "min[" << i << ", " << j << "] = "; 11 | std::cout << st.calcFunc(i, j) << std::endl; 12 | } 13 | } 14 | std::cout << "a = " << a << std::endl; 15 | } 16 | -------------------------------------------------------------------------------- /algos/timer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TIMER_HPP__ 2 | #define __TIMER_HPP__ 3 | class Timer { 4 | std::chrono::time_point timePoint; 5 | size_t value; 6 | public: 7 | void start() { timePoint = std::chrono::steady_clock::now(); } 8 | void finish() { 9 | auto curr = std::chrono::steady_clock::now(); 10 | auto elapsed = std::chrono::duration_cast(curr - timePoint); 11 | value = elapsed.count(); 12 | } 13 | size_t operator()() const { return value; } 14 | }; 15 | #endif // __TIMER_HPP__ -------------------------------------------------------------------------------- /codeforces-parser/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "building group-contests.cpp..." 3 | g++ -O3 -Wall -Wextra -pedantic group-contests.cpp -o "group-contests" 4 | echo "building contest-status.cpp..." 5 | g++ -O3 -Wall -Wextra -pedantic contest-status.cpp -o "contest-status" 6 | echo "building process-rating.cpp..." 7 | g++ -O3 -Wall -Wextra -pedantic process-rating.cpp -o "process-rating" 8 | echo "user-status.cpp..." 9 | g++ -O3 -Wall -Wextra -pedantic user-status.cpp -o user-status.exe 10 | echo "get-link.cpp..." 11 | g++ -O3 -Wall -Wextra -pedantic get-link.cpp -o "get-link" 12 | echo "search-in-file.cpp..." 13 | g++ -O3 -Wall -Wextra -pedantic search-in-file.cpp -o "search-in-file" -------------------------------------------------------------------------------- /codeforces-parser/get-link.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "cf-common.hpp" 3 | using namespace std; 4 | int main(int argc_, char *argv_[]) { 5 | //for (int i = 0; 6 | auto arguments = getArguments(argc_, argv_); 7 | std::string s; 8 | for (int i = 1; i < isz(arguments); i++) { 9 | s += arguments[i]; 10 | } 11 | while (s.size() && isspace(s.back())) 12 | s.pop_back(); 13 | //cerr << "s='" << s << "'" << std::endl; 14 | cout << s; 15 | return 0; 16 | } -------------------------------------------------------------------------------- /codeforces-parser/search-in-file.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "cf-common.hpp" 3 | using namespace std; 4 | int main(int argc_, char *argv_[]) { 5 | auto argv = getArguments(argc_, argv_); 6 | assert(argc_ == 3); 7 | // argv[1] == what 8 | // argv[2] == where 9 | std::string s = fileToString(argv[2]); 10 | cout << (s.find(argv[1]) != s.npos); 11 | return 0; 12 | } -------------------------------------------------------------------------------- /codeforces.com/1003A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Solution: Greatest frequency element, O(n log(n)) 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | std::ios_base::sync_with_stdio(false); 11 | std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); 12 | 13 | std::map count; 14 | 15 | int n; std::cin >> n; 16 | while (n--) { 17 | int coin; std::cin >> coin; 18 | count[coin]++; 19 | } 20 | 21 | int answ = 0; 22 | for (auto& p: count) { 23 | answ = std::max(answ, p.second); 24 | } 25 | std::cout << answ; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /codeforces.com/1151E.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 1151E. Number of Components 3 | Solution: math, combinatorics, contribution to the sum, O(n) 4 | */ 5 | #include 6 | int main() { 7 | for (int n; std::cin >> n; ) { 8 | int64_t answ = 0; 9 | for (int prev = -1, curr = -1, i = 0; i < n; i++) { 10 | prev = curr; 11 | std::cin >> curr; 12 | answ += (n - curr + 1LL) * (curr - 1 + 1LL); 13 | if (prev == -1) continue; 14 | int min = std::min(prev,curr); 15 | int max = std::max(prev,curr); 16 | answ -= (min - 1 + 1LL) * (n - max + 1LL); 17 | } 18 | std::cout << answ << std::endl; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0053C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 53C. Little Frog 3 | 4 | Solution: deque, constructive, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int n; std::cin >> n; 14 | std::deque order; 15 | for (int i = 1; i <= n; ++i) order.push_back(i); 16 | while (!order.empty()) { 17 | std::cout << order.front() << ' '; 18 | order.pop_front(); 19 | if (!order.empty()) { 20 | std::cout << order.back() << ' '; 21 | order.pop_back(); 22 | } 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0108A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 108A. Palindromic Times 3 | 4 | Solution: strings, palindrome, O(MAX) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | bool is_palindromic(int m) { 14 | char buf[6]; 15 | sprintf(buf, "%02d:%02d", m / 60 % 24, m % 60); 16 | std::string s(buf); auto t = s; 17 | std::reverse(t.begin(), t.end()); 18 | return s == t; 19 | } 20 | 21 | int main() { 22 | int h, m; scanf("%d:%d", &h, &m); 23 | m += h * 60; 24 | while (!is_palindromic(++m)); 25 | printf("%02d:%02d", m / 60 % 24, m % 60); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0114A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 114A. Cifera 3 | 4 | Solution: math, O(log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | typedef long long ll; 12 | 13 | int main() { 14 | ll k, n; std::cin >> k >> n; 15 | ll res = k, p = 0; 16 | while (res < n) { res *= k; ++p; } 17 | if (n == res) { std::cout << "YES\n" << p; } else { std::cout << "NO"; } 18 | return 0; 19 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0122B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 122B. Lucky Substring 3 | 4 | Solution: greedy, strings, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int n4 = 0, n7 = 0; std::string s; std::cin >> s; 14 | for (auto it : s) { 15 | n4 += (it == '4'); 16 | n7 += (it == '7'); 17 | } 18 | if (!n4 && !n7) { std::cout << -1; return 0; } 19 | std::cout << (n4 >= n7 ? "4" : "7"); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0135A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 135A. Replacement 3 | 4 | Solution: constructive, O(n log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n; std::cin >> n; 15 | std::vector arr(n); 16 | for (auto& it : arr) std::cin >> it; 17 | std::sort(arr.begin(), arr.end()); 18 | if (arr.back() == 1) arr.back()++; else arr.back() = 1; 19 | std::sort(arr.begin(), arr.end()); 20 | for (auto& it : arr) { 21 | std::cout << it << ' '; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0137A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 137A. Postcards and photos 3 | 4 | Solution: implementation, O(n^2) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int answ = 0; 14 | std::string s; std::cin >> s; 15 | while (!s.empty()) { 16 | int i; 17 | for (i = 0; i < std::min(5, (int)s.size()); ++i) { 18 | if (s[i] != s[0]) { 19 | break; 20 | } 21 | } 22 | answ++; 23 | s = s.substr(i); 24 | } 25 | std::cout << answ; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0157A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 157A. Game Outcome 3 | 4 | Solution: brute force, O(n^2) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n; std::cin >> n; 15 | std::vector row(n), col(n); 16 | for (int r = 0; r < n; ++r) { 17 | for (int c = 0; c < n; ++c) { 18 | int a; std::cin >> a; 19 | row[r] += a; col[c] += a; 20 | } 21 | } 22 | int answ = 0; 23 | for (int r = 0; r < n; ++r) { 24 | for (int c = 0; c < n; ++c) { 25 | answ += col[c] > row[r]; 26 | } 27 | } 28 | std::cout << answ; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0216A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 216A. Tiling with Hexagons 3 | 4 | Solution: math, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int a, b, c; std::cin >> a >> b >> c; 14 | if (b > c) std::swap(b,c); 15 | int answ = 0; 16 | for (int i = 1; i < b; ++i) { 17 | answ += a++; 18 | } 19 | answ *= 2; 20 | for (int i = b; i <= c; ++i) { 21 | answ += a; 22 | } 23 | std::cout << answ; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0263B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 263B. Squares 3 | 4 | Solution: greedy, sorting, O(n log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n, need; 15 | std::cin >> n >> need; --need; 16 | std::vector a(n); 17 | for (auto& it : a) std::cin >> it; 18 | std::sort(a.begin(), a.end(), std::greater()); 19 | if (need >= n) { std::cout << -1; return 0; } 20 | std::cout << a[need] << ' ' << a[need]; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0265B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 265B. Roadside Trees (Simplified Edition) 3 | 4 | Solution: greedy, math, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int n, prev = 1, answ = 0; std::cin >> n; 14 | while (n--) { 15 | int h; std::cin >> h; 16 | answ += 2 + std::abs(h-prev); 17 | prev = h; 18 | } 19 | std::cout << answ; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0268B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 268B. Buttons 3 | 4 | Solution: implementation, math, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int n; std::cin >> n; 13 | int r = n; 14 | for (int i = 1; i < n; ++i) { 15 | r += i * (n-i); 16 | } 17 | std::cout << r; 18 | return 0; 19 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0274A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 274A. k-Multiple Free Set 3 | 4 | Solution: greedy, implementation, std::set, O(n log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | typedef long long ll; 12 | int main() { 13 | int n, k; 14 | std::cin >> n >> k; 15 | if (k == 1) { 16 | std::cout << n; return 0; 17 | } 18 | std::set set; 19 | for (int i = 0; i < n; ++i) { 20 | int v; std::cin >> v; 21 | set.insert(v); 22 | } 23 | for (auto& it : set) { 24 | set.erase(it * k); 25 | } 26 | std::cout << set.size(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0284B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 284B. Cows and Poker Game 3 | 4 | Solution: implementation, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int n; std::cin >> n; 14 | std::string s; std::cin >> s; 15 | int nI = 0, answ = 0; 16 | for (auto& it : s) { 17 | nI += (it == 'I'); 18 | } 19 | for (auto& it : s) { 20 | answ += (it != 'F') && (nI - (it == 'I') == 0); 21 | } 22 | std::cout << answ; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0289A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 289A. Polo the Penguin and Segments 3 | 4 | Solution: implementation, math, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | typedef long long ll; 13 | int main() { 14 | int n, k; std::cin >> n >> k; 15 | int s = 0; 16 | for (int i = 0; i < n; ++i) { 17 | int l, r; std::cin >> l >> r; 18 | s += (r - l + 1); 19 | } 20 | std::cout << (s + k - 1) / k * k - s; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0302B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 302B. Eugeny and Play List 3 | 4 | Solution: prefix sums, two pointers, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int n, q; 14 | std::cin >> n >> q; 15 | std::vector sum{0}; 16 | for (int i = 0; i < n; ++i) { 17 | int c, t; std::cin >> c >> t; 18 | sum.push_back(sum.back() + c*t); 19 | } 20 | int p = 1; 21 | while (q--) { 22 | int v; std::cin >> v; 23 | while (sum[p] < v) ++p; 24 | std::cout << p << '\n'; 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0317A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 317A. Perfect Pair 3 | 4 | Solution: greedy, math, number theory, O(log(m)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | typedef long long ll; 11 | ll solve(ll x, ll y, ll m) { 12 | if (x < y) return solve(y, x, m); 13 | if (x >= m || y >= m) return 0; 14 | if (x <= 0) return -1; 15 | ll k = std::max(ll(1), (x - y + x - 1) / x); 16 | return solve(x, k*x+y, m)+k; 17 | } 18 | int main() { 19 | ll x, y, m; 20 | std::cin >> x >> y >> m; 21 | std::cout << solve(x,y,m); 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0322A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 322A. Ciel and Dancing 3 | 4 | Solution: constructive, greedy, O(n*m) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int n, m; std::cin >> n >> m; 13 | std::cout << n + m - 1 << '\n'; 14 | for (int i = 1; i <= m; ++i) { 15 | std::cout << 1 << ' ' << i << '\n'; 16 | } 17 | for (int i = 2; i <= n; ++i) { 18 | std::cout << i << ' ' << 1 << '\n'; 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0340A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 340A. The Wall 3 | 4 | Solution: math, gcd, lcm, O(log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | typedef long long ll; 12 | 13 | int gcd(int a, int b) { 14 | return b == 0 ? a : gcd(b, a % b); 15 | } 16 | 17 | ll lcm(int a, int b) { 18 | return ll(a) / gcd(a,b) * b; 19 | } 20 | 21 | int solve(int x, int y, int r) { 22 | return int(r / lcm(x,y)); 23 | } 24 | 25 | int main() { 26 | int x, y, a, b; std::cin >> x >> y >> a >> b; 27 | std::cout << solve(x,y,b)-solve(x,y,a-1); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0343A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 343A. Rational Resistance 3 | 4 | Solution: number theory, math, gcd, O(log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | #include 9 | typedef long long ll; 10 | int main() { 11 | ll a, b; 12 | while (std::cin >> a >> b) { 13 | ll answ = 0; 14 | while (b != 0) { 15 | answ += a / b; 16 | auto rem = a % b; 17 | a = b; 18 | b = rem; 19 | } 20 | std::cout << answ << std::endl; 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0355A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 355A. Vasya and Digital Root 3 | 4 | Solution: constructive, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int k, d; std::cin >> k >> d; 14 | if (d == 0 && k > 1) { 15 | std::cout << "No solution"; return 0; 16 | } 17 | std::string s; s.push_back(char('0' + d)); 18 | while ((int)s.size() < k) s.push_back('0'); 19 | std::cout << s; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0359A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 359A. Table 3 | 4 | Solution: constructive, greedy, O(n*m) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int R, C; std::cin >> R >> C; 13 | for (int r = 1; r <= R; ++r) { 14 | for (int c = 1; c <= C; ++c) { 15 | int v; std::cin >> v; 16 | if (v == 0) continue; 17 | if (c == 1 || c == C || r == R || r == 1) { 18 | std::cout << 2; return 0; 19 | } 20 | } 21 | } 22 | std::cout << 4; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0359B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 359B. Permutation 3 | 4 | Solution: constructive, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n, k; std::cin >> n >> k; 15 | std::vector arr(2*n); 16 | for (int i = 0; i < 2*n; ++i) { 17 | arr[i] = i+1; 18 | } 19 | for (int i = 0; i < k; ++i) { 20 | std::swap(arr[2*i], arr[2*i+1]); 21 | } 22 | for (auto& it : arr) { 23 | std::cout << it << ' '; 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0365A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 365A. Good Number 3 | 4 | Solution: implementation, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n, k; std::cin >> n >> k; 15 | int answ = 0; 16 | while (n--) { 17 | std::string s; std::cin >> s; 18 | std::sort(s.begin(), s.end()); 19 | s.erase(std::unique(s.begin(), s.end()), s.end()); 20 | answ += (int)s.size() >= k && s[k] == char('0' + k); 21 | } 22 | std::cout << answ; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0385B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 385B. Bear and Strings 3 | 4 | Solution: strings, two pointers, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | typedef long long ll; 13 | int main() { 14 | std::string s; std::cin >> s; int n = (int)s.size(); 15 | int l = 0, r = -1; 16 | ll answ = ll(n) * (n+1)/2; 17 | while (l < n) { 18 | while (r+1 < n && (r+1-l+1 < 4 || s.substr(r-2, 4) != "bear")) { 19 | ++r; 20 | } 21 | answ -= r-l+1; 22 | ++l; 23 | } 24 | std::cout << answ; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0389A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 389A. Fox and Number Game 3 | 4 | Solution: constructive, greedy, gcd, O(n^2 log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | int gcd(int a, int b) { 13 | return b == 0 ? a : gcd(b, a % b); 14 | } 15 | int main() { 16 | int n; std::cin >> n; 17 | std::vector x(n); 18 | for (auto& it : x) std::cin >> it; 19 | int gcd = x[0]; 20 | for (int i = 1; i < n; ++i) { 21 | gcd = ::gcd(x[i], gcd); 22 | } 23 | std::cout << gcd * n; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0439A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 439A. Devu, the Singer and Churu, the Joker 3 | 4 | Solution: greedy, implementation, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int main() { 15 | int n,d; std::cin >> n >> d; 16 | std::vector arr(n); 17 | for (auto& it : arr) std::cin >> it; 18 | int s = std::accumulate(arr.begin(), arr.end(), 0); 19 | if (d - s < 0 || (d - s) / 10 < n-1) { 20 | std::cout << -1; return 0; 21 | } 22 | std::cout << (d - s) / 5; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0439B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 439B. Devu, the Dumb Guy 3 | 4 | Solution: sorting, greedy, math, O(n log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | typedef long long ll; 14 | 15 | int main() { 16 | ll n, x; std::cin >> n >> x; 17 | std::vector cnt(n); 18 | for (auto& it : cnt) std::cin >> it; 19 | std::sort(cnt.begin(), cnt.end()); 20 | ll answ = 0; 21 | for (int i = 0; i < n; ++i) { 22 | answ += cnt[i] * std::max(ll(1), (x - i)); 23 | } 24 | std::cout << answ; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0448A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 448A. Rewards 3 | 4 | Solution: implementation, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int a(0), b(0), n; 13 | for (int i = 0; i < 3; ++i) { int v; std::cin >> v; a += v; } 14 | for (int i = 0; i < 3; ++i) { int v; std::cin >> v; b += v; } 15 | std::cin >> n; 16 | for (int k = 0; k <= n; ++k) { 17 | if (a - 5 * k > 0 || b - 10 * (n-k) > 0) { 18 | continue; 19 | } 20 | std::cout << "YES"; return 0; 21 | } 22 | std::cout << "NO"; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0451A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 451A. Game With Sticks 3 | 4 | Solution: implementation, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int n, m; std::cin >> n >> m; if (n > m) n = m; 13 | std::cout << (n % 2 == 1 ? "Akshat" : "Malvika"); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0471C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 471C. MUH and House of Cards 3 | 4 | Solution: number theory, math, O(sqrt(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | typedef long long ll; 12 | 13 | ll solve(ll n) { 14 | int answ = 0; 15 | for (int h = 1; (ll)h * h <= n; ++h) { 16 | ll need = 2 * h + 3LL * h * (h-1) / 2; 17 | if (need <= n && (n - need) % 3 == 0) { 18 | answ++; 19 | } 20 | } 21 | return answ; 22 | } 23 | 24 | int main() { 25 | ll n; while (std::cin >> n) std::cout << solve(n) << std::endl; 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0476C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 476C. Dreamoon and Sums 3 | 4 | Solution: math, number theory, arifmetic progression, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | typedef long long ll; 12 | 13 | const ll mod = (ll)1e9+7; 14 | 15 | int main() { 16 | ll a, b; 17 | while (std::cin >> a >> b) { 18 | ll answ = 0; 19 | for (ll r = 1; r < b; ++r) { 20 | answ = (answ + a * r + (a+1) * a % mod * ((mod+1)/2) % mod * r % mod * b % mod) % mod; 21 | } 22 | std::cout << answ << std::endl; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0486A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 486A. Calculating Function 3 | 4 | Solution: implementation, math, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | typedef long long ll; 13 | int main() { 14 | ll n; std::cin >> n; 15 | if (n % 2 == 0) { 16 | std::cout << n / 2; 17 | } else { 18 | std::cout << n / 2 - n; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0507B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 507B. Amr and Pins 3 | 4 | Solution: geometry, math, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | typedef long double Real; 13 | 14 | int main() { 15 | Real r, x1, y1, x2, y2; 16 | std::cin >> r >> x1 >> y1 >> x2 >> y2; 17 | Real dx = x2-x1, dy = y2-y1; 18 | int k = (int)std::ceil(std::sqrt((dx * dx + dy * dy) / (4 * r * r))); 19 | std::cout << k; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0515A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 515A. Drazil and Date 3 | 4 | Solution: geometry, math, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int x, y, s; std::cin >> x >> y >> s; 13 | if (x < 0) x = -x; 14 | if (y < 0) y = -y; 15 | int diff = s - (x+y); if (diff < 0) diff = -diff; 16 | std::cout << ( s >= (x+y) && diff % 2 == 0 ? "Yes" : "No"); 17 | return 0; 18 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0519C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 519C. Fox and Number Game 3 | 4 | Solution: math, brute force, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n, m; std::cin >> n >> m; 15 | // 1: 2 + 1 16 | // 2: 1 + 2 17 | int answ = 0; 18 | for (int n1 = 0; n1 <= n / 2; ++n1) { 19 | int rem1 = n - n1 * 2; 20 | int rem2 = m - n1; 21 | if (rem2 < 0) continue; 22 | int n2 = std::min(rem1, rem2/2); 23 | answ = std::max(answ,n1+n2); 24 | } 25 | std::cout << answ; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0556A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 556A. Case of the Zeros and Ones 3 | 4 | Solution: greedy, stack, strings, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n; std::string s; 15 | std::cin >> n >> s; 16 | 17 | std::vector stack; 18 | for (auto& it : s) { 19 | if (!stack.empty() && stack.back() != it) { 20 | stack.pop_back(); 21 | } else { 22 | stack.push_back(it); 23 | } 24 | } 25 | std::cout << stack.size(); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599 (extra)/0557B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 557B. Pasha and Tea 3 | 4 | Solution: greedy, math, sorting, O(n log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n, w; 15 | std::cin >> n >> w; 16 | std::vector arr(2*n); 17 | for (auto& it : arr) std::cin >> it; 18 | std::sort(arr.begin(), arr.end()); 19 | double max = std::min({1.0*arr[0], arr[n] / 2.0, w / 3.0 / n}); 20 | printf("%0.6f", 3 * n * max); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0058A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 58A. Chat room 3 | Solution: greedy, strings, O(n) 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | int main() { 10 | std::string t = "hello"; 11 | std::string s; 12 | std::cin >> s; 13 | for (int i = 0, p = 0; i < (int)t.size(); ++i) { 14 | while (p < (int)s.size() && s[p] != t[i]) ++p; 15 | if (p == (int)s.size()) { 16 | std::cout << "NO"; 17 | return 0; 18 | } 19 | ++p; 20 | } 21 | std::cout << "YES"; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0061A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 61A. Ultra-Fast Mathematician 3 | Solution: implementation 4 | */ 5 | #include 6 | #include 7 | 8 | int main() { 9 | std::string a, b; 10 | std::cin >> a >> b; 11 | std::string c = a; 12 | for (int i = 0; i < (int)c.size(); ++i) { 13 | c[i] = (b[i] - '0') ^ (c[i] - '0') + '0'; 14 | } 15 | std::cout << c; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0071A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 71A. Way Too Long Words 3 | Solution: strings 4 | */ 5 | #include 6 | #include 7 | 8 | int main() { 9 | int n; std::cin >> n; 10 | while (n--) { 11 | std::string s; std::cin >> s; 12 | if (s.size() > 10u) { 13 | s = s.front() + std::to_string(s.size()-2u) + s.back(); 14 | } 15 | std::cout << s << '\n'; 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0096A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problems: 96A. Football 3 | Solution: implementation, strings 4 | */ 5 | #include 6 | #include 7 | 8 | int main() { 9 | std::string s; 10 | std::cin >> s; 11 | std::cout << ( 12 | s.find(std::string(7, '0')) != -1 || 13 | s.find(std::string(7, '1')) != -1 ? "YES" : "NO"); 14 | return 0; 15 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0110A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 110A. Nearly Lucky Number 3 | Solution: implementation 4 | */ 5 | #include 6 | #include 7 | 8 | bool is_lucky_number(int n) { 9 | do { 10 | if (n % 10 != 4 && n % 10 != 7) return false; 11 | n /= 10; 12 | } while (n > 0); 13 | return true; 14 | } 15 | 16 | int main() { 17 | std::string s; 18 | std::cin >> s; 19 | int n = 0; 20 | for (auto& it : s) { 21 | n += (it == '4' || it == '7'); 22 | } 23 | std::cout << (is_lucky_number(n) ? "YES" : "NO"); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0112A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 112A. Petya and Strings 3 | Solution: strings, implementation 4 | */ 5 | #include 6 | #include 7 | 8 | int main() { 9 | std::string s, t; 10 | std::cin >> s >> t; 11 | for (auto& it : s) it = 'A' <= it && it <= 'Z' ? it - 'A' + 'a' : it; 12 | for (auto& it : t) it = 'A' <= it && it <= 'Z' ? it - 'A' + 'a' : it; 13 | if (s < t) { 14 | std::cout << -1; 15 | } else if (s > t) { 16 | std::cout << 1; 17 | } else if (s == t) { 18 | std::cout << 0; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0116A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 116A. Tram 3 | Solution: implementation 4 | */ 5 | #include 6 | #include 7 | 8 | int main() { 9 | int n; std::cin >> n; 10 | int max = 0, cur = 0; 11 | while (n--) { 12 | int a, b; std::cin >> a >> b; 13 | cur = cur - a + b; 14 | max = std::max(max, cur); 15 | } 16 | std::cout << max; 17 | return 0; 18 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0136A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 136A. Presents 3 | Solution: implementation 4 | */ 5 | #include 6 | #include 7 | int main() { 8 | int n; 9 | std::cin >> n; 10 | std::vector arr(1+n); 11 | for (int i = 1; i <= n; ++i) { 12 | int p; std::cin >> p; 13 | arr[p] = i; 14 | } 15 | for (int i = 1; i <= n; ++i) { 16 | std::cout << arr[i] << ' '; 17 | } 18 | return 0; 19 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0141A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 141A. Amusing Joke 3 | Solution: implementation, sorting, strings 4 | */ 5 | #include 6 | #include 7 | #include 8 | int main() { 9 | std::vector need(256, 0); 10 | std::string s; std::cin >> s; 11 | for (auto& it : s) need[it]++; 12 | std::cin >> s; 13 | for (auto& it : s) need[it]++; 14 | std::cin >> s; 15 | for (auto& it : s) need[it]--; 16 | for (auto& it : need) { 17 | if (it != 0) { 18 | std::cout << "NO"; 19 | return 0; 20 | } 21 | } 22 | std::cout << "YES"; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0160A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 160A. Twins 3 | Solution: greedy, sorting 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | int n; std::cin >> n; 11 | std::vector a(n); 12 | for (auto& it : a) { 13 | std::cin >> it; 14 | } 15 | std::sort(a.begin(), a.end(), std::greater()); 16 | int sum = 0, part1 = 0; for (auto& it : a) sum += it; 17 | int i; 18 | for (i = 0; i < n; ++i) { 19 | part1 += a[i]; 20 | if (2*part1 > sum) { 21 | break; 22 | } 23 | } 24 | std::cout << i+1; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0189A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 189A. Cut Ribbon 3 | Solution: brute force 4 | */ 5 | #include 6 | #include 7 | 8 | int main() { 9 | int n, a, b, c; 10 | std::cin >> n >> a >> b >> c; 11 | int answ = 0; 12 | for (int na = 0; na <= n / a; ++na) { 13 | for (int nb = 0; nb <= (n - na * a) / b; ++nb) { 14 | int rem = n - na * a - nb * b; 15 | if (rem % c != 0) continue; 16 | int nc = rem / c; 17 | answ = std::max(answ, na+nb+nc); 18 | } 19 | } 20 | std::cout << answ; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0258A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 258A. Little Elephant and Bits 3 | Solution: greedy, math 4 | */ 5 | #include 6 | #include 7 | 8 | int main() { 9 | std::string s; std::cin >> s; 10 | int p = std::max((int)s.find('0'), 0); 11 | std::cout << s.substr(0, p) + s.substr(p+1); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0268C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 268C. Beautiful Sets of Points 3 | Solution: geometry, constructive 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main() { 11 | 12 | int nRows, nCols; 13 | std::cin >> nCols >> nRows; 14 | 15 | int n = std::min(nRows, nCols); 16 | 17 | std::cout << n+1 << '\n'; 18 | for (int x = n; x >= 0; --x) { 19 | std::cout << x << ' ' << n - x << '\n'; 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0270A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 270A. Fancy Fence 3 | Solution: geometry, math, implementation 4 | */ 5 | #include 6 | 7 | int main() { 8 | int n; std::cin >> n; 9 | while (n--) { 10 | int a; std::cin >> a; 11 | std::cout << (360 % (180-a) == 0 ? "YES" : "NO") << '\n'; 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0276D.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 276D. Little Girl and Maximum XOR 3 | Solution: greedy, bitmasks, math 4 | */ 5 | #include 6 | 7 | typedef long long ll; 8 | 9 | int main() { 10 | ll l, r; std::cin >> l >> r; 11 | if (l == r) { 12 | std::cout << 0; 13 | return 0; 14 | } 15 | for (int i = 60; i >= 0; --i) { 16 | if (((l >> i) & 1) != ((r >> i) & 1)) { 17 | std::cout << (ll(1) << (i+1)) - 1; 18 | return 0; 19 | } 20 | } 21 | throw 1; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0285C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 285C. Building Permutation 3 | Solution: sorting, greedy, implementation 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main() { 11 | std::ios_base::sync_with_stdio(false); 12 | std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); 13 | 14 | int n; std::cin >> n; 15 | std::vector a(n); 16 | for (auto& it : a) std::cin >> it; 17 | std::sort(a.begin(), a.end()); 18 | int64_t res = 0; 19 | for (int i = 0; i < n; ++i) res += std::abs(a[i] - i - 1); 20 | std::cout << res; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0322B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 322B. Ciel and Flowers 3 | Solution: combinatorics, math 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | int a, b, c; std::cin >> a >> b >> c; 11 | int res = a / 3 + b / 3 + c / 3; 12 | if (a > 0 && b > 0 && c > 0) { 13 | res = std::max(res, (a-1) / 3 + (b - 1) / 3 + (c - 1) / 3 + 1); 14 | } 15 | if (a > 1 && b > 1 && c > 1) { 16 | res = std::max(res, (a-2) / 3 + (b - 2) / 3 + (c - 2) / 3 + 2); 17 | } 18 | std::cout << res; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0327A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 327A. Flipping Game 3 | Solution: brute force, dynamic programming 4 | */ 5 | #include 6 | #include 7 | int main() { 8 | int n; std::cin >> n; 9 | std::vector arr(1+n), pref(1+n); 10 | for (int i = 1; i <= n; ++i) { 11 | std::cin >> arr[i]; 12 | pref[i] = pref[i-1]+arr[i]; 13 | } 14 | int answ = 0; 15 | for (int i = 1; i <= n; ++i) { 16 | for (int j = i; j <= n; ++j) { 17 | int temp = pref[n] - 2*(pref[j] - pref[i-1]) + (j-i+1); 18 | answ = std::max(answ, temp); 19 | } 20 | } 21 | std::cout << answ; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0337A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 337A. Puzzles 3 | Solution: greedy 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | int main() { 10 | int k, n; 11 | std::cin >> k >> n; 12 | std::vector arr(n); 13 | for (auto& it : arr) std::cin >> it; 14 | std::sort(arr.begin(), arr.end()); 15 | int answ = (int)1e9; 16 | for (int i = 0; i + k - 1 < n; ++i) { 17 | answ = std::min(answ, arr[i+k-1]-arr[i]); 18 | } 19 | std::cout << answ; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0339B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 339B. Xenia and Ringroad 3 | Solution: implementation 4 | */ 5 | #include 6 | #include 7 | 8 | typedef long long ll; 9 | 10 | int main() { 11 | std::ios_base::sync_with_stdio(false); 12 | std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); 13 | 14 | int n, q; 15 | std::cin >> n >> q; 16 | 17 | int curr = 0; ll answ = 0; 18 | while (q--) { 19 | int next; std::cin >> next; --next; 20 | answ += (next - curr + n) % n; 21 | curr = next; 22 | } 23 | std::cout << answ; 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0455A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 455A. Boredom 3 | Solution: dynamic programming 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | typedef long long ll; 10 | 11 | int main() { 12 | const int AMAX = 1e5; 13 | std::vector cnt(1+AMAX); 14 | 15 | int n; std::cin >> n; 16 | while (n--) { int a; std::cin >> a; cnt[a]++; } 17 | 18 | std::vector max(1+AMAX); 19 | max[0] = 0; max[1] = cnt[1]; 20 | for (int i = 2; i <= AMAX; ++i) { 21 | max[i] = std::max((ll)cnt[i] * i + max[i-2], max[i-1]); 22 | } 23 | std::cout << max[AMAX]; 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0463B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 463B. Caisa and Pylons 3 | Solution: brute force, implementation, math 4 | */ 5 | #include 6 | #include 7 | #include 8 | typedef long long ll; 9 | int main() { 10 | int n; std::cin >> n; 11 | std::vector h(1+n); 12 | ll cur = 0, min = 0; 13 | for (int i = 1; i <= n; ++i) { 14 | std::cin >> h[i]; 15 | cur += h[i-1] - h[i]; 16 | min = std::min(min, cur); 17 | } 18 | std::cout << -min; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0478C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 478C. Table Decorations 3 | Solution: greedy, O(1) 4 | */ 5 | #include 6 | #include 7 | 8 | typedef long long ll; 9 | 10 | int main() { 11 | ll a, b, c; std::cin >> a >> b >> c; 12 | if (a > b) std::swap(a, b); 13 | if (a > c) std::swap(a, c); 14 | if (b > c) std::swap(b, c); 15 | if (c >= 2 * (a + b)) { 16 | std::cout << a + b; 17 | } else { 18 | std::cout << (a + b + c) / 3; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0493D.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 493D. Vasya and Chess 3 | Solution: constructive, math, games, O(1) 4 | */ 5 | #include 6 | 7 | int main() { 8 | int n; std::cin >> n; 9 | if (n % 2 == 0) { 10 | std::cout << "white\n1 2"; 11 | } else { 12 | std::cout << "black"; 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1500-1599/0501A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 501A. Contest 3 | Solution: implementation 4 | */ 5 | #include 6 | 7 | int main() { 8 | double p1, p2, t1, t2; 9 | std::cin >> p1 >> p2 >> t1 >> t2; 10 | double r1 = std::max(3*p1/10, p1 - p1 / 250 * t1); 11 | double r2 = std::max(3*p2/10, p2 - p2 / 250 * t2); 12 | if (r1 < r2) { 13 | printf("Vasya"); 14 | } else if (r1 > r2) { 15 | printf("Misha"); 16 | } else { 17 | printf("Tie"); 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699 (extra)/0084A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 84A. Toy Army 3 | 4 | Solution: greedy, constructive, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int solve(int nSteps, int nSoldiers) { 12 | if (nSteps == 0) return 0; 13 | return nSoldiers + solve(nSteps-1, nSoldiers / 2); 14 | } 15 | 16 | int main() { 17 | int n; 18 | while (std::cin >> n) { 19 | std::cout << solve(2, n) << std::endl; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699 (extra)/0103A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 103A. Testing Pants for Sadness 3 | 4 | Solution: math, combinatorics, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | typedef long long ll; 12 | 13 | int main() { 14 | int n; 15 | while (std::cin >> n) { 16 | ll answ = n; 17 | for (int i = 1, a; i <= n; ++i) { 18 | std::cin >> a; 19 | answ += (ll)i * (a-1); 20 | } 21 | std::cout << answ << std::endl; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699 (extra)/0467A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 467A. George and Accommodation 3 | 4 | Solution: implementation, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int n; 13 | while (std::cin >> n) { 14 | int answ = 0; 15 | while (n--) { 16 | int p, q; std::cin >> p >> q; 17 | answ += q - p >= 2; 18 | } 19 | std::cout << answ << std::endl; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0069A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 69A. Young Physicist 3 | 4 | Solution: implementation, geometry, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | int main() { 11 | int n; 12 | while (std::cin >> n) { 13 | int sx = 0, sy = 0, sz = 0,x,y,z; 14 | while (n--) { 15 | std::cin >> x >> y >> z; 16 | sx += x, sy += y, sz += z; 17 | } 18 | std::cout << (sx == 0 && sy == 0 && sz == 0 ? "YES\n" : "NO\n"); 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0122A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 122A. Lucky Division 3 | 4 | Solution: brute force, number theory, O(n*log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | bool is_lucky(int n) { 12 | do { 13 | if (!(n % 10 == 4 || n % 10 == 7)) return false; 14 | n /= 10; 15 | } while (n > 0); 16 | return true; 17 | } 18 | 19 | int main() { 20 | int n; 21 | while (std::cin >> n) { 22 | bool flag = false; 23 | for (int div = 4; !flag && div <= n; ++div) { 24 | if (is_lucky(div) && n % div == 0) { 25 | flag = true; 26 | } 27 | } 28 | std::cout << (flag ? "YES\n" : "NO\n"); 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0214A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 214A. System of Equations 3 | 4 | Solution: brute force, O(sqrt(n)+sqrt(m)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | int main() { 11 | int n, m; 12 | while (std::cin >> n >> m) { 13 | int cnt = 0; 14 | for (int a = 0; a <= m && a * a <= n; ++a) { 15 | for (int b = 0; a * a + b <= n && a + b * b <= m; ++b) { 16 | cnt += a * a + b == n && a + b * b == m; 17 | } 18 | } 19 | std::cout << cnt << std::endl; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0231A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 231A. Team 3 | 4 | Solution: implementation, counting, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | #include 9 | int main() { 10 | int n; 11 | while (std::cin >> n) { 12 | int cnt = 0, a, b, c; 13 | while (n--) { 14 | std::cin >> a >> b >> c; 15 | cnt += (a + b + c >= 2); 16 | } 17 | std::cout << cnt << std::endl; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0236A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 236A. Boy or Girl 3 | 4 | Solution: strings, counting sort, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | int main() { 14 | std::string s; 15 | while (std::cin >> s) { 16 | std::vector in(256); 17 | for (auto& it : s) in[it] = 1; 18 | int sum = std::accumulate(in.begin(), in.end(), 0); 19 | std::cout << (sum % 2 == 1 ? "IGNORE HIM!\n" : "CHAT WITH HER!\n"); 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0263A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 263A. Beautiful Matrix 3 | 4 | Solution: implementation, geometry, O(n^2) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | int main() { 12 | int answ = 0; 13 | for (int r = 1; r <= 5; ++r) { 14 | for (int c = 1; c <= 5; ++c) { 15 | int v; std::cin >> v; 16 | if (v == 1) { 17 | answ = std::abs(r-3) + std::abs(c-3); 18 | } 19 | } 20 | } 21 | std::cout << answ << std::endl; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0281A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 281A. Word Capitalization 3 | 4 | Solution: strings, implementation, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | std::string s; 14 | while (std::cin >> s) { 15 | if ('a' <= s[0] && s[0] <= 'z') { 16 | s[0] = char(s[0] - 'a' + 'A'); 17 | } 18 | std::cout << s << std::endl; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0282A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 282A. Bit++ 3 | 4 | Solution: implementation, strings, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int n; 14 | while (std::cin >> n) { 15 | int x = 0; 16 | while (n--) { 17 | std::string s; std::cin >> s; 18 | if (s.find('+') != std::string::npos) { 19 | ++x; 20 | } else --x; 21 | } 22 | std::cout << x << std::endl; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0318A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 318A. Even Odds 3 | 4 | Solution: math, number theory, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | typedef long long ll; 11 | int main() { 12 | ll n, k; 13 | while (std::cin >> n >> k) { 14 | ll nOdd = (n+1)/2; 15 | ll answ = (k <= nOdd) ? (2 * k - 1) : 2 * (k - nOdd); 16 | std::cout << answ << std::endl; 17 | } 18 | return 0; 19 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1600-1699/0344A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 344A. Magnets 3 | 4 | Solution: strings, implementation, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | int main() { 12 | int n; 13 | while (std::cin >> n) { 14 | int answ = 0; 15 | std::string group = ""; 16 | while (n--) { 17 | std::string s; std::cin >> s; 18 | if (group.empty() || group.back() == s.front()) { 19 | group = s; 20 | ++answ; 21 | } else { 22 | group.insert(group.end(), s.begin(), s.end()); 23 | } 24 | } 25 | std::cout << answ << std::endl; 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1700-1799 (extra)/0197A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 197A. Plate Game 3 | 4 | Solution: geometry, game theory, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int a, b, r; 13 | while (std::cin >> a >> b >> r) { 14 | std::cout << (a >= 2 * r && b >= 2 * r ? "First\n" : "Second\n"); 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1700-1799 (extra)/0201A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 201A. Clear Symmetry 3 | 4 | Solution: math, greedy, O(x) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int solve(int x) { 12 | if (x == 1) { 13 | return 1; 14 | } 15 | if (x == 3) { 16 | return 5; 17 | } 18 | int n = 3; 19 | while (true) { 20 | if ((n*n+1)/2>=x) { 21 | return n; 22 | } 23 | n += 2; 24 | } 25 | } 26 | 27 | int main() { 28 | int x; 29 | while (std::cin >> x) { 30 | std::cout << solve(x) << std::endl; 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1700-1799 (extra)/0378A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 378A. Playing with Dice 3 | 4 | Solution: brute force, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | int a, b; 14 | while (std::cin >> a >> b) { 15 | int na = 0, nb = 0; 16 | for (int x = 1; x <= 6; ++x) { 17 | int da = std::abs(x-a); 18 | int db = std::abs(x-b); 19 | na += da < db; 20 | nb += da > db; 21 | } 22 | std::cout << na << ' ' << 6 - na - nb << ' ' << nb << std::endl; 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1700-1799 (extra)/0560A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 560A. Currency System in Geraldion 3 | 4 | Solution: constructive, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int n; 13 | while (std::cin >> n) { 14 | bool is1 = false; 15 | for (int i = 0, v; i < n; ++i) { 16 | std::cin >> v; 17 | is1 = is1 || v == 1; 18 | } 19 | std::cout << (is1 ? -1 : 1) << std::endl; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1700-1799 (extra)/0577A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 577A. Multiplication Table 3 | 4 | Solution: brute force, number theory, math, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int n, x; 13 | while (std::cin >> n >> x) { 14 | int answ = 0; 15 | for (int i = 1; i <= n; ++i) { 16 | answ += x % i == 0 && x / i <= n; 17 | } 18 | std::cout << answ << std::endl; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1700-1799 (extra)/0651A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 651A. Joysticks 3 | 4 | Solution: greedy, implementation, O(a+b) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int a,b; 13 | while (std::cin >> a >> b) { 14 | int answ = 0; 15 | while (a > 0 && b > 0) { 16 | if (a == 1 && b == 1) { 17 | break; 18 | } 19 | if (a < b) { 20 | a++,b-=2; 21 | } else { 22 | b++,a-=2; 23 | } 24 | ++answ; 25 | } 26 | std::cout << answ << std::endl; 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899 (extra)/0029A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 29A. Spit Problem 3 | Solution: std::set, searching, pairs, O(n log(n)) 4 | */ 5 | #include 6 | using pii = std::pair; 7 | int main() { 8 | int n; scanf("%d", &n); 9 | std::set s; 10 | while (n--) { 11 | int p,d; scanf("%d %d", &p, &d); 12 | s.insert({p,p+d}); 13 | } 14 | bool ok = false; 15 | for (auto [x,y] : s) ok |= s.count({y,x}); 16 | printf(ok ? "YES\n" : "NO\n"); 17 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899 (extra)/0078A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 78A. Haiku 3 | Solution: strings, counting, O(n) 4 | */ 5 | #include 6 | #define all(x) (x).begin(),(x).end() 7 | std::string alp = "aeiou"; 8 | using vi = std::vector; 9 | int main() { 10 | std::sort(all(alp)); 11 | vi vec; 12 | for (std::string s; std::getline(std::cin, s); ) { 13 | int cnt(0); 14 | for (auto it : s) cnt += std::binary_search(all(alp), it); 15 | vec.push_back(cnt); 16 | } 17 | std::cout << (vec == vi{5,7,5} ? "YES" : "NO") << std::endl; 18 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899 (extra)/0080B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 80B. Depression 3 | Solution: geometry, angle, O(1) 4 | */ 5 | #include 6 | int main() { 7 | int h, m; scanf("%d:%d", &h, &m); 8 | h = 60 * (h % 12) + m; 9 | printf("%0.9f %0.9f\n", h / (12.0 * 60) * 360, m / 60.0 * 360); 10 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899 (extra)/0357A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 357A. Group of Students 3 | Solution: brute force, implementation, O(n) 4 | */ 5 | #include 6 | int main() { 7 | int m,s(0); scanf("%d", &m); 8 | std::vector c(1+m); 9 | for (int i = 1; i <= m; i++) { 10 | scanf("%d", &c[i]); 11 | s += c[i]; 12 | } 13 | int x, y, answ(0); scanf("%d %d", &x, &y); 14 | for (int i = 1, p(0); i <= m; i++) { 15 | if (x <= p && p <= y && x <= s && s <= y) { 16 | answ = i; 17 | } 18 | p += c[i]; 19 | s -= c[i]; 20 | } 21 | printf("%d\n", answ); 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899 (extra)/0385A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 385A. Bear and Raspberry 3 | Solution: brute force, implementation, O(n) 4 | */ 5 | #include 6 | int main() { 7 | int n, c; scanf("%d %d", &n, &c); 8 | int answ(0); 9 | std::vector d(n); 10 | for (auto &it : d) { 11 | scanf("%d", &it); 12 | } 13 | for (int i = 1; i < n; i++) { 14 | if (d[i] <= d[i-1]) { 15 | answ = std::max(answ,d[i-1]-d[i]-c); 16 | } 17 | } 18 | printf("%d\n", answ); 19 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899 (extra)/0426A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 426A. Sereja and Mugs 3 | Solution: implementation, O(n) 4 | */ 5 | #include 6 | int main() { 7 | int n, s, max(1); scanf("%d %d", &n, &s); 8 | for (int a; n--; s -= a, max = std::max(max, a)) scanf("%d", &a); 9 | std::cout << (s + max >= 0 ? "YES" : "NO") << std::endl; 10 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899/0235A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 235A. LCM Challenge 3 | Solution: lcm, number theory, math, brute force 4 | */ 5 | #include 6 | typedef long long ll; 7 | ll naive(int a, int b) { 8 | ll max = 1; 9 | for (ll i = a; i <= b; i++) { 10 | for (ll j = a; j <= b; j++) { 11 | const ll lcm = std::lcm(i,j); 12 | for (ll k = a; k <= b; k++) { 13 | max = std::max(max, std::lcm(lcm, k)); 14 | } 15 | } 16 | } 17 | return max; 18 | } 19 | int main() { 20 | for (int n; std::cin >> n; std::cout << naive(std::max(1, n-100), n) << std::endl); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899/0312B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 312B. Archer 3 | Solution: math, probability theory, O(eps) 4 | */ 5 | #include 6 | typedef long double ld; 7 | int main() { 8 | ld a, b, c, d; std::cin >> a >> b >> c >> d; 9 | ld p = a / b, q = c / d; 10 | ld res = p, coeff = (1-p)*(1-q), pow = 1; 11 | for (int i = 1; i < (int)1e6; i++) { 12 | pow *= coeff; 13 | res += pow * p; 14 | } 15 | std::cout << std::fixed << std::setprecision(6) << res << std::endl; 16 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899/0373A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 373A. Collecting Beats is Fun 3 | Solution: strings, counting, implementation, O(n^2) 4 | */ 5 | #include 6 | int main() { 7 | for (int k; std::cin >> k; ) { 8 | std::vector cnt(256); 9 | for (int i = 0; i < 4; i++) { 10 | std::string s; 11 | std::cin >> s; 12 | for (auto it : s) { 13 | cnt[it]++; 14 | } 15 | } 16 | bool ok = true; 17 | for (char c = '1'; c <= '9'; c++) { 18 | ok = ok && cnt[c] <= 2 * k; 19 | } 20 | std::cout << (ok ? "YES\n" : "NO\n"); 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899/0384A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 384A. Coder 3 | Solution: constructive, O(n^2) 4 | */ 5 | #include 6 | int main() { 7 | int n, cnt = 0; std::cin >> n; 8 | std::vector arr(n, std::string(n, '.')); 9 | for (int i = 0; i < n; i++) { 10 | for (int j = 0; j < n; j++) { 11 | if ((i+j)%2 == 0) { 12 | cnt++; 13 | arr[i][j] = 'C'; 14 | } 15 | } 16 | } 17 | std::cout << cnt << '\n'; 18 | for (auto &it : arr) std::cout << it << '\n'; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /codeforces.com/Codeforces Ladder 1800-1899/0443A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 443A. Anton and Letters 3 | Solution: strings, implementation, O(n*log(n)) 4 | */ 5 | #include 6 | int main() { 7 | std::string s; 8 | std::getline(std::cin, s); 9 | std::set set; 10 | for (auto it : s) { 11 | if ('a' <= it && it <= 'z') { 12 | set.insert(it); 13 | } 14 | } 15 | std::cout << set.size() << std::endl; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /codeforces.com/Div 3 Rounds/1102A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | problem: 1102A. Integer Sequence Dividing 3 | solution: math, sum of arithmetic progression 4 | */ 5 | #include "template.hpp" 6 | int main() { 7 | int n; std::cin >> n; 8 | ll sum = n * (n+1LL)/2; 9 | std::cout << sum % 2 << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /codeforces.com/Div 3 Rounds/1102C.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | problem: 1102C. Doors Breaking and Repairing 3 | solution: game theory 4 | */ 5 | #include "template.hpp" 6 | int main() { 7 | int n, x, y; 8 | std::cin >> n >> x >> y; 9 | vi a(n); std::cin >> a; 10 | if (x > y) { 11 | std::cout << n << std::endl; 12 | return 0; 13 | } 14 | int notGreater{}; 15 | for (auto &it : a) 16 | notGreater += !(x < it); 17 | std::cout << (notGreater+1)/2 << std::endl; 18 | } 19 | -------------------------------------------------------------------------------- /codeforces.com/Div 3 Rounds/1154A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | problem: 1154A. Restoring Three Numbers 3 | solution: math, sorting, max 4 | */ 5 | #include "template.hpp" 6 | int main() { 7 | // из максимального вычесть остальные 8 | vi a(4); std::cin >> a; 9 | std::sort(all(a)); 10 | int max = a--; 11 | for (auto &it : a) 12 | std::cout << (it = max - it) << ' '; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /codeforces.com/Div3-1009/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | main() { 3 | std::ios::sync_with_stdio(false); 4 | std::cin.tie(0); 5 | int tt; std::cin >> tt; 6 | while (tt --> 0) { 7 | // диагонали должны быть равными, тогда это квадрат 8 | // но конкретно в этой задаче условие сильнее: должны 9 | // быть равны половинки диагоналей между собой (чтобы угол был 90) 10 | int l, r, d, u; std::cin >> l >> r >> d >> u; 11 | std::cout << (l == r && l == d && l == u ? "Yes\n" : "No\n"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/01-A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 598A. Tricky Sum 3 | 4 | Solution: math, arithmetic progression, O(q * log(v)) 5 | */ 6 | 7 | #include 8 | 9 | typedef long long ll; 10 | 11 | ll sum2(int v) { 12 | ll s = 0, p = 1; 13 | while (p <= v) { 14 | s += p; p *= 2; 15 | } 16 | return s; 17 | } 18 | 19 | inline ll answer(int v) { 20 | return (ll)v * (v+1) / 2 - 2 * sum2(v); 21 | } 22 | 23 | int main() { 24 | int nQ; std::cin >> nQ; 25 | while (nQ--) { 26 | int v; 27 | std::cin >> v; 28 | std::cout << answer(v) << "\n"; 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/01-B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 598B. Queries on a String 3 | 4 | Solution: algorithm, rotate, strings, O(m * len) 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main() { 12 | int nQ; std::string s; 13 | std::cin >> s >> nQ; 14 | while (nQ--) { 15 | int l, r, k; 16 | std::cin >> l >> r >> k; 17 | --l, --r; 18 | k %= (r-l+1); 19 | std::rotate(s.begin()+l, s.begin()+r+1-k, s.begin()+r+1); 20 | } 21 | std::cout << s; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/06-A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 620A. Professor GukiZ's Robot 3 | 4 | Solution: math, implementation, O(1) 5 | 6 | Author: Dmitry Kozyrev, https://github.com/dmkz , dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | std::ios_base::sync_with_stdio(false); 15 | std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); 16 | 17 | int x1, y1, x2, y2; std::cin >> x1 >> y1 >> x2 >> y2; 18 | 19 | std::cout << std::max(std::abs(y2-y1), std::abs(x2 - x1)) << std::endl; 20 | 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/07-B.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 622B. The Time 3 | 4 | Solution: math, implementation, O(1) 5 | 6 | Author: Dmitry Kozyrev, https://github.com/dmkz , dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int h, m; 13 | scanf("%d:%d", &h, &m); 14 | m += 60 * h; 15 | int a; scanf("%d", &a); 16 | m += a; 17 | printf("%02d:%02d\n", m / 60 % 24, m % 60); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/13-A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 678A. Johny Likes Numbers 3 | 4 | Solution: implementation, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | typedef long long ll; 12 | 13 | int main() { 14 | ll n, k; 15 | std::cin >> n >> k; 16 | std::cout << (n / k + 1) * k; 17 | return 0; 18 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/14-A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 691A. Fashion in Berland 3 | 4 | Solution: implementation, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | typedef long long ll; 12 | 13 | int main() { 14 | std::ios_base::sync_with_stdio(false); 15 | std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); 16 | 17 | int n; std::cin >> n; 18 | int nZeros = 0; 19 | for (int i = 0 ; i < n; ++i) { 20 | int v; std::cin >> v; 21 | nZeros += v == 0; 22 | } 23 | std::cout << (n == 1 ? (nZeros == 1 ? "NO" : "YES") : (nZeros == 1 ? "YES" : "NO")); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/21-A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 808A. Lucky Year 3 | 4 | Solution: implementation, math, O(log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int64_t n, pow = 1; std::cin >> n; 13 | if (n < 10) {std::cout << 1; return 0; } 14 | while (pow * 10 <= n) pow *= 10; 15 | std::cout << (n/pow+1)*pow - n; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/24-A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 818A. Diplomas and Certificates 3 | 4 | Solution: math, O(1) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | int64_t n, k, s; std::cin >> n >> k; 13 | //(k+1) * s <= n / 2 14 | s = n / 2 / (k+1); 15 | std::cout << s << " " << k * s << " " << n - (k+1)*s; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/25-A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 825A. Binary Protocol 3 | 4 | Solution: implementation, two pointers, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int main() { 13 | std::string s; int n; 14 | std::cin >> n >> s; s += '0'; 15 | int i = 0, answ = 0; 16 | while (i <= n) { 17 | int r = i; 18 | while (s[r] == '1') ++r; 19 | answ = answ * 10 + (r - i); 20 | i = r+1; 21 | } 22 | std::cout << answ; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/26-A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 837A. Text Volume 3 | 4 | Solution: implementation, strings, O(n) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int f(const std::string& s) { 15 | int ret = 0; 16 | for (auto& it : s) { 17 | ret += 'A' <= it && it <= 'Z'; 18 | } 19 | return ret; 20 | } 21 | 22 | int main() { 23 | int n , answ = 0; std::cin >> n; 24 | while (n--) { 25 | std::string s; 26 | std::cin >> s; 27 | answ = std::max(answ, f(s)); 28 | } 29 | std::cout << answ; 30 | return 0; 31 | } -------------------------------------------------------------------------------- /codeforces.com/Educational Codeforces Rounds/27-A.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 845A. Chess Tourney 3 | 4 | Solution: sorting, O(n log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n; scanf("%d", &n); 15 | std::vector a(2*n); 16 | for (auto& it : a) scanf("%d", &it); 17 | std::sort(a.begin(), a.end()); 18 | printf(a[n-1] < a[n] ? "YES" : "NO"); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /contests/Advent-of-Code-2022/01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define all(x) (x).begin(),(x).end() 3 | #define isz(x) (int)(x).size() 4 | const bool easy_version = false; 5 | int main() { 6 | std::vector v; 7 | std::string s; 8 | while(std::getline(std::cin, s)) { 9 | if (v.empty() || isz(s) == 0) { 10 | v.push_back(0); 11 | } 12 | if (isz(s)) { 13 | v.back() += std::stoll(s); 14 | } 15 | } 16 | if(easy_version) { 17 | std::cout << *std::max_element(all(v)) << std::endl; 18 | } else { 19 | std::sort(all(v),std::greater<>()); 20 | std::cout << std::accumulate(v.begin(),v.begin()+3,0LL) << std::endl; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /contests/Advent-of-Code-2022/04.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool isIncludes(int L1, int R1, int L2, int R2) { 4 | return (L1 <= L2 && R2 <= R1) || (L2 <= L1 && R1 <= R2); 5 | } 6 | 7 | bool isOverlaps(int L1, int R1, int L2, int R2) { 8 | return !(R1 < L2 || R2 < L1); 9 | } 10 | 11 | int main() { 12 | std::string s; 13 | int answer1{},answer2{}; 14 | while(std::cin >> s) { 15 | int a,b,c,d; 16 | sscanf(s.c_str(), "%d-%d,%d-%d",&a,&b,&c,&d); 17 | answer1 += isIncludes(a,b,c,d); 18 | answer2 += isOverlaps(a,b,c,d); 19 | } 20 | std::cout << answer1 << std::endl; 21 | std::cout << answer2 << std::endl; 22 | } -------------------------------------------------------------------------------- /contests/BSUIR-2023-Semifinals/I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int t; std::cin >> t; 4 | while (t --> 0) { 5 | int n, m; std::cin >> n >> m; 6 | std::cout << (n % 4 == 0 && m % 4 == 0? "Yes\n" : "No\n"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /contests/MRC-Qual-2023/A.py: -------------------------------------------------------------------------------- 1 | print(2) -------------------------------------------------------------------------------- /contests/MRC-Qual-2023/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int32_t main() { 4 | // n = 24: 5 | // 1 2 3 ... 24 1 2 3 ... 24 1 2 3 ... 24 1 2 3 ... 24 6 | // 25 + 25 7 | // n = 25: 1 2 3 ... 25 1 2 3 ... 25 8 | // тоже 50 9 | // n = 26: 1 2 3 ... 25 26 1 2 3 ... 26 10 | // 51 11 | int n; cin >> n; 12 | int minN = 50 + max(0, n - 25); 13 | // n = 24: 14 | // 1 1 1 1 1 .... 1 1 1 1 2 2 2 2 .... 2 15 | // 25 - первая квота 16 | // 25 - вторая квота 17 | // затем лучшие команды вузов 18 | // какая-то линейная функция, при n = 27 будет 76 = 50 + (n-1) 19 | int maxN = 50 + (n-1); 20 | cout << minN << ' ' << maxN << endl; 21 | } 22 | -------------------------------------------------------------------------------- /contests/MRC-Qual-2023/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int int64_t 3 | using namespace std; 4 | int32_t main() { 5 | // 1, 7, 7^2, 7^3 6 | // похоже, ответ - количество делителей между первым и вторым числом 7 | int q, r; cin >> q >> r; 8 | int n = q * r - q, answ = 0; 9 | for (int x = 1; x * x <= n; x++) 10 | if (int y = n / x; y * x == n) 11 | answ += 1 + (x != y); 12 | cout << answ << endl; 13 | } 14 | -------------------------------------------------------------------------------- /contests/MRC-Qual-2023/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | using ld = long double; 4 | ld ask(int x) { 5 | cout << "? " << x << endl; 6 | ld dist; cin >> dist; 7 | return dist; 8 | } 9 | int32_t main() { 10 | // S = (abc) / (4R) ==> R = (abc)/(4S) 11 | // из трех запросов узнаем стороны треугольника 12 | // опишем возле него окружность 13 | ld right = ask(0), left = ask(180), down = ask(270); 14 | ld a = left+right; 15 | ld b = sqrtl(left*left+down*down); 16 | ld c = sqrtl(right*right+down*down); 17 | ld S = a * down / 2; 18 | ld R = (a*b*c)/(4*S); 19 | cout << fixed << setprecision(0); 20 | cout << "! " << R << endl; 21 | } 22 | -------------------------------------------------------------------------------- /contests/MRC-Qual-2024/A.py: -------------------------------------------------------------------------------- 1 | print(4); -------------------------------------------------------------------------------- /contests/MRC-Qual-2024/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | main() { 3 | std::string org; 4 | while(std::cin >> org) { 5 | bool isOrg = (org == "org"); 6 | int t; std::cin >> t; 7 | int qual; std::cin >> qual; 8 | int s; std::cin >> s; 9 | int b = 2; 10 | if (isOrg) { 11 | b = 4; 12 | } else if (s >= 30) { 13 | b = 3; 14 | } else if (t >= 2) { 15 | b = 3; 16 | } 17 | int T = 0; 18 | if (qual >= 60) { 19 | T = 2; 20 | } else if (qual >= 30) { 21 | T = 1; 22 | } 23 | std::cout << b + T << std::endl; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /contests/MRC-Qual-2024/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using ld = long double; 3 | main() { 4 | int u, m; 5 | while(std::cin >> u >> m) { 6 | std::vector sum(4+1); 7 | for (int count = 15; count --> 0; ) { 8 | int t, s; std::cin >> t >> s; 9 | ld cost = ld(s) / t; 10 | for (int i = 1; i <= t; i++) 11 | sum[i] += cost; 12 | for (int i = t+1; i <= 4; i++) 13 | sum[i] += m; 14 | } 15 | for (int t = 1; t <= 4; t++) { 16 | ld answ = sum[t]; 17 | if (answ >= u) 18 | answ += (answ - u); 19 | std::cout << answ << std::endl; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /contests/MRC-Qual-2024/analysis-v05.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/contests/MRC-Qual-2024/analysis-v05.pdf -------------------------------------------------------------------------------- /contests/Moscow Regional Contest 2021/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; std::cin >> n; 4 | std::cout << (n > 1); 5 | } -------------------------------------------------------------------------------- /contests/Moscow Regional Contest 2021/f.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; std::cin >> n; 4 | if (n <= 3) std::cout << "-1\n"; 5 | else { 6 | std::vector> edges; 7 | edges.emplace_back(1,2); 8 | edges.emplace_back(1,3); 9 | edges.emplace_back(2,3); 10 | edges.emplace_back(4,2); 11 | edges.emplace_back(4,3); 12 | for (int i = 5; i <= n; i++) { 13 | edges.emplace_back(i-1,i); 14 | } 15 | std::cout << edges.size() << '\n'; 16 | for (const auto &[a,b] : edges) 17 | std::cout << a << ' ' << b << '\n'; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /contests/Moscow Regional Contest 2021/n.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int a,b,c,d,e,f; 4 | while (std::cin >> a >> b >> c >> d >> e >> f) { 5 | if (a*c*e != b*d*f) { 6 | std::cout << "-1\n"; 7 | continue; 8 | } 9 | // triangle rules: 10 | if (a*c 2 | #define isz(x) (int)(x).size() 3 | using namespace std; 4 | // выводим: 5 | // 1 ... 9 6 | // 10 ... 99 7 | // 100 ... 999 8 | // 1000 ... 9999 9 | main() { 10 | int n; 11 | while (cin >> n) { 12 | string nn = to_string(n); 13 | int answ = 0; 14 | for (int start = 1; start <= n; start*=10) { 15 | int finish = start * 10 - 1; 16 | if (finish > n) 17 | finish = n; 18 | // выводим номера одинаковой длины группами по 500 19 | // (с округлением вверх) 20 | answ += (finish - start + 1 + 499) / 500; 21 | } 22 | cout << answ << endl; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contests/RuCode-2024-Final-EF/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define isz(x) (int)(x).size() 3 | using namespace std; 4 | // выводим: 5 | // 1 ... 9 6 | // 10 ... 99 7 | // 100 ... 999 8 | // 1000 ... 9999 9 | main() { 10 | int n; 11 | while (cin >> n) { 12 | string nn = to_string(n); 13 | int answ = 0; 14 | for (int start = 1; start <= n; start*=10) { 15 | int finish = start * 10 - 1; 16 | if (finish > n) 17 | finish = n; 18 | // выводим номера одинаковой длины группами по 500 19 | // (с округлением вверх) 20 | answ += (finish - start + 1 + 499) / 500; 21 | } 22 | cout << answ << endl; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contests/RuCode-2024-Final-EF/L.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | main() { 4 | cout << 0 << endl; 5 | } 6 | -------------------------------------------------------------------------------- /contests/RuCode-2024-Final-EF/M.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | const set valid{"???????? ? ???????? ???????", 4 | "??", 5 | "???????????", 6 | "???????", 7 | "??????", 8 | "??? ????", 9 | "?????????????????", 10 | "???????? ???????", 11 | "????? ??????????"}; 12 | main() { 13 | string s; 14 | getline(cin, s); 15 | int t = stoi(s); 16 | while (t --> 0) { 17 | getline(cin, s); 18 | cout << valid.count(s) << "\n"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /contests/RuCode-6.0-Final-CD/C.py: -------------------------------------------------------------------------------- 1 | import sys 2 | checks = ['a1', 'h7', 'c4'] 3 | 4 | def itr(x): 5 | print(x) 6 | sys.stdout.flush() 7 | return int(input()) == 0 8 | 9 | def step(): 10 | if itr(checks[0]) and itr(checks[1]): 11 | itr(checks[2]) 12 | 13 | T = int(input()) 14 | for _ in range(T): 15 | step() -------------------------------------------------------------------------------- /contests/RuCode-6.0-Final-CD/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | double solve(int k, int t) { 4 | return (double(t) - 0.5) / k; 5 | } 6 | 7 | int main() { 8 | std::ios::sync_with_stdio(false); 9 | std::cin.tie(0); 10 | int q; std::cin >> q; 11 | double max = 0; 12 | for (size_t i=0; i> k >> t; 15 | max = std::max(max, solve(k, t)); 16 | } 17 | std::cout< 2 | using namespace std; 3 | int main() { 4 | size_t pf, pe, pd, total, pc = 1; 5 | cin >> pf >> pe >> pd >> total; 6 | if (total == 0) { 7 | cout << 'F'; 8 | } else if (total >= 1 && total < pf + (pe+1)/2) { 9 | cout << "E"; 10 | } else if (total == pf+(pe+1)/2) { 11 | cout << "D/E"; 12 | } else if (total < pf+pe+(pd+1)/2) { 13 | cout << "D"; 14 | } else if (total == pf+pe+(pd+1)/2) { 15 | cout << "C/D"; 16 | } else if (total > pf+pe+(pd+1)/2 && total < pf+pe+pd+pc) { 17 | cout << "C"; 18 | } else { 19 | cout << "Champ AB"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Final-CD/M1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int l, r; 5 | cin >> l >> r; 6 | if (r-l==0) cout << l; 7 | else if (r-l==1) cout << -1; 8 | else cout << r-1; 9 | } 10 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Final-CD/RuCode-7.0-CD.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/contests/RuCode-7.0-Final-CD/RuCode-7.0-CD.pdf -------------------------------------------------------------------------------- /contests/RuCode-7.0-Final-EF/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | size_t pf, pe, pd, total, pc = 1; 5 | cin >> pf >> pe >> pd >> total; 6 | if (total == 0) { 7 | cout << 'F'; 8 | } else if (total >= 1 && total < pf + (pe+1)/2) { 9 | cout << "E"; 10 | } else if (total == pf+(pe+1)/2) { 11 | cout << "D/E"; 12 | } else if (total < pf+pe+(pd+1)/2) { 13 | cout << "D"; 14 | } else if (total == pf+pe+(pd+1)/2) { 15 | cout << "C/D"; 16 | } else if (total > pf+pe+(pd+1)/2 && total < pf+pe+pd+pc) { 17 | cout << "C"; 18 | } else { 19 | cout << "Champ AB"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Final-EF/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n, answ = 0; cin >> n; 5 | while (n --> 0) { 6 | string s; cin >> s; 7 | s += "00"; 8 | // считаем число нулей на конце числа - все они превратятся в девятки 9 | while (s.size() && s.back() == '0') { 10 | answ++; 11 | s.pop_back(); 12 | } 13 | // на конце могла остаться одна девятка, которая станет 8, и её надо вычесть 14 | if (s.size() && s.back() == '9') 15 | answ--; 16 | } 17 | cout << answ << endl; 18 | } 19 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Final-EF/M1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int l, r; 5 | cin >> l >> r; 6 | if (r-l==0) cout << l; 7 | else if (r-l==1) cout << -1; 8 | else cout << r-1; 9 | } 10 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Final-EF/N.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using ld = long double; 3 | using namespace std; 4 | int main() { 5 | int w, h; cin >> w >> h; 6 | ld d; cin >> d; 7 | // x^2+y^2=d^2 --- d это гипотенуза в прямоугольном треугольнике с катетами x и y*h 8 | // мы не знаем x и y, но знаем, что они относятся друг к другу как w к h 9 | // x/y=w/h=A => x = A*y --- подставим в уравнение и найдём y 10 | // (A^2+1)y^2=d^2 11 | ld A = ld(w)/h; 12 | ld y = d / sqrtl(A*A+1); 13 | // теперь мы знаем сколько пикселей в дюйме (h/y), это и есть ответ 14 | cout << fixed << setprecision(12); 15 | cout << h/y << endl; 16 | } 17 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Final-EF/RuCode-7.0-EF.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/contests/RuCode-7.0-Final-EF/RuCode-7.0-EF.pdf -------------------------------------------------------------------------------- /contests/RuCode-7.0-Qual/A.cpp: -------------------------------------------------------------------------------- 1 | #include "template.hpp" 2 | int main() { 3 | std::cout << 0; 4 | } 5 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Qual/B.cpp: -------------------------------------------------------------------------------- 1 | #include "template.hpp" 2 | int main() { 3 | int a, b; 4 | std::cin >> a >> b; 5 | std::cout << a+b; 6 | } 7 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Qual/C.cpp: -------------------------------------------------------------------------------- 1 | #include "template.hpp" 2 | int main() { 3 | int n; std::cin >> n; 4 | int low = 1; 5 | int high = n+1; 6 | // y >= low - всегда 7 | // y < high - всегда 8 | // ответ: low! 9 | while (high - low > 1) { 10 | int mid = (low+high)/2; 11 | std::cout << "? " << mid << std::endl; 12 | std::string s; std::cin >> s; 13 | if (s == "<") high = mid; 14 | else low = mid; 15 | } 16 | std::cout << "! " << low << std::endl; 17 | } 18 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Qual/E.cpp: -------------------------------------------------------------------------------- 1 | #include "template.hpp" 2 | #include "numeric.hpp" 3 | const int mod = (int)1e9+7; 4 | using namespace algos::numeric; 5 | using Int = IntMod; 6 | int main() { 7 | Int a,b,c,d; 8 | std::cin >> a >> b >> c >> d; 9 | std::cout << a / b + c / d << std::endl; 10 | } 11 | -------------------------------------------------------------------------------- /contests/RuCode-7.0-Qual/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | std::vector fib(100000+1, 1); 4 | for (int i = 2; i <= 100000; i++) 5 | fib[i] = (fib[i-1] + fib[i-2]) % 3; 6 | int L, R; std::cin >> L >> R; 7 | int answ{}; 8 | for (int i = L; i <= R; i++) 9 | answ += (fib[i] == 0); 10 | std::cout << answ << std::endl; 11 | } 12 | -------------------------------------------------------------------------------- /contests/WPS2009/Day 1/A. chieftain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: A. Chieftain 3 | Solution: linear max, O(n) 4 | */ 5 | #include 6 | int main() { 7 | std::ios_base::sync_with_stdio(false); 8 | std::cin.tie(0); 9 | int max = INT_MIN, cnt = 0, n; 10 | std::cin >> n; 11 | while (n--) { 12 | int v; std::cin >> v; 13 | if (v > max) { max = v; cnt = 0; } 14 | cnt += (v == max); 15 | } 16 | std::cout << cnt << std::endl; 17 | return 0; 18 | } -------------------------------------------------------------------------------- /contests/WPS2009/Day 1/C. inn.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: C. inn 3 | Solution: binary search on answer, O(t*log(n)) 4 | */ 5 | #include 6 | typedef long long ll; 7 | int main() { 8 | std::ios_base::sync_with_stdio(false); 9 | std::cin.tie(0); 10 | ll b, c; 11 | while (std::cin >> b >> c, b + c) { 12 | ll low = 0, high = INT_MAX; 13 | while (high - low > 1) { 14 | ll x = (low + high) / 2; 15 | if (- (x+1) * b + x * c > 0) { high = x; } 16 | else { low = x; } 17 | } 18 | std::cout << high << '\n'; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /contests/Yandex-Cup-2023-Qual/A.cpp: -------------------------------------------------------------------------------- 1 | #include "template.hpp" 2 | int main() { 3 | int n; std::cin >> n; 4 | vi a(n); std::cin >> a; 5 | vi lastPos(1e6+1, -1); 6 | for (int i = 0; i < n; i++) 7 | lastPos[a[i]] = i; 8 | int pos = -1; 9 | int answ{}; 10 | for (int item = 1; item <= 1e6; item++) { 11 | if (lastPos[item] > pos) { 12 | answ++; 13 | pos = lastPos[item]; 14 | } else { 15 | break; 16 | } 17 | } 18 | std::cout << answ << std::endl; 19 | } 20 | -------------------------------------------------------------------------------- /documents/2016-11-03 - бинарный поиск, немного про битовые операции.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/2016-11-03 - бинарный поиск, немного про битовые операции.pdf -------------------------------------------------------------------------------- /documents/2016-11-14 - более продвинутые применения бфса и дфса + LCA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/2016-11-14 - более продвинутые применения бфса и дфса + LCA.pdf -------------------------------------------------------------------------------- /documents/2016-11-28 - sqrt-декомпозиция в задачах на запросы к массиву.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/2016-11-28 - sqrt-декомпозиция в задачах на запросы к массиву.pdf -------------------------------------------------------------------------------- /documents/2016-12-01 - sparse table, fenwick tree.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/2016-12-01 - sparse table, fenwick tree.pdf -------------------------------------------------------------------------------- /documents/2016-12-12 - примеры задач на динамическое программирование.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/2016-12-12 - примеры задач на динамическое программирование.pdf -------------------------------------------------------------------------------- /documents/WPS2008.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/WPS2008.pdf -------------------------------------------------------------------------------- /documents/WPS2009.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/WPS2009.pdf -------------------------------------------------------------------------------- /documents/WPS2010.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/WPS2010.pdf -------------------------------------------------------------------------------- /documents/WPS2011.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/WPS2011.pdf -------------------------------------------------------------------------------- /documents/WPS2012.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/WPS2012.pdf -------------------------------------------------------------------------------- /documents/WPS2013.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/WPS2013.pdf -------------------------------------------------------------------------------- /documents/WPS2014.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/WPS2014.pdf -------------------------------------------------------------------------------- /documents/Конспект лекции по динамике.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/documents/Конспект лекции по динамике.pdf -------------------------------------------------------------------------------- /mirea/awards-2023-24/2024-ICPC Moscow Qualification-PLACE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/awards-2023-24/2024-ICPC Moscow Qualification-PLACE.pdf -------------------------------------------------------------------------------- /mirea/awards-2023-24/2024-ICPC-Qual-2-Barinov-Chikunov-Eroshev.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/awards-2023-24/2024-ICPC-Qual-2-Barinov-Chikunov-Eroshev.pdf -------------------------------------------------------------------------------- /mirea/awards-2023-24/2024-ICPC-Qual-2-Isakov-Kiriakov-Kobetz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/awards-2023-24/2024-ICPC-Qual-2-Isakov-Kiriakov-Kobetz.pdf -------------------------------------------------------------------------------- /mirea/awards-2023-24/2024-ICPC-Qual-3-Bekaldiev-Ivanitskii-Semenov.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/awards-2023-24/2024-ICPC-Qual-3-Bekaldiev-Ivanitskii-Semenov.pdf -------------------------------------------------------------------------------- /mirea/contests/2021-07-11 MIREA Goodbye Стипендия 2021/dmkozyrev/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int x1,y1,x2,y2; 4 | std::cin >> x1 >> y1 >> x2 >> y2; 5 | // x1 <= точка <= y1 6 | // x2 <= точка <= y2 7 | // значит, что: 8 | // max(x1,x2) <= точка <= min(y1,y2) 9 | // это и будет отрезок пересечения 10 | // осталось проверить, что он положительной длины 11 | int x = std::max(x1,x2); 12 | int y = std::min(y1,y2); 13 | if (x >= y) std::cout << "-1" << std::endl; 14 | else std::cout << x << ' ' << y << std::endl; 15 | return 0; 16 | } -------------------------------------------------------------------------------- /mirea/contests/2021-07-11 MIREA Goodbye Стипендия 2021/dmkozyrev/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using ld = long double; 3 | int main() { 4 | std::cout << std::setprecision(24); 5 | ld x1,y1,x2,y2; std::cin >> x1 >> y1 >> x2 >> y2; 6 | // прямоугольные треугольники подобны 7 | // коэффициент подобия: 8 | ld k = y2 / y1; 9 | // зная коэффициент подобия, можно найти x-координату общей вершины 10 | // из равенства отношения катетов: 11 | // (x2-x)/(x-x1) = y2/y1 = k 12 | std::cout << (k*x1+x2)/(k+1) << std::endl; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint C++/Задача A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin >> n; 7 | cout << (n - 1) << endl; 8 | } 9 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint C++/Задача B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | long long pown(long long n, long long power) { 5 | long long res = 1; 6 | for(int i = 0; i < power; ++i) { 7 | res *= n; 8 | } 9 | return res; 10 | } 11 | 12 | int main() { 13 | int tests; 14 | cin >> tests; 15 | for(int test = 0; test < tests; ++test) { 16 | int n; 17 | cin >> n; 18 | cout << 3LL * pown(7LL, n) << endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint C++/Задача C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int tests; 6 | cin >> tests; 7 | for(int test = 0; test < tests; ++test) { 8 | long long n, l, r; 9 | cin >> n >> l >> r; 10 | long long min = (l + n - 1) / n; 11 | long long max = (r + n - 1) / n; 12 | long long ans = max - min; 13 | cout << ans << endl; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint C++/Задача D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | const int LETTERS = 26; 6 | int tests; 7 | cin >> tests; 8 | for(int test = 0; test < tests; ++test) { 9 | vector ciphered(LETTERS); 10 | for(int i = 0; i < LETTERS; ++i) { 11 | cin >> ciphered[i]; 12 | } 13 | string s1, s2; 14 | cin >> s1 >> s2; 15 | int m = (int)s2.size(); 16 | 17 | string res; 18 | for(int i = 0; i < m; ++i) { 19 | res.append(ciphered[s2[i] - 'a']); 20 | } 21 | bool ans = (res == s1); 22 | cout << (ans ? "Yes" : "No") << endl; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint C++/Задача G.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | typedef long long ll; 5 | #define int ll 6 | 7 | int32_t main() { 8 | int tests; 9 | cin >> tests; 10 | for(int test = 0; test < tests; ++test) { 11 | int n; 12 | cin >> n; 13 | double p0, p1, p2, p3; 14 | cin >> p0 >> p1 >> p2 >> p3; 15 | 16 | double ans = n * (p1 + 2 * p2 + 3 * p3); 17 | 18 | cout << fixed << setprecision(12); 19 | cout << ans << endl; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint Python/Задача A.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | print(n - 1) 3 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint Python/Задача B.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | tests = int(input()) 3 | for test in range(tests): 4 | n = int(input()) 5 | print(3 * 7 ** n) 6 | 7 | 8 | main() 9 | 10 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint Python/Задача C.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | tests = int(input()) 3 | for test in range(tests): 4 | n, l, r = map(int, input().split()) 5 | min_n = (l + n - 1) // n 6 | max_n = (r + n - 1) // n 7 | print(max_n - min_n) 8 | 9 | 10 | main() 11 | 12 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint Python/Задача D.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | ALPH = "abcdefghijklmnopqrstuvwxyz" 3 | LETTERS = len(ALPH) 4 | TO_NUM = dict(zip(ALPH, range(LETTERS))) 5 | 6 | tests = int(input()) 7 | for test in range(tests): 8 | chars = [input() for _ in range(LETTERS)] 9 | ciphered = input() 10 | message = input() 11 | 12 | my_ciphered = ''.join((chars[TO_NUM[char]] for char in message)) 13 | print("Yes" if ciphered == my_ciphered else "No") 14 | 15 | 16 | main() 17 | 18 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/NoPoint Python/Задача G.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | tests = int(input()) 3 | for test in range(tests): 4 | n = int(input()) 5 | prob0, prob1, prob2, prob3 = map(float, input().split()) 6 | ans = (prob1 + prob2 * 2 + prob3 * 3) * n 7 | print(f"{ans:.12f}") 8 | 9 | 10 | main() 11 | 12 | -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/dmkozyrev C++/Задача A.cpp: -------------------------------------------------------------------------------- 1 | // решение: математика, O(1) 2 | // ссылка: https://codeforces.com/group/LB1sSRhotq/contest/346286/submission/129986172 3 | #include 4 | int main() { 5 | // ответ всегда n-1 6 | int n; std::cin >> n; 7 | std::cout << n-1 << std::endl; 8 | } -------------------------------------------------------------------------------- /mirea/contests/2021-09-26 MIREA Welcome Contest 2021/dmkozyrev C++/Задача C.cpp: -------------------------------------------------------------------------------- 1 | // Решение: математика, O(t) 2 | // Ссылка на сабмит: https://codeforces.com/group/LB1sSRhotq/contest/346286/submission/129986620 3 | #include 4 | int main() { 5 | int tt; std::cin >> tt; 6 | while (tt --> 0) { 7 | int64_t n,L,R; std::cin >> n >> L >> R; 8 | // нужно посчитать, сколько чисел на полуинтервале [L,R) делятся на n 9 | // пусть это f(L,R). Тогда f(L,R) = f(0,R) - f(0,L) 10 | // f(0,R) вычисляется как (R-1)/n 11 | // аналогично f(0,L) = (L-1)/n 12 | std::cout << (R-1)/n-(L-1)/n << std::endl; 13 | } 14 | } -------------------------------------------------------------------------------- /mirea/contests/2023-01-01 MIREA Happy New Year 2022-23/D_smart_win_condition.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | int tt; cin >> tt; 7 | while (tt--) { 8 | int n; cin >> n; 9 | // Андрей выигрывает, только если n < 2 или n == 9 10 | cout << (n < 2 || n == 9 ? "Andrey" : "Stepan") << '\n'; 11 | } 12 | } -------------------------------------------------------------------------------- /mirea/contests/2023-01-01 MIREA Happy New Year 2022-23/E_Eduard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main(){ 8 | int t; 9 | cin >> t; 10 | for (int it=0; it> x >> y >> t1; 13 | double sv=y/t1+9.81*t1/2; 14 | double cv=x/t1; 15 | double v=sqrt(sv*sv+cv*cv); 16 | double a=9.81*9.81; 17 | double b=y*9.81*4-4*v*v; 18 | double c=4*x*x+4*y*y; 19 | double d=b*b-4*a*c; 20 | double x1=(-b-sqrt(d))/(2*a); 21 | cout << sqrt(x1) << '\n'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mirea/contests/2023-01-01 MIREA Happy New Year 2022-23/E_python_formula.py: -------------------------------------------------------------------------------- 1 | g = 9.81 2 | 3 | from math import sqrt 4 | 5 | def solve(x, y, t1): 6 | tga1 = (y+g*t1*t1/2)/x 7 | Vs = g*x*x*(1+tga1*tga1)/2/(x*tga1-y) 8 | A = g*x*x/2/Vs 9 | B = -x 10 | C = A+y 11 | tga2 = (-B-sqrt(B*B-4*A*C))/2/A 12 | t2 = sqrt(2*(x*tga2 - y)/g) 13 | return t2 14 | 15 | 16 | t = int(input().strip()) 17 | 18 | for _ in range(t): 19 | print(solve(*[int(x) for x in input().strip().split()])) -------------------------------------------------------------------------------- /mirea/contests/2023-01-01 MIREA Happy New Year 2022-23/H_formula.py: -------------------------------------------------------------------------------- 1 | def fwd(t): 2 | a, s, n = t 3 | new_s = 6*(s+n) 4 | new_n = 6*n+1 5 | new_a = 6*a + 2 * new_s *(new_n - n) 6 | return new_a, new_s, new_n 7 | 8 | 9 | res = [(0, 0, 1)] 10 | 11 | for _ in range(10): 12 | res.append(fwd(res[-1])) 13 | 14 | q = int(input().strip()) 15 | 16 | for _ in range(q): 17 | k = int(input().strip()) 18 | print(res[k][0]) -------------------------------------------------------------------------------- /mirea/contests/2023-09-24-MIREA-Welcome-Contest-2023/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | int tt; cin >> tt; 7 | while (tt --> 0) { 8 | int n, k; cin >> n >> k; 9 | vector a(k); 10 | for (auto &it : a) 11 | cin >> it; 12 | // ответ это просто n-k, но важно не скипать чтение 13 | // номеров в мультитестах 14 | cout << n - k << endl; 15 | } 16 | } -------------------------------------------------------------------------------- /mirea/contests/2023-09-24-MIREA-Welcome-Contest-2023/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | int tt; cin >> tt; 7 | while (tt --> 0) { 8 | int n; cin >> n; 9 | // ищем максимальный делитель числа n 10 | // достаточно пробежать до корня из n 11 | // если число делится на x, то делится и на n / x 12 | // обновляем ответ за счёт n / x 13 | int answ = 1; 14 | for (int x = 2; x * x <= n; x++) 15 | if (n % x == 0) 16 | answ = max(answ, n / x); 17 | cout << answ << endl; 18 | } 19 | } -------------------------------------------------------------------------------- /mirea/contests/2023-09-24-MIREA-Welcome-Contest-2023/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | using ll = long long; 4 | // ответы для одной грани: 5 | // 3, 9, 18, 30 6 | // 3 + 6 + 9 + 12 + ... 7 | // 3 * (1 + 2 + ... n) 8 | ll s(ll n) { 9 | // функция считает число спичек на одной грани 10 | return 3 * n * (n + 1) / 2; 11 | } 12 | int main() { 13 | ios::sync_with_stdio(false); 14 | cin.tie(0); 15 | int tt; cin >> tt; 16 | while (tt --> 0) { 17 | ll n; cin >> n; 18 | // 4 грани вычесть шесть рёбер, посчитанных дважды 19 | cout << 4 * s(n) - 6 * n << endl; 20 | } 21 | } -------------------------------------------------------------------------------- /mirea/contests/2023-09-24-MIREA-Welcome-Contest-2023/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool isPrime(int n) { 4 | // проверка на простоту 5 | for (int x = 2; x * x <= n; x++) 6 | if (n % x == 0) 7 | return false; // важно делать break здесь 8 | return (n > 1); 9 | } 10 | int main() { 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | int tt; cin >> tt; 14 | while (tt --> 0) { 15 | int n; cin >> n; 16 | int a = n, b = n; 17 | // ищем ближайшее простое число сверху и снизу в цикле while 18 | while (!isPrime(b)) b++; 19 | while (!isPrime(a)) a--; 20 | cout << a << ' ' << b << endl; 21 | } 22 | } -------------------------------------------------------------------------------- /mirea/contests/2023-09-24-MIREA-Welcome-Contest-2023/I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | cout << fixed << setprecision(9); 7 | int tt; cin >> tt; 8 | while (tt --> 0) { 9 | int t1, t2; double R; 10 | cin >> t1 >> t2 >> R; 11 | // расстояние линейно зависит от радиуса 12 | // dist(R) = R * dist(1) 13 | // копируем-вставляем dist(1) из первого примера, получаем ответ 14 | cout << (t2 - t1) * R * 6.362265131567 << endl; 15 | } 16 | } -------------------------------------------------------------------------------- /mirea/contests/2024-09-22-MIREA-Welcome-Contest-2024/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void solve() { 4 | int n, s, k; 5 | cin >> n >> s >> k; 6 | // сразу переходим в 0-индексацию 7 | k--; 8 | // теперь находим период 9 | long long t = n / gcd(n, s); 10 | // целую часть и остаток 11 | long long q = k / t; 12 | long long r = k % t; 13 | // выводим ответ 14 | int answ = (int)((q + r * s) % n); 15 | cout << answ << "\n"; 16 | } 17 | main() { 18 | ios::sync_with_stdio(false); 19 | cin.tie(0); 20 | int tt; cin >> tt; 21 | while (tt --> 0) 22 | solve(); 23 | } 24 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023-2024/479446/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // нам нужно пройти слева направо, суммируя все значения "a", и узнать 5 | // величину максимального "проседания" по мане (минимальный баланс) 6 | // надо иметь на старте столько маны, чтобы этот минимум не увёл в 7 | // отрицательную зону 8 | int n; cin >> n; 9 | int64_t balance = 0, minBalance = 0; 10 | for (int i = 0, a; i < n; i++) { 11 | cin >> a; 12 | balance += a; 13 | if (balance < minBalance) 14 | minBalance = balance; 15 | } 16 | cout << -minBalance << endl; 17 | } 18 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023-2024/479446/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | // нужно знать лишь текущее время, когда человек освободится, посмотрев все 7 | // накопленные видео. Если оно меньше времени, когда приходит новое видео, то 8 | // мы вынуждены ждать, иначе добавляем длину нового видео к этому времени 9 | int n; cin >> n; 10 | int64_t currT = 0; 11 | for (int i = 0; i < n; i++) { 12 | int t, d; 13 | cin >> t >> d; 14 | if (t >= currT) 15 | currT = t; 16 | currT += d; 17 | } 18 | cout << currT << endl; 19 | } 20 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023-2024/483592/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | // надо удалить ближайший символ, который меньше своего соседа справа 7 | // если такого нет, то удалить последний символ в строке 8 | string s; cin >> s; 9 | int pos = 0; 10 | while (pos + 1 < (int)s.size() && s[pos] >= s[pos+1]) 11 | pos++; 12 | s.erase(pos, 1); 13 | cout << s << endl; 14 | } 15 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023-2024/483592/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | // в данном случае квадрат в круге это четыре равных прямоугольных треугольника 7 | // с катетами, равными r, поэтому площадь равна 4 * (0.5*r^2) 8 | long double r; cin >> r; 9 | cout << fixed << setprecision(12); 10 | cout << 2 * r * r << endl; 11 | } 12 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023-2024/constructives/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | main() { 4 | // в качестве "a" можно взять "g", а остаток суммы взять в качестве "b" 5 | int s, g; cin >> s >> g; 6 | int a = g, b = s - g; 7 | if (a > 0 && b > 0 && gcd(a,b) == g) 8 | cout << a << " " << b << "\n"; 9 | else 10 | cout << "-1\n"; 11 | } 12 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023-2024/constructives/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | main() { 4 | // стреляем по нечётным клеткам до n не включительно 5 | // затем добиваем, стреляя в самую последнюю клетку 6 | int n; cin >> n; 7 | vector a; 8 | for (int low = 1; low < n; low += 2) 9 | a.push_back(low); 10 | a.push_back(n); 11 | cout << a.size() << '\n'; 12 | for (auto it : a) 13 | cout << it << ' '; 14 | } 15 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023-2024/constructives/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define all(x) (x).begin(),(x).end() 3 | using namespace std; 4 | main() { 5 | int n; cin >> n; 6 | vector a(n); 7 | for (auto &it : a) 8 | cin >> it; 9 | // делим все числа на 2 пока делятся 10 | // ответ равен количеству различных чисел которые после этого остались 11 | for (auto &it : a) 12 | while (it % 2 == 0) 13 | it /= 2; 14 | sort(all(a)); 15 | cout << unique(all(a)) - a.begin() << endl; 16 | } 17 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023-2024/constructives/Условия-задач.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/cources/beginner/2023-2024/constructives/Условия-задач.pdf -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/combinatorics-level-2/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | // читаем данные и считаем сколько книг каждого типа: 7 | int n, m; cin >> n >> m; 8 | vector cnt(1+m); 9 | for (int i = 0, a; i < n; i++) { 10 | cin >> a; 11 | cnt[a]++; 12 | } 13 | // считаем ответ. pref - сумма кол-ва книг каждого типа на префиксе 14 | // к ответу добавляется cnt[j] * (cnt[j-1] + cnt[j-2] + ... + cnt[1]); 15 | int answ{}, pref{}; 16 | for (int i = 1; i <= m; i++) { 17 | answ += pref * cnt[i]; 18 | pref += cnt[i]; 19 | } 20 | cout << answ << endl; 21 | } 22 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/combinatorics-level-2/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | string s; cin >> s; 7 | int64_t answ{}; 8 | // две последние цифры должны делиться на 4 9 | for (int i = 0; i + 1 < (int)s.size(); i++) 10 | if (stoi(s.substr(i, 2)) % 4 == 0) 11 | answ += (i + 1); 12 | // либо это подстрока длины 1, которая сама делится на 4: 13 | for (int i = 0; i < (int)s.size(); i++) 14 | if ((s[i] - '0') % 4 == 0) 15 | answ++; 16 | cout << answ << '\n'; 17 | } 18 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/divisors-level-2/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int nTests; 5 | cin >> nTests; 6 | while (nTests--) { 7 | // читаем n: 8 | int64_t n; 9 | cin >> n; 10 | // находим минимальный простой делитель 11 | int64_t x = 2, p, q; 12 | while (x * x * x <= n && n % x != 0) x++; 13 | // мы нашли либо p, либо q, в любом случае поделим на него 14 | n /= x; 15 | if (n % x == 0) // делится на x ещё раз => значит x = p 16 | p = x, q = n / x; 17 | else // иначе x = q 18 | q = x, p = (int)sqrtl(n); 19 | // выводим ответ: 20 | cout << p << ' ' << q << '\n'; 21 | } 22 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/divisors-level-2/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n; cin >> n; 5 | // преобразуем уравнение, добавив слева и справа 1: 6 | // xy+x+y=n => xy+x+y+1=n+1 => (x+1)(y+1) = n+1 7 | // выходит, что количество решений столько, сколько делителей у n+1 8 | n++; 9 | int nDivisors = 0; 10 | for (int x = 1; x * x <= n; x++) 11 | if (int y = n / x; x * y == n) 12 | nDivisors += ((x == y) ? 1 : 2); 13 | // выводим ответ: 14 | cout << nDivisors << '\n'; 15 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/formulas-level-1/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n, k; 5 | cin >> n >> k; 6 | cout << ((n+k)/k*k) << endl; 7 | 8 | // целочисленное деление с округлением вверх: 9 | // f(a,b) = (a+b-1)/b 10 | // т.к. нам нужно строго большее по условию, то 1 вычитать не будем, 11 | // т.е. вместо a надо подставить a+1 12 | // не рекомендуется решать в double и использовать ceil, 13 | // если можно решать в целых числах 14 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/formulas-level-1/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // пусть дипломов = x 5 | // тогда грамот = k * x (по условию) 6 | // суммарно не больше половины, то есть: 7 | // x + k * x <= n / 2 ==> 2*(k+1)*x <= n (неравенство 1) 8 | // в задаче надо вывести x, k*x, и (n-(k+1)*x) 9 | int64_t n, k; 10 | cin >> n >> k; 11 | // выражаем x из неравенства (1): 12 | // 2*(k+1)*x <= n ==> x <= (n / (2*(k+1))) 13 | int64_t x = n / ((2*(k+1))); 14 | std::cout << x << ' ' << k * x << ' ' << (n-(k+1)*x) << endl; 15 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/formulas-level-1/D_cycle_while.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int64_t n; cin >> n; 5 | // блоки: 6 | // 1 7 | // 1 2 8 | // 1 2 3 9 | // 1 2 3 4 10 | // 1 ... k 11 | // 1 ... k k+1 12 | // найдём макс k такое, что n лежит внутри его блока 13 | // в каждом i-м блоке ровно i чисел 14 | // получается 1 + 2 + 3 + ... + k >= n 15 | // k * (k+1) / 2 >= n 16 | int64_t k = 1; 17 | while (k < n) { 18 | // n лежит за пределами этого блока 19 | n -= k; 20 | k++; 21 | } 22 | cout << n << endl; 23 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/geometry-level-2/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | int n; cin >> n; 7 | vector x(n), y(n); 8 | for (int i = 0; i < n; i++) 9 | cin >> x[i] >> y[i]; 10 | auto answ = 0LL; 11 | for (int i = 1; i < n; i++) 12 | // прибавляем полусумму оснований на высоту, но сразу удваиваем 13 | // не забываем приводить к типу лонг лонг 14 | answ += (x[i] - x[i-1] + 0LL) * (y[i] + y[i-1]); 15 | cout << answ << endl; 16 | } 17 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/geometry-level-2/B - Picture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/cources/beginner/2023/geometry-level-2/B - Picture.png -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/geometry-level-2/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | using ld = long double; 4 | int main() { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0); 7 | // читаем данные 8 | ld x1, y1, x2, y2; 9 | cin >> x1 >> y1 >> x2 >> y2; 10 | // выводим ответ (см. чертёж) 11 | cout << fixed << setprecision(12); 12 | cout << x1 + (x2 - x1) / (1 + y2 / y1) << endl; 13 | } 14 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/geometry-level-2/D - atan2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | template int sign(T t) { return t < 0 ? -1 : t > 0 ? +1 : 0; } 3 | using ld = long double; 4 | int main() { 5 | int t; scanf("%d", &t); 6 | while (t--) { 7 | int x1, y1, x2, y2; 8 | scanf("%d %d %d %d", &x1, &y1, &x2, &y2); 9 | printf("%d\n", sign(std::atan2(ld(y1), ld(x1)) - std::atan2(ld(y2), ld(x2)))); 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/geometry-level-2/D - complex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | template int sign(T t) { return t < 0 ? -1 : t > 0 ? +1 : 0; } 3 | using complex = std::complex; 4 | int main() { 5 | int t; scanf("%d", &t); 6 | while (t--) { 7 | int x1, y1, x2, y2; 8 | scanf("%d %d %d %d", &x1, &y1, &x2, &y2); 9 | // результат сравнения это разница между аргументами (полярными углами) 10 | // двух комплексных чисел: 11 | printf("%d\n", sign(std::arg(complex(x1,y1)) - std::arg(complex(x2,y2)))); 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/geometry-level-2/G - Picture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/cources/beginner/2023/geometry-level-2/G - Picture.png -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/implementation-level-1/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n,b,p; 4 | std::cin >> n >> b >> p; 5 | // каждый матч даёт 2*b+1 бутылок (b каждому участнику и 1 судье) 6 | // число полотенец n*p - константа 7 | int bottles{}, towels = n * p; 8 | while (n > 1) { 9 | int power = std::__lg(n); 10 | int participants = (1 << power); 11 | int numFights = participants / 2; 12 | bottles += numFights * (2 * b + 1); 13 | n = (n - participants) + numFights; 14 | } 15 | std::cout << bottles << ' ' << towels << '\n'; 16 | } 17 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/implementation-level-1/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n, k; cin >> n >> k; 5 | // храним номера живых людей в векторе 6 | vector players; 7 | for (int i = 1; i <= n; i++) 8 | players.push_back(i); 9 | int pos = 0; // позиция ведущего 10 | while (k --> 0) { 11 | // читаем сколько надо отсчитать 12 | int step; cin >> step; 13 | // отсчитываем от текущей позиции 14 | (pos += step) %= (int)players.size(); 15 | // выводим выбывшего 16 | cout << players[pos] << ' '; 17 | // удаляем его из вектора 18 | players.erase(players.begin()+pos); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/implementation-level-1/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool isLeapYear(int y) { 4 | // високосный год или нет 5 | return y % 400 == 0 || (y % 4 == 0 && y % 100 != 0); 6 | } 7 | int daysInYear(int y) { 8 | return 365 + isLeapYear(y); 9 | } 10 | int main() { 11 | int y; cin >> y; 12 | // надо найти первый год, до первого дня которого прошло 13 | // кратное 7 число дней, а високосность бы совпала с данным годом 14 | int days = daysInYear(y); 15 | int answer = y + 1; 16 | while (!(isLeapYear(answer) == isLeapYear(y) && days % 7 == 0)) { 17 | days += daysInYear(answer); 18 | answer++; 19 | } 20 | cout << answer << '\n'; 21 | } 22 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/implementation-of-some-operations/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | std::vector digit_count = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; 4 | int a, b; std::cin >> a >> b; 5 | int sum = 0; 6 | for (int i = a; i <= b; ++i) 7 | for (int temp = i; temp > 0; temp /= 10) 8 | sum += digit_count[temp % 10]; 9 | std::cout << sum << std::endl; 10 | return 0; 11 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/implementation-of-some-operations/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | std::ios_base::sync_with_stdio(false); 8 | std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); 9 | int n; std::cin >> n; 10 | std::vector pos(n); 11 | for (int i = 0; i < n; ++i) { 12 | int value; std::cin >> value; --value; 13 | pos[value] = i; 14 | } 15 | int64_t sum = 0; 16 | for (int i = 1; i < n; ++i) 17 | sum += std::abs(pos[i] - pos[i-1]); 18 | std::cout << sum << std::endl; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/implementation-of-some-operations/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | int nQ; std::string s; 7 | std::cin >> s >> nQ; 8 | while (nQ--) { 9 | int l, r, k; 10 | std::cin >> l >> r >> k; 11 | --l, --r; 12 | k %= (r-l+1); 13 | std::rotate(s.begin()+l, s.begin()+r+1-k, s.begin()+r+1); 14 | } 15 | std::cout << s; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/linear-algorithms-level-1/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | string a, b; 5 | cin >> a >> b; 6 | // дополняем лидирующими нулями 7 | auto maxSize = max(a.size(),b.size()); 8 | a.insert(0, string(maxSize-a.size(),'0')); 9 | b.insert(0, string(maxSize-b.size(),'0')); 10 | // сравниваем строки: 11 | int result = a.compare(b); // вернёт целое число 12 | if (result < 0) cout << "<" << endl; 13 | else if (result > 0) cout << ">" << endl; 14 | else cout << "=" << endl; 15 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/linear-algorithms-level-1/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // нам надо знать только сумму чисел и n, чтобы сказать, 5 | // сколько пуговиц реально застёгнуто 6 | int n, sum{}; 7 | cin >> n; 8 | for (int i = 0, a; i < n; i++) { 9 | cin >> a; 10 | sum += a; 11 | } 12 | bool yes = (n == 1 && sum == 1) || (n > 1 && sum == n-1); 13 | cout << (yes ? "YES\n" : "NO\n"); 14 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/linear-algorithms-level-1/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n; cin >> n; 5 | vector a(n); 6 | for (auto &it : a) 7 | cin >> it; 8 | // добавим элемент, который обломит возрастание в конце: 9 | a.push_back(0); 10 | n++; 11 | // теперь будем искать ответ 12 | int answ{1}, currLen{1}; 13 | for (int i = 1; i < n; i++) { 14 | if (a[i-1] < a[i]) { 15 | currLen++; 16 | } else { 17 | answ = max(answ, currLen); 18 | currLen = 1; 19 | } 20 | } 21 | cout << answ << endl; 22 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/linear-algorithms-level-1/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n; cin >> n; 5 | vector a(n); 6 | for (auto &it : a) 7 | cin >> it; 8 | // после сортировки надо посчитать минимум среди разностей 9 | // соседних элементов вектора и его количество 10 | sort(a.begin(), a.end()); 11 | int min = (a[1] - a[0]), cnt = 1; 12 | for (int i = 2; i < n; i++) { 13 | int diff = (a[i] - a[i-1]); 14 | if (diff < min) min = diff, cnt = 1; 15 | else if (diff == min) cnt++; 16 | } 17 | cout << min << ' ' << cnt << '\n'; 18 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/modular-math-level-2/A.py: -------------------------------------------------------------------------------- 1 | mod=10**9+7; 2 | a,b = map(int, input().split()) 3 | print((a+b)%mod) -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/modular-math-level-2/B.py: -------------------------------------------------------------------------------- 1 | mod=10**9+7; 2 | a,b = map(int, input().split()) 3 | print((a-b+mod)%mod) -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/modular-math-level-2/C.py: -------------------------------------------------------------------------------- 1 | mod=10**9+7; 2 | a,b = map(int, input().split()) 3 | print((a*b)%mod) -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/modular-math-level-2/D.py: -------------------------------------------------------------------------------- 1 | mod=10**9+7; 2 | a,n = map(int, input().split()) 3 | # в питоне можно возвести в степень n по модулю mod (модуль - третий параметр функции pow) 4 | # pow с третьим параметром берём остаток при каждом умножении. 5 | # То есть длинная арифметика не используется 6 | print(pow(a,n,mod)); -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/modular-math-level-2/E.py: -------------------------------------------------------------------------------- 1 | mod=10**9+7; 2 | a,b = map(int, input().split()) 3 | # в питоне можно возвести в -1 степень по модулю mod (третий параметр функции pow) 4 | # pow с третьим параметром берём остаток при каждом умножении. 5 | # То есть длинная арифметика не используется 6 | print(a*pow(b,-1,mod)%mod) -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/modular-math-level-2/F.py: -------------------------------------------------------------------------------- 1 | mod=10**9+7; 2 | a = int(input()) 3 | print(((a % mod) + mod) % mod) -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/modular-math-level-2/G.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Задача: сумма последовательности по модулю 3 | */ 4 | #include 5 | using namespace std; 6 | const int mod = (int)1e9+7; 7 | int main() { 8 | // ускоряем ввод-вывод (обязательно): 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | // решаем задачу: 12 | int n; cin >> n; 13 | int res{}; 14 | while (n --> 0) { 15 | int64_t a; cin >> a; 16 | res = (res + a % mod + mod) % mod; 17 | } 18 | cout << res << '\n'; 19 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/modular-math-level-2/H.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Задача: произведение последовательности по модулю 3 | */ 4 | #include 5 | using namespace std; 6 | const int mod = (int)1e9+7; 7 | int main() { 8 | // ускоряем ввод-вывод (обязательно): 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | // решаем задачу: 12 | int n; cin >> n; 13 | int res{1}; 14 | while (n --> 0) { 15 | int64_t a; cin >> a; 16 | int rem = (a % mod + mod) % mod; 17 | res = (res * 1LL * rem % mod); 18 | } 19 | cout << res << '\n'; 20 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/rofl-level-2/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define all(x) (x).begin(),(x).end() 3 | using namespace std; 4 | int32_t main() { 5 | // копируем увидительные числа из первого примера: 6 | set a{1342176,364722,6,9,18,30,56,99,7710,27594,52377,99858,190557}; 7 | a.insert({1,2,3,186,335,630,1161,2182,4080,14532,698870,2580795,4971008}); 8 | // читаем числа из ввода и выкидываем их из множества: 9 | int n; cin >> n; 10 | while (n --> 0) { 11 | int x; cin >> x; 12 | a.erase(x); 13 | } 14 | // выводим ответ: 15 | cout << a.size() << '\n'; 16 | for (auto &x : a) 17 | cout << x << ' '; 18 | } 19 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/rofl-level-2/B - random.cpp: -------------------------------------------------------------------------------- 1 | // попытка 2 2 | #include 3 | using namespace std; 4 | // Будем выводить рандомное число. Вероятность проиграть (попасть в единственный 5 | // магазин, в котором мы не сможем купить всё необходимое), потратив все деньги, 6 | // равна 1/29. Надо быть очень невезучим, чтобы не сдать задачу 7 | // в качестве ядра генератора случайных чисел можно использовать 8 | // текущее время в наносекундах 9 | mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count()); 10 | uniform_int_distribution dist(1, 29); 11 | int main() { 12 | int n, x; cin >> n >> x; 13 | cout << x << ' ' << dist(gen) << endl; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/rofl-level-2/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // Будем выводить рандомное число. Вероятность проиграть (попасть в единственный 4 | // магазин, в котором мы не сможем купить всё необходимое), потратив все деньги, 5 | // равна 1/29. Надо быть очень невезучим, чтобы не сдать задачу 6 | // в качестве ядра генератора случайных чисел можно использовать 7 | // текущую время и дату: 15:00 09.07.2023 = 150009072023 8 | mt19937 gen(150009072023); 9 | uniform_int_distribution dist(1, 29); 10 | int main() { 11 | int n, x; cin >> n >> x; 12 | cout << x << ' ' << dist(gen) << endl; 13 | return 0; 14 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/rofl-level-2/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | using ld = long double; 4 | int main() { 5 | // ответ: t-й член геометрической прогрессии a(t) = x * q^t 6 | // по тестам из условия найдём x и q 7 | // также используем тот факт, что ответ - целое число (тоже из условия задачи) 8 | ld q = cbrtl(352947/1029); // q = кубический корень(a(6)/a(3)) 9 | ld x = 1029/powl(q,3); // x = a(3) / q^3 10 | // отвечаем на запросы: 11 | int tt; cin >> tt; 12 | while (tt --> 0) { 13 | int t; cin >> t; 14 | cout << (int64_t)(x * powl(q, t)) << '\n'; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/rofl-level-2/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // ответ: младший единичный бит числа, или -1, если число равно 0 5 | // функция ffs (Find First Signed) находит младший единичный бит 6 | int tt; cin >> tt; 7 | while (tt --> 0) { 8 | int x; cin >> x; 9 | int res = __builtin_ffs(x); 10 | cout << res-1 << '\n'; 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/rofl-level-2/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | using ld = long double; 4 | int main() 5 | { 6 | // зависимость ответа от расстояния: квадратическая 7 | // то есть, f(r) = C * r^2 8 | // в тесте из условия дано f(1) --> находим C = 0.916297857297023 9 | // теперь можем решить задачу: 10 | ld x1, y1, x2, y2; 11 | cin >> x1 >> y1 >> x2 >> y2; 12 | ld r = hypotl(abs(x1-x2),abs(y1-y2)); 13 | cout << fixed << setprecision(12); 14 | cout << r * r * 0.916297857297023 << '\n'; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/rofl-level-2/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // Андрей выигрывает, только если n = 1, 2 или 9 5 | // У Стёпы слишком крутые простые числа 6 | // вот такой вот рофл 7 | int tt; cin >> tt; 8 | while (tt --> 0) { 9 | int n; cin >> n; 10 | cout << (n <= 1 || n == 9 ? "Andrey\n" : "Stepan\n"); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/sortings-and-grouping-level-2/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // читаем данные: 5 | int n, m; cin >> n >> m; 6 | vector a(n); 7 | for (auto &it : a) 8 | cin >> it; 9 | // отсортировать по убыванию (более точно по невозрастанию): 10 | sort(a.begin(), a.end(), greater<>()); 11 | // взять максимумы пока не перевалим за m: 12 | for (int i = 0; i < n; i++) { 13 | // берём текущую флешку 14 | m -= a[i]; 15 | // проверяем, набрали ли необходимый объём 16 | if (m <= 0) { 17 | cout << i+1 << '\n'; // выводим ответ 18 | break; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/steps-on-a-plane-level-1/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // читаем координаты начала и конца: 5 | int x1, y1, x2, y2; 6 | cin >> x1 >> y1 >> x2 >> y2; 7 | // считаем сколько шагов должны сделать в каждом направлении 8 | const int dx = abs(x1-x2); 9 | const int dy = abs(y1-y2); 10 | // пока можем - шагаем по диагонали, затем ходим лишь в направлении осей 11 | // получаем, что min(dx, dy) шагов по диагонали 12 | // затем max(dx, dy) - min(dx, dy) в направлении одной оси 13 | // суммарно max(dx, dy) 14 | cout << max(dx, dy); 15 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/strings-level-1/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n; cin >> n; 5 | string s; cin >> s; 6 | // фактически, нужно разбить строку на подстроки, используя 7 | // '0' как разделитель, то есть сделать split по символу '0' 8 | // В C++ нет split, придётся самим 9 | s += '0'; // добавим '0' в конец так, чтобы после каждого блока шёл 0 10 | int currBlockLen = 0; 11 | for (int i = 0; i <= n; i++) { 12 | if (s[i] == '0') { 13 | cout << currBlockLen; 14 | currBlockLen = 0; 15 | } else { 16 | currBlockLen++; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/time-and-segments-level-1/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // для работы с временем (чтение и вывод) удобнее всего 5 | // использовать scanf и printf, поддерживающие регулярные выражения 6 | int h, m, a; 7 | scanf("%d:%d %d", &h, &m, &a); 8 | const int currTime = h * 60 + m; 9 | const int nextTime = currTime + a; 10 | m = nextTime % 60; 11 | h = nextTime / 60 % 24; 12 | // выводим время с лидирующими нулями и ровно 2 символа: 13 | printf("%02d:%02d", h, m); 14 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/time-and-segments-level-1/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // читаем границы отрезка: 5 | int L1, R1, L2, R2; 6 | cin >> L1 >> R1 >> L2 >> R2; 7 | // находим границы пересечения двух отрезков: 8 | const int L = max(L1, L2); 9 | const int R = min(R1, R2); 10 | // проверяет длину отрезка на положительность: 11 | if (L >= R) cout << "-1"; 12 | else cout << L << ' ' << R; 13 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2023/time-and-segments-level-1/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // чтение данных: 5 | int n, t; cin >> n >> t; 6 | vector a(n); 7 | for (auto &it : a) 8 | cin >> it; 9 | // решение задачи 10 | for (int i = 0; i < n; i++) { 11 | // сколько можем потратить времени на чтение в эти сутки: 12 | const int delta = min(t, 86400 - a[i]); 13 | t -= delta; 14 | // если прочитали полностью, то выводим ответ: 15 | if (t == 0) { 16 | cout << (i+1); // в 1-индексации 17 | return 0; 18 | } 19 | } 20 | assert(false); 21 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/2024/2024-02-25/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void solve() { 4 | // посчитаем количество каждого числа и найдём то, которое встречается 5 | // 3 или более раз 6 | int n; cin >> n; 7 | map count; 8 | int answer = -1; 9 | while (n --> 0) { 10 | int number; cin >> number; 11 | count[number]++; 12 | if (count[number] >= 3) 13 | answer = number; 14 | } 15 | cout << answer << "\n"; 16 | } 17 | main() { 18 | // ускорение ввода-вывода 19 | ios::sync_with_stdio(false); 20 | cin.tie(0); 21 | // мультитесты 22 | int tt; cin >> tt; 23 | while (tt --> 0) 24 | solve(); 25 | } 26 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2024/2024-03-17/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void solve() { 4 | // строки = в красный 5 | // столбцы = в синий 6 | // надо проверить, есть ли строка, состоящая целиком из букв R 7 | // или есть ли столбец, состоящий целиком из букв B 8 | // чтение поля: 9 | int n = 8; 10 | vector a(n); 11 | for (auto &it : a) 12 | cin >> it; 13 | bool lastWasRed = false; 14 | for (const auto &it : a) 15 | // хотя бы одна строка целиком равна n буквам R 16 | lastWasRed |= (it == string(n, 'R')); 17 | cout << (lastWasRed ? 'R' : 'B') << "\n"; 18 | } 19 | int main() { 20 | int tt; cin >> tt; 21 | while (tt --> 0) solve(); 22 | } 23 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2024/2024-03-24/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define all(x) (x).begin(),(x).end() 3 | using namespace std; 4 | void solve() { 5 | // ответ: кол-во различных букв + n 6 | int n; cin >> n; 7 | string s; cin >> s; 8 | sort(all(s)); 9 | s.erase(unique(all(s)), s.end()); 10 | cout << s.size() + n << "\n"; 11 | } 12 | int main() { 13 | int tt; cin >> tt; 14 | while (tt --> 0) solve(); 15 | } 16 | -------------------------------------------------------------------------------- /mirea/cources/beginner/2024/2024-03-31/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define all(x) (x).begin(),(x).end() 3 | using namespace std; 4 | void solve() { 5 | // читаем строку: 6 | int n; cin >> n; 7 | string s; cin >> s; 8 | // ищем максимальный символ: 9 | int maxChar = 'a'; 10 | for (auto it : s) 11 | if (maxChar < it) 12 | maxChar = it; 13 | // выводим его номер в алфавите: 14 | cout << (maxChar - 'a' + 1) << "\n"; 15 | } 16 | int main() { 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | int t; cin >> t; 20 | while (t --> 0) 21 | solve(); 22 | } 23 | -------------------------------------------------------------------------------- /mirea/cources/beginner/binary-search/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl '\n' 3 | using namespace std; 4 | // low = 1'999'999'998 5 | // high = 2'000'000'000 6 | // (low+high) > 2^31-1 7 | main() { 8 | cin.tie(nullptr); 9 | int n; cin >> n; 10 | int low = 1, high = n+1; 11 | while (high - low > 1) { 12 | int mid = (low + high) / 2; // low + (high - low) / 2 = (2*low+high-low)/2 13 | cout << mid << endl; 14 | cout.flush(); 15 | string s; cin >> s; 16 | if (s == ">=") low = mid; 17 | else high = mid; 18 | } 19 | cout << "! " << low << endl; 20 | } 21 | -------------------------------------------------------------------------------- /mirea/cources/beginner/binary-search/B-own-binary-search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | int n, m; cin >> n >> m; 7 | // читаем вектор и сортируем его: 8 | vector a(n); 9 | for (auto &it : a) 10 | cin >> it; 11 | sort(a.begin(), a.end()); 12 | // читаем запросы и отвечаем на них 13 | for (int j = 0, bj; j < m; j++) { 14 | cin >> bj; 15 | int low = -1, high = n; 16 | while (high - low > 1) { 17 | int mid = (low + high) / 2; 18 | if (a[mid] <= bj) low = mid; 19 | else high = mid; 20 | } 21 | cout << high << " "; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mirea/cources/beginner/binary-search/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | main() { 4 | int n, m; cin >> n >> m; 5 | vector a(n), b(m); 6 | for (auto &it : a) cin >> it; 7 | for (auto &it : b) cin >> it; 8 | sort(b.begin(), b.end()); 9 | int answer = 0; 10 | for (int ai : a) { 11 | int minR = INT_MAX; 12 | // ближайшую вышку справа: 13 | auto iter = lower_bound(b.begin(), b.end(), ai); 14 | if (iter != b.end()) minR = min(minR, *iter - ai); 15 | // ближайшую слева: 16 | if (iter != b.begin()) minR = min(minR, ai - *(--iter)); 17 | // обновляем ответ: 18 | answer = max(answer, minR); 19 | } 20 | cout << answer << endl; 21 | } 22 | -------------------------------------------------------------------------------- /mirea/cources/beginner/bitset-lecture/example-1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define watch(x) cout << #x << " = " << (x) << endl 6 | 7 | int main() 8 | { 9 | setlocale(LC_ALL, "Ru-ru"); 10 | bitset<15> a; 11 | cin >> a; 12 | 13 | watch(a); 14 | 15 | cout << "меняет всё на противоположный:" << endl; 16 | a.flip(); 17 | watch(a); 18 | 19 | cout << "ставит всё в 1" << endl; 20 | a.set(); 21 | watch(a); 22 | 23 | cout << "ставит всё в 0" << endl; 24 | a.reset(); 25 | watch(a); 26 | 27 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/bitset-lecture/example-11.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC optimize("Ofast") 2 | #pragma GCC target("avx,avx2,fma") 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | #define watch(x) cout << (x) << " <-- " << #x << endl 9 | 10 | int main() 11 | { 12 | const int s = (int)1e6; 13 | int k; cin >> k; 14 | bitset a(1); 15 | for (int i = 0; i < k; i++) { 16 | int w; cin >> w; 17 | a |= (a << w); 18 | } 19 | 20 | cout << a.count() << endl; 21 | 22 | int i = a._Find_first(); 23 | while (i < a.size()) { 24 | cout << i << ' '; 25 | i = a._Find_next(i); 26 | } 27 | cout << endl; 28 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/bitset-lecture/example-2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #define watch(x) cout << #x << " = " << (x) << endl 6 | 7 | int main() 8 | { 9 | setlocale(LC_ALL, "Ru-ru"); 10 | bitset<15> a; 11 | cin >> a; 12 | 13 | watch(a); 14 | 15 | cout << "меняет на противоположный:" << endl; 16 | watch(a.flip(3)); 17 | 18 | cout << "ставит в 1" << endl; 19 | watch(a.set(5)); 20 | 21 | cout << "ставит в 0" << endl; 22 | 23 | watch(a.reset(6)); 24 | 25 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/bitset-lecture/example-7.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC optimize("Ofast") 2 | #pragma GCC target("avx,avx2,fma") 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | #define watch(x) cout << (x) << " <-- " << #x << endl 9 | 10 | int main() 11 | { 12 | const int n = (int)1e8; 13 | bitset a; 14 | a.set(); 15 | a.reset(0); 16 | a.reset(1); 17 | for (int x = 2; x * x < n; x++) 18 | if (a[x]) 19 | for (int y = x * x; y < n; y += x) 20 | a.reset(y); 21 | cout << a.count() << endl; 22 | 23 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/bitset-lecture/example-9.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC optimize("Ofast") 2 | #pragma GCC target("avx,avx2,fma") 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | #define watch(x) cout << (x) << " <-- " << #x << endl 9 | 10 | int main() 11 | { 12 | const int n = (int)100; 13 | bitset a; 14 | a.set(); 15 | a.reset(0); 16 | a.reset(1); 17 | for (int x = 2; x * x < n; x++) 18 | if (a[x]) 19 | for (int y = x * x; y < n; y += x) 20 | a.reset(y); 21 | 22 | cout << a.count() << endl; 23 | int i = a._Find_first(); 24 | while (i < a.size()) { 25 | cout << i << ' '; 26 | i = a._Find_next(i); 27 | } 28 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/contest-473112/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | using vi = vector; 4 | void remin(auto &x, const auto &y) { if (y < x) x = y; } 5 | int main() { 6 | // ускорение ввода-вывода 7 | ios::sync_with_stdio(false); 8 | cin.tie(0); 9 | // чтение данных 10 | int n; cin >> n; 11 | vi L(n); for (auto &it : L) cin >> it; 12 | // решение задачи 13 | int firstDead = n, answ{}; 14 | for (int i = n-1; i >= 0; i--) { 15 | answ += (i < firstDead); 16 | remin(firstDead, i - L[i]); 17 | } 18 | cout << answ << endl; 19 | } 20 | -------------------------------------------------------------------------------- /mirea/cources/beginner/contest-473112/D-linear-solution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n; cin >> n; 5 | string s; cin >> s; 6 | vector storage(2*n+1, -100); 7 | 8 | int *leftMost = &storage[n]; 9 | 10 | leftMost[0] = 0; 11 | int answ = 0, height = 0; 12 | for (int i = 0, x = 1; i < n; i++, x++) { 13 | height += (s[i] == '1' ? +1 : -1); 14 | if (leftMost[height] == -100) 15 | leftMost[height] = x; 16 | 17 | if (answ < x - leftMost[height]) 18 | answ = x - leftMost[height]; 19 | } 20 | cout << answ << endl; 21 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/contest-473112/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void remax(auto &x, const auto &y) { if (x < y) x = y; } 4 | int main() { 5 | // заменяем 0 на -1, а 1 на +1 6 | // тогда нужно найти отрезок, сумма на котором равна нулю 7 | int n; cin >> n; 8 | string s; std::cin >> s; 9 | map firstPos; 10 | firstPos[0] = -1; 11 | int balance = 0, answ = 0; 12 | for (int i = 0; i < n; i++) { 13 | balance += (s[i] == '1' ? +1 : -1); 14 | if (auto it = firstPos.find(balance); it == firstPos.end()) 15 | firstPos[balance] = i; 16 | remax(answ, i - firstPos[balance]); 17 | } 18 | cout << answ << endl; 19 | } 20 | -------------------------------------------------------------------------------- /mirea/cources/beginner/gready-constructive-easy-403329/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; std::cin >> n; 4 | std::vector a(n); 5 | for (int i = 0; i < n; i++) { 6 | std::cin >> a[i]; 7 | } 8 | // Рассматриваем тройки соседей слева-направо. 9 | // Нас интересуют тройки {1, 0, 1} 10 | // В них надо заменять самую правую единицу на ноль 11 | // Это оптимальный выбор в данной ситуации и в будущем 12 | int k = 0; 13 | for (int i = 1; i + 1 < n; i++) { 14 | if (a[i-1] == 1 && a[i] == 0 && a[i+1] == 1) { 15 | a[i+1] = 0; 16 | k++; 17 | } 18 | } 19 | std::cout << k << std::endl; 20 | } -------------------------------------------------------------------------------- /mirea/cources/beginner/set-map-lower_bound-403337/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | // читаем множество цитат 7 | string s; 8 | getline(cin, s); 9 | int n = stoi(s); 10 | set st; 11 | while(n--){ 12 | getline(cin,s); 13 | st.insert(s); 14 | } 15 | // читаем запросы и отвечаем на них: 16 | getline(cin, s); 17 | int q = stoi(s); 18 | while(q--){ 19 | getline(cin,s); 20 | cout<<(st.count(s)?"YES\n":"NO\n"); 21 | } 22 | } -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-1/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int answ = 1, n; 5 | cin >> n; 6 | // каждый новый разрез пересекает все другие разрезы и края окружности 7 | for (int i = 1; i <= n; ++i) 8 | answ += i; 9 | cout << answ << endl; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-1/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define all(x) (x).begin(),(x).end() 3 | using namespace std; 4 | const int inf = (int)1e9+7; 5 | int main() { 6 | int n; cin >> n; 7 | vector x(n); 8 | for (auto &it : x) 9 | cin >> it; 10 | sort(all(x)); 11 | vector dp(n, inf); 12 | for (int i = 1; i < n; i++) 13 | dp[i] = (x[i] - x[i-1]) + std::min(dp[i-1], (i-2>=0?dp[i-2]:0)); 14 | cout << dp.back() << endl; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-1/d-1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n, k; cin >> n >> k; 5 | // dp[N][2] = количество вариантов 6 | // dp[кол-во разрядов][нулевая цифра на конце или нет] 7 | vector dp(1+n, vector(2, 0)); 8 | dp[1][0] = 0; 9 | dp[1][1] = k-1; 10 | for (int cnt = 2; cnt <= n; cnt++) { 11 | // поставить нулевую цифру 12 | dp[cnt][0] = dp[cnt-1][1]; 13 | // поставить ненулевую цифру 14 | dp[cnt][1] = (k - 1) * (dp[cnt-1][0] + dp[cnt-1][1]); 15 | } 16 | cout << dp[n][0] + dp[n][1] << endl; 17 | } -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-1/e.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n; cin >> n; 5 | vector dp(1+n, 0); 6 | dp[0] = 1; 7 | for (int cnt = 1; cnt <= n; cnt++) { 8 | dp[cnt] += dp[cnt-1]; 9 | if (cnt >= 2) 10 | dp[cnt] += dp[cnt-2]; 11 | if (cnt >= 3) 12 | dp[cnt] += dp[cnt-3]; 13 | } 14 | cout << fixed << setprecision(0); 15 | cout << dp[n] << endl; 16 | } -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-1/f.py: -------------------------------------------------------------------------------- 1 | k, n = (int(x) for x in input().split()) 2 | a = [0]*(n+1); a[0] = 1 3 | for i in range(0, n): 4 | limit = min(n-i, k) 5 | for j in range(1, limit+1): 6 | a[i+j] += a[i] 7 | print(a[n]) -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-2/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | const int inf = (int)1e9+7; 4 | int main() { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0); 7 | int n; cin >> n; 8 | vector y(n); 9 | for (auto &item : y) 10 | cin >> item; 11 | vector dp(n); 12 | for (int i = 1; i < n; i++) 13 | dp[i] = min(abs(y[i] - y[i-1]) + dp[i-1], // прыгаем через 1 платфотму 14 | i-2>=0?(3*abs(y[i]-y[i-2])+dp[i-2]):inf);// через 2 платформы сразу 15 | cout << dp.back() << endl; 16 | } 17 | -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-2/b-1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n; cin >> n; 5 | vector a(n); 6 | for (auto &it : a) 7 | cin >> it; 8 | // находим ответ за квадрат, перебирая все варианты 9 | vector dp(n, 1); 10 | for (int i = 1; i < n; i++) 11 | for (int j = 0; j < i; j++) 12 | if (a[j] < a[i]) 13 | dp[i] = max(dp[i], dp[j] + 1); 14 | cout << *max_element(dp.begin(), dp.end()) << endl; 15 | } 16 | -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-2/b-2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | const int inf = (int)1e9+7; 4 | int main() { 5 | int n; cin >> n; 6 | // было: dp[конец] => максимальная длина 7 | vector dp(n+2, inf); // dp[длина] => минимальный конец 8 | dp[0] = -inf; 9 | for (int i = 0; i < n; i++) { 10 | int x; cin >> x; 11 | auto it = lower_bound(dp.begin(), dp.end(), x); 12 | *it = x; 13 | } 14 | int answ = 0; 15 | while (dp[answ+1] != inf) 16 | answ++; 17 | cout << answ << endl; 18 | } -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-2/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n; cin >> n; 5 | vector a(n, 0); for (auto &it : a) cin >> it; 6 | // инициализация динамики: 7 | vector dp(n, vector(n, 0)); 8 | for (int i = 0; i < n; i++) 9 | dp[i][i] = a[i]; 10 | // вычисление состояний динамики в порядке возрастания длины: 11 | for (int len = 2; len <= n; len++) 12 | for (int i = 0, j = len - 1; j < n; i++, j++) 13 | dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1]); 14 | // вывод ответа: 15 | cout << (dp[0][n-1] > 0 ? 1 : (dp[0][n-1] < 0 ? 2 : 0)); 16 | } 17 | -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-6/a.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | def f(n, a, b): 3 | if (n > 0): 4 | if ((a + b * 1) % 2 == 0): 5 | return f(n-1, (a + b * 1) // 2, b * 5) + "1" 6 | else: 7 | return f(n-1, (a + b * 2) // 2, b * 5) + "2" 8 | else: 9 | return "1" 10 | print(f(n,0,1)) -------------------------------------------------------------------------------- /mirea/cources/middle/acmp-dp/dp-6/c-formula.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | using ll = long long; 4 | int main() { 5 | vector answers = {0, 1, 1, 2, 4, 6, 9, 14}; 6 | vector diff(answers.size(), 0); 7 | for (int i = 1; i < (int)answers.size(); i++) 8 | diff[i] = answers[i] - answers[i-1]; 9 | 10 | int n; cin >> n; 11 | for (int i = (int)answers.size(); i <= n; i++) { 12 | ll nextDiff = diff[i-1] + diff[i-3]; 13 | diff.push_back(nextDiff); 14 | answers.push_back(answers.back() + nextDiff); 15 | } 16 | cout << answers[n] << endl; 17 | } 18 | -------------------------------------------------------------------------------- /mirea/cources/middle/blitz-1/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | // максимальное число простых это когда мы используем только двойки и тройки 7 | // а точнее, все двойки, и, возможно, одну тройку, если число нечётное 8 | int n; cin >> n; 9 | vector a; 10 | while (n >= 2) { // набираем двойки пока можем 11 | a.push_back(2); 12 | n -= 2; 13 | } 14 | if (n == 1) // заменяем последнюю двойку на тройку 15 | a.back() = 3; 16 | // выводим ответ: 17 | cout << a.size() << endl; 18 | for (auto it : a) 19 | cout << it << ' '; 20 | cout << endl; 21 | } 22 | -------------------------------------------------------------------------------- /mirea/cources/middle/combinatorics/level 1 - 402280/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int mod = (int)(1e9+7); // 1'000'000'000+7 5 | 6 | int binpow(int a, int64_t n) { 7 | if (n == 0) 8 | return 1; 9 | // n > 0 10 | if (a == 1) 11 | return 1; 12 | // a = a * 1LL * a; 13 | if (n % 2 == 0) // чёт 14 | return binpow(int(a * 1LL * a % mod), n / 2); 15 | return int(a * 1LL * binpow(a, n-1) % mod); 16 | } 17 | 18 | int main() { 19 | int a, n; 20 | cin >> a >> n; 21 | cout << binpow(a, n); 22 | } -------------------------------------------------------------------------------- /mirea/cources/middle/greedy-1/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define int int64_t 3 | using namespace std; 4 | main() { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0); 7 | // читаем + сортируем 8 | int n, k; 9 | cin >> n >> k; 10 | set a; 11 | for (int i = 0; i < n; i++) { 12 | int x; cin >> x; 13 | a.insert(x); 14 | } 15 | if (k == 1) { 16 | cout << a.size() << endl; 17 | return 0; 18 | } 19 | // теперь мы должны для каждого числа x вычеркнуть x * k 20 | for (auto x = a.begin(); x != a.end(); x++) 21 | if (auto y = a.find(*x * k); y != a.end()) 22 | a.erase(y); 23 | cout << a.size() << endl; 24 | } 25 | -------------------------------------------------------------------------------- /mirea/cources/middle/greedy-1/e.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | int n; cin >> n; 7 | vector a(n); 8 | for (auto &it : a) 9 | cin >> it; 10 | // компаратор: будем переставлять две подстроки, если это принесёт пользу 11 | // посортим строки по этому компаратору и выведем ответ 12 | sort(a.begin(), a.end(), [](const auto &fi, const auto &se) { 13 | return fi + se < se + fi; 14 | }); 15 | string res; 16 | for (auto &it : a) 17 | res += it; 18 | cout << res << endl; 19 | } 20 | -------------------------------------------------------------------------------- /mirea/cources/middle/multi-threading/helloworld.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() { 5 | const int nThreads = 16; 6 | std::vector threads; 7 | for (int id = 0; id < nThreads; id++) 8 | threads.emplace_back([threadId = id]() 9 | { 10 | std::cout << "Hello, world! #" << threadId << std::endl; 11 | }); 12 | for (auto &t : threads) 13 | if (t.joinable()) 14 | t.join(); 15 | std::cout << "All of the threads have been finished!" << std::endl; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /mirea/cources/middle/СПбГУ Динамика/i.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // инициализация рюкзака: 5 | const int SMAX = 10100; 6 | bitset dp; 7 | dp[0] = 1; 8 | // переходы: 9 | int s, n; cin >> s >> n; 10 | while (n --> 0) { 11 | int a; cin >> a; 12 | dp |= dp << a; 13 | } 14 | // нахождение ответа: 15 | int answ = 0; 16 | for (int i = 0; i <= s; i++) 17 | if (dp[i]) answ = i; 18 | cout << answ << endl; 19 | } -------------------------------------------------------------------------------- /mirea/cources/middle/СПбГУ Динамика/j.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | // Сопоставим буквам цифры: a = 0, b = 1, c = 2 5 | // запрещено: 01 6 | // инициализация dp: 7 | int n; cin >> n; 8 | vector dp(3, vector(1+n,0LL)); 9 | dp[2][0] = 1; 10 | // вычисление dp: 11 | for (int i = 1; i <= n; i++) { 12 | for (int prev = 0; prev < 3; prev++) { 13 | for (int curr = 0; curr < 3; curr++) { 14 | if (prev == 0 && curr == 1) continue; 15 | dp[curr][i] += dp[prev][i-1]; 16 | } 17 | } 18 | } 19 | cout << dp[0][n] + dp[1][n] + dp[2][n] << endl; 20 | } -------------------------------------------------------------------------------- /mirea/cources/mirea-training-contest-01/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | // чтение данных 7 | int n; cin >> n; 8 | vector a(n); 9 | for (auto &it : a) 10 | cin >> it; 11 | // сортируем 12 | sort(a.begin(), a.end()); 13 | // формируем скобки по 2 числа 14 | // объединяя максимумы с минимумами 15 | int64_t sum{}; 16 | for (int i = 0, j = n - 1; i < j; i++, j--) { 17 | int64_t s = a[i] + a[j]; 18 | sum += s * s; 19 | } 20 | cout << sum << endl; 21 | } 22 | -------------------------------------------------------------------------------- /mirea/cources/mirea-training-contest-01/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | cout << fixed << setprecision(12); 7 | int a, b; cin >> a >> b; 8 | if (atan2l(b, a) > atan2l(1, 1)) { 9 | cout << "-1\n"; 10 | return 0; 11 | } 12 | long double m = (a + b) / sqrtl(2); 13 | m /= sqrtl(2); 14 | // x = m / k >= b 15 | // k <= m / b 16 | int k = m / b; 17 | long double x = m / k; 18 | cout << x << endl; 19 | } 20 | -------------------------------------------------------------------------------- /mirea/gifts/geometry/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/geometry/example.png -------------------------------------------------------------------------------- /mirea/gifts/geometry/geoma-jacket-front.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/geometry/geoma-jacket-front.png -------------------------------------------------------------------------------- /mirea/gifts/geometry/jacket-back(2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/geometry/jacket-back(2).png -------------------------------------------------------------------------------- /mirea/gifts/geometry/jacket-back.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/geometry/jacket-back.psd -------------------------------------------------------------------------------- /mirea/gifts/geometry/jacket-front.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/geometry/jacket-front.psd -------------------------------------------------------------------------------- /mirea/gifts/geometry/kisspng-sacred-geometry-cube-geometric-shape-penrose-trian-5ce14568023222.353217011558267240009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/geometry/kisspng-sacred-geometry-cube-geometric-shape-penrose-trian-5ce14568023222.353217011558267240009.png -------------------------------------------------------------------------------- /mirea/gifts/geometry/png-clipart-geometry-triangle-animal-tiger-polygon-triangle-angle-leaf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/geometry/png-clipart-geometry-triangle-animal-tiger-polygon-triangle-angle-leaf.png -------------------------------------------------------------------------------- /mirea/gifts/just-mirea/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/just-mirea/example.png -------------------------------------------------------------------------------- /mirea/gifts/mirea-competitive-programming/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-competitive-programming/example.png -------------------------------------------------------------------------------- /mirea/gifts/mirea-competitive-programming/want-problems(4).psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-competitive-programming/want-problems(4).psd -------------------------------------------------------------------------------- /mirea/gifts/mirea-industries/201-2019912_stark-industries-logo-png.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-industries/201-2019912_stark-industries-logo-png.png -------------------------------------------------------------------------------- /mirea/gifts/mirea-industries/arc-reactor(1).psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-industries/arc-reactor(1).psd -------------------------------------------------------------------------------- /mirea/gifts/mirea-industries/back-2(1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-industries/back-2(1).png -------------------------------------------------------------------------------- /mirea/gifts/mirea-industries/front(1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-industries/front(1).png -------------------------------------------------------------------------------- /mirea/gifts/mirea-industries/mirea-t-shirt(1).psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-industries/mirea-t-shirt(1).psd -------------------------------------------------------------------------------- /mirea/gifts/mirea-industries/photo1699995862.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-industries/photo1699995862.jpeg -------------------------------------------------------------------------------- /mirea/gifts/mirea-logo/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-logo/example.png -------------------------------------------------------------------------------- /mirea/gifts/mirea-logo/mirea-black-tiny.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-logo/mirea-black-tiny.png -------------------------------------------------------------------------------- /mirea/gifts/mirea-logo/mirea-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-logo/mirea-black.png -------------------------------------------------------------------------------- /mirea/gifts/mirea-logo/mirea-white-big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-logo/mirea-white-big.png -------------------------------------------------------------------------------- /mirea/gifts/mirea-logo/want-problems(3).psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/mirea-logo/want-problems(3).psd -------------------------------------------------------------------------------- /mirea/gifts/summary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/summary.png -------------------------------------------------------------------------------- /mirea/gifts/undefined-behavior/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/undefined-behavior/code.png -------------------------------------------------------------------------------- /mirea/gifts/undefined-behavior/example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/undefined-behavior/example-1.png -------------------------------------------------------------------------------- /mirea/gifts/undefined-behavior/example-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/undefined-behavior/example-2.png -------------------------------------------------------------------------------- /mirea/gifts/undefined-behavior/hearth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/undefined-behavior/hearth.png -------------------------------------------------------------------------------- /mirea/gifts/undefined-behavior/undef.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/undefined-behavior/undef.png -------------------------------------------------------------------------------- /mirea/gifts/undefined-behavior/want-problems(5).psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/undefined-behavior/want-problems(5).psd -------------------------------------------------------------------------------- /mirea/gifts/want-problems/codeforces_logo.0113e4ab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/want-problems/codeforces_logo.0113e4ab.png -------------------------------------------------------------------------------- /mirea/gifts/want-problems/example-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/want-problems/example-black.png -------------------------------------------------------------------------------- /mirea/gifts/want-problems/example-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/want-problems/example-blue.png -------------------------------------------------------------------------------- /mirea/gifts/want-problems/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/want-problems/example.png -------------------------------------------------------------------------------- /mirea/gifts/want-problems/want-problems(1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/want-problems/want-problems(1).png -------------------------------------------------------------------------------- /mirea/gifts/want-problems/want-problems(1).psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/want-problems/want-problems(1).psd -------------------------------------------------------------------------------- /mirea/gifts/want-problems/want-problems(2).psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmkz/competitive-programming/629eaca2410efbd2b903f60701b8534d01569b7d/mirea/gifts/want-problems/want-problems(2).psd -------------------------------------------------------------------------------- /timus/1025.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: 1025. Democracy in Danger 3 | 4 | Solution: sorting, greedy, O(n log(n)) 5 | 6 | Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int main() { 14 | int n; scanf("%d", &n); 15 | std::vector a(n); 16 | for (auto& it : a) scanf("%d", &it); 17 | std::sort(a.begin(), a.end()); 18 | int answ = 0; 19 | for (int i = 0; i <= n / 2; ++i) { 20 | answ += (a[i]+1)/2; 21 | } 22 | printf("%d", answ); 23 | return 0; 24 | } --------------------------------------------------------------------------------