fork download
  1. import java.io.DataInputStream;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. //import java.util.StringTokenizer;
  5.  
  6.  
  7. class BYECAKES {
  8.  
  9. public static void main(String[] args) throws IOException {
  10. // TODO Auto-generated method stub
  11. //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  12. Reader r=new Reader();
  13. StringBuilder sb=new StringBuilder();
  14. while(true){
  15. //StringTokenizer st=new StringTokenizer(br.readLine());
  16. int a[]=new int[8];
  17. boolean flag=false;
  18. for(int i=0;i<8;i++){
  19. a[i]=r.nextInt();
  20. if(a[i]!=-1)flag=true;
  21. }
  22. if(!flag)break;
  23. if(a[0]<a[4] && a[1]<a[5] && a[2]<a[6] && a[3]<a[7]){
  24. sb.append((a[4]-a[0])+" "+(a[5]-a[1])+" "+(a[6]-a[2])+" "+(a[7]-a[3])+"\n");
  25. continue;
  26. }
  27.  
  28. int b[]=new int[4];
  29. b[0]=(int)Math.ceil(1.0*a[0]/a[4]);
  30. b[1]=(int)Math.ceil(1.0*a[1]/a[5]);
  31. b[2]=(int)Math.ceil(1.0*a[2]/a[6]);
  32. b[3]=(int)Math.ceil(1.0*a[3]/a[7]);
  33.  
  34. int max=Math.max(b[0],Math.max(b[1], Math.max(b[2],b[3])));
  35. /*b[0]+=max-b[0];
  36. b[1]+=max-b[1];
  37. b[2]+=max-b[2];
  38. b[3]+=max-b[3];
  39. */
  40. int ans[]=new int[4];
  41. ans[0]=max*a[4]-a[0];
  42. ans[1]=max*a[5]-a[1];
  43. ans[2]=max*a[6]-a[2];
  44. ans[3]=max*a[7]-a[3];
  45. sb.append((ans[0])+" "+(ans[1])+" "+(ans[2])+" "+(ans[3])+"\n");
  46. }
  47. System.out.println(sb);
  48. }
  49. static class Reader {
  50. final private int BUFFER_SIZE = 1 << 16;
  51. private DataInputStream din;
  52. private byte[] buffer;
  53. private int bufferPointer, bytesRead;
  54.  
  55. public Reader() {
  56. din = new DataInputStream(System.in);
  57. buffer = new byte[BUFFER_SIZE];
  58. bufferPointer = bytesRead = 0;
  59. }
  60.  
  61. public Reader(String file_name) throws IOException {
  62. din = new DataInputStream(new FileInputStream(file_name));
  63. buffer = new byte[BUFFER_SIZE];
  64. bufferPointer = bytesRead = 0;
  65. }
  66.  
  67. public String readLine() throws IOException {
  68. byte[] buf = new byte[64];
  69. int cnt = 0, c;
  70. while ((c = read()) != -1) {
  71. if (c == '\n')
  72. break;
  73. buf[cnt++] = (byte) c;
  74. }
  75. return new String(buf, 0, cnt);
  76. }
  77.  
  78. public int nextInt() throws IOException {
  79. int ret = 0;
  80. byte c = read();
  81. while (c <= ' ')
  82. c = read();
  83. boolean neg = (c == '-');
  84. if (neg)
  85. c = read();
  86. do {
  87. ret = ret * 10 + c - '0';
  88. } while ((c = read()) >= '0' && c <= '9');
  89. if (neg)
  90. return -ret;
  91. return ret;
  92. }
  93.  
  94. public long nextLong() throws IOException {
  95. long ret = 0;
  96. byte c = read();
  97. while (c <= ' ')
  98. c = read();
  99. boolean neg = (c == '-');
  100. if (neg)
  101. c = read();
  102. do {
  103. ret = ret * 10 + c - '0';
  104. } while ((c = read()) >= '0' && c <= '9');
  105. if (neg)
  106. return -ret;
  107. return ret;
  108. }
  109.  
  110. public double nextDouble() throws IOException {
  111. double ret = 0, div = 1;
  112. byte c = read();
  113. while (c <= ' ')
  114. c = read();
  115. boolean neg = (c == '-');
  116. if (neg)
  117. c = read();
  118. do {
  119. ret = ret * 10 + c - '0';
  120. } while ((c = read()) >= '0' && c <= '9');
  121. if (c == '.')
  122. while ((c = read()) >= '0' && c <= '9')
  123. ret += (c - '0') / (div *= 10);
  124. if (neg)
  125. return -ret;
  126. return ret;
  127. }
  128.  
  129. private void fillBuffer() throws IOException {
  130. bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
  131. if (bytesRead == -1)
  132. buffer[0] = -1;
  133. }
  134.  
  135. private byte read() throws IOException {
  136. if (bufferPointer == bytesRead)
  137. fillBuffer();
  138. return buffer[bufferPointer++];
  139. }
  140.  
  141. public void close() throws IOException {
  142. if (din == null)
  143. return;
  144. din.close();
  145. }
  146. }
  147. }
  148. //-1 -1 -1 -1 -1 -1 -1 -1 -1
Success #stdin #stdout 0.07s 380224KB
stdin
193 390 39 10 485 392 34 58 
-1 -1 -1 -1 -1 -1 -1 -1 
stdout
777 394 29 106