-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolutionb.java
54 lines (44 loc) · 1.56 KB
/
solutionb.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
52
53
54
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
class Solution {
static final long key = 811589153;
static class Pair {
long fst;
long snd;
Pair(long fst, long snd) {
this.fst = fst;
this.snd = snd;
}
}
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Long> numbers = br.lines()
.map(Long::parseLong)
.map(i -> i * key)
.collect(Collectors.toCollection(ArrayList::new));
ArrayList<Pair> numberPairs = IntStream.range(0, numbers.size())
.mapToObj(i -> new Pair(i, numbers.get(i)))
.collect(Collectors.toCollection(ArrayList::new));
List<Pair> original = new ArrayList<>(numberPairs);
for (int i = 0; i < 10; i++) {
for (Pair pair : original) {
int oldIndex = numberPairs.indexOf(pair);
numberPairs.remove(oldIndex);
int newIndex = Math.floorMod(oldIndex + pair.snd, numberPairs.size());
numberPairs.add(newIndex, pair);
}
}
int zeroPos = IntStream.range(0, numberPairs.size())
.filter(i -> numberPairs.get(i).snd == 0)
.findFirst()
.getAsInt();
long result = numberPairs.get((zeroPos + 1000) % numberPairs.size()).snd
+ numberPairs.get((zeroPos + 2000) % numberPairs.size()).snd
+ numberPairs.get((zeroPos + 3000) % numberPairs.size()).snd;
System.out.println(result);
}
}