buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
char[] input = Console.ReadLine().ToCharArray();
int ans = 0;
int count = 0;
for (int i = 0; i < input.Length; i++) {
if (input[i] == 'R') {
count++;
} else {
ans = count;
count = 0;
}
}
Console.WriteLine(Math.Max(ans, count));
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
char[] input = Console.ReadLine().ToCharArray();
int ans = 0;
int count = 0;
for (int i = 0; i < input.Length; i++) {
if (input[i] == 'R') {
count++;
} else {
ans = Math.Max(ans, count);
count = 0;
}
}
Console.WriteLine(Math.Max(ans, count));
}
}
|
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 107
| 7
|
using System;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int count = 0;
int maxCount = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] == 'R')
count++;
else {
if (count > maxCount)
maxCount = count;
count = 0;
}
}
Console.WriteLine(maxCount);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int count = 0;
int maxCount = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] == 'R')
count++;
else {
if (count > maxCount)
maxCount = count;
count = 0;
}
}
if (count > maxCount)
maxCount = count;
Console.WriteLine(maxCount);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 93
| 10
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
class Program {
static void Main(string[] args) {
const int mod = 998244353;
var exStdIn = new System.IO.StreamReader("stdin.txt");
System.Console.SetIn(exStdIn);
string s = Console.ReadLine();
int cnt = 0;
for (int i = 0; i < 3; i++) {
if (s[i] == 'R') {
cnt++;
}
}
if (cnt == 2 && s[1] == 'S')
cnt = 1;
Console.WriteLine(cnt);
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
class Program {
static void Main(string[] args) {
const int mod = 998244353;
// var exStdIn = new System.IO.StreamReader( "stdin.txt"
// );System.Console.SetIn( exStdIn );
string s = Console.ReadLine();
int cnt = 0;
for (int i = 0; i < 3; i++) {
if (s[i] == 'R') {
cnt++;
}
}
if (cnt == 2 && s[1] == 'S')
cnt = 1;
Console.WriteLine(cnt);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 234, 22], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 0, 131], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 0, 131], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 177
| 24
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Tasks {
public class A {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var S = Console.ReadLine();
var answer = 0;
var tmp = 0;
for (var i = 0; i < S.Length; i++) {
if (S[i] == 'R')
tmp++;
else {
answer = Math.Max(answer, tmp);
tmp = 0;
}
}
Console.WriteLine(answer);
}
public static class Scanner {
private static Queue<string> queue = new Queue<string>();
public static T Next<T>() {
if (!queue.Any())
foreach (var item in Console.ReadLine().Trim().Split(" "))
queue.Enqueue(item);
return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
}
public static T Scan<T>() => Next<T>();
public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(),
Next<T3>());
public static (T1, T2, T3,
T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(),
Next<T3>(), Next<T4>());
public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() =>
(Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Tasks {
public class A {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var S = Console.ReadLine();
var answer = 0;
var tmp = 0;
for (var i = 0; i < S.Length; i++) {
if (S[i] == 'R')
tmp++;
else {
answer = Math.Max(answer, tmp);
tmp = 0;
}
}
answer = Math.Max(answer, tmp);
Console.WriteLine(answer);
}
public static class Scanner {
private static Queue<string> queue = new Queue<string>();
public static T Next<T>() {
if (!queue.Any())
foreach (var item in Console.ReadLine().Trim().Split(" "))
queue.Enqueue(item);
return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
}
public static T Scan<T>() => Next<T>();
public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(),
Next<T3>());
public static (T1, T2, T3,
T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(),
Next<T3>(), Next<T4>());
public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() =>
(Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 468
| 11
|
using System;
using System.Linq;
namespace abc175.b {
class Program {
static void Main(string[] args) {
int num = getIntParam();
long[] paramArray = getLongParams();
int ret = 0;
for (int i = 0; i < num; i++) {
for (int j = i + 1; j < num; j++) {
for (int k = j + 1; k < num; k++) {
long[] comb =
new long[] { paramArray[i], paramArray[j], paramArray[k] };
Array.Sort(comb);
if ((paramArray[i] != paramArray[j]) &&
(paramArray[i] != paramArray[k]) &&
(paramArray[j] != paramArray[k])) {
if (paramArray[i] + paramArray[j] > paramArray[k]) {
ret++;
}
}
}
}
}
Console.WriteLine(ret);
}
//↓↓↓ shared function ↓↓↓
static int getIntParam() { return int.Parse(Console.ReadLine()); }
static int[] getIntParams() {
return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
}
static long getLongParam() { return long.Parse(Console.ReadLine()); }
static long[] getLongParams() {
return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
}
static string getStringParam() { return Console.ReadLine(); }
static string[] getStringParams() { return Console.ReadLine().Split(' '); }
}
}
|
using System;
using System.Linq;
namespace abc175.b {
class Program {
static void Main(string[] args) {
int num = getIntParam();
long[] paramArray = getLongParams();
int ret = 0;
for (int i = 0; i < num; i++) {
for (int j = i + 1; j < num; j++) {
for (int k = j + 1; k < num; k++) {
long[] comb =
new long[] { paramArray[i], paramArray[j], paramArray[k] };
Array.Sort(comb);
if ((comb[0] != comb[1]) && (comb[0] != comb[2]) &&
(comb[1] != comb[2])) {
if (comb[0] + comb[1] > comb[2]) {
ret++;
}
}
}
}
}
Console.WriteLine(ret);
}
//↓↓↓ shared function ↓↓↓
static int getIntParam() { return int.Parse(Console.ReadLine()); }
static int[] getIntParams() {
return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
}
static long getLongParam() { return long.Parse(Console.ReadLine()); }
static long[] getLongParams() {
return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
}
static string getStringParam() { return Console.ReadLine(); }
static string[] getStringParams() { return Console.ReadLine().Split(' '); }
}
}
|
[["-", 31, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["+", 31, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 31, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["-", 31, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 64, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 358
| 36
|
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Threading;
using System.Runtime.CompilerServices;
using System.IO.Pipes;
namespace AtCoder {
class Program {
struct Point {
public int x;
public int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
const int BiggestMod = 1000000007;
public static void Main() {
var num = int.Parse(Console.ReadLine());
var lines =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var ans = 0;
Array.Sort(lines);
for (int i = 0, l = num - 2; i < l; ++i)
for (int j = i + 1, m = num - 1; j < m; ++j)
if (lines[i] < lines[j])
for (int k = j + 1; k < num; ++k)
if (lines[k] < lines[i] + lines[j])
ans++;
Console.WriteLine(ans);
}
}
}
|
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Threading;
using System.Runtime.CompilerServices;
using System.IO.Pipes;
namespace AtCoder {
class Program {
struct Point {
public int x;
public int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
const int BiggestMod = 1000000007;
public static void Main() {
var num = int.Parse(Console.ReadLine());
var lines =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var ans = 0;
Array.Sort(lines);
for (int i = 0, l = num - 2; i < l; ++i)
for (int j = i + 1, m = num - 1; j < m; ++j)
if (lines[i] != lines[j])
for (int k = j + 1; k < num; ++k)
if (lines[j] != lines[k])
if (lines[k] < lines[i] + lines[j])
ans++;
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 7, 8, 7, 8, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 7, 8, 57, 15, 16, 17, 79], ["+", 8, 7, 8, 57, 64, 7, 26, 241, 0, 22], ["+", 0, 7, 8, 7, 8, 57, 64, 7, 0, 25], ["+", 8, 7, 8, 57, 64, 7, 8, 57, 0, 121], ["+", 8, 7, 8, 57, 64, 7, 8, 57, 0, 24], ["+", 64, 7, 8, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 57, 64, 7, 8, 57, 15, 16, 17, 79], ["+", 64, 7, 8, 57, 15, 16, 12, 204, 205, 22], ["+", 8, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 8, 57, 15, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 278
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
long[] ll = sc.LongArray();
long answer = 0;
for (int a = 0; a < n; a++) {
for (int b = a + 1; b < n; b++) {
for (int c = b + 1; c < n; c++) {
if (ll[a] == ll[b] || ll[a] == ll[c]) {
continue;
}
long sum = ll[a] + ll[b] + ll[c];
long max = Math.Max(ll[a], Math.Max(ll[b], ll[c]));
if (max * 2 < sum) {
answer++;
}
}
}
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
long[] ll = sc.LongArray();
long answer = 0;
for (int a = 0; a < n; a++) {
for (int b = a + 1; b < n; b++) {
for (int c = b + 1; c < n; c++) {
if (ll[a] == ll[b] || ll[a] == ll[c] || ll[b] == ll[c]) {
continue;
}
long sum = ll[a] + ll[b] + ll[c];
long max = Math.Max(ll[a], Math.Max(ll[b], ll[c]));
if (max * 2 < sum) {
answer++;
}
}
}
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 503
| 10
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Program {
static void Main() {
int number = int.Parse(Console.ReadLine());
if (number < 3) {
Console.WriteLine(0);
} else {
string[] numbersString = Console.ReadLine().Split(' ');
List<int> numbers = new List<int>();
for (int i = 0; i < number; i++) {
numbers.Add(int.Parse(numbersString[i]));
}
var convinations = GetCombination(numbers, 3);
int result = 0;
foreach (var combi in convinations) {
int a = combi[0];
int b = combi[1];
int c = combi[2];
bool zeroNotExists = !(a < 1 || b < 1 || c < 1);
bool diff = !(a == b || b == c || a == c);
bool canBeTriangle = a + b > c || a + c > b || b + c > a;
if (zeroNotExists && diff && canBeTriangle)
result++;
}
Console.WriteLine(result);
}
}
static List<List<int>> GetCombination(List<int> self, int n) {
return Enumerable.Range(0, n - 1)
.Aggregate(
Enumerable.Range(0, self.Count - n + 1)
.Select(num => new List<int> { num }),
(list, _) => list.SelectMany(
c => Enumerable.Range(c.Max() + 1, self.Count - c.Max() - 1)
.Select(num => new List<int>(c) { num })))
.Select(c => c.Select(num => self[num]).ToList())
.ToList();
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Program {
static void Main() {
int number = int.Parse(Console.ReadLine());
if (number < 3) {
Console.WriteLine(0);
} else {
string[] numbersString = Console.ReadLine().Split(' ');
List<int> numbers = new List<int>();
for (int i = 0; i < number; i++) {
numbers.Add(int.Parse(numbersString[i]));
}
var convinations = GetCombination(numbers, 3);
int result = 0;
foreach (var combi in convinations) {
int a = combi[0];
int b = combi[1];
int c = combi[2];
bool diff = !(a == b || b == c || a == c);
bool canBeTriangle = a + b > c && a + c > b && b + c > a;
if (diff && canBeTriangle)
result++;
}
Console.WriteLine(result);
}
}
static List<List<int>> GetCombination(List<int> self, int n) {
return Enumerable.Range(0, n - 1)
.Aggregate(
Enumerable.Range(0, self.Count - n + 1)
.Select(num => new List<int> { num }),
(list, _) => list.SelectMany(
c => Enumerable.Range(c.Max() + 1, self.Count - c.Max() - 1)
.Select(num => new List<int>(c) { num })))
.Select(c => c.Select(num => self[num]).ToList())
.ToList();
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 111], ["-", 0, 200, 0, 212, 0, 241, 0, 23, 0, 24], ["-", 0, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 23, 0, 16, 31, 16, 31, 16, 17, 18], ["-", 0, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 241, 0, 23, 0, 16, 31, 16, 17, 106], ["-", 0, 23, 0, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 23, 0, 16, 31, 16, 12, 16, 17, 18], ["-", 0, 23, 0, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 212, 0, 241, 0, 23, 0, 16, 17, 106], ["-", 0, 241, 0, 23, 0, 16, 12, 16, 31, 22], ["-", 0, 241, 0, 23, 0, 16, 12, 16, 17, 18], ["-", 0, 241, 0, 23, 0, 16, 12, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 241, 0, 23, 0, 25], ["-", 75, 196, 0, 210, 8, 196, 0, 197, 0, 35], ["-", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 106], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 98], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 106], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98]]
| 8
| 394
| 24
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
//整数の入力
int N = int.Parse(Console.ReadLine());
//スペース区切りの整数の入力
string[] L = Console.ReadLine().Split(' ');
// var L2 = L.Distinct().OrderBy(o => o);
var L2 = L.OrderBy(o => o).ToArray();
// string input = Console.ReadLine();
// int b = int.Parse(input[0]);
// int c = int.Parse(input[1]);
//文字列の入力
// string s = Console.ReadLine();
//出力
// onsole.WriteLine(N);
// Console.WriteLine(string.Join(" ", L));
if (L2.Count() <= 2) {
Console.WriteLine(0);
}
int count = 0;
for (int i = 0; i < L2.Count(); i++) {
for (int j = i + 1; j < L2.Count(); j++) {
int li = int.Parse(L2[i]);
int lj = int.Parse(L2[j]);
if (li == lj) {
continue;
}
for (int k = j + 1; k < L2.Count(); k++) {
int lk = int.Parse(L2[k]);
if (lj == lk) {
continue;
}
if (li < lj + lk && lj < li + lk && lk < li + lj) {
count++;
}
}
}
}
Console.WriteLine(count);
// Console.WriteLine(string.Join(" ", L2));
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
//整数の入力
int N = int.Parse(Console.ReadLine());
//スペース区切りの整数の入力
string[] L = Console.ReadLine().Split(' ');
// var L2 = L.Distinct().OrderBy(o => o);
var L2 = L.OrderBy(o => o).ToArray();
// string input = Console.ReadLine();
// int b = int.Parse(input[0]);
// int c = int.Parse(input[1]);
//文字列の入力
// string s = Console.ReadLine();
//出力
// onsole.WriteLine(N);
// Console.WriteLine(string.Join(" ", L));
int count = 0;
if (L2.Count() <= 2) {
Console.WriteLine(0);
Environment.Exit(0);
}
for (int i = 0; i < L2.Count(); i++) {
for (int j = i + 1; j < L2.Count(); j++) {
int li = int.Parse(L2[i]);
int lj = int.Parse(L2[j]);
if (li == lj) {
continue;
}
for (int k = j + 1; k < L2.Count(); k++) {
int lk = int.Parse(L2[k]);
if (lj == lk) {
continue;
}
if (li < lj + lk && lj < li + lk && lk < li + lj) {
count++;
}
}
}
}
Console.WriteLine(count);
// Console.WriteLine(string.Join(" ", L2));
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 262
| 15
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp3 {
internal class Program {
private static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var lengths =
Console.ReadLine().Split(" ").Select(x => decimal.Parse(x)).ToArray();
var combinations = GetCombinations(n, lengths).ToArray();
var allTriangleCount = combinations.Count(x => {
var maxLine = x.Max();
var otherSum = x.Except(new decimal[] { maxLine }).Sum();
return maxLine < otherSum;
});
Console.WriteLine(allTriangleCount);
}
private static IEnumerable<decimal[]> GetCombinations(int n,
decimal[] lengths) {
var combination = new Combination(n, 3);
while (combination != null) {
yield return combination.data.Select(x => lengths[x]).ToArray();
combination = combination.Successor();
}
}
private class Combination {
private long n = 0;
private long k = 0;
public long[] data = null;
public Combination(long n, long k) {
if (n < 0 || k < 0) {
throw new Exception("Negative parameter in constructor");
}
this.n = n;
this.k = k;
this.data = new long[k];
for (long i = 0; i < k; ++i) {
this.data[i] = i;
}
}
public Combination Successor() {
if (this.data.Length == 0 || this.data[0] == this.n - this.k) {
return null;
}
Combination answer = new Combination(this.n, this.k);
long i;
for (i = 0; i < this.k; ++i) {
answer.data[i] = this.data[i];
}
for (i = this.k - 1; i > 0 && answer.data[i] == this.n - this.k + i; --i)
;
++answer.data[i];
for (long j = i; j < this.k - 1; ++j) {
answer.data[j + 1] = answer.data[j] + 1;
}
return answer;
}
public string[] ApplyTo(string[] strarr) {
if (strarr.Length != this.n) {
throw new Exception("Bad array size");
}
string[] result = new string[this.k];
for (long i = 0; i < result.Length; ++i) {
result[i] = strarr[this.data[i]];
}
return result;
}
public static long Choose(long n, long k) {
if (n < 0 || k < 0) {
throw new Exception("Invalid negative parameter in Choose()");
}
if (n < k) {
return 0;
}
if (n == k) {
return 1;
}
long delta, iMax;
if (k < n - k) {
delta = n - k;
iMax = k;
} else {
delta = k;
iMax = n - k;
}
long answer = delta + 1;
for (long i = 2; i <= iMax; ++i) {
checked { answer = (answer * (delta + i)) / i; }
}
return answer;
}
public override string ToString() {
StringBuilder sb = new StringBuilder();
sb.Append("{ ");
for (long i = 0; i < this.k; ++i) {
sb.AppendFormat("{0} ", this.data[i]);
}
sb.Append("}");
return sb.ToString();
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp3 {
internal class Program {
private static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
if (n < 3) {
Console.WriteLine("0");
return;
}
var lengths =
Console.ReadLine().Split(" ").Select(x => decimal.Parse(x)).ToArray();
var combinations = GetCombinations(n, lengths).ToArray();
var allTriangleCount = combinations.Count(x => {
var maxLine = x.Max();
var otherSum = x.Except(new decimal[] { maxLine }).Sum();
return maxLine < otherSum;
});
Console.WriteLine(allTriangleCount);
}
private static IEnumerable<decimal[]> GetCombinations(int n,
decimal[] lengths) {
var combination = new Combination(n, 3);
while (combination != null) {
yield return combination.data.Select(x => lengths[x]).ToArray();
combination = combination.Successor();
}
}
private class Combination {
private long n = 0;
private long k = 0;
public long[] data = null;
public Combination(long n, long k) {
if (n < 0 || k < 0) {
throw new Exception("Negative parameter in constructor");
}
this.n = n;
this.k = k;
this.data = new long[k];
for (long i = 0; i < k; ++i) {
this.data[i] = i;
}
}
public Combination Successor() {
if (this.data.Length == 0 || this.data[0] == this.n - this.k) {
return null;
}
Combination answer = new Combination(this.n, this.k);
long i;
for (i = 0; i < this.k; ++i) {
answer.data[i] = this.data[i];
}
for (i = this.k - 1; i > 0 && answer.data[i] == this.n - this.k + i; --i)
;
++answer.data[i];
for (long j = i; j < this.k - 1; ++j) {
answer.data[j + 1] = answer.data[j] + 1;
}
return answer;
}
public string[] ApplyTo(string[] strarr) {
if (strarr.Length != this.n) {
throw new Exception("Bad array size");
}
string[] result = new string[this.k];
for (long i = 0; i < result.Length; ++i) {
result[i] = strarr[this.data[i]];
}
return result;
}
public static long Choose(long n, long k) {
if (n < 0 || k < 0) {
throw new Exception("Invalid negative parameter in Choose()");
}
if (n < k) {
return 0;
}
if (n == k) {
return 1;
}
long delta, iMax;
if (k < n - k) {
delta = n - k;
iMax = k;
} else {
delta = k;
iMax = n - k;
}
long answer = delta + 1;
for (long i = 2; i <= iMax; ++i) {
checked { answer = (answer * (delta + i)) / i; }
}
return answer;
}
public override string ToString() {
StringBuilder sb = new StringBuilder();
sb.Append("{ ");
for (long i = 0; i < this.k; ++i) {
sb.AppendFormat("{0} ", this.data[i]);
}
sb.Append("}");
return sb.ToString();
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 791
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace CompetitiveProgramming {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public long x;
public long a;
public long b;
public long c;
public Pair(long X, long Y, long Z, long D) {
x = X;
a = Y;
b = Z;
c = D;
}
public Pair(long a, long x) {
this.a = a;
this.x = x;
}
public Pair(long a, long b, long c) {
this.a = a;
this.b = b;
this.c = c;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.a <= p2.a;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.a >= p2.a;
}
}
}
class Zettiti : IComparable {
public long num;
public Zettiti(long num) { this.num = num; }
public int CompareTo(object obj) {
Zettiti kore = (Zettiti)obj;
long knum = Math.Abs(kore.num);
long mynum = Math.Abs(num);
return mynum.CompareTo(knum);
}
}
class Program {
static void Main(string[] args) {
// Utils.BinarySearch.Search
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long x = scan.Long();
long k = scan.Long();
long d = scan.Long();
long riso1 = x % d;
long riso2 = d - x % d;
long kaisu1 = x / d; // riso1にたどり着くまでの回数
if (k < kaisu1) {
Console.WriteLine(x - k * d);
return;
}
if (kaisu1 % 2 == k % 2) {
Console.WriteLine(riso1);
} else {
Console.WriteLine(riso2);
}
}
static bool isOK(long mid, long[] a, long[] f, long k) {
long count = 0;
for (long i = 0; i < a.Length; i++) {
long togo = mid / f[i];
;
count += Math.Max(0, a[i] - togo);
}
return (count <= k);
}
static void Output<T>(List<T> list, string kugiri = "\n") {
for (int i = 0; i < list.Count; i++) {
Console.Write(list[i]);
if (i != list.Count - 1) {
Console.Write(kugiri);
}
}
}
static void Output<T>(T[] list, string kugiri = "\n") {
for (int i = 0; i < list.Length; i++) {
Console.Write(list[i]);
if (i != list.Length - 1) {
Console.Write(kugiri);
}
}
}
static void Output<T>(T[,] list, string kugiri1 = " ",
string kugiri2 = "\n") {
int len1 = list.GetLength(0);
int len2 = list.GetLength(1);
for (int i = 0; i < len1; i++) {
for (int j = 0; j < len2; j++) {
Console.Write(list[i, j]);
if (j != len2 - 1) {
Console.Write(kugiri1);
}
}
if (i != len1 - 1) {
Console.Write(kugiri2);
}
}
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> FactorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = FactorialMemo.Count; i <= x; i++)
FactorialMemo.Add(FactorialMemo.Last() * i);
return FactorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private long len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(long n) {
char[] kore = new char[n];
for (long i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(long n, long m) {
char[,] kore = new char[n, m];
for (long i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n, bool minus1 = false) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
if (minus1)
kore[i]--;
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w, bool minus1 = false) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
if (minus1)
kore[i, j]--;
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n, bool minus1 = false) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
if (minus1)
kore[i]--;
}
return kore;
}
public int[,] Integer(long h, long w, bool minus1 = false) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
if (minus1)
kore[i, j]--;
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) {
if (num < 0) {
num += mod;
}
this.num = num % mod;
}
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> FactorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = FactorialMemo.Count; i <= x; i++)
FactorialMemo.Add(FactorialMemo.Last() * i);
return FactorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> FactorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = FactorialMemo.Count; i <= x; i++)
FactorialMemo.Add(FactorialMemo.Last() * i);
return FactorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public bool Any() { return _root != null; }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public T max() {
SB_BinarySearchTree<T>.Node ima = _root;
while (ima.RChild != null) {
ima = ima.RChild;
}
return ima.Value;
}
public T min() {
SB_BinarySearchTree<T>.Node ima = _root;
while (ima.LChild != null) {
ima = ima.LChild;
}
return ima.Value;
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
public class SortedMultiSet<T> : IEnumerable<T> {
private SortedDictionary<T, int> _dict;
public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); }
public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); }
public bool Contains(T item) { return _dict.ContainsKey(item); }
public void Add(T item) {
if (_dict.ContainsKey(item))
_dict[item]++;
else
_dict[item] = 1;
}
public void Add(IEnumerable<T> items) {
foreach (var item in items)
Add(item);
}
public void Remove(T item) {
if (!_dict.ContainsKey(item))
throw new ArgumentException();
if (--_dict[item] == 0)
_dict.Remove(item);
}
// Return the last value in the multiset
public T Peek() {
if (!_dict.Any())
throw new NullReferenceException();
return _dict.Last().Key;
}
// Return the last value in the multiset and remove it.
public T Pop() {
T item = Peek();
Remove(item);
return item;
}
public IEnumerator<T> GetEnumerator() {
foreach (var kvp in _dict)
for (int i = 0; i < kvp.Value; i++)
yield return kvp.Key;
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
class Treap<T> : IEnumerable<T>
where T : IComparable {
public int Length {
get { return this.Root == null ? 0 : this.NodeCount(this.Root); }
}
public T this[int i] {
get {
if (this.Root.Count < i - 1)
throw new IndexOutOfRangeException();
return this.Root.Get(i);
}
}
public Node Root;
private IComparer<T> Cmp = Comparer<T>.Default;
public Treap(IComparer<T> cmp = null) {
if (cmp != null)
this.Cmp = cmp;
}
public Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if (l.Priority > r.Priority) {
l.R = this.Merge(l.R, r);
return this.Update(l);
} else {
r.L = this.Merge(l, r.L);
return this.Update(r);
}
}
// 左にk個、右に残り(n-k)個に分割する
public (Node, Node) Split(int k) { return this.Split(this.Root, k); }
public (Node, Node) Split(Node t, int k) {
if (t == null)
return (null, null);
if (k <= this.NodeCount(t.L)) {
var s = this.Split(t.L, k);
t.L = s.Item2;
return (s.Item1, this.Update(t));
} else {
var s = this.Split(t.R, k - this.NodeCount(t.L) - 1);
t.R = s.Item1;
return (this.Update(t), s.Item2);
}
}
public int NodeCount(Node node) { return node == null ? 0 : node.Count; }
public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); }
public int LowerBouond(Node node, T value) {
if (node == null)
return 0;
if (this.Cmp.Compare(value, node.Value) <= 0)
return this.LowerBouond(node.L, value);
else
return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value);
}
public int UpperBound(T value) { return this.UpperBound(this.Root, value); }
public int UpperBound(Node node, T value) {
if (node == null)
return 0;
if (this.Cmp.Compare(value, node.Value) >= 0)
return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value);
else
return this.UpperBound(node.L, value);
}
public int ValueCount(T value) {
return this.UpperBound(value) - this.LowerBouond(value);
}
public void Insert(T value) {
var sub = this.Split(this.Root, this.LowerBouond(value));
var newNode = new Node(value);
var merged = this.Merge(sub.Item1, newNode);
this.Root = this.Merge(merged, sub.Item2);
}
public void Erase(T value) {
if (this.ValueCount(value) == 0)
return;
var sub = this.Split(this.Root, this.LowerBouond(value));
this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2);
}
public void InsertAt(Node node, int k) {
var sub = this.Split(this.Root, k);
var merged = this.Merge(sub.Item1, node);
this.Root = this.Merge(merged, sub.Item2);
}
public void InsertAt(T value, int k) {
var node = new Node(value);
var sub = this.Split(this.Root, k);
var merged = this.Merge(sub.Item1, node);
this.Root = this.Merge(merged, sub.Item2);
}
public Node EraseAt(int k) {
var sub = this.Split(this.Root, k);
var sub2 = this.Split(sub.Item2, 1);
var res = sub2.Item1;
this.Root = this.Merge(sub.Item1, sub2.Item2);
return res;
}
public Node Update(Node node) {
node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1;
return node;
}
public class Node {
private static Random Rand = new Random();
public T Value;
public Node L = null;
public Node R = null;
public int Count;
public double Priority;
public Node(T value, double priority) {
this.Value = value;
this.Priority = priority;
this.Count = 1;
}
public Node(T value) : this(value, Rand.NextDouble()) {}
public T Get(int i) { return this.GetNode(i).Value; }
public Node GetNode(int i) {
var lcount = 0;
if (this.L != null)
lcount = this.L.Count;
if (lcount == i)
return this;
else if (lcount < i)
return this.R.GetNode(i - lcount - 1);
else
return this.L.GetNode(i);
}
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++)
yield return this.Root.Get(i);
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
public static class ObjectExtension {
// ディープコピーの複製を作る拡張メソッド
public static T DeepClone<T>(this T src) {
using (var memoryStream = new System.IO.MemoryStream()) {
var binaryFormatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
binaryFormatter.Serialize(memoryStream, src); // シリアライズ
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
return (T)binaryFormatter.Deserialize(memoryStream); // デシリアライズ
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace CompetitiveProgramming {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public long x;
public long a;
public long b;
public long c;
public Pair(long X, long Y, long Z, long D) {
x = X;
a = Y;
b = Z;
c = D;
}
public Pair(long a, long x) {
this.a = a;
this.x = x;
}
public Pair(long a, long b, long c) {
this.a = a;
this.b = b;
this.c = c;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.a <= p2.a;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.a >= p2.a;
}
}
}
class Zettiti : IComparable {
public long num;
public Zettiti(long num) { this.num = num; }
public int CompareTo(object obj) {
Zettiti kore = (Zettiti)obj;
long knum = Math.Abs(kore.num);
long mynum = Math.Abs(num);
return mynum.CompareTo(knum);
}
}
class Program {
static void Main(string[] args) {
// Utils.BinarySearch.Search
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long x = scan.Long();
if (x < 0)
x = -x;
long k = scan.Long();
long d = scan.Long();
long riso1 = x % d;
long riso2 = d - x % d;
long kaisu1 = x / d; // riso1にたどり着くまでの回数
if (k < kaisu1) {
Console.WriteLine(x - k * d);
return;
}
if (kaisu1 % 2 == k % 2) {
Console.WriteLine(riso1);
} else {
Console.WriteLine(riso2);
}
}
static bool isOK(long mid, long[] a, long[] f, long k) {
long count = 0;
for (long i = 0; i < a.Length; i++) {
long togo = mid / f[i];
;
count += Math.Max(0, a[i] - togo);
}
return (count <= k);
}
static void Output<T>(List<T> list, string kugiri = "\n") {
for (int i = 0; i < list.Count; i++) {
Console.Write(list[i]);
if (i != list.Count - 1) {
Console.Write(kugiri);
}
}
}
static void Output<T>(T[] list, string kugiri = "\n") {
for (int i = 0; i < list.Length; i++) {
Console.Write(list[i]);
if (i != list.Length - 1) {
Console.Write(kugiri);
}
}
}
static void Output<T>(T[,] list, string kugiri1 = " ",
string kugiri2 = "\n") {
int len1 = list.GetLength(0);
int len2 = list.GetLength(1);
for (int i = 0; i < len1; i++) {
for (int j = 0; j < len2; j++) {
Console.Write(list[i, j]);
if (j != len2 - 1) {
Console.Write(kugiri1);
}
}
if (i != len1 - 1) {
Console.Write(kugiri2);
}
}
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> FactorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = FactorialMemo.Count; i <= x; i++)
FactorialMemo.Add(FactorialMemo.Last() * i);
return FactorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private long len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(long n) {
char[] kore = new char[n];
for (long i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(long n, long m) {
char[,] kore = new char[n, m];
for (long i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n, bool minus1 = false) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
if (minus1)
kore[i]--;
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w, bool minus1 = false) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
if (minus1)
kore[i, j]--;
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n, bool minus1 = false) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
if (minus1)
kore[i]--;
}
return kore;
}
public int[,] Integer(long h, long w, bool minus1 = false) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
if (minus1)
kore[i, j]--;
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) {
if (num < 0) {
num += mod;
}
this.num = num % mod;
}
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> FactorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = FactorialMemo.Count; i <= x; i++)
FactorialMemo.Add(FactorialMemo.Last() * i);
return FactorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> FactorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = FactorialMemo.Count; i <= x; i++)
FactorialMemo.Add(FactorialMemo.Last() * i);
return FactorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public bool Any() { return _root != null; }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public T max() {
SB_BinarySearchTree<T>.Node ima = _root;
while (ima.RChild != null) {
ima = ima.RChild;
}
return ima.Value;
}
public T min() {
SB_BinarySearchTree<T>.Node ima = _root;
while (ima.LChild != null) {
ima = ima.LChild;
}
return ima.Value;
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
public class SortedMultiSet<T> : IEnumerable<T> {
private SortedDictionary<T, int> _dict;
public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); }
public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); }
public bool Contains(T item) { return _dict.ContainsKey(item); }
public void Add(T item) {
if (_dict.ContainsKey(item))
_dict[item]++;
else
_dict[item] = 1;
}
public void Add(IEnumerable<T> items) {
foreach (var item in items)
Add(item);
}
public void Remove(T item) {
if (!_dict.ContainsKey(item))
throw new ArgumentException();
if (--_dict[item] == 0)
_dict.Remove(item);
}
// Return the last value in the multiset
public T Peek() {
if (!_dict.Any())
throw new NullReferenceException();
return _dict.Last().Key;
}
// Return the last value in the multiset and remove it.
public T Pop() {
T item = Peek();
Remove(item);
return item;
}
public IEnumerator<T> GetEnumerator() {
foreach (var kvp in _dict)
for (int i = 0; i < kvp.Value; i++)
yield return kvp.Key;
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
class Treap<T> : IEnumerable<T>
where T : IComparable {
public int Length {
get { return this.Root == null ? 0 : this.NodeCount(this.Root); }
}
public T this[int i] {
get {
if (this.Root.Count < i - 1)
throw new IndexOutOfRangeException();
return this.Root.Get(i);
}
}
public Node Root;
private IComparer<T> Cmp = Comparer<T>.Default;
public Treap(IComparer<T> cmp = null) {
if (cmp != null)
this.Cmp = cmp;
}
public Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if (l.Priority > r.Priority) {
l.R = this.Merge(l.R, r);
return this.Update(l);
} else {
r.L = this.Merge(l, r.L);
return this.Update(r);
}
}
// 左にk個、右に残り(n-k)個に分割する
public (Node, Node) Split(int k) { return this.Split(this.Root, k); }
public (Node, Node) Split(Node t, int k) {
if (t == null)
return (null, null);
if (k <= this.NodeCount(t.L)) {
var s = this.Split(t.L, k);
t.L = s.Item2;
return (s.Item1, this.Update(t));
} else {
var s = this.Split(t.R, k - this.NodeCount(t.L) - 1);
t.R = s.Item1;
return (this.Update(t), s.Item2);
}
}
public int NodeCount(Node node) { return node == null ? 0 : node.Count; }
public int LowerBouond(T value) { return this.LowerBouond(this.Root, value); }
public int LowerBouond(Node node, T value) {
if (node == null)
return 0;
if (this.Cmp.Compare(value, node.Value) <= 0)
return this.LowerBouond(node.L, value);
else
return this.NodeCount(node.L) + 1 + this.LowerBouond(node.R, value);
}
public int UpperBound(T value) { return this.UpperBound(this.Root, value); }
public int UpperBound(Node node, T value) {
if (node == null)
return 0;
if (this.Cmp.Compare(value, node.Value) >= 0)
return this.NodeCount(node.L) + 1 + this.UpperBound(node.R, value);
else
return this.UpperBound(node.L, value);
}
public int ValueCount(T value) {
return this.UpperBound(value) - this.LowerBouond(value);
}
public void Insert(T value) {
var sub = this.Split(this.Root, this.LowerBouond(value));
var newNode = new Node(value);
var merged = this.Merge(sub.Item1, newNode);
this.Root = this.Merge(merged, sub.Item2);
}
public void Erase(T value) {
if (this.ValueCount(value) == 0)
return;
var sub = this.Split(this.Root, this.LowerBouond(value));
this.Root = this.Merge(sub.Item1, this.Split(sub.Item2, 1).Item2);
}
public void InsertAt(Node node, int k) {
var sub = this.Split(this.Root, k);
var merged = this.Merge(sub.Item1, node);
this.Root = this.Merge(merged, sub.Item2);
}
public void InsertAt(T value, int k) {
var node = new Node(value);
var sub = this.Split(this.Root, k);
var merged = this.Merge(sub.Item1, node);
this.Root = this.Merge(merged, sub.Item2);
}
public Node EraseAt(int k) {
var sub = this.Split(this.Root, k);
var sub2 = this.Split(sub.Item2, 1);
var res = sub2.Item1;
this.Root = this.Merge(sub.Item1, sub2.Item2);
return res;
}
public Node Update(Node node) {
node.Count = this.NodeCount(node.L) + this.NodeCount(node.R) + 1;
return node;
}
public class Node {
private static Random Rand = new Random();
public T Value;
public Node L = null;
public Node R = null;
public int Count;
public double Priority;
public Node(T value, double priority) {
this.Value = value;
this.Priority = priority;
this.Count = 1;
}
public Node(T value) : this(value, Rand.NextDouble()) {}
public T Get(int i) { return this.GetNode(i).Value; }
public Node GetNode(int i) {
var lcount = 0;
if (this.L != null)
lcount = this.L.Count;
if (lcount == i)
return this;
else if (lcount < i)
return this.R.GetNode(i - lcount - 1);
else
return this.L.GetNode(i);
}
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++)
yield return this.Root.Get(i);
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
public static class ObjectExtension {
// ディープコピーの複製を作る拡張メソッド
public static T DeepClone<T>(this T src) {
using (var memoryStream = new System.IO.MemoryStream()) {
var binaryFormatter =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
binaryFormatter.Serialize(memoryStream, src); // シリアライズ
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
return (T)binaryFormatter.Deserialize(memoryStream); // デシリアライズ
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 13,736
| 11
|
using System;
namespace workspace {
public class Program {
static void Main() {
//入力値受け取り
String[] data = Console.ReadLine().Split(' ');
var X = long.Parse(data[0]); //座標
var K = long.Parse(data[1]); //移動回数
var D = long.Parse(data[2]); //移動距離
//保存用
long keep = 0;
//最小値比較
var straight = Math.Min(K, X / D);
K -= straight;
X -= straight * D;
if (K % 2 == 0) {
Console.WriteLine(X);
} else {
Console.WriteLine(D - X);
}
}
}
}
|
using System;
namespace workspace {
public class Program {
static void Main() {
//入力値受け取り
String[] data = Console.ReadLine().Split(' ');
var X = long.Parse(data[0]); //座標
var K = long.Parse(data[1]); //移動回数
var D = long.Parse(data[2]); //移動距離
X = Math.Abs(X);
//最小値比較
var straight = Math.Min(K, X / D);
K -= straight;
X -= straight * D;
if (K % 2 == 0) {
Console.WriteLine(X);
} else {
Console.WriteLine(D - X);
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 140
| 10
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
// ABC175
class ProgramA {
public void main() {
//入力
string s = Console.ReadLine();
// 30以上ならYes、それ以外はNoを出力
if (s == "RRR")
Console.WriteLine(3);
else if (s == "RRS" || s == "SRR")
Console.WriteLine(2);
else if (s == "SSS")
Console.WriteLine(0);
else
Console.WriteLine(1);
}
}
class ProgramB {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long count = 0;
//それぞれの距離を求めて、距離がD以下なら1足す
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
for (int k = j + 1; k < n; k++) {
long a = long.Parse(s[i]);
long b = long.Parse(s[j]);
long c = long.Parse(s[k]);
if (a == b || b == c || c == a)
continue;
if (a + b > c && b + c > a && c + a > b)
count++;
}
//答え出力
Console.WriteLine(count);
}
}
class ProgramC {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
long X = Math.Abs(long.Parse(s[0]));
long k = long.Parse(s[1]);
long D = long.Parse(s[2]);
if (X > k * D) {
Console.WriteLine(X - k * D);
return;
}
long count = X / D;
k -= count;
if (k % 2 == 0)
Console.WriteLine(X - count * D);
else
Console.WriteLine(Math.Abs(X - (count + 1) * D));
}
}
class ProgramD {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
string s = Console.ReadLine();
int wc = 0;
int rc = 0;
//まずは赤と白の石の数を数える
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
rc++;
else
wc++;
}
//白が0なら0(冷静に赤が0なら0だがこの下に通しても通る)
if (wc == 0) {
Console.WriteLine("0");
return;
}
int rw = 0;
int ww = 0;
//左から赤の数だけ並べる。不一致の白の数を数える
for (int i = 0; i < rc; i++) {
if (s[i] == 'W')
rw++;
}
//残りは白。不一致の赤の数を数える
for (int i = rc; i < n; i++) {
if (s[i] == 'R')
ww++;
}
//答は、赤か白の違う数の小さい方と絶対値の差の和を足す
Console.WriteLine(Math.Min(rw, ww) + Math.Abs(rw - ww));
}
}
class ProgramE {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
long n = long.Parse(s[0]);
long k = long.Parse(s[1]);
long[] a = new long[n];
string[] t = Console.ReadLine().Split(' ');
for (int i = 0; i < n; i++)
a[i] = long.Parse(t[i]);
long min = 0; //最初を0にすると1に答えができる
long max = 1000000000; //答候補の最大
//二分探索(答えを決め打ちして、切る回数を数える。k回以下ならmax,そうでないならmin)
//小さくした方が回数がかかるので、maxが満たす最小の丸太の長さ
while (min + 1 != max) {
long temp = (min + max) / 2;
long cut = 0;
//切る回数を数える
for (int i = 0; i < n; i++) {
// tempが大きいなら切らない
if (a[i] < temp)
continue;
//割り切れるかどうかで回数は変わる
if (a[i] % temp == 0)
cut += a[i] / temp - 1;
else
cut += a[i] / temp;
}
// k回以下ならmax更新、そうでないならminを更新
if (cut <= k)
max = temp;
else
min = temp;
}
//答え出力
Console.WriteLine(max);
}
}
}
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
// ABC175
class ProgramA {
public void main() {
//入力
string s = Console.ReadLine();
// 30以上ならYes、それ以外はNoを出力
if (s == "RRR")
Console.WriteLine(3);
else if (s == "RRS" || s == "SRR")
Console.WriteLine(2);
else if (s == "SSS")
Console.WriteLine(0);
else
Console.WriteLine(1);
}
}
class ProgramB {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long count = 0;
//それぞれの距離を求めて、距離がD以下なら1足す
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
for (int k = j + 1; k < n; k++) {
long a = long.Parse(s[i]);
long b = long.Parse(s[j]);
long c = long.Parse(s[k]);
if (a == b || b == c || c == a)
continue;
if (a + b > c && b + c > a && c + a > b)
count++;
}
//答え出力
Console.WriteLine(count);
}
}
class ProgramC {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
long X = Math.Abs(long.Parse(s[0]));
long k = long.Parse(s[1]);
long D = long.Parse(s[2]);
long count = Math.Min(k, X / D);
k -= count;
if (k % 2 == 0)
Console.WriteLine(X - count * D);
else
Console.WriteLine(Math.Abs(X - (count + 1) * D));
}
}
class ProgramD {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
string s = Console.ReadLine();
int wc = 0;
int rc = 0;
//まずは赤と白の石の数を数える
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
rc++;
else
wc++;
}
//白が0なら0(冷静に赤が0なら0だがこの下に通しても通る)
if (wc == 0) {
Console.WriteLine("0");
return;
}
int rw = 0;
int ww = 0;
//左から赤の数だけ並べる。不一致の白の数を数える
for (int i = 0; i < rc; i++) {
if (s[i] == 'W')
rw++;
}
//残りは白。不一致の赤の数を数える
for (int i = rc; i < n; i++) {
if (s[i] == 'R')
ww++;
}
//答は、赤か白の違う数の小さい方と絶対値の差の和を足す
Console.WriteLine(Math.Min(rw, ww) + Math.Abs(rw - ww));
}
}
class ProgramE {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
long n = long.Parse(s[0]);
long k = long.Parse(s[1]);
long[] a = new long[n];
string[] t = Console.ReadLine().Split(' ');
for (int i = 0; i < n; i++)
a[i] = long.Parse(t[i]);
long min = 0; //最初を0にすると1に答えができる
long max = 1000000000; //答候補の最大
//二分探索(答えを決め打ちして、切る回数を数える。k回以下ならmax,そうでないならmin)
//小さくした方が回数がかかるので、maxが満たす最小の丸太の長さ
while (min + 1 != max) {
long temp = (min + max) / 2;
long cut = 0;
//切る回数を数える
for (int i = 0; i < n; i++) {
// tempが大きいなら切らない
if (a[i] < temp)
continue;
//割り切れるかどうかで回数は変わる
if (a[i] % temp == 0)
cut += a[i] / temp - 1;
else
cut += a[i] / temp;
}
// k回以下ならmax更新、そうでないならminを更新
if (cut <= k)
max = temp;
else
min = temp;
}
//答え出力
Console.WriteLine(max);
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 48], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 917
| 30
|
using System;
using System.Linq;
namespace _175.C {
internal class Program {
private static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(long.Parse).ToList();
var x = Math.Abs(input[0]);
var k = input[1];
var d = input[2];
var a = Math.Min(k, x / d);
k -= a;
x -= d * a;
x = (k) % 2 == 0 ? x : Math.Abs(x - d);
if (k % 2 == 0) {
Console.WriteLine(x.ToString());
} else {
Console.WriteLine((d - x).ToString());
}
}
}
}
|
using System;
using System.Linq;
namespace _175.C {
internal class Program {
private static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(long.Parse).ToList();
var x = Math.Abs(input[0]);
var k = input[1];
var d = input[2];
var a = Math.Min(k, x / d);
k -= a;
x -= d * a;
if (k % 2 == 0) {
Console.WriteLine(x.ToString());
} else {
Console.WriteLine((d - x).ToString());
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 12, 41, 15, 16, 31, 16, 31, 23, 0, 24], ["-", 12, 41, 15, 16, 31, 16, 31, 23, 0, 22], ["-", 12, 41, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 11, 12, 41, 15, 16, 31, 16, 17, 109], ["-", 0, 11, 12, 41, 15, 16, 31, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["-", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 64, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["-", 0, 11, 12, 41, 75, 213, 63, 214, 205, 22], ["-", 0, 11, 12, 41, 75, 213, 63, 214, 0, 131], ["-", 0, 11, 12, 41, 75, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 41, 75, 213, 3, 4, 0, 24], ["-", 75, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 75, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 75, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 11, 12, 41, 75, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 168
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ABC_175 {
class C {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
long[] xkd = ReadLongs();
long x = xkd[0];
long k = xkd[1];
long d = xkd[2];
if (x == 0) {
WriteLine(0);
}
x = Abs(x);
long cnt = x / d;
if (cnt > k) {
WriteLine(x - k * d);
} else {
x = x % d;
k -= cnt;
if (k % 2 == 0) {
WriteLine(x);
} else {
WriteLine(d - x);
}
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ABC_175 {
class C {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
long[] xkd = ReadLongs();
long x = xkd[0];
long k = xkd[1];
long d = xkd[2];
x = Abs(x);
long cnt = x / d;
if (cnt > k) {
WriteLine(x - k * d);
} else {
x = x % d;
k -= cnt;
if (k % 2 == 0) {
WriteLine(x);
} else {
WriteLine(d - x);
}
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22]]
| 8
| 397
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long x = sc.NextLong();
long k = sc.NextLong();
long d = sc.NextLong();
long absX = Math.Abs(x);
long count = absX / d;
if (count >= k) {
Console.WriteLine(absX - k * d);
return;
}
x = absX - count * d;
long answer = Math.Min(Math.Abs(x), Math.Abs(x - d));
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long x = sc.NextLong();
long k = sc.NextLong();
long d = sc.NextLong();
long absX = Math.Abs(x);
long count = absX / d;
if (k <= count) {
Console.WriteLine(absX - k * d);
return;
}
x = absX - count * d;
k = k - count;
long answer = 0;
if (k % 2 == 0) {
answer = Math.Abs(x);
} else {
answer = Math.Abs(x - d);
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 438
| 34
|
using static System.Math;
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var x = Abs(long.Parse(line[0]));
var k = long.Parse(line[1]);
var d = long.Parse(line[2]);
getAns(x, k, d);
}
static void getAns(long x, long k, long d) {
if (x - k * d >= 0) {
Console.WriteLine(Abs(x - k * d));
return;
}
var t = x / d;
if ((k - t) % 2 == 0)
Console.WriteLine(Abs(x - t * d));
else
Console.WriteLine(Abs(x - d * (t + 1)));
}
}
|
using static System.Math;
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var x = Abs(long.Parse(line[0]));
var k = long.Parse(line[1]);
var d = long.Parse(line[2]);
getAns(x, k, d);
}
static void getAns(long x, long k, long d) {
var t = x / d;
if (t >= k) {
Console.WriteLine(Abs(x - k * d));
return;
}
if ((k - t) % 2 == 0)
Console.WriteLine(Abs(x - t * d));
else
Console.WriteLine(Abs(x - d * (t + 1)));
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
| 8
| 190
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_C.Lib_IO;
using static Contest_C.Lib_Minifunc;
namespace Contest_C {
public static class Entry {
public static void Main() {
checked {
long x, k, d;
Lib_IO.rm(out x, out k, out d);
ll c = x / d;
if (k < c) {
wm(Abs(x - k * d));
return;
}
long ans = x - c * d;
if ((k - c) % 2 != 0)
ans -= d;
Lib_IO.wm(Abs(ans));
}
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
[CS.MethodImpl(256)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static T[][][] inita<T>(long l1, long l2, long l3, T v = default(T)) {
var m = new T[l1][][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, l3, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e, out Y f) {
var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_C.Lib_IO;
using static Contest_C.Lib_Minifunc;
namespace Contest_C {
public static class Entry {
public static void Main() {
checked {
long x, k, d;
Lib_IO.rm(out x, out k, out d);
x = Abs(x);
ll c = x / d;
if (k < c) {
wm(Abs(x - k * d));
return;
}
long ans = x - c * d;
if ((k - c) % 2 != 0)
ans -= d;
Lib_IO.wm(Abs(ans));
}
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
[CS.MethodImpl(256)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static T[][][] inita<T>(long l1, long l2, long l3, T v = default(T)) {
var m = new T[l1][][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, l3, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e, out Y f) {
var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
[["+", 0, 287, 0, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 287, 0, 196, 0, 1, 0, 35]]
| 8
| 4,266
| 7
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var r = ReadSplit();
var x = Math.Abs(r[0].Long());
var k = r[1].Long();
var d = r[2].Long();
long ans = 0;
if (x >= k * d) {
ans = x - k * d;
WriteRead(ans);
return;
}
var c = x / d;
var now = x - c * d;
var z = k - c;
if (z % 2 == 0) {
ans = now;
} else {
ans = Math.Abs(now - d);
}
WriteRead(ans);
}
private static void Dfs(int key, int par, int[] ans,
Dictionary<int, List<int>> dic) {
var color = 1;
if (!dic.ContainsKey(key)) {
return;
}
foreach (var item in dic[key]) {
if (color == par) {
color++;
}
ans[item] = color;
Dfs(item, color, ans, dic);
color++;
}
}
public static List<long> GetCalcDivisor(long n) {
var res = new List<long>();
for (long i = 1L; i * i <= n; ++i) {
if (n % i == 0) {
res.Add(i);
long j = n / i;
if (j != i)
res.Add(j);
}
}
res.Sort();
return res;
}
class ModCombination {
public long _mod = 1000000007;
public int _max = 1000000;
long[] fac;
long[] finv;
long[] inv;
public ModCombination() : this(1000000007, 1000000) {}
public ModCombination(long mod, int max) {
_mod = mod;
_max = max;
fac = new long[max];
finv = new long[max];
inv = new long[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
public long Combination(int n, int m) {
if (n < m)
return 0;
if (n < 0 || m < 0)
return 0;
return fac[n] * (finv[m] * finv[n - m] % _mod) % _mod;
}
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
public static long ModPow(long x, long n) {
x = x % mod;
if (n == 0) {
return 1;
} else if (n % 2 == 1) {
return (x * ModPow(x, n - 1)) % mod;
} else {
return ModPow((x * x) % mod, n / 2) % mod;
}
}
/// <summary>
/// 最小公倍数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
/// <summary>
/// 最大公約数
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var r = ReadSplit();
var x = (ulong)Math.Abs(r[0].Long());
var k = (ulong)r[1].Long();
var d = (ulong)r[2].Long();
ulong ans = 0;
if (x >= k * d) {
ans = x - k * d;
WriteRead(ans);
return;
}
ulong c = x / d;
ulong now = x - c * d;
ulong z = k - c;
if (z % 2 == 0) {
ans = now;
} else {
ans = now - d;
}
WriteRead(Math.Abs((long)ans));
}
private static void Dfs(int key, int par, int[] ans,
Dictionary<int, List<int>> dic) {
var color = 1;
if (!dic.ContainsKey(key)) {
return;
}
foreach (var item in dic[key]) {
if (color == par) {
color++;
}
ans[item] = color;
Dfs(item, color, ans, dic);
color++;
}
}
public static List<long> GetCalcDivisor(long n) {
var res = new List<long>();
for (long i = 1L; i * i <= n; ++i) {
if (n % i == 0) {
res.Add(i);
long j = n / i;
if (j != i)
res.Add(j);
}
}
res.Sort();
return res;
}
class ModCombination {
public long _mod = 1000000007;
public int _max = 1000000;
long[] fac;
long[] finv;
long[] inv;
public ModCombination() : this(1000000007, 1000000) {}
public ModCombination(long mod, int max) {
_mod = mod;
_max = max;
fac = new long[max];
finv = new long[max];
inv = new long[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
public long Combination(int n, int m) {
if (n < m)
return 0;
if (n < 0 || m < 0)
return 0;
return fac[n] * (finv[m] * finv[n - m] % _mod) % _mod;
}
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
public static long ModPow(long x, long n) {
x = x % mod;
if (n == 0) {
return 1;
} else if (n % 2 == 1) {
return (x * ModPow(x, n - 1)) % mod;
} else {
return ModPow((x * x) % mod, n / 2) % mod;
}
}
/// <summary>
/// 最小公倍数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
/// <summary>
/// 最大公約数
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 1,839
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(" ");
var X = long.Parse(input[0]);
var K = long.Parse(input[1]);
var D = long.Parse(input[2]);
var numOfMove = Math.Abs(X) / D;
long position = 0;
if (numOfMove > K)
position = X - (K * D);
else {
// 必要な移動回数と実際の移動回数が奇数同士or偶数同士なら最小の値が取れる
if (numOfMove % 2 == 0 && K % 2 == 0)
position = X % D;
else if (numOfMove % 2 != 0 && K % 2 != 0)
position = X % D;
else {
position = Math.Min(Math.Abs(X % D + D), Math.Abs(X % D - D));
}
}
Console.WriteLine(position);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(" ");
var X = long.Parse(input[0]);
var K = long.Parse(input[1]);
var D = long.Parse(input[2]);
var numOfMove = Math.Abs(X) / D;
long position = 0;
if (numOfMove > K) {
position = Math.Abs(X) - (K * D);
} else {
// 必要な移動回数と実際の移動回数が奇数同士or偶数同士なら最小の値が取れる
if (numOfMove % 2 == 0 && K % 2 == 0)
position = X % D;
else if (numOfMove % 2 != 0 && K % 2 != 0)
position = X % D;
else {
position = Math.Min(Math.Abs(X % D + D), Math.Abs(X % D - D));
}
}
Console.WriteLine(Math.Abs(position));
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 11, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 202
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
long x = long.Parse(str[0]);
long k = long.Parse(str[1]);
long d = long.Parse(str[2]);
long ans = 0;
if (k > x / d) {
long xx = Math.Abs(x) % d;
long kk = k - x / d;
// Console.WriteLine(xx);
// Console.WriteLine(kk);
long kkk = kk % 2;
ans = Math.Abs(xx - d * kkk);
} else {
ans = Math.Abs(Math.Abs(x) - k * d);
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
long x = long.Parse(str[0]);
long k = long.Parse(str[1]);
long d = long.Parse(str[2]);
long ans = 0;
long absx = Math.Abs(x);
if (k > (absx / d)) {
long xx = Math.Abs(x) % d;
long kk = k - x / d;
// Console.WriteLine(xx);
// Console.WriteLine(kk);
long kkk = kk % 2;
ans = Math.Abs(xx - d * kkk);
} else {
ans = Math.Abs(Math.Abs(x) - k * d);
}
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 189
| 14
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
static public string al = "abcdefghijklmnopqrstuvwxyz";
public static void Main() {
// •ûj
//
var tn = longa();
var x = Abs(tn[0]);
var k = tn[1];
var d = tn[2];
if (k <= 50000000) {
for (int i = 0; i < k; i++) {
x = Min(Abs(x - d), Abs(x + d));
}
WriteLine(x);
return;
}
var xd = x / d;
if (xd > k) {
x -= d * k;
WriteLine(x);
return;
}
x -= d * xd;
k -= xd;
if (k == 0) {
WriteLine(x);
return;
}
if (x > Abs(x - d)) {
x -= d;
k--;
}
if (k % 2 == 0) {
WriteLine(x);
} else {
WriteLine(Min(Abs(x + d), Abs(x - d)));
}
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
if (n < r)
return 0;
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//Šeí“Çæ
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = double.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
static public string al = "abcdefghijklmnopqrstuvwxyz";
public static void Main() {
// •ûj
//
var tn = longa();
var x = Abs(tn[0]);
var k = tn[1];
var d = tn[2];
if (k <= 50000000) {
for (int i = 0; i < k; i++) {
x = Min(Abs(x - d), Abs(x + d));
}
WriteLine(x);
return;
}
var xd = x / d;
if (xd > k) {
x -= d * k;
WriteLine(Abs(x));
return;
}
x -= d * xd;
k -= xd;
if (k == 0) {
WriteLine(Abs(x));
return;
}
if (x > Abs(x - d)) {
x -= d;
k--;
}
if (k % 2 == 0) {
WriteLine(Abs(x));
} else {
WriteLine(Min(Abs(x + d), Abs(x - d)));
}
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
if (n < r)
return 0;
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//Šeí“Çæ
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = double.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 1,265
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
public const long mod = 1000000007;
static void Main(string[] args) {
var n = Input();
long ans = 0;
long ten = 1;
long nine = 1;
long eight = 1;
for (long i = 1; i <= n; i++) {
ten *= 10;
nine *= 9;
eight *= 8;
ten = ten % mod;
nine = nine % mod;
eight = eight % mod;
}
ans = (ten - nine * 2 + eight) % mod;
Console.WriteLine(ans);
}
static public long Input() { return long.Parse(Console.ReadLine()); }
static public string[] Input2() { return Console.ReadLine().Split(); }
/*static public void DFS(int h, int w, bool[][] _visited)
{
if (w < 0 || h < 0 || h > _visited.Length - 1 || w > _visited[h].Length-1
|| map[h][w]=='x') return; if (_visited[h][w]) return;
//Console.WriteLine(h + " " + w+" "+ _visited[h].Length + " " +
_visited.Length); _visited[h][w] = true;
DFS(h + 1, w,_visited);
DFS(h - 1, w,_visited);
DFS(h, w + 1,_visited);
DFS(h, w - 1,_visited);
}*/
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
public const long mod = 1000000007;
static void Main(string[] args) {
var n = Input();
long ans = 0;
long ten = 1;
long nine = 1;
long eight = 1;
for (long i = 1; i <= n; i++) {
ten *= 10;
nine *= 9;
eight *= 8;
ten = ten % mod;
nine = nine % mod;
eight = eight % mod;
}
ans = (ten - nine * 2 + eight) % mod;
if (ans < 0)
ans += mod;
Console.WriteLine(ans);
}
static public long Input() { return long.Parse(Console.ReadLine()); }
static public string[] Input2() { return Console.ReadLine().Split(); }
/*static public void DFS(int h, int w, bool[][] _visited)
{
if (w < 0 || h < 0 || h > _visited.Length - 1 || w > _visited[h].Length-1
|| map[h][w]=='x') return; if (_visited[h][w]) return;
//Console.WriteLine(h + " " + w+" "+ _visited[h].Length + " " +
_visited.Length); _visited[h][w] = true;
DFS(h + 1, w,_visited);
DFS(h - 1, w,_visited);
DFS(h, w + 1,_visited);
DFS(h, w - 1,_visited);
}*/
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 189
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace AtCoderBeginnerContest178 {
class Program {
static void Main(string[] args) {
// 課題C - Ubiquity(2020/9/13)
int input = int.Parse(Console.ReadLine());
int modItem = 1000000007;
long allPtn = 10;
long delPtn = 9;
long plusPtn = 8;
for (int i = 0; i < input - 1; i++) {
allPtn = allPtn * 10 % modItem;
delPtn = delPtn * 9 % modItem;
plusPtn = plusPtn * 8 % modItem;
}
long result = (allPtn - 2 * delPtn + plusPtn) % modItem;
Console.Write(result);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace AtCoderBeginnerContest178 {
class Program {
static void Main(string[] args) {
// 課題C - Ubiquity(2020/9/13)
int input = int.Parse(Console.ReadLine());
int modItem = 1000000007;
long allPtn = 10;
long delPtn = 9;
long plusPtn = 8;
for (int i = 0; i < input - 1; i++) {
allPtn = allPtn * 10 % modItem;
delPtn = delPtn * 9 % modItem;
plusPtn = plusPtn * 8 % modItem;
}
long result = (allPtn - 2 * delPtn + plusPtn) % modItem;
if (result < 0)
result = result + modItem;
Console.Write(result);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 140
| 12
|
//
// ABC178C
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_c
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace AtCoder.Template.ABC178C {
class Solver {
public static readonly long MOD_CONST =
1000000007; //(long)Math.Pow(10, 9) + 7;
public static void Main(string[] args) {
//出力高速化
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
public void Solve() {
int N = int.Parse(Console.ReadLine());
long WholeSet = powMod(10, N);
long Set0 = powMod(9, N);
long Set9 = Set0;
long Set0_9 = powMod(8, N);
long ans = (WholeSet - Set0) % MOD_CONST;
if (ans - Set9 < 0) {
ans = (ans - Set9 + MOD_CONST) % MOD_CONST;
} else {
ans = ans - Set9 % MOD_CONST;
}
ans = (ans + Set0_9) % MOD_CONST;
Console.WriteLine(ans);
}
/// <summary>
/// b^pを計算する
/// MOD_CONSTを考慮して、計算途中で毎回MODとる
/// </summary>
/// <param name="b">底</param>
/// <param name="p">冪数</param>
/// <returns></returns>
public static long powMod(long b, long p) {
long ans = 1;
for (long i = 0; i < p; ++i) {
ans = ans * b % MOD_CONST;
}
return ans;
}
//---------------------------------------------------------------------------------
#region MyLib
/// <summary>
/// string -> List<char>に分解する。1文字がListの1要素
/// </summary>
/// <param name="a"></param>
/// <returns></returns>
public static List<char> separeteToList(string a) {
var l = new List<char>(a.Length);
foreach (char x in a) {
l.Add(x);
}
return l;
}
/// <summary>
/// List<char> -> stringに合成する
/// </summary>
/// <param name="l"></param>
/// <returns></returns>
public static string combineCharList(List<char> l) {
var ans = new StringBuilder();
foreach (char x in l) {
ans.Append(x);
}
return ans.ToString();
}
/// <summary>
/// Aの文字をなるべくCorrectに合うように並びかえる。当然Correctにしかない文字もあるので、その場合はAの適当な文字で置き換える
/// 例)
/// A = abcde, eppstein
/// Corrent = acfbe, pipeline
/// ans = acdbe, pspetine
/// </summary>
/// <param name="A"></param>
/// <param name="Correct"></param>
public static List<char> FillChar(List<char> A, List<char> Correct) {
char Empty = ' ';
var ARemain = new List<char>(A);
var ans = new List<char>(A.Count);
for (int i = 0; i < Correct.Count; ++i) {
// Aの文字をなるべくCorrectに合うように、ansの文字を決める
int foundPos = ARemain.FindIndex(x => x == Correct[i]);
if (foundPos != -1) //文字がCorrectの中で見つかったら
{
char found = ARemain[foundPos];
ans.Add(found);
ARemain.Remove(found); //使った文字は除外
} else // Aにない文字もある。後で使わなかったAの適当な文字で埋める
{
ans.Add(Empty);
}
}
// Aにない文字がCorrectにあったら、Aの残りの文字で適当に埋める
for (int i = 0; i < A.Count; ++i) {
if (ans[i] == Empty) {
ans[i] = ARemain.First();
ARemain.RemoveAt(0);
}
}
return ans;
}
/// <summary>
/// リストから、重複したものを除外したリストを新規に作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="src"></param>
/// <param name="dst"></param>
public static void getDistinctList<T>(List<T> src, out List<T> dst) {
var iter = src.Distinct();
dst = new List<T>();
foreach (var item in iter) {
dst.Add(item);
}
}
/// <summary>
/// グラフ系
/// </summary>
public class Node {
public Node(long val) {
this.Value = val;
this.Children = new List<Node>();
}
public Node(long val, List<Node> children) {
this.Value = val;
this.Children = children;
}
public long Value { get; set; }
public List<Node> Children { get; set; }
}
public class UnionFind {
/// <summary>
/// parentId[x] : 要素xの親を返す
/// 例: parentId[3] => 2 : 要素3の親は2
/// ただしrootのみ、その木のサイズを返す
/// </summary>
private List<int> parentId;
public UnionFind(int n) {
parentId = new List<int>(n);
//最初はすべての木が独立。親は自分自身
for (int i = 0; i < n; ++i) {
parentId.Add(-1);
}
}
/// <summary>
/// 要素xが属する木の根の要素を返す
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public int root(int x) {
//自身の親が負なら、自身が根っこ
if (parentId[x] < 0) {
return x;
}
parentId[x] = root(parentId[x]); //経路の圧縮
return parentId[x];
}
/// <summary>
/// 要素x,yの入った木を併合する
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void unite(int x, int y) {
//それぞれの要素の根っこを調査
//以降、根っこにしか興味がないので、x,yを上書き
x = root(x);
y = root(y);
if (x ==
y) //どちらの要素のrootも同じ要素を指していたので、同じ木だった。よって併合しない
{
return;
}
//併合
//より木の深さが短くなるようにするため、要素数から、どちらの木がrootになるかを決定する
if (size(x) < size(y)) // xの木がyの木より大きくなるようにする
{
Swap<int>(ref x, ref y);
}
//この時点でxの木のほうがyの木より大きい
// rootの親の要素(=木の要素数)の更新
parentId[x] += parentId[y];
//より大きなxの木がyの木より大きくなるように、根っこをマージ
// yの木がxの木に付け加えられる
parentId[y] = x; // yの根っこryの親を要素xにした
}
/// <summary>
/// 要素x,yが入った木は同一の木か
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
/// <summary>
/// 要素xがある木の要素数を返す
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public int size(int x) {
// rootの親=要素数。uniteするたびに要素数が増えていく
return -parentId[root(x)];
}
}
/// <summary>
/// Clamping
/// </summary>
/// <typeparam name="T">比較型</typeparam>
/// <param name="x">clampしたい値</param>
/// <param name="min">最小値</param>
/// <param name="max">最大値</param>
/// <returns>clamp済みの値</returns>
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T> {
if (x.CompareTo(min) < 0) {
return min;
} else if (x.CompareTo(max) > 0) {
return max;
} else
return x;
// return Math.Max(Math.Min(x, max), min);
}
/// <summary>
/// 指定された底log_baseでの, 対数を計算
/// </summary>
/// <param name="x"></param>
/// <param name="log_base">指定の底</param>
/// <returns></returns>
public static double LogBase(double x, double log_base) {
// log_b(N) = log_a(N) / log_a(B)より
return Math.Log(x) / Math.Log(log_base);
}
/// <summary>
/// 交換
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="lhs"></param>
/// <param name="rhs"></param>
public static void Swap<T>(ref T lhs, ref T rhs) {
T temp = lhs;
lhs = rhs;
rhs = temp;
}
/// <summary>
/// 初項a, 公差d, 項数nの数列の和
/// </summary>
/// <param name="n">求めたいところ</param>
/// <returns>初項からxまで足した値</returns>
static long SumSeries(long a, long d, long n) {
return (2 * a + (n - 1) * d) * n / 2;
}
/// <summary>
/// 累積和の配列を計算する
/// Sum[ a[0], a[i] )がs[i+1]に入っている
/// s[0] : 0 //一切和を取らない場合
/// s[1] : ls[0] //a[0] + s[0] = a[0]
/// s[2] : ls[1] + s[1] //a[1] + a[0]
/// ...
/// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0]
/// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0]
///
/// 例: [1, 7)の和(a[1] + ... + a[6])
/// s[1] = a[0] //[0, 1)
/// s[7] = a[0] + a[1] + ... + a[6] //[0, 7)
/// よってs[7] - s[1]);
/// </summary>
/// <param name="ls">計算したい配列</param>
/// <returns>累積和配列</returns>
static List<long> AggregateSumList(List<long> a) {
var s = new List<long>(a.Count + 1);
if (a.Count == 0) {
return s;
}
s.Add(0); // s[0] = 0
for (int i = 0; i < a.Count; ++i) {
s.Add(a[i] + s[i]);
}
return s;
}
/// <summary>
/// 与えられた数が素数かどうかを計算する
/// </summary>
/// <param name="num">対象数</param>
/// <returns>true:素数, false:素数ではない(合成数)</returns>
public static bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
/// <summary>
/// 素因数分解
/// </summary>
/// <param name="n"></param>
/// <returns>keyが素数、valueがその素数の登場回数</returns>
public static Dictionary<long, long> PrimeFactorization(long n) {
var result = new Dictionary<long, long>();
//初めの素数2から割っていく
for (long p = 2; p * p <= n; p++) {
//割り切れないなら、素因数に含まれてない
if (n % p != 0)
continue;
long count = 0;
// 割り続ける
while (n % p == 0) {
count++;
n /= p;
}
result[p] = count;
}
// 素数が残っている場合
if (n != 1)
result[n] = 1;
return result;
}
/// <summary>
/// 順列mPnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Permutation(long m, long n) {
long ret = 1;
for (var i = 0; i < n; ++i) {
ret *= m - i;
}
return ret;
}
/// <summary>
/// 組み合わせmCnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Combination(long m, long n) {
if (m == n || n == 0) {
return 1;
}
long ans = 1;
for (var i = 1; i <= n; ++i) {
ans = ans * (m - i + 1) / i;
}
return ans;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
static long Lcm(long m, long n) {
var gcd = Gcd(m, n);
// return (m * n) / gcd;
return m / gcd * n; //桁あふれ対策
}
#endregion MyLib
}
}
|
//
// ABC178C
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_c
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace AtCoder.Template.ABC178C {
class Solver {
public static readonly long MOD_CONST =
1000000007; //(long)Math.Pow(10, 9) + 7;
public static void Main(string[] args) {
//出力高速化
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
public void Solve() {
int N = int.Parse(Console.ReadLine());
long WholeSet = powMod(10, N);
long Set0 = powMod(9, N);
long Set9 = Set0;
long Set0_9 = powMod(8, N);
long ans = WholeSet;
if (ans - Set0 < 0) {
ans = ans - Set0 + MOD_CONST;
} else {
ans = ans - Set0;
}
if (ans - Set9 < 0) {
ans = ans - Set9 + MOD_CONST;
} else {
ans = ans - Set9;
}
ans = (ans + Set0_9) % MOD_CONST;
Console.WriteLine(ans);
}
/// <summary>
/// b^pを計算する
/// MOD_CONSTを考慮して、計算途中で毎回MODとる
/// </summary>
/// <param name="b">底</param>
/// <param name="p">冪数</param>
/// <returns></returns>
public static long powMod(long b, long p) {
long ans = 1;
for (long i = 0; i < p; ++i) {
ans = ans * b % MOD_CONST;
}
return ans;
}
//---------------------------------------------------------------------------------
#region MyLib
/// <summary>
/// string -> List<char>に分解する。1文字がListの1要素
/// </summary>
/// <param name="a"></param>
/// <returns></returns>
public static List<char> separeteToList(string a) {
var l = new List<char>(a.Length);
foreach (char x in a) {
l.Add(x);
}
return l;
}
/// <summary>
/// List<char> -> stringに合成する
/// </summary>
/// <param name="l"></param>
/// <returns></returns>
public static string combineCharList(List<char> l) {
var ans = new StringBuilder();
foreach (char x in l) {
ans.Append(x);
}
return ans.ToString();
}
/// <summary>
/// Aの文字をなるべくCorrectに合うように並びかえる。当然Correctにしかない文字もあるので、その場合はAの適当な文字で置き換える
/// 例)
/// A = abcde, eppstein
/// Corrent = acfbe, pipeline
/// ans = acdbe, pspetine
/// </summary>
/// <param name="A"></param>
/// <param name="Correct"></param>
public static List<char> FillChar(List<char> A, List<char> Correct) {
char Empty = ' ';
var ARemain = new List<char>(A);
var ans = new List<char>(A.Count);
for (int i = 0; i < Correct.Count; ++i) {
// Aの文字をなるべくCorrectに合うように、ansの文字を決める
int foundPos = ARemain.FindIndex(x => x == Correct[i]);
if (foundPos != -1) //文字がCorrectの中で見つかったら
{
char found = ARemain[foundPos];
ans.Add(found);
ARemain.Remove(found); //使った文字は除外
} else // Aにない文字もある。後で使わなかったAの適当な文字で埋める
{
ans.Add(Empty);
}
}
// Aにない文字がCorrectにあったら、Aの残りの文字で適当に埋める
for (int i = 0; i < A.Count; ++i) {
if (ans[i] == Empty) {
ans[i] = ARemain.First();
ARemain.RemoveAt(0);
}
}
return ans;
}
/// <summary>
/// リストから、重複したものを除外したリストを新規に作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="src"></param>
/// <param name="dst"></param>
public static void getDistinctList<T>(List<T> src, out List<T> dst) {
var iter = src.Distinct();
dst = new List<T>();
foreach (var item in iter) {
dst.Add(item);
}
}
/// <summary>
/// グラフ系
/// </summary>
public class Node {
public Node(long val) {
this.Value = val;
this.Children = new List<Node>();
}
public Node(long val, List<Node> children) {
this.Value = val;
this.Children = children;
}
public long Value { get; set; }
public List<Node> Children { get; set; }
}
public class UnionFind {
/// <summary>
/// parentId[x] : 要素xの親を返す
/// 例: parentId[3] => 2 : 要素3の親は2
/// ただしrootのみ、その木のサイズを返す
/// </summary>
private List<int> parentId;
public UnionFind(int n) {
parentId = new List<int>(n);
//最初はすべての木が独立。親は自分自身
for (int i = 0; i < n; ++i) {
parentId.Add(-1);
}
}
/// <summary>
/// 要素xが属する木の根の要素を返す
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public int root(int x) {
//自身の親が負なら、自身が根っこ
if (parentId[x] < 0) {
return x;
}
parentId[x] = root(parentId[x]); //経路の圧縮
return parentId[x];
}
/// <summary>
/// 要素x,yの入った木を併合する
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void unite(int x, int y) {
//それぞれの要素の根っこを調査
//以降、根っこにしか興味がないので、x,yを上書き
x = root(x);
y = root(y);
if (x ==
y) //どちらの要素のrootも同じ要素を指していたので、同じ木だった。よって併合しない
{
return;
}
//併合
//より木の深さが短くなるようにするため、要素数から、どちらの木がrootになるかを決定する
if (size(x) < size(y)) // xの木がyの木より大きくなるようにする
{
Swap<int>(ref x, ref y);
}
//この時点でxの木のほうがyの木より大きい
// rootの親の要素(=木の要素数)の更新
parentId[x] += parentId[y];
//より大きなxの木がyの木より大きくなるように、根っこをマージ
// yの木がxの木に付け加えられる
parentId[y] = x; // yの根っこryの親を要素xにした
}
/// <summary>
/// 要素x,yが入った木は同一の木か
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
/// <summary>
/// 要素xがある木の要素数を返す
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public int size(int x) {
// rootの親=要素数。uniteするたびに要素数が増えていく
return -parentId[root(x)];
}
}
/// <summary>
/// Clamping
/// </summary>
/// <typeparam name="T">比較型</typeparam>
/// <param name="x">clampしたい値</param>
/// <param name="min">最小値</param>
/// <param name="max">最大値</param>
/// <returns>clamp済みの値</returns>
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T> {
if (x.CompareTo(min) < 0) {
return min;
} else if (x.CompareTo(max) > 0) {
return max;
} else
return x;
// return Math.Max(Math.Min(x, max), min);
}
/// <summary>
/// 指定された底log_baseでの, 対数を計算
/// </summary>
/// <param name="x"></param>
/// <param name="log_base">指定の底</param>
/// <returns></returns>
public static double LogBase(double x, double log_base) {
// log_b(N) = log_a(N) / log_a(B)より
return Math.Log(x) / Math.Log(log_base);
}
/// <summary>
/// 交換
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="lhs"></param>
/// <param name="rhs"></param>
public static void Swap<T>(ref T lhs, ref T rhs) {
T temp = lhs;
lhs = rhs;
rhs = temp;
}
/// <summary>
/// 初項a, 公差d, 項数nの数列の和
/// </summary>
/// <param name="n">求めたいところ</param>
/// <returns>初項からxまで足した値</returns>
static long SumSeries(long a, long d, long n) {
return (2 * a + (n - 1) * d) * n / 2;
}
/// <summary>
/// 累積和の配列を計算する
/// Sum[ a[0], a[i] )がs[i+1]に入っている
/// s[0] : 0 //一切和を取らない場合
/// s[1] : ls[0] //a[0] + s[0] = a[0]
/// s[2] : ls[1] + s[1] //a[1] + a[0]
/// ...
/// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0]
/// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0]
///
/// 例: [1, 7)の和(a[1] + ... + a[6])
/// s[1] = a[0] //[0, 1)
/// s[7] = a[0] + a[1] + ... + a[6] //[0, 7)
/// よってs[7] - s[1]);
/// </summary>
/// <param name="ls">計算したい配列</param>
/// <returns>累積和配列</returns>
static List<long> AggregateSumList(List<long> a) {
var s = new List<long>(a.Count + 1);
if (a.Count == 0) {
return s;
}
s.Add(0); // s[0] = 0
for (int i = 0; i < a.Count; ++i) {
s.Add(a[i] + s[i]);
}
return s;
}
/// <summary>
/// 与えられた数が素数かどうかを計算する
/// </summary>
/// <param name="num">対象数</param>
/// <returns>true:素数, false:素数ではない(合成数)</returns>
public static bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
/// <summary>
/// 素因数分解
/// </summary>
/// <param name="n"></param>
/// <returns>keyが素数、valueがその素数の登場回数</returns>
public static Dictionary<long, long> PrimeFactorization(long n) {
var result = new Dictionary<long, long>();
//初めの素数2から割っていく
for (long p = 2; p * p <= n; p++) {
//割り切れないなら、素因数に含まれてない
if (n % p != 0)
continue;
long count = 0;
// 割り続ける
while (n % p == 0) {
count++;
n /= p;
}
result[p] = count;
}
// 素数が残っている場合
if (n != 1)
result[n] = 1;
return result;
}
/// <summary>
/// 順列mPnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Permutation(long m, long n) {
long ret = 1;
for (var i = 0; i < n; ++i) {
ret *= m - i;
}
return ret;
}
/// <summary>
/// 組み合わせmCnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Combination(long m, long n) {
if (m == n || n == 0) {
return 1;
}
long ans = 1;
for (var i = 1; i <= n; ++i) {
ans = ans * (m - i + 1) / i;
}
return ans;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
static long Lcm(long m, long n) {
var gcd = Gcd(m, n);
// return (m * n) / gcd;
return m / gcd * n; //桁あふれ対策
}
#endregion MyLib
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 17, 109], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 22]]
| 8
| 1,665
| 31
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.Remoting;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static Dictionary<long, long> primeDic = new Dictionary<long, long>();
static long x;
static long k;
static long d;
static void Solve() {
x = Input.NextLong();
k = Input.NextLong();
d = Input.NextLong();
var ans = Calc();
Console.WriteLine(ans);
}
private static long Calc() {
x = Math.Abs(x);
if (x == 0) {
return Get0();
} else if (x == d) {
k = k - 1;
return Get0();
} else if (x < d) {
return GetX_D();
} else {
long x2 = x % d;
if ((x - x2) / d > k) {
return x - k * d;
} else {
x = x2;
k -= (x - x2) / d;
return GetX_D();
}
}
}
private static long Get0() { return k % 2 == 0 ? 0 : d; }
private static long GetX_D() { return k % 2 == 0 ? x : x - d; }
#region よく使う便利関数
private static void TrialDivision(long m) {
for (long i = 2; i * i <= m; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
primeDic.Add(i, ex);
}
}
if (m >= 2) {
primeDic.Add(m, 1);
}
// note まぁ1は違うよね
}
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.Remoting;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static Dictionary<long, long> primeDic = new Dictionary<long, long>();
static long x;
static long k;
static long d;
static void Solve() {
x = Input.NextLong();
k = Input.NextLong();
d = Input.NextLong();
var ans = Calc();
Console.WriteLine(ans);
}
private static long Calc() {
x = Math.Abs(x);
if (x == 0) {
return Get0();
} else if (x == d) {
k = k - 1;
return Get0();
} else if (x < d) {
return GetX_D();
} else {
long x2 = x % d;
if ((x - x2) / d >= k) {
return Math.Abs(x - k * d);
} else {
k -= (x - x2) / d;
x = x2;
return GetX_D();
}
}
}
private static long Get0() { return k % 2 == 0 ? 0 : d; }
// X < D
private static long GetX_D() { return k % 2 == 0 ? x : Math.Abs(x - d); }
#region よく使う便利関数
private static void TrialDivision(long m) {
for (long i = 2; i * i <= m; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
primeDic.Add(i, ex);
}
}
if (m >= 2) {
primeDic.Add(m, 1);
}
// note まぁ1は違うよね
}
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["-", 75, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 75, 57, 75, 196, 0, 57, 15, 16, 17, 20], ["+", 64, 196, 0, 37, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 37, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 37, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 37, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 37, 0, 213, 3, 4, 0, 25], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["-", 75, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 37, 0, 41, 75, 213, 63, 214, 205, 22], ["+", 0, 37, 0, 41, 75, 213, 63, 214, 0, 131], ["+", 0, 37, 0, 41, 75, 213, 63, 214, 141, 22], ["+", 0, 37, 0, 41, 75, 213, 3, 4, 0, 24], ["+", 0, 37, 0, 41, 75, 213, 3, 4, 0, 25]]
| 8
| 2,721
| 20
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
class Program {
static void Main(string[] args) {
var line = Console.ReadLine().Split(' ');
var x = long.Parse(line[0]);
var k = long.Parse(line[1]);
var d = long.Parse(line[2]);
var firstMoveCount = Math.Abs(x) / d;
var firstMovedPlace = Math.Abs(x) % d;
if (x < 0) {
firstMovedPlace *= -1;
}
var rem = k - firstMoveCount;
if (rem > 0) {
if (rem % 2 == 0) {
Console.WriteLine(firstMovedPlace);
} else {
Console.WriteLine(Math.Abs(firstMovedPlace - d) >
Math.Abs(firstMovedPlace + d)
? Math.Abs(firstMovedPlace + d)
: Math.Abs(firstMovedPlace - d));
}
} else {
var ans = Math.Abs(x) - (k * d);
if (x < 0) {
ans *= -1;
}
Console.WriteLine(ans);
}
Console.ReadLine();
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
class Program {
static void Main(string[] args) {
var line = Console.ReadLine().Split(' ');
var x = long.Parse(line[0]);
var k = long.Parse(line[1]);
var d = long.Parse(line[2]);
var firstMoveCount = Math.Abs(x) / d;
var firstMovedPlace = Math.Abs(x) % d;
if (x < 0) {
firstMovedPlace *= -1;
}
var rem = k - firstMoveCount;
if (rem > 0) {
if (rem % 2 == 0) {
Console.WriteLine(Math.Abs(firstMovedPlace));
} else {
Console.WriteLine(Math.Abs(firstMovedPlace - d) >
Math.Abs(firstMovedPlace + d)
? Math.Abs(firstMovedPlace + d)
: Math.Abs(firstMovedPlace - d));
}
} else {
var ans = Math.Abs(x) - (k * d);
if (x < 0) {
ans *= -1;
}
Console.WriteLine(Math.Abs(ans));
}
Console.ReadLine();
}
}
|
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 248
| 10
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Tasks {
public class C {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var (X, K, D) = Scanner.Scan<long, long, long>();
var tmp = Math.Min(K, X / D + 1);
X -= tmp * D;
K -= tmp;
Console.WriteLine(K % 2 == 0 ? Math.Abs(X)
: Math.Min(Math.Abs(X + D), Math.Abs(X - D)));
}
public static class Scanner {
private static Queue<string> queue = new Queue<string>();
public static T Next<T>() {
if (!queue.Any())
foreach (var item in Console.ReadLine().Trim().Split(" "))
queue.Enqueue(item);
return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
}
public static T Scan<T>() => Next<T>();
public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(),
Next<T3>());
public static (T1, T2, T3,
T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(),
Next<T3>(), Next<T4>());
public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() =>
(Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Tasks {
public class C {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var (X, K, D) = Scanner.Scan<long, long, long>();
var tmp = Math.Min(K, Math.Abs(X) / D);
if (X >= 0) {
X -= tmp * D;
} else {
X += tmp * D;
}
K -= tmp;
Console.WriteLine(K % 2 == 0 ? Math.Abs(X)
: Math.Min(Math.Abs(X + D), Math.Abs(X - D)));
}
public static class Scanner {
private static Queue<string> queue = new Queue<string>();
public static T Next<T>() {
if (!queue.Any())
foreach (var item in Console.ReadLine().Trim().Split(" "))
queue.Enqueue(item);
return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
}
public static T Scan<T>() => Next<T>();
public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(),
Next<T3>());
public static (T1, T2, T3,
T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(),
Next<T3>(), Next<T4>());
public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() =>
(Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
}
}
}
|
[["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 481
| 24
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
long mod = 1000000007;
int N = int.Parse(Console.ReadLine());
long result = pow(10, N) - pow(9, N) + pow(8, N) - pow(9, N);
result %= mod;
Console.WriteLine(result);
Console.ReadLine();
}
static long pow(long b, int p) {
long mod = 1000000007;
long result = 1;
for (int i = 0; i < p; i++) {
result = (result * b) % mod;
}
return result;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
long mod = 1000000007;
int N = int.Parse(Console.ReadLine());
long result = pow(10, N) - pow(9, N) + pow(8, N) - pow(9, N);
result %= mod;
result = (result + mod) % mod;
Console.WriteLine(result);
Console.ReadLine();
}
static long pow(long b, int p) {
long mod = 1000000007;
long result = 1;
for (int i = 0; i < p; i++) {
result = (result * b) % mod;
}
return result;
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 152
| 10
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var s = sc.La;
long p = Abs(s[0]) / s[2];
if (s[1] >= p) {
s[1] -= p;
} else {
if (s[0] < 0) {
s[0] += s[1] * s[2];
} else {
s[0] -= s[1] * s[2];
}
Console.WriteLine("{0}", s[0]);
return;
}
if (s[0] < 0) {
s[0] += p * s[2];
} else {
s[0] -= p * s[2];
}
s[1] %= 2;
if (s[1] == 0) {
Console.WriteLine("{0}", s[0]);
return;
} else if (Abs(s[0] - s[2]) > Abs(s[0] + s[2])) {
}
Console.WriteLine("{0}", Min(Abs(s[0] - s[2]), Abs(s[0] + s[2])));
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse);
}
public int[] Ia3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse);
}
public long[] La3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var s = sc.La;
long p = Abs(s[0]) / s[2];
if (s[1] >= p) {
s[1] -= p;
} else {
if (s[0] < 0) {
s[0] += s[1] * s[2];
} else {
s[0] -= s[1] * s[2];
}
Console.WriteLine("{0}", Abs(s[0]));
return;
}
if (s[0] < 0) {
s[0] += p * s[2];
} else {
s[0] -= p * s[2];
}
s[1] %= 2;
if (s[1] == 0) {
Console.WriteLine("{0}", Abs(s[0]));
return;
}
Console.WriteLine("{0}", Min(Abs(s[0] - s[2]), Abs(s[0] + s[2])));
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse);
}
public int[] Ia3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse);
}
public long[] La3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 75, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["-", 0, 57, 75, 57, 15, 16, 12, 213, 63, 22], ["-", 75, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 1,134
| 37
|
using System;
namespace ConsoleApp1 {
class ABC178C {
// https://atcoder.jp/contests/abc178/tasks/abc178_c
static void Main(string[] args) {
const UInt64 m = 1000000007;
uint N = uint.Parse(Console.ReadLine());
UInt64 result = 0;
UInt64 r10 = 10;
UInt64 r9 = 9;
UInt64 r8 = 8;
if (N > 1) {
// 10^N - 9^N * 2 + 8^N
for (UInt64 i = 1; i < N; i++) {
r10 = (r10 * 10) % m;
r9 = (r9 * 9) % m;
r8 = (r8 * 8) % m;
}
result = r10 - r9 - r9 + r8;
result = result % m;
result = (result + m) % m;
}
Console.WriteLine(result);
}
}
}
|
using System;
namespace ConsoleApp1 {
class ABC178C {
// https://atcoder.jp/contests/abc178/tasks/abc178_c
static void Main(string[] args) {
const long m = 1000000007;
uint N = uint.Parse(Console.ReadLine());
long result = 0;
long r10 = 10;
long r9 = 9;
long r8 = 8;
if (N > 1) {
// 10^N - 9^N * 2 + 8^N
for (int i = 1; i < N; i++) {
r10 = (r10 * 10) % m;
r9 = (r9 * 9) % m;
r8 = (r8 * 8) % m;
}
result = (r10 - r9 - r9 + r8 + m + m) % m;
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 64, 196, 0, 7, 10, 198, 39, 22], ["+", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22]]
| 8
| 151
| 24
|
using System;
using System.Linq;
using System.Collections.Generic;
class program {
static void Main() {
var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int n = nk[0], k = nk[1];
var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
var c = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
var roop = new List<List<int>>();
roop.Add(new List<int>());
var rmx = new List<List<long>>();
rmx.Add(new List<long>());
var rct = new List<int>();
var rsm = new List<long>();
var isr = new int[n];
int ct = 0;
for (int i = 0; i < n; i++) {
if (isr[i] == 0) {
var pre = i;
long s = 0;
var mx = long.MinValue;
roop.Add(new List<int>());
rmx.Add(new List<long>());
ct++;
rmx[ct - 1].Add(0);
for (int j = 0; j <= n; j++) {
pre = p[pre] - 1;
if (isr[pre] != 0) {
rmx[ct - 1].Add(mx);
rct.Add(j);
rsm.Add(s);
break;
} else {
s += c[pre];
roop[ct - 1].Add(c[pre]);
mx = c[pre] > mx ? c[pre] : mx;
isr[pre] = ct;
}
}
}
}
long ans = long.MinValue;
for (int i = 0; i < ct; i++) {
for (int j = 0; j < rct[i]; j++) {
rmx[i].Add(rmx[i][1]);
}
for (int j = 0; j < rct[i]; j++) {
if (roop[i][j] > 0) {
long sm = roop[i][j];
for (int sn = 1; sn < rct[i]; sn++) {
sm +=
(sn + j) >= rct[i] ? roop[i][sn + j - rct[i]] : roop[i][sn + j];
rmx[i][sn + 1] = Math.Max(rmx[i][sn], rmx[i][sn + 1]);
rmx[i][sn + 1] = Math.Max(rmx[i][sn + 1], sm);
}
}
}
rmx[i][rct[i]] = Math.Max(rmx[i][rct[i] - 1], rmx[i][rct[i]]);
rmx[i][rct[i]] = Math.Max(rsm[i], rmx[i][rct[i]]);
if (rct[i] > k) {
ans = Math.Max(rmx[i][k], ans);
} else {
ans = Math.Max(rmx[i][rct[i]], ans);
long kr = k / rct[i];
ans = Math.Max(rmx[i][k % rct[i]] + kr * rsm[i], ans);
}
}
Console.Write(ans);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class program {
static void Main() {
var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int n = nk[0], k = nk[1];
var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
var c = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
var roop = new List<List<int>>();
roop.Add(new List<int>());
var rmx = new List<List<long>>();
rmx.Add(new List<long>());
var rct = new List<int>();
var rsm = new List<long>();
var isr = new int[n];
int ct = 0;
for (int i = 0; i < n; i++) {
if (isr[i] == 0) {
var pre = i;
long s = 0;
var mx = long.MinValue;
roop.Add(new List<int>());
rmx.Add(new List<long>());
ct++;
rmx[ct - 1].Add(0);
for (int j = 0; j <= n; j++) {
pre = p[pre] - 1;
if (isr[pre] != 0) {
rmx[ct - 1].Add(mx);
rct.Add(j);
rsm.Add(s);
break;
} else {
s += c[pre];
roop[ct - 1].Add(c[pre]);
mx = c[pre] > mx ? c[pre] : mx;
isr[pre] = ct;
}
}
}
}
long ans = long.MinValue;
for (int i = 0; i < ct; i++) {
for (int j = 0; j < rct[i]; j++) {
rmx[i].Add(rmx[i][1]);
}
for (int j = 0; j < rct[i]; j++) {
if (roop[i][j] > 0) {
long sm = roop[i][j];
for (int sn = 1; sn < rct[i]; sn++) {
sm +=
(sn + j) >= rct[i] ? roop[i][sn + j - rct[i]] : roop[i][sn + j];
rmx[i][sn + 1] = Math.Max(rmx[i][sn], rmx[i][sn + 1]);
rmx[i][sn + 1] = Math.Max(rmx[i][sn + 1], sm);
}
}
}
rmx[i][rct[i]] = Math.Max(rmx[i][rct[i] - 1], rmx[i][rct[i]]);
rmx[i][rct[i]] = Math.Max(rsm[i], rmx[i][rct[i]]);
if (rct[i] > k) {
ans = Math.Max(rmx[i][k], ans);
} else {
ans = Math.Max(rmx[i][rct[i]], ans);
long kr = k / rct[i];
ans = Math.Max(rmx[i][k % rct[i]] + kr * rsm[i], ans);
ans = Math.Max(rmx[i][rct[i]] + (kr - 1) * rsm[i], ans);
}
}
Console.Write(ans);
}
}
|
[["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 204, 205, 204, 205, 22], ["+", 0, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 24], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["+", 0, 28, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 803
| 31
|
using System;
using System.Collections.Generic;
using System.Linq;
public static class Solution {
static long GetMax(List<long> list, long K) {
var N = list.Count;
var acc = new long[N * 2 + 1];
for (int i = 0; i < N; i++) {
acc[i + 1] = acc[i] + list[i];
}
for (int i = 0; i < N; i++) {
acc[i + N + 1] = acc[i + N] + list[i];
}
long score = 0;
var cycleScore = acc[N];
if (K > N) {
if (cycleScore > 0) {
var m = K / N;
score += cycleScore * m;
K -= m * N;
} else {
K = 1;
}
}
if (K > 0) {
long max = long.MinValue;
for (int l = 0; l < N; l++) {
for (int r = l + 1; r < N * 2 && r - l <= K; r++) {
var sum = acc[r] - acc[l];
max = Math.Max(max, sum);
}
}
score += max;
}
return score;
}
static long Solve(int N, long K, int[] P, long[] C) {
var seqs = new List<List<long>>();
var visited = new bool[N];
for (int i = 0; i < N; i++) {
if (visited[i]) {
continue;
}
var list = new List<long>();
var cur = i;
while (!visited[cur]) {
visited[cur] = true;
list.Add(C[cur]);
cur = P[cur];
}
seqs.Add(list);
}
var max = seqs.Max(s => GetMax(s, K));
return max;
}
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var N = (int)vals[0];
var K = vals[1];
var P =
Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray();
var C = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var max = Solve(N, K, P, C);
Console.WriteLine(max);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public static class Solution {
static long GetMax(List<long> list, long K) {
var N = list.Count;
var acc = new long[N * 2 + 1];
for (int i = 0; i < N; i++) {
acc[i + 1] = acc[i] + list[i];
}
for (int i = 0; i < N; i++) {
acc[i + N + 1] = acc[i + N] + list[i];
}
long score = 0;
var cycleScore = acc[N];
if (cycleScore > 0) {
var m = K / N;
if (K % N == 0) {
m--;
}
score += cycleScore * m;
K -= m * N;
}
if (K > 0) {
long max = long.MinValue;
for (int l = 0; l < N; l++) {
for (int r = l + 1; r < N * 2 && r - l <= K; r++) {
var sum = acc[r] - acc[l];
max = Math.Max(max, sum);
}
}
score += max;
}
return score;
}
static long Solve(int N, long K, int[] P, long[] C) {
var seqs = new List<List<long>>();
var visited = new bool[N];
for (int i = 0; i < N; i++) {
if (visited[i]) {
continue;
}
var list = new List<long>();
var cur = i;
while (!visited[cur]) {
visited[cur] = true;
list.Add(C[cur]);
cur = P[cur];
}
seqs.Add(list);
}
var max = seqs.Max(s => GetMax(s, K));
return max;
}
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var N = (int)vals[0];
var K = vals[1];
var P =
Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray();
var C = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var max = Solve(N, K, P, C);
Console.WriteLine(max);
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["-", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["-", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 554
| 28
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC178 {
public class QuestionC {
public static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
if (n == 1) {
Console.WriteLine(0);
return;
}
if (n == 2) {
Console.WriteLine(2);
return;
}
var m = 1000000007L;
var countAll = 1L;
var countIgnore0Or9 = 1L;
var countIgnore0And9 = 1L;
for (int i = 0; i < n; i++) {
countIgnore0Or9 = (countIgnore0Or9 * 9L) % m;
countIgnore0And9 = (countIgnore0And9 * 8L) % m;
countAll = (countAll * 10L) % m;
}
Console.WriteLine((countAll + countIgnore0And9 - (2 * countIgnore0Or9)) %
m);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC178 {
public class QuestionC {
public static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
if (n == 1) {
Console.WriteLine(0);
return;
}
if (n == 2) {
Console.WriteLine(2);
return;
}
var m = 1000000007L;
var countAll = 1L;
var countIgnore0Or9 = 1L;
var countIgnore0And9 = 1L;
for (int i = 0; i < n; i++) {
countIgnore0Or9 = (countIgnore0Or9 * 9L) % m;
countIgnore0And9 = (countIgnore0And9 * 8L) % m;
countAll = (countAll * 10L) % m;
}
var count =
(((countAll + countIgnore0And9 - (2 * countIgnore0Or9)) % m) + m) % m;
Console.WriteLine(count);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 169
| 19
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.C {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var N = ReadLong();
long x = 1;
long y = 1;
long z = 1;
var m = 1000000007L;
for (var i = 0; i < N; i++) {
x = x * 10 % m;
y = y * 8 % m;
z = z * 9 % m;
}
return (x % m + y % m - z % m - z % m) % m;
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.C {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var N = ReadLong();
long x = 1;
long y = 1;
long z = 1;
var m = 1000000007L;
for (var i = 0; i < N; i++) {
x = x * 10 % m;
y = y * 8 % m;
z = z * 9 % m;
}
var ans = (x % m + y % m - z % m - z % m) % m;
if (ans < 0) {
ans += m;
}
return ans;
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22]]
| 8
| 436
| 19
|
using System;
namespace ABC178 {
class Program {
static void Main() {
// 全体 - (0がない場合 + 9がない場合 - 0,9がない場合)
var n = int.Parse(Console.ReadLine());
var mod = new Modulo();
Console.WriteLine(
(mod.Pow(10, n) -
(mod.Multiply(mod.Pow(9, n), 2) - mod.Pow(8, n)) % 1000000007) %
1000000007);
}
}
public class Modulo {
private readonly int M = 1000000007;
public int Multiply(int a, int b) { return (int)(Math.BigMul(a, b) % M); }
public int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiply(p1, p1);
return ((m % 2) == 0) ? p2 : Multiply(p2, a);
}
}
}
}
|
using System;
namespace ABC178 {
class Program {
static void Main() {
// 全体 - (0がない場合 + 9がない場合 - 0,9がない場合)
var n = int.Parse(Console.ReadLine());
var mod = new Modulo();
long l = (mod.Pow(10, n) -
(mod.Multiply(mod.Pow(9, n), 2) - mod.Pow(8, n)) % 1000000007) %
1000000007;
Console.WriteLine(l < 0 ? 1000000007 + l : l);
}
}
public class Modulo {
private readonly int M = 1000000007;
public int Multiply(int a, int b) { return (int)(Math.BigMul(a, b) % M); }
public int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiply(p1, p1);
return ((m % 2) == 0) ? p2 : Multiply(p2, a);
}
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
| 8
| 203
| 21
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace ABC178 {
class Program {
static void Main(string[] args) {
// var NXT = Console.ReadLine().Split().Select(double.Parse).ToArray();
var N = long.Parse(Console.ReadLine());
// var abcd = Console.ReadLine().Split().Select(long.Parse).ToArray();
// var CA = Enumerable.Repeat(0, (int)N).Select(_ =>
// Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
// var L = Console.ReadLine().Split().Select(long.Parse).OrderBy(x =>
// x).ToArray();
var x = 1000000007L;
var a = 1L;
var b = 1L;
var c = 1L;
for (int i = 0; i < N; i++) {
a = (a * 10) % x;
b = (b * 9) % x;
c = (c * 8) % x;
}
var ans = (a - ((2 * b) % x - c)) % x;
// if (ans < 0) Console.WriteLine(ans + x);
// else Console.WriteLine(ans % x);
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace ABC178 {
class Program {
static void Main(string[] args) {
// var NXT = Console.ReadLine().Split().Select(double.Parse).ToArray();
var N = long.Parse(Console.ReadLine());
// var abcd = Console.ReadLine().Split().Select(long.Parse).ToArray();
// var CA = Enumerable.Repeat(0, (int)N).Select(_ =>
// Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
// var L = Console.ReadLine().Split().Select(long.Parse).OrderBy(x =>
// x).ToArray();
var x = 1000000007L;
var a = 1L;
var b = 1L;
var c = 1L;
for (int i = 0; i < N; i++) {
a = (a * 10) % x;
b = (b * 9) % x;
c = (c * 8) % x;
}
var ans = (a - ((2 * b) % x - c)) % x;
if (ans < 0)
Console.WriteLine(ans + x);
else
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 155
| 16
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var r = ReadSplit();
var n = r[0].Int();
var k = r[1].Long();
var pl = new long[n + 1];
var cl = new long[n + 1];
var rp = ReadSplit();
var rc = ReadSplit();
for (int i = 0; i < n; i++) {
pl[i] = rp[i].Long();
cl[i] = rc[i].Long();
}
// var roop = k / 5000;
// var sub = k % 5000;
// if (k >= 5000)
//{
// k = 5000;
//}
long ans = -1 * max;
for (int i = 0; i < n; i++) {
var dic = new long[n + 10];
long tmp = 0;
var now = pl[i];
long roopTmp = 0;
long breakCount = max;
long roopStart = -1;
for (int j = 0; j < k; j++) {
tmp += cl[now - 1];
if (dic[now] == 1) {
roopTmp += cl[now - 1];
if (roopStart == -1) {
roopStart = now;
}
}
if (dic[now] == 2) {
breakCount = j;
break;
}
dic[now]++;
now = pl[now - 1];
ans = Math.Max(tmp, ans);
}
long rCount = dic.Count(x => x == 2);
if (rCount > 0 && k > breakCount && roopTmp >= 0) {
var mul = (k - breakCount) / rCount;
var zan = (k - breakCount) % rCount;
tmp += mul * roopTmp;
tmp -= cl[now - 1];
ans = Math.Max(tmp, ans);
now = roopStart;
for (int m = 0; m < zan; m++) {
tmp += cl[now - 1];
now = pl[now - 1];
ans = Math.Max(tmp, ans);
}
}
}
WriteRead(ans);
}
private static void Dfs(int key, int par, int[] ans,
Dictionary<int, List<int>> dic) {
var color = 1;
if (!dic.ContainsKey(key)) {
return;
}
foreach (var item in dic[key]) {
if (color == par) {
color++;
}
ans[item] = color;
Dfs(item, color, ans, dic);
color++;
}
}
public static List<long> GetCalcDivisor(long n) {
var res = new List<long>();
for (long i = 1L; i * i <= n; ++i) {
if (n % i == 0) {
res.Add(i);
long j = n / i;
if (j != i)
res.Add(j);
}
}
res.Sort();
return res;
}
class ModCombination {
public long _mod = 1000000007;
public int _max = 1000000;
long[] fac;
long[] finv;
long[] inv;
public ModCombination() : this(1000000007, 1000000) {}
public ModCombination(long mod, int max) {
_mod = mod;
_max = max;
fac = new long[max];
finv = new long[max];
inv = new long[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
public long Combination(int n, int m) {
if (n < m)
return 0;
if (n < 0 || m < 0)
return 0;
return fac[n] * (finv[m] * finv[n - m] % _mod) % _mod;
}
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
public static long ModPow(long x, long n) {
x = x % mod;
if (n == 0) {
return 1;
} else if (n % 2 == 1) {
return (x * ModPow(x, n - 1)) % mod;
} else {
return ModPow((x * x) % mod, n / 2) % mod;
}
}
/// <summary>
/// 最小公倍数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
/// <summary>
/// 最大公約数
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var r = ReadSplit();
var n = r[0].Int();
var k = r[1].Long();
var pl = new long[n + 1];
var cl = new long[n + 1];
var rp = ReadSplit();
var rc = ReadSplit();
for (int i = 0; i < n; i++) {
pl[i] = rp[i].Long();
cl[i] = rc[i].Long();
}
long ans = -1 * max;
for (int i = 0; i < n; i++) {
var dic = new long[n + 10];
long tmp = 0;
var now = pl[i];
long roopTmp = 0;
long breakCount = max;
long roopStart = -1;
for (int j = 0; j < k; j++) {
tmp += cl[now - 1];
if (dic[now] == 1) {
roopTmp += cl[now - 1];
if (roopStart == -1) {
roopStart = now;
}
}
if (dic[now] == 2) {
breakCount = j;
break;
}
dic[now]++;
now = pl[now - 1];
ans = Math.Max(tmp, ans);
}
long rCount = dic.Count(x => x == 2);
if (rCount > 0 && k > breakCount && roopTmp >= 0) {
var mul = (k - breakCount) / rCount;
var zan = (k - breakCount) % rCount;
tmp += mul * roopTmp;
tmp -= cl[now - 1];
ans = Math.Max(tmp, ans);
now = roopStart;
if (zan == 0) {
zan = rCount;
tmp -= roopTmp;
}
for (int m = 0; m < zan; m++) {
tmp += cl[now - 1];
now = pl[now - 1];
ans = Math.Max(tmp, ans);
}
}
}
WriteRead(ans);
}
private static void Dfs(int key, int par, int[] ans,
Dictionary<int, List<int>> dic) {
var color = 1;
if (!dic.ContainsKey(key)) {
return;
}
foreach (var item in dic[key]) {
if (color == par) {
color++;
}
ans[item] = color;
Dfs(item, color, ans, dic);
color++;
}
}
public static List<long> GetCalcDivisor(long n) {
var res = new List<long>();
for (long i = 1L; i * i <= n; ++i) {
if (n % i == 0) {
res.Add(i);
long j = n / i;
if (j != i)
res.Add(j);
}
}
res.Sort();
return res;
}
class ModCombination {
public long _mod = 1000000007;
public int _max = 1000000;
long[] fac;
long[] finv;
long[] inv;
public ModCombination() : this(1000000007, 1000000) {}
public ModCombination(long mod, int max) {
_mod = mod;
_max = max;
fac = new long[max];
finv = new long[max];
inv = new long[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
public long Combination(int n, int m) {
if (n < m)
return 0;
if (n < 0 || m < 0)
return 0;
return fac[n] * (finv[m] * finv[n - m] % _mod) % _mod;
}
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
public static long ModPow(long x, long n) {
x = x % mod;
if (n == 0) {
return 1;
} else if (n % 2 == 1) {
return (x * ModPow(x, n - 1)) % mod;
} else {
return ModPow((x * x) % mod, n / 2) % mod;
}
}
/// <summary>
/// 最小公倍数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
/// <summary>
/// 最大公約数
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,119
| 16
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program {
static long MOD = 1000000007;
static void Main(string[] args) {
long N = int.Parse(Console.ReadLine());
long ans =
ModPow(10, N) - (2 * (ModPow(9, N)) % MOD) + (ModPow(8, N) % MOD) % MOD;
Console.WriteLine(ans);
}
static long ModPow(long a, long n) {
long res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = res * a % MOD;
}
a = a * a % MOD;
n >>= 1;
}
return res;
}
}
// dotnet run --project test
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program {
static long MOD = 1000000007;
static void Main(string[] args) {
long N = int.Parse(Console.ReadLine());
long ans = (ModPow(10, N) - (2 * (ModPow(9, N)) % MOD)) % MOD +
(ModPow(8, N) % MOD);
ans = ans % MOD;
if (ans < 0) {
ans += MOD;
}
Console.WriteLine(ans);
}
static long ModPow(long a, long n) {
long res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = res * a % MOD;
}
a = a * a % MOD;
n >>= 1;
}
return res;
}
}
// dotnet run --project test
|
[["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 109], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 161
| 20
|
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;
class Program {
//繰り返し2乗法
// N^Pをmodで割った余りを計算
static long PowMod(long N, long P, long mod) {
// 0乗の場合
if (P == 0) {
return 1;
}
//指数が偶数の場合
else if (P % 2 == 0) {
//指数を半分にして計算したもの同士を掛け合わせる
long half = PowMod(N, P / 2, mod);
return half * half % mod;
}
//奇数の場合
else {
//指数を一つ減らしたものに、Nをかける
long before = PowMod(N, P - 1, mod);
return N * before % mod;
}
}
// Main
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
long mod = 1000000007;
//全て0~9の組み合わせの数
long ans = PowMod(10, N, mod);
//うち、0がない組み合わせ(9がないのも数は同じ)
long non1 = PowMod(9, N, mod);
//うち、0も9もない組み合わせ
long non2 = PowMod(8, N, mod);
ans -= non1;
ans %= mod;
ans -= non1;
ans %= mod;
ans += non2;
ans %= mod;
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;
class Program {
//繰り返し2乗法
// N^Pをmodで割った余りを計算
static long PowMod(long N, long P, long mod) {
// 0乗の場合
if (P == 0) {
return 1;
}
//指数が偶数の場合
else if (P % 2 == 0) {
//指数を半分にして計算したもの同士を掛け合わせる
long half = PowMod(N, P / 2, mod);
return half * half % mod;
}
//奇数の場合
else {
//指数を一つ減らしたものに、Nをかける
long before = PowMod(N, P - 1, mod);
return N * before % mod;
}
}
// Main
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
long mod = 1000000007;
//全て0~9の組み合わせの数
long ans = PowMod(10, N, mod);
//うち、0がない組み合わせ(9がないのも数は同じ)
long non1 = PowMod(9, N, mod);
//うち、0も9もない組み合わせ
long non2 = PowMod(8, N, mod);
ans -= non1;
ans %= mod;
ans -= non1;
ans %= mod;
ans += non2;
ans %= mod;
if (ans < 0) {
ans += mod;
}
Console.WriteLine(ans);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 238
| 12
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.D {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var (N, K) = Read2Longs();
// インデックス変換
var P = ReadLongs().Select(x => (int)x - 1).ToList();
var C = ReadLongs();
// すべて0以下の場合
if (C.All(x => x <= 0)) {
// 一度だけ最大の場所に移動するのが最適
return C.Max();
}
var took = new bool[N];
var loops = new List<List<int>>();
for (var i = 0; i < N; i++) {
if (took[i])
continue;
var loop = new List<int>();
var next = P[i];
while (!took[P[next]]) {
loop.Add(next);
next = P[next];
took[next] = true;
}
loops.Add(loop);
}
var max = 0L;
foreach (var loop in loops) {
var score = GetScore(loop, C, K);
max = Math.Max(max, score);
}
return max;
}
private static long GetScore(List<int> loop, List<long> c, long count) {
var sum = loop.Select(x => c[x]).Sum();
// 1周が最適な場合
if (sum <= 0 || count < loop.Count) {
var maxScrore = 0L;
for (var start = 0; start < loop.Count; start++) {
var currentScoreSum = 0L;
var limit = Math.Min(loop.Count, count);
for (var i = 0; i < limit; i++) {
var next = start + i;
if (next >= loop.Count) {
next -= loop.Count;
}
currentScoreSum += c[loop[next]];
maxScrore = Math.Max(maxScrore, currentScoreSum);
}
}
return maxScrore;
}
// 1周以上が最適な場合
var score = sum * (count / loop.Count);
var nokoriCount = count % loop.Count;
return score + GetScore(loop, c, nokoriCount);
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.D {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var (N, K) = Read2Longs();
// インデックス変換
var P = ReadLongs().Select(x => (int)x - 1).ToList();
var C = ReadLongs();
// すべて0以下の場合
if (C.All(x => x <= 0)) {
// 一度だけ最大の場所に移動するのが最適
return C.Max();
}
var took = new bool[N];
var loops = new List<List<int>>();
for (var i = 0; i < N; i++) {
if (took[i])
continue;
var loop = new List<int>();
var next = P[i];
while (!took[P[next]]) {
loop.Add(next);
next = P[next];
took[next] = true;
}
loops.Add(loop);
}
var max = 0L;
foreach (var loop in loops) {
var score = GetScore(loop, C, K);
max = Math.Max(max, score);
}
return max;
}
private static long GetScore(List<int> loop, List<long> c, long count) {
var sum = loop.Select(x => c[x]).Sum();
// 1周が最適な場合
if (sum <= 0 || count <= loop.Count) {
var maxScrore = 0L;
for (var start = 0; start < loop.Count; start++) {
var currentScoreSum = 0L;
var limit = Math.Min(loop.Count, count);
for (var i = 0; i < limit; i++) {
var next = start + i;
if (next >= loop.Count) {
next -= loop.Count;
}
currentScoreSum += c[loop[next]];
maxScrore = Math.Max(maxScrore, currentScoreSum);
}
}
return maxScrore;
}
// 1周以上が最適な場合
var score = sum * (count / loop.Count);
var nokoriCount = count % loop.Count;
// 最後の一周で油断しない
if (nokoriCount == 0) {
score -= sum;
nokoriCount += loop.Count;
}
return score + GetScore(loop, c, nokoriCount);
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 758
| 20
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
static public string al = "abcdefghijklmnopqrstuvwxyz";
public static void Main() {
// 方針
//
var n = rint();
var a = new int[n + 1];
var b = new int[n + 1];
var temp1 = inta();
for (int i = 0; i < n; i++) {
a[temp1[i]]++;
}
var temp2 = inta();
for (int i = 0; i < n; i++) {
b[temp2[i]]++;
}
for (int i = 0; i < n; i++) {
a[i + 1] += a[i];
b[i + 1] += b[i];
}
var max = 0;
for (int i = 1; i <= n; i++) {
max = Max(a[i] - b[i - 1], max);
if (a[i] + b[i] - a[i - 1] - b[i - 1] > n) {
WriteLine("No");
return;
}
}
var ans = new List<int>();
for (int i = 0; i < n; i++) {
var add = (i + max) % n;
ans.Add(temp2[add]);
}
WriteLine("Yes");
WriteLine(string.Join(" ", ans));
// WriteLine(max);
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
if (n < r)
return 0;
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = double.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
static public string al = "abcdefghijklmnopqrstuvwxyz";
public static void Main() {
// 方針
//
var n = rint();
var a = new int[n + 1];
var b = new int[n + 1];
var temp1 = inta();
for (int i = 0; i < n; i++) {
a[temp1[i]]++;
}
var temp2 = inta();
for (int i = 0; i < n; i++) {
b[temp2[i]]++;
}
for (int i = 0; i < n; i++) {
a[i + 1] += a[i];
b[i + 1] += b[i];
}
var max = 0;
for (int i = 1; i <= n; i++) {
max = Max(a[i] - b[i - 1], max);
if (a[i] + b[i] - a[i - 1] - b[i - 1] > n) {
WriteLine("No");
return;
}
}
var ans = new List<int>();
for (int i = n - max; i < 2 * n - max; i++) {
var add = i % n;
ans.Add(temp2[add]);
}
WriteLine("Yes");
// WriteLine(string.Join(" ",temp1));
WriteLine(string.Join(" ", ans));
// WriteLine(max);
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
if (n < r)
return 0;
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = double.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 31, 203], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25]]
| 8
| 1,352
| 12
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
static class Program {
const int mod = (int)1e9 + 7;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var n = sc.I;
var a = sc.Ia;
var b = sc.Ia;
var g = new int [n << 1][];
for (int i = 0; i < n; i++) {
g[i] = new int[] { a[i], i };
g[i + n] = new int[] { b[i], -1 };
}
Array.Sort(g, (u, v) => u[0] - v[0]);
var qu1 = new Queue<(int, int)>();
var qu2 = new Queue<(int, int)>();
var ans = new int[n];
for (int i = 0; i < n; i++) {
if (g[i][0] == g[n + i][0]) {
Console.WriteLine("No");
return;
}
if (g[i][1] >= 0 && g[n + i][1] >= 0) {
qu1.Enqueue((i, n + i));
} else if (g[i][1] == g[n + i][1]) {
qu2.Enqueue((i, n + i));
} else {
ans[Max(g[i][1], g[n + i][1])] =
g[i][1] < g[n + i][1] ? g[i][0] : g[n + i][0];
}
}
while (qu1.Count > 0) {
var c = qu1.Dequeue();
var d = qu2.Dequeue();
if (g[c.Item1][0] != g[d.Item1][0]) {
ans[Max(g[c.Item1][1], g[d.Item1][1])] =
g[c.Item1][1] < g[d.Item1][1] ? g[c.Item1][0] : g[d.Item1][0];
ans[Max(g[c.Item2][1], g[d.Item2][1])] =
g[c.Item2][1] < g[d.Item2][1] ? g[c.Item2][0] : g[d.Item2][0];
} else {
ans[Max(g[c.Item1][1], g[d.Item2][1])] =
g[c.Item1][1] < g[d.Item2][1] ? g[c.Item1][0] : g[d.Item2][0];
ans[Max(g[c.Item2][1], g[d.Item1][1])] =
g[c.Item2][1] < g[d.Item1][1] ? g[c.Item2][0] : g[d.Item1][0];
}
}
Console.WriteLine("Yes");
Console.WriteLine(string.Join(" ", ans));
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse);
}
public int[] Ia3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse);
}
public long[] La3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
static class Program {
const int mod = (int)1e9 + 7;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var n = sc.I;
var a = sc.Ia;
var b = sc.Ia;
var g = new int [n << 1][];
for (int i = 0; i < n; i++) {
g[i] = new int[] { a[i], i };
g[i + n] = new int[] { b[i], -1 };
}
Array.Sort(g, (u, v) => u[0] - v[0]);
var qu1 = new Queue<(int, int)>();
var qu2 = new Queue<(int, int)>();
var ans = new int[n];
for (int i = 0; i < n; i++) {
if (g[i][0] == g[n + i][0]) {
Console.WriteLine("No");
return;
}
if (g[i][1] >= 0 && g[n + i][1] >= 0) {
qu1.Enqueue((i, n + i));
} else if (g[i][1] == g[n + i][1]) {
qu2.Enqueue((i, n + i));
} else {
ans[Max(g[i][1], g[n + i][1])] =
g[i][1] < g[n + i][1] ? g[i][0] : g[n + i][0];
}
}
while (qu1.Count > 0) {
var c = qu1.Dequeue();
var d = qu2.Dequeue();
if (g[c.Item1][0] != g[d.Item1][0] && g[c.Item2][0] != g[d.Item2][0]) {
ans[Max(g[c.Item1][1], g[d.Item1][1])] =
g[c.Item1][1] < g[d.Item1][1] ? g[c.Item1][0] : g[d.Item1][0];
ans[Max(g[c.Item2][1], g[d.Item2][1])] =
g[c.Item2][1] < g[d.Item2][1] ? g[c.Item2][0] : g[d.Item2][0];
} else {
ans[Max(g[c.Item1][1], g[d.Item2][1])] =
g[c.Item1][1] < g[d.Item2][1] ? g[c.Item1][0] : g[d.Item2][0];
ans[Max(g[c.Item2][1], g[d.Item1][1])] =
g[c.Item2][1] < g[d.Item1][1] ? g[c.Item2][0] : g[d.Item1][0];
}
}
Console.WriteLine("Yes");
Console.WriteLine(string.Join(" ", ans));
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse);
}
public int[] Ia3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse);
}
public long[] La3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
[["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 204, 205, 204, 205, 22], ["+", 12, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 214, 205, 22], ["+", 205, 204, 206, 207, 0, 28, 0, 214, 0, 131], ["+", 205, 204, 206, 207, 0, 28, 0, 214, 141, 22], ["+", 12, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 15, 16, 12, 16, 12, 204, 205, 204, 205, 22], ["+", 12, 16, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 1,576
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class d {
public static void Main() {
string[] str = Console.ReadLine().Split(' ');
long n = long.Parse(str[0]);
long k = long.Parse(str[1]);
long[] p =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
long[] c =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
var circle = new Dictionary<List<long>, List<long>>();
for (long i = 0; i < n; i++) {
long cur = i;
List<long> cost = new List<long>();
bool[] already = new bool[n];
List<long> path = new List<long>();
long bef = 0;
while (!already[cur]) {
already[cur] = true;
path.Add(cur);
cur = p[cur] - 1;
cost.Add(c[cur] + bef);
bef = cost[cost.Count - 1];
}
circle[path] = cost;
}
long ans = Int64.MinValue;
long temp = k;
foreach (var list in circle) {
long comp = 0;
var tag = list.Value;
if (list.Key.Count >= k) {
comp = tag.Take((int)k).Max();
} else {
if (tag[tag.Count - 1] < 0) {
comp = tag.Max();
} else {
long count = (k / tag.Count);
k %= tag.Count;
comp = (tag[tag.Count - 1] * count) + tag.Take((int)k).Max();
}
}
if (ans < comp) {
ans = comp;
}
k = temp;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class d {
public static void Main() {
string[] str = Console.ReadLine().Split(' ');
long n = long.Parse(str[0]);
long k = long.Parse(str[1]);
long[] p =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
long[] c =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
var circle = new Dictionary<List<long>, List<long>>();
for (long i = 0; i < n; i++) {
long cur = i;
List<long> cost = new List<long>();
bool[] already = new bool[n];
List<long> path = new List<long>();
long bef = 0;
while (!already[cur]) {
already[cur] = true;
path.Add(cur);
cur = p[cur] - 1;
cost.Add(c[cur] + bef);
bef = cost[cost.Count - 1];
}
circle[path] = cost;
}
long ans = Int64.MinValue;
long temp = k;
foreach (var list in circle) {
long comp = 0;
var tag = list.Value;
if (list.Key.Count > k) {
comp = tag.Take((int)k).Max();
} else if (list.Key.Count == k) {
comp = tag.Max();
} else {
if (tag[tag.Count - 1] < 0) {
comp = tag.Max();
} else {
k--;
long count = (k / tag.Count);
k -= tag.Count * count;
k++;
comp = (tag[tag.Count - 1] * count) + tag.Take((int)k).Max();
}
}
if (ans < comp) {
ans = comp;
}
k = temp;
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 210, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 210, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 214, 205, 214, 205, 22], ["+", 75, 57, 15, 16, 31, 214, 205, 214, 0, 131], ["+", 75, 57, 15, 16, 31, 214, 205, 214, 141, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 214, 0, 131], ["+", 0, 57, 75, 57, 15, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 210, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 210, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 68], ["+", 75, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29]]
| 8
| 450
| 33
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
class Program {
static void Main(string[] args) {
// var exStdIn = new System.IO.StreamReader( "stdin.txt"
// );System.Console.SetIn( exStdIn );
const long inf = 100000000000000;
var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = nk[0];
var p = Console.ReadLine().Split().Select(long.Parse).ToArray();
for (int i = 0; i < n; i++) {
p[i]--;
}
var c = Console.ReadLine().Split().Select(long.Parse).ToArray();
long finalAns = -inf;
for (int s = 0; s < n; s++) {
long mx = -inf;
long k = nk[1];
long sm = 0;
long now = s;
long cnt = 0;
do {
now = p[now];
sm += c[now];
cnt++;
} while (now != s);
long ans = 0;
if (sm >= 0) {
if (k / cnt > 0)
mx = 0;
ans += sm * (k / cnt);
k %= cnt;
} else {
k = Min(k, cnt + 1);
}
now = s;
long tmp = 0;
for (int j = 0; j < k; j++) {
now = p[now];
tmp += c[now];
if (tmp > mx) {
mx = tmp;
}
}
ans += mx;
if (ans > finalAns)
finalAns = ans;
}
Console.WriteLine(finalAns);
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
class Program {
static void Main(string[] args) {
// var exStdIn = new System.IO.StreamReader( "stdin.txt"
// );System.Console.SetIn( exStdIn );
const long inf = 100000000000000;
var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = nk[0];
var p = Console.ReadLine().Split().Select(long.Parse).ToArray();
for (int i = 0; i < n; i++) {
p[i]--;
}
var c = Console.ReadLine().Split().Select(long.Parse).ToArray();
long finalAns = -inf;
for (int s = 0; s < n; s++) {
long mx = -inf;
long k = nk[1];
long sm = 0;
long now = s;
long cnt = 0;
do {
now = p[now];
sm += c[now];
cnt++;
} while (now != s);
long ans = 0;
if (sm >= 0) {
if (k / cnt > 1) {
mx = 0;
ans += sm * (k / cnt - 1);
k %= cnt;
k += cnt;
}
} else {
k = Min(k, cnt + 1);
}
now = s;
long tmp = 0;
for (int j = 0; j < k; j++) {
now = p[now];
tmp += c[now];
if (tmp > mx) {
mx = tmp;
}
}
ans += mx;
if (ans > finalAns)
finalAns = ans;
}
Console.WriteLine(finalAns);
}
}
|
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 388
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using SC = Scanner;
class Solver {
public SC sc = new SC();
public void Solve() {
int N;
long K;
sc.Make(out N, out K);
var P = sc.ArrInt;
for (int i = 0; i < N; i++) {
P[i]--;
}
var C = sc.ArrLong;
var res = long.MinValue >> 1;
for (int i = 0; i < N; i++) {
var use = new HashSet<int>();
int now = P[i];
var A = new List<long>();
var sum = 0L;
var max = long.MinValue >> 1;
while (!use.Contains(now)) {
use.Add(now);
A.Add(C[now]);
sum += C[now];
if (A.Count <= K)
chmax(ref max, sum);
now = P[now];
}
chmax(ref res, max);
if (sum <= 0)
continue;
{
var calc = 0L;
calc += K / A.Count * sum;
var L = K % A.Count;
if (L == 0) {
chmax(ref res, calc);
continue;
}
max = long.MinValue >> 1;
sum = 0;
for (int j = 0; j < L; j++) {
sum += A[j];
chmax(ref max, sum);
}
chmax(ref res, calc + Max(max, 0));
}
}
Console.WriteLine(res);
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var sol = new Solver();
// var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();
sol.Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Out<T>(this IList<T> A, out T a) => a = A[0];
public static void Out<T>(this IList<T> A, out T a, out T b) {
a = A[0];
b = A[1];
}
public static void Out<T>(this IList<T> A, out T a, out T b, out T c) {
A.Out(out a, out b);
c = A[2];
}
public static void Out<T>(this IList<T> A, out T a, out T b, out T c,
out T d) {
A.Out(out a, out b, out c);
d = A[3];
}
public static string Concat<T>(this IEnumerable<T> A,
string sp) => string.Join(sp, A);
public static char ToChar(this int s, char begin = '0') => (char)(s + begin);
public static IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
public (T1, T2) Make<T1, T2>() {
Make(out T1 v1, out T2 v2);
return (v1, v2);
}
public (T1, T2, T3) Make<T1, T2, T3>() {
Make(out T1 v1, out T2 v2, out T3 v3);
return (v1, v2, v3);
}
public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() {
Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4);
return (v1, v2, v3, v4);
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using SC = Scanner;
class Solver {
public SC sc = new SC();
public void Solve() {
int N;
long K;
sc.Make(out N, out K);
var P = sc.ArrInt;
for (int i = 0; i < N; i++) {
P[i]--;
}
var C = sc.ArrLong;
var res = long.MinValue >> 1;
for (int i = 0; i < N; i++) {
var use = new HashSet<int>();
int now = P[i];
var A = new List<long>();
var sum = 0L;
var max = long.MinValue >> 1;
while (!use.Contains(now)) {
use.Add(now);
A.Add(C[now]);
sum += C[now];
if (A.Count <= K)
chmax(ref max, sum);
now = P[now];
}
chmax(ref res, max);
if (sum <= 0 || A.Count > K)
continue;
{
var calc = 0L;
calc += (K / A.Count - 1) * sum;
chmax(ref res, calc + max);
calc = 0;
calc += K / A.Count * sum;
var L = K % A.Count;
if (L == 0) {
chmax(ref res, calc);
continue;
}
max = long.MinValue >> 1;
sum = 0;
for (int j = 0; j < L; j++) {
sum += A[j];
chmax(ref max, sum);
}
chmax(ref res, calc + Max(max, 0));
}
}
Console.WriteLine(res);
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var sol = new Solver();
// var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();
sol.Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Out<T>(this IList<T> A, out T a) => a = A[0];
public static void Out<T>(this IList<T> A, out T a, out T b) {
a = A[0];
b = A[1];
}
public static void Out<T>(this IList<T> A, out T a, out T b, out T c) {
A.Out(out a, out b);
c = A[2];
}
public static void Out<T>(this IList<T> A, out T a, out T b, out T c,
out T d) {
A.Out(out a, out b, out c);
d = A[3];
}
public static string Concat<T>(this IEnumerable<T> A,
string sp) => string.Join(sp, A);
public static char ToChar(this int s, char begin = '0') => (char)(s + begin);
public static IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
public (T1, T2) Make<T1, T2>() {
Make(out T1 v1, out T2 v2);
return (v1, v2);
}
public (T1, T2, T3) Make<T1, T2, T3>() {
Make(out T1 v1, out T2 v2, out T3 v3);
return (v1, v2, v3);
}
public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() {
Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4);
return (v1, v2, v3, v4);
}
}
#endregion
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 85], ["+", 31, 23, 0, 16, 31, 16, 12, 214, 205, 22], ["+", 31, 23, 0, 16, 31, 16, 12, 214, 0, 131], ["+", 31, 23, 0, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 275], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 2,142
| 34
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_G.Lib_IO;
using static Contest_G.Lib_Minifunc;
namespace Contest_G {
public static class Entry {
public static void Main() {
checked {
int n, m;
Lib_IO.rm(out n, out m);
P<int, int>[] ab;
rl(m, out ab);
List<P<ll, ll, ll>> edge = new List<P<ll, ll, ll>>();
foreach (var e in ab) {
edge.Add(new P<ll, ll, ll>(e.A, e.B, 1));
}
StronglyConnectedComponents scc =
new StronglyConnectedComponents(edge, n);
scc.Build();
List<ll>[] ans = new List<ll>[scc.Group.Length];
for (int i = 0; i < scc.Group.Length; i++) {
ans[i] = new List<ll>();
ans[i].Add(scc.Group[i].Count);
ans[i].AddRange(scc.Group[i]);
}
Lib_IO.wm(ans.Length);
// Lib_IO.wx(ans);
}
}
public class StronglyConnectedComponents {
public List<long>[] Dag, Group;
int n;
HashSet<int>[] gg, rg;
List<int> order;
int[] comp;
bool[] used;
public StronglyConnectedComponents(IEnumerable<P<long, long, long>> inEdges,
long V) {
n = (int)V;
gg = new HashSet<int>[n];
rg = new HashSet<int>[n];
for (int i = 0; i < n; i++) {
gg[i] = new HashSet<int>();
rg[i] = new HashSet<int>();
}
order = new List<int>();
comp = Enumerable.Repeat(-1, n).ToArray();
used = new bool[n];
foreach (var e in inEdges) {
if (e.A == e.B)
continue;
gg[e.A].Add((int)e.B);
rg[e.B].Add((int)e.A);
}
}
public long this[long k] {
get { return comp[k]; }
}
public void Build() {
for (int i = 0; i < gg.Length; i++)
dfs(i);
order.Reverse();
int ptr = 0;
foreach (var i in order)
if (comp[i] == -1)
rdfs(i, ptr++);
Dag = new List<long>[ptr];
for (int i = 0; i < ptr; i++)
Dag[i] = new List<long>();
for (int i = 0; i < n; i++) {
foreach (var to in gg[i]) {
int x = comp[i], y = comp[to];
if (x == y)
continue;
Dag[x].Add(y);
}
}
Group = new List<long>[ptr];
for (int i = 0; i < ptr; i++)
Group[i] = new List<long>();
for (int i = 0; i < n; i++)
Group[comp[i]].Add(i);
}
void dfs(int idx) {
if (used[idx])
return;
used[idx] = true;
foreach (var to in gg[idx])
dfs(to);
order.Add(idx);
}
void rdfs(int idx, int cnt) {
if (comp[idx] != -1)
return;
comp[idx] = cnt;
foreach (var to in rg[idx])
rdfs(to, cnt);
}
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == 1))
a = b;
return r;
} // b の方が小さければ a を更新
[CS.MethodImpl(256)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == -1))
a = b;
return r;
} // b の方が大きければ a を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e, out Y f) {
var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using CS = System.Runtime.CompilerServices;
// using System.Diagnostics;
using static System.Math;
using ll = System.Int64;
using static Contest_G.Lib_IO;
using static Contest_G.Lib_Minifunc;
namespace Contest_G {
public static class Entry {
public static void Main() {
checked {
int n, m;
Lib_IO.rm(out n, out m);
P<int, int>[] ab;
rl(m, out ab);
List<P<ll, ll, ll>> edge = new List<P<ll, ll, ll>>();
foreach (var e in ab) {
edge.Add(new P<ll, ll, ll>(e.A, e.B, 1));
}
StronglyConnectedComponents scc =
new StronglyConnectedComponents(edge, n);
scc.Build();
List<ll>[] ans = new List<ll>[scc.Group.Length];
for (int i = 0; i < scc.Group.Length; i++) {
ans[i] = new List<ll>();
ans[i].Add(scc.Group[i].Count);
ans[i].AddRange(scc.Group[i]);
}
Lib_IO.wm(ans.Length);
Lib_IO.wx(ans);
}
}
public class StronglyConnectedComponents {
public List<long>[] Dag, Group;
int n;
HashSet<int>[] gg, rg;
List<int> order;
int[] comp;
bool[] used;
public StronglyConnectedComponents(IEnumerable<P<long, long, long>> inEdges,
long V) {
n = (int)V;
gg = new HashSet<int>[n];
rg = new HashSet<int>[n];
for (int i = 0; i < n; i++) {
gg[i] = new HashSet<int>();
rg[i] = new HashSet<int>();
}
order = new List<int>();
comp = Enumerable.Repeat(-1, n).ToArray();
used = new bool[n];
foreach (var e in inEdges) {
if (e.A == e.B)
continue;
gg[e.A].Add((int)e.B);
rg[e.B].Add((int)e.A);
}
}
public long this[long k] {
get { return comp[k]; }
}
public void Build() {
for (int i = 0; i < gg.Length; i++)
dfs(i);
order.Reverse();
int ptr = 0;
foreach (var i in order)
if (comp[i] == -1)
rdfs(i, ptr++);
Dag = new List<long>[ptr];
for (int i = 0; i < ptr; i++)
Dag[i] = new List<long>();
for (int i = 0; i < n; i++) {
foreach (var to in gg[i]) {
int x = comp[i], y = comp[to];
if (x == y)
continue;
Dag[x].Add(y);
}
}
Group = new List<long>[ptr];
for (int i = 0; i < ptr; i++)
Group[i] = new List<long>();
for (int i = 0; i < n; i++)
Group[comp[i]].Add(i);
}
void dfs(int idx) {
if (used[idx])
return;
used[idx] = true;
foreach (var to in gg[idx])
dfs(to);
order.Add(idx);
}
void rdfs(int idx, int cnt) {
if (comp[idx] != -1)
return;
comp[idx] = cnt;
foreach (var to in rg[idx])
rdfs(to, cnt);
}
}
}
#region BaseModule
public static class Lib_Minifunc {
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
[CS.MethodImpl(256)]
public static void swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
[CS.MethodImpl(256)]
public static void swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
swap1(ref a, ref b);
} // b の方が小さければ交換
[CS.MethodImpl(256)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == 1))
a = b;
return r;
} // b の方が小さければ a を更新
[CS.MethodImpl(256)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable {
bool r;
if (r = (a.CompareTo(b) == -1))
a = b;
return r;
} // b の方が大きければ a を更新
[CS.MethodImpl(256)]
public static bool inside(long i, long n) => (0 <= i && i < n);
[CS.MethodImpl(256)]
public static bool inside(long x, long y, long w,
long h) => (inside(x, w) && inside(y, h));
[CS.MethodImpl(256)]
public static T min<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmin(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static T max<T>(params T[] a)
where T : IComparable {
T m = a[0];
for (int i = 1; i < a.Length; i++)
chmax(ref m, a[i]);
return m;
}
[CS.MethodImpl(256)]
public static long mod(long a, long m = MOD1) {
var v = a % m;
return (v < 0 ? (m < 0 ? v - m : v + m) : v);
}
[CS.MethodImpl(256)]
public static long
ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0)
? a / b
: a / b + 1); // 整数商の切り上げ
[CS.MethodImpl(256)]
public static long round(double a) => Convert.ToInt64(a); // 四捨五入
public static string YES(bool a) => a ? "YES" : "NO";
public static string yes(bool a) => a ? "Yes" : "No";
[CS.MethodImpl(256)]
public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b);
[CS.MethodImpl(256)]
public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b,
c);
[CS.MethodImpl(256)]
public static P<T, U, V, W>
initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d);
public static T[] initc<T>(long l1)
where T : new() {
var m = new T[l1];
for (int i = 0; i < m.Length; i++)
m[i] = new T();
return m;
} // new制約は遅い
public static int[] range(long s, long c) =>
Enumerable.Range((int)s, (int)c).ToArray();
[CS.MethodImpl(256)]
public static T[] inita<T>(long l1, T v = default(T)) =>
Enumerable.Repeat(v, (int)l1).ToArray();
public static T[][] inita<T>(long l1, long l2, T v = default(T)) {
var m = new T[l1][];
for (int i = 0; i < m.Length; i++)
m[i] = inita(l2, v);
return m;
}
public static void shift(this IList<int> l, int o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
public static void shift(this IList<long> l, long o) {
for (int i = 0; i < l.Count; i++)
l[i] += o;
}
[CS.MethodImpl(256)]
public static bool initd<T, U>(this IDictionary<T, U> d, T k,
U v = default(U)) {
if (d.ContainsKey(k)) {
return false;
} else {
d[k] = v;
return true;
}
}
public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null)
where T : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.CompareTo(y));
break;
case -1:
Array.Sort(a, (x, y) => y.CompareTo(x));
break;
default:
break;
}
}
public static void sort<T, U>(this P<T, U>[] a, int o,
Comparison<P<T, U>> f = null)
where T : IComparable
where U : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
default:
break;
}
}
public static void sort<T, U, V>(this P<T, U, V>[] a, int o,
Comparison<P<T, U, V>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
default:
break;
}
}
public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o,
Comparison<P<T, U, V, W>> f = null)
where T : IComparable
where U : IComparable
where V : IComparable
where W : IComparable {
switch (o) {
case 0:
Array.Sort(a, f);
break;
case 1:
Array.Sort(a, (x, y) => x.A.CompareTo(y.A));
break;
case -1:
Array.Sort(a, (x, y) => y.A.CompareTo(x.A));
break;
case 2:
Array.Sort(a, (x, y) => x.B.CompareTo(y.B));
break;
case -2:
Array.Sort(a, (x, y) => y.B.CompareTo(x.B));
break;
case 3:
Array.Sort(a, (x, y) => x.C.CompareTo(y.C));
break;
case -3:
Array.Sort(a, (x, y) => y.C.CompareTo(x.C));
break;
case 4:
Array.Sort(a, (x, y) => x.D.CompareTo(y.D));
break;
case -4:
Array.Sort(a, (x, y) => y.D.CompareTo(x.D));
break;
default:
break;
}
}
}
public struct P<T, U> {
public T A;
public U B;
public P(T a, U b) {
A = a;
B = b;
}
public static implicit
operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B);
public static implicit
operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value);
}
public struct P<T, U, V> {
public T A;
public U B;
public V C;
public P(T a, U b, V c) {
A = a;
B = b;
C = c;
}
}
public struct P<T, U, V, W> {
public T A;
public U B;
public V C;
public W D;
public P(T a, U b, V c, W d) {
A = a;
B = b;
C = c;
D = d;
}
}
public static class Lib_IO {
class Prt : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {}
public Prt(System.IO.Stream s, Encoding e) : base(s, e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] { ' ' };
[CS.MethodImpl(256)]
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
[CS.MethodImpl(256)]
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
[CS.MethodImpl(256)]
static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T, U>(out T a, out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T, U, V>(out T a, out U b, out V c) {
var z = rm<T, U>(out a, out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) {
var z = rm<T, U, V>(out a, out b, out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var z = rm<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e, out Y f) {
var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries);
a = new T[z.Length];
for (int i = 0; i < a.Length; i++)
a[i] = cv<T>(z[i]);
return z;
}
public static string[][] rl<T>(long n, out T[] a) {
a = new T[n];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T, U>(long n, out P<T, U>[] a) {
a = new P<T, U>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
y[i] = rm(out o, out p);
a[i] = new P<T, U>(o, p);
}
return y;
}
public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) {
a = new P<T, U, V>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
y[i] = rm(out o, out p, out q);
a[i] = new P<T, U, V>(o, p, q);
}
return y;
}
public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) {
a = new P<T, U, V, W>[n];
var y = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
y[i] = rm(out o, out p, out q, out r);
a[i] = new P<T, U, V, W>(o, p, q, r);
}
return y;
}
public static string[][] rx<T>(long n, out T[][] a) {
a = new T[n][];
var y = new string[n][];
for (int i = 0; i < n; i++)
y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act) {
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[CS.MethodImpl(256)]
static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length - 1; i++)
Console.Write(wfm(a[i].GetType()) + " ", a[i]);
Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); }
public static void wl<T>(IList<T> a) {
wwp(() => {
var f = wfm(typeof(T));
if (a.Count == 0) {
Console.WriteLine();
} else {
foreach (T x in a)
Console.WriteLine(f, x);
}
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(() => {
var f = wfm(typeof(T));
var g = f + s;
foreach (var b in a) {
if (b.Count == 0) {
Console.WriteLine();
} else {
for (int i = 0; i < b.Count - 1; i++)
Console.Write(g, b[i]);
Console.WriteLine(f, b[b.Count - 1]);
}
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
[["+", 0, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 287, 0, 196, 0, 1, 0, 35]]
| 8
| 4,881
| 7
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public void Run() {
var n = ni();
var q = ni();
var a = ni(n);
var seg = new Inversion().CreateLazySegmentTree();
seg.Build(n, i => new InversionOp { Inversion = 0, One = a[i] == 1 ? 1 : 0,
Zero = a[i] == 0 ? 1 : 0 });
for (int i = 0; i < q; i++) {
var t = ni();
var l = ni() - 1;
var r = ni() - 1;
if (t == 1) {
seg.LazyUpdate(l, r + 1, true);
} else {
cout.WriteLine(seg.Query(l, r + 1).Inversion);
}
}
}
}
public struct InversionOp {
public long One;
public long Zero;
public long Inversion;
}
public class Inversion : ILazySegmentTreeDefinition<InversionOp, bool> {
public InversionOp Identity => new InversionOp();
public bool OperatorIdentity => false;
public InversionOp Apply(InversionOp monoid, int begin, int end,
bool operation) {
if (!operation)
return monoid;
long size = end - begin;
return new InversionOp {
One = monoid.Zero,
Zero = monoid.One,
Inversion = size * (size - 1) / 2 - monoid.Inversion,
};
}
public InversionOp Merge(InversionOp left, InversionOp right) {
return new InversionOp {
One = left.One + right.One,
Zero = left.Zero + right.Zero,
Inversion = left.Inversion + right.Inversion + left.One * right.Zero,
};
}
public bool MergeOperator(bool current, bool append) {
return current ^ append;
}
}
public interface ILazySegmentTreeDefinition<TMonoid, TOperatorMonoid> {
TMonoid Merge(TMonoid left, TMonoid right);
TMonoid Apply(TMonoid monoid, int begin, int @end, TOperatorMonoid operation);
TOperatorMonoid MergeOperator(TOperatorMonoid current,
TOperatorMonoid append);
TMonoid Identity { get; }
TOperatorMonoid OperatorIdentity { get; }
}
public static class LazySegmentTreeExtension {
public static LazySegmentTree<TMonoid, TOperatorMonoid>
CreateLazySegmentTree<TMonoid, TOperatorMonoid>(
this ILazySegmentTreeDefinition<TMonoid, TOperatorMonoid>
lazySegmentTreeMonoidOperator) {
return new LazySegmentTree<TMonoid, TOperatorMonoid>(
lazySegmentTreeMonoidOperator.Merge,
lazySegmentTreeMonoidOperator.Apply,
lazySegmentTreeMonoidOperator.MergeOperator,
lazySegmentTreeMonoidOperator.Identity,
lazySegmentTreeMonoidOperator.OperatorIdentity);
}
public static bool Check<TMonoid, TOperatorMonoid>(
this ILazySegmentTreeDefinition<TMonoid, TOperatorMonoid>
lazySegmentTreeMonoidOperator,
TMonoid m, TOperatorMonoid o1, TOperatorMonoid o2) {
var r1 = lazySegmentTreeMonoidOperator.Apply(
lazySegmentTreeMonoidOperator.Apply(m, 1, 2, o1), 1, 2, o2);
var r2 = lazySegmentTreeMonoidOperator.Apply(
m, 1, 2, lazySegmentTreeMonoidOperator.MergeOperator(o1, o2));
return r1.Equals(r2);
}
}
public sealed class LazySegmentTree<TMonoid, TOperatorMonoid> {
private int Count;
private TMonoid[] _node;
private TOperatorMonoid[] _operators;
private int[] _height;
private int[] _begin, _end;
private readonly TMonoid _identity;
private readonly TOperatorMonoid _operatorIdentity;
private readonly Func<TMonoid, TMonoid, TMonoid> _merge;
private readonly Func<TMonoid, int, int, TOperatorMonoid, TMonoid> _apply;
private readonly Func<TOperatorMonoid, TOperatorMonoid, TOperatorMonoid>
_mergeOperator;
public LazySegmentTree(
Func<TMonoid, TMonoid, TMonoid> merge,
Func<TMonoid, int, int, TOperatorMonoid, TMonoid> apply,
Func<TOperatorMonoid, TOperatorMonoid, TOperatorMonoid> mergeOperator,
TMonoid identity, TOperatorMonoid operatorIdentity) {
_merge = merge;
_apply = apply;
_mergeOperator = mergeOperator;
_identity = identity;
_operatorIdentity = operatorIdentity;
}
public void Build(IList<TMonoid> array) { Build(array.Count, i => array[i]); }
public void Build(int n, Func<int, TMonoid> create) {
Count = n;
_node = new TMonoid[2 * Count];
_operators = new TOperatorMonoid[2 * Count];
_begin = new int[2 * Count];
_end = new int[2 * Count];
_height = new int[2 * Count];
for (var i = 0; i < _node.Length; i++) {
_node[i] = _identity;
_operators[i] = _operatorIdentity;
}
for (var i = 0; i < n; i++) {
_node[i + Count] = create(i);
_begin[i + Count] = i;
_end[i + Count] = i + 1;
}
for (var i = 2; i < _height.Length; i++) {
_height[i] = _height[i >> 1] + 1;
}
for (var i = Count - 1; i > 0; i--) {
_node[i] = _merge(_node[i << 1], _node[i << 1 | 1]);
_begin[i] = _begin[i << 1];
_end[i] = _end[i << 1 | 1];
}
}
private void Propagate(int k) {
int childL = k << 1, childR = childL | 1;
_operators[childL] = _mergeOperator(_operators[childL], _operators[k]);
_operators[childR] = _mergeOperator(_operators[childR], _operators[k]);
_node[k] = Apply(k);
_operators[k] = _operatorIdentity;
}
public TMonoid Query(int begin, int end) {
TMonoid lv = _identity, rv = _identity;
begin += Count;
end += Count;
TopDownOperators(begin);
TopDownOperators(end - 1);
for (int l = begin, r = end - 1; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1) {
lv = _merge(lv, Apply(l++));
}
if ((r & 1) == 0) {
rv = _merge(Apply(r--), rv);
}
}
return _merge(lv, rv);
}
public void LazyUpdate(int begin, int end, TOperatorMonoid @operator) {
begin += Count;
end += Count;
TopDownOperators(begin);
TopDownOperators(end - 1);
for (int l = begin, r = end - 1; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1) {
_operators[l] = _mergeOperator(_operators[l], @operator);
l++;
}
if ((r & 1) == 0) {
_operators[r] = _mergeOperator(_operators[r], @operator);
r--;
}
}
BottomUpMonoids(begin);
BottomUpMonoids(end - 1);
}
private void TopDownOperators(int k) {
for (var i = _height[k]; i > 0; i--) {
Propagate(k >> i);
}
}
private TMonoid Apply(int k) {
return _apply(_node[k], _begin[k], _end[k], _operators[k]);
}
private void BottomUpMonoids(int k) {
while ((k >>= 1) > 0) {
_node[k] = _merge(Apply(k << 1), Apply(k << 1 | 1));
}
}
public TMonoid this[int index] {
get {
index += Count;
TopDownOperators(index);
return Apply(index);
}
set {
index += Count;
TopDownOperators(index);
_node[index] = value;
_operators[index] = _operatorIdentity;
BottomUpMonoids(index);
}
}
public void Diagonsis() {
for (var i = 1; i < Count; i++) {
Propagate(i);
var ex = _merge(Apply(i << 1), Apply(i << 1 | 1));
var ex2 = Apply(i);
if (!ex2.Equals(ex))
throw new Exception();
}
}
}
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public void Run() {
var n = ni();
var q = ni();
var a = ni(n);
var seg = new Inversion().CreateLazySegmentTree();
seg.Build(n, i => new InversionOp { Inversion = 0, One = a[i] == 1 ? 1 : 0,
Zero = a[i] == 0 ? 1 : 0 });
for (int i = 0; i < q; i++) {
var t = ni();
var l = ni() - 1;
var r = ni() - 1;
if (t == 1) {
seg.LazyUpdate(l, r + 1, true);
} else {
cout.WriteLine(seg.Query(l, r + 1).Inversion);
}
}
}
}
public struct InversionOp {
public long One;
public long Zero;
public long Inversion;
}
public class Inversion : ILazySegmentTreeDefinition<InversionOp, bool> {
public InversionOp Identity => new InversionOp();
public bool OperatorIdentity => false;
public InversionOp Apply(InversionOp monoid, int begin, int end,
bool operation) {
if (!operation)
return monoid;
long size = end - begin;
return new InversionOp {
One = monoid.Zero,
Zero = monoid.One,
Inversion = monoid.Zero * monoid.One - monoid.Inversion,
};
}
public InversionOp Merge(InversionOp left, InversionOp right) {
return new InversionOp {
One = left.One + right.One,
Zero = left.Zero + right.Zero,
Inversion = left.Inversion + right.Inversion + left.One * right.Zero,
};
}
public bool MergeOperator(bool current, bool append) {
return current ^ append;
}
}
public interface ILazySegmentTreeDefinition<TMonoid, TOperatorMonoid> {
TMonoid Merge(TMonoid left, TMonoid right);
TMonoid Apply(TMonoid monoid, int begin, int @end, TOperatorMonoid operation);
TOperatorMonoid MergeOperator(TOperatorMonoid current,
TOperatorMonoid append);
TMonoid Identity { get; }
TOperatorMonoid OperatorIdentity { get; }
}
public static class LazySegmentTreeExtension {
public static LazySegmentTree<TMonoid, TOperatorMonoid>
CreateLazySegmentTree<TMonoid, TOperatorMonoid>(
this ILazySegmentTreeDefinition<TMonoid, TOperatorMonoid>
lazySegmentTreeMonoidOperator) {
return new LazySegmentTree<TMonoid, TOperatorMonoid>(
lazySegmentTreeMonoidOperator.Merge,
lazySegmentTreeMonoidOperator.Apply,
lazySegmentTreeMonoidOperator.MergeOperator,
lazySegmentTreeMonoidOperator.Identity,
lazySegmentTreeMonoidOperator.OperatorIdentity);
}
public static bool Check<TMonoid, TOperatorMonoid>(
this ILazySegmentTreeDefinition<TMonoid, TOperatorMonoid>
lazySegmentTreeMonoidOperator,
TMonoid m, TOperatorMonoid o1, TOperatorMonoid o2) {
var r1 = lazySegmentTreeMonoidOperator.Apply(
lazySegmentTreeMonoidOperator.Apply(m, 1, 2, o1), 1, 2, o2);
var r2 = lazySegmentTreeMonoidOperator.Apply(
m, 1, 2, lazySegmentTreeMonoidOperator.MergeOperator(o1, o2));
return r1.Equals(r2);
}
}
public sealed class LazySegmentTree<TMonoid, TOperatorMonoid> {
private int Count;
private TMonoid[] _node;
private TOperatorMonoid[] _operators;
private int[] _height;
private int[] _begin, _end;
private readonly TMonoid _identity;
private readonly TOperatorMonoid _operatorIdentity;
private readonly Func<TMonoid, TMonoid, TMonoid> _merge;
private readonly Func<TMonoid, int, int, TOperatorMonoid, TMonoid> _apply;
private readonly Func<TOperatorMonoid, TOperatorMonoid, TOperatorMonoid>
_mergeOperator;
public LazySegmentTree(
Func<TMonoid, TMonoid, TMonoid> merge,
Func<TMonoid, int, int, TOperatorMonoid, TMonoid> apply,
Func<TOperatorMonoid, TOperatorMonoid, TOperatorMonoid> mergeOperator,
TMonoid identity, TOperatorMonoid operatorIdentity) {
_merge = merge;
_apply = apply;
_mergeOperator = mergeOperator;
_identity = identity;
_operatorIdentity = operatorIdentity;
}
public void Build(IList<TMonoid> array) { Build(array.Count, i => array[i]); }
public void Build(int n, Func<int, TMonoid> create) {
Count = n;
_node = new TMonoid[2 * Count];
_operators = new TOperatorMonoid[2 * Count];
_begin = new int[2 * Count];
_end = new int[2 * Count];
_height = new int[2 * Count];
for (var i = 0; i < _node.Length; i++) {
_node[i] = _identity;
_operators[i] = _operatorIdentity;
}
for (var i = 0; i < n; i++) {
_node[i + Count] = create(i);
_begin[i + Count] = i;
_end[i + Count] = i + 1;
}
for (var i = 2; i < _height.Length; i++) {
_height[i] = _height[i >> 1] + 1;
}
for (var i = Count - 1; i > 0; i--) {
_node[i] = _merge(_node[i << 1], _node[i << 1 | 1]);
_begin[i] = _begin[i << 1];
_end[i] = _end[i << 1 | 1];
}
}
private void Propagate(int k) {
int childL = k << 1, childR = childL | 1;
_operators[childL] = _mergeOperator(_operators[childL], _operators[k]);
_operators[childR] = _mergeOperator(_operators[childR], _operators[k]);
_node[k] = Apply(k);
_operators[k] = _operatorIdentity;
}
public TMonoid Query(int begin, int end) {
TMonoid lv = _identity, rv = _identity;
begin += Count;
end += Count;
TopDownOperators(begin);
TopDownOperators(end - 1);
for (int l = begin, r = end - 1; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1) {
lv = _merge(lv, Apply(l++));
}
if ((r & 1) == 0) {
rv = _merge(Apply(r--), rv);
}
}
return _merge(lv, rv);
}
public void LazyUpdate(int begin, int end, TOperatorMonoid @operator) {
begin += Count;
end += Count;
TopDownOperators(begin);
TopDownOperators(end - 1);
for (int l = begin, r = end - 1; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1) {
_operators[l] = _mergeOperator(_operators[l], @operator);
l++;
}
if ((r & 1) == 0) {
_operators[r] = _mergeOperator(_operators[r], @operator);
r--;
}
}
BottomUpMonoids(begin);
BottomUpMonoids(end - 1);
}
private void TopDownOperators(int k) {
for (var i = _height[k]; i > 0; i--) {
Propagate(k >> i);
}
}
private TMonoid Apply(int k) {
return _apply(_node[k], _begin[k], _end[k], _operators[k]);
}
private void BottomUpMonoids(int k) {
while ((k >>= 1) > 0) {
_node[k] = _merge(Apply(k << 1), Apply(k << 1 | 1));
}
}
public TMonoid this[int index] {
get {
index += Count;
TopDownOperators(index);
return Apply(index);
}
set {
index += Count;
TopDownOperators(index);
_node[index] = value;
_operators[index] = _operatorIdentity;
BottomUpMonoids(index);
}
}
public void Diagonsis() {
for (var i = 1; i < Count; i++) {
Propagate(i);
var ex = _merge(Apply(i << 1), Apply(i << 1 | 1));
var ex2 = Apply(i);
if (!ex2.Equals(ex))
throw new Exception();
}
}
}
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
[["-", 0, 11, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 141, 22], ["-", 12, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 12, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["-", 10, 229, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 10, 229, 0, 11, 12, 16, 31, 16, 12, 203], ["+", 0, 11, 12, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 11, 12, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 11, 12, 16, 31, 16, 12, 214, 141, 22]]
| 8
| 2,826
| 14
|
using System;
using static System.Console;
class A {
static void Main() {
var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
if (a[0] > a[1] * a[2]) {
WriteLine("No");
} else {
WriteLine("No");
}
}
}
|
using System;
class A {
static void Main() {
var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
if (a[0] > a[1] * a[2]) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
}
}
}
|
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 115], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 78
| 2
|
using System;
namespace _177 {
class Program {
static void Main(string[] args) { Console.WriteLine(solution()); }
static public string solution() {
string[] input = Console.ReadLine().Split(' ');
int D = int.Parse(input[0]); // Distance m
int T = int.Parse(input[1]); // Time min
int S = int.Parse(input[2]); // Speed m/min
if (D / T <= S)
return "Yes";
else {
return "No";
}
}
}
}
|
using System;
namespace _177 {
class Program {
static void Main(string[] args) { Console.WriteLine(solution()); }
static public string solution() {
string[] input = Console.ReadLine().Split(' ');
int D = int.Parse(input[0]); // Distance m
int T = int.Parse(input[1]); // Time min
int S = int.Parse(input[2]); // Speed m/min
if (S * T >= D)
return "Yes";
else {
return "No";
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 120
| 8
|
using System;
using System.Collections.Generic;
class TEST {
public static void Main() {
string[] values = Console.ReadLine().Split(
new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
int distance = int.Parse(values[0]);
int speed = int.Parse(values[1]);
int time = int.Parse(values[2]);
if (distance / speed > time) {
Console.WriteLine("No");
} else
Console.WriteLine("Yes");
// Console.ReadKey();
}
}
|
using System;
using System.Collections.Generic;
class TEST {
public static void Main() {
string[] values = Console.ReadLine().Split(
new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
float distance = float.Parse(values[0]);
float time = float.Parse(values[1]);
float speed = float.Parse(values[2]);
if (distance / speed > time) {
Console.WriteLine("No");
} else
Console.WriteLine("Yes");
// Console.ReadKey();
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22]]
| 8
| 119
| 16
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int d = int.Parse(input[0]);
int t = int.Parse(input[1]);
int s = int.Parse(input[2]);
string ans = "";
if ((double)(d / s) <= t) {
ans = "Yes";
} else {
ans = "No";
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
double d = double.Parse(input[0]);
double t = double.Parse(input[1]);
double s = double.Parse(input[2]);
string ans = "";
if ((d / s) <= t) {
ans = "Yes";
} else {
ans = "No";
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 57, 15, 16, 31, 74, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 74, 39, 199], ["-", 8, 196, 0, 57, 15, 16, 31, 74, 0, 25]]
| 8
| 125
| 15
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;
class Test {
// Driver code
public static void Main() {
var input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var d = input[0];
var t = input[1];
var s = input[2];
if ((d / s) <= t)
Console.Write("Yes");
else
Console.Write("No");
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;
class Test {
// Driver code
public static void Main() {
var input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var d = input[0];
var t = input[1];
var s = input[2];
var ans = d / (s * 1.0);
if (ans <= t)
Console.Write("Yes");
else
Console.Write("No");
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 48], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 250], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
| 8
| 151
| 13
|
using System;
class notLate {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int d = int.Parse(input[0]);
int t = int.Parse(input[1]);
int s = int.Parse(input[2]);
int time = d / s;
if (t > time) {
Console.WriteLine("Yes");
}
if (t == time) {
Console.WriteLine("Yes");
}
if (t < time) {
Console.WriteLine("No");
}
}
}
|
using System;
class notLate {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
decimal d = decimal.Parse(input[0]);
decimal t = decimal.Parse(input[1]);
decimal s = decimal.Parse(input[2]);
decimal time = d / s;
if (t > time) {
Console.WriteLine("Yes");
}
if (t == time) {
Console.WriteLine("Yes");
}
if (t < time) {
Console.WriteLine("No");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 133
| 14
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoderBeginnerContest177 {
class Program {
static void Main(string[] args) {
// 課題A:Don't be late(2020/8/29)
string[] input = Console.ReadLine().Split(' ');
int length = int.Parse(input[0]);
int time = int.Parse(input[1]);
int speed = int.Parse(input[2]);
long ansTime = length / speed;
if (ansTime <= time)
Console.Write("Yes");
else
Console.Write("No");
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoderBeginnerContest177 {
class Program {
static void Main(string[] args) {
// 課題A:Don't be late(2020/8/29)
string[] input = Console.ReadLine().Split(' ');
int length = int.Parse(input[0]);
int time = int.Parse(input[1]);
int speed = int.Parse(input[2]);
long move = speed * time;
if (move >= length)
Console.Write("Yes");
else
Console.Write("No");
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 124
| 12
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int[] A = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
if (A[1] >= A[0] / A[2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
//出力
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int[] A = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
if ((double)A[1] >= (double)A[0] / (double)A[2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
//出力
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 25], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 24], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 39, 199], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 25], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 0, 24], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 39, 199], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 0, 25]]
| 8
| 98
| 9
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var a = cin.ArrayLong(3);
var m = a[0] / a[2];
Console.WriteLine(m <= a[1] ? "Yes" : "No");
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var a = cin.ArrayLong(3);
var can = a[2] * a[1];
Console.WriteLine(can >= a[0] ? "Yes" : "No");
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 582
| 14
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.A {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var (D, T, S) = Read3Longs();
if (D / S > T) {
return "No";
}
return "Yes";
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.A {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var (D, T, S) = Read3Longs();
if ((double)D / (double)S > (double)T) {
return "No";
}
return "Yes";
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 57, 15, 16, 31, 16, 12, 74, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 12, 74, 39, 199], ["+", 0, 57, 15, 16, 31, 16, 12, 74, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 25]]
| 8
| 381
| 9
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public void Run() {
var n = ni();
var s = new string[n];
var c = new int[n];
for (int i = 0; i < n; i++) {
s[i] = ns();
c[i] = ni();
}
var isPalindrome = new bool[n, 22, 22];
for (int i = 0; i < n; i++) {
var ss = s[i];
for (int k = 0; k < 2; k++) {
for (int j = 0; j + k < ss.Length; j++) {
int left = j;
int right = j + k;
while (0 <= left && right < ss.Length && ss[left] == ss[right]) {
isPalindrome[i, left, right] = true;
left--;
right++;
}
}
}
}
for (int _ = 0; _ < 2; _++) {
}
var visited = new bool[n, 22, 22, 2];
var inf = long.MaxValue;
var pq = new PriorityQueue<(long cost, int k, int left, int right,
int leftToRight)>();
long ans = inf;
for (int i = 0; i < n; i++) {
pq.Enqueue((c[i], i, 0, s[i].Length - 1, 1));
}
while (pq.Count > 0) {
var (cost, k, left, right, leftToRight) = pq.Dequeue();
if (left == right + 1 || isPalindrome[k, left, right]) {
ans = cost;
break;
}
if (left > right)
continue;
if (visited[k, left, right, leftToRight])
continue;
visited[k, left, right, leftToRight] = true;
var f = s[k];
for (int j = 0; j < n; j++) {
var t = s[j];
int match = 0;
if (leftToRight == 1) {
for (int i = left, p = t.Length - 1; i <= right && p >= 0; i++, p--) {
if (f[i] == t[p]) {
match++;
} else {
break;
}
}
if (match > 0) {
if (left + match <= right) {
pq.Enqueue((cost + c[j], k, left + match, right, 1));
} else {
pq.Enqueue((cost + c[j], j, 0, t.Length - 1 - match, 0));
}
}
} else {
for (int i = right, p = 0; i >= left && p < t.Length; i--, p++) {
if (f[i] == t[p]) {
match++;
} else {
break;
}
}
if (match > 0) {
if (left <= right - match) {
pq.Enqueue((cost + c[j], k, left, right - match, 0));
} else {
pq.Enqueue((cost + c[j], j, match, t.Length - 1, 1));
}
}
}
}
}
if (ans >= inf)
ans = -1;
cout.WriteLine(ans);
}
}
public class PriorityQueue<T> {
private T[] _array = new T[128];
private int _size = 0;
private readonly Comparison<T> _compare;
public PriorityQueue() { _compare = Comparer<T>.Default.Compare; }
public PriorityQueue(Comparison<T> comp) { _compare = comp; }
public int Count {
get { return _size; }
}
private void Swap(int a, int b) {
var t = _array[a];
_array[a] = _array[b];
_array[b] = t;
}
private void Expand() {
var newlist = new T[_array.Length << 1];
Array.Copy(_array, newlist, _array.Length);
_array = newlist;
}
public bool Any() { return _size > 0; }
public void Enqueue(T newValue) {
int pos = ++_size;
if (_size >= _array.Length) {
Expand();
}
_array[pos] = newValue;
while (pos > 1) {
int parent = pos >> 1;
if (_compare(_array[parent], _array[pos]) > 0) {
Swap(parent, pos);
pos = parent;
} else {
break;
}
}
}
public T Peek() { return _array[1]; }
public T Dequeue() {
var top = _array[1];
int pos = 1;
_array[pos] = _array[_size--];
while ((pos << 1) <= _size) {
int left = pos << 1;
int right = left | 1;
int next = left;
if (right <= _size && _compare(_array[left], _array[right]) > 0) {
next = right;
}
if (_compare(_array[pos], _array[next]) > 0) {
Swap(next, pos);
pos = next;
} else {
break;
}
}
return top;
}
};
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public void Run() {
var n = ni();
var s = new string[n];
var c = new int[n];
for (int i = 0; i < n; i++) {
s[i] = ns();
c[i] = ni();
}
var isPalindrome = new bool[n, 22, 22];
for (int i = 0; i < n; i++) {
var ss = s[i];
for (int k = 0; k < 2; k++) {
for (int j = 0; j + k < ss.Length; j++) {
int left = j;
int right = j + k;
while (0 <= left && right < ss.Length && ss[left] == ss[right]) {
isPalindrome[i, left, right] = true;
left--;
right++;
}
}
}
}
for (int _ = 0; _ < 2; _++) {
}
var visited = new bool[n, 22, 22, 2];
var inf = long.MaxValue;
var pq = new PriorityQueue<(long cost, int k, int left, int right,
int leftToRight)>();
long ans = inf;
for (int i = 0; i < n; i++) {
pq.Enqueue((c[i], i, 0, s[i].Length - 1, 1));
}
while (pq.Count > 0) {
var (cost, k, left, right, leftToRight) = pq.Dequeue();
if (left == right + 1 || isPalindrome[k, left, right]) {
ans = cost;
break;
}
if (left > right)
continue;
if (visited[k, left, right, leftToRight])
continue;
visited[k, left, right, leftToRight] = true;
var f = s[k];
for (int j = 0; j < n; j++) {
var t = s[j];
var maxMatch = Math.Min(right - left + 1, t.Length);
int match = 0;
if (leftToRight == 1) {
for (int i = left, p = t.Length - 1; i <= right && p >= 0; i++, p--) {
if (f[i] == t[p]) {
match++;
} else {
break;
}
}
if (match == maxMatch) {
if (left + match <= right) {
pq.Enqueue((cost + c[j], k, left + match, right, 1));
} else {
pq.Enqueue((cost + c[j], j, 0, t.Length - 1 - match, 0));
}
}
} else {
for (int i = right, p = 0; i >= left && p < t.Length; i--, p++) {
if (f[i] == t[p]) {
match++;
} else {
break;
}
}
if (match == maxMatch) {
if (left <= right - match) {
pq.Enqueue((cost + c[j], k, left, right - match, 0));
} else {
pq.Enqueue((cost + c[j], j, match, t.Length - 1, 1));
}
}
}
}
}
if (ans >= inf)
ans = -1;
cout.WriteLine(ans);
}
}
public class PriorityQueue<T> {
private T[] _array = new T[128];
private int _size = 0;
private readonly Comparison<T> _compare;
public PriorityQueue() { _compare = Comparer<T>.Default.Compare; }
public PriorityQueue(Comparison<T> comp) { _compare = comp; }
public int Count {
get { return _size; }
}
private void Swap(int a, int b) {
var t = _array[a];
_array[a] = _array[b];
_array[b] = t;
}
private void Expand() {
var newlist = new T[_array.Length << 1];
Array.Copy(_array, newlist, _array.Length);
_array = newlist;
}
public bool Any() { return _size > 0; }
public void Enqueue(T newValue) {
int pos = ++_size;
if (_size >= _array.Length) {
Expand();
}
_array[pos] = newValue;
while (pos > 1) {
int parent = pos >> 1;
if (_compare(_array[parent], _array[pos]) > 0) {
Swap(parent, pos);
pos = parent;
} else {
break;
}
}
}
public T Peek() { return _array[1]; }
public T Dequeue() {
var top = _array[1];
int pos = 1;
_array[pos] = _array[_size--];
while ((pos << 1) <= _size) {
int left = pos << 1;
int right = left | 1;
int next = left;
if (right <= _size && _compare(_array[left], _array[right]) > 0) {
next = right;
}
if (_compare(_array[pos], _array[next]) > 0) {
Swap(next, pos);
pos = next;
} else {
break;
}
}
return top;
}
};
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 2,352
| 26
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace AGC047A {
class Program {
static void Main(string[] args) {
var N = RInt;
var A = new decimal[N];
for (int i = 0; i < N; i++) {
A[i] = decimal.Parse(Console.ReadLine()) * 1000000000;
}
int[] countTwo = new int[N];
int[] countFiv = new int[N];
for (int i = 0; i < N; i++) {
decimal a = A[i];
while (a % 2 == 0) {
countTwo[i]++;
a /= 2;
}
decimal b = A[i];
while (b % 5 == 0) {
countFiv[i]++;
b /= 5;
}
}
int[,] dp = new int[19, 19];
for (int i = 0; i < N; i++) {
int t = countTwo[i];
int f = countFiv[i];
if (t > 18)
t = 18;
if (f > 18)
f = 18;
dp[t, f]++;
}
// 累積和
for (int i = 18; i >= 0; i--) {
for (int j = 18; j >= 0; j--) {
if (j < 18)
dp[i, j] += dp[i, j + 1];
if (i < 18)
dp[i, j] += dp[i + 1, j];
if (i < 18 && j < 18)
dp[i, j] -= dp[i + 1, j + 1];
}
}
Draw(countTwo);
Draw(countFiv);
Draw(dp);
long ans = 0;
for (int i = 0; i < N; i++) {
int t = countTwo[i];
int f = countFiv[i];
if (t > 18)
t = 18;
if (f > 18)
f = 18;
ans += dp[18 - t, 18 - f];
if (dp[18 - t, 18 - f] != 0 && t <= 18 - t && f <= 18 - f)
ans--;
}
Console.WriteLine(ans / 2);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() {
_v = n >= mod || n < 0 ? (n % mod + mod) % mod : n;
}
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
public static void Draw<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
static public void Draw<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace AGC047A {
class Program {
static void Main(string[] args) {
var N = RInt;
var A = new decimal[N];
for (int i = 0; i < N; i++) {
A[i] = decimal.Parse(Console.ReadLine()) * 1000000000;
}
int[] countTwo = new int[N];
int[] countFiv = new int[N];
for (int i = 0; i < N; i++) {
decimal a = A[i];
while (a % 2 == 0) {
countTwo[i]++;
a /= 2;
}
decimal b = A[i];
while (b % 5 == 0) {
countFiv[i]++;
b /= 5;
}
}
long[,] dp = new long[19, 19];
for (int i = 0; i < N; i++) {
int t = countTwo[i];
int f = countFiv[i];
if (t > 18)
t = 18;
if (f > 18)
f = 18;
dp[t, f]++;
}
// 累積和
for (int i = 18; i >= 0; i--) {
for (int j = 18; j >= 0; j--) {
if (j < 18)
dp[i, j] += dp[i, j + 1];
if (i < 18)
dp[i, j] += dp[i + 1, j];
if (i < 18 && j < 18)
dp[i, j] -= dp[i + 1, j + 1];
}
}
Draw(countTwo);
Draw(countFiv);
Draw(dp);
long ans = 0;
for (int i = 0; i < N; i++) {
int t = countTwo[i];
int f = countFiv[i];
if (t > 18)
t = 18;
if (f > 18)
f = 18;
ans += dp[18 - t, 18 - f];
if (dp[18 - t, 18 - f] != 0 && 18 - t <= t && 18 - f <= f)
ans--;
}
Console.WriteLine(ans / 2);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() {
_v = n >= mod || n < 0 ? (n % mod + mod) % mod : n;
}
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
public static void Draw<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
static public void Draw<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
| 8
| 1,564
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class modMWorld {
public static long M = (int)Math.Pow(10, 9) + 7;
//必要な演算は、加減乗除、nCk,n!,a^n
public static long add(long a, long b) {
long sum = a + b;
sum += M;
return sum % M;
}
public static long sub(long a, long b) {
long dif = a - b;
dif += M * 2;
return dif % M;
}
public static long mul(long a, long b) {
long product = a;
product *= b;
return product % M;
}
public static long div(long a, long b) { return mul(a, Pow(b, M - 2)); }
public static long modify(long a) { return (a % M + M) % M; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static long Pow(long a, long m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
long p1 = Pow(a, m / 2);
long p2 = mul(p1, p1);
return ((m % 2) == 0) ? p2 : mul(p2, a);
}
}
public static long kaijou(long n) {
//!
long output = 1;
for (int i = 0; i < n; i++) {
output = mul(output, n - i);
}
return output;
}
public static long nCk(long n, long k) {
long output = 1;
for (int i = 1; i <= k; i++) {
output = mul(output, n - (i - 1));
output = div(output, i);
}
return output;
}
}
class Util {
public static string convertToBinary(int N, int length) {
string binary = Convert.ToString(N, 2);
while (length > binary.Length) {
binary = "0" + binary;
}
return binary;
}
public static int[] readintarr() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static long[] readlongarr() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
/// <summary>
/// nの約数を小さい順のリストで返します。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<int> make_divisor(int n) {
List<int> output = new List<int>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
output.Add(i);
if (i * i != n) {
output.Add(n / i);
}
}
}
output.Sort();
return output;
}
// iの素因数分解をします
public static List<int> soinsuuBunkai(int n) {
//素因数分解をします
List<int> output = new List<int>();
int target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
public static List<long> soinsuuBunkai(long n) {
List<long> output = new List<long>();
long target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
/// <summary>
/// 2引数の最大公約数を返します。longです。
/// </summary>
/// <param name="a">long 引数1</param>
/// <param name="b">long 引数2</param>
/// <returns></returns>
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2引数の最大公約数を返します。intです。
/// </summary>
/// <param name="a">int 引数1</param>
/// <param name="b">int 引数2</param>
/// <returns></returns>
public static int GCD(int a, int b) {
// if (a < b)
// swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2つの変数の中身を交換する。型はなんでもいい
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <param name="b"></param>
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)998244353; //(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
public static long nCr(long n, long r) {
long output = 1;
for (int i = 1; i <= r; i++) {
output *= (n + 1 - i);
output /= (i);
}
return output;
}
/// <summary>
/// 2引数の積 mod Mを求める。Mは10億7。
/// 変えられるよ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
/// <summary>
/// n! modMまたはnCmを求めるための準備を行う。引数は最大値。
/// </summary>
/// <param name="n"></param>
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
/// <summary>
/// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int Factorial(int n) { return factorial_modM[n]; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
/// <summary>
/// a / m Mod M を求める。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
/// <summary>
/// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <param name="r"></param>
/// <returns></returns>
public static int nCr_modM(int n, int r) {
if (r < 0)
return 0;
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
/// <summary>
/// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。
/// おすすめとしては、UnionFind<T>[] で宣言してしまう。
/// 配列で宣言したあと、コンストラクタ使ってnewするのを忘れないでね。
/// コンストラクタのitemは、そのノード固有のIDになるので、絶対必要です
/// </summary>
/// <typeparam name="T">int固定でいいよね。</typeparam>
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
this.item = item;
}
/// <summary>
/// 一番上の親を探す。
/// 探しながら繋がり方を最適化している。
/// UnionFindの頂点そのものを返すので、==での比較が可能。
/// </summary>
/// <returns></returns>
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
/// <summary>
/// unionfind2つを一つにつなぐ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
/// <summary>
/// 使い方:Permutation.next(配列) で次の配列を返す
/// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。
/// もし、次のがない場合、空の配列を返します。
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Permutation<T>
where T : IComparable {
public static T[] next(T[] letters) {
int pivot = -1;
for (int i = letters.Length - 2; i >= 0; i--) {
if (letters[i].CompareTo(letters[i + 1]) < 0) {
pivot = i;
break;
}
}
if (pivot == -1) {
return new T[0];
}
int big_min = letters.Length - 1;
T big_min_T = letters[letters.Length - 1];
for (int i = letters.Length - 1; i > pivot;
i--) { // big_min_Tより小さいかつ、pivotのより大きい
if (letters[pivot].CompareTo(letters[i]) > 0 &&
letters[pivot].CompareTo(big_min_T) < 0) {
big_min_T = letters[i];
big_min = i;
}
}
T temp = letters[pivot];
letters[pivot] = letters[big_min];
letters[big_min] = temp;
Array.Sort(letters, pivot + 1, letters.Length - pivot - 1);
return letters;
}
}
/// <summary>
/// 使い方 : Combination
/// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数)
/// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Combination<T>
where T : IComparable {
private static bool stop = false;
public static List<string> AllCombination(T[] letters, int n) {
// n桁ですよね。
List<string> outlist = new List<string>();
T[] state = new T[n];
for (int i = 0; i < n; i++) {
state[i] = letters[0];
}
outlist.Add(String.Join(" ", state));
while (true) {
next_keta(ref state, state.Length - 1, letters);
if (stop)
break;
outlist.Add(string.Join(" ", state));
}
return outlist;
}
public static T[] next_keta(ref T[] state, int keta, T[] letters) {
if (keta == -1) {
stop = true;
return new T[0];
}
if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) {
//見た桁を最初の要素にする処理を
state[keta] = letters[0];
return next_keta(ref state, keta - 1, letters);
} else {
int ketaindex = 0;
for (int i = 0; i < letters.Length; i++) {
if (state[keta].CompareTo(letters[i]) == 0) {
ketaindex = i;
break;
}
}
state[keta] = letters[ketaindex + 1];
return state;
}
}
}
/// <summary>
/// 常に昇順に並んでいるすごいやつだよ
///
/// </summary>
/// <typeparam name="T"></typeparam>
class phantaSortedList<T> {
public List<T> list;
readonly Comparison<T> cmp = Comparer<T>.Default.Compare;
public phantaSortedList() { list = new List<T>(); }
public void Add(T x) {
if (this.list.Count == 0) {
list.Add(x);
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
if (left == -1) {
if (cmp(list[0], x) >= 0) {
list.Insert(0, x);
} else {
list.Insert(1, x);
}
} else if (right == this.list.Count) {
if (cmp(list[this.list.Count - 1], x) >= 0) {
list.Insert(this.list.Count - 2, x);
} else {
list.Add(x);
}
} else {
list.Insert(right, x);
}
}
/// <summary>
/// xがあるならその最小indexを。ないなら-1を。
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public int indexSearch(T x) {
if (list.Count == 0) {
return -1;
}
int ok = list.Count;
int ng = -1;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
if (cmp(list[mid], x) >= 0) {
ok = mid;
} else {
ng = mid;
}
}
if (ok == list.Count) {
//リストの中にあるすべてのものより大きいものを検索した場合
return -1;
} else if (cmp(list[ok], x) == 0) {
return ok;
} else {
return -1;
}
}
/// <summary>
/// あるなら一つ削除。ないなら無視。
/// </summary>
/// <param name="x"></param>
public void Remove(T x) {
if (list.Count == 0) {
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
{
if (left == -1) {
if (cmp(list[0], x) == 0) {
list.RemoveAt(0);
}
} else if (right == this.list.Count) {
if (cmp(list.Last(), x) == 0) {
list.RemoveAt(list.Count - 1);
}
} else {
if (cmp(list[right], x) == 0) {
list.RemoveAt(right);
}
}
}
}
/// <summary>
/// 指定した値をlistから全滅させます。
/// </summary>
/// <param name="x"></param>
public void allRemove(T x) {
if (list.Count == 0) {
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
{
if (left == -1) {
while (cmp(list[0], x) == 0) {
list.RemoveAt(0);
}
} else if (right == this.list.Count) {
while (cmp(list.Last(), x) == 0) {
list.RemoveAt(list.Count - 1);
}
} else {
while (right < list.Count) {
if (cmp(list[right], x) == 0) {
list.RemoveAt(right);
} else {
break;
}
}
}
}
}
public T min() {
if (list.Count == 0)
return default(T);
return list[0];
}
public T max() {
if (list.Count == 0)
return default(T);
return list.Last();
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// あと絶対コンストラクタ使ってね
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
/// <summary>
/// !!!WARNING!!! 1-BASEです。
/// </summary>
/// <param name="m">要素の数の最大値。200001とか入れておくとよい</param>
/// <param name="f">2引数の関数</param>
/// <param
/// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param>
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
/// <summary>
/// j番目の値をxにする。計算し直さないので、
/// 入れ替えた後はall_update();を使おう
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
/// <summary>
/// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
/// <summary>
/// 木を全部計算し直す。多分NlogN。違うかも知れないから
/// よかったら教えて
/// </summary>
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
/// <summary>
/// j番目を消す。
/// </summary>
/// <param name="j"></param>
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
/// <summary>
/// s番目からt - 1 番目までの結果を返す。t番目は含まない。
/// これも当然のように1-BASE.
/// </summary>
/// <param name="s"></param>
/// <param name="t"></param>
/// <returns></returns>
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class pair<T> {
public T A;
public T B;
public pair() {}
public pair(T A, T B) {
this.A = A;
this.B = B;
}
}
public class chouten {
public int N;
public List<int> node;
public chouten(int n) {
this.N = n;
this.node = new List<int>();
}
}
public class ab {
public int a, b;
public ab(int a, int b) {
this.a = a;
this.b = b;
}
}
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
// System.Collections.Generic.SortedList<>
//文字列比較のcomparer
// StringComparer.OrdinalIgnoreCase
public static void Main() {
int N;
new readint(out N);
long[] d = new long[N];
for (int i = 0; i < N; i++) {
string s = Console.ReadLine();
d[i] = (long)decimal.Multiply(decimal.Parse(s), 1000000000m);
}
int[,] twoandfive = new int[50, 50];
Tuple<int, int>[] data = new Tuple<int, int>[N];
for (int i = 0; i < N; i++) {
long t = d[i];
int two = 0;
while (t % 2 == 0) {
t /= 2;
two++;
}
int five = 0;
while (t % 5 == 0) {
t /= 5;
five++;
}
data[i] = new Tuple<int, int>(two, five);
twoandfive[two, five]++;
}
long output = 0;
for (int i = 0; i < N; i++) {
Tuple<int, int> target = data[i];
int lefttwoes = target.Item1;
int leftfives = target.Item2;
twoandfive[lefttwoes, leftfives]--;
for (int twoes = 18 - lefttwoes; twoes < 50; twoes++) {
for (int fives = 18 - leftfives; fives < 50; fives++) {
output += twoandfive[twoes, fives];
}
}
}
Console.WriteLine(output);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class modMWorld {
public static long M = (int)Math.Pow(10, 9) + 7;
//必要な演算は、加減乗除、nCk,n!,a^n
public static long add(long a, long b) {
long sum = a + b;
sum += M;
return sum % M;
}
public static long sub(long a, long b) {
long dif = a - b;
dif += M * 2;
return dif % M;
}
public static long mul(long a, long b) {
long product = a;
product *= b;
return product % M;
}
public static long div(long a, long b) { return mul(a, Pow(b, M - 2)); }
public static long modify(long a) { return (a % M + M) % M; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static long Pow(long a, long m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
long p1 = Pow(a, m / 2);
long p2 = mul(p1, p1);
return ((m % 2) == 0) ? p2 : mul(p2, a);
}
}
public static long kaijou(long n) {
//!
long output = 1;
for (int i = 0; i < n; i++) {
output = mul(output, n - i);
}
return output;
}
public static long nCk(long n, long k) {
long output = 1;
for (int i = 1; i <= k; i++) {
output = mul(output, n - (i - 1));
output = div(output, i);
}
return output;
}
}
class Util {
public static string convertToBinary(int N, int length) {
string binary = Convert.ToString(N, 2);
while (length > binary.Length) {
binary = "0" + binary;
}
return binary;
}
public static int[] readintarr() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static long[] readlongarr() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
/// <summary>
/// nの約数を小さい順のリストで返します。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<int> make_divisor(int n) {
List<int> output = new List<int>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
output.Add(i);
if (i * i != n) {
output.Add(n / i);
}
}
}
output.Sort();
return output;
}
// iの素因数分解をします
public static List<int> soinsuuBunkai(int n) {
//素因数分解をします
List<int> output = new List<int>();
int target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
public static List<long> soinsuuBunkai(long n) {
List<long> output = new List<long>();
long target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
/// <summary>
/// 2引数の最大公約数を返します。longです。
/// </summary>
/// <param name="a">long 引数1</param>
/// <param name="b">long 引数2</param>
/// <returns></returns>
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2引数の最大公約数を返します。intです。
/// </summary>
/// <param name="a">int 引数1</param>
/// <param name="b">int 引数2</param>
/// <returns></returns>
public static int GCD(int a, int b) {
// if (a < b)
// swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2つの変数の中身を交換する。型はなんでもいい
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <param name="b"></param>
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)998244353; //(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
public static long nCr(long n, long r) {
long output = 1;
for (int i = 1; i <= r; i++) {
output *= (n + 1 - i);
output /= (i);
}
return output;
}
/// <summary>
/// 2引数の積 mod Mを求める。Mは10億7。
/// 変えられるよ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
/// <summary>
/// n! modMまたはnCmを求めるための準備を行う。引数は最大値。
/// </summary>
/// <param name="n"></param>
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
/// <summary>
/// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int Factorial(int n) { return factorial_modM[n]; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
/// <summary>
/// a / m Mod M を求める。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
/// <summary>
/// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <param name="r"></param>
/// <returns></returns>
public static int nCr_modM(int n, int r) {
if (r < 0)
return 0;
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
/// <summary>
/// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。
/// おすすめとしては、UnionFind<T>[] で宣言してしまう。
/// 配列で宣言したあと、コンストラクタ使ってnewするのを忘れないでね。
/// コンストラクタのitemは、そのノード固有のIDになるので、絶対必要です
/// </summary>
/// <typeparam name="T">int固定でいいよね。</typeparam>
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
this.item = item;
}
/// <summary>
/// 一番上の親を探す。
/// 探しながら繋がり方を最適化している。
/// UnionFindの頂点そのものを返すので、==での比較が可能。
/// </summary>
/// <returns></returns>
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
/// <summary>
/// unionfind2つを一つにつなぐ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
/// <summary>
/// 使い方:Permutation.next(配列) で次の配列を返す
/// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。
/// もし、次のがない場合、空の配列を返します。
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Permutation<T>
where T : IComparable {
public static T[] next(T[] letters) {
int pivot = -1;
for (int i = letters.Length - 2; i >= 0; i--) {
if (letters[i].CompareTo(letters[i + 1]) < 0) {
pivot = i;
break;
}
}
if (pivot == -1) {
return new T[0];
}
int big_min = letters.Length - 1;
T big_min_T = letters[letters.Length - 1];
for (int i = letters.Length - 1; i > pivot;
i--) { // big_min_Tより小さいかつ、pivotのより大きい
if (letters[pivot].CompareTo(letters[i]) > 0 &&
letters[pivot].CompareTo(big_min_T) < 0) {
big_min_T = letters[i];
big_min = i;
}
}
T temp = letters[pivot];
letters[pivot] = letters[big_min];
letters[big_min] = temp;
Array.Sort(letters, pivot + 1, letters.Length - pivot - 1);
return letters;
}
}
/// <summary>
/// 使い方 : Combination
/// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数)
/// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Combination<T>
where T : IComparable {
private static bool stop = false;
public static List<string> AllCombination(T[] letters, int n) {
// n桁ですよね。
List<string> outlist = new List<string>();
T[] state = new T[n];
for (int i = 0; i < n; i++) {
state[i] = letters[0];
}
outlist.Add(String.Join(" ", state));
while (true) {
next_keta(ref state, state.Length - 1, letters);
if (stop)
break;
outlist.Add(string.Join(" ", state));
}
return outlist;
}
public static T[] next_keta(ref T[] state, int keta, T[] letters) {
if (keta == -1) {
stop = true;
return new T[0];
}
if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) {
//見た桁を最初の要素にする処理を
state[keta] = letters[0];
return next_keta(ref state, keta - 1, letters);
} else {
int ketaindex = 0;
for (int i = 0; i < letters.Length; i++) {
if (state[keta].CompareTo(letters[i]) == 0) {
ketaindex = i;
break;
}
}
state[keta] = letters[ketaindex + 1];
return state;
}
}
}
/// <summary>
/// 常に昇順に並んでいるすごいやつだよ
///
/// </summary>
/// <typeparam name="T"></typeparam>
class phantaSortedList<T> {
public List<T> list;
readonly Comparison<T> cmp = Comparer<T>.Default.Compare;
public phantaSortedList() { list = new List<T>(); }
public void Add(T x) {
if (this.list.Count == 0) {
list.Add(x);
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
if (left == -1) {
if (cmp(list[0], x) >= 0) {
list.Insert(0, x);
} else {
list.Insert(1, x);
}
} else if (right == this.list.Count) {
if (cmp(list[this.list.Count - 1], x) >= 0) {
list.Insert(this.list.Count - 2, x);
} else {
list.Add(x);
}
} else {
list.Insert(right, x);
}
}
/// <summary>
/// xがあるならその最小indexを。ないなら-1を。
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public int indexSearch(T x) {
if (list.Count == 0) {
return -1;
}
int ok = list.Count;
int ng = -1;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
if (cmp(list[mid], x) >= 0) {
ok = mid;
} else {
ng = mid;
}
}
if (ok == list.Count) {
//リストの中にあるすべてのものより大きいものを検索した場合
return -1;
} else if (cmp(list[ok], x) == 0) {
return ok;
} else {
return -1;
}
}
/// <summary>
/// あるなら一つ削除。ないなら無視。
/// </summary>
/// <param name="x"></param>
public void Remove(T x) {
if (list.Count == 0) {
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
{
if (left == -1) {
if (cmp(list[0], x) == 0) {
list.RemoveAt(0);
}
} else if (right == this.list.Count) {
if (cmp(list.Last(), x) == 0) {
list.RemoveAt(list.Count - 1);
}
} else {
if (cmp(list[right], x) == 0) {
list.RemoveAt(right);
}
}
}
}
/// <summary>
/// 指定した値をlistから全滅させます。
/// </summary>
/// <param name="x"></param>
public void allRemove(T x) {
if (list.Count == 0) {
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
{
if (left == -1) {
while (cmp(list[0], x) == 0) {
list.RemoveAt(0);
}
} else if (right == this.list.Count) {
while (cmp(list.Last(), x) == 0) {
list.RemoveAt(list.Count - 1);
}
} else {
while (right < list.Count) {
if (cmp(list[right], x) == 0) {
list.RemoveAt(right);
} else {
break;
}
}
}
}
}
public T min() {
if (list.Count == 0)
return default(T);
return list[0];
}
public T max() {
if (list.Count == 0)
return default(T);
return list.Last();
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// あと絶対コンストラクタ使ってね
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
/// <summary>
/// !!!WARNING!!! 1-BASEです。
/// </summary>
/// <param name="m">要素の数の最大値。200001とか入れておくとよい</param>
/// <param name="f">2引数の関数</param>
/// <param
/// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param>
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
/// <summary>
/// j番目の値をxにする。計算し直さないので、
/// 入れ替えた後はall_update();を使おう
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
/// <summary>
/// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
/// <summary>
/// 木を全部計算し直す。多分NlogN。違うかも知れないから
/// よかったら教えて
/// </summary>
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
/// <summary>
/// j番目を消す。
/// </summary>
/// <param name="j"></param>
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
/// <summary>
/// s番目からt - 1 番目までの結果を返す。t番目は含まない。
/// これも当然のように1-BASE.
/// </summary>
/// <param name="s"></param>
/// <param name="t"></param>
/// <returns></returns>
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class pair<T> {
public T A;
public T B;
public pair() {}
public pair(T A, T B) {
this.A = A;
this.B = B;
}
}
public class chouten {
public int N;
public List<int> node;
public chouten(int n) {
this.N = n;
this.node = new List<int>();
}
}
public class ab {
public int a, b;
public ab(int a, int b) {
this.a = a;
this.b = b;
}
}
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
// System.Collections.Generic.SortedList<>
//文字列比較のcomparer
// StringComparer.OrdinalIgnoreCase
public static void Main() {
int N;
new readint(out N);
long[] d = new long[N];
for (int i = 0; i < N; i++) {
string s = Console.ReadLine();
d[i] = (long)decimal.Multiply(decimal.Parse(s), 1000000000m);
}
int[,] twoandfive = new int[50, 50];
Tuple<int, int>[] data = new Tuple<int, int>[N];
for (int i = 0; i < N; i++) {
long t = d[i];
int two = 0;
while (t % 2 == 0) {
t /= 2;
two++;
}
int five = 0;
while (t % 5 == 0) {
t /= 5;
five++;
}
data[i] = new Tuple<int, int>(two, five);
twoandfive[two, five]++;
}
long output = 0;
for (int i = 0; i < N; i++) {
Tuple<int, int> target = data[i];
int lefttwoes = target.Item1;
int leftfives = target.Item2;
twoandfive[lefttwoes, leftfives]--;
for (int twoes = Math.Max(18 - lefttwoes, 0); twoes < 50; twoes++) {
for (int fives = Math.Max(18 - leftfives, 0); fives < 50; fives++) {
output += twoandfive[twoes, fives];
}
}
}
Console.WriteLine(output);
}
}
|
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 5,562
| 14
|
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Schema;
namespace AtCoder {
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.OrdinalIgnoreCase);
return s.ToList();
}
public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); }
public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); }
public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); }
public static int PopCount(this int bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}
}
partial class AtCoder {
public string GetStr() { return Console.ReadLine().Trim(); }
public char GetChar() { return Console.ReadLine().Trim()[0]; }
public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<int>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<int>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
dic[a].Add(b);
if (isDirected == false)
dic[b].Add(a);
}
return dic;
}
Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<Edge>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<Edge>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
var c = input[2];
dic[a].Add(new Edge(b, c));
if (isDirected == false)
dic[b].Add(new Edge(a, c));
}
return dic;
}
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
void Multi<T>(out T a) => a = cv<T>(GetStr());
void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e,
out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
class Pair : IComparable<Pair> {
public Pair(int node, long cost) {
Node = node;
Cost = cost;
}
public int Node { get; set; }
public long Cost { get; set; }
public int CompareTo(Pair p) { return p.Cost > Cost ? 1 : -1; }
}
class Edge {
public Edge(int to, long length) {
To = to;
Length = length;
}
public int To { get; set; }
public long Length { get; set; }
}
class Comparable : IComparable<Comparable> {
public Comparable(int value) { Value = value; }
public int Value { get; set; }
public int CompareTo(Comparable c) {
var a = Math.Abs(Value);
var b = Math.Abs(c.Value);
return a > b ? 1 : a == b ? 0 : -1;
}
}
class Comparer<T> : IComparer<T> {
public int Compare(T t1, T t2) { return 1; }
}
partial class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new AtCoder().Solve();
Console.Out.Flush();
Console.Read();
}
}
public partial class AtCoder {
public void Solve() {
int N = GetInt();
var array = new long [14][];
for (int i = 0; i < 14; i++)
array[i] = new long[14];
for (int i = 0; i < N; i++) {
var a = GetStr();
if (a.Contains(".") && a.Split('.') [1].Any(_ => _ != '0')) {
var seisu = long.Parse(a.Split('.')[0]);
var longa = long.Parse(a.Split('.') [1].PadRight(9, '0'));
longa = seisu * (long)Math.Pow(10, 9) + longa;
int b = 0;
int c = 0;
var tmp = longa;
while (tmp % 2 == 0) {
b++;
tmp /= 2;
}
tmp = longa;
while (tmp % 5 == 0) {
c++;
tmp /= 5;
}
array[b][c]++;
} else {
var inta = (int)Math.Ceiling(double.Parse(a));
int b = 9, c = 9;
var tmp = inta;
while (tmp % 2 == 0) {
b++;
tmp /= 2;
}
tmp = inta;
while (tmp % 5 == 0) {
c++;
tmp /= 5;
}
if (b >= 14)
b = 13;
if (c >= 14)
c = 13;
array[b][c]++;
}
}
long sum = 0;
for (int i = 0; i < 14; i++) {
for (int j = 0; j < 14; j++) {
for (int k = 0; k < 14; k++) {
for (int l = 0; l < 14; l++) {
if (i + j >= 18 && k + l >= 18) {
sum += i == j && k == l ? array[i][k] * (array[j][l] - 1)
: array[i][k] * array[j][l];
}
}
}
}
}
Console.WriteLine(sum / 2);
}
}
}
|
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Schema;
namespace AtCoder {
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.OrdinalIgnoreCase);
return s.ToList();
}
public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); }
public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); }
public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); }
public static int PopCount(this int bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}
}
partial class AtCoder {
public string GetStr() { return Console.ReadLine().Trim(); }
public char GetChar() { return Console.ReadLine().Trim()[0]; }
public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<int>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<int>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
dic[a].Add(b);
if (isDirected == false)
dic[b].Add(a);
}
return dic;
}
Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<Edge>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<Edge>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
var c = input[2];
dic[a].Add(new Edge(b, c));
if (isDirected == false)
dic[b].Add(new Edge(a, c));
}
return dic;
}
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
void Multi<T>(out T a) => a = cv<T>(GetStr());
void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e,
out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
class Pair : IComparable<Pair> {
public Pair(int node, long cost) {
Node = node;
Cost = cost;
}
public int Node { get; set; }
public long Cost { get; set; }
public int CompareTo(Pair p) { return p.Cost > Cost ? 1 : -1; }
}
class Edge {
public Edge(int to, long length) {
To = to;
Length = length;
}
public int To { get; set; }
public long Length { get; set; }
}
class Comparable : IComparable<Comparable> {
public Comparable(int value) { Value = value; }
public int Value { get; set; }
public int CompareTo(Comparable c) {
var a = Math.Abs(Value);
var b = Math.Abs(c.Value);
return a > b ? 1 : a == b ? 0 : -1;
}
}
class Comparer<T> : IComparer<T> {
public int Compare(T t1, T t2) { return 1; }
}
partial class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new AtCoder().Solve();
Console.Out.Flush();
Console.Read();
}
}
public partial class AtCoder {
public void Solve() {
int N = GetInt();
var array = new long [50][];
for (int i = 0; i < 50; i++)
array[i] = new long[50];
for (int i = 0; i < N; i++) {
var a = GetStr();
if (a.Contains(".") && a.Split('.') [1].Any(_ => _ != '0')) {
var seisu = long.Parse(a.Split('.')[0]);
var longa = long.Parse(a.Split('.') [1].PadRight(9, '0'));
longa = seisu * (long)Math.Pow(10, 9) + longa;
int b = 0;
int c = 0;
var tmp = longa;
while (tmp % 2 == 0) {
b++;
tmp /= 2;
}
tmp = longa;
while (tmp % 5 == 0) {
c++;
tmp /= 5;
}
array[b][c]++;
} else {
var inta = (int)Math.Ceiling(double.Parse(a));
int b = 9, c = 9;
var tmp = inta;
while (tmp % 2 == 0) {
b++;
tmp /= 2;
}
tmp = inta;
while (tmp % 5 == 0) {
c++;
tmp /= 5;
}
array[b][c]++;
}
}
long sum = 0;
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
for (int k = 0; k < 50; k++) {
for (int l = 0; l < 50; l++) {
if (i + j >= 18 && k + l >= 18) {
sum += i == j && k == l ? array[i][k] * (array[j][l] - 1)
: array[i][k] * array[j][l];
}
}
}
}
}
Console.WriteLine(sum / 2);
}
}
}
|
[["-", 0, 227, 39, 224, 39, 224, 225, 226, 0, 203], ["+", 0, 227, 39, 224, 39, 224, 225, 226, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["-", 75, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["-", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 2,485
| 34
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirCondi {
class Class2 {
static void Main(string[] args) {
int x = 34;
if (x >= 30) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirCondi {
class Class2 {
static void Main(string[] args) {
int x = 34;
x = int.Parse(Console.ReadLine());
if (x >= 30) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 80
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0007 {
class Program {
static void Main(string[] args) {
var fStr = Console.ReadLine();
int N = int.Parse(fStr.Split(' ')[0]);
int D = int.Parse(fStr.Split(' ')[1]);
int index = 0;
int result = 0;
while (index < N) {
index++;
var rStr = Console.ReadLine();
int x = int.Parse(rStr.Split(' ')[0]);
int y = int.Parse(rStr.Split(' ')[1]);
if (Math.Sqrt(x * x + y * y) <= D) {
result++;
}
}
Console.WriteLine(result);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0007 {
class Program {
static void Main(string[] args) {
var fStr = Console.ReadLine();
var N = int.Parse(fStr.Split(' ')[0]);
var D = int.Parse(fStr.Split(' ')[1]);
int index = 0;
int result = 0;
while (index < N) {
index++;
var rStr = Console.ReadLine();
var x = Int64.Parse(rStr.Split(' ')[0]);
var y = Int64.Parse(rStr.Split(' ')[1]);
if (Math.Sqrt(x * x + y * y) <= (double)D) {
result++;
}
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 25]]
| 8
| 194
| 15
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(" ");
int N = int.Parse(input[0]);
int D = int.Parse(input[1]);
int counter = 0;
//出力
for (int count = 0; count < N; count++) {
string[] inputi = Console.ReadLine().Split(" ");
int xi = int.Parse(input[0]);
int yi = int.Parse(input[1]);
if (Math.Sqrt(Math.Pow(xi, 2) + Math.Pow(yi, 2)) <= D) {
counter++;
}
}
Console.WriteLine(counter);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(" ");
double N = double.Parse(input[0]);
double D = double.Parse(input[1]);
double counter = 0;
//出力
for (int count = 0; count < N; count++) {
string[] inputi = Console.ReadLine().Split(" ");
double xi = double.Parse(inputi[0]);
double yi = double.Parse(inputi[1]);
if (Math.Sqrt(Math.Pow(xi, 2) + Math.Pow(yi, 2)) <= D) {
counter++;
}
}
Console.WriteLine(counter);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22]]
| 8
| 167
| 22
|
using System;
class Program {
static void Main(string[] args) {
// N/Dの入力
String[] nums = Console.ReadLine().Split(' ');
int N = int.Parse(nums[0]);
int D = int.Parse(nums[1]);
//座標点の入力
int answer = 0;
for (int i = 0; i < N; i++) {
String[] point = Console.ReadLine().Split(' ');
double x = double.Parse(point[0]);
double y = double.Parse(point[1]);
double ans = System.Math.Sqrt(((x * x) + (y * y)));
if (ans <= D) {
answer++;
Console.WriteLine("true");
}
}
// 結果出力
Console.WriteLine(answer);
}
}
|
using System;
class Program {
static void Main(string[] args) {
// N/Dの入力
String[] nums = Console.ReadLine().Split(' ');
int N = int.Parse(nums[0]);
int D = int.Parse(nums[1]);
//座標点の入力
int answer = 0;
for (int i = 0; i < N; i++) {
String[] point = Console.ReadLine().Split(' ');
double x = double.Parse(point[0]);
double y = double.Parse(point[1]);
double ans = System.Math.Sqrt(((x * x) + (y * y)));
if (ans <= D) {
answer++;
}
}
// 結果出力
Console.WriteLine(answer);
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 181
| 9
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var inputs = Console.ReadLine().Split(" ");
var N = int.Parse(inputs[0]);
var D = int.Parse(inputs[1]);
var X = new List<int>();
var Y = new List<int>();
for (int i = 0; i < N; i++) {
inputs = Console.ReadLine().Split(" ");
X.Add(int.Parse(inputs[0]));
Y.Add(int.Parse(inputs[1]));
}
var count = 0;
for (int i = 0; i < N; i++) {
var distance = Math.Sqrt(X[i] * X[i] + Y[i] * Y[i]);
if (distance <= D)
count++;
}
Console.WriteLine(count);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var inputs = Console.ReadLine().Split(" ");
var N = int.Parse(inputs[0]);
var D = int.Parse(inputs[1]);
var X = new List<int>();
var Y = new List<int>();
for (int i = 0; i < N; i++) {
inputs = Console.ReadLine().Split(" ");
X.Add(int.Parse(inputs[0]));
Y.Add(int.Parse(inputs[1]));
}
var count = 0;
for (int i = 0; i < N; i++) {
var distance = Math.Sqrt(Math.Pow(X[i], 2) + Math.Pow(Y[i], 2));
if (distance <= D)
count++;
}
Console.WriteLine(count);
}
}
|
[["-", 0, 28, 0, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 21], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 28, 0, 16, 12, 16, 31, 204, 205, 22], ["-", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 215
| 24
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int d = int.Parse(input[1]);
int r = 0;
for (int i = 0; i < n; i++) {
string[] input2 = Console.ReadLine().Split(' ');
int x = int.Parse(input2[0]);
int y = int.Parse(input2[1]);
if (d * d >= x * x + y * y) {
r++;
}
}
Console.WriteLine(r);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
long d = long.Parse(input[1]);
int r = 0;
for (int i = 0; i < n; i++) {
string[] input2 = Console.ReadLine().Split(' ');
long x = long.Parse(input2[0]);
long y = long.Parse(input2[1]);
long p = d * d;
long s = x * x + y * y;
if (p >= s) {
r++;
}
}
Console.WriteLine(r);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 153
| 28
|
using System;
using System.Linq;
namespace Sample {
class Sample {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int N = int.Parse(str[0]);
int D = int.Parse(str[1]);
int ans = 0;
for (int i = 1; i <= N; i++) {
string[] str2 = Console.ReadLine().Split(' ');
int X = int.Parse(str2[0]);
int Y = int.Parse(str2[1]);
int tmpsq = (int)Math.Pow(X, 2) + (int)Math.Pow(Y, 2);
int tmp = (int)Math.Ceiling(Math.Sqrt(tmpsq));
if (tmp <= D) {
ans++;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
using System.Numerics;
namespace Sample {
class Sample {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
long N = long.Parse(str[0]);
long D = long.Parse(str[1]);
int ans = 0;
for (int i = 1; i <= N; i++) {
string[] str2 = Console.ReadLine().Split(' ');
long X = long.Parse(str2[0]);
long Y = long.Parse(str2[1]);
long tmpsq = (long)Math.Pow(X, 2) + (long)Math.Pow(Y, 2);
long tmp = (long)Math.Ceiling(Math.Sqrt(tmpsq));
if (tmp <= D) {
ans++;
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199]]
| 8
| 199
| 31
|
using System;
using System.Linq;
class names {
static void Main() {
int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
int n = s[0];
int d = s[1];
int ans = 0;
int f = 0;
for (int k = 0; k < n; k++) {
s = Console.ReadLine().Split().Select(int.Parse).ToArray();
f = s[1] * s[1] + s[0] * s[0];
if (f <= d * d) {
ans++;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
class names {
static void Main() {
long[] s = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = s[0];
long d = s[1];
long ans = 0;
long f = 0;
for (long k = 0; k < n; k++) {
s = Console.ReadLine().Split().Select(long.Parse).ToArray();
f = s[1] * s[1] + s[0] * s[0];
if (f <= d * d) {
ans++;
}
}
Console.WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 152
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace easy_Atcoder {
class Program {
static void Main(string[] args) {
double[] ND = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
int count = 0;
for (int i = 0; i < ND[0]; i++) {
double[] xy = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
double res = Math.Sqrt(xy[0] * xy[0] + xy[1] * xy[1]);
if (res <= ND[1]) {
count++;
Console.WriteLine(xy[0]);
Console.WriteLine(xy[1]);
Console.WriteLine("res is " + res);
}
}
Console.WriteLine(count);
}
// long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// long N = NK[0];
// long K = NK[1];
// long K = long.Parse(Console.ReadLine());
// int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// string S = Console.ReadLine();
// int x = int.Parse(Console.ReadLine());
// int b = int.Parse(Console.ReadLine());
// int N = int.Parse(Console.ReadLine());
// float N = float.Parse(Console.ReadLine());
// string c = Console.ReadLine();
// string B = Console.ReadLine();
// string[] s = Console.ReadLine().Split();
// var s = (new string[] { Console.ReadLine(), Console.ReadLine(),
// Console.ReadLine() }).Select(float.Parse); float[] a =
// Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X =
// Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new
// int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[]
// s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new
// Dictionary<long,long>(); for(int i=0;i<s[0];i++){
// long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
// else{hs.Add(q[0],q[1]);}
// }
// //最小公倍数
// static long Lcm(long a, long b)
// {
// return a/Gcd(a,b)*b;
// }
// //最大公約数
// static long Gcd(long m, long n)
// {
// if(n==0)return m;
// return Gcd(n,m%n);
// }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace easy_Atcoder {
class Program {
static void Main(string[] args) {
double[] ND = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
int count = 0;
for (int i = 0; i < ND[0]; i++) {
double[] xy = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
double res = Math.Sqrt(xy[0] * xy[0] + xy[1] * xy[1]);
if (res <= ND[1]) {
count++;
}
}
Console.WriteLine(count);
}
// long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// long N = NK[0];
// long K = NK[1];
// long K = long.Parse(Console.ReadLine());
// int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// string S = Console.ReadLine();
// int x = int.Parse(Console.ReadLine());
// int b = int.Parse(Console.ReadLine());
// int N = int.Parse(Console.ReadLine());
// float N = float.Parse(Console.ReadLine());
// string c = Console.ReadLine();
// string B = Console.ReadLine();
// string[] s = Console.ReadLine().Split();
// var s = (new string[] { Console.ReadLine(), Console.ReadLine(),
// Console.ReadLine() }).Select(float.Parse); float[] a =
// Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X =
// Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new
// int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[]
// s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new
// Dictionary<long,long>(); for(int i=0;i<s[0];i++){
// long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
// else{hs.Add(q[0],q[1]);}
// }
// //最小公倍数
// static long Lcm(long a, long b)
// {
// return a/Gcd(a,b)*b;
// }
// //最大公約数
// static long Gcd(long m, long n)
// {
// if(n==0)return m;
// return Gcd(n,m%n);
// }
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 221
| 31
|
using System;
using static System.Console;
using System.Linq;
namespace AC {
public class shiokara {
static void Main(string[] args) {
int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
int N = tmp[0], D = tmp[1];
int cnt = 0;
for (int i = 0; i < N; i++) {
tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
if (Math.Sqrt(Math.Pow(2, tmp[0]) + Math.Pow(2, tmp[1])) <= D)
cnt++;
}
WriteLine(cnt);
}
}
}
|
using System;
using static System.Console;
using System.Linq;
namespace AC {
public class shiokara {
static void Main(string[] args) {
int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
int N = tmp[0], D = tmp[1];
int cnt = 0;
for (int i = 0; i < N; i++) {
tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
if (Math.Sqrt(Math.Pow(tmp[0], 2) + Math.Pow(tmp[1], 2)) <= D)
cnt++;
}
WriteLine(cnt);
}
}
}
|
[["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 21], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 162
| 8
|
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Threading;
namespace AtCoder {
class Program {
struct Point {
public int x;
public int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
const int BiggestMod = 1000000007;
public static void Main() {
var args =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var n = args[0];
var d = args[1] * args[1];
var ans = 0;
for (int i = 0; i < n; i++) {
args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
if (args[0] * args[0] + args[1] * args[1] <= d)
ans++;
}
Console.WriteLine(ans);
}
}
}
|
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Threading;
namespace AtCoder {
class Program {
struct Point {
public int x;
public int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
const int BiggestMod = 1000000007;
public static void Main() {
var args =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var n = args[0];
var d = args[1] * args[1];
var ans = 0;
for (int i = 0; i < n; i++) {
args = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
if (Math.Abs(args[0] * args[0]) + Math.Abs(args[1] * args[1]) <= d)
ans++;
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 15, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 257
| 14
|
using System;
namespace _174.c {
internal class Program {
private static void Main(string[] args) {
var k = int.Parse(Console.ReadLine());
var a = 7;
var ans = -1;
for (var i = 0; i < k; i++) {
if (a % k == 0) {
ans = i + 1;
break;
}
a = a * 10 + 7;
}
Console.WriteLine(ans.ToString());
}
}
}
|
using System;
namespace _174.c {
internal class Program {
private static void Main(string[] args) {
var k = int.Parse(Console.ReadLine());
long a = 7;
var ans = -1;
for (var i = 0; i < k; i++) {
if (a % k == 0) {
ans = i + 1;
break;
}
a = (a % k) * (10 % k) + (7 % k);
}
Console.WriteLine(ans.ToString());
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 17, 109], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 24], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 17, 109], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 8
| 104
| 6
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
namespace AtCoder {
static class Program_D {
class Solver {
int ri => sc.Integer();
long rl => sc.Long();
double rd => sc.Double();
string rs => sc.Scan();
public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
private int[][] m;
public void Solve() {
m = new int [10][]; // 1...9
for (int i = 1; i <= 9; ++i) {
m[i] = new int[10];
for (int j = 1; j <= 9; ++j) {
var tmp = i * j;
m[i][j] = tmp % 10;
}
}
long k = rl;
long mod = k % 10;
long ans = 0;
long current = 0;
do {
// Wl($"current : {current}");
long trg = (17 - (current % 10)) % 10;
// Wl($"trg : {trg}");
long mult = 0;
for (int i = 1; i <= 9; ++i) {
if (m[mod][i] == trg)
mult = i;
}
if (mult == 0) {
Wl(-1);
return;
}
long multVal = k * mult;
// Wl(multVal);
current += multVal;
while (current % 10 == 7) {
ans++;
current /= 10;
}
if (current == 0)
break;
} while (true);
Wl(ans);
}
private void DumpMultTables() {
for (int i = 1; i <= 9; ++i) {
Wl($"[{i}]" + string.Join(" ", m[i].Select(tmp => $"{tmp}")));
}
}
// ----------------------------------------------------------------------------
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
string Rl() { return Console.ReadLine(); }
void Wl(UInt64 val) { Console.WriteLine(val); }
void Wl(Int64 val) { Console.WriteLine(val); }
void Wl(uint val) { Console.WriteLine(val); }
void Wl(int val) { Console.WriteLine(val); }
void Wl(double val) { Console.WriteLine(val); }
void Wl(string mes) { Console.WriteLine(mes); }
public int Int() { return int.Parse(Console.ReadLine()); }
public int[] Ints(int subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) - subtract)
.ToArray();
}
public Int64[] Int64s(Int64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => Int64.Parse(s) - subtract)
.ToArray();
}
public UInt64[] UInt64s(UInt64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => UInt64.Parse(s) - subtract)
.ToArray();
}
}
static void Main(string[] args) {
Console.SetOut(
new Printer(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve();
Console.Out.Flush();
}
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider =>
CultureInfo.InvariantCulture;
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
struct ModInt {
const int MOD = 1000000007;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => a.Data + b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => a.Data - b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div;
long p = MOD;
long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
namespace AtCoder {
static class Program_D {
class Solver {
int ri => sc.Integer();
long rl => sc.Long();
double rd => sc.Double();
string rs => sc.Scan();
public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
private int[][] m;
public void Solve() {
m = new int [10][]; // 1...9
for (int i = 1; i <= 9; ++i) {
m[i] = new int[10];
for (int j = 1; j <= 9; ++j) {
var tmp = i * j;
m[i][j] = tmp % 10;
}
}
long k = rl;
long mod = k % 10;
if (mod == 0) {
Wl(-1);
return;
}
long ans = 0;
long current = 0;
do {
// Wl($"current : {current}");
long trg = (17 - (current % 10)) % 10;
// Wl($"trg : {trg}");
long mult = 0;
for (int i = 1; i <= 9; ++i) {
if (m[mod][i] == trg)
mult = i;
}
if (mult == 0) {
Wl(-1);
return;
}
long multVal = k * mult;
// Wl(multVal);
current += multVal;
while (current % 10 == 7) {
ans++;
current /= 10;
}
if (current == 0)
break;
} while (true);
Wl(ans);
}
private void DumpMultTables() {
for (int i = 1; i <= 9; ++i) {
Wl($"[{i}]" + string.Join(" ", m[i].Select(tmp => $"{tmp}")));
}
}
// ----------------------------------------------------------------------------
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
string Rl() { return Console.ReadLine(); }
void Wl(UInt64 val) { Console.WriteLine(val); }
void Wl(Int64 val) { Console.WriteLine(val); }
void Wl(uint val) { Console.WriteLine(val); }
void Wl(int val) { Console.WriteLine(val); }
void Wl(double val) { Console.WriteLine(val); }
void Wl(string mes) { Console.WriteLine(mes); }
public int Int() { return int.Parse(Console.ReadLine()); }
public int[] Ints(int subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) - subtract)
.ToArray();
}
public Int64[] Int64s(Int64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => Int64.Parse(s) - subtract)
.ToArray();
}
public UInt64[] UInt64s(UInt64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => UInt64.Parse(s) - subtract)
.ToArray();
}
}
static void Main(string[] args) {
Console.SetOut(
new Printer(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve();
Console.Out.Flush();
}
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider =>
CultureInfo.InvariantCulture;
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
struct ModInt {
const int MOD = 1000000007;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => a.Data + b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => a.Data - b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div;
long p = MOD;
long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,558
| 16
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var K = cin.ReadInt;
int seven = 7 % K;
if (K % 2 == 0) {
WriteLine(-1);
}
for (int i = 1; i <= K; i++) {
if (seven == 0) {
WriteLine(i);
break;
}
seven = (seven * 10 + 7) % K;
}
// var num1 = 0; ;
// Console.WriteLine(Math.Abs(list.IndexOf(p) - list.IndexOf(q)));
// var num = cin.ReadInt;
// int[] array = cin.ReadIntArray(num);
// List<int> list = array.ToList();
////for (int i =0; i < num; i++) {
//// list.Add(array[i]);
////}
// var nk = Console.ReadLine().Split(' ');
// var n = int.Parse(nk[0]);
// var k = int.Parse(nk[1]);
// var t = new int[n][];
// for (int i =0; i < n;i++) {
// t[i] = cin.ReadIntArray(n);
//}
// int n = cin.ReadInt;
// int K = cin.ReadInt;
// int[] array = new int[n];
// for (int i =0; i < n; i++) {
// array[i] = cin.ReadInt;
//}
// for (int i =0; i < n; i++) {
// if (array[i] == 0) {
// WriteLine(n);
// }
//}
// int res = 0;
// int right = 0;
// long mult = 1;
// for (int left = 0; left < n; left++) {
// while (right < n && mult * array[right] <= K) {
// mult *= array[right];
// right++;
// }
// res = Math.Max(res, right - left);
// if (left == right) right++;
// else mult /= array[left];
//}
// WriteLine(res);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var K = cin.ReadInt;
int seven = 7 % K;
// if (K%2 == 0) {
// WriteLine(-1);
//}
for (int i = 1; i <= K; i++) {
if (seven == 0) {
WriteLine(i);
return;
}
seven = (seven * 10 + 7) % K;
}
WriteLine(-1);
// var num1 = 0; ;
// Console.WriteLine(Math.Abs(list.IndexOf(p) - list.IndexOf(q)));
// var num = cin.ReadInt;
// int[] array = cin.ReadIntArray(num);
// List<int> list = array.ToList();
////for (int i =0; i < num; i++) {
//// list.Add(array[i]);
////}
// var nk = Console.ReadLine().Split(' ');
// var n = int.Parse(nk[0]);
// var k = int.Parse(nk[1]);
// var t = new int[n][];
// for (int i =0; i < n;i++) {
// t[i] = cin.ReadIntArray(n);
//}
// int n = cin.ReadInt;
// int K = cin.ReadInt;
// int[] array = new int[n];
// for (int i =0; i < n; i++) {
// array[i] = cin.ReadInt;
//}
// for (int i =0; i < n; i++) {
// if (array[i] == 0) {
// WriteLine(n);
// }
//}
// int res = 0;
// int right = 0;
// long mult = 1;
// for (int left = 0; left < n; left++) {
// while (right < n && mult * array[right] <= K) {
// mult *= array[right];
// right++;
// }
// res = Math.Max(res, right - left);
// if (left == right) right++;
// else mult /= array[left];
//}
// WriteLine(res);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 536
| 24
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
private static void Main(string[] args) {
var k = Scanner.Integer();
var l = 9 * k;
int i = 1;
int value = 1;
while (i <= k) {
value = value * 10 % l;
if (value == 1) {
Console.WriteLine(i);
return;
}
if (value == 0) {
break;
}
i++;
}
Console.WriteLine(-1);
}
#region Utility
static readonly StreamScanner Scanner =
new StreamScanner(Console.OpenStandardInput());
/// <summary> 一括出力 </summary>
private static void OutAllLine(IEnumerable<int> items) {
var sb = new StringBuilder();
foreach (var result in items) {
sb.Append(result.ToString() + "\n");
}
sb = sb.Remove(sb.Length - 1, 1);
Console.WriteLine(sb);
}
#endregion
}
#region Utility Class
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanIncludeSpace() {
var sb = new StringBuilder();
for (var b = Char(); b >= 32 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
/// <summary> 数値読み込み </summary>
public List<long> ArrayLong(int count = 0) {
var scan = new List<long>();
for (int i = 0; i < count; i++) {
scan.Add(Long());
}
return scan;
}
/// <summary> 数値読み込み </summary>
public List<int> ArrayInt(int count = 0) {
var scan = new List<int>();
for (int i = 0; i < count; i++) {
scan.Add(Integer());
}
return scan;
}
}
public class Primer {
/// <summary> 素数判定 </summary>
public static bool IsPrime(int num) {
if (num < 2) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static IEnumerable<int> GetPrimeFactors(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
}
public class Mod109 {
public const int _7 = 1000000007;
public const int _9 = 1000000009;
public const int _3 = 998244353;
private readonly int ModValue;
public Mod109(int modValue = Mod109._7) { ModValue = modValue; }
/// <summary> 和 </summary>
public long Addition(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current + num) % ModValue));
}
/// <summary> 差 </summary>
public long Subtraction(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current - num) % ModValue));
}
/// <summary> 積 </summary>
public long Multiplication(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
1, (current, num) => ModifyPositive((current * num) % ModValue));
}
private long ModifyPositive(long value) {
return value < 0 ? (value + ModValue) : value;
}
}
public class BitArrayMaker {
public List<int> Integer(int bitValue, int length) {
var list = new List<int>();
for (int i = 0; i < length; i++) {
if (bitValue % 2 == 1) {
list.Add(i);
}
bitValue /= 2;
}
return list;
}
public bool[] Boolean(int bitValue, int length) {
var list = new bool[length];
for (int i = 0; i < length; i++) {
list[i] = bitValue % 2 == 1;
bitValue /= 2;
}
return list;
}
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
private static void Main(string[] args) {
var k = Scanner.Integer();
var l = k % 7 == 0 ? 9 * k / 7 : 9 * k;
int i = 1;
int value = 1;
while (i <= k) {
value = value * 10 % l;
if (value == 1) {
Console.WriteLine(i);
return;
}
if (value == 0) {
break;
}
i++;
}
Console.WriteLine(-1);
}
#region Utility
static readonly StreamScanner Scanner =
new StreamScanner(Console.OpenStandardInput());
/// <summary> 一括出力 </summary>
private static void OutAllLine(IEnumerable<int> items) {
var sb = new StringBuilder();
foreach (var result in items) {
sb.Append(result.ToString() + "\n");
}
sb = sb.Remove(sb.Length - 1, 1);
Console.WriteLine(sb);
}
#endregion
}
#region Utility Class
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanIncludeSpace() {
var sb = new StringBuilder();
for (var b = Char(); b >= 32 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
/// <summary> 数値読み込み </summary>
public List<long> ArrayLong(int count = 0) {
var scan = new List<long>();
for (int i = 0; i < count; i++) {
scan.Add(Long());
}
return scan;
}
/// <summary> 数値読み込み </summary>
public List<int> ArrayInt(int count = 0) {
var scan = new List<int>();
for (int i = 0; i < count; i++) {
scan.Add(Integer());
}
return scan;
}
}
public class Primer {
/// <summary> 素数判定 </summary>
public static bool IsPrime(int num) {
if (num < 2) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static IEnumerable<int> GetPrimeFactors(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
}
public class Mod109 {
public const int _7 = 1000000007;
public const int _9 = 1000000009;
public const int _3 = 998244353;
private readonly int ModValue;
public Mod109(int modValue = Mod109._7) { ModValue = modValue; }
/// <summary> 和 </summary>
public long Addition(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current + num) % ModValue));
}
/// <summary> 差 </summary>
public long Subtraction(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current - num) % ModValue));
}
/// <summary> 積 </summary>
public long Multiplication(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
1, (current, num) => ModifyPositive((current * num) % ModValue));
}
private long ModifyPositive(long value) {
return value < 0 ? (value + ModValue) : value;
}
}
public class BitArrayMaker {
public List<int> Integer(int bitValue, int length) {
var list = new List<int>();
for (int i = 0; i < length; i++) {
if (bitValue % 2 == 1) {
list.Add(i);
}
bitValue /= 2;
}
return list;
}
public bool[] Boolean(int bitValue, int length) {
var list = new bool[length];
for (int i = 0; i < length; i++) {
list[i] = bitValue % 2 == 1;
bitValue /= 2;
}
return list;
}
}
#endregion
}
|
[["+", 0, 212, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 212, 0, 41, 64, 16, 31, 16, 31, 203], ["+", 0, 212, 0, 41, 64, 16, 31, 16, 17, 48], ["+", 0, 212, 0, 41, 64, 16, 31, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 41, 64, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 41, 64, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102]]
| 8
| 1,248
| 12
|
using System;
public class Hello {
public static void Main() {
ulong K = ulong.Parse(System.Console.ReadLine());
if (K % 2 == 0) {
Console.WriteLine(-1);
return;
}
ulong count = (ulong)Math.Log10(K) + 1;
ulong v = 7;
for (ulong i = 1; i < count; i++) {
v = v * 10 + 7;
}
while (true) {
ulong a = v % K;
if (count == K) {
Console.WriteLine(-1);
return;
}
if (a == 0) {
Console.WriteLine(count);
return;
}
v = a * 10 + 7;
count++;
}
}
}
|
using System;
public class Hello {
public static void Main() {
ulong K = ulong.Parse(System.Console.ReadLine());
if (K % 2 == 0) {
Console.WriteLine(-1);
return;
}
ulong count = (ulong)Math.Log10(K) + 1;
ulong v = 7;
for (ulong i = 1; i < count; i++) {
v = v * 10 + 7;
}
while (true) {
ulong a = v % K;
if (a == 0) {
Console.WriteLine(count);
return;
}
if (count == K) {
Console.WriteLine(-1);
return;
}
v = a * 10 + 7;
count++;
}
}
}
|
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203]]
| 8
| 155
| 14
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder0802 {
class MainClass {
public static void Main(string[] args) {
long K = long.Parse(Console.ReadLine());
long seven = 7;
long ans = 1;
long lseven;
if (K % 2 != 0) {
for (var i = 1; i < 1000000; i++) {
if (seven % K == 0) {
break;
} else {
seven = seven * 10 + 7;
if (seven > K) {
seven %= K;
}
ans++;
}
//}
}
}
if (K % 2 == 0) {
Console.WriteLine("-1");
} else {
var test = seven % K;
Console.WriteLine(ans);
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder0802 {
class MainClass {
public static void Main(string[] args) {
long K = long.Parse(Console.ReadLine());
long seven = 7;
long ans = 1;
if (K % 2 != 0) {
for (var i = 1; i < 1000000; i++) {
if (seven % K == 0) {
break;
} else {
seven = seven * 10 + 7;
if (seven > K) {
seven %= K;
}
ans++;
}
//}
}
}
if (ans > K || K % 2 == 0) {
Console.WriteLine("-1");
} else {
var test = seven % K;
Console.WriteLine(ans);
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106]]
| 8
| 163
| 7
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
if (n % 2 == 0) {
Console.WriteLine("-1");
} else {
var ans = 0;
var rem = 0;
var current = 0;
var currentDigit = 1;
for (var i = 1; i <= 1000000; i++) {
if (currentDigit == 1) {
if (7 % n == 0) {
ans = 1;
break;
}
current = 7 % n;
currentDigit += 1;
rem = 7 % n;
} else {
if ((rem + ((current * (10 % n))) % n) % n == 0) {
ans = currentDigit;
break;
}
rem = (rem + ((current * (10 % n))) % n) % n;
current = (current * (10 % n)) % n;
currentDigit += 1;
}
}
Console.WriteLine(ans);
}
Console.ReadLine();
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
if (n % 2 == 0) {
Console.WriteLine("-1");
} else {
var ans = 0;
var rem = 0;
var current = 0;
var currentDigit = 1;
for (var i = 1; i <= 1000000; i++) {
if (currentDigit == 1) {
if (7 % n == 0) {
ans = 1;
break;
}
current = 7 % n;
currentDigit += 1;
rem = 7 % n;
} else {
if ((rem + ((current * (10 % n))) % n) % n == 0) {
ans = currentDigit;
break;
}
rem = (rem + ((current * (10 % n))) % n) % n;
current = (current * (10 % n)) % n;
currentDigit += 1;
}
}
if (ans == 0) {
ans = -1;
}
Console.WriteLine(ans);
}
Console.ReadLine();
}
}
|
[["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 235
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class c {
public static void Main() {
long k = long.Parse(Console.ReadLine());
long num = 0;
long ans = 1;
bool[] already = new bool[k];
if (k % 2 == 0) {
ans = -1;
} else {
while (true) {
num = (num * 10 + 7) % k;
if (num == 0 || already[num]) {
break;
}
already[num] = true;
ans++;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class c {
public static void Main() {
long k = long.Parse(Console.ReadLine());
long num = 0;
long ans = 1;
bool[] already = new bool[k];
if (k % 2 == 0) {
ans = -1;
} else {
while (true) {
num = (num * 10 + 7) % k;
if (num == 0) {
break;
}
if (already[num]) {
ans = -1;
break;
}
already[num] = true;
ans++;
}
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 75, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 75, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 75, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 135
| 13
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC174C {
class Program {
static void Main(string[] args) {
var K = RInt;
Dictionary<int, int> dic = new Dictionary<int, int>();
int a = 7;
int ans = 1;
while (true) {
a *= 10;
a += 7;
a %= K;
ans++;
if (dic.ContainsKey(a)) {
ans = -1;
break;
} else
dic.Add(a, 1);
if (a == 0)
break;
}
Console.WriteLine(ans);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC174C {
class Program {
static void Main(string[] args) {
var K = RInt;
Dictionary<int, int> dic = new Dictionary<int, int>();
int a = 7;
if (K == 1 || K == 7) {
Console.WriteLine(1);
return;
}
int ans = 1;
while (true) {
a *= 10;
a += 7;
a %= K;
ans++;
if (dic.ContainsKey(a)) {
ans = -1;
break;
} else
dic.Add(a, 1);
if (a == 0)
break;
}
Console.WriteLine(ans);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,206
| 21
|
using System;
using System.CodeDom;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PaperMario {
class Program {
public static void Main(string[] args) {
Console.ReadLine();
var str = Console.ReadLine();
var redCount = str.Count(c => c == 'R');
Console.WriteLine(redCount);
var changeCount = str.Take(redCount).Count(c => c == 'W');
Console.WriteLine(changeCount);
}
}
}
|
using System;
using System.CodeDom;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PaperMario {
class Program {
public static void Main(string[] args) {
Console.ReadLine();
var str = Console.ReadLine();
var redCount = str.Count(c => c == 'R');
var changeCount = str.Take(redCount).Count(c => c == 'W');
Console.WriteLine(changeCount);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 111
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace atcoder {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var str = Console.ReadLine().ToArray();
var tmp = 0;
var result = 0;
for (var i = 0; i < n; i++) {
if (str[i] == 'R') {
if (tmp + 1 <= n) {
result += tmp;
n -= tmp + 1;
tmp = 0;
} else {
result += n;
break;
}
} else {
tmp++;
}
}
Console.WriteLine(result);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace atcoder {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var str = Console.ReadLine().ToArray();
var rCnt = str.Count(c => c == 'R');
var tmp = 0;
var result = 0;
for (var i = 0; i < n; i++) {
if (str[i] == 'R') {
if (tmp + 1 <= rCnt) {
result += tmp;
rCnt -= tmp + 1;
tmp = 0;
} else {
result += rCnt;
break;
}
} else {
tmp++;
}
}
Console.WriteLine(result);
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 0, 28, 0, 218, 8, 16, 12, 252, 0, 104], ["+", 0, 28, 0, 218, 8, 16, 12, 252, 0, 253], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 151
| 22
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
public static (long m, long s)[,] dp;
static void Main(string[] args) {
checked {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var N = vals[0];
var S = Console.ReadLine();
var redseeker = N - 1;
var rcnt = S.Count(x => x == 'R');
var ans = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'W') {
while (redseeker >= 0 && S[redseeker] != 'R')
redseeker--;
redseeker--;
rcnt--;
if (rcnt == 0 || redseeker <= i)
break;
ans++;
}
if (rcnt == 0 || redseeker <= i)
break;
}
if (rcnt == S.Count(x => x == 'R'))
ans = 0;
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
public static (long m, long s)[,] dp;
static void Main(string[] args) {
checked {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var N = vals[0];
var S = Console.ReadLine();
var redseeker = N - 1;
var rcnt = S.Count(x => x == 'R');
var ans = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'W') {
while (redseeker >= 0 && S[redseeker] != 'R')
redseeker--;
redseeker--;
rcnt--;
if (redseeker + 1 <= i)
break;
ans++;
}
if (redseeker + 1 <= i)
break;
}
if (0 == S.Count(x => x == 'R'))
ans = 0;
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
}
|
[["-", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 106], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 287, 0, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 287, 0, 196, 0, 57, 15, 16, 31, 203]]
| 8
| 283
| 14
|
using System;
class Program {
static void Main(string[] args) {
int i, j;
int n = int.Parse(Console.ReadLine());
string strInput = Console.ReadLine();
char[] cInput = strInput.ToCharArray();
int result = 0;
int startRNum = 0; // Rで始まる。
int endWNum = 0;
i = 0;
while (cInput[i] == 'R' && i < n) {
startRNum++;
i++;
}
i = n - 1;
while (cInput[i] == 'W' && i >= 0) {
endWNum++;
i--;
}
// R...RW...Wになっている。またはどっちかの色のみ
if (startRNum + endWNum == n) {
Console.WriteLine(0);
return;
}
int lPtr = 0;
int rPtr = n - 1;
while (true) {
while (cInput[lPtr] == 'R' && lPtr < n)
lPtr++;
while (cInput[rPtr] == 'W' && rPtr >= 0)
rPtr--;
if (lPtr >= rPtr) {
break;
}
cInput[lPtr] = 'R';
cInput[rPtr] = 'W';
result++;
}
Console.WriteLine(result);
return;
}
}
|
using System;
class Program {
static void Main(string[] args) {
int i, j;
int n = int.Parse(Console.ReadLine());
string strInput = Console.ReadLine();
char[] cInput = strInput.ToCharArray();
int result = 0;
int startRNum = 0; // Rで始まる。
int endWNum = 0;
i = 0;
while (cInput[i] == 'R') {
startRNum++;
i++;
if (i >= n)
break;
}
i = n - 1;
while (cInput[i] == 'W') {
endWNum++;
i--;
if (i < 0)
break;
}
// R...RW...Wになっている。またはどっちかの色のみ
if (startRNum + endWNum == n) {
Console.WriteLine(0);
return;
}
int lPtr = 0;
int rPtr = n - 1;
while (true) {
while (cInput[lPtr] == 'R' && lPtr < n)
lPtr++;
while (cInput[rPtr] == 'W' && rPtr >= 0)
rPtr--;
if (lPtr >= rPtr) {
break;
}
cInput[lPtr] = 'R';
cInput[rPtr] = 'W';
result++;
}
Console.WriteLine(result);
return;
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 17, 18], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 17, 20], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 243
| 24
|
using System;
using System.Linq;
class program {
static void Main() {
var nk = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var log = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
int mxlg = (int)log.Max(), mnlg = mxlg / (1 + nk[1]);
int sum, mid;
while (mnlg < mxlg) {
sum = 0;
mid = (mnlg + mxlg) / 2;
for (int i = 0; i < nk[0]; i++) {
sum += (int)Math.Ceiling(log[i] / mid) - 1;
}
if (sum <= nk[1]) {
mxlg = mid;
} else {
mnlg = mid + 1;
}
}
Console.Write(mnlg);
}
}
|
using System;
using System.Linq;
class program {
static void Main() {
var nk = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var log = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
int mxlg = (int)log.Max(), mnlg = mxlg / (1 + nk[1]), mid;
uint sum;
while (mnlg < mxlg) {
sum = 0;
mid = (mnlg + mxlg) / 2;
for (int i = 0; i < nk[0]; i++) {
sum += (uint)Math.Ceiling(log[i] / mid) - 1;
}
if (sum <= nk[1]) {
mxlg = mid;
} else {
mnlg = mid + 1;
}
}
Console.Write(mnlg);
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199]]
| 8
| 190
| 8
|
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
namespace _0815 {
class Program {
static long[] a;
static long n, k;
static void Main(string[] args) {
var nk = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
n = nk[0];
k = nk[1];
a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
}
static long Solution() {
long lb = 0, ub = a.Max();
while (ub - lb > 1) {
long mid = (lb + ub) / 2;
if (p(mid)) {
ub = mid;
} else {
lb = mid;
}
}
return ub;
}
static bool p(long x) {
long res = 0;
foreach (long num in a) {
res += ((num + x - 1) / x) - 1;
}
return res <= k;
}
}
}
|
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
namespace _0815 {
class Program {
static long[] a;
static long n, k;
static void Main(string[] args) {
var nk = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
n = nk[0];
k = nk[1];
a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long result = Solution();
Console.WriteLine(result);
}
static long Solution() {
long lb = 0, ub = a.Max();
while (ub - lb > 1) {
long mid = (lb + ub) / 2;
if (p(mid)) {
ub = mid;
} else {
lb = mid;
}
}
return ub;
}
static bool p(long x) {
long res = 0;
foreach (long num in a) {
res += ((num + x - 1) / x) - 1;
}
return res <= k;
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 233
| 14
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace Atcoder_0404 {
class Program {
static void Main(string[] args) {
var NK = GetInput_long();
var n = NK[0];
var k = NK[1];
var A_n = GetInput_long().ToList();
A_n.Sort();
var a_max = A_n[A_n.Count - 1];
long successMin = a_max;
long nowMax = a_max;
long nowMin = 1;
long checkNumber = (nowMax + nowMin) / 2;
while (nowMin <= nowMax) {
//失敗成功判定
long sum = 0;
for (int i = 0; i < A_n.Count; i++) {
long needcut = A_n[i] / checkNumber;
sum += needcut;
}
//範囲の変更処理
if (sum <= k) //成功 もっとちいさいものをさがす;
{
if (successMin > checkNumber)
successMin = checkNumber;
nowMax = checkNumber - 1;
// nowMin = nowMin;
} else //失敗もっとおおきいものをさがす
{
// nowMax = nowMax;
nowMin = checkNumber + 1;
}
checkNumber = (nowMax + nowMin) / 2;
}
Console.WriteLine(successMin);
}
#region input
static string[] GetInput_string() {
var input = Console.ReadLine().Split(' ');
return input;
}
static int[] GetInput_int() {
var input = GetInput_string();
var result = new int[input.Length];
for (int i = 0; i < result.Length; i++) {
result[i] = int.Parse(input[i]);
}
return result;
}
static long[] GetInput_long() {
var input = GetInput_string();
var result = new long[input.Length];
for (int i = 0; i < result.Length; i++) {
result[i] = long.Parse(input[i]);
}
return result;
}
#endregion
#region sonota
static void Swap_array<T>(T[] target, int a, int b) {
T temp = target[a];
target[a] = target[b];
target[b] = temp;
}
static void Swap_list<T>(List<T> target, int a, int b) {
T temp = target[a];
target[a] = target[b];
target[b] = temp;
}
/// <summary>
/// 最大公約数
/// </summary>
public static int GCD(int a, int b) {
/* 自然数 a > b を確認・入替 */
if (a < b) {
int tmp = a;
a = b;
b = tmp;
}
/* ユークリッドの互除法 */
int r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
/// <summary>
/// 最小公倍数
/// </summary>
public static int LCM(int a, int b) {
int x = a * b;
b = GCD(a, b);
return x / b;
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace Atcoder_0404 {
class Program {
static void Main(string[] args) {
var NK = GetInput_long();
var n = NK[0];
var k = NK[1];
var A_n = GetInput_long().ToList();
A_n.Sort();
var a_max = A_n[A_n.Count - 1];
long successMin = a_max;
long nowMax = a_max;
long nowMin = 1;
long checkNumber = (nowMax + nowMin) / 2;
while (nowMin <= nowMax) {
//失敗成功判定
long sum = 0;
for (int i = 0; i < A_n.Count; i++) {
long needcut = A_n[i] / checkNumber;
if (A_n[i] % checkNumber == 0)
needcut -= 1;
sum += needcut;
}
//範囲の変更処理
if (sum <= k) //成功 もっとちいさいものをさがす;
{
if (successMin > checkNumber)
successMin = checkNumber;
nowMax = checkNumber - 1;
// nowMin = nowMin;
} else //失敗もっとおおきいものをさがす
{
// nowMax = nowMax;
nowMin = checkNumber + 1;
}
checkNumber = (nowMax + nowMin) / 2;
}
Console.WriteLine(successMin);
}
#region input
static string[] GetInput_string() {
var input = Console.ReadLine().Split(' ');
return input;
}
static int[] GetInput_int() {
var input = GetInput_string();
var result = new int[input.Length];
for (int i = 0; i < result.Length; i++) {
result[i] = int.Parse(input[i]);
}
return result;
}
static long[] GetInput_long() {
var input = GetInput_string();
var result = new long[input.Length];
for (int i = 0; i < result.Length; i++) {
result[i] = long.Parse(input[i]);
}
return result;
}
#endregion
#region sonota
static void Swap_array<T>(T[] target, int a, int b) {
T temp = target[a];
target[a] = target[b];
target[b] = temp;
}
static void Swap_list<T>(List<T> target, int a, int b) {
T temp = target[a];
target[a] = target[b];
target[b] = temp;
}
/// <summary>
/// 最大公約数
/// </summary>
public static int GCD(int a, int b) {
/* 自然数 a > b を確認・入替 */
if (a < b) {
int tmp = a;
a = b;
b = tmp;
}
/* ユークリッドの互除法 */
int r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
/// <summary>
/// 最小公倍数
/// </summary>
public static int LCM(int a, int b) {
int x = a * b;
b = GCD(a, b);
return x / b;
}
#endregion
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 581
| 15
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class PriorityQueue<T> : IEnumerable<T>
where T : IComparable<T> {
private List<T> heap = new List<T>();
private int lastindex = -1;
private void swap(int n, int m) {
T wait = heap[n];
heap[n] = heap[m];
heap[m] = wait;
}
public int Count() { return lastindex + 1; }
public void Enqueue(T data) {
int p;
if (lastindex + 1 < heap.Count()) {
heap[lastindex + 1] = data;
} else {
heap.Add(data);
}
lastindex++;
p = lastindex;
while (true) {
if (p > 0 && heap[p].CompareTo(heap[(p - 1) / 2]) <= -1) {
swap(p, (p - 1) / 2);
p = (p - 1) / 2;
} else {
break;
}
}
}
public T Peek() { return heap[0]; }
public T Dequeue() {
T result = Peek();
heap[0] = default(T);
swap(0, lastindex);
lastindex--;
int p = 0;
while (true) {
int np;
if (2 * p + 1 > lastindex) {
break;
} else {
np = ((2 * p + 1 == lastindex) ||
heap[2 * p + 1].CompareTo(heap[2 * p + 2]) <= -1)
? (2 * p + 1)
: (2 * p + 2);
}
if (heap[p].CompareTo(heap[np]) >= 1) {
swap(p, np);
p = np;
} else {
break;
}
}
return result;
}
public PriorityQueue<T> Clone() {
var c = new PriorityQueue<T>();
T[] ar = null;
heap.ToArray().CopyTo(ar, 0);
c.heap = ar.ToList();
c.lastindex = lastindex;
return c;
}
public IEnumerator<T> GetEnumerator() {
PriorityQueue<T> copy = new PriorityQueue<T>();
T[] carray = null;
heap.ToArray().CopyTo(carray, 0);
copy.heap = carray.ToList();
copy.lastindex = lastindex;
for (int i = 0; i < lastindex + 1; i++) {
yield return copy.Dequeue();
}
}
IEnumerator IEnumerable.GetEnumerator() {
PriorityQueue<T> copy = new PriorityQueue<T>();
T[] carray = null;
heap.ToArray().CopyTo(carray, 0);
copy.heap = carray.ToList();
copy.lastindex = lastindex;
for (int i = 0; i < lastindex + 1; i++) {
yield return copy.Dequeue();
}
}
}
class Program {
public static (long m, long s)[,] dp;
static void Main(string[] args) {
// checked
{
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var N = vals[0];
var K = vals[1];
var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var Max = A.Max() + 1;
var Min = 1;
while (Max - Min > 1) {
var md = (Max + Min) / 2;
var cnt = 0;
foreach (var a in A) {
cnt += (a + md - 1) / md;
}
if (cnt <= K) {
Max = md;
} else {
Min = md;
}
}
Console.WriteLine(Min);
Console.Out.Flush();
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class PriorityQueue<T> : IEnumerable<T>
where T : IComparable<T> {
private List<T> heap = new List<T>();
private int lastindex = -1;
private void swap(int n, int m) {
T wait = heap[n];
heap[n] = heap[m];
heap[m] = wait;
}
public int Count() { return lastindex + 1; }
public void Enqueue(T data) {
int p;
if (lastindex + 1 < heap.Count()) {
heap[lastindex + 1] = data;
} else {
heap.Add(data);
}
lastindex++;
p = lastindex;
while (true) {
if (p > 0 && heap[p].CompareTo(heap[(p - 1) / 2]) <= -1) {
swap(p, (p - 1) / 2);
p = (p - 1) / 2;
} else {
break;
}
}
}
public T Peek() { return heap[0]; }
public T Dequeue() {
T result = Peek();
heap[0] = default(T);
swap(0, lastindex);
lastindex--;
int p = 0;
while (true) {
int np;
if (2 * p + 1 > lastindex) {
break;
} else {
np = ((2 * p + 1 == lastindex) ||
heap[2 * p + 1].CompareTo(heap[2 * p + 2]) <= -1)
? (2 * p + 1)
: (2 * p + 2);
}
if (heap[p].CompareTo(heap[np]) >= 1) {
swap(p, np);
p = np;
} else {
break;
}
}
return result;
}
public PriorityQueue<T> Clone() {
var c = new PriorityQueue<T>();
T[] ar = null;
heap.ToArray().CopyTo(ar, 0);
c.heap = ar.ToList();
c.lastindex = lastindex;
return c;
}
public IEnumerator<T> GetEnumerator() {
PriorityQueue<T> copy = new PriorityQueue<T>();
T[] carray = null;
heap.ToArray().CopyTo(carray, 0);
copy.heap = carray.ToList();
copy.lastindex = lastindex;
for (int i = 0; i < lastindex + 1; i++) {
yield return copy.Dequeue();
}
}
IEnumerator IEnumerable.GetEnumerator() {
PriorityQueue<T> copy = new PriorityQueue<T>();
T[] carray = null;
heap.ToArray().CopyTo(carray, 0);
copy.heap = carray.ToList();
copy.lastindex = lastindex;
for (int i = 0; i < lastindex + 1; i++) {
yield return copy.Dequeue();
}
}
}
class Program {
public static (long m, long s)[,] dp;
static void Main(string[] args) {
checked {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var N = vals[0];
var K = vals[1];
var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var Max = A.Max();
var Inf = 0;
while (Max - Inf > 1) {
var md = (Max + Inf + 1) / 2;
var cnt = 0;
foreach (var a in A) {
cnt += (a + md - 1) / md - 1;
}
if (cnt <= K) {
Max = md;
} else {
Inf = md;
}
}
Console.WriteLine(Max);
Console.Out.Flush();
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 196, 0, 52, 15, 16, 31, 16, 12, 22], ["+", 0, 196, 0, 52, 15, 16, 31, 16, 12, 22], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 873
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
public class SegmentTree {
public int N { get; private set; }
public int[] Node;
public int InvalidVal { get; private set; }
public SegmentTree(int[] a, int invVal) {
InvalidVal = invVal;
for (N = 1; N < a.Length; N *= 2)
;
Node = new int[2 * N - 1];
for (int i = 0; i < Node.Length; i++) {
Node[i] = InvalidVal;
}
for (int i = 0; i < a.Length; i++) {
Node[N + i - 1] = a[i];
}
for (int i = N - 2; i >= 0; i--) {
Node[i] = Sum(Node[2 * i + 1], Node[2 * i + 2]);
}
}
public void Update(int x, int v) {
x += (N - 1);
Node[x] = v;
while (x > 0) {
x = (x - 1) / 2;
Node[x] = Sum(Node[2 * x + 1], Node[2 * x + 2]);
}
}
public int Get(int a, int b) { return Get(a, b, 0, 0, N); }
private int Get(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return InvalidVal;
}
if (a <= l && r <= b) {
return Node[k];
}
var vl = Get(a, b, 2 * k + 1, l, (l + r) / 2);
var vr = Get(a, b, 2 * k + 2, (l + r) / 2, r);
return Sum(vl, vr);
}
private static int Sum(int a, int b) { return a + b; }
}
public class Query {
public int L;
public int R;
public int Answer;
public Query(string s) {
var vals = s.Split(' ').Select(int.Parse).ToArray();
L = vals[0] - 1;
R = vals[1];
}
}
public static class Solution {
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var N = vals[0];
var Q = vals[1];
var c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var queries = new List<Query>();
for (int q = 0; q < Q; q++) {
queries.Add(new Query(Console.ReadLine()));
}
var segtree = new SegmentTree(c, 0);
var cur = 0;
var lastIndex = new int[N + 1];
foreach (var q in queries.OrderBy(q => q.R)) {
for (; cur < q.R; cur++) {
var v = c[cur];
segtree.Update(lastIndex[v], 0);
segtree.Update(cur, 1);
lastIndex[v] = cur;
}
q.Answer = segtree.Get(q.L, q.R);
}
Console.WriteLine(
string.Join(Environment.NewLine, queries.Select(q => q.Answer)));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class SegmentTree {
public int N { get; private set; }
public int[] Node;
public int InvalidVal { get; private set; }
public SegmentTree(int[] a, int invVal) {
InvalidVal = invVal;
for (N = 1; N < a.Length; N *= 2)
;
Node = new int[2 * N - 1];
for (int i = 0; i < Node.Length; i++) {
Node[i] = InvalidVal;
}
for (int i = 0; i < a.Length; i++) {
Node[N + i - 1] = a[i];
}
for (int i = N - 2; i >= 0; i--) {
Node[i] = Sum(Node[2 * i + 1], Node[2 * i + 2]);
}
}
public void Update(int x, int v) {
x += (N - 1);
Node[x] = v;
while (x > 0) {
x = (x - 1) / 2;
Node[x] = Sum(Node[2 * x + 1], Node[2 * x + 2]);
}
}
public int Get(int a, int b) { return Get(a, b, 0, 0, N); }
private int Get(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return InvalidVal;
}
if (a <= l && r <= b) {
return Node[k];
}
var vl = Get(a, b, 2 * k + 1, l, (l + r) / 2);
var vr = Get(a, b, 2 * k + 2, (l + r) / 2, r);
return Sum(vl, vr);
}
private static int Sum(int a, int b) { return a + b; }
}
public class Query {
// 1オリジン [L,R)
public int L;
public int R;
public int Answer;
public Query(string s) {
var vals = s.Split(' ').Select(int.Parse).ToArray();
L = vals[0];
R = vals[1] + 1;
}
}
public static class Solution {
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var N = vals[0];
var Q = vals[1];
// 1オリジン c[0]はダミー
var c = new int [1]
.Concat(Console.ReadLine().Split(' ').Select(int.Parse))
.ToArray();
var queries = new List<Query>();
for (int q = 0; q < Q; q++) {
queries.Add(new Query(Console.ReadLine()));
}
var segtree = new SegmentTree(c, 0);
var cur = 1;
var lastIndex = new int[N + 1];
foreach (var q in queries.OrderBy(q => q.R)) {
for (; cur < q.R; cur++) {
var v = c[cur];
segtree.Update(lastIndex[v], 0);
segtree.Update(cur, 1);
lastIndex[v] = cur;
}
q.Answer = segtree.Get(q.L, q.R);
}
Console.WriteLine(
string.Join(Environment.NewLine, queries.Select(q => q.Answer)));
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 63, 214, 205, 213, 63, 214, 205, 227, 0, 228], ["+", 205, 213, 63, 214, 205, 227, 39, 224, 39, 199], ["+", 63, 214, 205, 227, 39, 224, 225, 226, 0, 70], ["+", 63, 214, 205, 227, 39, 224, 225, 226, 0, 203], ["+", 63, 214, 205, 227, 39, 224, 225, 226, 0, 73], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 749
| 15
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
#region library
static int n = 0;
static int m = 0;
static int r = 0;
static int c = 0;
static int x = 0;
static int y = 0;
static string s = "";
static string[] ss;
static long sum = 0;
static long cnt = 0;
static long max = -1;
static long min = 2147483647;
static bool flg = false;
static bool flg2 = false;
static string alpha = "abcdefghijklmnopqrstuvwxyz";
static long mod = 1000000007;
static long[] arr;
static char[,] map;
static long[,] imap;
public class Input {
static readonly char[] separator = { ' ', '\r', '\n' };
readonly StreamReader sr;
readonly Queue<string> queue;
public Input(string path = "") {
queue = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
public bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
queue.Enqueue(elem);
}
return true;
}
public bool Any() { return queue.Any() || Read(); }
bool Read() {
if (!SetText(sr.ReadLine()))
return false;
if (!queue.Any())
return Read();
return queue.Any();
}
public string Next() {
if (!queue.Any() && !Read()) {
return "";
}
return queue.Dequeue();
}
bool Accumulate(int n) {
while (queue.Count() < n) {
if (!Read())
return false;
}
return true;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) {
if (!Accumulate(n))
return null;
var a = new T[n];
for (int i = 0; i < n; i++)
a[i] = add(parse(queue.Dequeue()), offset);
return a;
}
public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); }
public int[] NextInt(int n, int offset = 0) {
return NextT(n, offset, int.Parse, (x, y) => x + y);
}
public long[] NextLong(int n, long offset = 0) {
return NextT(n, offset, long.Parse, (x, y) => x + y);
}
public double[] NextDouble(int n, double offset = 0.0) {
return NextT(n, offset, double.Parse, (x, y) => x + y);
}
}
static Input input;
static int Int() { return input.NextInt(); }
static long Long() { return input.NextLong(); }
static double Double() { return input.NextDouble(); }
static string Text() { return input.Next(); }
static void wl(object obj = null) { Console.WriteLine(obj); }
static void w(object obj) { Console.Write(obj); }
static void Yes() { wl("YES"); }
static void No() { wl("NO"); }
static void Sum() { wl(sum); }
static void Cnt() { wl(cnt); }
static void SetArray(long num = -1) {
if (n == 0) {
n = Int();
}
arr = new long[n];
for (int i = 0; i < n; i++) {
if (num == -1)
arr[i] = Int();
else
arr[i] = num;
}
}
static void ShowArray() {
for (int i = 0; i < arr.Length; i++) {
if (i > 0)
w(" ");
w(arr[i]);
}
wl();
}
static void SetMap(char def = '@') {
if (r == 0 && c == 0) {
r = Int();
c = Int();
}
map = new char[r, c];
for (int i = 0; i < r; i++) {
if (def == '@')
s = Text();
for (int j = 0; j < c; j++) {
map[i, j] = (def == '@') ? s[j] : def;
}
}
}
static void SetIMap(long def = -1) {
if (r == 0 && c == 0) {
r = Int();
c = Int();
}
imap = new long[r, c];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
imap[i, j] = (def == -1) ? Int() : def;
}
}
}
static void ShowMap() {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
w(map[i, j]);
}
wl();
}
}
static void ShowIMap() {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
w(imap[i, j]);
}
wl();
}
}
#endregion
#region main
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
input = new Input();
Solve();
Console.Out.Flush();
}
class d {
public double dp; // P座標からの距離
public double dq; // Q座標からの距離
}
public static void Solve() {
s = Text();
string t = Text();
for (int i = 0; i < s.Length; i++) {
cnt = 0;
for (int j = 0; j < t.Length; j++) {
if (i + j < s.Length && s[i + j] == t[j]) {
cnt++;
}
}
max = Math.Max(max, cnt);
}
wl(t.Length - max);
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
#region library
static int n = 0;
static int m = 0;
static int r = 0;
static int c = 0;
static int x = 0;
static int y = 0;
static string s = "";
static string[] ss;
static long sum = 0;
static long cnt = 0;
static long max = -1;
static long min = 2147483647;
static bool flg = false;
static bool flg2 = false;
static string alpha = "abcdefghijklmnopqrstuvwxyz";
static long mod = 1000000007;
static long[] arr;
static char[,] map;
static long[,] imap;
public class Input {
static readonly char[] separator = { ' ', '\r', '\n' };
readonly StreamReader sr;
readonly Queue<string> queue;
public Input(string path = "") {
queue = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
public bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
queue.Enqueue(elem);
}
return true;
}
public bool Any() { return queue.Any() || Read(); }
bool Read() {
if (!SetText(sr.ReadLine()))
return false;
if (!queue.Any())
return Read();
return queue.Any();
}
public string Next() {
if (!queue.Any() && !Read()) {
return "";
}
return queue.Dequeue();
}
bool Accumulate(int n) {
while (queue.Count() < n) {
if (!Read())
return false;
}
return true;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) {
if (!Accumulate(n))
return null;
var a = new T[n];
for (int i = 0; i < n; i++)
a[i] = add(parse(queue.Dequeue()), offset);
return a;
}
public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); }
public int[] NextInt(int n, int offset = 0) {
return NextT(n, offset, int.Parse, (x, y) => x + y);
}
public long[] NextLong(int n, long offset = 0) {
return NextT(n, offset, long.Parse, (x, y) => x + y);
}
public double[] NextDouble(int n, double offset = 0.0) {
return NextT(n, offset, double.Parse, (x, y) => x + y);
}
}
static Input input;
static int Int() { return input.NextInt(); }
static long Long() { return input.NextLong(); }
static double Double() { return input.NextDouble(); }
static string Text() { return input.Next(); }
static void wl(object obj = null) { Console.WriteLine(obj); }
static void w(object obj) { Console.Write(obj); }
static void Yes() { wl("YES"); }
static void No() { wl("NO"); }
static void Sum() { wl(sum); }
static void Cnt() { wl(cnt); }
static void SetArray(long num = -1) {
if (n == 0) {
n = Int();
}
arr = new long[n];
for (int i = 0; i < n; i++) {
if (num == -1)
arr[i] = Int();
else
arr[i] = num;
}
}
static void ShowArray() {
for (int i = 0; i < arr.Length; i++) {
if (i > 0)
w(" ");
w(arr[i]);
}
wl();
}
static void SetMap(char def = '@') {
if (r == 0 && c == 0) {
r = Int();
c = Int();
}
map = new char[r, c];
for (int i = 0; i < r; i++) {
if (def == '@')
s = Text();
for (int j = 0; j < c; j++) {
map[i, j] = (def == '@') ? s[j] : def;
}
}
}
static void SetIMap(long def = -1) {
if (r == 0 && c == 0) {
r = Int();
c = Int();
}
imap = new long[r, c];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
imap[i, j] = (def == -1) ? Int() : def;
}
}
}
static void ShowMap() {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
w(map[i, j]);
}
wl();
}
}
static void ShowIMap() {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
w(imap[i, j]);
}
wl();
}
}
#endregion
#region main
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
input = new Input();
Solve();
Console.Out.Flush();
}
public static void Solve() {
s = Text();
string t = Text();
for (int i = 0; i < s.Length - t.Length + 1; i++) {
cnt = 0;
for (int j = 0; j < t.Length; j++) {
if (s[i + j] == t[j]) {
cnt++;
}
}
max = Math.Max(max, cnt);
}
wl(t.Length - max);
}
#endregion
}
|
[["-", 0, 208, 0, 235, 8, 201, 0, 235, 0, 269], ["-", 0, 208, 0, 235, 8, 201, 0, 235, 141, 22], ["-", 0, 235, 8, 201, 0, 235, 8, 201, 0, 45], ["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 259], ["-", 0, 235, 8, 201, 0, 235, 8, 201, 0, 46], ["-", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 15, 16, 12, 16, 31, 16, 31, 214, 0, 131], ["+", 15, 16, 12, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 15, 16, 12, 16, 31, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 72], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 0, 57, 15, 16, 31, 16, 12, 214, 205, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 16, 12, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 1,502
| 26
|
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Linq;
class TEST {
public static void Main() {
string S = Console.ReadLine();
string T = Console.ReadLine();
Console.WriteLine(T.Length - Atteru(T, S));
// Console.ReadKey();
}
static int Atteru(string t, string s) {
int bestcount = -1;
// int pointer=0;
for (int i = 0; i < s.Length - t.Length; i++) {
int count = 0;
for (int j = 0; j < t.Length; j++) {
if (s[i + j] == t[j]) {
count++;
}
}
if (bestcount < count)
bestcount = count;
}
return bestcount;
}
}
|
using System;
class TEST {
public static void Main() {
string S = Console.ReadLine();
string T = Console.ReadLine();
Console.WriteLine(T.Length - Atteru(T, S));
// Console.ReadKey();
}
static int Atteru(string t, string s) {
int bestcount = -1;
// int pointer=0;
for (int i = 0; i < s.Length - t.Length + 1; i++) {
int count = 0;
for (int j = 0; j < t.Length; j++) {
if (s[i + j] == t[j]) {
count++;
}
}
if (bestcount < count)
bestcount = count;
}
return bestcount;
}
}
|
[["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 165
| 21
|
using static System.Math;
using System;
public class Hello {
public static void Main() {
var s = Console.ReadLine().Trim();
var t = Console.ReadLine().Trim();
var sL = s.Length;
var tL = t.Length;
var ans = int.MaxValue;
for (int i = 0; i < sL - tL; i++) {
var w = s.Substring(i, tL);
ans = Min(ans, check(w, t));
}
Console.WriteLine(ans);
}
static int check(string a, string b) {
var aL = a.Length;
var res = 0;
for (int i = 0; i < aL; i++)
if (a[i] != b[i])
res++;
return res;
}
}
|
using static System.Math;
using System;
public class Hello {
public static void Main() {
var s = Console.ReadLine().Trim();
var t = Console.ReadLine().Trim();
var sL = s.Length;
var tL = t.Length;
var ans = int.MaxValue;
for (int i = 0; i <= sL - tL; i++) {
var w = s.Substring(i, tL);
ans = Min(ans, check(w, t, tL));
}
Console.WriteLine(ans);
}
static int check(string a, string b, int c) {
var res = 0;
for (int i = 0; i < c; i++)
if (a[i] != b[i])
res++;
return res;
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 176
| 16
|
using System;
namespace Atc_0008 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
string T = Console.ReadLine();
if (S.Contains(T)) {
Console.WriteLine(0);
return;
}
int count = 0;
int result = T.Length;
for (int i = 0; i < (S.Length - T.Length); i++) {
count = 0;
for (int j = 0; j < T.Length; j++) {
if (S.Substring(i + j, 1) != T.Substring(j, 1)) {
count++;
}
}
if (count < result) {
result = count;
}
if (count == 1) {
break;
}
}
Console.WriteLine(result);
}
}
}
|
using System;
namespace Atc_0008 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
string T = Console.ReadLine();
if (S.Contains(T)) {
Console.WriteLine(0);
return;
}
int count = 0;
int result = T.Length;
int num = (S.Length - T.Length + 1);
for (int i = 0; i < num; i++) {
count = 0;
for (int j = 0; j < T.Length; j++) {
if (S.Substring(i + j, 1) != T.Substring(j, 1)) {
count++;
}
}
if (count < result) {
result = count;
}
if (count == 1) {
break;
}
}
Console.WriteLine(result);
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 174
| 21
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
string t = Console.ReadLine();
char[] ss = s.ToCharArray();
char[] tt = t.ToCharArray();
int r = tt.Length;
for (int i = 0; i < ss.Length; i++) {
int rr = tt.Length;
for (int j = 0; j < tt.Length; j++) {
if (i + j < ss.Length) {
if (ss[i + j] == tt[j]) {
rr--;
}
}
}
if (rr < r) {
r = rr;
}
}
Console.WriteLine(r);
}
}
|
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
string t = Console.ReadLine();
char[] ss = s.ToCharArray();
char[] tt = t.ToCharArray();
int r = int.MaxValue;
for (int i = 0; i < ss.Length; i++) {
int rr = tt.Length;
for (int j = 0; j < tt.Length; j++) {
if (i + j < ss.Length) {
if (ss[i + j] == tt[j]) {
rr--;
}
} else {
rr = int.MaxValue;
}
}
if (rr < r) {
r = rr;
}
}
Console.WriteLine(r);
}
}
|
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 214, 205, 199], ["+", 75, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 165
| 23
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = ReadInt();
long[] a = ReadLongArray();
long ans = 0;
long mod = (long)Math.Pow(10, 9) + 7;
long sum = a.Sum();
for (int i = 0; i < n; i++) {
sum -= a[i];
if (sum < 0)
sum += mod;
ans += a[i] * sum;
ans %= mod;
}
Console.WriteLine(ans);
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
static int[] ReadIntArray() {
return ReadStringArray().Select(i => int.Parse(i)).ToArray();
}
static long[] ReadLongArray() {
return ReadStringArray().Select(i => long.Parse(i)).ToArray();
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = ReadInt();
long[] a = ReadLongArray();
long ans = 0;
long mod = (long)Math.Pow(10, 9) + 7;
long sum = 0;
for (int i = 0; i < a.Length; i++) {
sum += a[i];
sum %= mod;
}
for (int i = 0; i < n; i++) {
sum -= a[i];
if (sum < 0)
sum += mod;
ans += a[i] * sum;
ans %= mod;
}
Console.WriteLine(ans);
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
static int[] ReadIntArray() {
return ReadStringArray().Select(i => int.Parse(i)).ToArray();
}
static long[] ReadLongArray() {
return ReadStringArray().Select(i => long.Parse(i)).ToArray();
}
}
|
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 225
| 29
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC177 {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var input = Console.ReadLine().Split(' ').ToList();
List<long> A = new List<long>();
long tmp = 0;
long mod = (long)(Math.Pow(10, 9) + 7);
for (int i = 0; i < N; i++) {
A.Add(long.Parse(input[i]));
tmp += A[i];
tmp %= mod;
}
long sum = 0;
for (int i = 0; i < N; i++) {
tmp -= A[i];
if (tmp < 0)
sum += mod;
sum += A[i] * tmp;
sum %= mod;
}
System.Console.WriteLine(sum);
Console.ReadLine();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC177 {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var input = Console.ReadLine().Split(' ').ToList();
List<long> A = new List<long>();
long tmp = 0;
long mod = (long)(Math.Pow(10, 9) + 7);
for (int i = 0; i < N; i++) {
A.Add(long.Parse(input[i]));
tmp += A[i];
}
long sum = 0;
for (int i = 0; i < N; i++) {
tmp -= A[i];
long a = tmp % mod;
sum += A[i] * a;
sum %= mod;
}
System.Console.WriteLine(sum);
Console.ReadLine();
}
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 214
| 17
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace atcoder {
public class Program {
public static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var buffer = Console.ReadLine().Split();
var A = new List<long>();
foreach (var v in buffer)
A.Add(long.Parse(v));
var list = new List<long>();
list.Add(0);
for (int i = 0; i < N; i++)
list.Add(list[i] + A[i]);
long ans = 0;
for (int i = 0; i < N; i++) {
ans += A[i] * (list[N] - list[i + 1]) % 1000000007;
}
Console.WriteLine(ans % 1000000007);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace atcoder {
public class Program {
public static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var buffer = Console.ReadLine().Split();
var A = new List<long>();
foreach (var v in buffer)
A.Add(long.Parse(v));
var list = new List<long>();
list.Add(0);
for (int i = 0; i < N; i++)
list.Add(list[i] + A[i]);
long ans = 0;
for (int i = 0; i < N; i++) {
ans += A[i] * ((list[N] - list[i + 1]) % 1000000007);
ans %= 1000000007;
}
Console.WriteLine(ans);
}
}
}
|
[["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 198
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc177_c {
class Program {
static void Main(string[] args) {
var N = CIn.ReadLong();
var A = CIn.ReadIntArray(N);
var sum = new long[N + 1];
var sum2 = 0l;
for (var i = N; i >= 1; i--) {
sum[i - 1] = sum[i] + A[i - 1] % ((int)1e9 + 7);
sum2 = (sum2 + A[i - 1] * sum[i]) % ((int)1e9 + 7);
}
Console.WriteLine(sum2);
}
}
class CIn {
private static readonly Queue<string> fieldBuffer = new Queue<string>();
public static string Read() {
if (fieldBuffer.Count == 0) {
foreach (var field in Console.ReadLine().Split()) {
fieldBuffer.Enqueue(field);
}
};
return fieldBuffer.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static string[] ReadStringArray(long n) {
var array = new string[n];
for (var i = 0; i < n; i++) {
array[i] = Read();
}
return array;
}
public static int[] ReadIntArray(long n) {
var array = new int[n];
for (var i = 0; i < n; i++) {
array[i] = ReadInt();
}
return array;
}
public static long[] ReadLongArray(long n) {
var array = new long[n];
for (var i = 0; i < n; i++) {
array[i] = ReadLong();
}
return array;
}
public static double[] ReadDoubleArray(long n) {
var array = new double[n];
for (var i = 0; i < n; i++) {
array[i] = ReadDouble();
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc177_c {
class Program {
static void Main(string[] args) {
var N = CIn.ReadLong();
var A = CIn.ReadIntArray(N);
var sum = new long[N + 1];
var sum2 = 0l;
for (var i = N; i >= 1; i--) {
sum[i - 1] = sum[i] % ((int)1e9 + 7) + A[i - 1] % ((int)1e9 + 7);
sum2 = (sum2 + A[i - 1] * sum[i] % ((int)1e9 + 7)) % ((int)1e9 + 7);
}
Console.WriteLine(sum2);
}
}
class CIn {
private static readonly Queue<string> fieldBuffer = new Queue<string>();
public static string Read() {
if (fieldBuffer.Count == 0) {
foreach (var field in Console.ReadLine().Split()) {
fieldBuffer.Enqueue(field);
}
};
return fieldBuffer.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static string[] ReadStringArray(long n) {
var array = new string[n];
for (var i = 0; i < n; i++) {
array[i] = Read();
}
return array;
}
public static int[] ReadIntArray(long n) {
var array = new int[n];
for (var i = 0; i < n; i++) {
array[i] = ReadInt();
}
return array;
}
public static long[] ReadLongArray(long n) {
var array = new long[n];
for (var i = 0; i < n; i++) {
array[i] = ReadLong();
}
return array;
}
public static double[] ReadDoubleArray(long n) {
var array = new double[n];
for (var i = 0; i < n; i++) {
array[i] = ReadDouble();
}
return array;
}
}
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 109], ["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 23, 0, 16, 31, 74, 0, 24], ["+", 31, 16, 12, 23, 0, 16, 31, 74, 39, 199], ["+", 31, 16, 12, 23, 0, 16, 31, 74, 0, 25], ["+", 31, 16, 12, 23, 0, 16, 31, 74, 51, 250], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 25], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 16, 12, 23, 0, 24], ["+", 12, 16, 12, 23, 0, 16, 31, 74, 0, 24], ["+", 12, 16, 12, 23, 0, 16, 31, 74, 39, 199], ["+", 12, 16, 12, 23, 0, 16, 31, 74, 0, 25], ["+", 12, 16, 12, 23, 0, 16, 31, 74, 51, 250], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 23, 0, 16, 12, 16, 12, 23, 0, 25]]
| 8
| 474
| 18
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.