├── .gitignore ├── Contest ├── Atcoder │ ├── ABC194 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── ABC195 │ │ ├── a.cpp │ │ └── b.cpp │ ├── ABC196 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── f.cpp │ ├── ABC197 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── e.cpp │ ├── ABC200 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── D_chk.cpp │ │ └── D_n.cpp │ ├── ABC203 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ └── F.cpp │ ├── ABC204 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ └── E.cpp │ ├── ABC209 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ └── E.cpp │ ├── ABC210 │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── ABC212 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ └── E.cpp │ ├── ABC213 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ └── E.cpp │ └── ZONE2021 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ └── F.cpp ├── Codechef │ ├── CODEWARS │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ ├── f.cpp │ │ └── g.cpp │ ├── COOK117 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── COOK119A │ │ ├── BANQUNT.cpp │ │ ├── CHKPTS.cpp │ │ └── PERCAPTA.cpp │ ├── ENCO │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ ├── f.cpp │ │ ├── g.cpp │ │ └── h.cpp │ ├── LTIME83A │ │ ├── Divb-a.cpp │ │ ├── Divb-b.cpp │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── LTIME84A │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── LTIME85A │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── div2a.cpp │ │ ├── div2b.cpp │ │ └── e.cpp │ ├── LTIME89A │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── d_chk.cpp │ │ ├── div2a.cpp │ │ ├── e.cpp │ │ └── e_.cpp │ ├── LTIME90A │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── e.cpp │ ├── LTIME91A │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── bn.cpp │ │ ├── c.cpp │ │ ├── cn.cpp │ │ └── d.cpp │ ├── LTIME92A │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── bn.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── test.cpp │ ├── LTIME93A │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── div2a.cpp │ │ └── e.cpp │ ├── LTIME97A │ │ ├── 334118D.cpp │ │ ├── 334118E.cpp │ │ ├── A.cpp │ │ ├── AA.cpp │ │ ├── B.cpp │ │ ├── BB.cpp │ │ ├── C.cpp │ │ ├── CC.cpp │ │ └── D.cpp │ ├── RECODE │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── f.cpp │ ├── SMTC │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ └── START4 │ │ ├── cortsent.cpp │ │ ├── ctime.cpp │ │ ├── deque.cpp │ │ ├── lazychf.cpp │ │ ├── quizplag.cpp │ │ ├── subcent1r.cpp │ │ └── subcentr.cpp ├── Codeforces │ ├── April Fools Day Contest 2021 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── E.cpp │ │ └── Gn.cpp │ ├── Codeforces Global Round 14 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── E_chk.cpp │ │ ├── E_n.cpp │ │ ├── F.cpp │ │ ├── G.cpp │ │ ├── H.cpp │ │ └── I.cpp │ ├── Codeforces Global Round 15 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ └── F.cpp │ ├── Codeforces LATOKEN Round 1 (Div. 1 + Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── B_n.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── F1.cpp │ │ ├── F2.cpp │ │ ├── G.cpp │ │ └── H.cpp │ ├── Codeforces Round #632 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── f.cpp │ ├── Codeforces Round #633 │ │ ├── Div2-a.cpp │ │ ├── Div2-b.cpp │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Codeforces Round #634 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── f.cpp │ ├── Codeforces Round #635 │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Codeforces Round #636 │ │ ├── .a.cpp.swp │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── f.cpp │ ├── Codeforces Round #637 │ │ ├── Div2-a.cpp │ │ ├── Div2-b.cpp │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Codeforces Round #638 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #639 │ │ ├── Div2-a.cpp │ │ ├── Div2-b.cpp │ │ ├── a.cpp │ │ └── b.cpp │ ├── Codeforces Round #640 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ ├── f.cpp │ │ └── g.cpp │ ├── Codeforces Round #641 │ │ ├── Div2-a.cpp │ │ ├── Div2-b.cpp │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Codeforces Round #642 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── f.cpp │ ├── Codeforces Round #643 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #644 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ ├── f.cpp │ │ ├── g.cpp │ │ └── h.cpp │ ├── Codeforces Round #645 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #646 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #647 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── div2a.cpp │ │ ├── div2b.cpp │ │ └── div2c.cpp │ ├── Codeforces Round #648 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── f.cpp │ ├── Codeforces Round #649 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #650 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── f1.cpp │ ├── Codeforces Round #651 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── f.cpp │ ├── Codeforces Round #652 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #653 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #654 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e1.cpp │ ├── Codeforces Round #655 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #656 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #657 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #658 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #659 │ │ ├── a.cpp │ │ └── c.cpp │ ├── Codeforces Round #660 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #661 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e1.cpp │ │ └── f.cpp │ ├── Codeforces Round #662 │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── d.cpp │ ├── Codeforces Round #663 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #664 │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Codeforces Round #665 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #666 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #667 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── f.cpp │ ├── Codeforces Round #668 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #669 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #670 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #671 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #672 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c1.cpp │ │ ├── c2.cpp │ │ └── d.cpp │ ├── Codeforces Round #673 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── e.cpp │ ├── Codeforces Round #674 │ │ ├── a.cpp │ │ └── b.cpp │ ├── Codeforces Round #675 │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Codeforces Round #676 │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Codeforces Round #677 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #678 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #679 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #680 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #681 │ │ ├── a.cpp │ │ └── b.cpp │ ├── Codeforces Round #682 │ │ ├── a.cpp │ │ └── b.cpp │ ├── Codeforces Round #683 │ │ └── a.cpp │ ├── Codeforces Round #685 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e1.cpp │ ├── Codeforces Round #686 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #688 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #689 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #690 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #691 │ │ └── a.cpp │ ├── Codeforces Round #692 │ │ └── a.cpp │ ├── Codeforces Round #693 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── g.cpp │ ├── Codeforces Round #694 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #695 │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Codeforces Round #696 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #697 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ ├── f.cpp │ │ └── g.cpp │ ├── Codeforces Round #699 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #700 │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── b2.cpp │ ├── Codeforces Round #701 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #702 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ ├── f.cpp │ │ └── g.cpp │ ├── Codeforces Round #704 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #705 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #706 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Codeforces Round #707 │ │ ├── a.cpp │ │ └── b.cpp │ ├── Codeforces Round #708 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── d_chk.cpp │ │ ├── d_chk1.cpp │ │ └── e.cpp │ ├── Codeforces Round #710 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ ├── f.cpp │ │ └── g.cpp │ ├── Codeforces Round #711 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Codeforces Round #712 (Div. 1) │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── Codeforces Round #713 (Div. 3) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ └── G.cpp │ ├── Codeforces Round #715 (Div. 1) │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── Codeforces Round #716 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ └── E.cpp │ ├── Codeforces Round #717 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── D.cpp │ ├── Codeforces Round #719 (Div. 3) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── F1.cpp │ │ ├── F2.cpp │ │ └── G.cpp │ ├── Codeforces Round #720 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── Codeforces Round #721 (Div. 2) │ │ ├── A.cpp │ │ ├── B1.cpp │ │ ├── B2.cpp │ │ ├── C.cpp │ │ └── D.cpp │ ├── Codeforces Round #722 (Div. 1) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── Div2A.cpp │ │ └── Div2B.cpp │ ├── Codeforces Round #723 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C1.cpp │ │ ├── C2.cpp │ │ └── D.cpp │ ├── Codeforces Round #724 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── Codeforces Round #725 (Div. 3) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── E__Good.cpp │ │ ├── F.cpp │ │ ├── G.cpp │ │ ├── G__Generator.cpp │ │ ├── G__Good.cpp │ │ ├── Gn.cpp │ │ └── find.cpp │ ├── Codeforces Round #726 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── D_chk.cpp │ │ ├── E1.cpp │ │ └── E2.cpp │ ├── Codeforces Round #727 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ └── F.cpp │ ├── Codeforces Round #729 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E1.cpp │ │ └── E2.cpp │ ├── Codeforces Round #730 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D1.cpp │ │ ├── D2.cpp │ │ └── E.cpp │ ├── Codeforces Round #731 (Div. 3) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ ├── F__Generator.cpp │ │ ├── F__Good.cpp │ │ └── G.cpp │ ├── Codeforces Round #733 (Div. 1 + Div. 2, based on VK Cup 2021 - Elimination (Engine)) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ └── E.cpp │ ├── Codeforces Round #734 (Div. 3) │ │ ├── A.cpp │ │ ├── B1.cpp │ │ ├── B2.cpp │ │ ├── C.cpp │ │ ├── E.cpp │ │ └── F.cpp │ ├── Codeforces Round #735 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── D.cpp │ ├── Codeforces Round #736 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── D.cpp │ ├── Codeforces Round #737 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── D.cpp │ ├── Codeforces Round #738 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D1.cpp │ │ └── E.cpp │ ├── Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2) │ │ ├── A.cpp │ │ ├── A_n.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── C__Generator.cpp │ │ ├── C__Good.cpp │ │ ├── D.cpp │ │ ├── D_n.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ ├── G.cpp │ │ └── H.cpp │ ├── Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ ├── G.cpp │ │ └── H.cpp │ ├── Divide by Zero 2021 and Codeforces Round #714 (Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── Educational Codeforces Round 100 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Educational Codeforces Round 101 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Educational Codeforces Round 102 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Educational Codeforces Round 103 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Educational Codeforces Round 104 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Educational Codeforces Round 105 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Educational Codeforces Round 107 (Rated for Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── D_chk.cpp │ │ ├── E.cpp │ │ ├── E_chk.cpp │ │ ├── F.cpp │ │ └── G.cpp │ ├── Educational Codeforces Round 108 (Rated for Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ └── F.cpp │ ├── Educational Codeforces Round 109 (Rated for Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ └── F.cpp │ ├── Educational Codeforces Round 110 (Rated for Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ └── F.cpp │ ├── Educational Codeforces Round 111 (Rated for Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── E.cpp │ ├── Educational Codeforces Round 112 (Rated for Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ └── E.cpp │ ├── Educational Codeforces Round 85 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Educational Codeforces Round 86 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Educational Codeforces Round 87 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Educational Codeforces Round 88 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Educational Codeforces Round 90 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Educational Codeforces Round 91 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Educational Codeforces Round 92 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Educational Codeforces Round 93 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ ├── e.cpp │ │ └── f.cpp │ ├── Educational Codeforces Round 94 │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Educational Codeforces Round 95 │ │ ├── a.cpp │ │ ├── b.cpp │ │ └── c.cpp │ ├── Educational Codeforces Round 96 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Educational Codeforces Round 97 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Educational Codeforces Round 98 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Educational Codeforces Round 99 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── Global Round 10 │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ ├── d.cpp │ │ └── e.cpp │ ├── Harbour.Space Scholarship Contest 2021-2022 (open for everyone, rated, Div. 1 + Div. 2) │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ └── E.cpp │ └── upsolves │ │ ├── 1163B2.cpp │ │ ├── 1163C1.cpp │ │ ├── 1176F.cpp │ │ ├── 1496A.cpp │ │ ├── 1496B.cpp │ │ ├── 1498D.cpp │ │ ├── 1498F.cpp │ │ ├── 1501A.cpp │ │ ├── 1503D.cpp │ │ ├── 1504A.cpp │ │ ├── 1504B.cpp │ │ ├── 1509A.cpp │ │ ├── 1509B.cpp │ │ ├── 1510D.cpp │ │ ├── 1512E.cpp │ │ ├── 1513D.cpp │ │ ├── 1513E.cpp │ │ ├── 1514D.cpp │ │ ├── 1516D.cpp │ │ ├── 1516E.cpp │ │ ├── 1521D.cpp │ │ ├── 1523C.cpp │ │ ├── 1523D.cpp │ │ ├── 1527D.cpp │ │ ├── 1527E.cpp │ │ ├── 1528D.cpp │ │ ├── 1539F.cpp │ │ ├── 1540B.cpp │ │ ├── 1546A.cpp │ │ ├── 1546B.cpp │ │ ├── 1546C.cpp │ │ ├── 1552F.cpp │ │ ├── 334118A.cpp │ │ ├── 334118B.cpp │ │ ├── 334118C.cpp │ │ ├── 334118F.cpp │ │ ├── 488D.cpp │ │ ├── 584B.cpp │ │ ├── 767C.cpp │ │ ├── 979A.cpp │ │ ├── 979C.cpp │ │ ├── K.cpp │ │ └── test.cpp ├── Codejam │ ├── Qualification_Round_2021 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── D.cpp │ ├── Round_1A_2021 │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ └── Round_2 │ │ ├── A.cpp │ │ ├── A_chk.cpp │ │ ├── B.cpp │ │ ├── Brute.cpp │ │ └── C.cpp └── Kickstart │ ├── 2020 │ ├── RoundB │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ ├── RoundC │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ └── RoundD │ │ ├── a.cpp │ │ ├── b.cpp │ │ ├── c.cpp │ │ └── d.cpp │ └── 2021 │ ├── RoundA │ ├── a.cpp │ ├── b.cpp │ ├── c.cpp │ ├── chk.cpp │ ├── d.cpp │ └── d_n.cpp │ ├── RoundB │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp │ ├── RoundC │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp │ └── RoundD │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── C_n.cpp │ └── D.cpp ├── Library ├── Bigint.cpp ├── Bridge.cpp ├── DFT.cpp ├── Fast.cpp ├── Fenwick_Tree.cpp ├── HLD.cpp ├── KMP.cpp ├── Kth_Ancestor.cpp ├── LCA_Binary.cpp ├── LCA_Segment.cpp ├── Manacher.cpp ├── Matrix.cpp ├── Mod.cpp ├── NTT.cpp ├── Phi.cpp ├── Point2D.cpp ├── Point3D.cpp ├── Prime.cpp ├── Rabin_Karp.cpp ├── Segment_Tree.cpp ├── Segment_Tree_Lazy.cpp ├── Segment_Tree_Sum.cpp ├── SparseTable.cpp ├── Z_Function.cpp └── to_int.cpp ├── README.md └── Snippets ├── Prateek.h ├── snippet.cpp └── snippets_long.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore all 2 | * 3 | 4 | # Unignore all with extensions 5 | !*.cpp* 6 | !*.py* 7 | 8 | # Unignore all dirs 9 | !*/ 10 | 11 | # Ignore selected dirs 12 | 13 | .vscode 14 | .bin 15 | CP.code-workspace 16 | ac-library 17 | */a.out 18 | *.cpp__tests 19 | *.exe 20 | *__Good.cpp 21 | *__Generator.cpp -------------------------------------------------------------------------------- /Contest/Atcoder/ABC194/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int a, b; 17 | cin >> a >> b; 18 | a = a + b; 19 | int r; 20 | if (a >= 15 and b >= 8) { 21 | r = 1; 22 | } else if (a >= 10 and b >= 3) { 23 | r = 2; 24 | } else if (a >= 3) { 25 | r = 3; 26 | } else { 27 | r = 4; 28 | } 29 | cout << r; 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC194/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | vector a(n), b(n); 19 | for (int i = 0; i < n; ++i) { 20 | cin >> a[i] >> b[i]; 21 | } 22 | int ans = 1e18; 23 | for (int i = 0; i < n; ++i) { 24 | for (int j = 0; j < n; ++j) { 25 | if (i == j) { 26 | ans = min(ans, a[i] + b[i]); 27 | } else { 28 | ans = min(ans, max(a[i], b[j])); 29 | } 30 | } 31 | } 32 | cout << ans << '\n'; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC194/c.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | vector cnt(401); 19 | for (int i = 0, x; i < n; ++i) { 20 | cin >> x; 21 | x += 200; 22 | cnt[x]++; 23 | } 24 | int ans = 0; 25 | for (int i = 0; i <= 400; ++i) { 26 | for (int j = i + 1; j <= 400; ++j) { 27 | ans += cnt[i] * cnt[j] * (j - i) * (j - i); 28 | } 29 | } 30 | cout << ans << '\n'; 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC194/d.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | long double ans = 0; 19 | for (int i = 1; i < n; ++i) { 20 | ans += n * 1.0 / i; 21 | } 22 | cout << setprecision(14) << fixed << ans << '\n'; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC195/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int a, b; 17 | cin >> a >> b; 18 | cout << (b % a ? "No" : "Yes"); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC195/b.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Atcoder/ABC195/b.cpp -------------------------------------------------------------------------------- /Contest/Atcoder/ABC196/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int a, b, c, d; 17 | cin >> a >> b >> c >> d; 18 | int mx = -1e9; 19 | for (int i = a; i <= b; ++i) { 20 | for (int j = c; j <= d; ++j) { 21 | mx = max(mx, i - j); 22 | } 23 | } 24 | cout << mx; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC196/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | string s; 17 | cin >> s; 18 | for (char c : s) { 19 | if (c == '.') break; 20 | cout << c; 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC196/c.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e6 + 10; 12 | 13 | int to_int(string s){ 14 | reverse(all(s)); 15 | int ans = 0,c = 1; 16 | for(auto &e : s){ 17 | ans += (e-'0')*c; 18 | c *= 10; 19 | } 20 | return ans; 21 | } 22 | 23 | int32_t main(){ 24 | ios::sync_with_stdio(false); 25 | cin.tie(NULL); 26 | int n; 27 | cin >> n; 28 | int ans = 0; 29 | for (int i = 1; i < N; ++i) { 30 | string K = to_string(i) + to_string(i); 31 | if (to_int(K) <= n) { 32 | ++ans; 33 | } 34 | } 35 | cout << ans << '\n'; 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC197/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | string s; 17 | cin >> s; 18 | cout << s.substr(1) << s[0]; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC197/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, m, x, y; 17 | cin >> n >> m >> x >> y; 18 | string s[n]; 19 | for (int i = 0; i < n; ++i) { 20 | cin >> s[i]; 21 | } 22 | --x, --y; 23 | 24 | function solve = [&](int x, int y, int dx, int dy) { 25 | if (x < 0 or x >= n or y < 0 or y >= m or s[x][y] == '#') return 0LL; 26 | return 1 + solve(x + dx, y + dy, dx, dy); 27 | }; 28 | 29 | debug(s[x][y]); 30 | 31 | cout << -3 + solve(x, y, 0, -1) + solve(x, y, 0, 1) + solve(x, y, -1, 0) + solve(x, y, 1, 0); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC200/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | cout << (n + 99) / 100; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC200/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, k; 17 | cin >> n >> k; 18 | while (k--) { 19 | if (n % 200 == 0) { 20 | n /= 200; 21 | } else { 22 | n = stoll(to_string(n) + "200"); 23 | } 24 | } 25 | cout << n; 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC200/C.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | map cnt; 19 | for (int i = 0; i < n; ++i) { 20 | int x; 21 | cin >> x; 22 | cnt[x % 200]++; 23 | } 24 | int ans = 0; 25 | for (auto [_, v] : cnt) { 26 | ans += v * (v - 1) / 2; 27 | } 28 | cout << ans << '\n'; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC203/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int a, b, c; 17 | cin >> a >> b >> c; 18 | if (a == b) { 19 | cout << c; 20 | } else if (b == c) { 21 | cout << a; 22 | } else if (a == c) { 23 | cout << b; 24 | } else { 25 | cout << 0; 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC203/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int to_int(string s){ 14 | int ans = 0; 15 | for(char c : s) { 16 | ans = ans*10 + (c - '0'); 17 | } 18 | return ans; 19 | } 20 | 21 | int32_t main(){ 22 | ios::sync_with_stdio(false); 23 | cin.tie(NULL); 24 | int n, k; 25 | cin >> n >> k; 26 | int ans = 0; 27 | for (int i = 1; i <= n; ++i) { 28 | for (int j = 1; j <= k; ++j) { 29 | ans += to_int(to_string(i) + "0" + to_string(j)); 30 | } 31 | } 32 | cout << ans; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC203/C.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, k; 17 | cin >> n >> k; 18 | vector> a(n); 19 | for (auto &[x, y] : a) { 20 | cin >> x >> y; 21 | } 22 | sort(all(a)); 23 | int cur = 0; 24 | for (auto &[x, y] : a) { 25 | if (cur + k < x) { 26 | cout << cur + k << '\n'; 27 | return 0; 28 | } 29 | int d = x - cur; 30 | k -= d; 31 | k += y; 32 | cur = x; 33 | } 34 | cout << cur + k << '\n'; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC203/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Atcoder/ABC203/F.cpp -------------------------------------------------------------------------------- /Contest/Atcoder/ABC204/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int x, y; 17 | cin >> x >> y; 18 | if (x == y) { 19 | cout << x << '\n'; 20 | } else { 21 | cout << 1 + 2 - x - y << '\n'; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC204/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | vector a(n); 19 | int ans = 0; 20 | for (int i = 0; i < n; ++i) { 21 | cin >> a[i]; 22 | ans += max(a[i] - 10, 0LL); 23 | } 24 | cout << ans; 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC209/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int a, b; 17 | cin >> a >> b; 18 | cout << max(0LL, b - a + 1); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC209/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, x; 17 | cin >> n >> x; 18 | for (int i = 0; i < n; ++i) { 19 | int c; 20 | cin >> c; 21 | x -= c; 22 | if (i & 1) 23 | ++x; 24 | } 25 | if (x >= 0) { 26 | cout << "Yes"; 27 | } else { 28 | cout << "No"; 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC210/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, a, x, y; 17 | cin >> n >> a >> x >> y; 18 | if (n > a) { 19 | cout << a * x + (n - a) * y; 20 | } else { 21 | cout << n * x; 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC210/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | string s; 19 | cin >> s; 20 | int i = 0; 21 | while (s[i] == '0') ++i; 22 | ++i; 23 | cout << (i & 1 ? "Takahashi" : "Aoki"); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC212/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int a, b; 17 | cin >> a >> b; 18 | if (a and !b) { 19 | cout << "Gold"; 20 | } else if (!a and b) { 21 | cout << "Silver"; 22 | } else { 23 | cout << "Alloy"; 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC212/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | string s; 17 | cin >> s; 18 | int v = 1; 19 | for (int i = 1; i < 4; ++i) { 20 | int a = s[i - 1] - '0'; 21 | int b = s[i] - '0'; 22 | v &= ((a + 1) % 10 == b); 23 | } 24 | sort(all(s)); 25 | if (s.front() == s.back() or v) { 26 | cout << "Weak"; 27 | } else { 28 | cout << "Strong"; 29 | } 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC212/C.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, m; 17 | cin >> n >> m; 18 | vector a(n), b(m); 19 | for (int i = 0; i < n; ++i) { 20 | cin >> a[i]; 21 | } 22 | for (int i = 0; i < m; ++i) { 23 | cin >> b[i]; 24 | } 25 | sort(all(a)); 26 | sort(all(b)); 27 | int ans = 1e17; 28 | for (int i = 0; i < n; ++i) { 29 | auto k = lower_bound(all(b), a[i]) - b.begin(); 30 | debug(k); 31 | if (k != m) ans = min(ans, abs(a[i] - b[k])); 32 | --k; 33 | if (k != -1) ans = min(ans, abs(a[i] - b[k])); 34 | } 35 | cout << ans; 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC213/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int a, b; 17 | cin >> a >> b; 18 | cout << (a ^ b); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ABC213/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | vector a(n); 19 | vector b(n); 20 | iota(all(b), 0LL); 21 | for (int &i : a) { 22 | cin >> i; 23 | } 24 | sort(all(b), [&](int x, int y){ 25 | return a[x] > a[y]; 26 | }); 27 | cout << b[1] + 1; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ZONE2021/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | string s; 17 | cin >> s; 18 | int r = 0; 19 | for (int i = 0; i + 3 < 12; ++i) { 20 | if (s.substr(i, 4) == "ZONe") ++r; 21 | } 22 | cout << r; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ZONE2021/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, D, H; 17 | cin >> n >> D >> H; 18 | long double ans = 0; 19 | for (int i = 0; i < n; ++i) { 20 | int d, h; 21 | cin >> d >> h; 22 | long double x = D * h - d * H; 23 | x /= (D - d); 24 | ans = max(ans, x); 25 | } 26 | cout << setprecision(14) << fixed << ans << '\n'; 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Contest/Atcoder/ZONE2021/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Atcoder/ZONE2021/F.cpp -------------------------------------------------------------------------------- /Contest/Codechef/CODEWARS /a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int a,b,c,d; 15 | cin >> a >> b >> c >> d; 16 | cout << d-b << ' ' << d-c << ' ' << d-a << '\n'; 17 | return; 18 | } 19 | 20 | int32_t main(){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | int tt = 1; 24 | cin >> tt; 25 | f(i,0,tt) test(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Contest/Codechef/CODEWARS /c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | const int M = 5e5+100; 13 | int cnt[2*M]; 14 | 15 | int32_t main(){ 16 | ios::sync_with_stdio(false); 17 | cin.tie(NULL); 18 | int n; 19 | cin >> n; 20 | f(i,0,n){ 21 | int x,y; 22 | cin >> x >> y; 23 | cnt[x+M] += 1; 24 | cnt[y+M+1] -= 1; 25 | } 26 | int ans = 0; 27 | int cur = 0; 28 | f(i,0,2*M+100){ 29 | cur += cnt[i]; 30 | ans += cur; 31 | ans %= MOD; 32 | } 33 | cout << ans << '\n'; 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codechef/COOK117/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n,q; 15 | cin >> n >> q; 16 | int cur = 0,ans = 0; 17 | while(q--){ 18 | int l,r; 19 | cin >> l >> r; 20 | ans += abs(cur-l)+abs(l-r); 21 | cur = r; 22 | } 23 | cout << ans << '\n'; 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | f(i,0,tt) test(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Contest/Codechef/ENCO/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int r; 15 | cin >> r; 16 | int ans = r*r*2; 17 | cout << ans << '\n'; 18 | return; 19 | } 20 | 21 | int32_t main(){ 22 | ios::sync_with_stdio(false); 23 | cin.tie(NULL); 24 | int tt = 1; 25 | cin >> tt; 26 | f(i,0,tt) test(); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Contest/Codechef/ENCO/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | string s; 15 | int n; 16 | cin >> n; 17 | cin >> s; 18 | vector cnt(26); 19 | for(auto &e : s){ 20 | cnt[e-'a']++; 21 | } 22 | f(i,0,26){ 23 | if(cnt[i]){ 24 | cout << char(i+'a') << '\n'; 25 | return; 26 | } 27 | } 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | f(i,0,tt) test(); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codechef/ENCO/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | map cnt; 17 | f(i,0,n){ 18 | int x; 19 | cin >> x; 20 | cnt[x]++; 21 | } 22 | for(auto &e : cnt){ 23 | cout << e.F << ':' << e.S << '\n'; 24 | } 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | int tt = 1; 32 | cin >> tt; 33 | f(i,0,tt) test(); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codechef/ENCO/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n,k; 15 | cin >> n >> k; 16 | vector A(2*n+1); 17 | vector pre(2*n+1); 18 | f(i,1,n+1){ 19 | cin >> A[i]; 20 | A[i+n] = A[i]; 21 | } 22 | f(i,1,2*n+1){ 23 | pre[i] = pre[i-1]+A[i]; 24 | } 25 | int ans = 0; 26 | f(i,1,n+1){ 27 | ans = max(ans,pre[i+k-1]-pre[i-1]); 28 | } 29 | cout << ans << '\n'; 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | f(i,0,tt) test(); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codechef/ENCO/e.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | double t = sqrt(2*n+1)+0.5; 17 | int tt = t; 18 | int ans = (tt-tt*tt+2*n)/2; 19 | cout << ans << '\n'; 20 | return; 21 | } 22 | 23 | int32_t main(){ 24 | ios::sync_with_stdio(false); 25 | cin.tie(NULL); 26 | int tt = 1; 27 | cin >> tt; 28 | f(i,0,tt) test(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Contest/Codechef/LTIME84A/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i> n; 15 | vector A(n); 16 | for(auto &e : A) cin >> e; 17 | int ans = 0; 18 | f(i,0,n){ 19 | int mx = -MOD,mn = MOD; 20 | f(j,i,n){ 21 | mx = max(mx,A[j]); 22 | mn = min(mn,A[j]); 23 | if(mx - mn == abs(A[j]-A[i])){ 24 | ans++; 25 | } 26 | } 27 | } 28 | cout << ans << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | f(i,0,tt) test(); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME85A/div2a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> s >> n; 20 | int ans = 0; 21 | while(s){ 22 | if(s <= n){ 23 | if(s & 1 and s != 1) ans += 2; 24 | else ans++; 25 | break; 26 | } 27 | int v = s/n; 28 | ans += v; 29 | s -= v*n; 30 | } 31 | cout << ans << '\n'; 32 | return; 33 | } 34 | 35 | int32_t main(){ 36 | ios::sync_with_stdio(false); 37 | cin.tie(NULL); 38 | int tt = 1; 39 | cin >> tt; 40 | f(i,0,tt) test(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Contest/Codechef/LTIME89A/div2a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> x; 20 | cout << 0 << ' ' << x << '\n'; 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME89A/e_.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n >> m; 20 | vector> A(m); 21 | for(auto &i : A) { 22 | cin >> i[0] >> i[1]; 23 | } 24 | for(int i = 0; i < n-1; ++i) { 25 | for(int j = 0; j < n-i-1; ++j) { 26 | cout << "1 "; 27 | } 28 | cout << '\n'; 29 | } 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | f(i,0,tt) test(); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME91A/bn.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int tt; 9 | cin >> tt; 10 | while (tt--) { 11 | int n; 12 | string s, p; 13 | cin >> n >> s >> p; 14 | int c = 0; 15 | int flg = 1; 16 | for (int i = 0; i < n; ++i) { 17 | if (s[i] != p[i]) { 18 | if (s[i] == '1') ++c; 19 | else --c; 20 | } 21 | if (c < 0) { 22 | flg = 0; 23 | break; 24 | } 25 | } 26 | if (flg and c == 0) { 27 | cout << "Yes\n"; 28 | } else { 29 | cout << "No\n"; 30 | } 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME92A/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int odd = 0; 17 | for (int i = 0, x; i < n; ++i) { 18 | cin >> x; 19 | odd += (x & 1); 20 | } 21 | if (odd & 1) { 22 | cout << "2\n"; 23 | } else { 24 | cout << "1\n"; 25 | } 26 | return; 27 | } 28 | 29 | int32_t main(){ 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | int tt = 1; 33 | cin >> tt; 34 | for (int t = 1; t <= tt; ++t) { 35 | test(); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME92A/c.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, x; 15 | cin >> n >> x; 16 | for (int i = 1; i <= n; ++i) { 17 | if (x % i == 0 and x / i <= n) { 18 | cout << "Yes\n"; 19 | return; 20 | } 21 | } 22 | cout << "No\n"; 23 | return; 24 | } 25 | 26 | int32_t main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int tt = 1; 30 | cin >> tt; 31 | for (int t = 1; t <= tt; ++t) { 32 | test(); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME92A/test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codechef/LTIME92A/test.cpp -------------------------------------------------------------------------------- /Contest/Codechef/LTIME93A/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n); 17 | set s; 18 | for (int i = 0; i < n; ++i) { 19 | cin >> a[i]; 20 | s.insert(a[i]); 21 | } 22 | reverse(all(a)); 23 | if (is_sorted(all(a)) or s.size() == 1) { 24 | cout << "No\n"; 25 | return; 26 | } 27 | cout << "Yes\n"; 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME93A/div2a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, k; 15 | cin >> n >> k; 16 | int d = n / k; 17 | cout << n - d * k << '\n'; 18 | return; 19 | } 20 | 21 | int32_t main(){ 22 | ios::sync_with_stdio(false); 23 | cin.tie(NULL); 24 | int tt = 1; 25 | cin >> tt; 26 | for (int t = 1; t <= tt; ++t) { 27 | test(); 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME97A/334118D.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int dp[N]; 14 | 15 | void test(){ 16 | int n; 17 | cin >> n; 18 | cout << dp[n] << '\n'; 19 | return; 20 | } 21 | 22 | int32_t main(){ 23 | ios::sync_with_stdio(false); 24 | cin.tie(NULL); 25 | 26 | dp[0] = 1; 27 | for (int i = 1; i < N; ++i) { 28 | for (int j : {1, 2, 4, 6}) { 29 | if (i - j >= 0) { 30 | dp[i] += dp[i - j]; 31 | dp[i] %= MOD; 32 | } 33 | } 34 | } 35 | 36 | 37 | int tt = 1; 38 | cin >> tt; 39 | for (int t = 1; t <= tt; ++t) { 40 | test(); 41 | } 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME97A/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int a, b, x; 15 | cin >> a >> b >> x; 16 | cout << (b - a) / x << '\n'; 17 | return; 18 | } 19 | 20 | int32_t main(){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | int tt = 1; 24 | cin >> tt; 25 | for (int t = 1; t <= tt; ++t) { 26 | test(); 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME97A/AA.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, m, k; 15 | cin >> n >> m; 16 | if ((m & (m - 1)) == 0) { 17 | cout << "Yes\n"; 18 | } else { 19 | cout << "No\n"; 20 | } 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | for (int t = 1; t <= tt; ++t) { 30 | test(); 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Contest/Codechef/LTIME97A/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | string s; 15 | cin >> s; 16 | if (s.length() <= 3) { 17 | cout << "Error\n"; 18 | return; 19 | } 20 | int n = s.length(); 21 | int x = (s[0] == '<' and s[1] == '/' and s[n - 1] == '>'); 22 | for (int i = 2; i < n - 1; ++i) { 23 | x &= (isdigit(s[i]) or (s[i] >= 'a' and s[i] <= 'z')); 24 | } 25 | cout << (x ? "Success" : "Error") << '\n'; 26 | return; 27 | } 28 | 29 | int32_t main(){ 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | int tt = 1; 33 | cin >> tt; 34 | for (int t = 1; t <= tt; ++t) { 35 | test(); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codechef/RECODE/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | string s; 15 | cin >> s; 16 | int n = s.length(); 17 | string t = s.back()+s.substr(0,n-1); 18 | string m = s.substr(1)+s[0]; 19 | if(t == m){ 20 | cout << "YES\n"; 21 | }else{ 22 | cout << "NO\n"; 23 | } 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | f(i,0,tt) test(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Contest/Codechef/SMTC/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int ans = -1; 17 | f(i,0,62){ 18 | if((1ll<> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Contest/Codechef/START4/lazychf.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int x, m, d; 15 | cin >> x >> m >> d; 16 | cout << min(x * m, x + d) << '\n'; 17 | return; 18 | } 19 | 20 | int32_t main(){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | int tt = 1; 24 | cin >> tt; 25 | for (int t = 1; t <= tt; ++t) { 26 | test(); 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contest/Codeforces/April Fools Day Contest 2021/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | string s; 17 | while (getline(cin, s)) { 18 | cout << "NO" << endl; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Contest/Codeforces/April Fools Day Contest 2021/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | int ans = 0; 18 | cin >> n; 19 | cout << 1 + (n - 1) % 9 << '\n'; 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Contest/Codeforces/April Fools Day Contest 2021/C.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | string s; 17 | cin >> s; 18 | int n = s.length(); 19 | int ans = 0; 20 | if (n <= 2) { 21 | cout << "YES\n"; 22 | return 0; 23 | } 24 | int a = s[0] - 'A', b = s[1] - 'A'; 25 | for (int i = 2; i < n; ++i) { 26 | int c = (a + b) % 26; 27 | if (c != s[i] - 'A') { 28 | cout << "NO\n"; 29 | return 0; 30 | } 31 | a = b; 32 | b = c; 33 | } 34 | cout << "YES\n"; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/April Fools Day Contest 2021/Gn.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | for (int i = 0; i <= 26; ++i) { 17 | 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Global Round 14/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | bool square(int x) { 14 | int sq = sqrt(x); 15 | return sq * sq == x; 16 | } 17 | 18 | void test(){ 19 | int n; 20 | cin >> n; 21 | if (n % 2 == 0 and square(n / 2)) { 22 | cout << "YES\n"; 23 | return; 24 | } 25 | if (n % 4 == 0 and square(n / 4)) { 26 | cout << "YES\n"; 27 | return; 28 | } 29 | cout << "NO\n"; 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | for (int t = 1; t <= tt; ++t) { 39 | test(); 40 | } 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Global Round 14/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Global Round 14/F.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Global Round 14/G.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Global Round 14/G.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Global Round 14/H.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Global Round 14/H.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Global Round 14/I.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Global Round 14/I.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Global Round 15/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | string s; 15 | int n; 16 | cin >> n; 17 | cin >> s; 18 | string t = s; 19 | sort(all(t)); 20 | int ans = 0; 21 | // debug(s, t); 22 | for (int i = 0; i < n; ++i) { 23 | ans += (s[i] != t[i]); 24 | } 25 | cout << ans << '\n'; 26 | return; 27 | } 28 | 29 | int32_t main(){ 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | int tt = 1; 33 | cin >> tt; 34 | for (int t = 1; t <= tt; ++t) { 35 | test(); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)/F1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)/F1.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)/F2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)/F2.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)/G.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)/G.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)/H.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)/H.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #632/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n,m; 15 | cin >> n >> m; 16 | f(i,0,m-1){ 17 | cout << "W"; 18 | } 19 | cout << "B\n"; 20 | f(i,1,n){ 21 | f(j,0,m){ 22 | cout << "B"; 23 | } 24 | cout << '\n'; 25 | } 26 | return; 27 | } 28 | 29 | int32_t main(){ 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | int tt = 1; 33 | cin >> tt; 34 | f(i,0,tt) test(); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #632/f.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 5e5 + 1; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | vector fact(n+1,1); 19 | f(i,1,n+1){ 20 | for(int j=2*i;j<=n;j+=i){ 21 | fact[j] = i; 22 | } 23 | } 24 | sort(fact.begin()+1,fact.end()); 25 | f(i,2,n+1){ 26 | cout << fact[i] << ' '; 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #633/Div2-a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | cout << n << '\n'; 17 | return; 18 | } 19 | 20 | int32_t main(){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | int tt = 1; 24 | cin >> tt; 25 | f(i,0,tt) test(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #634/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | if(n & 1){ 17 | cout << n/2 << '\n'; 18 | }else{ 19 | cout << n/2-1 << '\n'; 20 | } 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #634/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n,a,b; 15 | cin >> n >> a >> b; 16 | string res = ""; 17 | f(i,0,b){ 18 | res += i+'a'; 19 | } 20 | f(i,b,a){ 21 | res += b-1+'a'; 22 | } 23 | string ans = ""; 24 | while(ans.length()> tt; 39 | f(i,0,tt) test(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #636/.a.cpp.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #636/.a.cpp.swp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #636/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int sm = 1; 17 | int pw = 2; 18 | while(1){ 19 | sm += pw; 20 | if(n%sm == 0){ 21 | cout << n/sm << '\n'; 22 | return; 23 | } 24 | pw *= 2; 25 | } 26 | return; 27 | } 28 | 29 | int32_t main(){ 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | int tt = 1; 33 | cin >> tt; 34 | f(i,0,tt) test(); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #636/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n),A(n); 17 | f(i,0,n){ 18 | cin >> a[i]; 19 | A[i] = (a[i]>0); 20 | } 21 | int ans = 0; 22 | for(int i=0,j;i> tt; 40 | f(i,0,tt) test(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #637/Div2-a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n,a,b,c,d; 15 | cin >> n >> a >> b >> c >> d; 16 | if(max(c-d,n*(a-b))<=min(c+d,n*(a+b))){ 17 | cout << "Yes\n"; 18 | }else{ 19 | cout << "No\n"; 20 | } 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #638/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int ans = 1ll<> tt; 32 | f(i,0,tt) test(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #639/Div2-a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n,m; 15 | cin >> n >> m; 16 | if(n == 1 or m == 1){ 17 | cout << "YES\n"; 18 | return; 19 | } 20 | if(n==2 and m == 2){ 21 | cout << "YES\n"; 22 | return; 23 | } 24 | cout << "NO\n"; 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | int tt = 1; 32 | cin >> tt; 33 | f(i,0,tt) test(); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #639/Div2-b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int ans = 0; 17 | int sq = sqrt(n)+1; 18 | for(int i=sq;i>=1;i--){ 19 | int sm = (i*(i-1)/2)*3+2*i; 20 | if(sm <= n){ 21 | int v = n/sm; 22 | n -= v*sm; 23 | ans+=v; 24 | } 25 | } 26 | cout << ans << '\n'; 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | f(i,0,tt) test(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #639/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int tt; 6 | cin >> tt; 7 | while(tt--){ 8 | int n; 9 | cin >> n; 10 | vector A(n),C(n); 11 | int mx = 0; 12 | for(int i=0;i> A[i]; 14 | int d = i+A[i]; 15 | if(d<0){ 16 | d = (n-abs(d)%n)%n; 17 | }else{ 18 | d = d%n; 19 | } 20 | C[d]++; 21 | mx = max(mx,C[d]); 22 | } 23 | cout << ((mx>=2)?"NO\n":"YES\n"); 24 | } 25 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #640/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | string n; 15 | cin >> n; 16 | vector ans; 17 | f(i,0,n.length()){ 18 | if(n[i]!='0'){ 19 | ans.pb((n[i]-'0')*pow(10,(int)n.length()-i-1)); 20 | } 21 | } 22 | cout<< ans.size() << '\n'; 23 | for(auto &e : ans){ 24 | cout << e << ' '; 25 | } 26 | cout << '\n'; 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | f(i,0,tt) test(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #640/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n,k; 15 | cin >> n >> k; 16 | cout << k+(k+n-2)/(n-1)-1 << '\n'; 17 | return; 18 | } 19 | 20 | int32_t main(){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | int tt = 1; 24 | cin >> tt; 25 | f(i,0,tt) test(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #641/Div2-a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n,k; 15 | cin >> n >> k; 16 | f(i,2,n+1){ 17 | if(n%i == 0){ 18 | cout << n+i+2*(k-1) << '\n'; 19 | return; 20 | } 21 | } 22 | return; 23 | } 24 | 25 | int32_t main(){ 26 | ios::sync_with_stdio(false); 27 | cin.tie(NULL); 28 | int tt = 1; 29 | cin >> tt; 30 | f(i,0,tt) test(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #641/Div2-b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector dp(n+1),A(n+1); 17 | f(i,1,n+1){ 18 | cin >> A[i]; 19 | } 20 | int ans = 1; 21 | for(int i=n;i>=1;i--){ 22 | dp[i] = 1; 23 | for(int j=i;j<=n;j+=i){ 24 | if(A[j]>A[i]){ 25 | dp[i] = max(dp[i],dp[j]+1); 26 | } 27 | } 28 | ans = max(ans,dp[i]); 29 | } 30 | cout << ans << '\n'; 31 | return; 32 | } 33 | 34 | int32_t main(){ 35 | ios::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | int tt = 1; 38 | cin >> tt; 39 | f(i,0,tt) test(); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #642/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i> n >> m; 21 | if(n == 1){ 22 | cout << "0\n"; 23 | }else if(n == 2){ 24 | cout << m << '\n'; 25 | }else{ 26 | cout << 2*m << '\n'; 27 | } 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | f(i,0,tt) test(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #642/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i> n; 21 | int ans = 0; 22 | while(n!=1){ 23 | int cell = n*4-4; 24 | ans += (n/2)*cell; 25 | n-=2; 26 | } 27 | cout << ans << '\n'; 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | f(i,0,tt) test(); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #643/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i> n; 21 | vector A(n); 22 | f(i,0,n){ 23 | cin >> A[i]; 24 | } 25 | sort(all(A)); 26 | int cur = 0,R = 0; 27 | f(i,0,n){ 28 | cur++; 29 | if(A[i]<=cur){ 30 | R++; 31 | cur = 0; 32 | } 33 | } 34 | cout << R << '\n'; 35 | return; 36 | } 37 | 38 | int32_t main(){ 39 | ios::sync_with_stdio(false); 40 | cin.tie(NULL); 41 | int tt = 1; 42 | cin >> tt; 43 | f(i,0,tt) test(); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #643/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i> n >> k; 20 | int ans = n; 21 | k--; 22 | int min = 9,max = 0; 23 | while(k-- and min){ 24 | string s = to_string(ans); 25 | sort(all(s)); 26 | min = s.front()-'0'; 27 | max = s.back()-'0'; 28 | ans += min*max; 29 | } 30 | cout << ans << '\n'; 31 | return; 32 | } 33 | 34 | int32_t main(){ 35 | ios::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | int tt = 1; 38 | cin >> tt; 39 | f(i,0,tt) test(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #643/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define f(i,x,n) for(int i=x;i> n >> s; 22 | if(s>=2*n){ 23 | cout << "YES\n"; 24 | int sm = 0; 25 | f(i,1,n){ 26 | cout << 2 << ' '; 27 | sm += 2; 28 | } 29 | cout << s-sm << '\n' << "1\n"; 30 | return 0; 31 | } 32 | cout << "NO\n"; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #644/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i> a >> b; 21 | int A = min(max(2*a,b)*max(2*a,b),max(a,2*b)*max(a,2*b)); 22 | cout << A << '\n'; 23 | return; 24 | } 25 | 26 | int32_t main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int tt = 1; 30 | cin >> tt; 31 | f(i,0,tt) test(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #644/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i> n; 21 | vector A(n); 22 | for(auto &e : A) cin >> e; 23 | sort(all(A)); 24 | int ans = 1e18; 25 | f(i,1,n){ 26 | ans = min(ans,A[i]-A[i-1]); 27 | } 28 | cout << ans << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | f(i,0,tt) test(); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #647/div2c.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | int pw = 1; 21 | int ans = 0; 22 | while(pw <= n){ 23 | ans += n/pw; 24 | pw *= 2; 25 | } 26 | cout << ans << '\n'; 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | f(i,0,tt) test(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #650/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> a; 20 | cout << a[0]; 21 | int n = a.length(); 22 | f(i,1,n){ 23 | cout << a[i]; 24 | i++; 25 | } 26 | cout << '\n'; 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | f(i,0,tt) test(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #650/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector a(n); 21 | vector c(2); 22 | f(i,0,n){ 23 | cin >> a[i]; 24 | a[i] %= 2; 25 | if(a[i] != i%2){ 26 | c[a[i]]++; 27 | } 28 | } 29 | if(c[0] == c[1]){ 30 | cout << c[0] << '\n'; 31 | }else{ 32 | cout << "-1\n"; 33 | } 34 | return; 35 | } 36 | 37 | int32_t main(){ 38 | ios::sync_with_stdio(false); 39 | cin.tie(NULL); 40 | int tt = 1; 41 | cin >> tt; 42 | f(i,0,tt) test(); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #651/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | cout << n/2 << '\n'; 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #652/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | if(n % 4 != 0){ 21 | cout << "NO\n"; 22 | }else{ 23 | cout << "YES\n"; 24 | } 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | int tt = 1; 32 | cin >> tt; 33 | f(i,0,tt) test(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #652/d.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 22 | cout << dp[n]*4 % MOD << '\n'; 23 | return; 24 | } 25 | 26 | int32_t main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int tt = 1; 30 | dp[3] = dp[4] = 1; 31 | f(i,5,N) dp[i] = (dp[i-1]+2*dp[i-2]+(i%3 == 0)) % MOD; 32 | cin >> tt; 33 | f(i,0,tt) test(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #653/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> x >> y >> n; 20 | int v = (n-y)/x; 21 | cout << x*v+y << '\n'; 22 | return; 23 | } 24 | 25 | int32_t main(){ 26 | ios::sync_with_stdio(false); 27 | cin.tie(NULL); 28 | int tt = 1; 29 | cin >> tt; 30 | f(i,0,tt) test(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #654/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | cout << (n+1)/2 << '\n'; 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #654/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n >> r; 20 | if(n <= r){ 21 | int ans = (n-1)*n/2+1; 22 | cout << ans << '\n'; 23 | }else{ 24 | int ans = r*(r+1)/2; 25 | cout << ans << '\n'; 26 | } 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | f(i,0,tt) test(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #654/c.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> a >> b >> n >> m; 20 | if(n+m > a+b){ 21 | cout << "No\n"; 22 | return; 23 | } 24 | int mn = min(a,b); 25 | if(m > mn){ 26 | cout << "No\n"; 27 | return; 28 | } 29 | cout << "Yes\n"; 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | f(i,0,tt) test(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #655/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | f(i,0,n){ 21 | cout << "1 "; 22 | } 23 | cout << '\n'; 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | f(i,0,tt) test(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #655/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector> R; 21 | for(int i = 1; i*i <= n; ++i){ 22 | if(n % i == 0){ 23 | R.pb({max(n-i,i),i,n-i}); 24 | R.pb({max(n-n/i,n/i),n/i,n-n/i}); 25 | } 26 | } 27 | sort(all(R)); 28 | cout << R[0][1] << ' ' << R[0][2] << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | f(i,0,tt) test(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #655/d.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define f(i,x,n) for(int i=x;i> n; 22 | vector a(n); 23 | int sm[2] = {0,0}; 24 | f(i,0,n){ 25 | cin >> a[i]; 26 | sm[i%2] += a[i]; 27 | } 28 | int cur[2] = {0,0}; 29 | int ans = 0; 30 | f(i,0,n){ 31 | // debug(sm[i%2]+cur[1-i%2]); 32 | ans = max(ans,sm[i%2]+cur[1-i%2]); 33 | cur[i%2] += a[i]; 34 | sm[i%2] -= a[i]; 35 | // debug(ans); 36 | } 37 | cout << ans << '\n'; 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #656/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> x >> y >> z; 20 | int a = min(x,y),b = min(x,z),c = min(y,z); 21 | if(x == max(a,b) and y == max(a,c) and z == max(b,c)){ 22 | cout << "YES\n"; 23 | cout << a << ' ' << b << ' ' << c << '\n'; 24 | }else{ 25 | cout << "NO\n"; 26 | } 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | f(i,0,tt) test(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #656/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector done(n+1); 21 | f(i,0,2*n){ 22 | int x; 23 | cin >> x; 24 | if(done[x]) continue; 25 | cout << x << ' '; 26 | done[x] = 1; 27 | } 28 | cout << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | f(i,0,tt) test(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #661/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int tt; 9 | cin >> tt; 10 | while(tt--){ 11 | int n; 12 | cin >> n; 13 | vector a(n); 14 | for(int i = 0; i < n; ++i){ 15 | cin >> a[i]; 16 | } 17 | sort(a.begin(),a.end()); 18 | int chk = 1; 19 | for(int i = 1; i < n; ++i){ 20 | chk &= (a[i]-a[i-1] <= 1); 21 | } 22 | if(chk){ 23 | cout << "YES\n"; 24 | }else{ 25 | cout << "NO\n"; 26 | } 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #661/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int tt; 9 | cin >> tt; 10 | while(tt--){ 11 | int n; 12 | cin >> n; 13 | vector a(n),b(n); 14 | vector op1(n),op2(n); 15 | int mn1 = 1e9, mn2 = 1e9; 16 | for(int i = 0; i < n; ++i){ 17 | cin >> a[i]; 18 | mn1 = min(mn1,a[i]); 19 | } 20 | for(int i = 0; i < n; ++i){ 21 | cin >> b[i]; 22 | mn2 = min(mn2,b[i]); 23 | } 24 | int ans = 0; 25 | for(int i = 0; i < n; ++i){ 26 | op1[i] = a[i]-mn1; 27 | op2[i] = b[i]-mn2; 28 | int mn = min(op1[i],op2[i]); 29 | ans += mn; 30 | op1[i] -= mn; 31 | op2[i] -= mn; 32 | ans += op1[i]+op2[i]; 33 | } 34 | cout << ans << '\n'; 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #661/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int tt; 9 | cin >> tt; 10 | while(tt--){ 11 | int n; 12 | cin >> n; 13 | vector a(n); 14 | for(int i = 0; i < n; ++i){ 15 | cin >> a[i]; 16 | } 17 | int ans = 0; 18 | for(int s = 2; s <= 2*n; ++s){ 19 | vector cnt(2*n); 20 | int v = 0; 21 | for(int i = 0; i < n; ++i){ 22 | if(s-a[i] > 0){ 23 | if(cnt[s-a[i]]){ 24 | v++; 25 | --cnt[s-a[i]]; 26 | }else{ 27 | cnt[a[i]]++; 28 | } 29 | } 30 | } 31 | ans = max(ans,v); 32 | } 33 | cout << ans << '\n'; 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #661/d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int tt; 9 | cin >> tt; 10 | while(tt--){ 11 | int n; 12 | string s; 13 | cin >> n >> s; 14 | set se[2]; 15 | int ans = 0; 16 | vector R(n); 17 | for(int i = 0; i < n; ++i){ 18 | int v = s[i]-'0'; 19 | if(se[v^1].empty()){ 20 | ans++; 21 | R[i] = ans; 22 | se[v].insert(ans); 23 | }else{ 24 | int k = *se[v^1].begin(); 25 | se[v^1].erase(k); 26 | R[i] = k; 27 | se[v].insert(k); 28 | } 29 | } 30 | cout << ans << '\n'; 31 | for(int i = 0; i < n; ++i){ 32 | cout << R[i] << " \n"[ i==n-1 ]; 33 | } 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #662/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int tt; 9 | cin >> tt; 10 | while(tt--){ 11 | int n; 12 | cin >> n; 13 | cout << (n+2)/2 << '\n'; 14 | } 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #663/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int tt; 9 | cin >> tt; 10 | while(tt--){ 11 | int n; 12 | cin >> n; 13 | for(int i = 1; i <= n; ++i){ 14 | cout << i << " \n"[i == n]; 15 | } 16 | } 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #663/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int tt; 9 | cin >> tt; 10 | while(tt--){ 11 | int n,m; 12 | cin >> n >> m; 13 | string s[n]; 14 | for(int i = 0; i < n; ++i){ 15 | cin >> s[i]; 16 | } 17 | int v = 0; 18 | for(int i = 0; i < m-1; ++i){ 19 | if(s[n-1][i] == 'D') v++; 20 | } 21 | for(int i = 0; i < n-1; ++i){ 22 | if(s[i][m-1] == 'R') v++; 23 | } 24 | cout << v << '\n'; 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #664/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int tt; 9 | cin >> tt; 10 | while(tt--){ 11 | int r,g,b,w; 12 | cin >> r >> g >> b >> w; 13 | int chk = 0; 14 | for(int i = 0; i < 10; ++i){ 15 | int c = (r%2)+(g%2)+(b%2)+(w%2); 16 | if(c <= 1){ 17 | chk = 1; 18 | break; 19 | } 20 | if(r and g and b){ 21 | --r,--g,--b; 22 | w += 3; 23 | } 24 | } 25 | if(chk){ 26 | cout << "Yes\n"; 27 | }else{ 28 | cout << "No\n"; 29 | } 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #664/c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | 5 | int32_t main(){ 6 | ios::sync_with_stdio(false); 7 | cin.tie(NULL); 8 | int n,m; 9 | cin >> n >> m; 10 | vector a(n),b(m); 11 | for(int i = 0; i < n; ++i){ 12 | cin >> a[i]; 13 | } 14 | for(int i = 0; i < m; ++i){ 15 | cin >> b[i]; 16 | } 17 | for(int mask = 0; mask <= (1<<9); ++mask){ 18 | int f = 1; 19 | for(int i = 0; i < n; ++i){ 20 | int c = 0; 21 | for(int j = 0; j < m; ++j){ 22 | if((mask|(a[i]&b[j])) == mask){ 23 | c = 1; 24 | } 25 | } 26 | if(!c){ 27 | f = 0; 28 | } 29 | } 30 | if(f){ 31 | cout << mask; 32 | return 0; 33 | } 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #665/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n >> k; 20 | if(n <= k){ 21 | cout << k-n << '\n'; 22 | }else{ 23 | n -= k; 24 | if(n & 1){ 25 | cout << 1 << '\n'; 26 | }else{ 27 | cout << 0 << '\n'; 28 | } 29 | } 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | f(i,0,tt) test(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #665/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> x1 >> y1 >> z1 >> x2 >> y2 >> z2; 20 | int ans = min(z1,y2)*2; 21 | z1 -= ans/2; 22 | y2 -= ans/2; 23 | int mn = min(z1,z2); 24 | z1 -= mn; 25 | z2 -= mn; 26 | mn = min(z2,x1); 27 | x1 -= mn; 28 | z2 -= mn; 29 | ans -= min(z2,y1)*2; 30 | cout << ans << '\n'; 31 | return; 32 | } 33 | 34 | int32_t main(){ 35 | ios::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | int tt = 1; 38 | cin >> tt; 39 | f(i,0,tt) test(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #667/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> a >> b; 20 | int d = abs(a-b); 21 | cout << d/10+(d%10 != 0) << '\n'; 22 | return; 23 | } 24 | 25 | int32_t main(){ 26 | ios::sync_with_stdio(false); 27 | cin.tie(NULL); 28 | int tt = 1; 29 | cin >> tt; 30 | f(i,0,tt) test(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #668/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector A(n); 21 | for(int &i : A){ 22 | cin >> i; 23 | } 24 | reverse(all(A)); 25 | for(int i : A){ 26 | cout << i << ' '; 27 | } 28 | cout << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | f(i,0,tt) test(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #668/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector A(n); 21 | for(int i = 0; i < n; ++i){ 22 | cin >> A[i]; 23 | } 24 | int sm = 0; 25 | for(int i = 0; i < n; ++i){ 26 | sm += A[i]; 27 | sm = max(sm,0ll); 28 | } 29 | cout << sm << '\n'; 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | f(i,0,tt) test(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #671/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | int cur = 2; 21 | int ans = 0; 22 | int sm = 1; 23 | while(sm <= n){ 24 | ans++; 25 | cur = cur*2; 26 | sm += (cur*(cur-1))/2; 27 | // debug(sm); 28 | } 29 | cout << ans << '\n'; 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | f(i,0,tt) test(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #672/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector A(n); 21 | for(int i = 0; i < n; ++i){ 22 | cin >> A[i]; 23 | } 24 | int chk = 1; 25 | for(int i = 1; i < n; ++i){ 26 | chk &= (A[i] < A[i-1]); 27 | } 28 | if(chk){ 29 | cout << "NO\n"; 30 | }else{ 31 | cout << "YES\n"; 32 | } 33 | return; 34 | } 35 | 36 | int32_t main(){ 37 | ios::sync_with_stdio(false); 38 | cin.tie(NULL); 39 | int tt = 1; 40 | cin >> tt; 41 | f(i,0,tt) test(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #673/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "C:\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n >> k; 20 | vector A(n); 21 | int mn = 1e9; 22 | for(int &i : A) { 23 | cin >> i; 24 | } 25 | sort(A.begin(), A.end()); 26 | int ans = 0; 27 | for(int i = 1; i < n; ++i) { 28 | ans += (k-A[i]) / A[0]; 29 | } 30 | cout << ans << '\n'; 31 | return; 32 | } 33 | 34 | int32_t main(){ 35 | ios::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | int tt = 1; 38 | cin >> tt; 39 | f(i,0,tt) test(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #675/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> a >> b >> c; 20 | cout << max({a,b,c}) << '\n'; 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #676/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> a >> b; 20 | int ans = 0; 21 | for(int i = 0; i < 32; ++i) { 22 | int b1 = (a >> i) & 1; 23 | int b2 = (b >> i) & 1; 24 | if(b1^b2) { 25 | ans += (1LL << i); 26 | } 27 | } 28 | cout << ans << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | f(i,0,tt) test(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #676/c.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define f(i,x,n) for(int i=x;i> s; 22 | int n = s.length(); 23 | cout << 3 << '\n'; 24 | cout << "L 2\n"; 25 | cout << "R 2\n"; 26 | cout << "R " << 2*n-1 << '\n'; 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #677/e.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define f(i,x,n) for(int i=x;i> n; 24 | 25 | vector res = { 26 | 0, 1, 3, 40, 1260, 72576, 6652800, 889574400, 163459296000, 39520825344000, 12164510040883200 27 | }; 28 | cout << res[n/2] << '\n'; 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #678/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n >> m; 20 | vector A(n); 21 | int sum = 0; 22 | for(int i = 0; i < n; ++i) { 23 | cin >> A[i]; 24 | sum += A[i]; 25 | } 26 | if(sum == m) { 27 | cout << "YES\n"; 28 | } else { 29 | cout << "NO\n"; 30 | } 31 | return; 32 | } 33 | 34 | int32_t main(){ 35 | ios::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | int tt = 1; 38 | cin >> tt; 39 | f(i,0,tt) test(); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #678/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector A(n-2, 0); 21 | A.push_back(1); 22 | A.push_back(1); 23 | for(int i = 0; i < n; ++i) { 24 | for(auto i : A) { 25 | cout << i << ' '; 26 | } 27 | cout << '\n'; 28 | int bk = A.back(); 29 | A.pop_back(); 30 | A.insert(A.begin(), bk); 31 | } 32 | return; 33 | } 34 | 35 | int32_t main(){ 36 | ios::sync_with_stdio(false); 37 | cin.tie(NULL); 38 | int tt = 1; 39 | cin >> tt; 40 | f(i,0,tt) test(); 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #680/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> a >> b >> c >> d; 20 | cout << max(a+b, c+d) << '\n'; 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #682/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | for (int i = 0; i < n; ++i) { 21 | cout << 1 << ' '; 22 | } 23 | cout << '\n'; 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | f(i,0,tt) test(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #682/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector a(n); 21 | map cnt; 22 | for (int i = 0; i < n; ++i) { 23 | cin >> a[i]; 24 | ++cnt[a[i]]; 25 | } 26 | for (auto &e : cnt) { 27 | if(e.S > 1) { 28 | cout << "YES\n"; 29 | return; 30 | } 31 | } 32 | cout << "NO\n"; 33 | return; 34 | } 35 | 36 | int32_t main(){ 37 | ios::sync_with_stdio(false); 38 | cin.tie(NULL); 39 | int tt = 1; 40 | cin >> tt; 41 | f(i,0,tt) test(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #685/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | if (n == 1) { 21 | cout << "0\n"; 22 | return; 23 | } 24 | int ans = 0; 25 | if (n & 1) { 26 | ++ans; 27 | --n; 28 | } 29 | ans++; 30 | if (n > 2) ++ans; 31 | cout << ans << '\n'; 32 | return; 33 | } 34 | 35 | int32_t main(){ 36 | ios::sync_with_stdio(false); 37 | cin.tie(NULL); 38 | int tt = 1; 39 | cin >> tt; 40 | f(i,0,tt) test(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #686/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector a(n); 21 | iota(all(a),2); 22 | a.back() = 1; 23 | for (int i : a) { 24 | cout << i << ' '; 25 | } 26 | cout << '\n'; 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | f(i,0,tt) test(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #689/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n >> k; 20 | for (int i = 0; i < n; ++i) { 21 | cout << char(i%3 + 'a'); 22 | } 23 | cout << '\n'; 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | f(i,0,tt) test(); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #690/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector a(n); 21 | for (int &i : a) { 22 | cin >> i; 23 | } 24 | int l = 0, r = n - 1; 25 | while (l < r) { 26 | cout << a[l] << ' ' << a[r] << ' '; 27 | ++l, --r; 28 | } 29 | if (l == r) cout << a[l]; 30 | cout << '\n'; 31 | return; 32 | } 33 | 34 | int32_t main(){ 35 | ios::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | int tt = 1; 38 | cin >> tt; 39 | f(i,0,tt) test(); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #690/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | string s; 21 | cin >> s; 22 | for (int i = 0; i <= 4; ++i) { 23 | string k = s.substr(0,i) + s.substr(n - (4 - i), 4 - i); 24 | if (k == "2020") { 25 | cout << "Yes\n"; 26 | return; 27 | } 28 | } 29 | cout << "No\n"; 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | f(i,0,tt) test(); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #693/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> w >> h >> n; 20 | int c = 1; 21 | while (w % 2 == 0) { 22 | w /= 2; 23 | c *= 2; 24 | } 25 | while (h % 2 == 0) { 26 | h /= 2; 27 | c *= 2; 28 | } 29 | if (c >= n) { 30 | cout << "YES\n"; 31 | } else { 32 | cout << "NO\n"; 33 | } 34 | return; 35 | } 36 | 37 | int32_t main(){ 38 | ios::sync_with_stdio(false); 39 | cin.tie(NULL); 40 | int tt = 1; 41 | cin >> tt; 42 | f(i,0,tt) test(); 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #694/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n >> k; 20 | int mn = 0; 21 | int sm = 0; 22 | for (int i = 0; i < n; ++i) { 23 | int x; 24 | cin >> x; 25 | sm += x; 26 | mn += (x + k - 1) / k; 27 | } 28 | cout << (sm + k - 1) / k << ' ' << mn<< '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | f(i,0,tt) test(); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #696/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | string b; 17 | cin >> b; 18 | int prv = -1; 19 | for (int i = 0; i < n; ++i) { 20 | int v = b[i] - '0'; 21 | if (v + 1 != prv) { 22 | cout << 1; 23 | prv = v + 1; 24 | } else { 25 | cout << 0; 26 | prv = v; 27 | } 28 | } 29 | cout << '\n'; 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | for (int t = 1; t <= tt; ++t) { 39 | test(); 40 | } 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #697/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | while (n % 2 == 0) { 17 | n /= 2; 18 | } 19 | cout << (n == 1 ? "NO\n" : "YES\n"); 20 | return; 21 | } 22 | 23 | int32_t main(){ 24 | ios::sync_with_stdio(false); 25 | cin.tie(NULL); 26 | int tt = 1; 27 | cin >> tt; 28 | for (int t = 1; t <= tt; ++t) { 29 | test(); 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #697/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int d = n / 2020, r = n % 2020; 17 | if (d >= r) { 18 | cout << "YES\n"; 19 | } else { 20 | cout << "NO\n"; 21 | } 22 | return; 23 | } 24 | 25 | int32_t main(){ 26 | ios::sync_with_stdio(false); 27 | cin.tie(NULL); 28 | int tt = 1; 29 | cin >> tt; 30 | for (int t = 1; t <= tt; ++t) { 31 | test(); 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #701/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int ans = MOD; 15 | int a, b; 16 | cin >> a >> b; 17 | for (int i = 0; i < N; ++i) { 18 | if (b != 1) { 19 | int op = i, x = a; 20 | while (x) { 21 | x /= b; 22 | ++op; 23 | } 24 | ans = min(ans, op); 25 | } 26 | ++b; 27 | } 28 | cout << ans << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | for (int t = 1; t <= tt; ++t) { 38 | test(); 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #701/d.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e6 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, m; 17 | cin >> n >> m; 18 | int lc = 1; 19 | for (int i = 1; i <= 16; ++i) { 20 | lc = lcm(lc, i); 21 | } 22 | int x; 23 | for (int i = 0; i < n; ++i) { 24 | for (int j = 0; j < m; ++j) { 25 | cin >> x; 26 | if ((i + j) & 1) { 27 | cout << lc + x * x * x * x << ' '; 28 | } else { 29 | cout << lc << ' '; 30 | } 31 | } 32 | cout << '\n'; 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #704/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int p, a, b, c; 15 | cin >> p >> a >> b >> c; 16 | cout << min({((p + a - 1) / a) * a - p, ((p + b - 1) / b) * b - p, ((p + c - 1) / c) * c - p}) << '\n'; 17 | return; 18 | } 19 | 20 | int32_t main(){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | int tt = 1; 24 | cin >> tt; 25 | for (int t = 1; t <= tt; ++t) { 26 | test(); 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #705/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, k; 15 | cin >> n >> k; 16 | vector res; 17 | for (int i = k + 1; i <= n; ++i) { 18 | res.push_back(i); 19 | } 20 | for (int i = k - 1; i >= (k + 1) / 2; --i) { 21 | res.push_back(i); 22 | } 23 | cout << res.size() << '\n'; 24 | for (int i : res) { 25 | cout << i << ' '; 26 | } 27 | cout << '\n'; 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #708/d_chk.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #710/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, m, x; 15 | cin >> n >> m >> x; 16 | int X = x % n; 17 | if (X == 0) X = n; 18 | int Y = (x + n - 1) / n; 19 | 20 | debug(X, Y); 21 | 22 | int r = (X - 1) * m + Y; 23 | cout << r << '\n'; 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | for (int t = 1; t <= tt; ++t) { 33 | test(); 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #711/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int can(int x) { 14 | int sm = 0; 15 | int n = x; 16 | while (x) { 17 | sm += x % 10; 18 | x /= 10; 19 | } 20 | return gcd(sm, n) > 1; 21 | } 22 | 23 | void test(){ 24 | int n; 25 | cin >> n; 26 | while (!can(n)) ++n; 27 | cout << n << '\n'; 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #713 (Div. 3)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | map c; 17 | map ind; 18 | for (int i = 0, x; i < n; ++i) { 19 | cin >> x; 20 | ind[x] = i + 1; 21 | c[x]++; 22 | } 23 | for (auto e : c) { 24 | if (e.second == 1) { 25 | cout << ind[e.first] << '\n'; 26 | return; 27 | } 28 | } 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | for (int t = 1; t <= tt; ++t) { 38 | test(); 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #713 (Div. 3)/G.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e7 + 10; 12 | 13 | int ans[N]; 14 | int sum[N]; 15 | 16 | void test(){ 17 | int x; 18 | cin >> x; 19 | cout << ans[x] << '\n'; 20 | return; 21 | } 22 | 23 | int32_t main(){ 24 | ios::sync_with_stdio(false); 25 | cin.tie(NULL); 26 | memset(ans, -1, sizeof ans); 27 | int tt = 1; 28 | for (int i = 1; i < N; ++i) { 29 | for (int j = i; j < N; j += i) { 30 | sum[j] += i; 31 | } 32 | if (sum[i] < N and ans[sum[i]] == -1) { 33 | ans[sum[i]] = i; 34 | } 35 | } 36 | cin >> tt; 37 | for (int t = 1; t <= tt; ++t) { 38 | test(); 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #716 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int v = 0; 17 | for (int i = 0; i < n; ++i) { 18 | int x; 19 | cin >> x; 20 | int sq = sqrt(x); 21 | v += (sq * sq == x); 22 | } 23 | if (v == n) { 24 | cout << "NO\n"; 25 | } else { 26 | cout << "YES\n"; 27 | } 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #716 (Div. 2)/E.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #716 (Div. 2)/E.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #719 (Div. 3)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | string s; 16 | cin >> n >> s; 17 | vector done(26); 18 | for (int i = 0, j = 0; i < n; i = j) { 19 | while (j < n and s[i] == s[j]) ++j; 20 | if (done[s[i] - 'A']) { 21 | cout << "NO\n"; 22 | return; 23 | } 24 | done[s[i] - 'A'] = 1; 25 | } 26 | cout << "YES\n"; 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | for (int t = 1; t <= tt; ++t) { 36 | test(); 37 | } 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #719 (Div. 3)/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | vector ans; 14 | 15 | void test(){ 16 | int n; 17 | cin >> n; 18 | cout << upper_bound(all(ans), n) - ans.begin() << '\n'; 19 | return; 20 | } 21 | 22 | int32_t main(){ 23 | ios::sync_with_stdio(false); 24 | cin.tie(NULL); 25 | 26 | for (int i = 1; i <= 9; ++i) { 27 | int cur = 0; 28 | for (int j = 0; j < 11; ++j) { 29 | cur = cur * 10 + i; 30 | ans.push_back(cur); 31 | } 32 | } 33 | sort(all(ans)); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #719 (Div. 3)/D.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n); 17 | map cnt; 18 | for (int i = 0; i < n; ++i) { 19 | cin >> a[i]; 20 | a[i] -= i; 21 | cnt[a[i]]++; 22 | } 23 | int ans = 0; 24 | for (auto [_, e] : cnt) { 25 | ans += e * (e - 1) / 2; 26 | } 27 | cout << ans << '\n'; 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #720 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int a, b; 15 | cin >> a >> b; 16 | if (b == 1) { 17 | cout << "NO\n"; 18 | return; 19 | } 20 | b *= 2; 21 | cout << "YES\n"; 22 | cout << a * (b - 1) << ' ' << a << ' ' << a * b << '\n'; 23 | return; 24 | } 25 | 26 | int32_t main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int tt = 1; 30 | cin >> tt; 31 | for (int t = 1; t <= tt; ++t) { 32 | test(); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #721 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | vector pw; 14 | 15 | void test(){ 16 | int n; 17 | cin >> n; 18 | int ans = 0; 19 | for (int i : pw) { 20 | if (i < n) ans = i; 21 | } 22 | cout << ans << '\n'; 23 | return; 24 | } 25 | 26 | int32_t main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int tt = 1; 30 | for (int i = 0; i < 40; ++i) { 31 | pw.push_back((1LL << i) - 1); 32 | } 33 | cin >> tt; 34 | for (int t = 1; t <= tt; ++t) { 35 | test(); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #721 (Div. 2)/B1.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | string s; 17 | cin >> s; 18 | if (n & 1) { 19 | int cnt = count(all(s), '0'); 20 | if (s[n / 2] == '0' and cnt > 1) { 21 | cout << "ALICE\n"; 22 | } else { 23 | cout << "BOB\n"; 24 | } 25 | return; 26 | } 27 | cout << "BOB\n"; 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #722 (Div. 1)/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 998244353, N = 1e6 + 10; 12 | 13 | int dp[N]; 14 | int f[N]; 15 | 16 | int32_t main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(NULL); 19 | int n; 20 | cin >> n; 21 | 22 | for (int i = 1; i < N; ++i) { 23 | for (int j = i; j < N; j += i) { 24 | f[j]++; 25 | if (f[j] >= MOD) f[j] -= MOD; 26 | } 27 | } 28 | 29 | dp[1] = 1; 30 | int sm = 1; 31 | for (int i = 2; i <= n; ++i) { 32 | dp[i] = f[i] + sm; 33 | if (dp[i] >= MOD) dp[i] -= MOD; 34 | sm += dp[i]; 35 | if (sm >= MOD) sm -= MOD; 36 | } 37 | cout << dp[n] << '\n'; 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #722 (Div. 1)/Div2A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int mn = 100; 17 | vector a(n); 18 | for (int i = 0; i < n; ++i) { 19 | cin >> a[i]; 20 | mn = min(mn, a[i]); 21 | } 22 | cout << n - count(all(a), mn) << '\n'; 23 | return; 24 | } 25 | 26 | int32_t main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int tt = 1; 30 | cin >> tt; 31 | for (int t = 1; t <= tt; ++t) { 32 | test(); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #722 (Div. 1)/Div2B.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #722 (Div. 1)/Div2B.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #723 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | n = n * 2; 17 | vector a(n); 18 | for (int i = 0; i < n; ++i) { 19 | cin >> a[i]; 20 | } 21 | sort(all(a)); 22 | int i = 0, j = n / 2; 23 | while (j < n) { 24 | cout << a[i] << ' ' << a[j] << ' '; 25 | ++i, ++j; 26 | } 27 | cout << '\n'; 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #723 (Div. 2)/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | vector pw; 14 | 15 | void test(){ 16 | int n; 17 | cin >> n; 18 | int t = n / 11; 19 | int rem = n % 11; 20 | if (rem > t / 10) { 21 | cout << "NO\n"; 22 | } else { 23 | cout << "YES\n"; 24 | } 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | pw.push_back(1); 32 | for (int i = 0; i < 10; ++i) { 33 | pw.push_back(pw.back() * 10); 34 | } 35 | int tt = 1; 36 | cin >> tt; 37 | for (int t = 1; t <= tt; ++t) { 38 | test(); 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #723 (Div. 2)/C1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #723 (Div. 2)/C1.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #725 (Div. 3)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n); 17 | for (int i = 0; i < n; ++i) { 18 | cin >> a[i]; 19 | } 20 | int mx = max_element(all(a)) - a.begin(); 21 | int mn = min_element(all(a)) - a.begin(); 22 | if (mn > mx) { 23 | swap(mn, mx); 24 | } 25 | cout << min({mx + 1, n - mn, mn + 1 + n - mx}) << '\n'; 26 | return; 27 | } 28 | 29 | int32_t main(){ 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | int tt = 1; 33 | cin >> tt; 34 | for (int t = 1; t <= tt; ++t) { 35 | test(); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #725 (Div. 3)/E__Good.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #725 (Div. 3)/E__Good.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #725 (Div. 3)/G__Generator.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9, N = 1e5 + 10; 12 | 13 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 14 | int getRand(int l, int r){ 15 | uniform_int_distribution uid(l, r); 16 | return uid(rng); 17 | } 18 | 19 | int32_t main(){ 20 | ios::sync_with_stdio(false); 21 | cin.tie(NULL); 22 | cout << 1 << '\n'; 23 | cout << getRand(1, MOD) << ' ' << getRand(1, MOD) << ' ' << getRand(1, 100) << ' ' << getRand(1, 100) << '\n'; 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #725 (Div. 3)/find.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | bool is_prime (int x) { 14 | if (x < 2 or (x > 2 and x % 2 == 0)) return false; 15 | for (int i = 3; i * i <= x; i += 2) { 16 | if (x % i == 0) { 17 | return false; 18 | } 19 | } 20 | return true; 21 | } 22 | 23 | int32_t main(){ 24 | ios::sync_with_stdio(false); 25 | cin.tie(NULL); 26 | cout << 10000 << '\n'; 27 | for (int i = 1; i <= 10000; ++i) { 28 | cout << 999999937 << ' ' << 999999937 << ' ' << 100 << '\n'; 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #726 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n); 17 | int sm = 0; 18 | for (int i = 0; i < n; ++i) { 19 | cin >> a[i]; 20 | sm += a[i]; 21 | } 22 | if (sm >= n) { 23 | cout << sm - n << '\n'; 24 | } else { 25 | cout << 1 << '\n'; 26 | } 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | for (int t = 1; t <= tt; ++t) { 36 | test(); 37 | } 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #726 (Div. 2)/D_chk.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e4 + 10; 12 | 13 | int win[N]; 14 | 15 | int32_t main(){ 16 | ios::sync_with_stdio(false); 17 | cin.tie(NULL); 18 | win[1] = 0; 19 | for (int i = 2; i < N; ++i) { 20 | for (int j = 2; j < i; ++j) { 21 | if (i % j == 0 and win[i - j] == 0) { 22 | win[i] = 1; 23 | } 24 | } 25 | if ((i & (i - 1)) == 0) { 26 | cout << i << ' ' << win[i] << '\n'; 27 | } else { 28 | if (i % 2 == 0) { 29 | assert(win[i]); 30 | } else { 31 | assert(!win[i]); 32 | } 33 | } 34 | 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #726 (Div. 2)/E1.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, k; 17 | cin >> n >> k; 18 | string s; 19 | cin >> s; 20 | string ans = ""; 21 | while (!s.empty()) { 22 | string res = ""; 23 | while (res.length() < k) { 24 | res += s; 25 | } 26 | while (res.length() > k) res.pop_back(); 27 | if (ans.empty()) { 28 | ans = res; 29 | } 30 | if (res < ans) { 31 | ans = res; 32 | } 33 | s.pop_back(); 34 | } 35 | cout << ans << '\n'; 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #727 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, x, t; 15 | cin >> n >> x >> t; 16 | int one = min(n - 1, t / x); 17 | int ans = (n - 1 - one) * one; 18 | ans += one * (one + 1) / 2; 19 | cout << ans << '\n'; 20 | return; 21 | } 22 | 23 | int32_t main(){ 24 | ios::sync_with_stdio(false); 25 | cin.tie(NULL); 26 | int tt = 1; 27 | cin >> tt; 28 | for (int t = 1; t <= tt; ++t) { 29 | test(); 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #727 (Div. 2)/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n, q; 17 | cin >> n >> q; 18 | vector> cnt(n + 1, vector(26)); 19 | string s; 20 | cin >> s; 21 | for (int i = 1; i <= n; ++i) { 22 | cnt[i] = cnt[i - 1]; 23 | cnt[i][s[i - 1] - 'a']++; 24 | } 25 | while (q--) { 26 | int l, r; 27 | cin >> l >> r; 28 | int ans = 0; 29 | for (int i = 0; i < 26; ++i) { 30 | ans += (cnt[r][i] - cnt[l - 1][i]) * (i + 1); 31 | } 32 | cout << ans << '\n'; 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #727 (Div. 2)/E.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #727 (Div. 2)/E.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #727 (Div. 2)/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #727 (Div. 2)/F.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #729 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #729 (Div. 2)/A.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #729 (Div. 2)/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, a, b; 15 | cin >> n >> a >> b; 16 | int val = 17 | for (int i = 0; i < 60; ++i) { 18 | 19 | } 20 | return; 21 | } 22 | 23 | int32_t main(){ 24 | ios::sync_with_stdio(false); 25 | cin.tie(NULL); 26 | int tt = 1; 27 | cin >> tt; 28 | for (int t = 1; t <= tt; ++t) { 29 | test(); 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #729 (Div. 2)/C.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #729 (Div. 2)/C.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #729 (Div. 2)/E1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #729 (Div. 2)/E1.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #729 (Div. 2)/E2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #729 (Div. 2)/E2.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #730 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int a, b; 15 | cin >> a >> b; 16 | cout << abs(a - b) << ' '; 17 | if (a == b) { 18 | cout << 0 << '\n'; 19 | return; 20 | } 21 | int mn = min(a, b); 22 | int d = abs(a - b); 23 | cout << min(mn % d, d - mn % d) << '\n'; 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | for (int t = 1; t <= tt; ++t) { 33 | test(); 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #730 (Div. 2)/D1.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | // #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e4; 12 | 13 | int dp[N][N]; 14 | 15 | void test(){ 16 | int n, k; 17 | cin >> n >> k; 18 | cout << 0 << endl; 19 | int r; 20 | cin >> r; 21 | // assert(false); 22 | if (r == 1) return; 23 | for (int i = 1; i < n; ++i) { 24 | cout << (i ^ (i - 1)) << endl; 25 | cin >> r; 26 | if (r == 1) return; 27 | } 28 | assert(false); 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | for (int t = 1; t <= tt; ++t) { 38 | test(); 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #730 (Div. 2)/E.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Codeforces Round #730 (Div. 2)/E.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #731 (Div. 3)/D.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n); 17 | for (int &i : a) cin >> i; 18 | cout << 0 << ' '; 19 | for (int i = 1; i < n; ++i) { 20 | int v = a[i] & a[i - 1]; 21 | cout << a[i - 1] - v << ' '; 22 | a[i] ^= (a[i - 1] - v); 23 | // debug(a); 24 | } 25 | cout << '\n'; 26 | return; 27 | } 28 | 29 | int32_t main(){ 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | int tt = 1; 33 | cin >> tt; 34 | for (int t = 1; t <= tt; ++t) { 35 | test(); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #733 (Div. 1 + Div. 2, based on VK Cup 2021 - Elimination (Engine))/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | string s; 15 | cin >> s; 16 | cout << *max_element(all(s)) << '\n'; 17 | return; 18 | } 19 | 20 | int32_t main(){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | int tt = 1; 24 | cin >> tt; 25 | for (int t = 1; t <= tt; ++t) { 26 | test(); 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #734 (Div. 3)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int v = n / 3; 17 | if (n % 3 == 2) { 18 | cout << v << ' ' << v + 1 << '\n'; 19 | } else if (n % 3 == 1) { 20 | cout << v + 1 << ' ' << v << '\n'; 21 | } else { 22 | cout << v << ' ' << v << '\n'; 23 | } 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | for (int t = 1; t <= tt; ++t) { 33 | test(); 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #735 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n); 17 | for (int i = 0; i < n; ++i) { 18 | cin >> a[i]; 19 | } 20 | int ans = 0; 21 | for (int i = 1; i < n; ++i) { 22 | ans = max(ans, a[i] * a[i - 1]); 23 | } 24 | cout << ans << '\n'; 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | int tt = 1; 32 | cin >> tt; 33 | for (int t = 1; t <= tt; ++t) { 34 | test(); 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #735 (Div. 2)/D.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | string ans = ""; 15 | int n; 16 | cin >> n; 17 | int rem = n; 18 | int oth = n / 2; 19 | for (int i = 0; i < oth; ++i) { 20 | ans += 'a'; 21 | } 22 | ans += 'b'; 23 | for (int i = 0; i < oth - 1; ++i) { 24 | ans += 'a'; 25 | } 26 | while (ans.size() < n) { 27 | ans += 'd'; 28 | } 29 | cout << ans << '\n'; 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | for (int t = 1; t <= tt; ++t) { 39 | test(); 40 | } 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #736 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int p; 15 | cin >> p; 16 | for (int i = 2; i <= 100; ++i) { 17 | for (int j = i + 1; j <= 100; ++j) { 18 | if (p % i == p % j) { 19 | cout << i << ' ' << j << '\n'; 20 | return; 21 | } 22 | } 23 | } 24 | assert(false); 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | int tt = 1; 32 | cin >> tt; 33 | for (int t = 1; t <= tt; ++t) { 34 | test(); 35 | } 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Codeforces Round #738 (Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int val = -1; 17 | for (int i = 0, x; i < n; ++i) { 18 | cin >> x; 19 | if (val == -1) { 20 | val = x; 21 | } else { 22 | val &= x; 23 | } 24 | } 25 | cout << val << '\n'; 26 | return; 27 | } 28 | 29 | int32_t main(){ 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | int tt = 1; 33 | cin >> tt; 34 | for (int t = 1; t <= tt; ++t) { 35 | test(); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int ans = 0; 17 | while (n >= 2050) { 18 | int r = 2050; 19 | while (r <= n / 10) { 20 | r *= 10; 21 | } 22 | n -= r; 23 | ++ans; 24 | } 25 | if (n != 0) { 26 | ans = -1; 27 | } 28 | cout << ans << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | for (int t = 1; t <= tt; ++t) { 38 | test(); 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)/E.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)/E.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)/F.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)/G.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)/G.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)/H.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)/H.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/D.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/D.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/E.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/E.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/F.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/G.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/G.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/H.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2)/H.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 101/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> s; 21 | n = s.length(); 22 | if (n & 1) { 23 | cout << "NO\n"; 24 | return; 25 | } 26 | if (s.front() == ')' or s.back() == '(') { 27 | cout << "NO\n"; 28 | } else { 29 | cout << "YES\n"; 30 | } 31 | return; 32 | } 33 | 34 | int32_t main(){ 35 | ios::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | int tt = 1; 38 | cin >> tt; 39 | f(i,0,tt) test(); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 102/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, d; 15 | cin >> n >> d; 16 | vector a(n); 17 | for (int i = 0; i < n; ++i) cin >> a[i]; 18 | sort(all(a)); 19 | for (int i = 2; i < n; ++i) { 20 | a[i] = min(a[i], a[0] + a[1]); 21 | } 22 | sort(all(a)); 23 | if (a.back() <= d) { 24 | cout << "YES\n"; 25 | } else { 26 | cout << "NO\n"; 27 | } 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 102/c.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, k; 15 | cin >> n >> k; 16 | vector a(k); 17 | iota(all(a), 1); 18 | int d = n - k; 19 | reverse(a.begin() + k - d - 1, a.end()); 20 | for (int i : a) { 21 | cout << i << ' '; 22 | } 23 | cout << '\n'; 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | for (int t = 1; t <= tt; ++t) { 33 | test(); 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 103/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, k; 15 | cin >> n >> k; 16 | int sm1 = ((n + k - 1) / k) * k; 17 | cout << (sm1 + n - 1) / n << '\n'; 18 | return; 19 | } 20 | 21 | int32_t main(){ 22 | ios::sync_with_stdio(false); 23 | cin.tie(NULL); 24 | int tt = 1; 25 | cin >> tt; 26 | for (int t = 1; t <= tt; ++t) { 27 | test(); 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 104/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n); 17 | for (int &i : a) { 18 | cin >> i; 19 | } 20 | sort(all(a)); 21 | int ans = n; 22 | int i = 0; 23 | while (i < n and a[i] == a[0]) { 24 | ++i; 25 | --ans; 26 | } 27 | cout << ans << '\n'; 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | for (int t = 1; t <= tt; ++t) { 37 | test(); 38 | } 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 104/d.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | vector P; 14 | 15 | void test(){ 16 | int n; 17 | cin >> n; 18 | cout << (upper_bound(all(P), n) - begin(P)) << '\n'; 19 | return; 20 | } 21 | 22 | int32_t main(){ 23 | ios::sync_with_stdio(false); 24 | cin.tie(NULL); 25 | int tt = 1; 26 | int n = 3; 27 | const int INF = 3e9; 28 | while (n * n <= 3e9) { 29 | P.push_back(max({(n * n - 1) / 2, 1 + (n * n - 1) / 2, n})); 30 | n += 2; 31 | } 32 | sort(all(P)); 33 | cin >> tt; 34 | for (int t = 1; t <= tt; ++t) { 35 | test(); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 107 (Rated for Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | int ans = 0; 17 | for (int i = 0; i < n; ++i) { 18 | int x; 19 | cin >> x; 20 | ans += (x != 2); 21 | } 22 | cout << ans << '\n'; 23 | return; 24 | } 25 | 26 | int32_t main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int tt = 1; 30 | cin >> tt; 31 | for (int t = 1; t <= tt; ++t) { 32 | test(); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 107 (Rated for Div. 2)/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Educational Codeforces Round 107 (Rated for Div. 2)/F.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 107 (Rated for Div. 2)/G.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Educational Codeforces Round 107 (Rated for Div. 2)/G.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 108 (Rated for Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int r, b, d; 15 | cin >> r >> b >> d; 16 | int df = abs(r - b); 17 | if (df <= d * min(r, b)) { 18 | cout << "YES\n"; 19 | } else { 20 | cout << "NO\n"; 21 | } 22 | return; 23 | } 24 | 25 | int32_t main(){ 26 | ios::sync_with_stdio(false); 27 | cin.tie(NULL); 28 | int tt = 1; 29 | cin >> tt; 30 | for (int t = 1; t <= tt; ++t) { 31 | test(); 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 108 (Rated for Div. 2)/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, m, k; 15 | cin >> n >> m >> k; 16 | int cst = (n - 1) * 1 + (m - 1) * n; 17 | if (cst == k) { 18 | cout << "YES\n"; 19 | } else { 20 | cout << "NO\n"; 21 | } 22 | return; 23 | } 24 | 25 | int32_t main(){ 26 | ios::sync_with_stdio(false); 27 | cin.tie(NULL); 28 | int tt = 1; 29 | cin >> tt; 30 | for (int t = 1; t <= tt; ++t) { 31 | test(); 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 108 (Rated for Div. 2)/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Educational Codeforces Round 108 (Rated for Div. 2)/F.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 109 (Rated for Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int k; 15 | cin >> k; 16 | int v = gcd(k, 100 - k); 17 | int ans = k / v + (100 - k) / v; 18 | cout << ans << '\n'; 19 | return; 20 | } 21 | 22 | int32_t main(){ 23 | ios::sync_with_stdio(false); 24 | cin.tie(NULL); 25 | int tt = 1; 26 | cin >> tt; 27 | for (int t = 1; t <= tt; ++t) { 28 | test(); 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 109 (Rated for Div. 2)/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Educational Codeforces Round 109 (Rated for Div. 2)/F.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 110 (Rated for Div. 2)/F.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/Educational Codeforces Round 110 (Rated for Div. 2)/F.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 111 (Rated for Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int s; 15 | cin >> s; 16 | int ans = sqrt(s); 17 | ans += (ans * ans != s); 18 | cout << ans << '\n'; 19 | return; 20 | } 21 | 22 | int32_t main(){ 23 | ios::sync_with_stdio(false); 24 | cin.tie(NULL); 25 | int tt = 1; 26 | cin >> tt; 27 | for (int t = 1; t <= tt; ++t) { 28 | test(); 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 86/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int x,y,a,b; 15 | cin >> x >> y >> a >> b; 16 | int mn = min(x,y); 17 | int ans = min(a*x+a*y,mn*b+(x-mn)*a+(y-mn)*a); 18 | cout << ans << '\n'; 19 | return; 20 | } 21 | 22 | int32_t main(){ 23 | ios::sync_with_stdio(false); 24 | cin.tie(NULL); 25 | int tt = 1; 26 | cin >> tt; 27 | f(i,0,tt) test(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 86/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | string t; 15 | cin >> t; 16 | int n = t.length(); 17 | if(count(all(t),'1') == n){ 18 | cout << t << '\n'; 19 | return; 20 | } 21 | if(count(all(t),'0') == n){ 22 | cout << t << '\n'; 23 | return; 24 | } 25 | f(i,0,n){ 26 | cout << "10"; 27 | } 28 | cout << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | f(i,0,tt) test(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 88/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define int ll 7 | #define f(i,x,n) for(int i=x;i> n >> m >> k; 21 | int crd = n/k; 22 | if(m<=crd){ 23 | cout << m << '\n'; 24 | return; 25 | } 26 | int left = m-crd; 27 | int mx = (left+k-2)/(k-1); 28 | debug(mx,left); 29 | cout << crd-mx << '\n'; 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | f(i,0,tt) test(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 90/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> a >> b >> c; 20 | if(a < c){ 21 | cout << 1 << ' '; 22 | }else{ 23 | cout << -1 << ' '; 24 | } 25 | int cst = a*b; 26 | if(c < cst){ 27 | cout << b << ' '; 28 | }else{ 29 | cout << -1 << ' '; 30 | } 31 | cout << '\n'; 32 | return; 33 | } 34 | 35 | int32_t main(){ 36 | ios::sync_with_stdio(false); 37 | cin.tie(NULL); 38 | int tt = 1; 39 | cin >> tt; 40 | f(i,0,tt) test(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 90/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> s; 20 | int c0 = count(all(s),'0'); 21 | int c1 = count(all(s),'1'); 22 | int mn = min(c0,c1); 23 | if(mn & 1){ 24 | cout << "DA\n"; 25 | }else{ 26 | cout << "NET\n"; 27 | } 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | f(i,0,tt) test(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 92/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> l >> r; 20 | if(2*l <= r){ 21 | cout << l << ' ' << 2*l << '\n'; 22 | }else{ 23 | cout << "-1 -1\n"; 24 | } 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | int tt = 1; 32 | cin >> tt; 33 | f(i,0,tt) test(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 93/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector a(n); 21 | for(int i = 0; i < n; ++i){ 22 | cin >> a[i]; 23 | } 24 | if(a[n-1] >= a[0]+a[1]){ 25 | cout << 1 << ' ' << 2 << ' ' << n << '\n'; 26 | }else{ 27 | cout << "-1\n"; 28 | } 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | f(i,0,tt) test(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 93/c.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | string s; 21 | cin >> s; 22 | int cur = 0; 23 | map cnt; 24 | cnt[0]++; 25 | int ans = 0; 26 | for(int i = 1; i <= s.length(); ++i){ 27 | cur += (s[i-1]-'0'); 28 | ans += cnt[cur-i]; 29 | cnt[cur-i]++; 30 | } 31 | cout << ans << '\n'; 32 | return; 33 | } 34 | 35 | int32_t main(){ 36 | ios::sync_with_stdio(false); 37 | cin.tie(NULL); 38 | int tt = 1; 39 | cin >> tt; 40 | f(i,0,tt) test(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 94/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | string s; 21 | cin >> s; 22 | int m = (2*n-1)/2; 23 | for(int i = 0; i < n; ++i){ 24 | cout << s[m]; 25 | } 26 | cout << '\n'; 27 | return; 28 | } 29 | 30 | int32_t main(){ 31 | ios::sync_with_stdio(false); 32 | cin.tie(NULL); 33 | int tt = 1; 34 | cin >> tt; 35 | f(i,0,tt) test(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 95/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> x >> y >> k; 20 | int req = k-1+y*k; 21 | int op = (req+x-2)/(x-1)+k; 22 | cout << op << '\n'; 23 | return; 24 | } 25 | 26 | int32_t main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int tt = 1; 30 | cin >> tt; 31 | f(i,0,tt) test(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 96/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n >> k; 20 | vector A(n); 21 | 22 | for(int i = 0; i < n; ++i) { 23 | cin >> A[i]; 24 | } 25 | sort(all(A)); 26 | for(int i = n-2; i >= 0 and k; --i) { 27 | A[n-1] += A[i]; 28 | --k; 29 | } 30 | cout << A[n-1] << '\n'; 31 | return; 32 | } 33 | 34 | int32_t main(){ 35 | ios::sync_with_stdio(false); 36 | cin.tie(NULL); 37 | int tt = 1; 38 | cin >> tt; 39 | f(i,0,tt) test(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 97/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> l >> r; 20 | if(r/2 >= l) { 21 | cout << "NO\n"; 22 | } else { 23 | cout << "YES\n"; 24 | } 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | int tt = 1; 32 | cin >> tt; 33 | f(i,0,tt) test(); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 98/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "\Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> x >> y; 20 | if (x == y) { 21 | cout << x + y << '\n'; 22 | return; 23 | } 24 | cout << x + y + max(x, y) - min(x, y) - 1 << '\n'; 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | int tt = 1; 32 | cin >> tt; 33 | f(i,0,tt) test(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 99/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> s; 20 | cout << s.length() << '\n'; 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 99/b.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | int c = 0; 21 | while (c * (c + 1) / 2 < n) { 22 | ++c; 23 | } 24 | c += ((c * (c + 1) / 2) - n == 1); 25 | cout << c << '\n'; 26 | return; 27 | } 28 | 29 | int32_t main(){ 30 | ios::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | int tt = 1; 33 | cin >> tt; 34 | f(i,0,tt) test(); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Educational Codeforces Round 99/c.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> x >> y; 20 | cout << x - 1 << ' ' << y << '\n'; 21 | return; 22 | } 23 | 24 | int32_t main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(NULL); 27 | int tt = 1; 28 | cin >> tt; 29 | f(i,0,tt) test(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Contest/Codeforces/Global Round 10/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n; 20 | vector a(n); 21 | for(int i = 0; i < n; ++i){ 22 | cin >> a[i]; 23 | } 24 | sort(all(a)); 25 | if(a[0] == a[n-1]){ 26 | cout << n << '\n'; 27 | }else{ 28 | cout << "1\n"; 29 | } 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt; 38 | f(i,0,tt) test(); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Contest/Codeforces/Harbour.Space Scholarship Contest 2021-2022 (open for everyone, rated, Div. 1 + Div. 2)/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | cout << (n + 1) / 10 << '\n'; 17 | return; 18 | } 19 | 20 | int32_t main(){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(NULL); 23 | int tt = 1; 24 | cin >> tt; 25 | for (int t = 1; t <= tt; ++t) { 26 | test(); 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contest/Codeforces/upsolves/1501A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n), b(n); 17 | for (int i = 0; i < n; ++i) { 18 | cin >> a[i] >> b[i]; 19 | } 20 | vector t(n); 21 | for (int i = 0; i < n; ++i) { 22 | cin >> t[i]; 23 | } 24 | int cur 25 | for (int i = 0; i + 1 < n; ++i) { 26 | 27 | } 28 | 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | for (int t = 1; t <= tt; ++t) { 38 | test(); 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Codeforces/upsolves/1509A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n; 15 | cin >> n; 16 | vector a(n); 17 | for (int &i : a) cin >> i; 18 | sort(all(a), [&](int x, int y){ 19 | return x % 2 < y % 2; 20 | }); 21 | for (int i : a) cout << i << ' '; 22 | cout << '\n'; 23 | return; 24 | } 25 | 26 | int32_t main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int tt = 1; 30 | cin >> tt; 31 | for (int t = 1; t <= tt; ++t) { 32 | test(); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Codeforces/upsolves/1528D.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 600 + 10; 12 | 13 | int g[N][N]; 14 | vector> edges; 15 | 16 | int32_t main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(NULL); 19 | int n, m; 20 | cin >> n >> m; 21 | for (int i = 0; i < m; ++i) { 22 | int a, b, c; 23 | cin >> a >> b >> c; 24 | g[a][b] = c; 25 | edges.push_back({a, b, c}); 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Contest/Codeforces/upsolves/1546B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | int n, m; 15 | cin >> n >> m; 16 | n = 2 * n - 1; 17 | string res(m, 0); 18 | for (int i = 0; i < n; ++i) { 19 | string s; 20 | cin >> s; 21 | for (int j = 0; j < m; ++j) res[j] ^= s[j]; 22 | } 23 | cout << res << endl; 24 | return; 25 | } 26 | 27 | int32_t main(){ 28 | ios::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int tt = 1; 31 | cin >> tt; 32 | for (int t = 1; t <= tt; ++t) { 33 | test(); 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Contest/Codeforces/upsolves/334118A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | string s; 17 | cin >> s; 18 | int ans[2] = {0, 0}; 19 | for (char c : s) { 20 | ans[(c - '0') & 1] += (c - '0'); 21 | } 22 | cout << ans[0] << ' ' << ans[1] << '\n'; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Contest/Codeforces/upsolves/334118C.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int n; 17 | cin >> n; 18 | vector r; 19 | for (int i = 0; i < n; ++i) { 20 | string s; 21 | cin >> s; 22 | int mx = *max_element(all(s)) - '0'; 23 | r.push_back(mx); 24 | } 25 | sort(all(r), greater()); 26 | int ans = 0; 27 | int d; 28 | cin >> d; 29 | for (int i = 0; i < d; ++i) { 30 | ans += r[i]; 31 | } 32 | cout << ans << '\n'; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Contest/Codeforces/upsolves/979A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int64_t n; 5 | std::cin >> n; 6 | if (n == 0) { 7 | std::cout << 0 << '\n'; 8 | } else if (n & 1) { 9 | std::cout << (n + 1) / 2 << '\n'; 10 | } else { 11 | std::cout << n + 1 << '\n'; 12 | } 13 | } -------------------------------------------------------------------------------- /Contest/Codeforces/upsolves/K.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prateeksharma21/Competitive-Programming/66881adf7bbdb53bf519f5d873d91fe5a9db3deb/Contest/Codeforces/upsolves/K.cpp -------------------------------------------------------------------------------- /Contest/Codeforces/upsolves/test.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | 15 | return; 16 | } 17 | 18 | int32_t main(){ 19 | ios::sync_with_stdio(false); 20 | cin.tie(NULL); 21 | int tt = 1; 22 | cin >> tt; 23 | for (int t = 1; t <= tt; ++t) { 24 | test(); 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Contest/Codejam/Round_2/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int n; 14 | 15 | void test(){ 16 | for (int i = 1; i < n; ++i) { 17 | cout << "M " << i << ' ' << n << endl; 18 | int x; 19 | cin >> x; 20 | if (x != i) { 21 | cout << "S " << i << ' ' << x << endl; 22 | cin >> x; 23 | assert(x == 1); 24 | } 25 | } 26 | cout << "D" << endl; 27 | int x; 28 | cin >> x; 29 | assert(x == 1); 30 | return; 31 | } 32 | 33 | int32_t main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(NULL); 36 | int tt = 1; 37 | cin >> tt >> n; 38 | for (int t = 1; t <= tt; ++t) { 39 | test(); 40 | } 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Contest/Codejam/Round_2/A_chk.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e8, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | double v = 0; 17 | for (int i = 1; i <= 100; ++i) { 18 | v += (MOD + i - 1) / i; 19 | } 20 | debug(v); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Contest/Codejam/Round_2/Brute.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e3 + 10; 12 | 13 | int dp[N][N]; 14 | 15 | int32_t main(){ 16 | ios::sync_with_stdio(false); 17 | cin.tie(NULL); 18 | for (int i = 3; i < N; ++i) { 19 | for (int j = 3; j <= i; ++j) { 20 | for (int k = 3; k < N; ++k) { 21 | if (dp[]) 22 | } 23 | } 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Contest/Kickstart/2020/RoundB/a.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int tt; 17 | cin >> tt; 18 | f(_,1,tt+1){ 19 | cout << "Case #" << _ << ": "; 20 | int n; 21 | cin >> n; 22 | vector a(n); 23 | f(i,0,n){ 24 | cin >> a[i]; 25 | } 26 | int ans = 0; 27 | f(i,1,n-1){ 28 | if(a[i]>a[i-1] and a[i]>a[i+1]) ans++; 29 | } 30 | cout << ans << '\n'; 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Contest/Kickstart/2020/RoundB/b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define F first 4 | #define S second 5 | #define pb push_back 6 | #define f(i,x,n) for(int i=x;i; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int tt; 17 | cin >> tt; 18 | f(_,1,tt+1){ 19 | cout << "Case #" << _ << ": "; 20 | int n,d; 21 | cin >> n >> d; 22 | vector a(n); 23 | f(i,0,n){ 24 | cin >> a[i]; 25 | } 26 | int nxt = d; 27 | for(int i=n-1;i>=0;i--){ 28 | int k = nxt/a[i]; 29 | a[i] = k*a[i]; 30 | nxt = a[i]; 31 | } 32 | cout << a[0] << '\n'; 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Contest/Kickstart/2021/RoundA/a.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define F first 9 | #define S second 10 | #define pb push_back 11 | #define int ll 12 | #define f(i,x,n) for(int i=x;i> n >> k; 20 | string s; 21 | cin >> s; 22 | int good = 0; 23 | for (int i = 0; i < n; ++i) { 24 | good += (s[i] != s[n - i - 1]); 25 | } 26 | good /= 2; 27 | cout << abs(good - k) << '\n'; 28 | return; 29 | } 30 | 31 | int32_t main(){ 32 | ios::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | int tt = 1; 35 | cin >> tt; 36 | f(i,0,tt){ 37 | cout << "Case #" << i+1 << ": "; 38 | test(); 39 | } 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Contest/Kickstart/2021/RoundA/chk.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | int32_t main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(NULL); 16 | int v = 0; 17 | for (int i = 1; i <= 3; ++i) { 18 | for (int j = 1; j <= 3; ++j) { 19 | for (int k = 1; k <= 3; ++k) { 20 | for (int l = 1; l <= 3; ++l) { 21 | if ((i + j + k + l) & 1) { 22 | ++v; 23 | } 24 | } 25 | } 26 | } 27 | } 28 | cout << v << '\n'; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Contest/Kickstart/2021/RoundB/A.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void Solve() { 14 | int n; 15 | cin >> n; 16 | string s; 17 | cin >> s; 18 | cout << 1 << ' '; 19 | int cur = 1; 20 | for (int i = 1; i < n; ++i) { 21 | if (s[i] > s[i - 1]) { 22 | ++cur; 23 | } else { 24 | cur = 1; 25 | } 26 | cout << cur << ' '; 27 | } 28 | cout << '\n'; 29 | return; 30 | } 31 | 32 | int32_t main(){ 33 | ios::sync_with_stdio(false); 34 | cin.tie(NULL); 35 | int tt = 1; 36 | cin >> tt; 37 | for (int t = 1; t <= tt; ++t) { 38 | cout << "Case #" << t << ": "; 39 | Solve(); 40 | } 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Contest/Kickstart/2021/RoundC/B.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 2e6 + 10; 12 | 13 | void Solve() { 14 | int g; 15 | cin >> g; 16 | int sum = 0, ans = 0; 17 | for (int i = 0; sum + i < g; ++i) { 18 | sum += i; 19 | int rem = g - sum; 20 | if (rem % (i + 1) == 0) { 21 | ++ans; 22 | } 23 | } 24 | cout << ans << '\n'; 25 | return; 26 | } 27 | 28 | int32_t main(){ 29 | ios::sync_with_stdio(false); 30 | cin.tie(NULL); 31 | int tt = 1; 32 | cin >> tt; 33 | for (int t = 1; t <= tt; ++t) { 34 | cout << "Case #" << t << ": "; 35 | Solve(); 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Library/Bridge.cpp: -------------------------------------------------------------------------------- 1 | int n; 2 | vector> adj; 3 | 4 | vector visited; 5 | vector tin, low; 6 | int timer; 7 | 8 | void IS_BRIDGE(int u, int v) { 9 | // processes the bridge multiple times 10 | } 11 | 12 | void dfs(int v, int p = -1) { 13 | visited[v] = true; 14 | tin[v] = low[v] = timer++; 15 | for (int to : adj[v]) { 16 | if (to == p) continue; 17 | if (visited[to]) { 18 | low[v] = min(low[v], tin[to]); 19 | } else { 20 | dfs(to, v); 21 | low[v] = min(low[v], low[to]); 22 | if (low[to] > tin[v]) 23 | IS_BRIDGE(v, to); 24 | } 25 | } 26 | } 27 | 28 | void find_bridges() { 29 | timer = 0; 30 | visited.assign(n, false); 31 | tin.assign(n, -1); 32 | low.assign(n, -1); 33 | for (int i = 0; i < n; ++i) { 34 | if (!visited[i]) 35 | dfs(i); 36 | } 37 | } -------------------------------------------------------------------------------- /Library/Fast.cpp: -------------------------------------------------------------------------------- 1 | #pragma GCC target("avx2") 2 | #pragma GCC optimization("O3") 3 | #pragma GCC optimization("unroll-loops") 4 | #pragma GCC optimize("Ofast") 5 | #pragma GCC target("avx,avx2,fma") 6 | #pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline") //Optimization flags 7 | #pragma GCC option("arch=native", "tune=native", "no-zero-upper") //Enable AVX -------------------------------------------------------------------------------- /Library/Fenwick_Tree.cpp: -------------------------------------------------------------------------------- 1 | template 2 | struct Fenwick{ 3 | int n; 4 | vector bit; 5 | 6 | Fenwick(int n){ 7 | this->n = n; 8 | bit.assign(n,0); 9 | } 10 | 11 | Fenwick(vector a) : Fenwick((int)a.size()){ 12 | for(int i = 0; i < int(a.size()); ++i){ 13 | update(i,a[i]); 14 | } 15 | } 16 | 17 | T query(int r){ 18 | T res = 0; 19 | while(r>=0){ 20 | res += bit[r]; 21 | r = r&(r+1); 22 | r--; 23 | } 24 | return res; 25 | } 26 | 27 | T query(int l,int r){ 28 | return query(r)-query(l-1); 29 | } 30 | 31 | void update(int i,T val){ 32 | while(i < n){ 33 | bit[i] += val; 34 | i = i | (i+1); 35 | } 36 | } 37 | 38 | void range_add(int l,int r,T val){ 39 | update(l,val); 40 | update(r+1,-val); 41 | } 42 | }; -------------------------------------------------------------------------------- /Library/KMP.cpp: -------------------------------------------------------------------------------- 1 | vector prefix_fun(const string &s){ 2 | int n = s.size(); 3 | vector PI(n); 4 | for(int i = 1; i < n; ++i){ 5 | int j = PI[i-1]; 6 | while(j and s[i] != s[j]){ 7 | j = PI[j-1]; 8 | } 9 | if(s[i] == s[j]) j++; 10 | PI[i] = j; 11 | } 12 | return PI; 13 | } 14 | 15 | vector KMP(const string &s, const string &t){ 16 | int n = s.size(), m = t.size(); 17 | string r = t+"#"+s; 18 | vector PI = prefix_fun(r); 19 | int l = r.length(); 20 | vector occ; 21 | for(int i = m+1; i < l; ++i){ 22 | if(PI[i] == m){ 23 | occ.push_back(i-2*m); 24 | } 25 | } 26 | return occ; 27 | } -------------------------------------------------------------------------------- /Library/Kth_Ancestor.cpp: -------------------------------------------------------------------------------- 1 | int parent[N][LG]; 2 | 3 | void dfs(int u, int p = 0){ 4 | parent[u][0] = p; 5 | for (auto &v : G[u]){ 6 | if (v != p){ 7 | dfs(v, u); 8 | } 9 | } 10 | } 11 | 12 | void precompute(){ 13 | for(int j = 1; j < LG; ++j){ 14 | for(int i = 1; i <= n; ++i){ 15 | if (parent[i][j - 1]){ 16 | parent[i][j] = parent[parent[i][j - 1]][j - 1]; 17 | } 18 | } 19 | } 20 | } 21 | 22 | int kth(int u, int d){ 23 | for (int j = LG - 1; j >= 0; j--){ 24 | if ((1ll << j) <= d){ 25 | u = parent[u][j]; 26 | d -= (1ll << j); 27 | } 28 | } 29 | return u; 30 | } -------------------------------------------------------------------------------- /Library/Manacher.cpp: -------------------------------------------------------------------------------- 1 | pair,vector> Manacher(const string & s){ 2 | int n = s.length(); 3 | vector Odd(n); 4 | int l = 0, r = -1; 5 | for(int i = 0; i < n; ++i){ 6 | Odd[i] = 1; 7 | if(i <= r){ 8 | Odd[i] = min(Odd[r-i+l],r-i+1); 9 | } 10 | while(i-Odd[i] >= 0 and i+Odd[i] < n and s[i-Odd[i]] == s[i+Odd[i]]){ 11 | ++Odd[i]; 12 | } 13 | if(i+Odd[i]-1 > r){ 14 | l = i-Odd[i]+1; 15 | r = i+Odd[i]-1; 16 | } 17 | } 18 | vector Even(n); 19 | l = 0, r = -1; 20 | for(int i = 0; i < n; ++i){ 21 | if(i <= r){ 22 | Even[i] = min(Even[r-i+l+1],r-i+1); 23 | } 24 | while(i-Even[i]-1 >= 0 and i+Even[i] < n and s[i-Even[i]-1] == s[i+Even[i]]){ 25 | ++Even[i]; 26 | } 27 | if(i+Even[i]-1 > r){ 28 | l = i-Even[i]; 29 | r = i+Even[i]-1; 30 | } 31 | } 32 | return {Odd,Even}; 33 | } 34 | -------------------------------------------------------------------------------- /Library/Phi.cpp: -------------------------------------------------------------------------------- 1 | // Phi at n: 2 | int phi(int n){ 3 | int res = n; 4 | for(int i = 2; i*i <= n; i++){ 5 | if(n%i == 0){ 6 | while(n % i == 0) n /= i; 7 | res -= res/i; 8 | } 9 | } 10 | if(n > 1){ 11 | res -= res/n; 12 | } 13 | return res; 14 | } 15 | 16 | // Phi from 1 to n: 17 | vector Phi(int n){ 18 | vector phi(n+1); 19 | iota(phi.begin(),phi.end(),0); 20 | for(int i = 2; i <= n; ++i){ 21 | if(phi[i] == i){ 22 | for(int j = i; j <= n; j += i){ 23 | phi[j] -= phi[j] / i; 24 | } 25 | } 26 | } 27 | return phi; 28 | } -------------------------------------------------------------------------------- /Library/Rabin_Karp.cpp: -------------------------------------------------------------------------------- 1 | vector Rabin_Karp(string const &s, string const &t){ 2 | const int p = 29; 3 | const long long MOD = 10000000000129; 4 | int S = s.size(), T = t.size(); 5 | if (S > T) return vector(); 6 | vector pw(T); 7 | pw[0] = 1; 8 | for (int i = 1; i < T; i++){ 9 | pw[i] = pw[i - 1] * p % MOD; 10 | } 11 | vector H(T + 1); 12 | for (int i = 0; i < T; i++){ 13 | H[i + 1] = (H[i] + (t[i] - 'a' + 1) * pw[i]) % MOD; 14 | } 15 | long long hs = 0; 16 | for (int i = 0; i < S; i++){ 17 | hs = (hs + (s[i] - 'a' + 1) * pw[i]) % MOD; 18 | } 19 | vector occurences; 20 | for (int i = 0; i + S - 1 < T; i++){ 21 | long long cur_hs = (H[i + S] - H[i] + MOD) % MOD; 22 | if (cur_hs == (hs * pw[i]) % MOD){ 23 | occurences.push_back(i); 24 | } 25 | } 26 | return occurences; 27 | } 28 | -------------------------------------------------------------------------------- /Library/SparseTable.cpp: -------------------------------------------------------------------------------- 1 | template 2 | class SparseTable { 3 | int n, lg; 4 | vector> st; 5 | 6 | public: 7 | SparseTable (vector a) { 8 | this->n = a.size(); 9 | this->lg = log2(n) + 1; 10 | st = vector>(n, vector(lg)); 11 | for (int i = 0; i < n; ++i) { 12 | st[i][0] = a[i]; 13 | } 14 | compute(); 15 | } 16 | 17 | T op (T a, T b) { 18 | if (max_mode) return max(a, b); 19 | return min(a, b); 20 | } 21 | 22 | void compute() { 23 | for (int j = 1; j < lg; ++j) { 24 | for (int i = 0; i + (1 << j) <= n; ++i) { 25 | st[i][j] = op(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]); 26 | } 27 | } 28 | } 29 | 30 | T query(int l, int r) { 31 | int j = log2(r - l + 1); 32 | return op (st[l][j], st[r - (1 << j) + 1][j]); 33 | } 34 | }; -------------------------------------------------------------------------------- /Library/Z_Function.cpp: -------------------------------------------------------------------------------- 1 | vector z_function(const string &s){ 2 | int n = s.length(); 3 | vector z(n); 4 | for(int i = 1, l = 0, r = 0; i < n; ++i){ 5 | if(i <= r){ 6 | z[i] = min(r - i + 1, z[i - l]); 7 | } 8 | while(i + z[i] < n and s[z[i]] == s[i + z[i]]){ 9 | ++z[i]; 10 | } 11 | if(i + z[i] - 1 > r){ 12 | l = i; 13 | r = i + z[i] - 1; 14 | } 15 | } 16 | return z; 17 | } -------------------------------------------------------------------------------- /Library/to_int.cpp: -------------------------------------------------------------------------------- 1 | int to_int(string s){ 2 | int ans = 0; 3 | for(char c : s) { 4 | ans = ans*10 + (c - '0'); 5 | } 6 | return ans; 7 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Competitive Programming 2 | This Repository contains various Algorithms implementation by me. 3 | -------------------------------------------------------------------------------- /Snippets/snippet.cpp: -------------------------------------------------------------------------------- 1 | #ifdef Prateek 2 | #include "Prateek.h" 3 | #else 4 | #include 5 | using namespace std; 6 | #define debug(...) 42 7 | #endif 8 | #define int ll 9 | #define all(c) begin(c),end(c) 10 | using ll = long long; 11 | const int MOD = 1e9+7, N = 1e5 + 10; 12 | 13 | void test(){ 14 | 15 | return; 16 | } 17 | 18 | int32_t main(){ 19 | ios::sync_with_stdio(false); 20 | cin.tie(NULL); 21 | int tt = 1; 22 | cin >> tt; 23 | for (int t = 1; t <= tt; ++t) { 24 | test(); 25 | } 26 | return 0; 27 | } --------------------------------------------------------------------------------