//https://www.nowcoder.com/practice/9df4b80fc3ab475288e5c26972440e1b?tpId=107&tags=&title=&diffculty=0&judgeStatus=0&rp=1
import java.util.Scanner;
public class Main6 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
System.out.println((a+b-c)*d);
}
}
//https://www.nowcoder.com/practice/a4f527b043c04551bf4b80b4275a53bd?tpId=107&tags=&title=&diffculty=0&judgeStatus=0&rp=1
import java.util.Scanner;
public class Main7 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int number = sc.nextInt();
if(number%5==0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
}
//https://www.nowcoder.com/practice/61a0f16117484d219b59c62224b33b1c?tpId=107&tags=&title=&diffculty=0&judgeStatus=0&rp=1
import java.util.Scanner;
public class Main8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int xx = sc.nextInt();
if(xx>0) {
System.out.println(-1);
}
if(xx==0) {
System.out.println(0);
}
if(xx<0){
System.out.println(1);
}
}
}
}
//https://www.nowcoder.com/practice/0948f4f3344c452f843afd3585dd0f8d?tpId=107&tags=&title=&diffculty=0&judgeStatus=0&rp=1
public class Main9 {
public static void main(String[] args) {
int number = 0;
int total=0;
while(number<2020) {
number++;
int a = number%10;
int b = number/10%10;
int c = number/100%10;
int d = number/1000;
if((a==9||b==9||c==9||d==9)){
System.out.println(number);
total++;
}
}
System.out.println(total);
}
}
//https://www.nowcoder.com/practice/e0e4f81dcd55408a8973f8033bbeb1d2?tpId=107&&tqId=33376&rp=1&ru=/ta/beginner-programmers&qru=/ta/beginner-programmers/question-ranking
import java.util.Arrays;
import java.util.Scanner;
public class Main0 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int max = 0;
int min = 0;
int x = sc.nextInt();
int[] array = new int[x];
for(int i=0;i<x;i++) {
array[i] = sc.nextInt();
}
Arrays.sort(array);
for(int i=0;i<array.length;i++) {
min = array[i];
break;
}
for(int i=0;i<array.length/2;i++) {
int temp = array[i];
array[i] = array[array.length-i-1];
array[array.length-i-1] = temp;
}
for(int i=0;i<array.length;i++) {
max = array[i];
break;
}
System.out.println(max-min);
}
}
}
https://www.nowcoder.com/practice/e0e4f81dcd55408a8973f8033bbeb1d2?tpId=107&&tqId=33376&rp=1&ru=/ta/beginner-programmers&qru=/ta/beginner-programmers/question-ranking
import java.util.Arrays;
import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int max = 0;
int min = 0;
int x = sc.nextInt();
int[] array = new int[x];
for (int i = 0; i < x; i++) {
array[i] = sc.nextInt();
}
Arrays.sort(array);
max= array[array.length-1];
min= array[0];
System.out.println(max-min);
}
}
}
//https://www.nowcoder.com/practice/0f855c7642b74cccb3c2366bb7732d2a?tpId=107&&tqId=33395&rp=1&ru=/ta/beginner-programmers&qru=/ta/beginner-programmers/question-ranking
import java.util.Scanner;
public class Main2 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int n = sc.nextInt();
if(n<12) {
System.out.println(2);
}
else {
System.out.println(((n/12)*4)+2);
}
}
}
}
//https://www.nowcoder.com/practice/da13e0cf321e4df9acd0fdf0a433cbb0?tpId=107&tqId=33395&rp=1&ru=%2Fta%2Fbeginner-programmers&qru=%2Fta%2Fbeginner-programmers%2Fquestion-ranking
import java.util.Scanner;
public class Main3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
long m = sc.nextLong();
long n = sc.nextLong();
System.out.println(GreatestCommonDivisor(n, m)+LeastCommonMultiple(n,m));
}
}
public static long GreatestCommonDivisor(long n,long m) {
long res =1;
long min = Math.min(m, n);
for(long i=min;i>0;i--) {
if(m%i==0&&n%i==0) {
return i;
}
}
return res;
}
public static long LeastCommonMultiple(long n,long m) {
long res = m*n;
long max = Math.max(m, n);
for(long i = max;i<m*n;i++) {
if(i%m==0&i%n==0) {
return i;
}
}
return res;
}
}