Question: I don't know if this is true, but when I was reading FAQ on one of the problem providing sites, I found something, that poke my attention:

> 
> Check your input/output methods. In C++, using cin and cout is too slow. Use these, and you will guarantee not being able to solve any problem with a decent amount of input or output. Use printf and scanf instead.
> 
> 
> 

Can someone please clarify this? Is really using *scanf()* in C++ programs faster than using *cin >> something* ? If yes, that is it a good practice to use it in C++ programs? I thought that it was C specific, though I am just learning C++...

Answer: 
The statements `cin` and `cout` in general use seem to be slower than `scanf` and `printf` in C++, but actually they are FASTER!

The thing is: In C++, whenever you use `cin` and `cout`, a synchronization process takes place by default that makes sure that if you use both `scanf` and `cin` in your program, then they both work in sync with each other. This sync process takes time. Hence `cin` and `cout` APPEAR to be slower.

However, if the synchronization process is set to not occur, `cin` is faster than `scanf`.

To skip the sync process, include the following code snippet in your program right in the beginning of `main()`:

```
std::ios::sync_with_stdio(false);

```

Visit [this site](http://www.cplusplus.com/reference/ios/ios_base/sync_with_stdio/) for more information.
Of course it's ridiculous to use cstdio over iostream. At least when you develop software (if you are already using c++ over c, then go all the way and use it's benefits instead of only suffering from it's disadvantages).

But in the online judge you are not developing software, you are creating a program that should be able to do things Microsoft software takes 60 seconds to achieve in 3 seconds!!!

So, in this case, the golden rule goes like (of course if you dont get into even more trouble by using java)

* Use c++ and use all of it's power (and heaviness/slowness) to solve the problem
* If you get time limited, then change the cins and couts for printfs and scanfs
(if you get screwed up by using the class string, print like this: printf(%s,mystr.c\_str());
* If you still get time limited, then try to make some obvious optimizations (like avoiding too many embedded for/while/dowhiles or recursive functions). Also make sure to pass by reference objects that are too big...
* If you still get time limited, then try changing std::vectors and sets for c-arrays.
* If you still get time limited, then go on to the next problem...