Guest User

Untitled

a guest
May 11th, 2021
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. final private static int BUFFER_SIZE = 1 << 16;
  2. private static DataInputStream din = new DataInputStream(System.in);
  3. private static byte[] buffer = new byte[BUFFER_SIZE];
  4. private static int bufferPointer = 0, bytesRead = 0;
  5.  
  6. public static int readInt() throws IOException {
  7. int ret = 0;
  8. byte c = Read();
  9. while (c <= ' ')
  10. c = Read();
  11. boolean neg = (c == '-');
  12. if (neg)
  13. c = Read();
  14. do {
  15. ret = ret * 10 + c - '0';
  16. } while ((c = Read()) >= '0' && c <= '9');
  17.  
  18. if (neg)
  19. return -ret;
  20. return ret;
  21. }
  22. private static void fillBuffer() throws IOException {
  23. bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
  24. if (bytesRead == -1)
  25. buffer[0] = -1;
  26. }
  27.  
  28. private static byte Read() throws IOException {
  29. if (bufferPointer == bytesRead)
  30. fillBuffer();
  31. return buffer[bufferPointer++];
  32. }
RAW Paste Data