I did not understand the editorial

#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int m=1000000007;
long long int sum=0;
int *a=new int[n];

    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    int q;
    cin>>q;

    for(int i=0;i<q;i++){
        int *temp=new int[n];

        for(int j=0;j<n;j++){
            temp[j]=0;
        }

        int x;
        cin>>x;

        int sum=0;
        if(x==0){
            for(int j=0;j<n;j++){
                temp[j]=(a[j]<<1)%m;
            }
        }

        else{
            temp[x]=(a[x]+a[0])%m;
            int j=x-1;
            while(j!=x){
                int index=j-x;
                if(index<0)
                    index+=n;
                temp[j]=(a[j]+a[index])%m;
                j--;
                if(j<0){
                    j=n-1;
                }
            }
        }
        a=temp;
    }

    for(int i=0;i<n;i++){
        sum=(sum+a[i])%m;
    }


    cout<<sum<<endl;
    return 0;

}

why are we doing %m every time ?

hi @discobot to keep the overall no in integer range else adding again and again can lead to integer overflow, say if i say keep adding but maintain under 10
eg 2,9,11,100…
so if u do % 10 every time it will be under 10
start 2 + 9 = 11 ,11 % 10 = 1
now add to this 1 + 11 = 12, 12 % 10 = 2
now add to this 2 + 100 = 102, 102 % 10 = 2

Hi! To find out what I can do, say @discobot display help.