arrow_forward
همه ارسالها
جزئیات ارسال کد#837
برای پسندیدن وارد شوید
1////TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
2//// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
3//void main() {
4// //TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
5// // to see how IntelliJ IDEA suggests fixing it.
6// IO.println(String.format("Hello and welcome!"));
7//
8// for (int i = 1; i <= 5; i++) {
9// //TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
10// // for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
11// IO.println("i = " + i);
12// }
13//}
14
15
16import java.util.Arrays;
17import java.util.Scanner;
18public class Main {
19 public static void main(String[] args) {
20 Scanner sc = new Scanner(System.in);
21 int n = sc.nextInt();
22
23// int m = sc.nextInt();
24
25 int[] arr = new int[n+1];
26 Arrays.fill(arr,0);
27 for (int i=1; i<2*n+1; i++){
28 int input =sc.nextInt();
29 if(arr[input]==0) {
30 arr[input] += i;
31 }
32 else {
33 arr[input]= Math.abs(arr[input]-i);
34 }
35 }
36 long res =0;
37 for (int i =0 ;i<n+1;i++){
38 res+=arr[i];
39 }
40 System.out.print(res);
41
42
43 }
44}
کد ارسالشده برای داوری خودکار هاتکدز
UTF-8