import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
        int x=sc.nextInt();
        int totalSum=0;
       int[] arr=new int[n];
       for(int i=0;i<n;i++){
           arr[i]=sc.nextInt();
       }
        
       for(int i=0;i<n;i++){
           int value;
           if(i==n-1){
               value=arr[i]+arr[0];
           }
           else{
                value=arr[i]+arr[i+1];
           }
          if(value%x==0) totalSum+=value;
       }
        System.out.println(totalSum);

    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: