final int mod = 1000 * 1000 * 1000 + 7;
int add(int a, int b) { return (a + b) % mod; }
int subtract(int a, int b) { return (a + mod - b) % mod; }
int multiply(int a, int b) { return (int) ((long) a * b % mod); }
int[][] interval, outside;
int GLOBAL_N;
boolean ok(int i, int j) {
return 0 <= i && i <= j && j < GLOBAL_N;
}
int f_interval(int i, int j) {
return ok(i, j) ? interval[i][j] : 1;
}
int f_outside(int i, int j) {
return ok(i, j) ? outside[i][j] : 1;
}
int n = s.length();
GLOBAL_N = n;
interval = new int[n][n];
outside = new int[n][n];
for (int i = n - 1; i >= 0; --i)
for (int j = i; j < n; ++j) {
interval[i][j] = add(f_interval(i + 1, j), f_interval(i, j - 1));
if (s.charAt(i) != s.charAt(j))
interval[i][j] = subtract(interval[i][j], f_interval(i + 1, j - 1));
}
for (int i = 0; i < n; ++i)
for (int j = n - 1; j > i; --j) {
outside[i][j] = add(f_outside(i - 1, j), f_outside(i, j + 1));
if (s.charAt(i) != s.charAt(j))
outside[i][j] = subtract(outside[i][j], f_outside(i - 1, j + 1));
}
int[] ans = new int[n];
for (int i = 0; i < n; ++i) {
ans[i] = add(ans[i], f_outside(i - 1, i + 1));
for (int j = i + 1; j < n; ++j)
if (s.charAt(i) == s.charAt(j)) {
int tmp = multiply(f_interval(i + 1, j - 1), f_outside(i - 1, j + 1));
ans[i] = add(ans[i], tmp);
ans[j] = add(ans[j], tmp);
}
}
write(ans);
int X = 0;
for(int i = 0; i < n; ++i)
X ^= multiply(ans[i], i + 1);
return X;
}
ZmluYWwgaW50IG1vZCA9IDEwMDAgKiAxMDAwICogMTAwMCArIDc7CmludCBhZGQoaW50IGEsIGludCBiKSB7IHJldHVybiAoYSArIGIpICUgbW9kOyB9CmludCBzdWJ0cmFjdChpbnQgYSwgaW50IGIpIHsgcmV0dXJuIChhICsgbW9kIC0gYikgJSBtb2Q7IH0KaW50IG11bHRpcGx5KGludCBhLCBpbnQgYikgeyByZXR1cm4gKGludCkgKChsb25nKSBhICogYiAlIG1vZCk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bal0sIGZfb3V0c2lkZShpIC0gMSwgaiArIDEpKTsKCQl9CgoJaW50W10gYW5zID0gbmV3IGludFtuXTsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CgkJYW5zW2ldID0gYWRkKGFuc1tpXSwgZl9vdXRzaWRlKGkgLSAxLCBpICsgMSkpOwoJCWZvciAoaW50IGogPSBpICsgMTsgaiA8IG47ICsraikKCQkJaWYgKHMuY2hhckF0KGkpID09IHMuY2hhckF0KGopKSB7CgkJCQlpbnQgdG1wID0gbXVsdGlwbHkoZl9pbnRlcnZhbChpICsgMSwgaiAtIDEpLCBmX291dHNpZGUoaSAtIDEsIGogKyAxKSk7CgkJCQlhbnNbaV0gPSBhZGQoYW5zW2ldLCB0bXApOwoJCQkJYW5zW2pdID0gYWRkKGFuc1tqXSwgdG1wKTsKCQkJfQoJfQoJd3JpdGUoYW5zKTsKCWludCBYID0gMDsKCWZvcihpbnQgaSA9IDA7IGkgPCBuOyArK2kpCgkJWCBePSBtdWx0aXBseShhbnNbaV0sIGkgKyAxKTsKCXJldHVybiBYOwp9
Main.java:1: error: class, interface, or enum expected
final int mod = 1000 * 1000 * 1000 + 7;
^
Main.java:2: error: class, interface, or enum expected
int add(int a, int b) { return (a + b) % mod; }
^
Main.java:2: error: class, interface, or enum expected
int add(int a, int b) { return (a + b) % mod; }
^
Main.java:3: error: class, interface, or enum expected
int subtract(int a, int b) { return (a + mod - b) % mod; }
^
Main.java:4: error: class, interface, or enum expected
int multiply(int a, int b) { return (int) ((long) a * b % mod); }
^
Main.java:6: error: class, interface, or enum expected
int GLOBAL_N;
^
Main.java:7: error: class, interface, or enum expected
boolean ok(int i, int j) {
^
Main.java:9: error: class, interface, or enum expected
}
^
Main.java:12: error: class, interface, or enum expected
}
^
Main.java:15: error: class, interface, or enum expected
}
^
Main.java:16: error: class, interface, or enum expected
public int solve(String s) {
^
Main.java:18: error: class, interface, or enum expected
GLOBAL_N = n;
^
Main.java:19: error: class, interface, or enum expected
interval = new int[n][n];
^
Main.java:20: error: class, interface, or enum expected
outside = new int[n][n];
^
Main.java:21: error: class, interface, or enum expected
for (int i = n - 1; i >= 0; --i)
^
Main.java:21: error: class, interface, or enum expected
for (int i = n - 1; i >= 0; --i)
^
Main.java:21: error: class, interface, or enum expected
for (int i = n - 1; i >= 0; --i)
^
Main.java:22: error: class, interface, or enum expected
for (int j = i; j < n; ++j) {
^
Main.java:22: error: class, interface, or enum expected
for (int j = i; j < n; ++j) {
^
Main.java:24: error: class, interface, or enum expected
if (s.charAt(i) != s.charAt(j))
^
Main.java:26: error: class, interface, or enum expected
}
^
Main.java:27: error: class, interface, or enum expected
for (int i = 0; i < n; ++i)
^
Main.java:27: error: class, interface, or enum expected
for (int i = 0; i < n; ++i)
^
Main.java:28: error: class, interface, or enum expected
for (int j = n - 1; j > i; --j) {
^
Main.java:28: error: class, interface, or enum expected
for (int j = n - 1; j > i; --j) {
^
Main.java:30: error: class, interface, or enum expected
if (s.charAt(i) != s.charAt(j))
^
Main.java:32: error: class, interface, or enum expected
}
^
Main.java:35: error: class, interface, or enum expected
for (int i = 0; i < n; ++i) {
^
Main.java:35: error: class, interface, or enum expected
for (int i = 0; i < n; ++i) {
^
Main.java:35: error: class, interface, or enum expected
for (int i = 0; i < n; ++i) {
^
Main.java:37: error: class, interface, or enum expected
for (int j = i + 1; j < n; ++j)
^
Main.java:37: error: class, interface, or enum expected
for (int j = i + 1; j < n; ++j)
^
Main.java:37: error: class, interface, or enum expected
for (int j = i + 1; j < n; ++j)
^
Main.java:40: error: class, interface, or enum expected
ans[i] = add(ans[i], tmp);
^
Main.java:41: error: class, interface, or enum expected
ans[j] = add(ans[j], tmp);
^
Main.java:42: error: class, interface, or enum expected
}
^
Main.java:45: error: class, interface, or enum expected
int X = 0;
^
Main.java:46: error: class, interface, or enum expected
for(int i = 0; i < n; ++i)
^
Main.java:46: error: class, interface, or enum expected
for(int i = 0; i < n; ++i)
^
Main.java:46: error: class, interface, or enum expected
for(int i = 0; i < n; ++i)
^
Main.java:48: error: class, interface, or enum expected
return X;
^
Main.java:49: error: class, interface, or enum expected
}
^
42 errors