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.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var L = sc.ReadInt();
var R = sc.ReadInt();
if (R - L >= 2019) {
Console.WriteLine(0);
} else {
var ans = int.MaxValue;
for (int i = L; i < R; i++) {
for (int j = i + 1; j <= R; j++) {
ans = Math.Min(ans, (i * j) % 2019);
}
}
Console.WriteLine(ans);
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var L = sc.ReadInt();
var R = sc.ReadInt();
if (R - L >= 2019) {
Console.WriteLine(0);
} else {
var ans = long.MaxValue;
for (long i = L; i < R; i++) {
for (long j = i + 1; j <= R; j++) {
ans = Math.Min(ans, (i * j) % 2019);
}
}
Console.WriteLine(ans);
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 1,158
| 6
|
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 Atcoder {
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 int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
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.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
public static List<Pair>[
,
] pairs;
public static int[,] ans;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long l = scan.Long();
long r = scan.Long();
long min = 2020;
if (r - l >= 2018) {
Console.WriteLine(0);
} else {
for (long i = l; i <= r; i++) {
for (long j = l + 1; j <= r; j++) {
long m = i * j % 2019;
min = Math.Min(min, m);
}
}
Console.WriteLine(min);
}
}
static int[] Togo;
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 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;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
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;
}
}
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 char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = 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) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
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) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
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) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
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();
}
}
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) { this.num = num; }
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.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 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 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];
}
}
}
|
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 Atcoder {
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 int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
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.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
public static List<Pair>[
,
] pairs;
public static int[,] ans;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long l = scan.Long();
long r = scan.Long();
long min = 2020;
if (r - l >= 2018) {
Console.WriteLine(0);
} else {
for (long i = l; i <= r; i++) {
for (long j = i + 1; j <= r; j++) {
long m = i * j % 2019;
min = Math.Min(min, m);
}
}
Console.WriteLine(min);
}
}
static int[] Togo;
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 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;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
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;
}
}
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 char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = 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) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
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) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
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) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
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();
}
}
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) { this.num = num; }
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.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 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 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];
}
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22]]
| 8
| 9,613
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static void Main(string[] args) {
try {
Solve.Answer();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var LR = IO_ShortCut.ReadSplitLong;
var L = LR[0];
var R = LR[1];
R = Min(R, L + 2018);
long ans = 2018;
for (var i = L; i <= R; i++) {
for (var j = L; j <= R; j++) {
long x = i * j % 2019;
ans = Min(x, ans);
}
}
WriteLine(ans);
}
}
public class IO_ShortCut {
#region Input
public static string ReadString => ReadLine();
public static int ReadInt => int.Parse(ReadLine());
public static long ReadLong => long.Parse(ReadLine());
public static double ReadDouble => double.Parse(ReadLine());
public static List<string> ReadSplitString => ReadLine().Split().ToList();
public static List<int> ReadSplitInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToList();
public static List<long> ReadSplitLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToList();
public static List<double> ReadSplitdouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToList();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
#endregion
}
/// <summary>
/// 正の数の四則演算のみ対応
/// </summary>
public class Mod {
// 割る数の定義
private readonly static long M = 1000000007;
// 足し算
public static long Add(long a, long b) => (a * b) % M;
// 引き算
public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M
: (a - b) % M + M;
// 掛け算
public static long Multi(long a, long b) => (a * b) % M;
}
public class MathLib {}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static void Main(string[] args) {
try {
Solve.Answer();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var LR = IO_ShortCut.ReadSplitLong;
var L = LR[0];
var R = LR[1];
R = Min(R, L + 2019);
long ans = 2018;
for (var i = L; i <= R - 1; i++) {
for (var j = i + 1; j <= R; j++) {
long x = i * j % 2019;
ans = Min(x, ans);
}
}
WriteLine(ans);
}
}
public class IO_ShortCut {
#region Input
public static string ReadString => ReadLine();
public static int ReadInt => int.Parse(ReadLine());
public static long ReadLong => long.Parse(ReadLine());
public static double ReadDouble => double.Parse(ReadLine());
public static List<string> ReadSplitString => ReadLine().Split().ToList();
public static List<int> ReadSplitInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToList();
public static List<long> ReadSplitLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToList();
public static List<double> ReadSplitdouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToList();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
#endregion
}
/// <summary>
/// 正の数の四則演算のみ対応
/// </summary>
public class Mod {
// 割る数の定義
private readonly static long M = 1000000007;
// 足し算
public static long Add(long a, long b) => (a * b) % M;
// 引き算
public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M
: (a - b) % M + M;
// 掛け算
public static long Multi(long a, long b) => (a * b) % M;
}
public class MathLib {}
}
|
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 516
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static _20200227.Cin;
using static _20200227.Util;
using Pair = _20200227.VTuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using System.Text;
namespace _20200227 {
public class Program {
public static void Main(string[] args) {
// Abc089_B(); 4m
// Arc090_A(); 10m
Abc133_C();
}
public static void Abc133_C() {
long L = rl;
long R = rl;
if (R - L >= 2019) {
Console.WriteLine(0);
} else {
long min = INF;
for (int l = (int)L; l < R; l++) {
for (int r = l + 1; r <= R; r++) {
ChMin(ref min, (l % 2019 * r % 2019) % 2019);
}
}
Console.WriteLine(min);
}
}
public static void Arc090_A() {
long N = rl;
long[] A = rla;
long[] B = rla;
A = Accumulate(A);
B = Accumulate(B);
long max = 0;
for (int i = 1; i <= N; i++) {
ChMax(ref max, A[i] + B[N] - B[i - 1]);
}
Console.WriteLine(max);
}
public static void Abc089_B() {
long N = rl;
HashSet<string> hs = new HashSet<string>();
for (int i = 0; i < N; i++) {
hs.Add(rs);
}
if (hs.Count == 3) {
Console.WriteLine("Three");
} else {
Console.WriteLine("Four");
}
}
}
public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>,
IEquatable<VTuple<T1, T2>> {
public T1 First;
public T2 Second;
public VTuple(T1 a, T2 b) {
First = a;
Second = b;
}
public int CompareTo(VTuple<T1, T2> a) {
int b = Comparer<T1>.Default.Compare(First, a.First);
if (b != 0)
return b;
return Comparer<T2>.Default.Compare(Second, a.Second);
}
public override bool Equals(object a) {
return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a);
}
public bool Equals(VTuple<T1, T2> a) {
return EqualityComparer<T1>.Default.Equals(First, a.First) &&
EqualityComparer<T2>.Default.Equals(Second, a.Second);
}
public override int GetHashCode() {
int a = First != null ? First.GetHashCode() : 0;
int b = Second != null ? Second.GetHashCode() : 0;
uint c = ((uint)a << 5) | ((uint)a >> 27);
return ((int)c + a) ^ b;
}
}
public class HashMap<K, V> : Dictionary<K, V> {
V i;
static Func<V> j =
System.Linq.Expressions.Expression
.Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V)))
.Compile();
public HashMap() {}
public HashMap(V a) { i = a; }
new public V this[K a] { get { V b;
if (TryGetValue(a, out b))
return b;
else
return base[a] = i != null ? i : j();
}
set { base[a] = value; }
}
}
public static class Util {
public static readonly long INF = (long)1e17;
public readonly static long MOD = (long)1e9 + 7;
public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 };
public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 };
public static void DontAutoFlush() {
var a = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(a);
}
public static void Flush() { Console.Out.Flush(); }
public static T[] Sort<T>(T[] a) {
Array.Sort<T>(a);
return a;
}
public static T[] SortDecend<T>(T[] a) {
Array.Sort<T>(a);
Array.Reverse(a);
return a;
}
public static void Swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); }
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static long ModAdd(long a, long b) {
long c = a + b;
if (c >= MOD)
return c % MOD;
return c;
}
public static long ModMul(long a, long b) {
long c = a * b;
if (c >= MOD)
return c % MOD;
return c;
}
public static void ChModAdd(ref long a, long b) {
a += b;
if (a >= MOD)
a %= MOD;
}
public static void ChModMul(ref long a, long b) {
a *= b;
if (a >= MOD)
a %= MOD;
}
public static void FillArray<T>(T[] a, T b) {
int c = a.Length;
for (int d = 0; d < c; d++)
a[d] = b;
}
public static void FillArray<T>(T[,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
for (int e = 0; e < c; e++)
for (int f = 0; f < d; f++) {
a[e, f] = b;
}
}
public static void FillArray<T>(T[,,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
int e = a.GetLength(2);
for (int f = 0; f < c; f++)
for (int g = 0; g < d; g++) {
for (int h = 0; h < e; h++) {
a[f, g, h] = b;
}
}
}
public static long[] Accumulate(long[] a) {
long[] b = new long[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
public static double[] Accumulate(double[] a) {
double[] b = new double[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
}
public static class Cin {
public static long rl {
get { return ReadLong(); }
}
public static long[] rla {
get { return ReadLongArray(); }
}
public static double rd {
get { return ReadDouble(); }
}
public static double[] rda {
get { return ReadDoubleArray(); }
}
public static string rs {
get { return ReadString(); }
}
public static int ReadInt() { return int.Parse(k()); }
public static long ReadLong() { return long.Parse(k()); }
public static double ReadDouble() { return double.Parse(k()); }
public static string ReadString() { return k(); }
public static int[] ReadIntArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static void ReadCols(out long[] a, out long[] b, long c) {
a = new long[c];
b = new long[c];
for (int d = 0; d < c; d++) {
a[d] = ReadLong();
b[d] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long d) {
a = new long[d];
b = new long[d];
c = new long[d];
for (int e = 0; e < d; e++) {
a[e] = ReadLong();
b[e] = ReadLong();
c[e] = ReadLong();
}
}
public static int[][] ReadIntTable(int a) {
i = null;
int[][] b = new int [a][];
for (int c = 0; c < a; c++)
b[c] = ReadIntArray();
return b;
}
public static long[][] ReadLongTable(long a) {
i = null;
long[][] b = new long [a][];
for (long c = 0; c < a; c++)
b[c] = ReadLongArray();
return b;
}
static string[] i { get; set; }
static int j { get; set; }
static string k() {
if (i == null || i.Length <= j) {
i = Console.ReadLine().Split(' ');
j = 0;
}
return i[j++];
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static _20200227.Cin;
using static _20200227.Util;
using Pair = _20200227.VTuple<long, long>;
using Graph =
System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using System.Text;
namespace _20200227 {
public class Program {
public static void Main(string[] args) {
// Abc089_B(); 4m
// Arc090_A(); 10m
Abc133_C();
}
public static void Abc133_C() {
long L = rl;
long R = rl;
if (R - L >= 2019) {
Console.WriteLine(0);
} else {
long min = INF;
for (int l = (int)L; l < R; l++) {
for (int r = l + 1; r <= R; r++) {
ChMin(ref min, ((l % 2019) * (r % 2019)) % 2019);
}
}
Console.WriteLine(min);
}
}
public static void Arc090_A() {
long N = rl;
long[] A = rla;
long[] B = rla;
A = Accumulate(A);
B = Accumulate(B);
long max = 0;
for (int i = 1; i <= N; i++) {
ChMax(ref max, A[i] + B[N] - B[i - 1]);
}
Console.WriteLine(max);
}
public static void Abc089_B() {
long N = rl;
HashSet<string> hs = new HashSet<string>();
for (int i = 0; i < N; i++) {
hs.Add(rs);
}
if (hs.Count == 3) {
Console.WriteLine("Three");
} else {
Console.WriteLine("Four");
}
}
}
public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>,
IEquatable<VTuple<T1, T2>> {
public T1 First;
public T2 Second;
public VTuple(T1 a, T2 b) {
First = a;
Second = b;
}
public int CompareTo(VTuple<T1, T2> a) {
int b = Comparer<T1>.Default.Compare(First, a.First);
if (b != 0)
return b;
return Comparer<T2>.Default.Compare(Second, a.Second);
}
public override bool Equals(object a) {
return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a);
}
public bool Equals(VTuple<T1, T2> a) {
return EqualityComparer<T1>.Default.Equals(First, a.First) &&
EqualityComparer<T2>.Default.Equals(Second, a.Second);
}
public override int GetHashCode() {
int a = First != null ? First.GetHashCode() : 0;
int b = Second != null ? Second.GetHashCode() : 0;
uint c = ((uint)a << 5) | ((uint)a >> 27);
return ((int)c + a) ^ b;
}
}
public class HashMap<K, V> : Dictionary<K, V> {
V i;
static Func<V> j =
System.Linq.Expressions.Expression
.Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V)))
.Compile();
public HashMap() {}
public HashMap(V a) { i = a; }
new public V this[K a] { get { V b;
if (TryGetValue(a, out b))
return b;
else
return base[a] = i != null ? i : j();
}
set { base[a] = value; }
}
}
public static class Util {
public static readonly long INF = (long)1e17;
public readonly static long MOD = (long)1e9 + 7;
public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 };
public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 };
public static void DontAutoFlush() {
var a = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(a);
}
public static void Flush() { Console.Out.Flush(); }
public static T[] Sort<T>(T[] a) {
Array.Sort<T>(a);
return a;
}
public static T[] SortDecend<T>(T[] a) {
Array.Sort<T>(a);
Array.Reverse(a);
return a;
}
public static void Swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); }
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static long ModAdd(long a, long b) {
long c = a + b;
if (c >= MOD)
return c % MOD;
return c;
}
public static long ModMul(long a, long b) {
long c = a * b;
if (c >= MOD)
return c % MOD;
return c;
}
public static void ChModAdd(ref long a, long b) {
a += b;
if (a >= MOD)
a %= MOD;
}
public static void ChModMul(ref long a, long b) {
a *= b;
if (a >= MOD)
a %= MOD;
}
public static void FillArray<T>(T[] a, T b) {
int c = a.Length;
for (int d = 0; d < c; d++)
a[d] = b;
}
public static void FillArray<T>(T[,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
for (int e = 0; e < c; e++)
for (int f = 0; f < d; f++) {
a[e, f] = b;
}
}
public static void FillArray<T>(T[,,] a, T b) {
int c = a.GetLength(0);
int d = a.GetLength(1);
int e = a.GetLength(2);
for (int f = 0; f < c; f++)
for (int g = 0; g < d; g++) {
for (int h = 0; h < e; h++) {
a[f, g, h] = b;
}
}
}
public static long[] Accumulate(long[] a) {
long[] b = new long[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
public static double[] Accumulate(double[] a) {
double[] b = new double[a.Length + 1];
for (int c = 0; c < a.Length; c++)
b[c + 1] = b[c] + a[c];
return b;
}
}
public static class Cin {
public static long rl {
get { return ReadLong(); }
}
public static long[] rla {
get { return ReadLongArray(); }
}
public static double rd {
get { return ReadDouble(); }
}
public static double[] rda {
get { return ReadDoubleArray(); }
}
public static string rs {
get { return ReadString(); }
}
public static int ReadInt() { return int.Parse(k()); }
public static long ReadLong() { return long.Parse(k()); }
public static double ReadDouble() { return double.Parse(k()); }
public static string ReadString() { return k(); }
public static int[] ReadIntArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
i = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static void ReadCols(out long[] a, out long[] b, long c) {
a = new long[c];
b = new long[c];
for (int d = 0; d < c; d++) {
a[d] = ReadLong();
b[d] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long d) {
a = new long[d];
b = new long[d];
c = new long[d];
for (int e = 0; e < d; e++) {
a[e] = ReadLong();
b[e] = ReadLong();
c[e] = ReadLong();
}
}
public static int[][] ReadIntTable(int a) {
i = null;
int[][] b = new int [a][];
for (int c = 0; c < a; c++)
b[c] = ReadIntArray();
return b;
}
public static long[][] ReadLongTable(long a) {
i = null;
long[][] b = new long [a][];
for (long c = 0; c < a; c++)
b[c] = ReadLongArray();
return b;
}
static string[] i { get; set; }
static int j { get; set; }
static string k() {
if (i == null || i.Length <= j) {
i = Console.ReadLine().Split(' ');
j = 0;
}
return i[j++];
}
}
}
|
[["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
| 8
| 2,190
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]C - Remainder Minimization 2019
var line = ReadLine();
var L = line[0];
var R = line[1];
var remainders = new List<long>();
int count = 0;
for (long i = L; i <= R; i++) {
var remainder = i % 2019;
remainders.Add(remainder);
count++;
if (count == 2019) {
break;
}
}
var lib = new Library.Combination();
var combis = lib.AllCombinations<long>(remainders, 2);
long min = long.MaxValue;
foreach (var c in combis) {
long m = c[0] * c[1];
min = Math.Min(min, m);
}
Console.WriteLine(min);
}
static List<long> ReadLine() {
var line = Console.ReadLine();
var arr = line.Split(' ');
return arr.Select(x => long.Parse(x)).ToList();
}
}
}
namespace Library {
class Combination {
public IEnumerable<List<T>>
AllCombinations<T>(List<T> source, int n, bool isAllowDupication = false) {
//[summary]異なる要素から、n個を選ぶ組み合わせを列挙する
//"isAllowDupication"を"true"にすると、重複を許可する
//(重複を許可して、nを要素数と同じにすると、順列を列挙する)
if (n == 1) {
foreach (var s in source) {
yield return new List<T> { s };
}
yield break;
} else {
for (int i = 0; i < source.Count; i++) {
List<T> clone;
if (isAllowDupication) {
//重複を許可する場合は、その要素のみを削除
clone = new List<T>(source);
clone.RemoveAt(i);
} else {
//重複を許可しない場合は、自分よりも前の要素はすべて削除
clone = new List<T>(source.Skip(i + 1));
}
//再帰処理
var items = AllCombinations(clone, n - 1, isAllowDupication);
foreach (var item in items) {
item.Insert(0, source[i]);
yield return item;
}
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]C - Remainder Minimization 2019
var line = ReadLine();
var L = line[0];
var R = line[1];
var remainders = new List<long>();
int count = 0;
for (long i = L; i <= R; i++) {
var remainder = i % 2019;
remainders.Add(remainder);
count++;
if (count == 2019) {
break;
}
}
var lib = new Library.Combination();
var combis = lib.AllCombinations<long>(remainders, 2);
long min = long.MaxValue;
foreach (var c in combis) {
long m = c[0] * c[1];
min = Math.Min(min, m % 2019);
}
Console.WriteLine(min);
}
static List<long> ReadLine() {
var line = Console.ReadLine();
var arr = line.Split(' ');
return arr.Select(x => long.Parse(x)).ToList();
}
}
}
namespace Library {
class Combination {
public IEnumerable<List<T>>
AllCombinations<T>(List<T> source, int n, bool isAllowDupication = false) {
//[summary]異なる要素から、n個を選ぶ組み合わせを列挙する
//"isAllowDupication"を"true"にすると、重複を許可する
//(重複を許可して、nを要素数と同じにすると、順列を列挙する)
if (n == 1) {
foreach (var s in source) {
yield return new List<T> { s };
}
yield break;
} else {
for (int i = 0; i < source.Count; i++) {
List<T> clone;
if (isAllowDupication) {
//重複を許可する場合は、その要素のみを削除
clone = new List<T>(source);
clone.RemoveAt(i);
} else {
//重複を許可しない場合は、自分よりも前の要素はすべて削除
clone = new List<T>(source.Skip(i + 1));
}
//再帰処理
var items = AllCombinations(clone, n - 1, isAllowDupication);
foreach (var item in items) {
item.Insert(0, source[i]);
yield return item;
}
}
}
}
}
}
|
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 424
| 2
|
using System;
namespace ABC133 {
class C {
static void Main(string[] args) {
long MOD = 2019;
string[] input = Console.ReadLine().Split(' ');
long L = long.Parse(input[0]);
long R = long.Parse(input[1]);
long min = MOD;
for (long i = L; i <= R - 1; i++) {
for (long j = i + 1; i <= R; i++) {
if (((i * j) % MOD) == 0) {
Console.WriteLine(0);
return;
}
if (((i * j) % MOD) < min) {
min = ((i * j) % MOD);
}
}
}
Console.WriteLine(min);
}
}
}
|
using System;
namespace ABC133 {
class C {
static void Main(string[] args) {
long MOD = 2019;
string[] input = Console.ReadLine().Split(' ');
long L = long.Parse(input[0]);
long R = long.Parse(input[1]);
long min = MOD;
for (long i = L; i <= R - 1; i++) {
for (long j = i + 1; j <= R; j++) {
if (((i * j) % MOD) == 0) {
Console.WriteLine(0);
return;
}
if (((i * j) % MOD) < min) {
min = ((i * j) % MOD);
}
}
}
Console.WriteLine(min);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22]]
| 8
| 172
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
public static void Main() {
var line =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var L = line[0];
var R = line[1];
int ans = 2020;
if (R - L > 2019) {
ans = 0;
} else {
for (int i = L; i < R; i++) {
for (int j = i + 1; j <= R; j++) {
if ((i * j) % 2019 < ans) {
ans = (i * j) % 2019;
}
}
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
public static void Main() {
var line =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var L = line[0];
var R = line[1];
long ans = 2020;
if (R - L > 2019) {
ans = 0;
} else {
for (var i = L; i < R; i++) {
for (var j = i + 1; j <= R; j++) {
if ((i * j) % 2019 < ans) {
ans = (i * j) % 2019;
}
}
}
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["+", 75, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217]]
| 8
| 162
| 8
|
using System;
using System.Linq;
class C {
static void Main() {
var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var m = int.MaxValue;
for (var i = a[0]; i < a[1]; i++)
for (var j = i + 1; j <= a[1]; j++) {
var x = i * j % 2019;
if (x == 0) {
Console.WriteLine(0);
return;
}
if (x < m)
m = x;
}
Console.WriteLine(m);
}
}
|
using System;
using System.Linq;
class C {
static void Main() {
var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var m = long.MaxValue;
for (var i = a[0]; i < a[1]; i++)
for (var j = i + 1; j <= a[1]; j++) {
var x = i * j % 2019;
if (x == 0) {
Console.WriteLine(0);
return;
}
if (x < m)
m = x;
}
Console.WriteLine(m);
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199]]
| 8
| 137
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions {
public static int ToInt(this string s) => int.Parse(s);
public static long ToLong(this string s) => long.Parse(s);
public static char ToChar(this string s) => char.Parse(s);
public static double ToDouble(this string s) => double.Parse(s);
public static int[] ToIntArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
public static long[] ToLongArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
public static double[] ToDoubleArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
public static Queue<T>
ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
public static Stack<T>
ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq);
}
static class MyMath {
static public long GCD(long a,
long b) => (a < b) ? GCD(b, a)
: ((b == 0) ? a : GCD(b, a % b));
static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b)
: (b / GCD(a, b) * a);
static private readonly long _m = 1000000000 + 7;
static public long Mod(long val) => (val % _m + _m) % _m;
static private long ExtGCD(long a, long b, ref long x, ref long y) =>
(b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0)
: (ExtGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0);
static private long ModInverseInner(long a, long dummy1 = 0,
long dummy2 = 0) =>
ExtGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1);
static public long ModInverse(long a) => ModInverseInner(a, 0, 0);
}
class Program {
static string[] ReadLines(int n) =>
Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();
static void Main() {
var lr = Console.ReadLine().ToIntArray();
int L = lr[0];
int R = lr[1];
int ans = 2018;
// iとjそれぞれせいぜい2019個見れば十分
for (int i = L; i <= Math.Min(R - 1, L + 2019); i++) {
for (int j = i + 1; j <= Math.Min(R, L + 2019); j++) {
ans = Math.Min(ans, (i * j) % 2019);
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions {
public static int ToInt(this string s) => int.Parse(s);
public static long ToLong(this string s) => long.Parse(s);
public static char ToChar(this string s) => char.Parse(s);
public static double ToDouble(this string s) => double.Parse(s);
public static int[] ToIntArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
public static long[] ToLongArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
public static double[] ToDoubleArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
public static Queue<T>
ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq);
public static Stack<T>
ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq);
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq);
}
static class MyMath {
static public long GCD(long a,
long b) => (a < b) ? GCD(b, a)
: ((b == 0) ? a : GCD(b, a % b));
static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b)
: (b / GCD(a, b) * a);
static private readonly long _m = 1000000000 + 7;
static public long Mod(long val) => (val % _m + _m) % _m;
static private long ExtGCD(long a, long b, ref long x, ref long y) =>
(b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0)
: (ExtGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0);
static private long ModInverseInner(long a, long dummy1 = 0,
long dummy2 = 0) =>
ExtGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1);
static public long ModInverse(long a) => ModInverseInner(a, 0, 0);
}
class Program {
static string[] ReadLines(int n) =>
Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();
static void Main() {
var lr = Console.ReadLine().ToIntArray();
long L = lr[0];
long R = lr[1];
long ans = 2018;
// iとjそれぞれせいぜい2019個見れば十分
for (long i = L; i <= Math.Min(R - 1, L + 2019); i++) {
for (long j = i + 1; j <= Math.Min(R, L + 2019); j++) {
ans = Math.Min(ans, (i * j) % 2019);
}
}
Console.WriteLine(ans);
}
}
|
[["-", 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], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 749
| 10
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int L = int.Parse(s[0]);
int R = int.Parse(s[1]);
if (L / 2019 != R / 2019) {
Console.WriteLine(0);
return;
}
L %= 2019;
R %= 2019;
int ans = int.MaxValue;
for (int l = L; l <= R; l++) {
for (int r = l; r <= R; r++) {
ans = Math.Min(ans, (l * r) % 2019);
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int L = int.Parse(s[0]);
int R = int.Parse(s[1]);
if (L / 2019 != R / 2019) {
Console.WriteLine(0);
return;
}
L %= 2019;
R %= 2019;
int ans = int.MaxValue;
for (int l = L; l <= R; l++) {
for (int r = l + 1; r <= R; r++) {
ans = Math.Min(ans, (l * r) % 2019);
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 180
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC133C {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var l = input[0];
var r = input[1] + 1;
var r2 = l + 2020;
var r3 = Math.Min(r, r2);
var min = 9999;
foreach (var x in Enumerable.Range(l, r3 - l))
foreach (var y in Enumerable.Range(x + 1, r3 - l - 1)) {
var result = (long)x * y % 2019;
if (min > result) {
min = (int)result;
}
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC133C {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var l = input[0];
var r = input[1] + 1;
var r2 = l + 2020;
var r3 = Math.Min(r, r2);
var min = 9999;
foreach (var x in Enumerable.Range(l, r3 - l))
foreach (var y in Enumerable.Range(x + 1, r3 - x - 1)) {
var result = (long)x * y % 2019;
if (min > result) {
// Console.WriteLine($"{x} * {y} = {(long)x * y % 2019}");
min = (int)result;
}
}
Console.WriteLine(min);
}
}
}
|
[["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
| 8
| 187
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program {
class Program {
static void Main(string[] args) {
var lr = Console.ReadLine().Split(' ');
var l = int.Parse(lr[0]);
var r = int.Parse(lr[1]);
if (r - l >= 2019) {
Console.WriteLine(0);
} else {
long minValue = long.MaxValue;
for (int i = l; i < r; i++) {
for (int j = i + 1; j <= r; j++) {
long ij = i * j;
var result = ij % 2019;
if (minValue > result) {
minValue = result;
}
}
}
Console.WriteLine(minValue);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Program {
class Program {
static void Main(string[] args) {
var lr = Console.ReadLine().Split(' ');
long l = long.Parse(lr[0]);
long r = long.Parse(lr[1]);
if (r - l >= 2019) {
Console.WriteLine(0);
} else {
long minValue = long.MaxValue;
for (var i = l; i < r; i++) {
for (var j = i + 1; j <= r; j++) {
long ij = i * j;
var result = ij % 2019;
if (minValue > result) {
minValue = result;
}
}
}
Console.WriteLine(minValue);
}
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 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, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["+", 75, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217]]
| 8
| 182
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var ss = Console.ReadLine().Split();
var L = long.Parse(ss[0]);
var R = long.Parse(ss[1]);
if (R - L >= 2019) {
Console.WriteLine(0);
return;
}
var min = long.MaxValue;
for (long i = L; i < R; i++) {
for (long j = L + 1; j <= R; j++) {
long m = ((i % 2019) * ((j + 1) % 2019)) % 2019;
if (m < min) {
min = m;
}
}
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var ss = Console.ReadLine().Split();
var L = long.Parse(ss[0]);
var R = long.Parse(ss[1]);
if (R - L >= 2019) {
Console.WriteLine(0);
return;
}
var min = long.MaxValue;
for (long i = L; i < R; i++) {
for (long j = L + 1; j <= R; j++) {
long m = ((i % 2019) * (j % 2019)) % 2019;
if (m < min) {
min = m;
}
}
}
Console.WriteLine(min);
}
}
}
|
[["-", 0, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["-", 12, 23, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 16, 12, 23, 0, 16, 31, 23, 0, 25]]
| 8
| 175
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
//
public class ABC133_C // ←Class名変更!! Program
{
public static void Main() {
var n = Rla();
var l = n[0];
var r = n[1];
var result = 2019L;
if (2019 <= (r - l)) {
WriteLine($"{result}");
return;
}
for (var i = l; i < r; i++) {
for (var j = i + 1; j <= r; j++) {
var a = (i * j) % 2019;
if (a < result) {
result = a;
}
if (result == 0) {
WriteLine($"{result}");
return;
}
}
}
WriteLine($"{result}");
return;
} // Main
public static string Rs() { return ReadLine(); }
public static char Rc() {
var c = ReadLine();
return c[0];
} //最初の1文字だけ返す
public static int Ri() { return int.Parse(ReadLine()); }
public static long Rl() { return long.Parse(ReadLine()); }
public static char[] Rca() { return ReadLine().ToCharArray(); }
public static int[] Ria() {
return Array.ConvertAll(ReadLine().Split(' '), int.Parse);
}
public static long[] Rla() {
return Array.ConvertAll(ReadLine().Split(' '), long.Parse);
}
} // Class
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
//
public class ABC133_C // ←Class名変更!! Program
{
public static void Main() {
var n = Rla();
var l = n[0];
var r = n[1];
var result = 2019L;
if (2019 <= (r - l)) {
WriteLine($"{0}");
return;
}
for (var i = l; i < r; i++) {
for (var j = i + 1; j <= r; j++) {
var a = (i * j) % 2019;
if (a < result) {
result = a;
}
if (result == 0) {
WriteLine($"{result}");
return;
}
}
}
WriteLine($"{result}");
return;
} // Main
public static string Rs() { return ReadLine(); }
public static char Rc() {
var c = ReadLine();
return c[0];
} //最初の1文字だけ返す
public static int Ri() { return int.Parse(ReadLine()); }
public static long Rl() { return long.Parse(ReadLine()); }
public static char[] Rca() { return ReadLine().ToCharArray(); }
public static int[] Ria() {
return Array.ConvertAll(ReadLine().Split(' '), int.Parse);
}
public static long[] Rla() {
return Array.ConvertAll(ReadLine().Split(' '), long.Parse);
}
} // Class
|
[["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 203]]
| 8
| 339
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ABC133C {
class Program {
static void Solve(Input input) {
var mod = 19;
var l = input.NextLong();
var r = input.NextLong();
var max1 = Math.Min(r, l + mod);
var min = int.MaxValue;
for (long i = l; i < max1; i++) {
var m = (int)((i * (i + 1)) % mod);
var h = new HashSet<int>();
var max2 = Math.Min(r - i, mod);
for (int j = 0; j < max2; j++) {
if (h.Contains(m)) {
// 一周した
break;
}
h.Add(m);
m += (int)i;
m %= mod;
}
min = Math.Min(min, h.Min());
}
Console.WriteLine(min);
}
#region Main
public static void Main(string[] args) {
// 出力が少ないときはこれをセットする方が時間かかるけれど
// その場合は出力がボトルネックになっていないので、まあ良しとする
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input();
// 仮想的に標準入力をセットする
// input.SetText("");
Solve(input);
Console.Out.Flush();
}
#endregion
#region Competitive Template
#pragma warning disable CS0414
static readonly int MOD = (int)1e9 + 7;
#pragma warning restore CS0414
class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
// スペース単独指定の方がもちろん早い
static readonly char[] separator = { ' ', '\r', '\n' };
Queue<string> q { get; set; }
StreamReader sr;
/// <summary>
/// 特定のファイルから読み出したい場合はpath指定する
/// </summary>
/// <param name="path"></param>
public Input(string path = "") {
q = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public 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>
bool read() {
var s = sr.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 string Next() {
if (!q.Any()) {
if (!read()) {
return "";
}
}
return q.Dequeue();
}
/// <summary>
/// 指定個数queueにたまるまでenqueueし続ける
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
bool accumulate(int n) {
while (q.Count() < n) {
if (!read())
return false;
}
return true;
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
/// <summary>
/// n個の要素をparseして、それぞれにoffsetをaddした配列を返す
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="n"></param>
/// <param name="offset"></param>
/// <param name="parse"></param>
/// <param name="add"></param>
/// <returns></returns>
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(q.Dequeue()), offset);
return a;
}
public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x);
public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse,
(x, y) => x + y);
public long[] NextLong(int n, long offset = 0) => NextT(n, offset,
long.Parse,
(x, y) => x + y);
public double[] NextDouble(int n, double offset = 0.0) =>
NextT(n, offset, double.Parse, (x, y) => x + y);
}
static class Utils {
public static void Print<T>(IEnumerable<T> ie, string sep = " ") =>
Console.WriteLine(string.Join(sep, ie));
public static void Print<T>(params T[] objs) => Print(objs);
public static T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
public static void Swap<T>(ref T x, ref T y)
where T : struct {
var t = x;
x = y;
y = t;
}
public static void Swap<T>(IList<T> list, int i, int j)
where T : struct {
var t = list[i];
list[i] = list[j];
list[j] = t;
}
/// <summary>
/// vでfillされたT[d1][d2]配列を作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="d1"></param>
/// <param name="d2"></param>
/// <param name="v"></param>
/// <returns></returns>
public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(v, d2).ToArray())
.ToArray();
}
/// <summary>
/// vでfillされたT[d1][d2][d3]配列を作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="d1"></param>
/// <param name="d2"></param>
/// <param name="d3"></param>
/// <param name="v"></param>
/// <returns></returns>
public static T[][][] Create3DArray<T>(int d1, int d2, int d3,
T v = default(T)) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(0, d2)
.Select(__ => Enumerable.Repeat(v, d3).ToArray())
.ToArray())
.ToArray();
}
}
#endregion
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ABC133C {
class Program {
static void Solve(Input input) {
var mod = 2019;
var l = input.NextLong();
var r = input.NextLong();
var max1 = Math.Min(r, l + mod);
var min = int.MaxValue;
for (long i = l; i < max1; i++) {
var m = (int)((i * (i + 1)) % mod);
var h = new HashSet<int>();
var max2 = Math.Min(r - i, mod);
for (int j = 0; j < max2; j++) {
if (h.Contains(m)) {
// 一周した
break;
}
h.Add(m);
m += (int)i;
m %= mod;
}
min = Math.Min(min, h.Min());
}
Console.WriteLine(min);
}
#region Main
public static void Main(string[] args) {
// 出力が少ないときはこれをセットする方が時間かかるけれど
// その場合は出力がボトルネックになっていないので、まあ良しとする
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input();
// 仮想的に標準入力をセットする
// input.SetText("");
Solve(input);
Console.Out.Flush();
}
#endregion
#region Competitive Template
#pragma warning disable CS0414
static readonly int MOD = (int)1e9 + 7;
#pragma warning restore CS0414
class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
// スペース単独指定の方がもちろん早い
static readonly char[] separator = { ' ', '\r', '\n' };
Queue<string> q { get; set; }
StreamReader sr;
/// <summary>
/// 特定のファイルから読み出したい場合はpath指定する
/// </summary>
/// <param name="path"></param>
public Input(string path = "") {
q = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public 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>
bool read() {
var s = sr.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 string Next() {
if (!q.Any()) {
if (!read()) {
return "";
}
}
return q.Dequeue();
}
/// <summary>
/// 指定個数queueにたまるまでenqueueし続ける
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
bool accumulate(int n) {
while (q.Count() < n) {
if (!read())
return false;
}
return true;
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
/// <summary>
/// n個の要素をparseして、それぞれにoffsetをaddした配列を返す
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="n"></param>
/// <param name="offset"></param>
/// <param name="parse"></param>
/// <param name="add"></param>
/// <returns></returns>
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(q.Dequeue()), offset);
return a;
}
public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x);
public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse,
(x, y) => x + y);
public long[] NextLong(int n, long offset = 0) => NextT(n, offset,
long.Parse,
(x, y) => x + y);
public double[] NextDouble(int n, double offset = 0.0) =>
NextT(n, offset, double.Parse, (x, y) => x + y);
}
static class Utils {
public static void Print<T>(IEnumerable<T> ie, string sep = " ") =>
Console.WriteLine(string.Join(sep, ie));
public static void Print<T>(params T[] objs) => Print(objs);
public static T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
public static void Swap<T>(ref T x, ref T y)
where T : struct {
var t = x;
x = y;
y = t;
}
public static void Swap<T>(IList<T> list, int i, int j)
where T : struct {
var t = list[i];
list[i] = list[j];
list[j] = t;
}
/// <summary>
/// vでfillされたT[d1][d2]配列を作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="d1"></param>
/// <param name="d2"></param>
/// <param name="v"></param>
/// <returns></returns>
public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(v, d2).ToArray())
.ToArray();
}
/// <summary>
/// vでfillされたT[d1][d2][d3]配列を作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="d1"></param>
/// <param name="d2"></param>
/// <param name="d3"></param>
/// <param name="v"></param>
/// <returns></returns>
public static T[][][] Create3DArray<T>(int d1, int d2, int d3,
T v = default(T)) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(0, d2)
.Select(__ => Enumerable.Repeat(v, d3).ToArray())
.ToArray())
.ToArray();
}
}
#endregion
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 1,304
| 2
|
using System;
namespace ConsoleApp3 {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
long l = long.Parse(input[0]);
long r = long.Parse(input[1]);
r = Math.Min(r, l + 2019);
long minMod = 2018;
for (long i = l; i < r; i++) {
for (long j = i + 1; i <= r; i++) {
long mod = (i * j) % 2019;
minMod = Math.Min(minMod, mod);
if (minMod == 0) {
break;
}
}
}
Console.WriteLine(minMod);
}
}
}
|
using System;
namespace ConsoleApp3 {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
long l = long.Parse(input[0]);
long r = long.Parse(input[1]);
r = Math.Min(r, l + 2019);
long minMod = 2018;
for (long i = l; i < r; i++) {
for (long j = i + 1; j <= r; j++) {
long mod = (i * j) % 2019;
minMod = Math.Min(minMod, mod);
if (minMod == 0) {
break;
}
}
}
Console.WriteLine(minMod);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22]]
| 8
| 155
| 4
|
using System;
class ProgramC {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int L = int.Parse(input[0]);
int R = int.Parse(input[1]);
int Lr = L % 2019;
int Rr = R % 2019;
if (R - L >= 2018)
Console.WriteLine("0");
else if (Lr < Rr)
if (Lr <= 3 && Rr >= 673)
Console.WriteLine("0");
else {
int result = 2018;
for (int i = Lr; i < Rr; i++)
for (int j = Lr + 1; j < Rr; j++) {
int test = (i * j) % 2019;
if (test <= result)
result = test;
}
Console.WriteLine(result);
}
else if (Lr > Rr)
Console.WriteLine("0");
}
}
|
using System;
class ProgramC {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int L = int.Parse(input[0]);
int R = int.Parse(input[1]);
int Lr = L % 2019;
int Rr = R % 2019;
if (R - L >= 2018)
Console.WriteLine("0");
else if (Lr < Rr)
if (Lr <= 3 && Rr >= 673)
Console.WriteLine("0");
else {
int result = 2018;
for (int i = Lr; i < Rr; i++)
for (int j = Lr + 1; j <= Rr; j++) {
int test = (i * j) % 2019;
if (test <= result)
result = test;
}
Console.WriteLine(result);
}
else if (Lr > Rr)
Console.WriteLine("0");
}
}
|
[["-", 75, 196, 0, 7, 8, 7, 15, 16, 17, 18], ["+", 75, 196, 0, 7, 8, 7, 15, 16, 17, 19]]
| 8
| 203
| 2
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class AtCoder {
const int MOD = 1000000007;
public void Slove() {
var inputs = Console.ReadLine().Split();
int ln = int.Parse(inputs[0]);
int rn = int.Parse(inputs[1]);
int count = Math.Min(2019, rn - ln + 1);
int ans = 2018;
foreach (int num in Enumerable.Range(ln, count))
foreach (int num2 in Enumerable.Range(ln, count).Skip(ln - num + 1)) {
ans = Math.Min(ans, num * num2 % 2019);
}
Console.WriteLine(ans);
}
static void Main() {
var ac = new AtCoder();
ac.Slove();
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class AtCoder {
const int MOD = 1000000007;
public void Slove() {
var inputs = Console.ReadLine().Split();
int ln = int.Parse(inputs[0]);
int rn = int.Parse(inputs[1]);
int count = Math.Min(2019, rn - ln + 1);
long ans = 2018;
foreach (int num in Enumerable.Range(ln, count - 1))
foreach (int num2 in Enumerable.Range(ln, count).Skip(ln - num + 1)) {
ans = Math.Min(ans, (long)num * num2 % 2019);
}
Console.WriteLine(ans);
}
static void Main() {
var ac = new AtCoder();
ac.Slove();
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 25]]
| 8
| 184
| 7
|
using System;
class Program {
static void Main(string[] args) {
var data = Console.ReadLine().Split(' ');
var l = int.Parse(data[0]);
var r = int.Parse(data[1]);
var min = 2019;
// l-rの間に2019の倍数が含まれている時
if (r - l > 2019) {
Console.WriteLine(0);
} else {
for (int i = l; i < r; i++) {
for (int j = i + 1; j < r + 1; j++) {
if ((i * j) % 2019 < min) {
min = (i * j) % 2019;
if (min == 0) {
break;
}
}
}
}
Console.WriteLine(min);
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
var data = Console.ReadLine().Split(' ');
var l = int.Parse(data[0]);
var r = int.Parse(data[1]);
long min = 2019;
// l-rの間に2019の倍数が含まれている時
if (r - l > 2019) {
Console.WriteLine(0);
} else {
for (long i = l; i < r; i++) {
for (long j = i + 1; j < r + 1; j++) {
if ((i * j) % 2019 < min) {
min = (i * j) % 2019;
if (min == 0) {
break;
}
}
}
}
Console.WriteLine(min);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 163
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split();
long L = long.Parse(input[0]);
long R = long.Parse(input[1]);
long ans = long.MaxValue;
for (long i = L; i <= Math.Min(R, L + 2030); i++) {
for (long j = L + 1; j <= Math.Min(R, L + 2030); j++) {
ans = Math.Min(ans, Math.Min((i * j) % 2019, (i % 2019) * (j % 2019)));
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split();
long L = long.Parse(input[0]);
long R = long.Parse(input[1]);
long ans = long.MaxValue;
for (long i = L; i <= Math.Min(R, L + 2030); i++) {
for (long j = i + 1; j <= Math.Min(R, L + 2030); j++) {
ans = Math.Min(ans, Math.Min((i * j) % 2019, (i % 2019) * (j % 2019)));
}
}
Console.WriteLine(ans);
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22]]
| 8
| 169
| 2
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
var L = int.Parse(input[0]);
var R = int.Parse(input[1]);
int ans = 2019;
for (var v = L; v < R; v++) {
for (var w = v + 1; w < R; w++) {
ans = Math.Min(ans, ((v % 2019) * (w % 2019)) % 2019);
if (ans == 0)
break;
}
if (ans == 0)
break;
}
Console.WriteLine(ans);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
var L = int.Parse(input[0]);
var R = int.Parse(input[1]);
int ans = 2019;
for (var v = L; v < R; v++) {
for (var w = v + 1; w <= R; w++) {
ans = Math.Min(ans, ((v % 2019) * (w % 2019)) % 2019);
if (ans == 0)
break;
}
if (ans == 0)
break;
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 149
| 2
|
using System;
namespace AtCoderABC133C {
class Program {
static void Main(string[] args) {
int ans = int.MaxValue;
string[] s = Console.ReadLine().Split(' ');
int L = int.Parse(s[0]);
int R = int.Parse(s[1]);
if (R - L > 674)
ans = 0;
else {
for (int i = L; i < R; i++) {
for (int j = i + 1; j <= R; j++) {
int buffer = (i % 2019) * (j % 2019);
if (ans > buffer)
ans = buffer;
}
}
}
Console.WriteLine(ans.ToString());
}
}
}
|
using System;
namespace AtCoderABC133C {
class Program {
static void Main(string[] args) {
int ans = int.MaxValue;
string[] s = Console.ReadLine().Split(' ');
int L = int.Parse(s[0]);
int R = int.Parse(s[1]);
if (R - L > 674)
ans = 0;
else {
for (int i = L; i < R; i++) {
for (int j = i + 1; j <= R; j++) {
int buffer = ((i % 2019) * (j % 2019)) % 2019;
if (ans > buffer)
ans = buffer;
}
}
}
Console.WriteLine(ans.ToString());
}
}
}
|
[["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 158
| 4
|
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder {
class Inonoa {
// なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて
static void Main() {
long[] lr = ILongs();
if (lr[1] - lr[0] >= 2019) {
Console.WriteLine(0);
return;
} else {
long l = lr[0] % 2019;
long r = lr[1] % 2019;
long ans = 2019;
if (r > l) {
for (long i = l; i <= r - 1; i++) {
for (long j = i + 1; j <= r; j++) {
if ((i * j) % 2019 < ans)
ans = i * j;
}
}
Console.WriteLine(ans);
return;
} else {
for (long i = l; i <= r - 1 + 2019; i++) {
for (long j = l + 1; j <= r + 2019; j++) {
if (i * j % 2019 < ans)
ans = i * j;
}
}
Console.WriteLine(ans);
return;
}
}
}
static readonly long MOD = 1000000007;
///< summary>a_1, a_2, a_3, ...みたいなの</summary>
static long[] ILongs() {
string[] s = ReadLine().Split();
long[] re = new long[s.Length];
for (long i = 0; i < s.Length; i++) {
re[i] = long.Parse(s[i]);
}
return re;
}
///< summary>xooxoxoxxoxo...みたいなの</summary>
static char[] IChars() { return ReadLine().ToCharArray(); }
///< summary>n m とかをちょっとはやくかくだけ</summary>
static string[] IStrings() { return ReadLine().Split(); }
///< summary>n行の入力を取ったり</summary>
static long[][] ILongLongs(long n) {
long[][] re = new long [n][];
for (long i = 0; i < n; i++) {
string[] s = ReadLine().Split();
re[i] = new long[s.Length];
for (long j = 0; j < s.Length; j++) {
re[i][j] = long.Parse(s[j]);
}
}
return re;
}
///< summary>n行の文字列を取ったり</summary>
static char[][] ICharsChars(long n) {
char[][] re = new char [n][];
for (long i = 0; i < n; i++) {
re[i] = ReadLine().ToCharArray();
}
return re;
}
}
}
|
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder {
class Inonoa {
// なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて
static void Main() {
long[] lr = ILongs();
if (lr[1] - lr[0] >= 2018) {
Console.WriteLine(0);
return;
} else {
long l = lr[0] % 2019;
long r = lr[1] % 2019;
long ans = 2019;
if (r > l) {
for (long i = l; i <= r - 1; i++) {
for (long j = i + 1; j <= r; j++) {
if ((i * j) % 2019 < ans)
ans = i * j % 2019;
}
}
Console.WriteLine(ans);
return;
} else {
for (long i = l; i <= r - 1 + 2019; i++) {
for (long j = l + 1; j <= r + 2019; j++) {
if (i * j % 2019 < ans)
ans = i * j % 2019;
}
}
Console.WriteLine(ans);
return;
}
}
}
static readonly long MOD = 1000000007;
///< summary>a_1, a_2, a_3, ...みたいなの</summary>
static long[] ILongs() {
string[] s = ReadLine().Split();
long[] re = new long[s.Length];
for (long i = 0; i < s.Length; i++) {
re[i] = long.Parse(s[i]);
}
return re;
}
///< summary>xooxoxoxxoxo...みたいなの</summary>
static char[] IChars() { return ReadLine().ToCharArray(); }
///< summary>n m とかをちょっとはやくかくだけ</summary>
static string[] IStrings() { return ReadLine().Split(); }
///< summary>n行の入力を取ったり</summary>
static long[][] ILongLongs(long n) {
long[][] re = new long [n][];
for (long i = 0; i < n; i++) {
string[] s = ReadLine().Split();
re[i] = new long[s.Length];
for (long j = 0; j < s.Length; j++) {
re[i][j] = long.Parse(s[j]);
}
}
return re;
}
///< summary>n行の文字列を取ったり</summary>
static char[][] ICharsChars(long n) {
char[][] re = new char [n][];
for (long i = 0; i < n; i++) {
re[i] = ReadLine().ToCharArray();
}
return re;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 109], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 532
| 6
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int L = int.Parse(str[0]);
int R = int.Parse(str[1]);
long mod = 2019;
long ans = 2018;
Random rnd = new System.Random();
for (var i = 0; i < 30000000; i++) {
long a1 = L + i % (R - L);
long a2 = a1 + 1 + rnd.Next(R - (int)a1 - 1);
ans = Math.Min(ans, (a1 * a2) % mod);
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int L = int.Parse(str[0]);
int R = int.Parse(str[1]);
long mod = 2019;
long ans = 2018;
Random rnd = new System.Random();
for (var i = 0; i < 30000000; i++) {
long a1 = L + i % (R - L);
long a2 = a1 + 1 + rnd.Next(R - (int)a1);
ans = Math.Min(ans, (a1 * a2) % mod);
// Console.WriteLine(a1+" "+a2);
}
Console.WriteLine(ans);
}
}
|
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 160
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Prog {
public void run() {
var input = Console.ReadLine().Split();
int L = int.Parse(input[0]);
int l = L % 2019;
int R = int.Parse(input[1]);
int r = R % 2019;
int LL = (L - l) / 2019;
int RR = (R - r) / 2019;
int ans = 0;
if (LL == RR) {
for (int i = l; i < r; i++) {
for (int j = i + 1; j <= r; j++) {
ans = Math.Min(ans, (i * j) % 2019);
}
}
} else if (l == 0 || r == 0) {
ans = 0;
} else {
ans = 0;
}
Console.WriteLine(ans);
}
public static void Main() {
var prog = new Prog();
prog.run();
}
/*
最小公倍数
public static long Lcm(long a, long b)
{
return a * b / Gcd(a, b);
}
// ユークリッドの互除法
public static long Gcd(long a, long b)
{
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0)
{
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
*/
// a<=c, b<=d;
}
// Array.ConvertAll(int.Parse)
// str.IndexOf("Stage",System.StringComparison.CurrentCulture)
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Prog {
public void run() {
var input = Console.ReadLine().Split();
int L = int.Parse(input[0]);
int l = L % 2019;
int R = int.Parse(input[1]);
int r = R % 2019;
int LL = (L - l) / 2019;
int RR = (R - r) / 2019;
int ans = 2018;
if (LL == RR) {
for (int i = l; i < r; i++) {
for (int j = i + 1; j <= r; j++) {
ans = Math.Min(ans, (i * j) % 2019);
}
}
} else if (l == 0 || r == 0) {
ans = 0;
} else {
ans = 0;
}
Console.WriteLine(ans);
}
public static void Main() {
var prog = new Prog();
prog.run();
}
/*
最小公倍数
public static long Lcm(long a, long b)
{
return a * b / Gcd(a, b);
}
// ユークリッドの互除法
public static long Gcd(long a, long b)
{
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0)
{
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
*/
// a<=c, b<=d;
}
// Array.ConvertAll(int.Parse)
// str.IndexOf("Stage",System.StringComparison.CurrentCulture)
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 223
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using static AtCoderer.Exter;
using static System.Math;
namespace AtCoderer {
public class App {
public static void Solve() {
long l, r;
ParseArray(out l, out r);
if ((r - l) >= 2019)
Console.WriteLine(0);
else {
long min = 2019;
for (long i = l; i < r; i++)
for (long j = i + 1; j < r; j++)
if ((i * j) % 2019 < min)
min = (i * j) % 2019;
Console.WriteLine(min);
}
}
public static void Main(string[] args) {
Solve();
Console.ReadKey();
}
}
public static class Exter {
public class Point {
public int a;
public int b;
public Point(int x, int y) {
a = x;
b = y;
}
}
public static int[] OrderBy(this int[] IArr) {
int[] arr = new int[IArr.Length];
Array.Copy(IArr, arr, IArr.Length);
Array.Sort(arr);
return arr;
}
public static char[] OrderBy(this string IArr) {
char[] arr = new char[IArr.Length];
Array.Copy(IArr.ToCharArray(), arr, IArr.Length);
Array.Sort(arr);
return arr;
}
public static long nCm(long n, long m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * nCm(n - 1, m - 1) / m % 1000000007;
}
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static IEnumerable<int> Factor(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
public static int Parse() { return int.Parse(Console.ReadLine()); }
public static int[] ParseArray(this string s) {
return s.Split().Select(v => int.Parse(v)).ToArray();
}
public static int[] ParseArray(this string[] s) {
return s.Select(v => int.Parse(v)).ToArray();
}
public static long[] ParseArrayL(this string s) {
return s.Split().Select(v => long.Parse(v)).ToArray();
}
public static void ParseArray(out int a, out int b) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
public static void ParseArray(out int a, out int b, out int c) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
public static void ParseArray(out int a, out int b, out int c, out int d) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
public static void ParseArray(out long a, out long b) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
public static void ParseArray(out long a, out long b, out long c) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
public static void ParseArray(out long a, out long b, out long c,
out long d) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int x,
int y) => y == 0 ? x : GcdRecursive(y, x % y);
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long x,
long y) => y == 0 ? x
: GcdRecursive(y, x % y);
public static string ToString(this IEnumerable<char> v) {
return string.Join("", v);
}
public static string Join<T>(this IEnumerable<T> v, char c) {
return string.Join(c.ToString(), v);
}
public static string Join<T>(this IEnumerable<T> v, string s) {
return string.Join(s, v);
}
public static int[] ReadArr {
get {
return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
}
}
public class EnumAll {
bool Over = false;
int UpperValue;
int Dimension;
public int[] Current { private set; get; }
public EnumAll(int Value, int Dimension) {
this.Dimension = Dimension;
UpperValue = Value;
Current = new int[Dimension];
Current[0] = -1;
}
public bool Next() {
if (Over)
return false;
bool flag = false;
for (int i = 0; i < Dimension; i++) {
if (++Current[i] >= UpperValue)
Current[i] = 0;
else {
flag = true;
break;
}
}
if (!flag) {
Over = true;
return false;
}
return true;
}
public bool IsOver() { return Over; }
}
public class UnionFind {
private int[] Parent;
private int GetRoot(int v) {
if (Parent[v] < 0)
return v;
else
return Parent[v] = GetRoot(Parent[v]);
}
public UnionFind(int size) {
Parent = new int[size];
for (int i = 0; i < size; i++)
Parent[i] = -1;
}
public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); }
public void Connect(int a, int b) {
a = GetRoot(a);
b = GetRoot(b);
if (a == b)
return;
if (Parent[b] < Parent[a]) {
Parent[b] += Parent[a];
Parent[a] = b;
} else {
Parent[a] += Parent[b];
Parent[b] = a;
}
}
public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; }
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static AtCoderer.Exter;
using static System.Math;
namespace AtCoderer {
public class App {
public static void Solve() {
long l, r;
ParseArray(out l, out r);
if ((r - l) >= 2019)
Console.WriteLine(0);
else {
long min = 2019;
for (long i = l; i <= r; i++)
for (long j = i + 1; j <= r; j++)
if ((i * j) % 2019 < min)
min = (i * j) % 2019;
Console.WriteLine(min);
}
}
public static void Main(string[] args) {
Solve();
Console.ReadKey();
}
}
public static class Exter {
public class Point {
public int a;
public int b;
public Point(int x, int y) {
a = x;
b = y;
}
}
public static int[] OrderBy(this int[] IArr) {
int[] arr = new int[IArr.Length];
Array.Copy(IArr, arr, IArr.Length);
Array.Sort(arr);
return arr;
}
public static char[] OrderBy(this string IArr) {
char[] arr = new char[IArr.Length];
Array.Copy(IArr.ToCharArray(), arr, IArr.Length);
Array.Sort(arr);
return arr;
}
public static long nCm(long n, long m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * nCm(n - 1, m - 1) / m % 1000000007;
}
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static IEnumerable<int> Factor(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
public static int Parse() { return int.Parse(Console.ReadLine()); }
public static int[] ParseArray(this string s) {
return s.Split().Select(v => int.Parse(v)).ToArray();
}
public static int[] ParseArray(this string[] s) {
return s.Select(v => int.Parse(v)).ToArray();
}
public static long[] ParseArrayL(this string s) {
return s.Split().Select(v => long.Parse(v)).ToArray();
}
public static void ParseArray(out int a, out int b) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
public static void ParseArray(out int a, out int b, out int c) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
public static void ParseArray(out int a, out int b, out int c, out int d) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
public static void ParseArray(out long a, out long b) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
public static void ParseArray(out long a, out long b, out long c) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
public static void ParseArray(out long a, out long b, out long c,
out long d) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int x,
int y) => y == 0 ? x : GcdRecursive(y, x % y);
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long x,
long y) => y == 0 ? x
: GcdRecursive(y, x % y);
public static string ToString(this IEnumerable<char> v) {
return string.Join("", v);
}
public static string Join<T>(this IEnumerable<T> v, char c) {
return string.Join(c.ToString(), v);
}
public static string Join<T>(this IEnumerable<T> v, string s) {
return string.Join(s, v);
}
public static int[] ReadArr {
get {
return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
}
}
public class EnumAll {
bool Over = false;
int UpperValue;
int Dimension;
public int[] Current { private set; get; }
public EnumAll(int Value, int Dimension) {
this.Dimension = Dimension;
UpperValue = Value;
Current = new int[Dimension];
Current[0] = -1;
}
public bool Next() {
if (Over)
return false;
bool flag = false;
for (int i = 0; i < Dimension; i++) {
if (++Current[i] >= UpperValue)
Current[i] = 0;
else {
flag = true;
break;
}
}
if (!flag) {
Over = true;
return false;
}
return true;
}
public bool IsOver() { return Over; }
}
public class UnionFind {
private int[] Parent;
private int GetRoot(int v) {
if (Parent[v] < 0)
return v;
else
return Parent[v] = GetRoot(Parent[v]);
}
public UnionFind(int size) {
Parent = new int[size];
for (int i = 0; i < size; i++)
Parent[i] = -1;
}
public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); }
public void Connect(int a, int b) {
a = GetRoot(a);
b = GetRoot(b);
if (a == b)
return;
if (Parent[b] < Parent[a]) {
Parent[b] += Parent[a];
Parent[a] = b;
} else {
Parent[a] += Parent[b];
Parent[b] = a;
}
}
public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; }
}
}
}
|
[["-", 0, 57, 75, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 17, 19], ["-", 75, 196, 0, 7, 8, 7, 15, 16, 17, 18], ["+", 75, 196, 0, 7, 8, 7, 15, 16, 17, 19]]
| 8
| 1,640
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
public class C {
public static void Main() {
long L = GetLong();
long R = GetLong();
if (R - L + 1 >= 2019) {
Console.WriteLine(0);
return;
}
long min = long.MaxValue;
for (long i = L; i <= R; i++) {
for (long j = L + 1; j <= R; j++)
min = Math.Min(min, (i * j) % 2019);
}
Console.WriteLine(min);
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
public class C {
public static void Main() {
long L = GetLong();
long R = GetLong();
if (R - L + 1 >= 2019) {
Console.WriteLine(0);
return;
}
long min = long.MaxValue;
for (long i = L; i <= R; i++) {
for (long j = i + 1; j <= R; j++)
min = Math.Min(min, (i * j) % 2019);
}
Console.WriteLine(min);
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22]]
| 8
| 286
| 2
|
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
static class P {
static void Main() {
var lr = Console.ReadLine().Split().Select(int.Parse).ToArray();
if (lr[1] - lr[0] >= 2019)
Console.WriteLine(0);
else {
var min = 2018;
for (int i = lr[0]; i <= lr[1]; i++) {
for (int j = i + 1; j <= lr[1]; j++) {
min = Min(min, i * j % 2019);
}
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
static class P {
static void Main() {
var lr = Console.ReadLine().Split().Select(long.Parse).ToArray();
if (lr[1] - lr[0] >= 2019)
Console.WriteLine(0);
else {
long min = 2018;
for (long i = lr[0]; i <= lr[1]; i++) {
for (long j = i + 1; j <= lr[1]; j++) {
min = Min(min, i * j % 2019);
}
}
Console.WriteLine(min);
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 180
| 8
|
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());
int n = scan.Integer();
int[] a = scan.Integer(n);
long[] b = new long[n];
long sum = 0;
for (int i = 1; i < n; i += 2) {
sum += 2 * a[i];
}
b[0] = a.Sum() - sum;
for (int i = 1; i < n; i++) {
b[i] = 2 * a[i - 1] - b[i - 1];
}
Output(b, " ");
}
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 string[] Scan(long n) {
string[] str = new string[n];
for (long i = 0; i < n; i++) {
str[i] = Scan();
}
return str;
}
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 {
public 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());
int n = scan.Integer();
long[] a = scan.Long(n);
long[] b = new long[n];
long sum = 0;
for (int i = 1; i < n; i += 2) {
sum += 2 * a[i];
}
b[0] = a.Sum() - sum;
for (int i = 1; i < n; i++) {
b[i] = 2 * a[i - 1] - b[i - 1];
}
Output(b, " ");
}
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 string[] Scan(long n) {
string[] str = new string[n];
for (long i = 0; i < n; i++) {
str[i] = Scan();
}
return str;
}
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 {
public 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, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 13,807
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class c {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
var ans = new List<int>();
ans.Add(a.Sum());
for (int i = 1; i < n; i = i + 2)
ans[0] -= 2 * a[i];
for (int i = 0; i < n - 1; i++)
ans.Add(2 * a[i] - ans[i]);
foreach (var item in ans)
Console.Write("{0} ", item);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class c {
static void Main() {
long n = long.Parse(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse).ToList();
var ans = new List<long>();
ans.Add(a.Sum());
for (int i = 1; i < n; i = i + 2)
ans[0] -= 2 * a[i];
for (int i = 0; i < n - 1; i++)
ans.Add(2 * a[i] - ans[i]);
foreach (var item in ans)
Console.Write("{0} ", item);
}
}
|
[["-", 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], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
| 8
| 168
| 8
|
using System;
public class HelloWorld {
static public void Main() {
var S = Console.ReadLine();
var flag = true;
for (int i = 1; i < 4; i++) {
if (S[i] == S[i - 1]) {
flag = false;
break;
}
}
if (flag) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("Bad");
}
}
}
|
using System;
public class HelloWorld {
static public void Main() {
var S = Console.ReadLine();
var flag = true;
for (int i = 1; i < 4; i++) {
if (S[i] == S[i - 1]) {
flag = false;
break;
}
}
if (flag) {
Console.WriteLine("Good");
} else {
Console.WriteLine("Bad");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 95
| 2
|
using System;
namespace A_Security {
class Program {
static void Main(string[] args) {
var pass = Console.ReadLine();
if (pass[0] == pass[1]) {
Console.WriteLine("bad");
} else if (pass[1] == pass[2]) {
Console.WriteLine("bad");
} else if (pass[2] == pass[3]) {
Console.WriteLine("bad");
} else {
Console.WriteLine("good");
}
}
}
}
|
using System;
namespace A_Security {
class Program {
static void Main(string[] args) {
var pass = Console.ReadLine();
if (pass[0] == pass[1]) {
Console.WriteLine("Bad");
} else if (pass[1] == pass[2]) {
Console.WriteLine("Bad");
} else if (pass[2] == pass[3]) {
Console.WriteLine("Bad");
} else {
Console.WriteLine("Good");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 114
| 8
|
using System;
class ABC131_A {
static void Main(string[] args) {
string str = Console.ReadLine();
if (str[0] != str[1] && str[1] != str[2] && str[2] != str[3]) {
Console.WriteLine("good");
} else {
Console.WriteLine("Bad");
}
}
}
|
using System;
class Problem {
static void Main(string[] args) {
string str = Console.ReadLine();
if (str[0] != str[1] && str[1] != str[2] && str[2] != str[3]) {
Console.WriteLine("Good");
} else {
Console.WriteLine("Bad");
}
}
}
|
[["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 82
| 4
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string a = Console.ReadLine();
for (int i = 0; i < a.Length - 1; i++) {
if (a[i] == a[i + 1])
Console.Write("Bad");
}
Console.Write("Good");
}
}
}
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string a = Console.ReadLine();
for (int i = 0; i < a.Length - 1; i++) {
if (a[i] == a[i + 1]) {
Console.Write("Bad");
return;
}
}
Console.Write("Good");
}
}
}
|
[["+", 0, 7, 8, 196, 0, 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], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 83
| 4
|
using System;
class Program {
static void Main(string[] args) {
char[] s = Console.ReadLine().ToCharArray();
char x = 's';
foreach (char c in s) {
if (x.Equals(c)) {
Console.WriteLine("Bad");
} else {
x = c;
}
}
Console.WriteLine("Good");
}
}
|
using System;
class Program {
static void Main(string[] args) {
char[] s = Console.ReadLine().ToCharArray();
char x = 's';
foreach (char c in s) {
if (x.Equals(c)) {
Console.WriteLine("Bad");
return;
} else {
x = c;
}
}
Console.WriteLine("Good");
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 85
| 2
|
using System;
namespace Bite_Eating {
class Program {
static void Main(string[] args) {
string arg = Console.ReadLine();
string[] w = arg.Split(' ');
int n = int.Parse(w[0]);
int L = int.Parse(w[1]);
int b;
if (L < 0) {
int ws = n + L;
if (ws <= 0) {
b = n - 1;
} else {
b = ws - 1;
}
} else {
b = 0;
}
int start = L;
int sum = 0;
for (int i = 0; i < n; i++) {
if (i == b) {
sum += 0;
} else {
sum += start;
}
start++;
}
Console.WriteLine(sum);
}
}
}
|
using System;
namespace Bite_Eating {
class Program {
static void Main(string[] args) {
string arg = Console.ReadLine();
string[] w = arg.Split(' ');
int n = int.Parse(w[0]);
int L = int.Parse(w[1]);
int b;
if (L < 0) {
int ws = n + L;
if (ws <= 0) {
b = n - 1;
} else {
b = n - ws;
}
} else {
b = 0;
}
int start = L;
int sum = 0;
for (int i = 0; i < n; i++) {
if (i == b) {
sum += 0;
} else {
sum += start;
}
start++;
}
Console.WriteLine(sum);
}
}
}
|
[["-", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 174
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
public static void Main() {
var line =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int N = line[0];
int L = line[1];
List<int> list = new List<int>();
for (int i = 1; i <= N; i++) {
list.Add(L + i - 1);
}
int m = 0;
foreach (var l in list) {
m = m + l;
}
if (L > 0) {
Console.WriteLine(m - list[0]);
} else if (L + N > 0) {
Console.WriteLine(m);
} else if (L + N < 0) {
Console.WriteLine(m - list[list.Count() - 1]);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
public static void Main() {
var line =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int N = line[0];
int L = line[1];
List<int> list = new List<int>();
for (int i = 1; i <= N; i++) {
list.Add(L + i - 1);
}
int m = 0;
foreach (var l in list) {
m = m + l;
}
if (L > 0) {
Console.WriteLine(m - list[0]);
} else if (L + N > 0) {
Console.WriteLine(m);
} else if (L + N <= 0) {
Console.WriteLine(m - list[list.Count() - 1]);
}
}
}
|
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 19]]
| 8
| 203
| 2
|
using System;
using System.Collections.Generic;
class program {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int N = int.Parse(s[0]);
int L = int.Parse(s[1]);
int min = 100;
int point = 100;
for (int i = 0; i < N; i++) {
int v = Math.Abs(L + i);
if (v < min) {
point = i;
min = v;
}
}
int sum = 0;
for (int i = 0; i < N; i++) {
if (i != point) {
sum += L + i;
}
}
Console.WriteLine(sum);
}
}
|
using System;
using System.Collections.Generic;
class program {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int N = int.Parse(s[0]);
int L = int.Parse(s[1]);
int min = 10000000;
int point = 10000000;
for (int i = 0; i < N; i++) {
int v = Math.Abs(L + i);
if (v <= min) {
point = i;
min = v;
}
}
int sum = 0;
for (int i = 0; i < N; i++) {
if (i != point) {
sum += L + i;
}
}
Console.WriteLine(sum);
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 161
| 6
|
using System;
using System.Linq;
namespace B___Bite_Eating {
class Program {
static void Main(string[] args) {
var N_L = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = N_L[0], L = N_L[1];
int a = L, l = L + N - 1;
bool flg = a < 0 && l > 0;
var sum = (double)N / 2 * (a + l) - (flg ? 0 : l < 0 ? l : a);
Console.WriteLine(sum);
}
}
}
|
using System;
using System.Linq;
namespace B___Bite_Eating {
class Program {
static void Main(string[] args) {
var N_L = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = N_L[0], L = N_L[1];
int a = L, l = L + N - 1;
bool flg = a < 0 && l > 0;
var sum = (double)N / 2 * (a + l) - (flg ? 0 : l <= 0 ? l : a);
Console.WriteLine(sum);
}
}
}
|
[["-", 12, 23, 0, 41, 75, 41, 15, 16, 17, 18], ["+", 12, 23, 0, 41, 75, 41, 15, 16, 17, 19]]
| 8
| 127
| 2
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
var data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var n = data[0];
var l = data[1];
var appleArray = new int[n];
for (int i = 0; i < n; i++) {
appleArray[i] = l + i;
}
if (l < 0 && n < Math.Abs(l)) {
Console.WriteLine(appleArray.Sum() - appleArray[n - 1]);
} else {
Console.WriteLine(appleArray.Sum() - Math.Max(l, 0));
}
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
var data = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var n = data[0];
var l = data[1];
var appleArray = new int[n];
for (int i = 0; i < n; i++) {
appleArray[i] = l + i;
}
if (l < 0 && n <= Math.Abs(l)) {
Console.WriteLine(appleArray.Sum() - appleArray[n - 1]);
} else {
Console.WriteLine(appleArray.Sum() - Math.Max(l, 0));
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
| 8
| 158
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split();
int N = int.Parse(input[0]);
int L = int.Parse(input[1]);
int sum = 0;
if (L >= 0) {
for (int i = 0; i < N - 1; i++) {
sum += L + 1 + i;
}
} else if (L + N - 1 >= 0) {
for (int i = 0; i < N; i++) {
sum += L + 1 + i;
}
} else {
for (int i = 0; i < N - 1; i++) {
sum += L + i;
}
}
Console.WriteLine(sum);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split();
int N = int.Parse(input[0]);
int L = int.Parse(input[1]);
int sum = 0;
if (L >= 0) {
for (int i = 0; i < N - 1; i++) {
sum += L + 1 + i;
}
} else if (L + N - 1 >= 0) {
for (int i = 0; i < N; i++) {
sum += L + i;
}
} else {
for (int i = 0; i < N - 1; i++) {
sum += L + i;
}
}
Console.WriteLine(sum);
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
| 8
| 181
| 2
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string[] a = (Console.ReadLine().Split(' '));
int[] b = new int[2];
for (int i = 0; i < a.Length; i++) {
b[i] = int.Parse(a[i]);
}
int res = 0;
int min = -9999;
for (int i = 0; i < b[1]; i++) {
int num = b[0] + i;
res += num;
if (min * min > num * num) {
min = num;
}
}
res -= min;
Console.Write(res);
}
}
}
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string[] a = (Console.ReadLine().Split(' '));
int[] b = new int[2];
for (int i = 0; i < a.Length; i++) {
b[i] = int.Parse(a[i]);
}
int res = 0;
int min = -9999;
for (int i = 0; i < b[0]; i++) {
int num = b[1] + i;
res += num;
if (min * min > num * num) {
min = num;
}
}
res -= min;
Console.Write(res);
}
}
}
|
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 157
| 4
|
using System;
namespace AtCoderABC131B {
class Program {
static void Main(string[] args) {
int ans = 0;
string[] s = Console.ReadLine().Split(' ');
int N = int.Parse(s[0]);
int L = int.Parse(s[1]);
ans = N * (L * 2 + N - 1) / 2;
if (L >= 0) {
ans -= L;
} else {
if (L + N < 0) {
ans -= L + N - 1;
}
}
Console.WriteLine(ans.ToString());
}
}
}
|
using System;
namespace AtCoderABC131B {
class Program {
static void Main(string[] args) {
int ans = 0;
string[] s = Console.ReadLine().Split(' ');
int N = int.Parse(s[0]);
int L = int.Parse(s[1]);
ans = N * (L * 2 + N - 1) / 2;
if (L >= 0) {
ans -= L;
} else {
if (L + N <= 0) {
ans -= L + N - 1;
}
}
Console.WriteLine(ans.ToString());
}
}
}
|
[["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 131
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace app02 {
class Program {
static void Main(string[] args) {
string[] NL = Console.ReadLine().Split(' ');
int N = int.Parse(NL[0]);
int L = int.Parse(NL[1]);
int[] taste = new int[N];
int maxApplePi = 0;
int resultApplePi = 0;
int abs = 99;
for (int i = 0; i < N; i++) {
taste[i] = L + (i + 1) - 1;
}
for (int i = 0; i < N; i++) {
maxApplePi += taste[i];
}
for (int i = 0; i < N; i++) {
int applePi = 0;
for (int j = 0; j < N; j++) {
if (i == j) {
continue;
}
applePi += taste[j];
}
int newAbs = Math.Abs(maxApplePi - applePi);
if (newAbs < abs) {
resultApplePi = applePi;
abs = newAbs;
}
}
Console.WriteLine($"{resultApplePi}");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace app02 {
class Program {
static void Main(string[] args) {
string[] NL = Console.ReadLine().Split(' ');
int N = int.Parse(NL[0]);
int L = int.Parse(NL[1]);
int[] taste = new int[N];
int maxApplePi = 0;
int resultApplePi = 0;
int abs = 10000;
for (int i = 0; i < N; i++) {
taste[i] = L + (i + 1) - 1;
}
for (int i = 0; i < N; i++) {
maxApplePi += taste[i];
}
for (int i = 0; i < N; i++) {
int applePi = 0;
for (int j = 0; j < N; j++) {
if (i == j) {
continue;
}
applePi += taste[j];
}
int newAbs = Math.Abs(maxApplePi - applePi);
if (newAbs < abs) {
resultApplePi = applePi;
abs = newAbs;
}
}
Console.WriteLine($"{resultApplePi}");
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 263
| 2
|
using System;
namespace SolutionB {
class Program {
static void Main(string[] args) {
String s = Console.ReadLine();
String[] inputs = s.Split();
int n = int.Parse(inputs[0]);
int l = int.Parse(inputs[1]);
int res = 0;
for (int i = 0; i < n; i++) {
if (l > 0) {
// 味が全て正の場合、最初の要素を除外
if (i == 0)
continue;
} else if (l < 0 && n + l < 0) {
// 味が全て負の場合、最後の要素を除外
if (i == n - 1)
continue;
} else {
// 味が負から正に変わる場合、0になる要素を除外するが、足しても合計は変わらない
}
res += l + i;
}
Console.WriteLine($"{res}");
}
}
}
|
using System;
namespace SolutionB {
class Program {
static void Main(string[] args) {
String s = Console.ReadLine();
String[] inputs = s.Split();
int n = int.Parse(inputs[0]);
int l = int.Parse(inputs[1]);
int res = 0;
for (int i = 0; i < n; i++) {
if (l > 0) {
// 味が全て正の場合、最初の要素を除外
if (i == 0)
continue;
} else if (l < 0 && n + l <= 0) {
// 味が全て負の場合、最後の要素を除外
if (i == n - 1)
continue;
} else {
// 味が負から正に変わる場合、0になる要素を除外するが、足しても合計は変わらない
}
res += l + i;
}
Console.WriteLine($"{res}");
}
}
}
|
[["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 19]]
| 8
| 153
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace B_ABC131 {
class MainClass {
static int[] s;
public static void Main(string[] args) {
s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);
int tmp = s[1];
int ans = s[1];
if (s[0] + s[1] > 0 && s[1] < 0) {
for (int i = 0; i < s[0] - 1; i++) {
tmp = tmp + 1;
ans += tmp;
}
} else if (s[0] + s[1] < 0) {
for (int i = 0; i < s[0] - 2; i++) {
tmp = tmp + 1;
ans += tmp;
}
} else {
ans = s[1] + 1;
tmp = s[1] + 1;
for (int i = 0; i < s[0] - 2; i++) {
tmp = tmp + 1;
ans += tmp;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace B_ABC131 {
class MainClass {
static int[] s;
public static void Main(string[] args) {
s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);
int tmp = s[1];
int ans = s[1];
if (s[0] + s[1] > 0 && s[1] < 0) {
for (int i = 0; i < s[0] - 1; i++) {
tmp = tmp + 1;
ans += tmp;
}
} else if (s[0] + s[1] <= 0) {
for (int i = 0; i < s[0] - 2; i++) {
tmp = tmp + 1;
ans += tmp;
}
} else {
ans = s[1] + 1;
tmp = s[1] + 1;
for (int i = 0; i < s[0] - 2; i++) {
tmp = tmp + 1;
ans += tmp;
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19]]
| 8
| 243
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsTest {
public class Program {
static void Main(string[] args) {
string[] line = Console.ReadLine().Split(' ');
int N = int.Parse(line[0]), L = int.Parse(line[1]);
int result = ((L - 1) * N) + ((N + 1) * N / 2);
if (L > 0)
result -= L;
else if (Math.Abs(L) > N)
result -= (L + N - 1);
Console.WriteLine(result);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsTest {
public class Program {
static void Main(string[] args) {
string[] line = Console.ReadLine().Split(' ');
int N = int.Parse(line[0]), L = int.Parse(line[1]);
int result = ((L - 1) * N) + ((N + 1) * N / 2);
if (L > 0)
result -= L;
else if (Math.Abs(L) >= N)
result -= (L + N - 1);
Console.WriteLine(result);
}
}
}
|
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 20]]
| 8
| 142
| 2
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace ProjectContest {
class Test {
static void Main() {
var nl = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
int n = nl[0], l = nl[1];
int[] L = new int[n];
for (int i = 0; i < n; i++)
L[i] = l + i;
int sum = L.Sum();
int min = Math.Abs(L[0]);
int t = 0;
for (int i = 1; i < n; i++) {
int now = Math.Min(min, Math.Abs(L[i]));
t = min == now ? t : i;
}
Console.WriteLine(sum - L[t]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace ProjectContest {
class Test {
static void Main() {
var nl = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
int n = nl[0], l = nl[1];
int[] L = new int[n];
for (int i = 0; i < n; i++)
L[i] = l + i;
int sum = L.Sum();
int min = Math.Abs(L[0]);
int t = 0;
for (int i = 1; i < n; i++) {
int now = Math.Min(min, Math.Abs(L[i]));
t = min == now ? t : i;
min = now;
}
Console.WriteLine(sum - L[t]);
}
}
}
|
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 191
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCorder {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var list = new List<KeyValuePair<int, int>>();
for (int i = 0; i < n; i++) {
var input = Console.ReadLine();
var ar = input.Split(' ');
list.Add(new KeyValuePair<int, int>(int.Parse(ar[0]), int.Parse(ar[1])));
}
var sum = 0;
foreach (var item in list.OrderBy(t => t.Value)) {
sum += item.Value;
if (sum > item.Key) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCorder {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var list = new List<KeyValuePair<int, int>>();
for (int i = 0; i < n; i++) {
var input = Console.ReadLine();
var ar = input.Split(' ');
list.Add(new KeyValuePair<int, int>(int.Parse(ar[0]), int.Parse(ar[1])));
}
var sum = 0;
foreach (var item in list.OrderBy(t => t.Value)) {
sum += item.Key;
if (sum > item.Value) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22]]
| 8
| 194
| 4
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Ha2ne2Util.Cin;
using static Ha2ne2Util.Util;
using static System.Console;
using static System.Math;
using System.Collections;
using Pair = System.Tuple<long, long>;
/// <summary>
/// https://atcoder.jp/contests/abc131
/// 2020/02/05
/// </summary>
namespace ABC131 {
public class Program {
public static void Main(string[] args) {
// A(); 4m
// B();
// C(); 37m
D();
// E();
// F();
}
public static void F() {}
public static void E() {}
public static void D() {
long N = rl;
Pair[] A = new Pair[N];
for (int i = 0; i < N; i++) {
A[i] = new Pair(rl, rl);
}
A = A.OrderByDescending(p => p.Item2).ToArray();
long timeLimit = A[0].Item2;
long curr = 0;
for (int i = 0; i < N; i++) {
if (timeLimit != A[i].Item2 && curr <= A[i].Item2) {
curr = 0;
timeLimit = A[i].Item2;
}
curr += A[i].Item1;
}
if (curr <= timeLimit) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
public static void C() {
long A = rl;
long B = rl;
long C = rl;
long D = rl;
long gcd = GCD((int)C, (int)D);
long lcm = (C * D) / gcd;
long c1 = (A - 1) / C;
long d1 = (A - 1) / D;
long cd1 = (A - 1) / lcm;
long a = c1 + d1 - cd1;
long c2 = B / C;
long d2 = B / D;
long cd2 = B / lcm;
long b = c2 + d2 - cd2;
long ans = (B - A + 1) - (b - a);
Console.WriteLine(ans);
}
public static void B() {
long N = rl;
long L = rl;
long[] A = new long[N];
for (int i = 0; i < N; i++) {
A[i] = L + i;
}
long min = INF;
long ans = 0;
for (int i = 0; i < N; i++) {
if (Abs(A[i]) < Abs(min)) {
min = A[i];
}
ans += A[i];
}
Console.WriteLine(ans - min);
}
public static void A() {
string S = rs;
for (int i = 0; i < S.Length - 1; i++) {
if (S[i] == S[i + 1]) {
Console.WriteLine("Bad");
return;
}
}
if (S[S.Length - 1] == S[S.Length - 2]) {
Console.WriteLine("Bad");
} else {
Console.WriteLine("Good");
}
}
}
}
namespace Ha2ne2Util {
public static class Cin {
public static long rl => ReadLong();
public static long[] rla => ReadLongArray();
public static double rd => ReadDouble();
public static double[] rda => ReadDoubleArray();
public static string rs => ReadString();
private static string[] Tokens { get; set; }
private static int Pointer { get; set; }
public static string Next() {
if (Tokens == null || Tokens.Length <= Pointer) {
Tokens = Console.ReadLine().Split(' ');
Pointer = 0;
}
return Tokens[Pointer++];
}
public static int ReadInt() { return int.Parse(Next()); }
public static long ReadLong() { return long.Parse(Next()); }
public static double ReadDouble() { return double.Parse(Next()); }
public static string ReadString() { return Next(); }
public static int[] ReadIntArray() {
Tokens = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
Tokens = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
Tokens = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static void ReadCols(out long[] a, out long[] b, long N) {
a = new long[N];
b = new long[N];
for (int i = 0; i < N; i++) {
a[i] = ReadLong();
b[i] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long N) {
a = new long[N];
b = new long[N];
c = new long[N];
for (int i = 0; i < N; i++) {
a[i] = ReadLong();
b[i] = ReadLong();
c[i] = ReadLong();
}
}
public static int[][] ReadIntTable(int n) {
Tokens = null;
int[][] ret = new int [n][];
for (int i = 0; i < n; i++) {
ret[i] = ReadIntArray();
}
return ret;
}
public static long[][] ReadLongTable(long n) {
Tokens = null;
long[][] ret = new long [n][];
for (long i = 0; i < n; i++) {
ret[i] = ReadLongArray();
}
return ret;
}
}
/// <summary>
/// ユーティリティー
/// </summary>
public static class Util {
// 10^17
public static readonly long INF = (long)1e17;
// 10^9 + 7
public readonly static long MOD = (long)1e9 + 7;
/// <summary>
/// Console.WriteLineの自動フラッシュをしないようにする
/// </summary>
public static void DontAutoFlush() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public static void Flush() { Console.Out.Flush(); }
public static IEnumerable<int> Range(int end) {
for (int i = 0; i < end; i++) {
yield return i;
}
}
public static IEnumerable<int> Range(int from, int end) {
for (int i = from; i < end; i++) {
yield return i;
}
}
public static IEnumerable<int> Range(int from, int end, int step) {
for (int i = from; i < end; i += step) {
yield return i;
}
}
/// <summary>
/// ソートをして結果を返します。
/// 破壊的関数です。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <returns></returns>
public static T[] Sort<T>(T[] array) {
Array.Sort<T>(array);
return array;
}
/// <summary>
/// 降順ソートをして結果を返します。
/// 破壊的関数です。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <returns></returns>
public static T[] SortDecend<T>(T[] array) {
Array.Sort<T>(array);
Array.Reverse(array);
return array;
}
/// <summary>
/// 引数aと引数bの値を入れ替えます
/// </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 _a = a;
a = b;
b = _a;
}
/// <summary>
/// 先頭と末尾に要素を増やした新しい配列を返します。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <returns></returns>
public static T[] AddHeadAndTail<T>(T[] array) {
int len = array.Length;
T[] res = new T[len + 2];
Array.Copy(array, 0, res, 1, len);
return res;
}
/// <summary>
/// 昇順ソート済みの配列を2分探索します。
/// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。
/// </summary>
/// <param name="array"></param>
/// <param name="n"></param>
/// <returns></returns>
public static int BinarySearch(long[] array, long n) {
int left = 0;
int right = array.Length - 1;
while (left <= right) {
int mid = (right - left) / 2 + left;
if (array[mid] == n) {
return mid;
} else if (n < array[mid]) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return left;
}
public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); }
/// <summary>
/// nの約数の配列を返します。
/// 配列は昇順ソートされています。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int[] GetDivisor(int n) {
double sqrt = Math.Sqrt(n);
List<int> divisor = new List<int>();
for (int i = 1; i <= sqrt; i++) {
if (n % i == 0) {
divisor.Add(i);
int d = n / i;
if (d != i) {
divisor.Add(d);
}
}
}
return Sort(divisor.ToArray());
}
public static void Deconstruct<T>(this T[] items, out T t0) {
t0 = items.Length > 0 ? items[0] : default(T);
}
public static void Deconstruct<T>(this T[] items, out T t0, out T t1) {
if (items.Length < 2)
throw new ArgumentException();
t0 = items[0];
t1 = items[1];
}
public static void Deconstruct<T>(this T[] items, out T t0, out T t1,
out T t2) {
if (items.Length < 3)
throw new ArgumentException();
t0 = items[0];
t1 = items[1];
t2 = items[2];
}
public static void Deconstruct<T>(this T[] items, out T t0, out T t1,
out T t2, out T t3) {
if (items.Length < 4)
throw new ArgumentException();
t0 = items[0];
t1 = items[1];
t2 = items[2];
t3 = items[3];
}
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static long ModAdd(long a, long b) {
long res = a + b;
if (res >= MOD)
return res % MOD;
return res;
}
public static long ModMul(long a, long b) {
long res = a * b;
if (res >= MOD)
return res % MOD;
return res;
}
public static void ChModAdd(ref long a, long b) {
a += b;
if (a >= MOD)
a %= MOD;
}
public static void ChModMul(ref long a, long b) {
a *= b;
if (a >= MOD)
a %= MOD;
}
public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) {
T min = source.First();
long minValue = long.MaxValue;
foreach (T x in source) {
long n = conv(x);
if (n < minValue) {
min = x;
}
}
return min;
}
public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) {
T min = source.First();
long maxValue = long.MinValue;
foreach (T x in source) {
long n = conv(x);
if (maxValue < n) {
min = x;
}
}
return min;
}
public static void FillArray<T>(T[] array, T value) {
int max = array.Length;
for (int i = 0; i < max; i++) {
array[i] = value;
}
}
public static void FillArray<T>(T[,] array, T value) {
int max0 = array.GetLength(0);
int max1 = array.GetLength(1);
for (int i = 0; i < max0; i++) {
for (int j = 0; j < max1; j++) {
array[i, j] = value;
}
}
}
public static void FillArray<T>(T[,,] array, T value) {
int max0 = array.GetLength(0);
int max1 = array.GetLength(1);
int max2 = array.GetLength(2);
for (int i = 0; i < max0; i++) {
for (int j = 0; j < max1; j++) {
for (int k = 0; k < max2; k++) {
array[i, j, k] = value;
}
}
}
}
/// <summary>
/// めぐる式二分探索
/// okにはpredを満たすindexを、ngにはpredを満たさないindexを指定します。
/// 引数がng<okの場合、最小のokとなるindexをokに代入します。(lower_bound)
/// 引数がok<ngの場合、最大のokとなるindexをokに代入します。(upper_bound)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <param name="okIndex"></param>
/// <param name="ngIndex"></param>
/// <param name="pred"></param>
public static void MeguruBinarySearch<T>(T[] array, ref long okIndex,
ref long ngIndex,
Predicate<T> pred) {
while (Math.Abs(okIndex - ngIndex) > 1) {
long mid = (okIndex + ngIndex) / 2;
if (pred(array[mid])) {
okIndex = mid;
} else {
ngIndex = mid;
}
}
}
}
/// <summary>
/// UnionFindTree
/// </summary>
public class UnionFindTree {
public int[] Node;
public UnionFindTree(int N) {
Node = new int[N];
for (int i = 0; i < N; i++) {
Node[i] = -1;
}
}
public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); }
public bool Merge(int x, int y) {
int xr = GetRoot(x);
int yr = GetRoot(y);
if (xr == yr)
return false;
// xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ)
if (Node[xr] > Node[yr])
Swap(ref xr, ref yr);
// グループの数を合算する
Node[xr] += Node[yr];
// 根を張り替える
Node[yr] = xr;
return true;
}
public int Size(int x) { return -Node[GetRoot(x)]; }
public int GetRoot(int n) {
if (Node[n] < 0) {
return n;
} else {
// 根を張りなおす。
Node[n] = GetRoot(Node[n]);
return Node[n];
}
}
}
/// <summary>
/// PriorityQueue
/// </summary>
/// <typeparam name="T"></typeparam>
public class PriorityQueue<T> {
private Comparison<T> _comparison = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <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;
}
public PriorityQueue(int maxSize, Comparison<T> comparison) {
_heap = new T[maxSize];
_comparison = comparison;
}
private int Compare(T x, T y) {
return _comparison(x, y);
// if (_comparison != null) return _comparison(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.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Ha2ne2Util.Cin;
using static Ha2ne2Util.Util;
using static System.Console;
using static System.Math;
using System.Collections;
using Pair = System.Tuple<long, long>;
/// <summary>
/// https://atcoder.jp/contests/abc131
/// 2020/02/05
/// </summary>
namespace ABC131 {
public class Program {
public static void Main(string[] args) {
// A(); 4m
// B();
// C(); 37m
D();
// E();
// F();
}
public static void F() {}
public static void E() {}
public static void D() {
long N = rl;
Pair[] A = new Pair[N];
for (int i = 0; i < N; i++) {
A[i] = new Pair(rl, rl);
}
A = A.OrderByDescending(p => p.Item2).ToArray();
long timeLimit = A[0].Item2;
long curr = 0;
for (int i = 0; i < N; i++) {
if (timeLimit != A[i].Item2 && curr <= timeLimit - A[i].Item2) {
curr = 0;
timeLimit = A[i].Item2;
}
curr += A[i].Item1;
}
if (curr <= timeLimit) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
public static void C() {
long A = rl;
long B = rl;
long C = rl;
long D = rl;
long gcd = GCD((int)C, (int)D);
long lcm = (C * D) / gcd;
long c1 = (A - 1) / C;
long d1 = (A - 1) / D;
long cd1 = (A - 1) / lcm;
long a = c1 + d1 - cd1;
long c2 = B / C;
long d2 = B / D;
long cd2 = B / lcm;
long b = c2 + d2 - cd2;
long ans = (B - A + 1) - (b - a);
Console.WriteLine(ans);
}
public static void B() {
long N = rl;
long L = rl;
long[] A = new long[N];
for (int i = 0; i < N; i++) {
A[i] = L + i;
}
long min = INF;
long ans = 0;
for (int i = 0; i < N; i++) {
if (Abs(A[i]) < Abs(min)) {
min = A[i];
}
ans += A[i];
}
Console.WriteLine(ans - min);
}
public static void A() {
string S = rs;
for (int i = 0; i < S.Length - 1; i++) {
if (S[i] == S[i + 1]) {
Console.WriteLine("Bad");
return;
}
}
if (S[S.Length - 1] == S[S.Length - 2]) {
Console.WriteLine("Bad");
} else {
Console.WriteLine("Good");
}
}
}
}
namespace Ha2ne2Util {
public static class Cin {
public static long rl => ReadLong();
public static long[] rla => ReadLongArray();
public static double rd => ReadDouble();
public static double[] rda => ReadDoubleArray();
public static string rs => ReadString();
private static string[] Tokens { get; set; }
private static int Pointer { get; set; }
public static string Next() {
if (Tokens == null || Tokens.Length <= Pointer) {
Tokens = Console.ReadLine().Split(' ');
Pointer = 0;
}
return Tokens[Pointer++];
}
public static int ReadInt() { return int.Parse(Next()); }
public static long ReadLong() { return long.Parse(Next()); }
public static double ReadDouble() { return double.Parse(Next()); }
public static string ReadString() { return Next(); }
public static int[] ReadIntArray() {
Tokens = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
public static long[] ReadLongArray() {
Tokens = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
public static double[] ReadDoubleArray() {
Tokens = null;
return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
}
public static void ReadCols(out long[] a, out long[] b, long N) {
a = new long[N];
b = new long[N];
for (int i = 0; i < N; i++) {
a[i] = ReadLong();
b[i] = ReadLong();
}
}
public static void ReadCols(out long[] a, out long[] b, out long[] c,
long N) {
a = new long[N];
b = new long[N];
c = new long[N];
for (int i = 0; i < N; i++) {
a[i] = ReadLong();
b[i] = ReadLong();
c[i] = ReadLong();
}
}
public static int[][] ReadIntTable(int n) {
Tokens = null;
int[][] ret = new int [n][];
for (int i = 0; i < n; i++) {
ret[i] = ReadIntArray();
}
return ret;
}
public static long[][] ReadLongTable(long n) {
Tokens = null;
long[][] ret = new long [n][];
for (long i = 0; i < n; i++) {
ret[i] = ReadLongArray();
}
return ret;
}
}
/// <summary>
/// ユーティリティー
/// </summary>
public static class Util {
// 10^17
public static readonly long INF = (long)1e17;
// 10^9 + 7
public readonly static long MOD = (long)1e9 + 7;
/// <summary>
/// Console.WriteLineの自動フラッシュをしないようにする
/// </summary>
public static void DontAutoFlush() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public static void Flush() { Console.Out.Flush(); }
public static IEnumerable<int> Range(int end) {
for (int i = 0; i < end; i++) {
yield return i;
}
}
public static IEnumerable<int> Range(int from, int end) {
for (int i = from; i < end; i++) {
yield return i;
}
}
public static IEnumerable<int> Range(int from, int end, int step) {
for (int i = from; i < end; i += step) {
yield return i;
}
}
/// <summary>
/// ソートをして結果を返します。
/// 破壊的関数です。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <returns></returns>
public static T[] Sort<T>(T[] array) {
Array.Sort<T>(array);
return array;
}
/// <summary>
/// 降順ソートをして結果を返します。
/// 破壊的関数です。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <returns></returns>
public static T[] SortDecend<T>(T[] array) {
Array.Sort<T>(array);
Array.Reverse(array);
return array;
}
/// <summary>
/// 引数aと引数bの値を入れ替えます
/// </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 _a = a;
a = b;
b = _a;
}
/// <summary>
/// 先頭と末尾に要素を増やした新しい配列を返します。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <returns></returns>
public static T[] AddHeadAndTail<T>(T[] array) {
int len = array.Length;
T[] res = new T[len + 2];
Array.Copy(array, 0, res, 1, len);
return res;
}
/// <summary>
/// 昇順ソート済みの配列を2分探索します。
/// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。
/// </summary>
/// <param name="array"></param>
/// <param name="n"></param>
/// <returns></returns>
public static int BinarySearch(long[] array, long n) {
int left = 0;
int right = array.Length - 1;
while (left <= right) {
int mid = (right - left) / 2 + left;
if (array[mid] == n) {
return mid;
} else if (n < array[mid]) {
right = mid - 1;
} else {
left = mid + 1;
}
}
return left;
}
public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); }
/// <summary>
/// nの約数の配列を返します。
/// 配列は昇順ソートされています。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int[] GetDivisor(int n) {
double sqrt = Math.Sqrt(n);
List<int> divisor = new List<int>();
for (int i = 1; i <= sqrt; i++) {
if (n % i == 0) {
divisor.Add(i);
int d = n / i;
if (d != i) {
divisor.Add(d);
}
}
}
return Sort(divisor.ToArray());
}
public static void Deconstruct<T>(this T[] items, out T t0) {
t0 = items.Length > 0 ? items[0] : default(T);
}
public static void Deconstruct<T>(this T[] items, out T t0, out T t1) {
if (items.Length < 2)
throw new ArgumentException();
t0 = items[0];
t1 = items[1];
}
public static void Deconstruct<T>(this T[] items, out T t0, out T t1,
out T t2) {
if (items.Length < 3)
throw new ArgumentException();
t0 = items[0];
t1 = items[1];
t2 = items[2];
}
public static void Deconstruct<T>(this T[] items, out T t0, out T t1,
out T t2, out T t3) {
if (items.Length < 4)
throw new ArgumentException();
t0 = items[0];
t1 = items[1];
t2 = items[2];
t3 = items[3];
}
public static void ChMax(ref long a, long b) {
if (a < b)
a = b;
}
public static void ChMin(ref long a, long b) {
if (a > b)
a = b;
}
public static long ModAdd(long a, long b) {
long res = a + b;
if (res >= MOD)
return res % MOD;
return res;
}
public static long ModMul(long a, long b) {
long res = a * b;
if (res >= MOD)
return res % MOD;
return res;
}
public static void ChModAdd(ref long a, long b) {
a += b;
if (a >= MOD)
a %= MOD;
}
public static void ChModMul(ref long a, long b) {
a *= b;
if (a >= MOD)
a %= MOD;
}
public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) {
T min = source.First();
long minValue = long.MaxValue;
foreach (T x in source) {
long n = conv(x);
if (n < minValue) {
min = x;
}
}
return min;
}
public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) {
T min = source.First();
long maxValue = long.MinValue;
foreach (T x in source) {
long n = conv(x);
if (maxValue < n) {
min = x;
}
}
return min;
}
public static void FillArray<T>(T[] array, T value) {
int max = array.Length;
for (int i = 0; i < max; i++) {
array[i] = value;
}
}
public static void FillArray<T>(T[,] array, T value) {
int max0 = array.GetLength(0);
int max1 = array.GetLength(1);
for (int i = 0; i < max0; i++) {
for (int j = 0; j < max1; j++) {
array[i, j] = value;
}
}
}
public static void FillArray<T>(T[,,] array, T value) {
int max0 = array.GetLength(0);
int max1 = array.GetLength(1);
int max2 = array.GetLength(2);
for (int i = 0; i < max0; i++) {
for (int j = 0; j < max1; j++) {
for (int k = 0; k < max2; k++) {
array[i, j, k] = value;
}
}
}
}
/// <summary>
/// めぐる式二分探索
/// okにはpredを満たすindexを、ngにはpredを満たさないindexを指定します。
/// 引数がng<okの場合、最小のokとなるindexをokに代入します。(lower_bound)
/// 引数がok<ngの場合、最大のokとなるindexをokに代入します。(upper_bound)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <param name="okIndex"></param>
/// <param name="ngIndex"></param>
/// <param name="pred"></param>
public static void MeguruBinarySearch<T>(T[] array, ref long okIndex,
ref long ngIndex,
Predicate<T> pred) {
while (Math.Abs(okIndex - ngIndex) > 1) {
long mid = (okIndex + ngIndex) / 2;
if (pred(array[mid])) {
okIndex = mid;
} else {
ngIndex = mid;
}
}
}
}
/// <summary>
/// UnionFindTree
/// </summary>
public class UnionFindTree {
public int[] Node;
public UnionFindTree(int N) {
Node = new int[N];
for (int i = 0; i < N; i++) {
Node[i] = -1;
}
}
public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); }
public bool Merge(int x, int y) {
int xr = GetRoot(x);
int yr = GetRoot(y);
if (xr == yr)
return false;
// xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ)
if (Node[xr] > Node[yr])
Swap(ref xr, ref yr);
// グループの数を合算する
Node[xr] += Node[yr];
// 根を張り替える
Node[yr] = xr;
return true;
}
public int Size(int x) { return -Node[GetRoot(x)]; }
public int GetRoot(int n) {
if (Node[n] < 0) {
return n;
} else {
// 根を張りなおす。
Node[n] = GetRoot(Node[n]);
return Node[n];
}
}
}
/// <summary>
/// PriorityQueue
/// </summary>
/// <typeparam name="T"></typeparam>
public class PriorityQueue<T> {
private Comparison<T> _comparison = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <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;
}
public PriorityQueue(int maxSize, Comparison<T> comparison) {
_heap = new T[maxSize];
_comparison = comparison;
}
private int Compare(T x, T y) {
return _comparison(x, y);
// if (_comparison != null) return _comparison(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;
}
}
}
|
[["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33]]
| 8
| 3,498
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace AtCoder {
class Program {
static void Main() {
//ここから
int N = IO.ReadLineToInt();
List<Pair> list = new List<Pair>();
long sum = 0;
string ans = "Yes";
for (int i = 0; i < N; i++) {
long[] temp = IO.ReadLineToLongArray();
Pair pair = new Pair();
pair.A = temp[0];
pair.B = temp[1];
list.Add(pair);
sum += temp[0];
}
list = list.OrderByDescending(l => l.B).ToList();
for (int i = 0; i < N; i++) {
if (sum > list[i].B) {
ans = "No";
break;
} else {
sum -= list[i].B;
}
}
//ここまで
Console.WriteLine(ans);
Console.ReadKey();
}
}
class Pair {
public long A;
public long B;
}
class Func {
long mod = 1000000007;
static public void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
static public int Factorial(int a) {
return a == 1 ? a : a * Factorial(a - 1);
}
static public int Conbin(int n, int m) {
return Factorial(n) / (Factorial(n - m) * Factorial(m));
}
static public void Factoring(long num, ref long[] vs) {
if (num == 1) {
vs[1]++;
}
for (long i = 2; i < (long)Math.Sqrt(num); i++) {
if (num % i == 0) {
vs[i]++;
Factoring(num / i, ref vs);
}
}
vs[1]++;
}
}
class IO {
static public string ReadLineToString() { return Console.ReadLine(); }
static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
static public string[] ReadLineToStringArray() {
return Console.ReadLine().Split(' ').ToArray();
}
static public int[] ReadLineToIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] ReadLineToLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public List<string> ReadLineToStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> ReadLineToIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> ReadLineToLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace AtCoder {
class Program {
static void Main() {
//ここから
int N = IO.ReadLineToInt();
List<Pair> list = new List<Pair>();
long sum = 0;
string ans = "Yes";
for (int i = 0; i < N; i++) {
long[] temp = IO.ReadLineToLongArray();
Pair pair = new Pair();
pair.A = temp[0];
pair.B = temp[1];
list.Add(pair);
sum += temp[0];
}
list = list.OrderByDescending(l => l.B).ToList();
for (int i = 0; i < N; i++) {
if (sum > list[i].B) {
ans = "No";
break;
} else {
sum -= list[i].A;
}
}
//ここまで
Console.WriteLine(ans);
Console.ReadKey();
}
}
class Pair {
public long A;
public long B;
}
class Func {
long mod = 1000000007;
static public void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
static public int Factorial(int a) {
return a == 1 ? a : a * Factorial(a - 1);
}
static public int Conbin(int n, int m) {
return Factorial(n) / (Factorial(n - m) * Factorial(m));
}
static public void Factoring(long num, ref long[] vs) {
if (num == 1) {
vs[1]++;
}
for (long i = 2; i < (long)Math.Sqrt(num); i++) {
if (num % i == 0) {
vs[i]++;
Factoring(num / i, ref vs);
}
}
vs[1]++;
}
}
class IO {
static public string ReadLineToString() { return Console.ReadLine(); }
static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
static public string[] ReadLineToStringArray() {
return Console.ReadLine().Split(' ').ToArray();
}
static public int[] ReadLineToIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] ReadLineToLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public List<string> ReadLineToStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> ReadLineToIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> ReadLineToLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
}
}
|
[["-", 75, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 214, 141, 22]]
| 8
| 742
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
public static void Main() {
int N = int.Parse(Console.ReadLine());
List<Tuple<int, int>> K = new List<Tuple<int, int>>() { Capacity = N };
for (int i = 0; i < N; i++) {
var s = Console.ReadLine().Split(' ');
int A = int.Parse(s[0]);
int B = int.Parse(s[1]);
K.Add(new Tuple<int, int>(B, A));
}
K.Sort((x, y) => {
if (x.Item1 < y.Item1)
return 1;
else if (x.Item1 > y.Item1)
return -1;
else {
if (x.Item2 < y.Item2)
return 1;
else if (x.Item2 > y.Item2)
return -1;
else
return 0;
}
});
int j, CT = K[0].Item1;
for (j = 0; j < N; j++) {
CT = Math.Min(CT, K[0].Item1) - K[j].Item2;
}
if (j == N && CT >= 0)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
public static void Main() {
int N = int.Parse(Console.ReadLine());
List<Tuple<int, int>> K = new List<Tuple<int, int>>() { Capacity = N };
for (int i = 0; i < N; i++) {
var s = Console.ReadLine().Split(' ');
int A = int.Parse(s[0]);
int B = int.Parse(s[1]);
K.Add(new Tuple<int, int>(B, A));
}
K.Sort((x, y) => {
if (x.Item1 < y.Item1)
return 1;
else if (x.Item1 > y.Item1)
return -1;
else {
if (x.Item2 < y.Item2)
return 1;
else if (x.Item2 > y.Item2)
return -1;
else
return 0;
}
});
int j, CT = K[0].Item1;
for (j = 0; j < N; j++) {
CT = Math.Min(CT, K[j].Item1) - K[j].Item2;
}
if (j == N && CT >= 0)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
[["-", 0, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 214, 205, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 307
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProblemD {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var As = new int[N];
var Bs = new int[N];
var dicts = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
var read =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
As[i] = read[0];
Bs[i] = read[1];
if (dicts.Keys.Contains(read[1]))
dicts[read[1]] += read[0];
else
dicts.Add(read[1], read[0]);
}
var dictList = dicts.OrderBy(x => x.Key).ToList();
var sums = 0;
var isYes = true;
foreach (var d in dictList) {
sums += d.Value;
if (d.Key < sums) {
isYes = false;
break;
}
}
Console.WriteLine(isYes ? "Yse" : "No");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProblemD {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var As = new int[N];
var Bs = new int[N];
var dicts = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
var read =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
As[i] = read[0];
Bs[i] = read[1];
if (dicts.Keys.Contains(read[1]))
dicts[read[1]] += read[0];
else
dicts.Add(read[1], read[0]);
}
var dictList = dicts.OrderBy(x => x.Key).ToList();
var sums = 0;
var isYes = true;
foreach (var d in dictList) {
sums += d.Value;
if (d.Key < sums) {
isYes = false;
break;
}
}
Console.WriteLine(isYes ? "Yes" : "No");
}
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222]]
| 8
| 276
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace test {
class Program {
static void Main(string[] args) {
var N = ReadInt();
var AB = new List<int[]>();
for (int i = 0; i < N; i++) {
var input = ReadArrayInt();
var A = input[0];
var B = input[1];
AB.Add(new int[] { A, B });
}
AB = AB.OrderBy(l => l[1]).ThenBy(l => l[0]).ToList();
var time = 0L;
for (int i = 0; i < N; i++) {
time += AB[i][0];
if (time > AB[i][1]) {
Console.WriteLine("Bad");
return;
}
}
Console.WriteLine("Yes");
Console.ReadLine();
}
static string Read() { return Console.ReadLine(); }
static int ReadInt() { return int.Parse(Read()); }
static long ReadLong() { return long.Parse(Read()); }
static int[] ReadArrayInt() {
return Read().Split(' ').Select(s => int.Parse(s)).ToArray();
}
static long[] ReadArrayLong() {
return Read().Split(' ').Select(s => long.Parse(s)).ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace test {
class Program {
static void Main(string[] args) {
var N = ReadInt();
var AB = new List<int[]>();
for (int i = 0; i < N; i++) {
var input = ReadArrayInt();
var A = input[0];
var B = input[1];
AB.Add(new int[] { A, B });
}
AB = AB.OrderBy(l => l[1]).ThenBy(l => l[0]).ToList();
var time = 0L;
for (int i = 0; i < N; i++) {
time += AB[i][0];
if (time > AB[i][1]) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
Console.ReadLine();
}
static string Read() { return Console.ReadLine(); }
static int ReadInt() { return int.Parse(Read()); }
static long ReadLong() { return long.Parse(Read()); }
static int[] ReadArrayInt() {
return Read().Split(' ').Select(s => int.Parse(s)).ToArray();
}
static long[] ReadArrayLong() {
return Read().Split(' ').Select(s => long.Parse(s)).ToArray();
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 329
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ABC_131 {
class E {
static void Main(string[] args) { Method(args); }
static void Method(string[] args) {
int[] nk = ReadInts();
int n = nk[0];
int k = nk[1];
int max = (n - 1) * (n - 2) / 2;
if (k > max) {
WriteLine(-1);
}
int delta = max - k;
int m = delta + n - 1;
WriteLine(m);
for (int i = 1; i < n; i++) {
WriteLine(1 + " " + (i + 1));
}
if (delta == 0)
return;
for (int i = 1; i < n; i++) {
for (int j = i + 1; j < n; j++) {
WriteLine((i + 1) + " " + (j + 1));
delta--;
if (delta == 0)
return;
}
}
}
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_131 {
class E {
static void Main(string[] args) { Method(args); }
static void Method(string[] args) {
int[] nk = ReadInts();
int n = nk[0];
int k = nk[1];
int max = (n - 1) * (n - 2) / 2;
if (k > max) {
WriteLine(-1);
return;
}
int delta = max - k;
int m = delta + n - 1;
WriteLine(m);
for (int i = 1; i < n; i++) {
WriteLine(1 + " " + (i + 1));
}
if (delta == 0)
return;
for (int i = 1; i < n; i++) {
for (int j = i + 1; j < n; j++) {
WriteLine((i + 1) + " " + (j + 1));
delta--;
if (delta == 0)
return;
}
}
}
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, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 431
| 2
|
using System;
using System.Collections.Generic;
public class Program {
public void Solve() {
var sc = new Scanner();
int N = sc.NextInt();
HashSet<int> X, Y;
X = new HashSet<int>();
Y = new HashSet<int>();
var uf = new UnionFind(200001);
for (int i = 0; i < N; i++) {
int x = sc.NextInt();
int y = sc.NextInt();
X.Add(x);
Y.Add(y);
uf.Union(x, y + 100000);
}
var mapX = new HashMap<int, int>();
var mapY = new HashMap<int, int>();
foreach (int i in X) {
mapX[uf.Find(i)]++;
}
foreach (int i in Y) {
mapY[uf.Find(i)]++;
}
long ans = 0;
foreach (KeyValuePair<int, int> pair in mapX) {
// Console.WriteLine($"{pair.Value} {mapY[pair.Key]}");
ans += (long)pair.Value * mapY[pair.Key];
}
Console.WriteLine(ans - N);
}
public static void Main(string[] args) { new Program().Solve(); }
}
class HashMap<K, V> : Dictionary<K, V> {
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = default(V);
}
set { base[i] = value; }
}
}
class UnionFind {
private int[] Par, Rank;
public UnionFind(int max) {
Par = new int[max];
Rank = new int[max];
for (int i = 0; i < max; i++) {
Par[i] = i;
}
}
public int Find(int n) {
if (Par[n] == n) {
return n;
} else {
return Find(Par[n]);
}
}
public bool Same(int a, int b) { return Find(a) == Find(b); }
public void Union(int a, int b) {
a = Find(a);
b = Find(b);
if (a == b)
return;
if (Rank[a] < Rank[b]) {
Par[a] = b;
} else {
Par[b] = a;
if (Rank[a] == Rank[b])
Rank[a]++;
}
}
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region スペース区切りで取得
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region 型変換
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region 配列取得
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
using System;
using System.Collections.Generic;
public class Program {
public void Solve() {
var sc = new Scanner();
int N = sc.NextInt();
HashSet<int> X, Y;
X = new HashSet<int>();
Y = new HashSet<int>();
var uf = new UnionFind(200001);
for (int i = 0; i < N; i++) {
int x = sc.NextInt();
int y = sc.NextInt();
X.Add(x);
Y.Add(y);
uf.Union(x, y + 100000);
}
var mapX = new HashMap<int, int>();
var mapY = new HashMap<int, int>();
foreach (int i in X) {
mapX[uf.Find(i)]++;
}
foreach (int i in Y) {
mapY[uf.Find(i + 100000)]++;
}
long ans = 0;
foreach (KeyValuePair<int, int> pair in mapX) {
// Console.WriteLine($"{pair.Value} {mapY[pair.Key]}");
ans += (long)pair.Value * mapY[pair.Key];
}
Console.WriteLine(ans - N);
}
public static void Main(string[] args) { new Program().Solve(); }
}
class HashMap<K, V> : Dictionary<K, V> {
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = default(V);
}
set { base[i] = value; }
}
}
class UnionFind {
private int[] Par, Rank;
public UnionFind(int max) {
Par = new int[max];
Rank = new int[max];
for (int i = 0; i < max; i++) {
Par[i] = i;
}
}
public int Find(int n) {
if (Par[n] == n) {
return n;
} else {
return Find(Par[n]);
}
}
public bool Same(int a, int b) { return Find(a) == Find(b); }
public void Union(int a, int b) {
a = Find(a);
b = Find(b);
if (a == b)
return;
if (Rank[a] < Rank[b]) {
Par[a] = b;
} else {
Par[b] = a;
if (Rank[a] == Rank[b])
Rank[a]++;
}
}
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region スペース区切りで取得
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region 型変換
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region 配列取得
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 947
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Sandbox {
internal class Program {
private static readonly int MaxNumber = 10001;
private static readonly List<int>[] XtoY =
Enumerable.Range(0, MaxNumber).Select(_ => new List<int>()).ToArray();
private static readonly List<int>[] YtoX =
Enumerable.Range(0, MaxNumber).Select(_ => new List<int>()).ToArray();
private static readonly bool[] VisitedX = new bool[MaxNumber];
private static readonly bool[] VisitedY = new bool[MaxNumber];
private static void Main(string[] args) {
var scanner = new Scanner();
var n = scanner.GetNextAsInt();
var maxX = int.MinValue;
var maxY = int.MinValue;
for (var i = 0; i < n; i++) {
var xi = scanner.GetNextAsInt();
var yi = scanner.GetNextAsInt();
XtoY[xi].Add(yi);
YtoX[yi].Add(xi);
maxX = Math.Max(xi, maxX);
maxY = Math.Max(xi, maxY);
}
var result = 0L;
for (var xx = 1; xx <= maxX; xx++) {
var countX = 0;
var countY = 0;
DfsX(xx, ref countX, ref countY);
result += (long)countX * (long)countY;
}
result -= n;
Console.WriteLine(result);
}
private static void DfsX(int x, ref int countX, ref int countY) {
if (VisitedX[x]) {
return;
}
countX++;
VisitedX[x] = true;
foreach (var yy in XtoY[x]) {
DfsY(yy, ref countX, ref countY);
}
}
private static void DfsY(int y, ref int countX, ref int countY) {
if (VisitedY[y]) {
return;
}
countY++;
VisitedY[y] = true;
foreach (var xx in YtoX[y]) {
DfsX(xx, ref countX, ref countY);
}
}
#region String Scanner
public class Scanner {
private const char Separator = ' ';
private readonly StreamReader _Stream =
new StreamReader(Console.OpenStandardInput());
private int _Pos;
private string[] _Line = new string[0];
#region get a element
public string GetNext() {
// ReSharper disable once InvertIf
if (this._Pos >= this._Line.Length) {
// ReSharper disable once PossibleNullReferenceException
this._Line = this._Stream.ReadLine().Split(Separator);
this._Pos = 0;
}
return this._Line[this._Pos++];
}
public int GetNextAsInt() { return int.Parse(this.GetNext()); }
public long GetNextAsLong() { return long.Parse(this.GetNext()); }
public double GetNextAsDouble() { return double.Parse(this.GetNext()); }
#endregion
#region get array
public string[] ToArrayFromNextLine() {
if (this._Pos >= this._Line.Length) {
// ReSharper disable once PossibleNullReferenceException
this._Line = this._Stream.ReadLine().Split(Separator);
}
this._Pos = this._Line.Length;
return this._Line;
}
public int[] ToIntArrayFromNextLine() {
return ToIntArray(this.ToArrayFromNextLine());
}
public long[] ToLongArrayFromNextLine() {
return ToLongArray(this.ToArrayFromNextLine());
}
public double[] ToDoubleArrayFromNextLine() {
return ToDoubleArray(this.ToArrayFromNextLine());
}
#endregion
#region convert array
private static int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private static long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private static double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Sandbox {
internal class Program {
private static readonly int MaxNumber = 100001;
private static readonly List<int>[] XtoY =
Enumerable.Range(0, MaxNumber).Select(_ => new List<int>()).ToArray();
private static readonly List<int>[] YtoX =
Enumerable.Range(0, MaxNumber).Select(_ => new List<int>()).ToArray();
private static readonly bool[] VisitedX = new bool[MaxNumber];
private static readonly bool[] VisitedY = new bool[MaxNumber];
private static void Main(string[] args) {
var scanner = new Scanner();
var n = scanner.GetNextAsInt();
var maxX = int.MinValue;
var maxY = int.MinValue;
for (var i = 0; i < n; i++) {
var xi = scanner.GetNextAsInt();
var yi = scanner.GetNextAsInt();
XtoY[xi].Add(yi);
YtoX[yi].Add(xi);
maxX = Math.Max(xi, maxX);
maxY = Math.Max(xi, maxY);
}
var result = 0L;
for (var xx = 1; xx <= maxX; xx++) {
var countX = 0;
var countY = 0;
DfsX(xx, ref countX, ref countY);
result += (long)countX * (long)countY;
}
result -= n;
Console.WriteLine(result);
}
private static void DfsX(int x, ref int countX, ref int countY) {
if (VisitedX[x]) {
return;
}
countX++;
VisitedX[x] = true;
foreach (var yy in XtoY[x]) {
DfsY(yy, ref countX, ref countY);
}
}
private static void DfsY(int y, ref int countX, ref int countY) {
if (VisitedY[y]) {
return;
}
countY++;
VisitedY[y] = true;
foreach (var xx in YtoX[y]) {
DfsX(xx, ref countX, ref countY);
}
}
#region String Scanner
public class Scanner {
private const char Separator = ' ';
private readonly StreamReader _Stream =
new StreamReader(Console.OpenStandardInput());
private int _Pos;
private string[] _Line = new string[0];
#region get a element
public string GetNext() {
// ReSharper disable once InvertIf
if (this._Pos >= this._Line.Length) {
// ReSharper disable once PossibleNullReferenceException
this._Line = this._Stream.ReadLine().Split(Separator);
this._Pos = 0;
}
return this._Line[this._Pos++];
}
public int GetNextAsInt() { return int.Parse(this.GetNext()); }
public long GetNextAsLong() { return long.Parse(this.GetNext()); }
public double GetNextAsDouble() { return double.Parse(this.GetNext()); }
#endregion
#region get array
public string[] ToArrayFromNextLine() {
if (this._Pos >= this._Line.Length) {
// ReSharper disable once PossibleNullReferenceException
this._Line = this._Stream.ReadLine().Split(Separator);
}
this._Pos = this._Line.Length;
return this._Line;
}
public int[] ToIntArrayFromNextLine() {
return ToIntArray(this.ToArrayFromNextLine());
}
public long[] ToLongArrayFromNextLine() {
return ToLongArray(this.ToArrayFromNextLine());
}
public double[] ToDoubleArrayFromNextLine() {
return ToDoubleArray(this.ToArrayFromNextLine());
}
#endregion
#region convert array
private static int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private static long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private static double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
}
#endregion
}
}
|
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 922
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace attocoda {
class Program {
static void Main(string[] args) {
int x, a;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
x = int.Parse(word[1]);
if (x < a)
Console.WriteLine(0);
else
Console.WriteLine(10);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace attocoda {
class Program {
static void Main(string[] args) {
int x, a;
var word = Console.ReadLine().Split(' ');
x = int.Parse(word[0]);
a = int.Parse(word[1]);
if (x < a)
Console.WriteLine(0);
else
Console.WriteLine(10);
Console.ReadKey();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22]]
| 8
| 118
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ACB130A {
class Program {
static void Main(string[] args) {
int x, a;
var word = Console.ReadLine().Split(' ');
x = int.Parse(word[0]);
a = int.Parse(word[1]);
if (x < a) {
Console.WriteLine(0);
} else if (x > a) {
Console.WriteLine(10);
}
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ACB130A {
class Program {
static void Main(string[] args) {
int x, a;
var word = Console.ReadLine().Split(' ');
x = int.Parse(word[0]);
a = int.Parse(word[1]);
if (x < a) {
Console.WriteLine(0);
} else if (x >= a) {
Console.WriteLine(10);
}
Console.ReadKey();
}
}
}
|
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 20]]
| 8
| 128
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABCA130 {
class Program {
static void Main(string[] args) {
int a, A, X;
var word = Console.ReadLine().Split();
A = int.Parse(word[0]);
X = int.Parse(word[1]);
if (X < A)
a = 10;
else
a = 0;
Console.WriteLine(a);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABCA130 {
class Program {
static void Main(string[] args) {
int a, A, X;
var word = Console.ReadLine().Split();
A = int.Parse(word[0]);
X = int.Parse(word[1]);
if (X <= A)
a = 10;
else
a = 0;
Console.WriteLine(a);
Console.ReadKey();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 118
| 2
|
using System;
class Program {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
if (a > b) {
Console.WriteLine(10);
} else {
Console.WriteLine(0);
}
}
}
|
using System;
class Program {
static void Main() {
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
if (a >= b) {
Console.WriteLine(10);
} else {
Console.WriteLine(0);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 83
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var a = CinTAr();
if (a[0] < a[1]) {
Cout("0");
} else {
Cout("0");
}
}
static string Cin() { return Console.ReadLine(); }
static string[] CinAr() { return Console.ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return int.Parse(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static void Cout(string s) { Console.WriteLine(s); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var a = CinTAr();
if (a[0] < a[1]) {
Cout("0");
} else {
Cout("10");
}
}
static string Cin() { return Console.ReadLine(); }
static string[] CinAr() { return Console.ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return int.Parse(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static void Cout(string s) { Console.WriteLine(s); }
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 214
| 2
|
using System;
using System.Linq;
public class Test {
public static void Main() {
// your code goes here
var b = Console.ReadLine().Split().Select(y => int.Parse(y)).ToArray();
int x = b[0];
int a = b[1];
if (x < a) {
Console.WriteLine("10");
} else {
Console.WriteLine("0");
}
}
}
|
using System;
using System.Linq;
public class Test {
public static void Main() {
// your code goes here
var b = Console.ReadLine().Split().Select(y => int.Parse(y)).ToArray();
int x = b[0];
int a = b[1];
if (x < a) {
Console.WriteLine("0");
} else {
Console.WriteLine("10");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 96
| 4
|
using System;
using System.Collections.Generic;
using static AtCoderer.Exter;
using static System.Math;
using System.Linq;
namespace AtCoderer {
public class App {
public static void Solve() {
var r = readarr;
Console.WriteLine(r[0] <= r[1] ? 10 : 0);
}
public static void Main(string[] args) {
Solve();
Console.ReadKey();
}
}
public static class Exter {
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int a,
int b) => b == 0 ? a : GcdRecursive(b, a % b);
public static void EnumArr<t>(this IEnumerable<t> v) {
Console.WriteLine(string.Join(",", v));
}
public static string ToString(this IEnumerable<char> v) {
return string.Join(",", v);
}
public static int[] readarr {
get {
return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
}
}
public class UnionFind {
private int[] Parent;
private int GetRoot(int v) {
if (Parent[v] < 0)
return v;
else
return Parent[v] = GetRoot(Parent[v]);
}
public UnionFind(int size) {
Parent = new int[size];
for (int i = 0; i < size; i++)
Parent[i] = -1;
}
public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); }
public void Connect(int a, int b) {
a = GetRoot(a);
b = GetRoot(b);
if (a == b)
return;
if (Parent[b] < Parent[a]) {
Parent[b] += Parent[a];
Parent[a] = b;
} else {
Parent[a] += Parent[b];
Parent[b] = a;
}
}
public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; }
}
}
}
|
using System;
using System.Collections.Generic;
using static AtCoderer.Exter;
using static System.Math;
using System.Linq;
namespace AtCoderer {
public class App {
public static void Solve() {
var r = readarr;
Console.WriteLine(r[0] >= r[1] ? 10 : 0);
}
public static void Main(string[] args) {
Solve();
Console.ReadKey();
}
}
public static class Exter {
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int a,
int b) => b == 0 ? a : GcdRecursive(b, a % b);
public static void EnumArr<t>(this IEnumerable<t> v) {
Console.WriteLine(string.Join(",", v));
}
public static string ToString(this IEnumerable<char> v) {
return string.Join(",", v);
}
public static int[] readarr {
get {
return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
}
}
public class UnionFind {
private int[] Parent;
private int GetRoot(int v) {
if (Parent[v] < 0)
return v;
else
return Parent[v] = GetRoot(Parent[v]);
}
public UnionFind(int size) {
Parent = new int[size];
for (int i = 0; i < size; i++)
Parent[i] = -1;
}
public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); }
public void Connect(int a, int b) {
a = GetRoot(a);
b = GetRoot(b);
if (a == b)
return;
if (Parent[b] < Parent[a]) {
Parent[b] += Parent[a];
Parent[a] = b;
} else {
Parent[a] += Parent[b];
Parent[b] = a;
}
}
public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; }
}
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
| 8
| 534
| 2
|
using System;
namespace Atcoder_program_test_Csharp {
using System;
class Program {
static void Main(string[] args) {
string line = Console.ReadLine();
string[] str = line.Split(' ');
int X = int.Parse(str[0]);
int A = int.Parse(str[1]);
if (X < A)
Console.Write("10");
if (X >= A)
Console.Write("0");
}
}
}
|
using System;
namespace Atcoder_program_test_Csharp {
using System;
class Program {
static void Main(string[] args) {
string line = Console.ReadLine();
string[] str = line.Split(' ');
int X = int.Parse(str[0]);
int A = int.Parse(str[1]);
if (X >= A)
Console.Write("10");
if (X < A)
Console.Write("0");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 104
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC {
class ProgramB {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var list =
Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
var result = int.MaxValue;
for (var t = 1; t < n; t++) {
var s1 = 0;
var s2 = 0;
for (var j = 0; j < n; j++) {
if (t >= list[j])
s1 += list[j];
else
s2 += list[j];
}
result = Math.Min(result, Math.Abs(s1 - s2));
}
Console.WriteLine(result);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC {
class ProgramB {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var list =
Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
var result = int.MaxValue;
for (var t = 0; t < n - 1; t++) {
var s1 = 0;
var s2 = 0;
for (var j = 0; j < n; j++) {
if (t >= j)
s1 += list[j];
else
s2 += list[j];
}
result = Math.Min(result, Math.Abs(s1 - s2));
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 178
| 7
|
using System;
public class AtCoderB {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] weights = new int[n];
{
var line = Console.ReadLine();
var words = line.Split(' ');
for (int i = 0; i < n; i++) {
weights[i] = int.Parse(words[i]);
}
}
int answer = int.MaxValue;
for (int i = 0; i < n; i++) {
int sumA = 0;
for (int j = 0; j < i; j++) {
sumA += weights[j];
}
int sumB = 0;
for (int k = n; k < n; k++) {
sumB += weights[k];
}
answer = Math.Min(answer, Math.Abs(sumA - sumB));
}
Console.WriteLine(answer);
}
}
|
using System;
public class AtCoderB {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] weights = new int[n];
{
var line = Console.ReadLine();
var words = line.Split(' ');
for (int i = 0; i < n; i++) {
weights[i] = int.Parse(words[i]);
}
}
int answer = int.MaxValue;
for (int i = 0; i < n; i++) {
int sumA = 0;
for (int j = 0; j < i; j++) {
sumA += weights[j];
}
int sumB = 0;
for (int k = i; k < n; k++) {
sumB += weights[k];
}
answer = Math.Min(answer, Math.Abs(sumA - sumB));
}
Console.WriteLine(answer);
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22]]
| 8
| 198
| 2
|
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B_Balance {
class Program {
static void Main(string[] args) {
int total = int.Parse(ReadLine());
string input = ReadLine();
string[] array = input.Split(' ');
int[] n = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
n[i] = int.Parse(array[i]);
}
int a = 0;
int b = 0;
int answerA = 0;
int answerB = 0;
int count = 0;
for (int j = 1; j < array.Length; j++) {
for (int k = 0; k <= j - 1; k++) {
a += n[k];
}
for (int m = j; m < array.Length; m++) {
b += n[m];
}
count++;
if (a >= b) {
break;
}
a = 0;
b = 0;
}
int c = a - n[count];
int d = b + n[count];
answerA = System.Math.Abs(c - d);
answerB = System.Math.Abs(a - b);
if (answerA < answerB) {
WriteLine(answerA);
} else {
WriteLine(answerB);
}
ReadKey();
}
}
}
|
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B_Balance {
class Program {
static void Main(string[] args) {
int total = int.Parse(ReadLine());
string input = ReadLine();
string[] array = input.Split(' ');
int[] n = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
n[i] = int.Parse(array[i]);
}
int a = 0;
int b = 0;
int answerA = 0;
int answerB = 0;
int count = 0;
for (int j = 1; j < array.Length; j++) {
for (int k = 0; k <= j - 1; k++) {
a += n[k];
}
for (int m = j; m < array.Length; m++) {
b += n[m];
}
count++;
if (a >= b) {
break;
}
a = 0;
b = 0;
}
int c = a - n[count - 1];
int d = b + n[count - 1];
answerA = System.Math.Abs(c - d);
answerB = System.Math.Abs(a - b);
if (answerA < answerB) {
WriteLine(answerA);
} else {
WriteLine(answerB);
}
ReadKey();
}
}
}
|
[["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 313
| 4
|
using System;
using System.Linq;
public class Hello {
public static void Main() {
// Your code here!
int n = int.Parse(Console.ReadLine());
int ans = 10000;
string[] mofu = Console.ReadLine().Split(' ');
int[] mofii = mofu.Select(int.Parse).ToArray();
for (int i = 1; i < n; i++) {
int t = i;
int w1 = 0;
int w2 = 0;
for (int j = 0; j < t; j++) {
w1 += mofii[j];
}
for (int j = t; j < n; j++) {
w2 += mofii[j];
}
w1 = w1 - w2;
if (w1 < 0) {
w1 = -w1;
}
if (ans > w1) {
ans = w1;
}
}
System.Console.WriteLine("ans:" + ans);
}
}
|
using System;
using System.Linq;
public class Hello {
public static void Main() {
// Your code here!
int n = int.Parse(Console.ReadLine());
int ans = 10000;
string[] mofu = Console.ReadLine().Split(' ');
int[] mofii = mofu.Select(int.Parse).ToArray();
for (int i = 1; i < n; i++) {
int t = i;
int w1 = 0;
int w2 = 0;
for (int j = 0; j < t; j++) {
w1 += mofii[j];
}
for (int j = t; j < n; j++) {
w2 += mofii[j];
}
w1 = w1 - w2;
if (w1 < 0) {
w1 = -w1;
}
if (ans > w1) {
ans = w1;
}
}
System.Console.WriteLine(ans);
}
}
|
[["-", 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]]
| 8
| 198
| 4
|
namespace ABC128.B {
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
public class Program {
public static void Main(string[] args) {
var n = ReadInputAsInt();
var w = ReadInputsAsInt().ToList();
WriteLine(Solve(n, w));
}
public static int Solve(int n, List<int> w) {
return Enumerable.Range(0, n - 1)
.Select(k => Abs(w.Take(k).Sum() - w.Skip(k).Sum()))
.Min();
}
static IEnumerable<int>
ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x));
static int ReadInputAsInt() => int.Parse(ReadLine());
}
}
|
namespace ABC128.B {
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
public class Program {
public static void Main(string[] args) {
var n = ReadInputAsInt();
var w = ReadInputsAsInt().ToList();
WriteLine(Solve(n, w));
}
public static int Solve(int n, List<int> w) {
return Enumerable.Range(1, n - 1)
.Select(k => Abs(w.Take(k).Sum() - w.Skip(k).Sum()))
.Min();
}
static IEnumerable<int>
ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x));
static int ReadInputAsInt() => int.Parse(ReadLine());
}
}
|
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 187
| 2
|
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());
int n = scan.Integer();
int m = scan.Integer();
int[] a = scan.Integer(m, true);
Mlong[] dp = new Mlong[n];
bool[] dame = new bool[n];
for (int i = 0; i < n; i++) {
dp[i] = 0;
}
for (int i = 0; i < m; i++) {
dame[a[i]] = true;
}
if (!dame[0])
dp[0] = 1;
if (n > 2 && !dame[1])
dp[1] = 1;
for (int i = 0; i < n; i++) {
if (i + 2 < n && !dame[i + 2]) {
dp[i + 2] += dp[i];
}
if (i + 1 < n && !dame[i + 1]) {
dp[i + 1] += dp[i];
}
}
Console.WriteLine(dp[n - 1].num);
}
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 string[] Scan(long n) {
string[] str = new string[n];
for (long i = 0; i < n; i++) {
str[i] = Scan();
}
return str;
}
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 {
public 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());
int n = scan.Integer();
int m = scan.Integer();
int[] a = scan.Integer(m, true);
Mlong[] dp = new Mlong[n];
bool[] dame = new bool[n];
for (int i = 0; i < n; i++) {
dp[i] = 0;
}
for (int i = 0; i < m; i++) {
dame[a[i]] = true;
}
if (!dame[0])
dp[0] = 1;
if (n >= 2 && !dame[1])
dp[1] = 1;
for (int i = 0; i < n; i++) {
if (i + 2 < n && !dame[i + 2]) {
dp[i + 2] += dp[i];
}
if (i + 1 < n && !dame[i + 1]) {
dp[i + 1] += dp[i];
}
}
Console.WriteLine(dp[n - 1].num);
}
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 string[] Scan(long n) {
string[] str = new string[n];
for (long i = 0; i < n; i++) {
str[i] = Scan();
}
return str;
}
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 {
public 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, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20]]
| 8
| 13,912
| 2
|
using System;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = input[0];
var M = input[1];
var mod = 1000000007;
var ans = new Ans[N + 1];
for (int i = 1; i <= N; i++) {
ans[i] = new Ans() { Count = 0, Available = true };
}
for (int i = 0; i < M; i++) {
ans[int.Parse(Console.ReadLine())].Available = false;
}
if (ans[1].Available)
ans[1].Count = 1;
if (ans[2].Available)
ans[2].Count = ans[1].Count + 1;
for (int i = 3; i <= N; i++) {
if (ans[i].Available)
ans[i].Count = (ans[i - 1].Count + ans[i - 2].Count) % mod;
}
Console.WriteLine(ans[N].Count);
}
class Ans {
public long Count { get; set; }
public bool Available { get; set; }
}
}
}
|
using System;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
var N = input[0];
var M = input[1];
var mod = 1000000007;
var ans = new Ans[N + 1];
for (int i = 1; i <= N; i++) {
ans[i] = new Ans() { Count = 0, Available = true };
}
for (int i = 0; i < M; i++) {
ans[int.Parse(Console.ReadLine())].Available = false;
}
if (ans[1].Available)
ans[1].Count = 1;
if (N >= 2 && ans[2].Available)
ans[2].Count = ans[1].Count + 1;
for (int i = 3; i <= N; i++) {
if (ans[i].Available)
ans[i].Count = (ans[i - 1].Count + ans[i - 2].Count) % mod;
}
Console.WriteLine(ans[N].Count);
}
class Ans {
public long Count { get; set; }
public bool Available { get; set; }
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 283
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
public class Program {
static void Main(string[] args) {
const int x = 1000000007;
int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
int N = vs[0];
int M = vs[1];
int[,] pt = new int[N + 1, 2];
pt[0, 0] = 0;
pt[0, 1] = 1;
pt[1, 0] = 1;
pt[1, 1] = 0;
pt[2, 0] = 1;
pt[2, 1] = 1;
for (int i = 3; i <= N; i++) {
pt[i, 0] = (pt[i - 1, 0] + pt[i - 1, 1]) % x;
pt[i, 1] = pt[i - 1, 0];
}
int pos = 0, mv = 0;
long ans = 1;
for (int i = 0; i < M; i++) {
int a = int.Parse(Console.ReadLine());
if (a == pos) {
Console.WriteLine(0);
return;
}
mv = a - 1 - pos;
ans = ans * (pt[mv, 0] + pt[mv, 1]) % x;
pos = a + 1;
}
mv = N - pos;
ans = ans * (pt[mv, 0] + pt[mv, 1]) % x;
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
public class Program {
static void Main(string[] args) {
const int x = 1000000007;
int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
int N = vs[0];
int M = vs[1];
int[,] pt = new int[N + 3, 2];
pt[0, 0] = 0;
pt[0, 1] = 1;
pt[1, 0] = 1;
pt[1, 1] = 0;
pt[2, 0] = 1;
pt[2, 1] = 1;
for (int i = 3; i <= N; i++) {
pt[i, 0] = (pt[i - 1, 0] + pt[i - 1, 1]) % x;
pt[i, 1] = pt[i - 1, 0];
}
int pos = 0, mv = 0;
long ans = 1;
for (int i = 0; i < M; i++) {
int a = int.Parse(Console.ReadLine());
if (a == pos) {
Console.WriteLine(0);
return;
}
mv = a - 1 - pos;
ans = ans * (pt[mv, 0] + pt[mv, 1]) % x;
pos = a + 1;
}
mv = N - pos;
ans = ans * (pt[mv, 0] + pt[mv, 1]) % x;
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
| 8
| 356
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
int N = vals[0];
int M = vals[1];
int mod = 1000000007;
long[] d = new long[N + 1];
for (int i = 0; i < M; i++) {
int a = int.Parse(Console.ReadLine());
d[a] = -1;
}
d[0] = 1;
for (int i = 1; i < N; i++) {
if (d[i + 1] == -1)
d[i + 1] = 0;
else {
if (i == 1)
d[i + 1] = d[i];
else
d[i + 1] = (d[i] + d[i - 1]) % mod;
}
}
Console.Write(d[N]);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
int N = vals[0];
int M = vals[1];
int mod = 1000000007;
long[] d = new long[N + 1];
for (int i = 0; i < M; i++) {
int a = int.Parse(Console.ReadLine());
d[a] = -1;
}
d[0] = 1;
for (int i = 0; i < N; i++) {
if (d[i + 1] == -1)
d[i + 1] = 0;
else {
if (i == 0)
d[i + 1] = d[i];
else
d[i + 1] = (d[i] + d[i - 1]) % mod;
}
}
Console.Write(d[N]);
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 230
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
Func cin2;
void calc() {
cin = new Scanner();
int[] NM = cin.ArrayInt(2, 0);
int N = NM[0];
int M = NM[1];
int[] a = new int[N];
long[] ans = new long[N];
bool broken = false;
if (M > 0) {
for (int i = 0; i < M; i++)
a[cin.nextInt() - 1] = 1;
}
if (a[0] == 0 && a[1] == 0) {
ans[0] = 1;
ans[1] = 2;
} else if (a[0] == 1 && a[1] == 0) {
ans[0] = 0;
ans[1] = 1;
} else if (a[0] == 0 && a[1] == 1) {
ans[0] = 1;
ans[1] = 0;
}
for (int i = 2; i < N; i++) {
if (a[i] == 0)
ans[i] = ans[i - 2] + ans[i - 1];
if (a[i - 1] == 1 && a[i] == 1) {
broken = true;
break;
}
ans[i] %= 1000000007;
}
if (a[0] == 1 && a[1] == 1)
broken = true;
if (broken == true)
Console.WriteLine(0);
else
Console.WriteLine(ans[N - 1]);
}
}
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 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 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 Answer {
public static void Int2DArrayAns(int[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
} // Answer.IntArrayAns(x);
public static void Char2DArrayAns(char[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
}
}
class Func {
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
Func cin2;
void calc() {
cin = new Scanner();
int[] NM = cin.ArrayInt(2, 0);
int N = NM[0];
int M = NM[1];
int[] a = new int[N + 1];
long[] ans = new long[N + 1];
bool broken = false;
if (M > 0) {
for (int i = 0; i < M; i++)
a[cin.nextInt() - 1] = 1;
}
if (a[0] == 0 && a[1] == 0) {
ans[0] = 1;
ans[1] = 2;
} else if (a[0] == 1 && a[1] == 0) {
ans[0] = 0;
ans[1] = 1;
} else if (a[0] == 0 && a[1] == 1) {
ans[0] = 1;
ans[1] = 0;
}
for (int i = 2; i < N; i++) {
if (a[i] == 0)
ans[i] = ans[i - 2] + ans[i - 1];
if (a[i - 1] == 1 && a[i] == 1) {
broken = true;
break;
}
ans[i] %= 1000000007;
}
if (a[0] == 1 && a[1] == 1)
broken = true;
if (broken == true)
Console.WriteLine(0);
else
Console.WriteLine(ans[N - 1]);
}
}
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 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 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 Answer {
public static void Int2DArrayAns(int[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
} // Answer.IntArrayAns(x);
public static void Char2DArrayAns(char[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
}
}
class Func {
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
| 8
| 992
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) { A(); }
static void A() {
var NM = ReadSplitInt();
var N = NM[0];
var M = NM[1];
var a = new int[N + 1];
for (int i = 0; i < M; i++)
a[ReadInt()] = 1;
var dp = new long[N + 1];
for (int i = N; i >= 0; i--) {
if (a[i] == 1 && i == N)
break;
if (i == N) {
dp[N] = 1;
continue;
}
if (a[i] == 1)
continue;
if (i == N - 1) {
dp[i] = dp[i + 1];
continue;
}
dp[i] = dp[i + 1] + dp[i + 2];
}
Println(dp[0] % 1000000007);
}
static IEnumerable<int> Range(int start, int stop) {
if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
return new List<int>();
return Enumerable.Range(start, stop - start);
}
static bool IsDigit(string str) {
var i = 0;
return int.TryParse(str, out i);
}
static int SumDigits(long num) {
return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
}
static int[] ToIntArray(string str) {
return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
}
static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);
static bool IsPrime(int x) {
if (x <= 1 || (x != 2 && x % 2 == 0))
return false;
if (x == 2)
return true;
for (int i = 3; i < x; i += 2)
if (x % i == 0)
return false;
return true;
}
static string Read() => Console.ReadLine();
static int ReadInt() => int.Parse(Read());
static long ReadLong() => long.Parse(Read());
static List<string> ReadSplit() => Read().Split().ToList();
static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
static List<long>
ReadSplitLong() => Read().Split().Select(long.Parse).ToList();
static void Print(object value) => Console.Write(value.ToString());
static void Println(object value) => Console.WriteLine(value.ToString());
static string Join<T>(IEnumerable<T> list) => string.Join("", list);
}
public static class MyExtensions {
public static string Slice(this string str, int start = 0, int stop = 0) {
if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
return "";
if (stop == 0)
stop = str.Length;
return str.Substring(start, stop - start);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) { A(); }
static void A() {
var NM = ReadSplitInt();
var N = NM[0];
var M = NM[1];
var a = new int[N + 1];
for (int i = 0; i < M; i++)
a[ReadInt()] = 1;
var dp = new long[N + 1];
for (int i = N; i >= 0; i--) {
if (a[i] == 1 && i == N)
break;
if (i == N) {
dp[N] = 1;
continue;
}
if (a[i] == 1)
continue;
if (i == N - 1) {
dp[i] = dp[i + 1];
continue;
}
dp[i] = (dp[i + 1] + dp[i + 2]) % 1000000007;
}
Println(dp[0]);
}
static IEnumerable<int> Range(int start, int stop) {
if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
return new List<int>();
return Enumerable.Range(start, stop - start);
}
static bool IsDigit(string str) {
var i = 0;
return int.TryParse(str, out i);
}
static int SumDigits(long num) {
return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
}
static int[] ToIntArray(string str) {
return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
}
static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);
static bool IsPrime(int x) {
if (x <= 1 || (x != 2 && x % 2 == 0))
return false;
if (x == 2)
return true;
for (int i = 3; i < x; i += 2)
if (x % i == 0)
return false;
return true;
}
static string Read() => Console.ReadLine();
static int ReadInt() => int.Parse(Read());
static long ReadLong() => long.Parse(Read());
static List<string> ReadSplit() => Read().Split().ToList();
static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
static List<long>
ReadSplitLong() => Read().Split().Select(long.Parse).ToList();
static void Print(object value) => Console.Write(value.ToString());
static void Println(object value) => Console.WriteLine(value.ToString());
static string Join<T>(IEnumerable<T> list) => string.Join("", list);
}
public static class MyExtensions {
public static string Slice(this string str, int start = 0, int stop = 0) {
if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
return "";
if (stop == 0)
stop = str.Length;
return str.Substring(start, stop - start);
}
}
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 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, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 738
| 6
|
using System;
class ProgramC {
static void Main(string[] args) {
//まずは数字を読む
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int m = int.Parse(input[1]);
int[] fallstair = new int[m + 1];
long[] stair = new long[n + 1];
//とりあえず全部読みこむ
for (int i = 0; i < m; i++)
fallstair[i] = int.Parse(Console.ReadLine());
//ない階段を数える
int count = 0;
//結果出力
long output = 0;
//初期条件設定
if (m >= 2) {
if (fallstair[count] == 1 && fallstair[count + 1] == 2) {
output = 0;
goto end;
} else if (fallstair[count] == 1 && fallstair[count + 1] != 2) {
stair[0] = 0;
stair[1] = 1;
count++;
} else if (fallstair[count] != 1 && fallstair[count] == 2) {
stair[0] = 1;
stair[1] = 0;
count++;
} else {
stair[0] = 1;
stair[1] = 2;
}
} else if (m == 1) {
if (fallstair[count] == 1) {
stair[0] = 0;
stair[1] = 1;
count++;
} else if (fallstair[count] == 2) {
stair[0] = 1;
stair[1] = 0;
count++;
} else {
stair[0] = 1;
stair[1] = 2;
}
}
for (int i = 2; i < n; i++) {
int fall = fallstair[count];
if (fall == i + 1) {
stair[i] = 0;
count++;
} else
stair[i] = stair[i - 1] + stair[i - 2];
//ダメなときは出す
if (stair[i] == 0 && stair[i - 1] == 0) {
output = 0;
goto end;
}
if (stair[i] > 1000000007)
stair[i] %= 1000000007;
}
output = stair[n - 1];
//普通に終われば普通に出す
//最初からダメなら求めない
end:
;
Console.WriteLine(output);
}
}
|
using System;
class ProgramC {
static void Main(string[] args) {
//まずは数字を読む
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int m = int.Parse(input[1]);
int[] fallstair = new int[m + 1];
long[] stair = new long[n + 1];
//とりあえず全部読みこむ
for (int i = 0; i < m; i++)
fallstair[i] = int.Parse(Console.ReadLine());
//ない階段を数える
int count = 0;
//結果出力
long output = 0;
//初期条件設定
if (m >= 2) {
if (fallstair[count] == 1 && fallstair[count + 1] == 2) {
output = 0;
goto end;
} else if (fallstair[count] == 1 && fallstair[count + 1] != 2) {
stair[0] = 0;
stair[1] = 1;
count++;
} else if (fallstair[count] != 1 && fallstair[count] == 2) {
stair[0] = 1;
stair[1] = 0;
count++;
} else {
stair[0] = 1;
stair[1] = 2;
}
} else if (m <= 1) {
if (fallstair[count] == 1) {
stair[0] = 0;
stair[1] = 1;
count++;
} else if (fallstair[count] == 2) {
stair[0] = 1;
stair[1] = 0;
count++;
} else {
stair[0] = 1;
stair[1] = 2;
}
}
for (int i = 2; i < n; i++) {
int fall = fallstair[count];
if (fall == i + 1) {
stair[i] = 0;
count++;
} else
stair[i] = stair[i - 1] + stair[i - 2];
//ダメなときは出す
if (stair[i] == 0 && stair[i - 1] == 0) {
output = 0;
goto end;
}
if (stair[i] > 1000000007)
stair[i] %= 1000000007;
}
output = stair[n - 1];
//普通に終われば普通に出す
//最初からダメなら求めない
end:
;
Console.WriteLine(output);
}
}
|
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19]]
| 8
| 471
| 2
|
using System;
using System.Collections.Generic;
namespace AtcoderProgram {
class Program {
static Dictionary<int, int> fib = new Dictionary<int, int>();
static void createfib(int n) {
fib.Add(-1, 1);
fib.Add(0, 1);
fib.Add(1, 1);
fib.Add(2, 2);
for (int i = 3; i < n; i++) {
int a, b;
fib.TryGetValue(i - 1, out a);
fib.TryGetValue(i - 2, out b);
fib.Add(i, a + b);
}
}
static void Main(string[] args) {
string[] nm = Console.ReadLine().Split(' ');
int num = int.Parse(nm[0]);
int m = int.Parse(nm[1]);
if (num == 1) {
Console.WriteLine(1);
return;
}
if (num == 2) {
Console.WriteLine(m == 0 ? 2 : 1);
return;
}
createfib(num + 1);
if (m == 0) {
int fff;
fib.TryGetValue(num, out fff);
Console.WriteLine(fff % 1000000007);
return;
}
int[] elm = new int[m];
for (int i = 0; i < m; i++) {
elm[i] = int.Parse(Console.ReadLine());
}
List<int> prod = new List<int>();
for (int i = 0; i < elm.Length; i++) {
if (i == 0)
prod.Add(elm[i] - 1);
else {
if (elm[i] - elm[i - 1] == 1) {
Console.WriteLine(0);
return;
}
prod.Add(elm[i] - elm[i - 1] - 2);
}
}
prod.Add(num - elm[m - 1] - 1);
Int64 res = 1;
foreach (int j in prod) {
int k;
fib.TryGetValue(j, out k);
res = res * k;
res = res % 1000000007;
}
Console.WriteLine(res);
}
}
}
|
using System;
using System.Collections.Generic;
namespace AtcoderProgram {
class Program {
static Dictionary<int, int> fib = new Dictionary<int, int>();
static void createfib(int n) {
fib.Add(-1, 1);
fib.Add(0, 1);
fib.Add(1, 1);
fib.Add(2, 2);
for (int i = 3; i < n; i++) {
int a, b;
fib.TryGetValue(i - 1, out a);
fib.TryGetValue(i - 2, out b);
fib.Add(i, (a + b) % 1000000007);
}
}
static void Main(string[] args) {
string[] nm = Console.ReadLine().Split(' ');
int num = int.Parse(nm[0]);
int m = int.Parse(nm[1]);
if (num == 1) {
Console.WriteLine(1);
return;
}
if (num == 2) {
Console.WriteLine(m == 0 ? 2 : 1);
return;
}
createfib(num + 1);
if (m == 0) {
int fff;
fib.TryGetValue(num, out fff);
Console.WriteLine(fff % 1000000007);
return;
}
int[] elm = new int[m];
for (int i = 0; i < m; i++) {
elm[i] = int.Parse(Console.ReadLine());
}
List<int> prod = new List<int>();
for (int i = 0; i < elm.Length; i++) {
if (i == 0)
prod.Add(elm[i] - 1);
else {
if (elm[i] - elm[i - 1] == 1) {
Console.WriteLine(0);
return;
}
prod.Add(elm[i] - elm[i - 1] - 2);
}
}
prod.Add(num - elm[m - 1] - 1);
Int64 res = 1;
foreach (int j in prod) {
int k;
fib.TryGetValue(j, out k);
res = res * k;
res = res % 1000000007;
}
Console.WriteLine(res);
}
}
}
|
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 477
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions {
public static int ToInt(this string s) => int.Parse(s);
public static long ToLong(this string s) => long.Parse(s);
public static char ToChar(this string s) => char.Parse(s);
public static double ToDouble(this string s) => double.Parse(s);
public static int[] ToIntArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
public static long[] ToLongArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
public static double[] ToDoubleArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}
class Program {
static string[] ReadLines(int n) =>
Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();
static void Main() {
long xxxx = 1000000007;
var nm = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
long N = nm[0];
long M = nm[1];
long[] memo = new long[N + 1];
//長さiの区間を移動するための組み合わせを先に求める
memo[0] = 0;
memo[1] = 1;
memo[2] = 1;
for (int i = 3; i < memo.Length; i++) {
memo[i] = memo[i - 1] % xxxx + memo[i - 2] % xxxx;
memo[i] %= xxxx;
}
var aList = Enumerable.Range(0, (int)M)
.Select(n => Console.ReadLine().ToLong())
.Distinct()
.ToArray();
for (int i = 0; i < aList.Length - 1; i++) {
if (aList[i + 1] - aList[i] == 1) {
Console.WriteLine(0);
return;
}
}
long current = 0;
List<long> safeAreaList = new List<long>();
for (int i = 0; i < aList.Length; i++) {
//現在居る区画の最小
var first = current;
//現在居る区画の最大
var last = aList[i] - 1;
//現在居る区画の長さ
var len = last - first + 1;
safeAreaList.Add(len);
current = aList[i] + 1;
}
//最後、N段目までがある
safeAreaList.Add(N - current + 1);
long ans = 1;
foreach (var x in safeAreaList) {
ans *= memo[x];
ans %= xxxx;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions {
public static int ToInt(this string s) => int.Parse(s);
public static long ToLong(this string s) => long.Parse(s);
public static char ToChar(this string s) => char.Parse(s);
public static double ToDouble(this string s) => double.Parse(s);
public static int[] ToIntArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
public static long[] ToLongArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
public static double[] ToDoubleArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}
class Program {
static string[] ReadLines(int n) =>
Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();
static void Main() {
long xxxx = 1000000007;
var nm = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
long N = nm[0];
long M = nm[1];
long[] memo = new long[N + 2];
//長さiの区間を移動するための組み合わせを先に求める
memo[0] = 0;
memo[1] = 1;
memo[2] = 1;
for (int i = 3; i < memo.Length; i++) {
memo[i] = memo[i - 1] % xxxx + memo[i - 2] % xxxx;
memo[i] %= xxxx;
}
var aList = Enumerable.Range(0, (int)M)
.Select(n => Console.ReadLine().ToLong())
.Distinct()
.ToArray();
for (int i = 0; i < aList.Length - 1; i++) {
if (aList[i + 1] - aList[i] == 1) {
Console.WriteLine(0);
return;
}
}
long current = 0;
List<long> safeAreaList = new List<long>();
for (int i = 0; i < aList.Length; i++) {
//現在居る区画の最小
var first = current;
//現在居る区画の最大
var last = aList[i] - 1;
//現在居る区画の長さ
var len = last - first + 1;
safeAreaList.Add(len);
current = aList[i] + 1;
}
//最後、N段目までがある
safeAreaList.Add(N - current + 1);
long ans = 1;
foreach (var x in safeAreaList) {
ans *= memo[x];
ans %= xxxx;
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
| 8
| 640
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
class Program {
void Run() {
var sc = new Scanner();
int n = sc.NextInt();
int m = sc.NextInt();
int[] a = new int[m];
for (int i = 0; i < m; i++)
a[i] = sc.NextInt();
int res = 0;
int mod = 1000000007;
long[] c = new long[n + 1];
c[0] = m > 0 && a[0] == 0 ? 0 : 1;
c[1] = m > 0 && a[0] == 1 ? 0 : 1;
for (int i = 2; i <= n; i++) {
if (Array.BinarySearch(a, i) >= 0)
continue;
c[i] = c[i - 1] + c[i - 2];
}
Console.WriteLine(c[n] % mod);
}
static void Main(string[] args) { new Program().Run(); }
static long Gcd(long a, long b)
{
if (a < b)
return Gcd(b, a);
if (b == 0)
return a;
return Gcd(b, a % b);
}
}
class Scanner {
int index = -1;
string[] buf;
public Scanner() {}
public int NextInt() {
CheckNext();
return int.Parse(buf[index++]);
}
public long NextLong() {
CheckNext();
return long.Parse(buf[index++]);
}
public double NextDouble() {
CheckNext();
return double.Parse(buf[index++]);
}
public string NextString() {
CheckNext();
return buf[index++];
}
private void CheckNext() {
if (index >= 0 && index < buf.Length)
return;
buf = Console.ReadLine().Split(' ');
index = 0;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
class Program {
void Run() {
var sc = new Scanner();
int n = sc.NextInt();
int m = sc.NextInt();
int[] a = new int[m];
for (int i = 0; i < m; i++)
a[i] = sc.NextInt();
int res = 0;
int mod = 1000000007;
long[] c = new long[n + 1];
c[0] = m > 0 && a[0] == 0 ? 0 : 1;
c[1] = m > 0 && a[0] == 1 ? 0 : 1;
for (int i = 2; i <= n; i++) {
if (Array.BinarySearch(a, i) >= 0)
continue;
c[i] = (c[i - 1] + c[i - 2]) % mod;
}
Console.WriteLine(c[n]);
}
static void Main(string[] args) { new Program().Run(); }
static long Gcd(long a, long b)
{
if (a < b)
return Gcd(b, a);
if (b == 0)
return a;
return Gcd(b, a % b);
}
}
class Scanner {
int index = -1;
string[] buf;
public Scanner() {}
public int NextInt() {
CheckNext();
return int.Parse(buf[index++]);
}
public long NextLong() {
CheckNext();
return long.Parse(buf[index++]);
}
public double NextDouble() {
CheckNext();
return double.Parse(buf[index++]);
}
public string NextString() {
CheckNext();
return buf[index++];
}
private void CheckNext() {
if (index >= 0 && index < buf.Length)
return;
buf = Console.ReadLine().Split(' ');
index = 0;
}
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 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], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 439
| 6
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ABC129C {
class Program {
static void Solve(Input input) {
var n = input.NextInt();
var m = input.NextInt();
var a = new int[n + 1];
for (int i = 0; i < m; i++) {
a[input.NextInt()] = 1;
}
var sum = new int[n + 1];
if (n > 0 && a[0] == 0)
sum[0] = 1;
if (n > 1 && a[1] == 0)
sum[1] = 1;
for (int i = 2; i <= n; i++) {
if (a[i] != 0)
continue;
sum[i] = (sum[i - 1] + sum[i - 2]) % 1000000007;
}
Console.WriteLine(sum[n]);
}
#region Competitive Template
public static void Main(string[] args) {
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input();
// 仮想的に標準入力をセットする
// input.SetText("");
Solve(input);
Console.Out.Flush();
}
class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
static readonly char[] separator = { ' ', '\r', '\n' };
public bool IsEof { get; set; }
Queue<string> q { get; set; }
StreamReader sr;
public Input(string path = "") {
IsEof = false;
q = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public 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>
bool read() {
var s = sr.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 string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public string[] Next(int n) =>
Enumerable.Range(0, n).Select(_ => Next()).ToArray();
public int[] NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToArray();
public long[] NextLong(int n) =>
Next(n).Select(x => long.Parse(x)).ToArray();
public double[] NextDouble(int n) =>
Next(n).Select(x => double.Parse(x)).ToArray();
}
static class Utils {
public static void Print<T>(IEnumerable<T> ie, string sep = " ") =>
Console.WriteLine(string.Join(sep, ie));
public static void Print<T>(params T[] objs) => Print(objs);
public static T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
public static void Swap<T>(ref T x, ref T y)
where T : struct {
var t = x;
x = y;
y = t;
}
public static void Swap<T>(IList<T> list, int i, int j)
where T : struct {
var t = list[i];
list[i] = list[j];
list[j] = t;
}
}
#endregion
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ABC129C {
class Program {
static void Solve(Input input) {
var n = input.NextInt();
var m = input.NextInt();
var a = new int[n + 1];
for (int i = 0; i < m; i++) {
a[input.NextInt()] = 1;
}
var sum = new long[n + 1];
if (n >= 0 && a[0] == 0)
sum[0] = 1;
if (n >= 1 && a[1] == 0)
sum[1] = 1;
for (int i = 2; i <= n; i++) {
if (a[i] != 0)
continue;
sum[i] = (sum[i - 1] + sum[i - 2]) % 1000000007;
}
Console.WriteLine(sum[n]);
}
#region Competitive Template
public static void Main(string[] args) {
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input();
// 仮想的に標準入力をセットする
// input.SetText("");
Solve(input);
Console.Out.Flush();
}
class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
static readonly char[] separator = { ' ', '\r', '\n' };
public bool IsEof { get; set; }
Queue<string> q { get; set; }
StreamReader sr;
public Input(string path = "") {
IsEof = false;
q = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public 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>
bool read() {
var s = sr.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 string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public string[] Next(int n) =>
Enumerable.Range(0, n).Select(_ => Next()).ToArray();
public int[] NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToArray();
public long[] NextLong(int n) =>
Next(n).Select(x => long.Parse(x)).ToArray();
public double[] NextDouble(int n) =>
Next(n).Select(x => double.Parse(x)).ToArray();
}
static class Utils {
public static void Print<T>(IEnumerable<T> ie, string sep = " ") =>
Console.WriteLine(string.Join(sep, ie));
public static void Print<T>(params T[] objs) => Print(objs);
public static T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
public static void Swap<T>(ref T x, ref T y)
where T : struct {
var t = x;
x = y;
y = t;
}
public static void Swap<T>(IList<T> list, int i, int j)
where T : struct {
var t = list[i];
list[i] = list[j];
list[j] = t;
}
}
#endregion
}
}
|
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20]]
| 8
| 969
| 6
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections;
using System.Linq;
class Program {
static int[,] s;
static decimal result;
static Hashtable ht = new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N, M, K;
static long[,] table;
static void Main() {
Read4();
Read5();
int tmp, tmpr;
int[,,] check =
new int[K, N, 2]; //チェック中にタテヨコ届く値を状態保存する。
for (int j = 0; j < N; j++) {
for (int i = 0; i < K; i++) {
tmpr = 0;
tmp = 0;
if (check[i, j, 0] > 0) {
tmpr = check[i, j, 0];
} else {
for (int x = i; x < K; x++) {
if (s[x, j] < 0) {
tmpr = tmp;
break;
}
tmp++;
if (x == K - 1) {
tmpr = tmp;
}
}
for (int x = i; x < K; x++) {
if (s[x, j] < 0) {
break;
}
check[x, j, 0] = tmp;
}
}
tmp = 0;
if (check[i, j, 1] > 0) {
tmpr += check[i, j, 1];
} else {
for (int y = j; y < N; y++) {
if (s[i, y] < 0) {
tmpr += tmp;
break;
}
tmp++;
if (y == N - 1) {
tmpr = tmp;
}
}
for (int y = j; y < N; y++) {
if (s[i, y] < 0) {
break;
}
check[i, y, 1] = tmp;
}
}
result = Math.Max(result, tmpr);
}
}
if (result > 0) {
result--;
} //タテヨコで自マスを数えてるので重複分を減
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
s = new int[K, N];
}
static void Read5() // N行K項
{
for (int i = 0; i < N; i++) {
string tmp = Console.ReadLine();
for (int j = 0; j < K; j++) {
if (tmp[j] == '.') {
s[j, i] = 1;
}
if (tmp[j] == '#') {
s[j, i] = -1;
}
}
}
}
}
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections;
using System.Linq;
class Program {
static int[,] s;
static decimal result;
static Hashtable ht = new Hashtable();
static StringBuilder sb = new StringBuilder();
static int N, M, K;
static long[,] table;
static void Main() {
Read4();
Read5();
int tmp, tmpr;
int[,,] check =
new int[K, N, 2]; //チェック中にタテヨコ届く値を状態保存する。
for (int j = 0; j < N; j++) {
for (int i = 0; i < K; i++) {
tmpr = 0;
tmp = 0;
if (check[i, j, 0] > 0) {
tmpr = check[i, j, 0];
} else {
for (int x = i; x < K; x++) {
if (s[x, j] < 0) {
tmpr = tmp;
break;
}
tmp++;
if (x == K - 1) {
tmpr = tmp;
}
}
for (int x = i; x < K; x++) {
if (s[x, j] < 0) {
break;
}
check[x, j, 0] = tmp;
}
}
tmp = 0;
if (check[i, j, 1] > 0) {
tmpr += check[i, j, 1];
} else {
for (int y = j; y < N; y++) {
if (s[i, y] < 0) {
tmpr += tmp;
break;
}
tmp++;
if (y == N - 1) {
tmpr += tmp;
}
}
for (int y = j; y < N; y++) {
if (s[i, y] < 0) {
break;
}
check[i, y, 1] = tmp;
}
}
result = Math.Max(result, tmpr);
}
}
if (result > 0) {
result--;
} //タテヨコで自マスを数えてるので重複分を減
Console.WriteLine(result.ToString());
}
static void Read1() // 1項
{
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read4() // NK1行
{
string[] tmp = Console.ReadLine().Split(' ');
N = int.Parse(tmp[0]);
K = int.Parse(tmp[1]);
s = new int[K, N];
}
static void Read5() // N行K項
{
for (int i = 0; i < N; i++) {
string tmp = Console.ReadLine();
for (int j = 0; j < K; j++) {
if (tmp[j] == '.') {
s[j, i] = 1;
}
if (tmp[j] == '#') {
s[j, i] = -1;
}
}
}
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
| 8
| 617
| 2
|
using System;
public class S {
private const char BLANK = '.';
private const char ROCK = '#';
public static void Main() {
var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var HEIGHT = input[0];
var WIDTH = input[1];
var TORCHMAP = new int[HEIGHT, WIDTH];
int w_startIndex = -1;
var h_startIndex = new int[WIDTH];
var currentLine = new char[WIDTH];
var w_currentCount = 0;
var h_currentCount = new int[WIDTH];
var MAX = 0;
for (int i = 0; i < WIDTH; i++) {
h_startIndex[i] = -1;
}
for (int i = 0; i < HEIGHT; i++) {
currentLine = Console.ReadLine().ToCharArray();
w_currentCount = 0;
w_startIndex = -1;
for (int k = 0; k < WIDTH; k++) {
if (currentLine[k] == '.') {
if (w_startIndex == -1) {
w_startIndex = k;
}
if (h_startIndex[k] == -1) {
h_startIndex[k] = i;
}
w_currentCount++;
h_currentCount[k]++;
} else {
if (w_startIndex != -1) {
for (int WI = k - 1; WI >= w_startIndex; WI--) {
TORCHMAP[i, WI] += w_currentCount;
MAX = Math.Max(TORCHMAP[i, WI], MAX);
}
}
if (h_startIndex[k] != -1) {
for (int HI = i - 1; HI >= h_startIndex[k]; HI--) {
TORCHMAP[HI, k] += h_currentCount[k] - 1;
MAX = Math.Max(TORCHMAP[HI, k], MAX);
}
}
w_currentCount = 0;
h_currentCount[k] = 0;
w_startIndex = -1;
h_startIndex[k] = -1;
}
}
if (w_startIndex != -1) {
for (int WI = WIDTH - 1; WI >= w_startIndex; WI--) {
TORCHMAP[i, WI] += w_currentCount;
MAX = Math.Max(TORCHMAP[i, WI], MAX);
}
}
}
for (int i = 0; i < WIDTH; i++) {
if (h_startIndex[i] != -1) {
for (int HI = WIDTH - 1; HI >= h_startIndex[i]; HI--) {
TORCHMAP[HI, i] += h_currentCount[i] - 1;
MAX = Math.Max(TORCHMAP[HI, i], MAX);
}
}
}
Console.WriteLine(MAX);
}
}
|
using System;
public class S {
private const char BLANK = '.';
private const char ROCK = '#';
public static void Main() {
var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var HEIGHT = input[0];
var WIDTH = input[1];
var TORCHMAP = new int[HEIGHT, WIDTH];
int w_startIndex = -1;
var h_startIndex = new int[WIDTH];
var currentLine = new char[WIDTH];
var w_currentCount = 0;
var h_currentCount = new int[WIDTH];
var MAX = 0;
for (int i = 0; i < WIDTH; i++) {
h_startIndex[i] = -1;
}
for (int i = 0; i < HEIGHT; i++) {
currentLine = Console.ReadLine().ToCharArray();
w_currentCount = 0;
w_startIndex = -1;
for (int k = 0; k < WIDTH; k++) {
if (currentLine[k] == '.') {
if (w_startIndex == -1) {
w_startIndex = k;
}
if (h_startIndex[k] == -1) {
h_startIndex[k] = i;
}
w_currentCount++;
h_currentCount[k]++;
} else {
if (w_startIndex != -1) {
for (int WI = k - 1; WI >= w_startIndex; WI--) {
TORCHMAP[i, WI] += w_currentCount;
MAX = Math.Max(TORCHMAP[i, WI], MAX);
}
}
if (h_startIndex[k] != -1) {
for (int HI = i - 1; HI >= h_startIndex[k]; HI--) {
TORCHMAP[HI, k] += h_currentCount[k] - 1;
MAX = Math.Max(TORCHMAP[HI, k], MAX);
}
}
w_currentCount = 0;
h_currentCount[k] = 0;
w_startIndex = -1;
h_startIndex[k] = -1;
}
}
if (w_startIndex != -1) {
for (int WI = WIDTH - 1; WI >= w_startIndex; WI--) {
TORCHMAP[i, WI] += w_currentCount;
MAX = Math.Max(TORCHMAP[i, WI], MAX);
}
}
}
for (int i = 0; i < WIDTH; i++) {
if (h_startIndex[i] != -1) {
for (int HI = HEIGHT - 1; HI >= h_startIndex[i]; HI--) {
TORCHMAP[HI, i] += h_currentCount[i] - 1;
MAX = Math.Max(TORCHMAP[HI, i], MAX);
}
}
}
Console.WriteLine(MAX);
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22]]
| 8
| 540
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class Program {
static void Main() {
var HW = ReadLine().Split().Select(int.Parse).ToArray();
var H = HW[0];
var W = HW[1];
var x = new UnionFind[H];
for (int i = 0; i < H; i++) {
x[i] = new UnionFind(W);
}
var y = new UnionFind[W];
for (int i = 0; i < W; i++) {
y[i] = new UnionFind(H);
}
var m = new bool[H, W];
for (int i = 0; i < H; i++) {
var S = ReadLine();
for (int j = 0; j < W; j++) {
m[i, j] = S[j] == '.';
}
}
for (int i = 0; i < H; i++) {
for (int j = 1; j < W; j++) {
if (m[i, j - 1] && m[i, j])
x[i].Unite(j - 1, j);
}
}
for (int i = 1; i < H; i++) {
for (int j = 0; j < W; j++) {
if (m[i - 1, j] && m[i, j])
y[j].Unite(i - 1, i);
}
}
var ans = 0;
for (int i = 0; i < W; i++) {
for (int j = 0; j < H; j++) {
ans = Max(ans, x[i].Size(j) + y[j].Size(i) - 1);
}
}
WriteLine(ans);
}
}
public class UnionFind {
int[] parent;
int count;
public int Count => count;
public UnionFind(int length) {
parent = new int[length];
for (int i = 0; i < parent.Length; i++) {
parent[i] = -1;
}
count = length;
}
int Root(int x) => parent[x] < 0 ? x : parent[x] = Root(parent[x]);
public bool Same(int x, int y) => Root(x) == Root(y);
public void Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x == y)
return;
count--;
if (parent[x] < parent[y]) {
parent[x] += parent[y];
parent[y] = x;
} else {
parent[y] += parent[x];
parent[x] = y;
}
}
public int Size(int x) => -parent[Root(x)];
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class Program {
static void Main() {
var HW = ReadLine().Split().Select(int.Parse).ToArray();
var H = HW[0];
var W = HW[1];
var x = new UnionFind[H];
for (int i = 0; i < H; i++) {
x[i] = new UnionFind(W);
}
var y = new UnionFind[W];
for (int i = 0; i < W; i++) {
y[i] = new UnionFind(H);
}
var m = new bool[H, W];
for (int i = 0; i < H; i++) {
var S = ReadLine();
for (int j = 0; j < W; j++) {
m[i, j] = S[j] == '.';
}
}
for (int i = 0; i < H; i++) {
for (int j = 1; j < W; j++) {
if (m[i, j - 1] && m[i, j])
x[i].Unite(j - 1, j);
}
}
for (int i = 1; i < H; i++) {
for (int j = 0; j < W; j++) {
if (m[i - 1, j] && m[i, j])
y[j].Unite(i - 1, i);
}
}
var ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans = Max(ans, x[i].Size(j) + y[j].Size(i) - 1);
}
}
WriteLine(ans);
}
}
public class UnionFind {
int[] parent;
int count;
public int Count => count;
public UnionFind(int length) {
parent = new int[length];
for (int i = 0; i < parent.Length; i++) {
parent[i] = -1;
}
count = length;
}
int Root(int x) => parent[x] < 0 ? x : parent[x] = Root(parent[x]);
public bool Same(int x, int y) => Root(x) == Root(y);
public void Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x == y)
return;
count--;
if (parent[x] < parent[y]) {
parent[x] += parent[y];
parent[y] = x;
} else {
parent[y] += parent[x];
parent[x] = y;
}
}
public int Size(int x) => -parent[Root(x)];
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 633
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Solution {
public int H, W;
public char[,] MP;
public long MOD = 1000000007;
public void Run() {
{
var line = Input.ReadIntArray();
H = line[0];
W = line[1];
}
MP = new char[H, W];
for (int y = 0; y < H; y++) {
var line = Console.ReadLine();
for (int x = 0; x < W; x++) {
MP[y, x] = line[x];
}
}
int[,] L, U, R, D;
L = new int[H, W];
U = new int[H, W];
R = new int[H, W];
D = new int[H, W];
{
for (int y = 0; y < H; y++) {
int last = 0;
for (int x = 0; x < W; x++) {
if (MP[y, x] == '#') {
last = 0;
} else {
L[y, x] = last;
last++;
}
}
}
}
{
for (int y = 0; y < H; y++) {
int last = 0;
for (int x = W - 1; x >= 0; x--) {
if (MP[y, x] == '#') {
last = 0;
} else {
R[y, x] = last;
last++;
}
}
}
}
{
for (int x = 0; x < W; x++) {
int last = 0;
for (int y = 0; y < H; y++) {
if (MP[y, x] == '#') {
last = 0;
} else {
U[y, x] = last;
last++;
}
}
}
}
{
for (int x = 0; x < W; x++) {
int last = 0;
for (int y = H - 1; y >= 0; y--) {
if (MP[y, x] == '#') {
last = 0;
} else {
D[y, x] = last;
last++;
}
}
}
}
int ret = 0;
for (int y = 0; y < H; y++) {
for (int x = 0; x < H; x++) {
ret = Math.Max(ret, L[y, x] + R[y, x] + U[y, x] + D[y, x] + 1);
}
}
Console.WriteLine(ret);
}
}
// libs ----------
// common ----------
internal static class Input {
public static string ReadString() {
string line = Console.ReadLine();
return line;
}
public static int ReadInt() {
string line = Console.ReadLine();
return int.Parse(line);
}
public static int[] ReadIntArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(int.Parse).ToArray();
}
public static long ReadLong() {
string line = Console.ReadLine();
return long.Parse(line);
}
public static long[] ReadLongArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(long.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(double.Parse).ToArray();
}
}
internal class Program {
public static void Main(string[] args) {
var s = new Solution();
s.Run();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Solution {
public int H, W;
public char[,] MP;
public long MOD = 1000000007;
public void Run() {
{
var line = Input.ReadIntArray();
H = line[0];
W = line[1];
}
MP = new char[H, W];
for (int y = 0; y < H; y++) {
var line = Console.ReadLine();
for (int x = 0; x < W; x++) {
MP[y, x] = line[x];
}
}
int[,] L, U, R, D;
L = new int[H, W];
U = new int[H, W];
R = new int[H, W];
D = new int[H, W];
{
for (int y = 0; y < H; y++) {
int last = 0;
for (int x = 0; x < W; x++) {
if (MP[y, x] == '#') {
last = 0;
} else {
L[y, x] = last;
last++;
}
}
}
}
{
for (int y = 0; y < H; y++) {
int last = 0;
for (int x = W - 1; x >= 0; x--) {
if (MP[y, x] == '#') {
last = 0;
} else {
R[y, x] = last;
last++;
}
}
}
}
{
for (int x = 0; x < W; x++) {
int last = 0;
for (int y = 0; y < H; y++) {
if (MP[y, x] == '#') {
last = 0;
} else {
U[y, x] = last;
last++;
}
}
}
}
{
for (int x = 0; x < W; x++) {
int last = 0;
for (int y = H - 1; y >= 0; y--) {
if (MP[y, x] == '#') {
last = 0;
} else {
D[y, x] = last;
last++;
}
}
}
}
int ret = 0;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
ret = Math.Max(ret, L[y, x] + R[y, x] + U[y, x] + D[y, x] + 1);
}
}
Console.WriteLine(ret);
}
}
// libs ----------
// common ----------
internal static class Input {
public static string ReadString() {
string line = Console.ReadLine();
return line;
}
public static int ReadInt() {
string line = Console.ReadLine();
return int.Parse(line);
}
public static int[] ReadIntArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(int.Parse).ToArray();
}
public static long ReadLong() {
string line = Console.ReadLine();
return long.Parse(line);
}
public static long[] ReadLongArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(long.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(double.Parse).ToArray();
}
}
internal class Program {
public static void Main(string[] args) {
var s = new Solution();
s.Run();
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 803
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;
class Program {
int[] cmb;
static void Main(string[] args) {
int[] HW = ReadLineParseIntArray();
int[,] map = new int[HW[0], HW[1]];
string[] s = new string[HW[0] + 1];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < HW[0]; i++) {
sb.Append(ReadLine());
sb.Append("#");
s[i] = sb.ToString();
sb.Clear();
}
for (int x = 0; x <= HW[1]; x++)
sb.Append("#");
s[HW[0]] = sb.ToString();
for (int y = 0; y < HW[0]; y++) {
int start = -1;
for (int x = 0; x <= HW[1]; x++) {
if (s[y][x] == '.' && start == -1)
start = x;
if (s[y][x] == '#' && start != -1) {
for (int i = start; i < x; i++)
map[y, i] += x - start;
start = -1;
}
}
}
for (int x = 0; x < HW[1]; x++) {
int start = -1;
for (int y = 0; y <= HW[0]; y++) {
if (s[y][x] == '.' && start == -1)
start = y;
else if (s[y][x] == '#' && start != -1) {
for (int i = 0; i < y; i++)
map[i, x] += y - start;
start = -1;
}
}
}
int max = 0;
for (int y = 0; y < HW[0]; y++) {
for (int x = 0; x < HW[1]; x++)
if (map[y, x] > max)
max = map[y, x];
}
WriteLine(max - 1);
}
static int[] ReadLineParseIntArray() =>
ReadLine().Split(' ').Select(int.Parse).ToArray();
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;
class Program {
int[] cmb;
static void Main(string[] args) {
int[] HW = ReadLineParseIntArray();
int[,] map = new int[HW[0], HW[1]];
string[] s = new string[HW[0] + 1];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < HW[0]; i++) {
sb.Append(ReadLine());
sb.Append("#");
s[i] = sb.ToString();
sb.Clear();
}
for (int x = 0; x <= HW[1]; x++)
sb.Append("#");
s[HW[0]] = sb.ToString();
for (int y = 0; y < HW[0]; y++) {
int start = -1;
for (int x = 0; x <= HW[1]; x++) {
if (s[y][x] == '.' && start == -1)
start = x;
if (s[y][x] == '#' && start != -1) {
for (int i = start; i < x; i++)
map[y, i] += x - start;
start = -1;
}
}
}
for (int x = 0; x < HW[1]; x++) {
int start = -1;
for (int y = 0; y <= HW[0]; y++) {
if (s[y][x] == '.' && start == -1)
start = y;
else if (s[y][x] == '#' && start != -1) {
for (int i = start; i < y; i++)
map[i, x] += y - start;
start = -1;
}
}
}
int max = 0;
for (int y = 0; y < HW[0]; y++) {
for (int x = 0; x < HW[1]; x++)
if (map[y, x] > max)
max = map[y, x];
}
WriteLine(max - 1);
}
static int[] ReadLineParseIntArray() =>
ReadLine().Split(' ').Select(int.Parse).ToArray();
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22]]
| 8
| 534
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ABC129D {
class Program {
static void Solve(Input input) {
var h = input.NextInt();
var w = input.NextInt();
var map = new int[h, w];
for (int i = 0; i < h; i++) {
var s = input.Next();
for (int j = 0; j < w; j++) {
// 障害物あり
if (s[j] == '#')
map[i, j] = 1;
}
}
// h,wがそんなに大きくないので、すべてのマスの照らされるマスを数え上げる
// TLEするなら周辺のマスをいい感じに使う?
var max = int.MinValue;
// [x,y,xy]: xy=0はそのマスのx座標でのカウント値
// xy=1はそのマスのy座標でのカウント値
// ただし、自分のマスを重複カウントしているので実際の値は2つの和-1
var countMap = new int[h, w, 2];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
light(map, countMap, h, w, j, i);
var count = countMap[i, j, 0] + countMap[i, j, 1] - 1;
if (count > max)
max = count;
}
}
Console.WriteLine(Math.Max(0, max));
}
static void light(int[,] map, int[,,] cmap, int h, int w, int x, int y) {
if (map[y, x] != 0) {
cmap[y, x, 0] = cmap[y, x, 1] = 0;
return;
}
if (x > 0 && cmap[y, x - 1, 0] != 0) {
cmap[y, x, 0] = cmap[y, x - 1, 0];
} else {
int count = 0;
// x+
for (int j = x + 1; j < w; j++) {
if (map[y, j] != 0)
break;
count++;
}
// x-
for (int j = x - 1; j >= 0; j--) {
if (map[y, j] != 0)
break;
count++;
}
cmap[y, x, 0] = count + 1;
}
if (y > 0 && cmap[y - 1, x, 1] != 0) {
cmap[y, x, 1] = cmap[y - 1, x, 1];
} else {
int count = 0;
// y+
for (int i = y + 1; i < h; i++) {
if (map[i, x] != 0)
break;
count++;
}
// y-
for (int i = y - 1; i >= 0; i--) {
if (map[i, x] != 0)
break;
count++;
}
cmap[y, x, 1] = count + 1;
}
}
#region Competitive Template
public static void Main(string[] args) {
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input(@"E:\Downloads\input.txt");
// 仮想的に標準入力をセットする
// input.SetText("");
Solve(input);
Console.Out.Flush();
}
class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
static readonly char[] separator = { ' ', '\r', '\n' };
public bool IsEof { get; set; }
Queue<string> q { get; set; }
StreamReader sr;
public Input(string path = "") {
IsEof = false;
q = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public 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>
bool read() {
var s = sr.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 string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public string[] Next(int n) =>
Enumerable.Range(0, n).Select(_ => Next()).ToArray();
public int[] NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToArray();
public long[] NextLong(int n) =>
Next(n).Select(x => long.Parse(x)).ToArray();
public double[] NextDouble(int n) =>
Next(n).Select(x => double.Parse(x)).ToArray();
}
static class Utils {
public static void Print<T>(IEnumerable<T> ie, string sep = " ") =>
Console.WriteLine(string.Join(sep, ie));
public static void Print<T>(params T[] objs) => Print(objs);
public static T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
public static void Swap<T>(ref T x, ref T y)
where T : struct {
var t = x;
x = y;
y = t;
}
public static void Swap<T>(IList<T> list, int i, int j)
where T : struct {
var t = list[i];
list[i] = list[j];
list[j] = t;
}
}
#endregion
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ABC129D {
class Program {
static void Solve(Input input) {
var h = input.NextInt();
var w = input.NextInt();
var map = new int[h, w];
for (int i = 0; i < h; i++) {
var s = input.Next();
for (int j = 0; j < w; j++) {
// 障害物あり
if (s[j] == '#')
map[i, j] = 1;
}
}
// h,wがそんなに大きくないので、すべてのマスの照らされるマスを数え上げる
// TLEするなら周辺のマスをいい感じに使う?
var max = int.MinValue;
// [x,y,xy]: xy=0はそのマスのx座標でのカウント値
// xy=1はそのマスのy座標でのカウント値
// ただし、自分のマスを重複カウントしているので実際の値は2つの和-1
var countMap = new int[h, w, 2];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
light(map, countMap, h, w, j, i);
var count = countMap[i, j, 0] + countMap[i, j, 1] - 1;
if (count > max)
max = count;
}
}
Console.WriteLine(Math.Max(0, max));
}
static void light(int[,] map, int[,,] cmap, int h, int w, int x, int y) {
if (map[y, x] != 0) {
cmap[y, x, 0] = cmap[y, x, 1] = 0;
return;
}
if (x > 0 && cmap[y, x - 1, 0] != 0) {
cmap[y, x, 0] = cmap[y, x - 1, 0];
} else {
int count = 0;
// x+
for (int j = x + 1; j < w; j++) {
if (map[y, j] != 0)
break;
count++;
}
// x-
for (int j = x - 1; j >= 0; j--) {
if (map[y, j] != 0)
break;
count++;
}
cmap[y, x, 0] = count + 1;
}
if (y > 0 && cmap[y - 1, x, 1] != 0) {
cmap[y, x, 1] = cmap[y - 1, x, 1];
} else {
int count = 0;
// y+
for (int i = y + 1; i < h; i++) {
if (map[i, x] != 0)
break;
count++;
}
// y-
for (int i = y - 1; i >= 0; i--) {
if (map[i, x] != 0)
break;
count++;
}
cmap[y, x, 1] = count + 1;
}
}
#region Competitive Template
public static void Main(string[] args) {
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input();
// 仮想的に標準入力をセットする
// input.SetText("");
Solve(input);
Console.Out.Flush();
}
class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
static readonly char[] separator = { ' ', '\r', '\n' };
public bool IsEof { get; set; }
Queue<string> q { get; set; }
StreamReader sr;
public Input(string path = "") {
IsEof = false;
q = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public 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>
bool read() {
var s = sr.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 string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public string[] Next(int n) =>
Enumerable.Range(0, n).Select(_ => Next()).ToArray();
public int[] NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToArray();
public long[] NextLong(int n) =>
Next(n).Select(x => long.Parse(x)).ToArray();
public double[] NextDouble(int n) =>
Next(n).Select(x => double.Parse(x)).ToArray();
}
static class Utils {
public static void Print<T>(IEnumerable<T> ie, string sep = " ") =>
Console.WriteLine(string.Join(sep, ie));
public static void Print<T>(params T[] objs) => Print(objs);
public static T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
public static void Swap<T>(ref T x, ref T y)
where T : struct {
var t = x;
x = y;
y = t;
}
public static void Swap<T>(IList<T> list, int i, int j)
where T : struct {
var t = list[i];
list[i] = list[j];
list[j] = t;
}
}
#endregion
}
}
|
[["-", 0, 212, 0, 230, 3, 4, 0, 28, 0, 258]]
| 8
| 1,343
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dx = { 0, 1, 0, -1 };
static readonly int[] dy = { 1, 0, -1, 0 };
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
var L = Console.ReadLine();
int len = L.Length;
var dp = new long[len + 1, 2];
for (var i = 0; i <= len; i++) {
dp[i, 0] = 0;
dp[i, 1] = 0;
}
dp[0, 0] = 1L;
for (var i = 0; i < len; i++) {
dp[i + 1, 1] = (dp[i + 1, 1] + (dp[i, 1] * 3L)) % MOD;
if (L[i] == '0') {
dp[i + 1, 0] = (dp[i + 1, 0] + dp[i, 0]) % MOD;
} else {
dp[i + 1, 0] = (dp[i + 1, 0] + (dp[i, 0] * 2L)) % MOD;
dp[i + 1, 1] = (dp[i + 1, 1] + dp[i, 0]) % MOD;
}
}
Console.WriteLine(dp[len, 0] + dp[len, 1]);
}
}
public class Scanner {
public int[] SplitRead() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] SplitReadL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dx = { 0, 1, 0, -1 };
static readonly int[] dy = { 1, 0, -1, 0 };
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
var L = Console.ReadLine();
int len = L.Length;
var dp = new long[len + 1, 2];
for (var i = 0; i <= len; i++) {
dp[i, 0] = 0;
dp[i, 1] = 0;
}
dp[0, 0] = 1L;
for (var i = 0; i < len; i++) {
dp[i + 1, 1] = (dp[i + 1, 1] + (dp[i, 1] * 3L)) % MOD;
if (L[i] == '0') {
dp[i + 1, 0] = (dp[i + 1, 0] + dp[i, 0]) % MOD;
} else {
dp[i + 1, 0] = (dp[i + 1, 0] + (dp[i, 0] * 2L)) % MOD;
dp[i + 1, 1] = (dp[i + 1, 1] + dp[i, 0]) % MOD;
}
}
Console.WriteLine((dp[len, 0] + dp[len, 1]) % MOD);
}
}
public class Scanner {
public int[] SplitRead() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] SplitReadL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
}
}
|
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 518
| 4
|
using System;
using System.Linq;
namespace ABC129 {
class Program {
static void Main(string[] args) {
var L = Console.ReadLine();
var mod = 1000000007;
var ans = L.Skip(1).Aggregate(
new long[] { 1, 2 },
(p, c) => c == '1' ? new[] { (p[0] * 3 + p[1]) % mod, (p[1] * 2) % mod }
: new[] { (p[0] * 3) % mod, p[1] });
Console.WriteLine(ans.Sum());
}
}
}
|
using System;
using System.Linq;
namespace ABC129 {
class Program {
static void Main(string[] args) {
var L = Console.ReadLine();
long mod = 1000000007;
var ans = L.Skip(1).Aggregate(
new long[] { 1, 2 },
(p, c) => c == '1' ? new[] { (p[0] * 3 + p[1]) % mod, (p[1] * 2) % mod }
: new[] { (p[0] * 3) % mod, p[1] });
Console.WriteLine(ans.Sum() % mod);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 140
| 4
|
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 k = sc.NextLong();
long answer = (n - k + 1);
if (k == 1) {
answer = 0;
}
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 k = sc.NextLong();
long answer = n - k;
if (k == 1) {
answer = 0;
}
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, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["-", 0, 200, 0, 212, 0, 23, 0, 16, 17, 72], ["-", 0, 200, 0, 212, 0, 23, 0, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 25]]
| 8
| 382
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var o = Ints;
var N = o[0];
var K = o[1];
if (N == 1)
Write(0);
else
Write(N - K);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long i, long N, long MOD = 1000000007) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long Power2(long i, long N) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i;
i = i * i;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var o = Ints;
var N = o[0];
var K = o[1];
if (K == 1)
Write(0);
else
Write(N - K);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long i, long N, long MOD = 1000000007) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long Power2(long i, long N) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i;
i = i * i;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
| 8
| 956
| 2
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections;
using System.Linq;
class Program {
static List<int> s = new List<int>();
static decimal result;
static Hashtable ht = new Hashtable();
static int N, M;
static long[,] table;
static void Main() {
Read1();
if (M == 1) {
Console.WriteLine(result.ToString());
return;
}
result = N - M;
Console.WriteLine(result.ToString());
}
static void Read1() {
string[] tmp = Console.ReadLine().Split();
N = int.Parse(tmp[0]);
M = int.Parse(tmp[0]);
}
static void Read2(int kosuu) {
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < kosuu; i++) {
s.Add(int.Parse(tmp[i]));
}
}
}
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections;
using System.Linq;
class Program {
static List<int> s = new List<int>();
static decimal result;
static Hashtable ht = new Hashtable();
static int N, M;
static long[,] table;
static void Main() {
Read1();
if (M == 1) {
Console.WriteLine(result.ToString());
return;
}
result = N - M;
Console.WriteLine(result.ToString());
}
static void Read1() {
string[] tmp = Console.ReadLine().Split();
N = int.Parse(tmp[0]);
M = int.Parse(tmp[1]);
}
static void Read2(int kosuu) {
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < kosuu; i++) {
s.Add(int.Parse(tmp[i]));
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 225
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
static void Main(string[] args) {
int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
int n = s[0];
int k = s[1];
WriteLine(k == 0 ? 0 : n - k);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
static void Main(string[] args) {
int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
int n = s[0];
int k = s[1];
WriteLine(k == 1 ? 0 : n - k);
}
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203]]
| 8
| 107
| 2
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine();
int n = int.Parse(input.Split(' ')[0]);
int k = int.Parse(input.Split(' ')[1]);
int max = n - k + 1;
if (k > 1) {
Console.WriteLine(max - 1);
} else {
Console.WriteLine(n);
}
}
}
}
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine();
int n = int.Parse(input.Split(' ')[0]);
int k = int.Parse(input.Split(' ')[1]);
int max = n - k + 1;
if (k > 1) {
Console.WriteLine(max - 1);
} else {
Console.WriteLine(0);
}
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 107
| 2
|
using System;
class Program {
static string[] GetVals(string splitChar) {
var src = Console.ReadLine();
return src.Split(new string[] { splitChar }, StringSplitOptions.None);
}
static string[] GetVals(char splitChar) {
var src = Console.ReadLine();
return src.Split(splitChar);
}
static string GetVal() { return Console.ReadLine(); }
static void Write(object o) { Console.WriteLine(String.Format("{0}", o)); }
static int ParseI(string val) { return int.Parse(val); }
static double ParseD(string val) { return double.Parse(val); }
static void Main(string[] args) {
var vals = GetVals(' ');
int a = int.Parse(vals[0]);
int b = int.Parse(vals[1]);
if (a <= 1)
Write(0);
else
Write((a - (b - 1)) - 1);
}
}
|
using System;
class Program {
static string[] GetVals(string splitChar) {
var src = Console.ReadLine();
return src.Split(new string[] { splitChar }, StringSplitOptions.None);
}
static string[] GetVals(char splitChar) {
var src = Console.ReadLine();
return src.Split(splitChar);
}
static string GetVal() { return Console.ReadLine(); }
static void Write(object o) { Console.WriteLine(String.Format("{0}", o)); }
static int ParseI(string val) { return int.Parse(val); }
static double ParseD(string val) { return double.Parse(val); }
static void Main(string[] args) {
var vals = GetVals(' ');
int a = int.Parse(vals[0]);
int b = int.Parse(vals[1]);
if (b <= 1)
Write(0);
else
Write((a - (b - 1)) - 1);
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
| 8
| 220
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace ConsoleApp3 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
if (n - k <= 0) {
WriteLine(0);
return;
}
WriteLine(n - k);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace ConsoleApp3 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
if (k == 1) {
WriteLine(0);
return;
}
WriteLine(n - k);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 120
| 6
|
using System;
using System.IO;
namespace Sandbox {
internal class Program {
private static void Main(string[] args) {
var scanner = new Scanner();
var n = scanner.GetNextAsInt();
var k = scanner.GetNextAsInt();
if (n == 1) {
Console.WriteLine("0");
return;
}
Console.WriteLine(n - k);
}
#region String Scanner
public class Scanner {
private const char Separator = ' ';
private readonly StreamReader _Stream =
new StreamReader(Console.OpenStandardInput());
private int _Pos;
private string[] _Line = new string[0];
#region get a element
public string GetNext() {
// ReSharper disable once InvertIf
if (this._Pos >= this._Line.Length) {
// ReSharper disable once PossibleNullReferenceException
this._Line = this._Stream.ReadLine().Split(Separator);
this._Pos = 0;
}
return this._Line[this._Pos++];
}
public int GetNextAsInt() { return int.Parse(this.GetNext()); }
public long GetNextAsLong() { return long.Parse(this.GetNext()); }
public double GetNextAsDouble() { return double.Parse(this.GetNext()); }
#endregion
#region get array
public string[] ToArrayFromNextLine() {
if (this._Pos >= this._Line.Length) {
// ReSharper disable once PossibleNullReferenceException
this._Line = this._Stream.ReadLine().Split(Separator);
}
this._Pos = this._Line.Length;
return this._Line;
}
public int[] ToIntArrayFromNextLine() {
return ToIntArray(this.ToArrayFromNextLine());
}
public long[] ToLongArrayFromNextLine() {
return ToLongArray(this.ToArrayFromNextLine());
}
public double[] ToDoubleArrayFromNextLine() {
return ToDoubleArray(this.ToArrayFromNextLine());
}
#endregion
#region convert array
private static int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private static long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private static double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
}
#endregion
}
}
|
using System;
using System.IO;
namespace Sandbox {
internal class Program {
private static void Main(string[] args) {
var scanner = new Scanner();
var n = scanner.GetNextAsInt();
var k = scanner.GetNextAsInt();
if (k == 1) {
Console.WriteLine("0");
return;
}
Console.WriteLine(n - k);
}
#region String Scanner
public class Scanner {
private const char Separator = ' ';
private readonly StreamReader _Stream =
new StreamReader(Console.OpenStandardInput());
private int _Pos;
private string[] _Line = new string[0];
#region get a element
public string GetNext() {
// ReSharper disable once InvertIf
if (this._Pos >= this._Line.Length) {
// ReSharper disable once PossibleNullReferenceException
this._Line = this._Stream.ReadLine().Split(Separator);
this._Pos = 0;
}
return this._Line[this._Pos++];
}
public int GetNextAsInt() { return int.Parse(this.GetNext()); }
public long GetNextAsLong() { return long.Parse(this.GetNext()); }
public double GetNextAsDouble() { return double.Parse(this.GetNext()); }
#endregion
#region get array
public string[] ToArrayFromNextLine() {
if (this._Pos >= this._Line.Length) {
// ReSharper disable once PossibleNullReferenceException
this._Line = this._Stream.ReadLine().Split(Separator);
}
this._Pos = this._Line.Length;
return this._Line;
}
public int[] ToIntArrayFromNextLine() {
return ToIntArray(this.ToArrayFromNextLine());
}
public long[] ToLongArrayFromNextLine() {
return ToLongArray(this.ToArrayFromNextLine());
}
public double[] ToDoubleArrayFromNextLine() {
return ToDoubleArray(this.ToArrayFromNextLine());
}
#endregion
#region convert array
private static int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private static long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private static double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (var i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
}
#endregion
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
| 8
| 558
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
class Program {
static void Main(string[] args) {
var cin = new Scanner();
var N = cin.nextInt();
var K = cin.nextInt();
if (K == 1) {
Console.WriteLine(0);
} else {
Console.WriteLine(K - N);
}
}
public static int BinarySearch<T>(T[] array, T target)
where T : IComparable<T> {
int min = 0;
int max = array.Length - 1;
while (true) {
if (max < min)
return -1;
int mid = min + (max - min) / 2;
switch (target.CompareTo(array[mid])) {
case -1:
max = mid - 1;
break;
case 1:
min = mid + 1;
break;
case 0:
return mid;
}
}
}
}
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 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 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;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
class Program {
static void Main(string[] args) {
var cin = new Scanner();
var N = cin.nextInt();
var K = cin.nextInt();
if (K == 1) {
Console.WriteLine(0);
} else {
Console.WriteLine(N - K);
}
}
public static int BinarySearch<T>(T[] array, T target)
where T : IComparable<T> {
int min = 0;
int max = array.Length - 1;
while (true) {
if (max < min)
return -1;
int mid = min + (max - min) / 2;
switch (target.CompareTo(array[mid])) {
case -1:
max = mid - 1;
break;
case 1:
min = mid + 1;
break;
case 0:
return mid;
}
}
}
}
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 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 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;
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 553
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC {
public static void Main() {
var read = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = read[0];
int K = read[1];
int minus = N - K;
if (K == 1) {
Console.WriteLine(0);
} else {
Console.WriteLine(1 + minus);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC {
public static void Main() {
var read = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = read[0];
int K = read[1];
int minus = N - K;
if (K == 1) {
Console.WriteLine(0);
} else {
Console.WriteLine(minus);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
| 8
| 124
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var N = Int1;
var A = Longs;
Array.Sort(A);
if (A[0] > 0) {
Write(A.Sum() - 2 * A[0]);
for (int i = 0; i < N - 2; ++i) {
Write(A[0], A[i + 1]);
A[0] -= A[i + 1];
}
Write(A[N - 1], A[0]);
return;
} else if (A[N - 1] <= 0) {
long an = 0;
A = A.Reverse().ToArray();
for (int i = 0; i < N - 1; ++i)
an -= A[i + 1];
Write(A[0] + an);
for (int i = 0; i < N - 1; ++i) {
Write(A[0], A[i + 1]);
A[0] -= A[i + 1];
}
return;
}
long ans = 0;
var positive = new List<long>();
var negative = new List<long>();
for (int i = 0; i < N; ++i) {
if (A[i] >= 0)
positive.Add(A[i]);
else
negative.Add(A[i]);
ans += Abs(A[i]);
}
Write(ans);
while (positive.Count > 1) {
Write(negative[0], positive.Last());
negative[0] -= positive.Last();
positive.RemoveAt(positive.Count - 1);
}
while (negative.Count > 0) {
Write(positive[0], negative.Last());
positive[0] -= negative.Last();
negative.RemoveAt(negative.Count - 1);
}
}
}
public static class Graph {
public static long[] dijkstra(List<Tuple<long, int>>[] edge, int from,
long INF = Math2.INFL) {
long[] ret = Enumerable.Range(0, edge.Length).Select(_ => INF).ToArray();
var pq =
new PriorityQueue<Tuple<long, int>>((a, b) => (int)(a.Item1 - b.Item1));
ret[from] = 0;
pq.Enqueue(new Tuple<long, int>(0, from));
while (pq.Count > 0) {
var p = pq.Dequeue();
var v = p.Item2;
if (ret[v] < p.Item1)
continue;
foreach (var e in edge[v]) {
if (ret[e.Item2] > ret[v] + e.Item1) {
ret[e.Item2] = ret[v] + e.Item1;
pq.Enqueue(new Tuple<long, int>(ret[e.Item2], e.Item2));
}
}
}
return ret;
}
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = n; i >= n - r + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
// public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ",
// a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var N = Int1;
var A = Longs;
Array.Sort(A);
if (A[0] >= 0) {
Write(A.Sum() - 2 * A[0]);
for (int i = 0; i < N - 2; ++i) {
Write(A[0], A[i + 1]);
A[0] -= A[i + 1];
}
Write(A[N - 1], A[0]);
return;
} else if (A[N - 1] < 0) {
long an = 0;
A = A.Reverse().ToArray();
for (int i = 0; i < N - 1; ++i)
an -= A[i + 1];
Write(A[0] + an);
for (int i = 0; i < N - 1; ++i) {
Write(A[0], A[i + 1]);
A[0] -= A[i + 1];
}
return;
}
long ans = 0;
var positive = new List<long>();
var negative = new List<long>();
for (int i = 0; i < N; ++i) {
if (A[i] >= 0)
positive.Add(A[i]);
else
negative.Add(A[i]);
ans += Abs(A[i]);
}
Write(ans);
while (positive.Count > 1) {
Write(negative[0], positive.Last());
negative[0] -= positive.Last();
positive.RemoveAt(positive.Count - 1);
}
while (negative.Count > 0) {
Write(positive[0], negative.Last());
positive[0] -= negative.Last();
negative.RemoveAt(negative.Count - 1);
}
}
}
public static class Graph {
public static long[] dijkstra(List<Tuple<long, int>>[] edge, int from,
long INF = Math2.INFL) {
long[] ret = Enumerable.Range(0, edge.Length).Select(_ => INF).ToArray();
var pq =
new PriorityQueue<Tuple<long, int>>((a, b) => (int)(a.Item1 - b.Item1));
ret[from] = 0;
pq.Enqueue(new Tuple<long, int>(0, from));
while (pq.Count > 0) {
var p = pq.Dequeue();
var v = p.Item2;
if (ret[v] < p.Item1)
continue;
foreach (var e in edge[v]) {
if (ret[e.Item2] > ret[v] + e.Item1) {
ret[e.Item2] = ret[v] + e.Item1;
pq.Enqueue(new Tuple<long, int>(ret[e.Item2], e.Item2));
}
}
}
return ret;
}
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = n; i >= n - r + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
// public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ",
// a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18]]
| 8
| 1,981
| 4
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.