A plus B

Submit solution

Points: 1
Time limit: 5.0s
Memory limit: 256M

Problem type
Allowed languages
C, C++, Haskell, Java, Python

This problem is intended as an introduction to the submission and judging system. For a detailed write-up of how to process input and output in your language of choice, see algocoding.wordpress.com/2015/04/23/fast-io-methods-for-competitive-programming/.

All input and output should be done using the standard input and output streams respectively.

Input Specification

The first line will contain an integer \(N\) (\(1 \leq N \leq 10^5\)). The next \(N\) lines will each contain a pair of space-separated integers whose absolute value is less than \(10^9\).

Output Specification

Output \(N\) lines each containing a single integer: The sum of each pair of integers from the input, in the same order as they are given.

Sample Input

1 1
-1 0

Sample Output



  • 0
    mvhv  commented on Aug. 14, 2017, 3:53 a.m.

    I spent far too long trying to cram this into one gross line.

    for _ in range(int(input())): print(sum(map(int, input().split())))

    Can anything think of something shorter? I feel like this could be much worse but I/O makes it hard to obfuscate.

    • 3
      1021839  commented on Dec. 27, 2017, 4:13 p.m.

      I suppose you could take advantage of the fact that Python functions are first-class objects:

      for i in[input]*int(input()):print(sum(map(int,i().split())))

      • 0
        mvhv  commented on Jan. 1, 2018, 1:39 p.m.

        Ha, that's fantastic! I knew you can overload std::function::operator() to create first-class functions, but I never really considered how Python functions are obviously first-class by definition.

    • 0
      gozzarda  commented on Aug. 14, 2017, 1:23 p.m.

      A couple of minutes in Haskell gets me this:

      main=interact$unlines.map(show.sum.(map read).words).tail.lines

      Forgive the lack of whitespace. Readable Haskell would have between 4 and 16 extra spaces depending on your tastes.

  • 0
    lymiah  commented on Aug. 3, 2017, 6:45 a.m. edited

    The time seems to vary quite a lot between runs. Something I posted took about a second, then I resubmitted the same code later and it took about 4 seconds..

    • 0
      maxward  commented on Aug. 3, 2017, 2:57 p.m.

      It is because you are using endl, which causes a buffer flush, and thus is variable.

  • 1
    Tommoa  commented on July 27, 2017, 2:51 p.m.

    I'm surprised at the difference between using

    cout << endl


    cout << '\n' then cout.flush() at the end of the program.

    as well as the difference made with

    ios::sync_with_stdio(false) and cin.tie(0).

    I don't think there are any problems at all with only flushing cout at the end of your program, but are there any disadvantages when it comes to competitive programming when ios::sync_with_stdio(false) and cin.tie(0) would cause an error (other than when mixing C-style input/output and C++ streams)?

    • 0
      maxward  commented on July 27, 2017, 3:08 p.m. edit 2

      I am actually not surprised, this is a common issue with cin/cout. Using endl is very slow, as it forces a buffer flush. Using cin and cout can also be very slow unless you use the commands you posted, especially when the judge uses a HDD, which it does. Luckily, with the commands you mentioned, cin/cout become very fast. AFAIK it has no disadvantages other than that you can't use scanf/printf with cin/cout if you unsync and untie them.

      • 0
        Tommoa  commented on July 27, 2017, 3:17 p.m.

        Awesome, I'll make sure to use it in the future then. Thanks