<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rishit Chaudhary</title>
    <description>The latest articles on DEV Community by Rishit Chaudhary (@rishitc).</description>
    <link>https://dev.to/rishitc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F466786%2F9503df44-20c8-40cb-ad1c-22fb50c6e67b.png</url>
      <title>DEV Community: Rishit Chaudhary</title>
      <link>https://dev.to/rishitc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rishitc"/>
    <language>en</language>
    <item>
      <title>Learning Rust (Part 1 of N)</title>
      <dc:creator>Rishit Chaudhary</dc:creator>
      <pubDate>Mon, 09 Aug 2021 14:55:53 +0000</pubDate>
      <link>https://dev.to/rishitc/using-rust-part-1-of-n-1pmk</link>
      <guid>https://dev.to/rishitc/using-rust-part-1-of-n-1pmk</guid>
      <description>&lt;p&gt;I recently started reading up about the Rust programming language. I've read a lot of cool stuff about it, and I've decided to blog my journey through the process of learning Rust.&lt;/p&gt;

&lt;p&gt;As far as I've read, Rust follows a completely different model, with regards to sharing of variables, with the concept of &lt;em&gt;owner&lt;/em&gt;, &lt;em&gt;borrowing&lt;/em&gt; and &lt;em&gt;shared borrows&lt;/em&gt;. It also statically checks programs for memory leaks and &lt;a href="https://stackoverflow.com/questions/49023664/could-software-written-only-in-rust-fully-avoid-race-conditions#:~:text=Race%20conditions%20are%20not%20memory,processes%2C%20servers%2C%20..."&gt;data race conditions&lt;/a&gt;, so you know your program is free of such insidious bugs, if it compiles successfully.&lt;/p&gt;

&lt;p&gt;I've read that it also gives pleasant helpful error messages. I've dealt with and diagnosed long error logs such as template meta-programming bugs in C++, so I have firsthand experience in being at the receiving end of the compiler vomiting volumes of information at you. I'm curious to see how the Rust compiler's error messages are in terms of their description and accuracy.&lt;/p&gt;

&lt;p&gt;So, at the outset, I've set my learning path as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=PpWR6zungUk&amp;amp;list=PLlrxD0HtieHjbTjrchBwOVks_sr8EVW1x"&gt;The Rust series from Microsoft Developer channel on YouTube&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.manning.com/books/rust-in-action"&gt;Rust In Action - Systems programming concepts and techniques By Tim McNamara&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nostarch.com/Rust2018"&gt;The Rust Programming Language (Covers Rust 2018)
by Steve Klabnik and Carol Nichols&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oreilly.com/library/view/programming-rust-2nd/9781492052586/"&gt;Programming Rust, 2nd Edition
by Jim Blandy, Jason Orendorff, Leonora F.S. Tindall&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I plan to go through each resource sequentially, while also solving all the exercises in each one. I estimate that this whole process would take me about &lt;em&gt;6 months&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;As any curious reader would notice, I've not mentioned the primary resource for Rust: &lt;a href="https://doc.rust-lang.org/book/"&gt;The Book&lt;/a&gt;. I plan to keep this resource as my main reference as I go through the learning process.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Update: (11/08/2021)&lt;/strong&gt;&lt;br&gt;
As noted out by &lt;a class="mentioned-user" href="https://dev.to/vorfeedcanal"&gt;@vorfeedcanal&lt;/a&gt;
, the book &lt;a href="https://nostarch.com/Rust2018"&gt;The Rust Programming Language (Covers Rust 2018)&lt;br&gt;
by Steve Klabnik and Carol Nichols&lt;/a&gt; is actually the printed version of &lt;a href="https://doc.rust-lang.org/book/"&gt;The Book&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
I've decided to refer the &lt;a href="https://doc.rust-lang.org/book/"&gt;The Book&lt;/a&gt;, as being the web version, it will be continually updated.&lt;br&gt;&lt;br&gt;
You can find more details about this &lt;a href="https://doc.rust-lang.org/book/"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  How do I Apply What I Learn?
&lt;/h2&gt;

&lt;p&gt;As I start off, I plan to apply what I learn in solving competitive programming questions on &lt;a href="https://codeforces.com/"&gt;CodeForces&lt;/a&gt;. I've solved question from there before, and written 2 blogs on them as well, here on &lt;em&gt;dev.to&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;I'll restart blogging about solving CodeForces questions, but I'll switch my language from Modern C++ to Rust, so that I can really dive into learning this new language.&lt;/p&gt;

&lt;p&gt;In addition, solving the questions and exercises in the different material I read, will be important. I'll maintain a GitHub repository for each resource I work on, to keep everything in sync.&lt;/p&gt;

&lt;h2&gt;
  
  
  So When Do I Start?
&lt;/h2&gt;

&lt;p&gt;I have already started working through the Microsoft Developer series on YouTube, which I plan to finish a little more than halfway by August 19th, Thursday. I'll add another blog post then, to update my progress and share what I learnt.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Onwards and Upwards! ...&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rust</category>
      <category>programming</category>
    </item>
    <item>
      <title>Solving Codeforces Problem: 136A - Presents</title>
      <dc:creator>Rishit Chaudhary</dc:creator>
      <pubDate>Wed, 23 Jun 2021 14:45:17 +0000</pubDate>
      <link>https://dev.to/rishitc/solving-codeforces-problem-136a-presents-246g</link>
      <guid>https://dev.to/rishitc/solving-codeforces-problem-136a-presents-246g</guid>
      <description>&lt;p&gt;Today we are going to attempt to solve the Codeforces problem: 136A - Presents. Alright! so let's begin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The Question&lt;/li&gt;
&lt;li&gt;My Analysis with Sample Examples&lt;/li&gt;
&lt;li&gt;Code and Complexity&lt;/li&gt;
&lt;li&gt;Links and References&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Question &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Problem Statement &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited n his friends there.&lt;br&gt;&lt;br&gt;
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. &lt;strong&gt;He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi.&lt;/strong&gt; He also remembered that each of his friends received exactly one gift.&lt;br&gt;&lt;br&gt;
Now Petya wants to know for each friend i the number of a friend who has given him a gift.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Input
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The first line contains one integer &lt;strong&gt;n (1 ≤ n ≤ 100) — the quantity of friends Petya invited to the party.&lt;/strong&gt; The second line contains &lt;strong&gt;n space-separated integers: the i-th number is pi — the number of a friend who gave a gift to friend number i.&lt;/strong&gt; It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;Print n space-separated integers: the &lt;strong&gt;i-th number should equal the number of the friend who gave a gift to friend number i.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My Analysis with Sample Examples &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Now, before discussing the solution, I first need to address a mistake in the description in the input of the question as given on Codeforces. In the input description, it says that:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;the i-th number is pi — the number of a friend who gave a gift to friend number i.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is not how the input is given in the various test cases. On closer inspection this is very similar to the description of the expected output of the questions:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;i-th number should equal the number of the friend who gave a gift to friend number i.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, now the natural question you'll be asking is &lt;strong&gt;"What exactly is the input format?"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If we re-examine the description of the &lt;strong&gt;Problem Statement&lt;/strong&gt; above, we see the line:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;He numbered all his friends with integers from 1 to n. Petya remembered that a friend number i gave a gift to a friend number pi.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Eureka! This is the &lt;strong&gt;correct description&lt;/strong&gt; of the input format! We can verify this as well with the given sample examples. Let's try that now.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example-1
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Input
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;4&lt;br&gt;
2 3 4 1&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, on the first line we are given that Petya invited 4 friends to the party &lt;em&gt;(I sincerely hope none of his friends got left out 😅)&lt;/em&gt;, and on next line we are given a list of numbers that needs to be interpreted as follows (&lt;strong&gt;Notice:&lt;/strong&gt; The numbers in bold are the ones visible in the input, in that order):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Friend 1 gave a present to Friend &lt;strong&gt;2&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Friend 2 gave a present to Friend &lt;strong&gt;3&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Friend 3 gave a present to Friend &lt;strong&gt;4&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Friend 4 gave a present to Friend &lt;strong&gt;1&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Alright, so now what we need to do is to output a list of numbers such that at the &lt;code&gt;i-th&lt;/code&gt; position we give the number of the friend &lt;strong&gt;who gave a present&lt;/strong&gt; to friend &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So our output should be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;4 1 2 3&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which should be interpreted as (&lt;strong&gt;Notice:&lt;/strong&gt; The numbers in bold are the ones visible in the output, in that order):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Friend &lt;strong&gt;4&lt;/strong&gt; gave a present to Friend 1&lt;/li&gt;
&lt;li&gt;Friend &lt;strong&gt;1&lt;/strong&gt; gave a present to Friend 2&lt;/li&gt;
&lt;li&gt;Friend &lt;strong&gt;2&lt;/strong&gt; gave a present to Friend 3&lt;/li&gt;
&lt;li&gt;Friend &lt;strong&gt;3&lt;/strong&gt; gave a present to Friend 4&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;4 1 2 3&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Example-2
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Input
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;3&lt;br&gt;
1 3 2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, on the first line we are given that Petya invited 3 friends to the party, and on next line we are given a list of numbers that needs to be interpreted as follows (&lt;strong&gt;Notice:&lt;/strong&gt; The numbers in bold are the ones visible in the input, in that order):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Friend 1 gave a present to Friend &lt;strong&gt;1&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Friend 2 gave a present to Friend &lt;strong&gt;3&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Friend 3 gave a present to Friend &lt;strong&gt;2&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Alright, so other than the fact that &lt;em&gt;Friend 1 doesn't seem to have the New Year spirit&lt;/em&gt;, what we need to do is to output a list of numbers such that at the &lt;code&gt;i-th&lt;/code&gt; position we give the number of the friend &lt;strong&gt;who gave a present&lt;/strong&gt; to friend &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So our output should be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1 3 2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which should be interpreted as (&lt;strong&gt;Notice:&lt;/strong&gt; The numbers in bold are the ones visible in the output, in that order):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Friend &lt;strong&gt;1&lt;/strong&gt; gave a present to Friend 1&lt;/li&gt;
&lt;li&gt;Friend &lt;strong&gt;3&lt;/strong&gt; gave a present to Friend 2&lt;/li&gt;
&lt;li&gt;Friend &lt;strong&gt;2&lt;/strong&gt; gave a present to Friend 3&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;1 3 2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Example-3
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Input
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;2&lt;br&gt;
1 2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, on the first line we are given that Petya invited 2 friends to the party, and on next line we are given a list of numbers that needs to be interpreted as follows (&lt;strong&gt;Notice:&lt;/strong&gt; The numbers in bold are the ones visible in the input, in that order):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Friend 1 gave a present to Friend &lt;strong&gt;1&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Friend 2 gave a present to Friend &lt;strong&gt;2&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Alright, so other than the fact that &lt;em&gt;Friend 1 and Friend 2 should starting asking themselves why they came with presents to the party&lt;/em&gt;, what we need to do is to output a list of numbers such that at the &lt;code&gt;i-th&lt;/code&gt; position we give the number of the friend &lt;strong&gt;who gave a present&lt;/strong&gt; to friend &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So our output should be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1 2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Which should be interpreted as (&lt;strong&gt;Notice:&lt;/strong&gt; The numbers in bold are the ones visible in the output, in that order):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Friend &lt;strong&gt;1&lt;/strong&gt; gave a present to Friend 1&lt;/li&gt;
&lt;li&gt;Friend &lt;strong&gt;2&lt;/strong&gt; gave a present to Friend 2&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;1 2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Code and Complexity &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Alright, so now we know how to interpret out input and process it to get our output. To be extra sure we have also verified our logic over the given examples as well. Let's now translate this logic into code. For this I'll be using modern C++ (C++11 and beyond), so that it's easier to get the big picture logic which is implemented in the code.&lt;/p&gt;

&lt;p&gt;Another interesting reason to use modern C++ is that some of its features make the code more readable and similar looking to Python code &lt;em&gt;(many people consider this a plus).&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @file 136A-Presents.cpp
 * @author Rishit Chaudhary (@rishitc)
 * @version 1.0
 * @date 2021-06-23
 * 
 * @copyright Copyright (c) 2021
 * 
 */&lt;/span&gt;

&lt;span class="cp"&gt;#include &amp;lt;iostream&amp;gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;ios_base&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;sync_with_stdio&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tie&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cin&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cin&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Zero index correction for p&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Complexity
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Complexity Type&lt;/th&gt;
&lt;th&gt;Answer&lt;/th&gt;
&lt;th&gt;My Comments&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;td&gt;n (1 ≤ n ≤ 100) — the quantity of friends Petya invited to the party.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;td&gt;n (1 ≤ n ≤ 100) — the quantity of friends Petya invited to the party.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Difficulty &lt;em&gt;(subjective value)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;Easy&lt;/td&gt;
&lt;td&gt;The use of language in the question combined with the mistake in the description of the input does make the question a bit hard to grasp at first.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Links and References &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Link to the problem: &lt;a href="https://codeforces.com/problemset/problem/136/A"&gt;https://codeforces.com/problemset/problem/136/A&lt;/a&gt;&lt;br&gt;
Link to my submission: &lt;a href="https://codeforces.com/contest/136/submission/120021060"&gt;https://codeforces.com/contest/136/submission/120021060&lt;/a&gt;&lt;br&gt;
Link to the solution at my GitHub Repository: &lt;a href="https://github.com/rishitc/Codeforces-Codes/blob/main/136A-Presents.cpp"&gt;https://github.com/rishitc/Codeforces-Codes/blob/main/136A-Presents.cpp&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>cpp</category>
      <category>programming</category>
      <category>competitiveprogramming</category>
    </item>
    <item>
      <title>Solving Codeforces Problem: 467A - George and Accommodation</title>
      <dc:creator>Rishit Chaudhary</dc:creator>
      <pubDate>Sat, 19 Jun 2021 16:08:21 +0000</pubDate>
      <link>https://dev.to/rishitc/solving-codeforces-problem-467a-george-and-accommodation-39jb</link>
      <guid>https://dev.to/rishitc/solving-codeforces-problem-467a-george-and-accommodation-39jb</guid>
      <description>&lt;p&gt;Today we are going to attempt to solve the Codeforces problem &lt;em&gt;467A - George and Accommodation&lt;/em&gt;. Alright! so let's begin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The Question&lt;/li&gt;
&lt;li&gt;My Analysis with Sample Examples&lt;/li&gt;
&lt;li&gt;Code and Complexity&lt;/li&gt;
&lt;li&gt;Links and References&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Question &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Problem Statement
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.&lt;br&gt;&lt;br&gt;
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Input
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.&lt;br&gt;&lt;br&gt;
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Print a single integer — the number of rooms where George and Alex can move in.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  My Analysis with Sample Examples &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Now, as per the question we need to check if a room, say &lt;code&gt;ri&lt;/code&gt; has enough space left for 2 people, i.e. George and Alex. So putting this in the form of a condition, we get &lt;em&gt;(assuming we start counting the rooms from 1)&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;qi - pi ≥ 2, ∀ i ∈ [1, n]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's try out our logic on the examples given in the problem:&lt;/p&gt;

&lt;h3&gt;
  
  
  Example-1
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Input
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;3&lt;br&gt;
1 1&lt;br&gt;
2 2&lt;br&gt;
3 3&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, it's clearly visible that each and every room in the dormitory is full, so there is no space for our two friends 😢. Hence the answer will be 0.&lt;/p&gt;

&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;0&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Example-2
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Input
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;3&lt;br&gt;
1 10&lt;br&gt;
0 10&lt;br&gt;
10 10&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, we see that the first room with capacity 10 and number of occupants 1, and the second room with capacity 10 and number of occupants 0 have more than enough space for our 2 friends 😊. Great! So that gives us the answer of 2 rooms in the dormitory.&lt;/p&gt;

&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Code and Complexity &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Alright, so now we know mathematically what we need to check for each room in the dormitory and we have verified our logic over the examples as well. Let's now translate this logic into code. For this I'll be using &lt;em&gt;modern C++&lt;/em&gt; (C++11 and beyond), so that it's easier to get the big picture logic which is implemented in the code.&lt;br&gt;&lt;br&gt;
Another interesting reason to use modern C++ is that some of its features make the code more readable and similar looking to Python code &lt;em&gt;(many people consider this a plus)&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * @file 467A-George_and_Accommodation.cpp
 * @author Rishit Chaudhary (@rishitc)
 * @version 1.0
 * @date 2021-06-19
 * 
 * @copyright Copyright (c) 2021
 * 
 */&lt;/span&gt;

&lt;span class="cp"&gt;#include &amp;lt;iostream&amp;gt;
&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;Space_for_George_and_Alex&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cin&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cin&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;Space_for_George_and_Alex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Complexity
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Complexity Type&lt;/th&gt;
&lt;th&gt;Answer&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity&lt;/td&gt;
&lt;td&gt;O(1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Difficulty &lt;em&gt;(subjective value)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;Easy&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Links and References &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Link to the problem: &lt;a href="https://codeforces.com/problemset/problem/467/A"&gt;https://codeforces.com/problemset/problem/467/A&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Link to my submission: &lt;a href="https://codeforces.com/contest/467/submission/120009560"&gt;https://codeforces.com/contest/467/submission/120009560&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Link to the solution at my GitHub Repository: &lt;a href="https://github.com/rishitc/Codeforces-Codes/blob/main/467A-George_and_Accommodation.cpp"&gt;https://github.com/rishitc/Codeforces-Codes/blob/main/467A-George_and_Accommodation.cpp&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>computerscience</category>
      <category>cpp</category>
      <category>programming</category>
      <category>competitiveprogramming</category>
    </item>
  </channel>
</rss>
