@Darklordx/

TEMPLATE-37

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//TEMPLATE
import java.util.*;
import java.math.*;
public class Main {
    static Scanner scan;
    public static void println(Object s){System.out.println(s);}
    public static void print(Object s){System.out.print(s);}
    public static int nextInt(){return scan.nextInt();}
    public static long nextLong(){return scan.nextLong();}
    
    public static int nextIntL(){int i = scan.nextInt(); scan.nextLine(); return i;}
    public static long nextLongL(){long i = scan.nextLong(); scan.nextLine(); return i;}

    public static String nextLine(){return scan.nextLine();}
    
    static void printArray(int arr[]) 
    { 
        int n = arr.length; 
        for (int i=0; i<n; ++i) 
            System.out.print(arr[i]+" "); 
        System.out.println(); 
    }

    public static void main(String[] args) {scan = new Scanner(System.in);solution();}

    //Solution goes below:
    public static void solution(){
        int n = nextInt();
        boolean zeros = false;
        long tmp;
        long cost = 0;
        int pm = 0;
        for(int i=0; i<n;i++){
            tmp = nextLong();
            if(tmp>=1){
                cost+=tmp-1;
            }else if(tmp<=-1){
                cost+=-1-tmp;
                pm=1-pm;
            }else if(tmp==0){
                zeros = true;
                cost+=1;
            }
        }
        if(pm==1&&zeros== false){
            cost+=2;
        }
        println(cost);
    }

}