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