Skip to content

Commit fcee1ba

Browse files
authored
Create Array Rotation.java
1 parent 01d5993 commit fcee1ba

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import java.util.*;
2+
import java.lang.*;
3+
import java.io.*;
4+
5+
class Codechef
6+
{
7+
static class FastReader
8+
{
9+
BufferedReader br;
10+
StringTokenizer st;
11+
12+
public FastReader()
13+
{
14+
br = new BufferedReader(new
15+
InputStreamReader(System.in));
16+
}
17+
18+
String next()
19+
{
20+
while (st == null || !st.hasMoreElements())
21+
{
22+
try
23+
{
24+
st = new StringTokenizer(br.readLine());
25+
}
26+
catch (IOException e)
27+
{
28+
e.printStackTrace();
29+
}
30+
}
31+
return st.nextToken();
32+
}
33+
34+
int nextInt()
35+
{
36+
return Integer.parseInt(next());
37+
}
38+
39+
40+
long nextLong()
41+
{
42+
return Long.parseLong(next());
43+
}
44+
45+
double nextDouble()
46+
{
47+
return Double.parseDouble(next());
48+
}
49+
50+
String nextLine()
51+
{
52+
String str = "";
53+
try
54+
{
55+
str = br.readLine();
56+
}
57+
catch (IOException e)
58+
{
59+
e.printStackTrace();
60+
}
61+
return str;
62+
}
63+
}
64+
public static void main(String[] args) throws java.lang.Exception{
65+
FastReader sc=new FastReader();
66+
int n=sc.nextInt();
67+
long[] arr=new long[n];
68+
long sum=0;
69+
for(int i=0;i<n;i++) {
70+
arr[i]=sc.nextLong();
71+
sum=(sum+arr[i])%1000000007;
72+
}
73+
74+
int q=sc.nextInt(),x;
75+
for(int i=0;i<q;i++) {
76+
x=sc.nextInt();
77+
if(sum<0) {
78+
sum=(((sum*2)%1000000007)+1000000007)%1000000007;
79+
}
80+
else {
81+
sum=(sum*2)%1000000007;
82+
}
83+
System.out.print(sum+"\n");
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)