buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static long Mod = (long)998244353;
static void Main(string[] args) {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
var NM = Sarray();
var N = NM[0];
var M = NM[1];
var AB = new List<Tuple<long, long>>();
for (var i = 0; i < N; ++i) {
var ab = Sarray();
AB.Add(Tuple.Create(ab[0], ab[1]));
}
AB.Sort((l, r) => (int)(r.Item2 - l.Item2));
var st = new SegTree((int)M);
var ans = 0L;
foreach (var ab in AB) {
var fd = st.GetFreeday((int)ab.Item1);
if (fd == -1)
continue;
st.Set(fd, false);
ans += ab.Item2;
}
WriteLine(ans);
// Out.Flush();
}
public class SegTree {
int N;
int ON;
// left | right
bool[] val;
public SegTree(int n) {
ON = n;
N = 2;
while (N < n)
N <<= 1;
val = Enumerable.Repeat(true, 2 * N - 1).ToArray();
for (var i = n + 1; i <= N; ++i)
Set(i, false);
}
public void Set(int n, bool v) {
if (ON < n)
return;
var i = N - 1 + n;
if (GetValue(i) != v) {
SetValue(i, v);
_chg(i);
}
}
// nが変更された
void _chg(int n) {
var p = Parent(n);
if (p < 1)
return;
var v = GetValue(Left(p)) | GetValue(Right(p));
if (GetValue(p) != v) {
SetValue(p, v);
_chg(p);
}
}
public int GetFreeday(int n) {
if (ON < n)
return -1;
var i = N - 1 + n;
if (GetValue(i))
return n;
// 右側にあるtrueを探す
var pre = i;
var next = Parent(pre);
while (0 < next && !(Left(next) == pre && GetValue(Right(next)))) {
pre = next;
next = Parent(pre);
}
if (next < 1)
return -1;
next = Right(next);
while (next < N) {
next = Left(next);
if (!GetValue(next))
next = Right(Parent(next));
}
return next - (N - 1);
}
// 1開始
bool GetValue(int n) => val[n - 1];
void SetValue(int n, bool v) => val[n - 1] = v;
int Parent(int n) => n / 2;
int Left(int n) => n * 2;
int Right(int n) => n * 2 + 1;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static long Mod = (long)998244353;
static void Main(string[] args) {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
var NM = Sarray();
var N = NM[0];
var M = NM[1];
var AB = new List<Tuple<long, long>>();
for (var i = 0; i < N; ++i) {
var ab = Sarray();
AB.Add(Tuple.Create(ab[0], ab[1]));
}
AB.Sort((l, r) => (int)(r.Item2 - l.Item2));
var st = new SegTree((int)M);
var ans = 0L;
foreach (var ab in AB) {
var fd = st.GetFreeday((int)ab.Item1);
if (fd == -1)
continue;
st.Set(fd, false);
ans += ab.Item2;
}
WriteLine(ans);
// Out.Flush();
}
public class SegTree {
int N;
int ON = int.MaxValue;
// left | right
bool[] val;
public SegTree(int n) {
N = 2;
while (N < n)
N <<= 1;
val = Enumerable.Repeat(true, 2 * N - 1).ToArray();
for (var i = n + 1; i <= N; ++i)
Set(i, false);
ON = n;
}
public void Set(int n, bool v) {
if (ON < n)
return;
var i = N - 1 + n;
if (GetValue(i) != v) {
SetValue(i, v);
_chg(i);
}
}
// nが変更された
void _chg(int n) {
var p = Parent(n);
if (p < 1)
return;
var v = GetValue(Left(p)) | GetValue(Right(p));
if (GetValue(p) != v) {
SetValue(p, v);
_chg(p);
}
}
public int GetFreeday(int n) {
if (ON < n)
return -1;
var i = N - 1 + n;
if (GetValue(i))
return n;
// 右側にあるtrueを探す
var pre = i;
var next = Parent(pre);
while (0 < next && !(Left(next) == pre && GetValue(Right(next)))) {
pre = next;
next = Parent(pre);
}
if (next < 1)
return -1;
next = Right(next);
while (next < N) {
next = Left(next);
if (!GetValue(next))
next = Right(Parent(next));
}
return next - (N - 1);
}
// 1開始
bool GetValue(int n) => val[n - 1];
void SetValue(int n, bool v) => val[n - 1] = v;
int Parent(int n) => n / 2;
int Left(int n) => n * 2;
int Right(int n) => n * 2 + 1;
}
}
}
|
[["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 263, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 263, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35], ["+", 0, 263, 8, 196, 0, 7, 8, 1, 0, 35], ["+", 0, 263, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 263, 8, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 725
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
// functions
public void Solve() {
//ここから
int[] o = IO.intm;
int n = o[0];
int m = o[1];
var a = new int[n];
var b = new int[n];
var ab = new Tuple<int, int>[n];
for (int i = 0; i < n; ++i) {
var oo = IO.intm;
ab[i] = new Tuple<int, int>(oo[0], oo[1]);
}
ab = ab.OrderBy(X => X.Item1).ToArray();
var q = new PriorityQueue<Tuple<int, int>>((x, y) => y.Item2 - x.Item2);
int j = 0;
long ans = 0;
for (int i = 1; i <= m; ++i) {
while (j < n && ab[j].Item1 <= i) {
IO.wri(ab[j].Item1);
q.Enqueue(ab[j]);
j++;
}
if (q.Any())
ans += q.Dequeue().Item2;
}
IO.wri(ans);
}
}
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
// b-aで降順
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public double[] doublem => strm.Select(double.Parse).ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
public double double1 => doublem[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("No");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
// functions
public void Solve() {
//ここから
int[] o = IO.intm;
int n = o[0];
int m = o[1];
var a = new int[n];
var b = new int[n];
var ab = new Tuple<int, int>[n];
for (int i = 0; i < n; ++i) {
var oo = IO.intm;
ab[i] = new Tuple<int, int>(oo[0], oo[1]);
}
ab = ab.OrderBy(X => X.Item1).ToArray();
var q = new PriorityQueue<Tuple<int, int>>((x, y) => y.Item2 - x.Item2);
int j = 0;
long ans = 0;
for (int i = 1; i <= m; ++i) {
while (j < n && ab[j].Item1 <= i) {
q.Enqueue(ab[j]);
j++;
}
if (q.Any())
ans += q.Dequeue().Item2;
}
IO.wri(ans);
}
}
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
// b-aで降順
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public double[] doublem => strm.Select(double.Parse).ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
public double double1 => doublem[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("No");
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 214, 205, 204, 205, 22], ["-", 0, 28, 0, 214, 205, 204, 206, 207, 0, 70], ["-", 0, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 214, 205, 204, 206, 207, 0, 73], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 1,455
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC137_D___Summer_Vacation {
class Program {
static void Main(string[] args) {
var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var N = NM[0];
var M = NM[1];
var jobs = new List<int>[M + 1];
for (int i = 0; i < M + 1; i++)
jobs[i] = new List<int>();
for (int i = 0; i < N; i++) {
var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
jobs[ab[0]].Add(ab[1]);
}
var acceptablleJobs = new PriorityQueue<int>(false);
long rewardSum = 0;
for (int day = 1; day <= M; day++) {
foreach (int r in jobs[day])
acceptablleJobs.Push(r);
if (acceptablleJobs.Count() > 0)
rewardSum += acceptablleJobs.Pop();
}
Console.WriteLine(rewardSum);
}
}
class PriorityQueue<T>
where T : IComparable<T> {
private List<T> nodes;
private Boolean isAsc;
public PriorityQueue(Boolean _isAsc) {
this.nodes = new List<T>();
this.isAsc = _isAsc;
}
public int Count() { return this.nodes.Count; }
public T Pop() {
T returnNode = this.nodes[0];
this.nodes[0] = this.nodes[nodes.Count - 1];
this.nodes.RemoveAt(nodes.Count - 1);
int root = 0;
while (root * 2 + 1 < this.nodes.Count) {
int child = root * 2 + 1;
if (child + 1 < this.nodes.Count &&
compare(this.nodes[child + 1], this.nodes[child]) > 0)
child += 1;
if (compare(this.nodes[child], this.nodes[root]) > 0) {
swap(child, root);
root = child;
} else {
break;
}
}
return returnNode;
}
public T Top() { return this.nodes[0]; }
public void Push(T t) {
this.nodes.Add(t);
var addPosition = nodes.Count - 1;
while (addPosition > 0) {
var parent = (int)(addPosition - 1) / 2;
if (compare(nodes[addPosition], nodes[parent]) > 0) {
swap(addPosition, parent);
addPosition = parent;
} else {
break;
}
}
}
private int compare(T x, T y) {
return this.isAsc ? y.CompareTo(x) : x.CompareTo(y);
}
private void swap(int x, int y) {
T temp = nodes[x];
nodes[x] = nodes[y];
nodes[y] = temp;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC137_D___Summer_Vacation {
class Program {
static void Main(string[] args) {
var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var N = NM[0];
var M = NM[1];
var jobs = new List<int>[M + 1];
for (int i = 0; i < M + 1; i++)
jobs[i] = new List<int>();
for (int i = 0; i < N; i++) {
var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
if (ab[0] <= M)
jobs[ab[0]].Add(ab[1]);
}
var acceptablleJobs = new PriorityQueue<int>(false);
long rewardSum = 0;
for (int day = 1; day <= M; day++) {
foreach (int r in jobs[day])
acceptablleJobs.Push(r);
if (acceptablleJobs.Count() > 0)
rewardSum += acceptablleJobs.Pop();
}
Console.WriteLine(rewardSum);
}
}
class PriorityQueue<T>
where T : IComparable<T> {
private List<T> nodes;
private Boolean isAsc;
public PriorityQueue(Boolean _isAsc) {
this.nodes = new List<T>();
this.isAsc = _isAsc;
}
public int Count() { return this.nodes.Count; }
public T Pop() {
T returnNode = this.nodes[0];
this.nodes[0] = this.nodes[nodes.Count - 1];
this.nodes.RemoveAt(nodes.Count - 1);
int root = 0;
while (root * 2 + 1 < this.nodes.Count) {
int child = root * 2 + 1;
if (child + 1 < this.nodes.Count &&
compare(this.nodes[child + 1], this.nodes[child]) > 0)
child += 1;
if (compare(this.nodes[child], this.nodes[root]) > 0) {
swap(child, root);
root = child;
} else {
break;
}
}
return returnNode;
}
public T Top() { return this.nodes[0]; }
public void Push(T t) {
this.nodes.Add(t);
var addPosition = nodes.Count - 1;
while (addPosition > 0) {
var parent = (int)(addPosition - 1) / 2;
if (compare(nodes[addPosition], nodes[parent]) > 0) {
swap(addPosition, parent);
addPosition = parent;
} else {
break;
}
}
}
private int compare(T x, T y) {
return this.isAsc ? y.CompareTo(x) : x.CompareTo(y);
}
private void swap(int x, int y) {
T temp = nodes[x];
nodes[x] = nodes[y];
nodes[y] = temp;
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
| 8
| 639
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ABC137_D {
class Program {
static void Main(string[] args) {
var NM = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
var N = NM[0];
var M = NM[1];
var list = new List<int>[M + 1];
for (int i = 0; i < N; i++) {
var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
if (line[0] > M)
continue;
if (list[line[0]] == null)
list[line[0]] = new List<int>();
list[line[0]].Add(line[1]);
}
long ans = 0;
var cand = new PriorityQueue<int>();
for (int i = 0; i < M; i++) {
foreach (var item in list[i + 1]) {
cand.Push(item);
}
if (cand.Count == 0)
continue;
var mx = cand.Pop();
}
Console.WriteLine(ans);
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public int Count { get; private set; }
private bool Descendance;
private T[] data = new T[65536];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PriorityQueue(bool descendance = false) { Descendance = descendance; }
public T Top {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
ValidateNonEmpty();
return data[1];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Pop() {
var top = Top;
var elem = data[Count--];
int index = 1;
while (true) {
if ((index << 1) >= Count) {
if (index << 1 > Count)
break;
if (elem.CompareTo(data[index << 1]) > 0 ^ Descendance)
data[index] = data[index <<= 1];
else
break;
} else {
var nextIndex =
data[index << 1].CompareTo(data[(index << 1) + 1]) <= 0 ^
Descendance
? (index << 1)
: (index << 1) + 1;
if (elem.CompareTo(data[nextIndex]) > 0 ^ Descendance)
data[index] = data[index = nextIndex];
else
break;
}
}
data[index] = elem;
return top;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T value) {
int index = ++Count;
if (data.Length == Count)
Extend(data.Length * 2);
while ((index >> 1) != 0) {
if (data[index >> 1].CompareTo(value) > 0 ^ Descendance)
data[index] = data[index >>= 1];
else
break;
}
data[index] = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Extend(int newSize) {
T[] newDatas = new T[newSize];
data.CopyTo(newDatas, 0);
data = newDatas;
}
private void ValidateNonEmpty() {
if (Count == 0)
throw new Exception();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ABC137_D {
class Program {
static void Main(string[] args) {
var NM = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
var N = NM[0];
var M = NM[1];
var list = new List<int>[M + 1];
for (int i = 0; i < N; i++) {
var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
if (line[0] > M)
continue;
if (list[line[0]] == null)
list[line[0]] = new List<int>();
list[line[0]].Add(line[1]);
}
long ans = 0;
var cand = new PriorityQueue<int>(true);
for (int i = 0; i < M; i++) {
if (list[i + 1] != null)
foreach (var item in list[i + 1]) {
cand.Push(item);
}
if (cand.Count == 0)
continue;
ans += cand.Pop();
}
Console.WriteLine(ans);
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public int Count { get; private set; }
private bool Descendance;
private T[] data = new T[65536];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PriorityQueue(bool descendance = false) { Descendance = descendance; }
public T Top {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
ValidateNonEmpty();
return data[1];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Pop() {
var top = Top;
var elem = data[Count--];
int index = 1;
while (true) {
if ((index << 1) >= Count) {
if (index << 1 > Count)
break;
if (elem.CompareTo(data[index << 1]) > 0 ^ Descendance)
data[index] = data[index <<= 1];
else
break;
} else {
var nextIndex =
data[index << 1].CompareTo(data[(index << 1) + 1]) <= 0 ^
Descendance
? (index << 1)
: (index << 1) + 1;
if (elem.CompareTo(data[nextIndex]) > 0 ^ Descendance)
data[index] = data[index = nextIndex];
else
break;
}
}
data[index] = elem;
return top;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T value) {
int index = ++Count;
if (data.Length == Count)
Extend(data.Length * 2);
while ((index >> 1) != 0) {
if (data[index >> 1].CompareTo(value) > 0 ^ Descendance)
data[index] = data[index >>= 1];
else
break;
}
data[index] = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Extend(int newSize) {
T[] newDatas = new T[newSize];
data.CopyTo(newDatas, 0);
data = newDatas;
}
private void ValidateNonEmpty() {
if (Count == 0)
throw new Exception();
}
}
}
|
[["+", 0, 230, 3, 4, 0, 28, 0, 211, 0, 146], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 215], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
| 8
| 698
| 17
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using E = System.Linq.Enumerable;
internal partial class Solver {
struct Edge {
public int From, To, Cost;
}
public void Run() {
var n = ni();
var m = ni();
var p = ni();
var adj = Enumerable.Range(0, n).Select(_ => new List<Edge>()).ToArray();
for (int i = 0; i < m; i++) {
var a = ni() - 1;
var b = ni() - 1;
var c = ni();
adj[a].Add(new Edge { From = a, To = b, Cost = c - p });
}
var ans = BellmanFord(adj);
cout.WriteLine(ans);
}
private long BellmanFord(List<Edge>[] adj) {
var n = adj.Length;
var maxScore = new long[n];
var inf = (long)1e10;
for (int i = 0; i < n; i++) {
maxScore[i] = -inf;
}
maxScore[0] = 0;
for (int i = 0; i < 5 * n; i++) {
for (int j = 0; j < n; j++) {
foreach (var edge in adj[j]) {
if (maxScore[edge.To] < maxScore[edge.From] + edge.Cost) {
maxScore[edge.To] = maxScore[edge.From] + edge.Cost;
if (i >= n) {
maxScore[edge.To] = inf;
}
}
}
}
}
if (maxScore[n - 1] >= inf)
return -1;
return Math.Max(0, maxScore[n - 1]);
}
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
new Solver(Console.In, Console.Out).Run();
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
internal static class LinqPadExtension {
public static T Dump<T>(this T obj) {
#if LOCAL
return LINQPad.Extensions.Dump(obj);
#else
return obj;
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (TokenQueue.Count == 0) {
if (!StockTokens()) {
throw new InvalidOperationException();
}
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0) {
return true;
}
return StockTokens();
}
private static readonly char[] _separator = new[] { ' ', '\t' };
private bool StockTokens() {
while (true) {
string line = Reader.ReadLine();
if (line == null) {
return false;
}
string[] tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0) {
continue;
}
foreach (string token in tokens) {
TokenQueue.Enqueue(token);
}
return true;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using E = System.Linq.Enumerable;
internal partial class Solver {
struct Edge {
public int From, To, Cost;
}
public void Run() {
var n = ni();
var m = ni();
var p = ni();
var adj = Enumerable.Range(0, n).Select(_ => new List<Edge>()).ToArray();
for (int i = 0; i < m; i++) {
var a = ni() - 1;
var b = ni() - 1;
var c = ni();
adj[a].Add(new Edge { From = a, To = b, Cost = c - p });
}
var ans = BellmanFord(adj);
cout.WriteLine(ans);
}
private long BellmanFord(List<Edge>[] adj) {
var n = adj.Length;
var maxScore = new long[n];
var inf = (long)1e10;
for (int i = 0; i < n; i++) {
maxScore[i] = -inf;
}
maxScore[0] = 0;
for (int i = 0; i < 2 * n; i++) {
for (int j = 0; j < n; j++) {
foreach (var edge in adj[j]) {
if (maxScore[edge.From] == -inf)
continue;
if (maxScore[edge.To] < maxScore[edge.From] + edge.Cost) {
maxScore[edge.To] = maxScore[edge.From] + edge.Cost;
if (i >= n) {
maxScore[edge.To] = inf;
}
}
}
}
}
if (maxScore[n - 1] >= inf)
return -1;
return Math.Max(0, maxScore[n - 1]);
}
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
new Solver(Console.In, Console.Out).Run();
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
internal static class LinqPadExtension {
public static T Dump<T>(this T obj) {
#if LOCAL
return LINQPad.Extensions.Dump(obj);
#else
return obj;
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (TokenQueue.Count == 0) {
if (!StockTokens()) {
throw new InvalidOperationException();
}
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0) {
return true;
}
return StockTokens();
}
private static readonly char[] _separator = new[] { ' ', '\t' };
private bool StockTokens() {
while (true) {
string line = Reader.ReadLine();
if (line == null) {
return false;
}
string[] tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0) {
continue;
}
foreach (string token in tokens) {
TokenQueue.Enqueue(token);
}
return true;
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 205, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 0, 131], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 210, 8, 196, 0, 57, 64, 116, 0, 35]]
| 8
| 1,205
| 16
|
using Training20200530.Questions;
using Training20200530.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Training20200530.Algorithms;
namespace Training20200530.Questions {
/// <summary>
/// https://atcoder.jp/contests/abc137/tasks/abc137_e
/// </summary>
public class QuestionB : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var nmp = inputStream.ReadIntArray();
var nodesCount = nmp[0];
var edgesCount = nmp[1];
var penalty = nmp[2];
var graph = new WeightedGraph(
nodesCount, Enumerable.Repeat(0, edgesCount).Select(_ => {
var abc = inputStream.ReadIntArray();
var a = abc[0] - 1;
var b = abc[1] - 1;
var c = abc[2];
return new WeightedEdge(a, b, penalty - c);
}));
var bellmanFord = new BellmanFord<BasicNode, WeightedEdge>(graph);
var result = bellmanFord.GetDistancesFrom(new BasicNode(0));
var distances = result.Item1;
var negativeCycleNodes = result.Item2;
if (negativeCycleNodes[nodesCount - 1]) {
yield return -1;
} else {
yield return Math.Max(-distances[nodesCount - 1], 0);
}
}
}
}
namespace Training20200530 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionB(); // 問題に合わせて書き換え
var answers =
question.Solve(new StreamReader(@"C:\Users\amats\Downloads\b46"));
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
public interface INode {
int Index { get; }
}
public interface IEdge<TNode>
where TNode : INode {
TNode From { get; }
TNode To { get; }
}
public interface IWeightedEdge<TNode> : IEdge<TNode>
where TNode : INode {
int Weight { get; }
}
public interface IGraph<TNode, TEdge>
where TEdge : IEdge<TNode>
where TNode : INode {
IEnumerable<TEdge> this[TNode node] { get; }
IEnumerable<TEdge> Edges { get; }
IEnumerable<TNode> Nodes { get; }
int NodeCount { get; }
}
public struct BasicNode : INode {
public int Index { get; }
public BasicNode(int index) { Index = index; }
public override string ToString() => Index.ToString();
}
[System.Runtime.InteropServices.StructLayout(
System.Runtime.InteropServices.LayoutKind.Auto)]
public struct WeightedEdge : IWeightedEdge<BasicNode> {
public BasicNode From { get; }
public BasicNode To { get; }
public int Weight { get; }
public WeightedEdge(int from, int to) : this(from, to, 1) {}
public WeightedEdge(int from, int to, int weight) {
From = new BasicNode(from);
To = new BasicNode(to);
Weight = weight;
}
public override string ToString() => $"{From}--[{Weight}]-->{To}";
}
public class WeightedGraph : IGraph<BasicNode, WeightedEdge> {
private readonly List<WeightedEdge>[] _edges;
public IEnumerable<WeightedEdge> this[BasicNode node] => _edges[node.Index];
public IEnumerable<WeightedEdge> Edges =>
Nodes.SelectMany(node => this[node]);
public IEnumerable<BasicNode> Nodes =>
Enumerable.Range(0, NodeCount).Select(i => new BasicNode(i));
public int NodeCount { get; }
public WeightedGraph(int nodeCount)
: this(nodeCount, Enumerable.Empty<WeightedEdge>()) {}
public WeightedGraph(int nodeCount, IEnumerable<WeightedEdge> edges) {
_edges = Enumerable.Repeat(0, nodeCount)
.Select(_ => new List<WeightedEdge>())
.ToArray();
NodeCount = nodeCount;
foreach (var edge in edges) {
AddEdge(edge);
}
}
public WeightedGraph(int nodeCount, IEnumerable<IEnumerable<int>> distances) {
_edges = new List<WeightedEdge>[nodeCount];
int i = 0;
foreach (var row in distances) {
_edges[i] = new List<WeightedEdge>(nodeCount);
int j = 0;
foreach (var distance in row) {
_edges[i].Add(new WeightedEdge(i, j++, distance));
}
i++;
}
}
public void AddEdge(WeightedEdge edge) => _edges[edge.From.Index].Add(edge);
}
namespace Algorithms {
public class BellmanFord<TNode, TEdge>
where TEdge : IWeightedEdge<TNode>
where TNode : INode {
protected readonly List<TEdge> _edges;
protected readonly int _nodeCount;
public BellmanFord(IGraph<TNode, TEdge> graph)
: this(graph.Edges, graph.NodeCount) {}
public BellmanFord(IEnumerable<TEdge> edges, int nodeCount) {
_edges = edges.ToList();
_nodeCount = nodeCount;
}
public Tuple<long[], bool[]> GetDistancesFrom(TNode startNode) {
const long Inf = 1L << 60;
var distances = Enumerable.Repeat(Inf, _nodeCount).ToArray();
var negativeCycleNodes = new bool[_nodeCount];
distances[startNode.Index] = 0;
for (int i = 1; i <= 2 * _nodeCount; i++) {
foreach (var edge in _edges) {
// そもそも出発点に未到達なら無視
if (distances[edge.From.Index] < (Inf >> 1)) {
var newCost = distances[edge.From.Index] + edge.Weight;
if (distances[edge.To.Index] > newCost) {
distances[edge.To.Index] = newCost;
if (i >= _nodeCount) {
negativeCycleNodes[edge.To.Index] = true;
}
}
if (negativeCycleNodes[edge.From.Index]) {
negativeCycleNodes[edge.To.Index] = true;
}
}
}
}
for (int i = 0; i < _nodeCount; i++) {
if (negativeCycleNodes[i]) {
distances[i] = long.MinValue;
}
}
return new Tuple<long[], bool[]>(distances, negativeCycleNodes);
}
}
}
}
#region Base Classes
namespace Training20200530.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace Training20200530.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
using Training20200530.Questions;
using Training20200530.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Training20200530.Algorithms;
namespace Training20200530.Questions {
/// <summary>
/// https://atcoder.jp/contests/abc137/tasks/abc137_e
/// </summary>
public class QuestionB : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var nmp = inputStream.ReadIntArray();
var nodesCount = nmp[0];
var edgesCount = nmp[1];
var penalty = nmp[2];
var graph = new WeightedGraph(
nodesCount, Enumerable.Repeat(0, edgesCount).Select(_ => {
var abc = inputStream.ReadIntArray();
var a = abc[0] - 1;
var b = abc[1] - 1;
var c = abc[2];
return new WeightedEdge(a, b, penalty - c);
}));
var bellmanFord = new BellmanFord<BasicNode, WeightedEdge>(graph);
var result = bellmanFord.GetDistancesFrom(new BasicNode(0));
var distances = result.Item1;
var negativeCycleNodes = result.Item2;
if (negativeCycleNodes[nodesCount - 1]) {
yield return -1;
} else {
yield return Math.Max(-distances[nodesCount - 1], 0);
}
}
}
}
namespace Training20200530 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionB(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
public interface INode {
int Index { get; }
}
public interface IEdge<TNode>
where TNode : INode {
TNode From { get; }
TNode To { get; }
}
public interface IWeightedEdge<TNode> : IEdge<TNode>
where TNode : INode {
int Weight { get; }
}
public interface IGraph<TNode, TEdge>
where TEdge : IEdge<TNode>
where TNode : INode {
IEnumerable<TEdge> this[TNode node] { get; }
IEnumerable<TEdge> Edges { get; }
IEnumerable<TNode> Nodes { get; }
int NodeCount { get; }
}
public struct BasicNode : INode {
public int Index { get; }
public BasicNode(int index) { Index = index; }
public override string ToString() => Index.ToString();
}
[System.Runtime.InteropServices.StructLayout(
System.Runtime.InteropServices.LayoutKind.Auto)]
public struct WeightedEdge : IWeightedEdge<BasicNode> {
public BasicNode From { get; }
public BasicNode To { get; }
public int Weight { get; }
public WeightedEdge(int from, int to) : this(from, to, 1) {}
public WeightedEdge(int from, int to, int weight) {
From = new BasicNode(from);
To = new BasicNode(to);
Weight = weight;
}
public override string ToString() => $"{From}--[{Weight}]-->{To}";
}
public class WeightedGraph : IGraph<BasicNode, WeightedEdge> {
private readonly List<WeightedEdge>[] _edges;
public IEnumerable<WeightedEdge> this[BasicNode node] => _edges[node.Index];
public IEnumerable<WeightedEdge> Edges =>
Nodes.SelectMany(node => this[node]);
public IEnumerable<BasicNode> Nodes =>
Enumerable.Range(0, NodeCount).Select(i => new BasicNode(i));
public int NodeCount { get; }
public WeightedGraph(int nodeCount)
: this(nodeCount, Enumerable.Empty<WeightedEdge>()) {}
public WeightedGraph(int nodeCount, IEnumerable<WeightedEdge> edges) {
_edges = Enumerable.Repeat(0, nodeCount)
.Select(_ => new List<WeightedEdge>())
.ToArray();
NodeCount = nodeCount;
foreach (var edge in edges) {
AddEdge(edge);
}
}
public WeightedGraph(int nodeCount, IEnumerable<IEnumerable<int>> distances) {
_edges = new List<WeightedEdge>[nodeCount];
int i = 0;
foreach (var row in distances) {
_edges[i] = new List<WeightedEdge>(nodeCount);
int j = 0;
foreach (var distance in row) {
_edges[i].Add(new WeightedEdge(i, j++, distance));
}
i++;
}
}
public void AddEdge(WeightedEdge edge) => _edges[edge.From.Index].Add(edge);
}
namespace Algorithms {
public class BellmanFord<TNode, TEdge>
where TEdge : IWeightedEdge<TNode>
where TNode : INode {
protected readonly List<TEdge> _edges;
protected readonly int _nodeCount;
public BellmanFord(IGraph<TNode, TEdge> graph)
: this(graph.Edges, graph.NodeCount) {}
public BellmanFord(IEnumerable<TEdge> edges, int nodeCount) {
_edges = edges.ToList();
_nodeCount = nodeCount;
}
public Tuple<long[], bool[]> GetDistancesFrom(TNode startNode) {
var distances = Enumerable.Repeat(long.MaxValue, _nodeCount).ToArray();
var negativeCycleNodes = new bool[_nodeCount];
distances[startNode.Index] = 0;
for (int i = 1; i <= 2 * _nodeCount; i++) {
foreach (var edge in _edges) {
// そもそも出発点に未到達なら無視
if (distances[edge.From.Index] < (long.MaxValue >> 1)) {
var newCost = distances[edge.From.Index] + edge.Weight;
if (distances[edge.To.Index] > newCost) {
distances[edge.To.Index] = newCost;
if (i >= _nodeCount) {
negativeCycleNodes[edge.To.Index] = true;
}
}
if (negativeCycleNodes[edge.From.Index]) {
negativeCycleNodes[edge.To.Index] = true;
}
}
}
}
for (int i = 0; i < _nodeCount; i++) {
if (negativeCycleNodes[i]) {
distances[i] = long.MinValue;
}
}
return new Tuple<long[], bool[]>(distances, negativeCycleNodes);
}
}
}
}
#region Base Classes
namespace Training20200530.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace Training20200530.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
[["-", 0, 213, 3, 4, 0, 28, 0, 230, 0, 228], ["-", 0, 213, 3, 4, 0, 28, 0, 230, 39, 22], ["-", 3, 4, 0, 28, 0, 230, 3, 4, 0, 24], ["-", 0, 28, 0, 230, 3, 4, 0, 28, 0, 258], ["-", 3, 4, 0, 28, 0, 230, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 251, 0, 154], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 151], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 214, 205, 199], ["+", 15, 16, 12, 23, 0, 16, 31, 214, 0, 131], ["+", 15, 16, 12, 23, 0, 16, 31, 214, 141, 22]]
| 8
| 1,553
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
static class CodeJam {
class Edge {
public readonly int A;
public readonly int B;
public readonly int C;
public Edge(int[] args) {
A = args[0] - 1;
B = args[1] - 1;
C = args[2];
}
}
static bool[] Research(Edge[] edges, int N) {
var nexts = new List<int>[N];
for (int i = 0; i < N; ++i) {
nexts[i] = new List<int>();
}
foreach (var e in edges) {
nexts[e.B].Add(e.A);
}
var connected = new bool[N];
connected[N - 1] = true;
var q = new Queue<int>();
q.Enqueue(N - 1);
while (q.Count > 0) {
int a = q.Dequeue();
foreach (int b in nexts[a]) {
if (!connected[b]) {
connected[b] = true;
q.Enqueue(b);
}
}
}
return connected;
}
static int Solve(int N, int M, int P, Edge[] edges) {
const int INF = int.MaxValue / 2;
var D = Enumerable.Repeat(INF, N).ToArray();
D[0] = 0;
var connected = Research(edges, N);
for (int i = 0; i < N; ++i) {
foreach (var e in edges) {
if (D[e.A] < INF && connected[e.A] && connected[e.B]) {
int d = Math.Min(D[e.A] + P - e.C, 0);
if (d < D[e.B]) {
if (i == N - 1) {
return -1;
}
D[e.B] = d;
}
}
}
}
return (D[N - 1] < INF) ? Math.Max(-D[N - 1], 0) : -1;
}
static void Main(string[] args) {
var V1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int N = V1[0], M = V1[1], P = V1[2];
var edges = new Edge[M];
for (int i = 0; i < M; ++i) {
var V2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
edges[i] = new Edge(V2);
}
Console.WriteLine(Solve(N, M, P, edges));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
static class CodeJam {
class Edge {
public readonly int A;
public readonly int B;
public readonly int C;
public Edge(int[] args) {
A = args[0] - 1;
B = args[1] - 1;
C = args[2];
}
}
static bool[] Research(Edge[] edges, int N) {
var nexts = new List<int>[N];
for (int i = 0; i < N; ++i) {
nexts[i] = new List<int>();
}
foreach (var e in edges) {
nexts[e.B].Add(e.A);
}
var connected = new bool[N];
connected[N - 1] = true;
var q = new Queue<int>();
q.Enqueue(N - 1);
while (q.Count > 0) {
int a = q.Dequeue();
foreach (int b in nexts[a]) {
if (!connected[b]) {
connected[b] = true;
q.Enqueue(b);
}
}
}
return connected;
}
static int Solve(int N, int M, int P, Edge[] edges) {
const int INF = int.MaxValue / 2;
var D = Enumerable.Repeat(INF, N).ToArray();
D[0] = 0;
var connected = Research(edges, N);
for (int i = 0; i < N; ++i) {
foreach (var e in edges) {
if (D[e.A] < INF && connected[e.A] && connected[e.B] &&
D[e.A] + P - e.C < D[e.B]) {
if (i == N - 1) {
return -1;
}
D[e.B] = D[e.A] + P - e.C;
}
}
}
return (D[N - 1] < INF) ? Math.Max(-D[N - 1], 0) : -1;
}
static void Main(string[] args) {
var V1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int N = V1[0], M = V1[1], P = V1[2];
var edges = new Edge[M];
for (int i = 0; i < M; ++i) {
var V2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
edges[i] = new Edge(V2);
}
Console.WriteLine(Solve(N, M, P, edges));
}
}
|
[["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["-", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 205, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 0, 131], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 141, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 16, 12, 214, 141, 22], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 600
| 31
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace ABC137E_2 {
class Program {
public static void Solve(Input input) {
var n = input.NextInt();
var m = input.NextInt();
var p = input.NextInt();
var bf = new BellmanFord(n);
for (int i = 0; i < m; i++) {
var a = input.NextInt() - 1;
var b = input.NextInt() - 1;
var c = -(input.NextInt() - p);
bf.AddPath(a, b, c);
}
var sp = bf.ShortestPath(0, true);
if (sp[n - 1] == BellmanFord.NegCycle) {
Console.WriteLine("-1");
} else {
Console.WriteLine(Math.Max(0, -sp[n - 1]));
}
}
/// <summary>
/// 重み付き・有向グラフの単一始点最短経路
/// 辺の重みが負数でもOK(てか負数ないならDijkstra使って)
/// </summary>
class BellmanFord {
public static readonly long Inf = long.MaxValue / 3;
public static readonly long NegCycle = -Inf;
struct Edge {
public int From;
public int To;
public long Cost;
public Edge(int from, int to, long cost) {
this.From = from;
this.To = to;
this.Cost = cost;
}
}
// 接続情報
readonly List<Edge> es;
// ノード数
readonly int V;
/// <summary>
///
/// </summary>
/// <param name="v">ノード数</param>
public BellmanFord(int v) {
es = new List<Edge>();
V = v;
}
/// <summary>
/// 経路追加
/// </summary>
public void AddPath(int from, int to,
long cost) => es.Add(new Edge(from, to, cost));
/// <summary>
/// sから各ノードへの最短経路
///
/// needsDetailがtrue
/// sとの経路に負の閉路がある: NegSycle
///
/// needsDetailがfalse
/// 一つでも閉路があればnullを返す
/// </summary>
public long[] ShortestPath(int s, bool needsDetail) {
var E = this.es.Count();
var d = Enumerable.Repeat(Inf, V).ToArray();
d[s] = 0;
int count = RelaxEdges(E, d, (x, y) => x + y);
// 閉路が一つでもある
if (needsDetail && count > V - 1)
return null;
// 詳細な負の閉路検出
RelaxEdges(E, d, (x, y) => NegCycle);
return d;
}
/// <summary>
/// 辺の緩和
/// </summary>
int RelaxEdges(int E, long[] d, Func<long, long, long> relax) {
int count;
for (count = 0; count < V; count++) {
var update = false;
for (int i = 0; i < E; i++) {
var e = es[i];
if (d[e.From] == Inf)
continue;
if (d[e.To] > d[e.From] + e.Cost) {
d[e.To] = relax(d[e.From], e.Cost);
update = true;
}
}
if (!update)
break;
}
return count;
}
}
#region Main
public static void Main(string[] args) {
// 出力が少ないときはこれをセットする方が時間かかるけれど
// そのときにTLEするのはアルゴリズムが悪いせいだし、まあ良しとする
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input();
// 仮想的に標準入力をセットする
// テスト入力したまま提出することがままあるので……
#if DEBUG
input.SetText("");
#endif
Solve(input);
Console.Out.Flush();
}
#endregion
#region Competitive Template
#pragma warning disable CS0414
static readonly int MOD = (int)1e9 + 7;
static readonly int[] dx = { 1, 0, -1, 0 };
static readonly int[] dy = { 0, 1, 0, -1 };
/// <summary> 左上が原点 </summary>
static readonly char[] dir = { 'R', 'U', 'L', 'D' };
#pragma warning restore CS0414
public class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
// スペース単独指定の方がもちろん早い
static readonly char[] separator = { ' ', '\r', '\n' };
readonly StreamReader sr;
readonly Queue<string> queue;
/// <summary>
/// 特定のファイルから読み出したい場合はpath指定する
/// </summary>
public Input(string path = "") {
queue = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
public void SetText(IEnumerable<string> items) {
foreach (var item in items)
SetText(item);
}
/// <summary>
/// 入力予約
/// </summary>
public bool SetText(string s) {
if (string.IsNullOrEmpty(s))
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries))
queue.Enqueue(elem);
return true;
}
/// <summary>
/// 要素が存在するか
/// </summary>
public bool Any() => queue.Any() || Read();
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
bool Read() {
if (!SetText(sr.ReadLine()))
return false;
if (!queue.Any())
return Read();
return queue.Any();
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
public string Next() {
if (!queue.Any() && !Read())
return "";
return queue.Dequeue();
}
/// <summary>
/// 指定個数queueにたまるまでenqueueし続ける
/// </summary>
bool Accumulate(int n) {
while (queue.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>
T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) {
if (!Accumulate(n))
return null;
var a = new T[n];
for (int i = 0; i < n; i++)
a[i] = add(parse(queue.Dequeue()), offset);
return a;
}
public string[] Next(int n) => 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 T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
/// <summary>
/// vでfillされたT[d1][d2]配列を作成する
/// </summary>
public static T[][] Create2DArray<T>(int d1, int d2, T v) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(v, d2).ToArray())
.ToArray();
}
/// <summary>
/// vでfillされたT[d1][d2][d3]配列を作成する
/// </summary>
public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v) {
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 ABC137E_2 {
class Program {
public static void Solve(Input input) {
var n = input.NextInt();
var m = input.NextInt();
var p = input.NextInt();
var bf = new BellmanFord(n);
for (int i = 0; i < m; i++) {
var a = input.NextInt() - 1;
var b = input.NextInt() - 1;
var c = -(input.NextInt() - p);
bf.AddPath(a, b, c);
}
var sp = bf.ShortestPath(0, true);
if (sp[n - 1] == BellmanFord.NegCycle) {
Console.WriteLine("-1");
} else {
Console.WriteLine(Math.Max(0, -sp[n - 1]));
}
}
/// <summary>
/// 重み付き・有向グラフの単一始点最短経路
/// 辺の重みが負数でもOK(てか負数ないならDijkstra使って)
/// </summary>
class BellmanFord {
public static readonly long Inf = long.MaxValue / 3;
public static readonly long NegCycle = -Inf;
public bool HasNegCycle = false;
struct Edge {
public int From;
public int To;
public long Cost;
public Edge(int from, int to, long cost) {
From = from;
To = to;
Cost = cost;
}
}
// 接続情報
readonly List<Edge> es;
// ノード数
readonly int V;
/// <summary>
///
/// </summary>
/// <param name="v">ノード数</param>
public BellmanFord(int v) {
es = new List<Edge>();
V = v;
}
/// <summary>
/// 経路追加
/// </summary>
public void AddPath(int from, int to,
long cost) => es.Add(new Edge(from, to, cost));
/// <summary>
/// sから各ノードへの最短経路
/// 負の経路がある場合HasNegCycleがtrueになる
///
/// needsDetailがtrue
/// sとの経路に負の閉路があるノードはNegCycle
///
/// needsDetailがfalse
/// 負の経路がある辺の情報は不確かのまま
/// </summary>
public long[] ShortestPath(int s, bool needsDetail) {
var E = es.Count();
var d = Enumerable.Repeat(Inf, V).ToArray();
d[s] = 0;
int count = RelaxEdges(E, d, (x, y) => x + y);
// 閉路が一つでもある
HasNegCycle = count > V - 1;
if (needsDetail) {
// 詳細な負の閉路検出
RelaxEdges(E, d, (x, y) => NegCycle);
}
return d;
}
/// <summary>
/// 辺の緩和
/// </summary>
int RelaxEdges(int E, long[] d, Func<long, long, long> relax) {
int count;
for (count = 0; count < V; count++) {
var update = false;
for (int i = 0; i < E; i++) {
var e = es[i];
if (d[e.From] == Inf)
continue;
if (d[e.To] > d[e.From] + e.Cost) {
d[e.To] = relax(d[e.From], e.Cost);
update = true;
}
}
if (!update)
break;
}
return count;
}
}
#region Main
public static void Main(string[] args) {
// 出力が少ないときはこれをセットする方が時間かかるけれど
// そのときにTLEするのはアルゴリズムが悪いせいだし、まあ良しとする
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 通常は引数無しで、ファイルから読み出したい場合はpath指定する
var input = new Input();
// 仮想的に標準入力をセットする
// テスト入力したまま提出することがままあるので……
#if DEBUG
input.SetText("");
#endif
Solve(input);
Console.Out.Flush();
}
#endregion
#region Competitive Template
#pragma warning disable CS0414
static readonly int MOD = (int)1e9 + 7;
static readonly int[] dx = { 1, 0, -1, 0 };
static readonly int[] dy = { 0, 1, 0, -1 };
/// <summary> 左上が原点 </summary>
static readonly char[] dir = { 'R', 'U', 'L', 'D' };
#pragma warning restore CS0414
public class Input {
// 変な改行コードがたまに混じっているので、一応セパレート指定する
// スペース単独指定の方がもちろん早い
static readonly char[] separator = { ' ', '\r', '\n' };
readonly StreamReader sr;
readonly Queue<string> queue;
/// <summary>
/// 特定のファイルから読み出したい場合はpath指定する
/// </summary>
public Input(string path = "") {
queue = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
/// <summary>
/// 入力予約
/// </summary>
public void SetText(IEnumerable<string> items) {
foreach (var item in items)
SetText(item);
}
/// <summary>
/// 入力予約
/// </summary>
public bool SetText(string s) {
if (string.IsNullOrEmpty(s))
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries))
queue.Enqueue(elem);
return true;
}
/// <summary>
/// 要素が存在するか
/// </summary>
public bool Any() => queue.Any() || Read();
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
bool Read() {
if (!SetText(sr.ReadLine()))
return false;
if (!queue.Any())
return Read();
return queue.Any();
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
public string Next() {
if (!queue.Any() && !Read())
return "";
return queue.Dequeue();
}
/// <summary>
/// 指定個数queueにたまるまでenqueueし続ける
/// </summary>
bool Accumulate(int n) {
while (queue.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>
T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) {
if (!Accumulate(n))
return null;
var a = new T[n];
for (int i = 0; i < n; i++)
a[i] = add(parse(queue.Dequeue()), offset);
return a;
}
public string[] Next(int n) => 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 T Max<T>(params T[] objs) => objs.Max();
public static T Min<T>(params T[] objs) => objs.Min();
/// <summary>
/// vでfillされたT[d1][d2]配列を作成する
/// </summary>
public static T[][] Create2DArray<T>(int d1, int d2, T v) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(v, d2).ToArray())
.ToArray();
}
/// <summary>
/// vでfillされたT[d1][d2][d3]配列を作成する
/// </summary>
public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v) {
return Enumerable.Repeat(0, d1)
.Select(_ => Enumerable.Repeat(0, d2)
.Select(__ => Enumerable.Repeat(v, d3).ToArray())
.ToArray())
.ToArray();
}
}
#endregion
}
}
|
[["+", 0, 235, 8, 201, 0, 124, 0, 251, 0, 259], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 1, 0, 11, 31, 214, 205, 273, 0, 274], ["-", 8, 196, 0, 1, 0, 11, 31, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 214, 205, 273, 0, 274], ["-", 0, 212, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 215], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,567
| 29
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Contest {
const long MOD1 = 1000000007L; // 10^9+7
public static void Main() {
int n, m, p;
VT<int, int, int>[] abcl;
MyIO.ReadMulti(out n, out m, out p);
MyIO.ReadLines(m, out abcl);
VT<int, int, int>[] edges = new VT<int, int, int>[m];
for (int i = 0; i < m; i++)
edges[i] = new VT<int, int, int>(abcl[i].Item1 - 1, abcl[i].Item2 - 1,
-1 * (abcl[i].Item3 - p));
long[] r = BellmanFord(edges, n, 0);
if (r[n - 1] == long.MinValue) {
MyIO.WriteMulti(-1);
} else if (0 < r[n - 1]) {
MyIO.WriteMulti(0);
} else {
MyIO.WriteMulti(-r[n - 1]);
}
}
public static long[] BellmanFord(VT<int, int, int>[] inEdges, int V,
int start) {
long[] dist = Enumerable.Repeat(long.MaxValue, V).ToArray();
dist[start] = 0;
for (int i = 0; i < V - 1; i++) {
foreach (var e in inEdges) {
if (dist[e.Item1] == long.MaxValue)
continue;
dist[e.Item2] = Math.Min(dist[e.Item2], dist[e.Item1] + e.Item3);
}
}
foreach (var e in inEdges) {
if (dist[e.Item1] == long.MaxValue)
continue;
// if(dist[e.Item1] + e.Item3 < dist[e.Item2])
//return new long[0];
if (dist[e.Item1] + e.Item3 < dist[e.Item2])
dist[e.Item2] = long.MinValue;
if (dist[e.Item1] == long.MinValue)
dist[e.Item2] = long.MinValue;
}
return dist;
}
}
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(int n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(int n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(int n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(int n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(int n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) {
return t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
}
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Contest {
const long MOD1 = 1000000007L; // 10^9+7
public static void Main() {
int n, m, p;
VT<int, int, int>[] abcl;
MyIO.ReadMulti(out n, out m, out p);
MyIO.ReadLines(m, out abcl);
VT<int, int, int>[] edges = new VT<int, int, int>[m];
for (int i = 0; i < m; i++)
edges[i] = new VT<int, int, int>(abcl[i].Item1 - 1, abcl[i].Item2 - 1,
-1 * (abcl[i].Item3 - p));
long[] r = BellmanFord(edges, n, 0);
if (r[n - 1] == long.MinValue) {
MyIO.WriteMulti(-1);
} else if (0 < r[n - 1]) {
MyIO.WriteMulti(0);
} else {
MyIO.WriteMulti(-r[n - 1]);
}
}
public static long[] BellmanFord(VT<int, int, int>[] inEdges, int V,
int start) {
long[] dist = Enumerable.Repeat(long.MaxValue, V).ToArray();
dist[start] = 0;
for (int i = 0; i < V - 1; i++) {
foreach (var e in inEdges) {
if (dist[e.Item1] == long.MaxValue)
continue;
dist[e.Item2] = Math.Min(dist[e.Item2], dist[e.Item1] + e.Item3);
}
}
for (int i = 0; i < V; i++) {
foreach (var e in inEdges) {
if (dist[e.Item1] == long.MaxValue)
continue;
// if(dist[e.Item1] + e.Item3 < dist[e.Item2]) return
//new long[0];
if (dist[e.Item1] + e.Item3 < dist[e.Item2])
dist[e.Item2] = long.MinValue;
if (dist[e.Item1] == long.MinValue)
dist[e.Item2] = long.MinValue;
}
}
return dist;
}
}
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(int n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(int n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(int n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(int n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(int n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) {
return t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
}
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 210, 8, 196, 0, 46]]
| 8
| 2,223
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
// using System.Threading.Tasks;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
readonly Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
readonly int dom = 998244353;
bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (b.CompareTo(a) < 0) {
a = b;
return true;
}
return false;
}
void solve() {
int N = cin.nextint;
int M = cin.nextint;
int P = cin.nextint;
var BF = new BellmanFord();
var G = BF.Input(P, M, true);
var dist = new long[N];
var ok = BF.Run(G, 0, N, out dist);
if (ok) {
WriteLine("-1");
} else {
WriteLine(Max(0, -dist[N - 1]));
}
}
}
class BellmanFord {
public readonly long Inf;
public BellmanFord(long Inf = long.MaxValue / 2) { this.Inf = Inf; }
public class Edge {
public int from, to;
public long cost;
public Edge(int from, int to, long cost) {
this.from = from;
this.to = to;
this.cost = cost;
}
}
/// <summary>
/// BellmanFordな入力を行う
/// </summary>
/// <param name="m">辺数</param>
/// <param name="dir">有向/無向 デフォルト: 無向</param>
/// <param name="indexed">indexedの補正 デフォルト: 1</param>
/// <returns></returns>
public Edge[] Input(int P, int m, bool dir = false, int indexed = 1,
bool cost = true) {
var cin = new Scanner();
var ret = new Edge[dir ? m : m + m];
for (int i = 0; i < m; i++) {
int a = cin.nextint - indexed;
int b = cin.nextint - indexed;
var c = cost ? cin.nextlong : 1;
c = P - c;
ret[i] = new Edge(a, b, c);
if (!dir)
ret[i + m] = new Edge(b, a, c);
}
return ret;
}
public bool Run(Edge[] edges, int s, int n, out long[] dist) {
dist = new long[n];
for (int i = 0; i < n; i++)
dist[i] = Inf;
dist[s] = 0;
for (int i = 0; i < n; i++) {
foreach (var e in edges) {
if (dist[e.from] == Inf)
continue;
var d = dist[e.from] + e.cost;
if (d < dist[e.to]) {
dist[e.to] = d;
// n回目にも更新があるなら負の閉路が存在する
if (i == n - 1 && e.to == n - 1)
return true;
}
}
}
return false;
}
}
static class Ex {
public static void join<T>(this IEnumerable<T> values, string sep = " ") =>
WriteLine(string.Join(sep, values));
public static string
concat<T>(this IEnumerable<T> values) => string.Concat(values);
public static string reverse(this string s) {
var t = s.ToCharArray();
Array.Reverse(t);
return t.concat();
}
public static int lower_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int upper_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
}
class Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T f;
public U s;
public Pair(T f, U s) {
this.f = f;
this.s = s;
}
public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0
? f.CompareTo(a.f)
: s.CompareTo(a.s);
public override string ToString() => $"{f} {s}";
}
class Scanner {
string[] s;
int i;
readonly char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan => ReadLine().Split();
public int[] scanint => Array.ConvertAll(scan, int.Parse);
public long[] scanlong => Array.ConvertAll(scan, long.Parse);
public double[] scandouble => Array.ConvertAll(scan, double.Parse);
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint => int.Parse(next);
public long nextlong => long.Parse(next);
public double nextdouble => double.Parse(next);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
// using System.Threading.Tasks;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
readonly Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
readonly int dom = 998244353;
bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (b.CompareTo(a) < 0) {
a = b;
return true;
}
return false;
}
void solve() {
int N = cin.nextint;
int M = cin.nextint;
int P = cin.nextint;
var BF = new BellmanFord();
var G = BF.Input(P, M, true);
var dist = new long[N];
var ok = BF.Run(G, 0, N, out dist);
if (ok) {
WriteLine("-1");
} else {
WriteLine(Max(0, -dist[N - 1]));
}
}
}
class BellmanFord {
public readonly long Inf;
public BellmanFord(long Inf = long.MaxValue / 2) { this.Inf = Inf; }
public class Edge {
public int from, to;
public long cost;
public Edge(int from, int to, long cost) {
this.from = from;
this.to = to;
this.cost = cost;
}
}
/// <summary>
/// BellmanFordな入力を行う
/// </summary>
/// <param name="m">辺数</param>
/// <param name="dir">有向/無向 デフォルト: 無向</param>
/// <param name="indexed">indexedの補正 デフォルト: 1</param>
/// <returns></returns>
public Edge[] Input(int P, int m, bool dir = false, int indexed = 1,
bool cost = true) {
var cin = new Scanner();
var ret = new Edge[dir ? m : m + m];
for (int i = 0; i < m; i++) {
int a = cin.nextint - indexed;
int b = cin.nextint - indexed;
var c = cost ? cin.nextlong : 1;
c = P - c;
ret[i] = new Edge(a, b, c);
if (!dir)
ret[i + m] = new Edge(b, a, c);
}
return ret;
}
public bool Run(Edge[] edges, int s, int n, out long[] dist) {
dist = new long[n];
for (int i = 0; i < n; i++)
dist[i] = Inf;
dist[s] = 0;
for (int i = 0; i <= 4 * n; i++) {
foreach (var e in edges) {
if (dist[e.from] == Inf)
continue;
var d = dist[e.from] + e.cost;
if (d < dist[e.to]) {
dist[e.to] = d;
// n回目にも更新があるなら負の閉路が存在する
if (n - 1 <= i && e.to == n - 1)
return true;
}
}
}
return false;
}
}
static class Ex {
public static void join<T>(this IEnumerable<T> values, string sep = " ") =>
WriteLine(string.Join(sep, values));
public static string
concat<T>(this IEnumerable<T> values) => string.Concat(values);
public static string reverse(this string s) {
var t = s.ToCharArray();
Array.Reverse(t);
return t.concat();
}
public static int lower_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int upper_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
}
class Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T f;
public U s;
public Pair(T f, U s) {
this.f = f;
this.s = s;
}
public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0
? f.CompareTo(a.f)
: s.CompareTo(a.s);
public override string ToString() => $"{f} {s}";
}
class Scanner {
string[] s;
int i;
readonly char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan => ReadLine().Split();
public int[] scanint => Array.ConvertAll(scan, int.Parse);
public long[] scanlong => Array.ConvertAll(scan, long.Parse);
public double[] scandouble => Array.ConvertAll(scan, double.Parse);
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint => int.Parse(next);
public long nextlong => long.Parse(next);
public double nextdouble => double.Parse(next);
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 22]]
| 8
| 1,316
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC136A {
class Program {
static void Main(string[] args) {
string[] ABC = Console.ReadLine().Split(' ');
int A = int.Parse(ABC[0]);
int B = int.Parse(ABC[1]);
int C = int.Parse(ABC[2]);
Console.WriteLine(C - (A - B));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC136A {
class Program {
static void Main(string[] args) {
string[] ABC = Console.ReadLine().Split(' ');
int A = int.Parse(ABC[0]);
int B = int.Parse(ABC[1]);
int C = int.Parse(ABC[2]);
Console.WriteLine(Math.Max(0, C - (A - B)));
}
}
}
|
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 116
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0028 {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
int A = int.Parse(str.Split(' ')[0]);
int B = int.Parse(str.Split(' ')[1]);
int C = int.Parse(str.Split(' ')[2]);
int tmp = A - B;
if (tmp == 0) {
Console.WriteLine(0);
return;
}
tmp = C - tmp;
if (tmp < 0) {
tmp = 0;
}
Console.WriteLine(tmp);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0028 {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
int A = int.Parse(str.Split(' ')[0]);
int B = int.Parse(str.Split(' ')[1]);
int C = int.Parse(str.Split(' ')[2]);
int tmp = A - B;
tmp = C - tmp;
if (tmp < 0) {
tmp = 0;
}
Console.WriteLine(tmp);
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22]]
| 8
| 164
| 17
|
using System;
using System.IO;
using System.Linq;
using System.Text;
namespace Contest {
class Program {
private Scanner sc;
public void Solve() {
sc = new Scanner();
int A = sc.NextInt();
int B = sc.NextInt();
int C = sc.NextInt();
C -= (A - B);
Console.WriteLine(C);
}
static void Main() => new Program().Solve();
}
}
class Scanner {
public Scanner() {
_stream = new StreamReader(Console.OpenStandardInput());
_pos = 0;
_line = new string[0];
_separator = ' ';
}
private readonly char _separator;
private readonly StreamReader _stream;
private int _pos;
private string[] _line;
#region get a element
public string Next() {
if (_pos >= _line.Length) {
_line = _stream.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 convert array
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 get array
public string[] Array() {
if (_pos >= _line.Length)
_line = _stream.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.IO;
using System.Linq;
using System.Text;
namespace Contest {
class Program {
private Scanner sc;
public void Solve() {
sc = new Scanner();
int A = sc.NextInt();
int B = sc.NextInt();
int C = sc.NextInt();
Console.WriteLine(Math.Max(0, C - (A - B)));
}
static void Main() => new Program().Solve();
}
}
class Scanner {
public Scanner() {
_stream = new StreamReader(Console.OpenStandardInput());
_pos = 0;
_line = new string[0];
_separator = ' ';
}
private readonly char _separator;
private readonly StreamReader _stream;
private int _pos;
private string[] _line;
#region get a element
public string Next() {
if (_pos >= _line.Length) {
_line = _stream.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 convert array
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 get array
public string[] Array() {
if (_pos >= _line.Length)
_line = _stream.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
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 538
| 19
|
using System;
namespace newEx {
class Program {
static void Main(string[] args) {
string[] l = Console.ReadLine().Split(' ');
int p = int.Parse(l[0]);
int q = int.Parse(l[1]);
int r = int.Parse(l[2]);
// string l = Console.ReadLine();
// int r = int.Parse(l);
Console.WriteLine(Volume(p, q, r));
}
static int Volume(int A, int B, int C) //修正200630
{
//容器2のあまり
if (A > B) //修正200630
{
return (C - (A - B));
} else
// if (A < B) //修正200630
{
return (C - (A + B));
} //修正200630
}
}
}
|
using System;
namespace newEx {
class Program {
static void Main(string[] args) {
string[] l = Console.ReadLine().Split(' ');
int p = int.Parse(l[0]);
int q = int.Parse(l[1]);
int r = int.Parse(l[2]);
// string l = Console.ReadLine();
// int r = int.Parse(l);
Console.WriteLine(Volume(p, q, r));
}
static int Volume(int A, int B, int C) //修正200630
{
//容器2のあまり
if (C > A - B) //修正200630
{
return (C - (A - B));
} else
// if (A < B) //修正200630
{
return 0;
} //修正200630
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 0, 57, 75, 196, 0, 37, 0, 23, 0, 24], ["-", 75, 196, 0, 37, 0, 23, 0, 16, 31, 22], ["-", 75, 196, 0, 37, 0, 23, 0, 16, 17, 33], ["-", 0, 37, 0, 23, 0, 16, 12, 23, 0, 24], ["-", 0, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 23, 0, 16, 12, 23, 0, 16, 17, 72], ["-", 0, 23, 0, 16, 12, 23, 0, 16, 12, 22], ["-", 0, 37, 0, 23, 0, 16, 12, 23, 0, 25], ["-", 0, 57, 75, 196, 0, 37, 0, 23, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 37, 0, 203]]
| 8
| 148
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoderA {
static void Main() {
int a;
int b;
int c;
{
var line = Console.ReadLine();
var words = line.Split(' ');
a = int.Parse(words[0]);
b = int.Parse(words[1]);
c = int.Parse(words[2]);
}
Console.WriteLine(c - (a - b));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoderA {
static void Main() {
int a;
int b;
int c;
{
var line = Console.ReadLine();
var words = line.Split(' ');
a = int.Parse(words[0]);
b = int.Parse(words[1]);
c = int.Parse(words[2]);
}
Console.WriteLine(Math.Max(0, c - (a - b)));
}
}
|
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 108
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var str = IO.GetIntList();
var ans = str[2] - str[0] + str[1];
Console.WriteLine(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var str = IO.GetIntList();
var ans = Math.Max(str[2] - (str[0] - str[1]), 0);
Console.WriteLine(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 326
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC136A {
class Program {
static void Main(string[] args) {
int a, b, c, s;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = int.Parse(word[2]);
s = c - (a - b);
Console.WriteLine(s);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC136A {
class Program {
static void Main(string[] args) {
int a, b, c, s;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = int.Parse(word[2]);
s = c - (a - b);
if (a - b < c)
Console.WriteLine(s);
else
Console.WriteLine("0");
Console.ReadKey();
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 130
| 18
|
using System;
using System.Linq;
namespace CSharp {
class Program {
public static void Main() {
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
Console.WriteLine(input[2] - (input[0] - input[1]));
}
}
}
|
using System;
using System.Linq;
namespace CSharp {
class Program {
public static void Main() {
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
Console.WriteLine(Math.Max(0, input[2] - (input[0] - input[1])));
}
}
}
|
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 73
| 7
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var a = cin.ReadInt;
var b = cin.ReadInt;
var c = cin.ReadInt;
var ans = c - (a - b);
System.Console.WriteLine(ans);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var a = cin.ReadInt;
var b = cin.ReadInt;
var c = cin.ReadInt;
var ans = 0;
if ((a - b) <= c) {
ans = c - (a - b);
}
System.Console.WriteLine(ans);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 465
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeginnerContest136 {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int A = int.Parse(str[0]);
int B = int.Parse(str[1]);
int C = int.Parse(str[2]);
int result = Math.Min(A, B + C);
Console.Write(result);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeginnerContest136 {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int A = int.Parse(str[0]);
int B = int.Parse(str[1]);
int C = int.Parse(str[2]);
int result = Math.Max(0, C - (A - B));
Console.Write(result);
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 124
| 12
|
using System;
namespace AC3 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
int D = (B + C) - A;
Console.WriteLine(D);
}
}
}
|
using System;
namespace AC3 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
int D = (B + C) - A;
if (D > 0) {
Console.WriteLine(D);
} else {
Console.Write(0);
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 97
| 18
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int ans = c - (a - b);
Console.WriteLine(ans);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int ans = c - (a - b);
Console.WriteLine(Math.Max(ans, 0));
}
}
|
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 93
| 7
|
using System;
namespace Transfer {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int result = b - c;
if (result < 0) {
result = 0;
}
Console.WriteLine(result);
}
}
}
|
using System;
namespace Transfer {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int result = c - (a - b);
if (result < 0) {
result = 0;
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
| 8
| 105
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var a = CinTAr();
Cout((a[1] + a[2]) - a[0]);
Cin();
}
static readonly int MOD1E9 = 10000007;
static bool isInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static int[] yakusuu(int n) {
if (n == 1) {
return new int[] { 1 };
}
HashSet<int> res = new HashSet<int>();
for (int i = 1; i < Math.Ceiling(n / 2.0); i++) {
if (n % i == 0) {
res.Add(i);
res.Add(n / i);
}
}
return res.ToArray();
}
/// <summary>
/// Debug時のみの使用を推奨
/// </summary>
/// <typeparam name="Type"></typeparam>
/// <param name="types"></param>
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = "";
foreach (var i in types) {
text += " " + i;
}
WriteLine(text.Substring(1));
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var a = CinTAr();
var i = (a[1] + a[2]) - a[0];
if (i <= 0) {
i = 0;
}
Cout(i);
Cin();
}
static readonly int MOD1E9 = 10000007;
static bool isInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static int[] yakusuu(int n) {
if (n == 1) {
return new int[] { 1 };
}
HashSet<int> res = new HashSet<int>();
for (int i = 1; i < Math.Ceiling(n / 2.0); i++) {
if (n % i == 0) {
res.Add(i);
res.Add(n / i);
}
}
return res.ToArray();
}
/// <summary>
/// Debug時のみの使用を推奨
/// </summary>
/// <typeparam name="Type"></typeparam>
/// <param name="types"></param>
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = "";
foreach (var i in types) {
text += " " + i;
}
WriteLine(text.Substring(1));
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 635
| 21
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int A = int.Parse(input[1]);
int B = int.Parse(input[2]);
if (N * A > B) {
Console.WriteLine(B);
} else if (N * A < B) {
Console.WriteLine(N * A);
}
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int A = int.Parse(input[1]);
int B = int.Parse(input[2]);
if (N * A > B) {
Console.WriteLine(B);
} else {
Console.WriteLine(N * A);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 48], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25]]
| 8
| 119
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace atcoder {
public class Program {
public static void Main(string[] args) {
var buffer = Console.ReadLine().Split();
var N = int.Parse(buffer[0]);
var D = int.Parse(buffer[1]);
int[,] list = new int[N, D];
for (int i = 0; i < N; i++) {
buffer = Console.ReadLine().Split();
for (int j = 0; j < D; j++)
list[i, j] = int.Parse(buffer[j]);
}
var ans = 0;
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
double sum = 0.0;
for (int k = 0; k < D; k++)
sum += Math.Pow(list[i, k] - list[j, k], 2);
for (int k = 0; k < sum; k++)
if (k * k == sum)
ans++;
}
}
Console.WriteLine(ans);
// Console.ReadKey();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace atcoder {
public class Program {
public static void Main(string[] args) {
var buffer = Console.ReadLine().Split();
var N = int.Parse(buffer[0]);
var D = int.Parse(buffer[1]);
int[,] list = new int[N, D];
for (int i = 0; i < N; i++) {
buffer = Console.ReadLine().Split();
for (int j = 0; j < D; j++)
list[i, j] = int.Parse(buffer[j]);
}
var ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int sum = 0;
for (int k = 0; k < D; k++) {
var tmp = Math.Abs(list[i, k] - list[j, k]);
sum += tmp * tmp;
}
for (int k = 0; k <= sum; k++)
if (k * k == sum)
ans++;
}
}
Console.WriteLine(ans);
// Console.ReadKey();
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 1, 0, 11, 31, 22], ["-", 0, 7, 8, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 8, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 269
| 25
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample {
class Sample {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int N = int.Parse(str[0]);
int D = int.Parse(str[1]);
int[][] zahyo = new int [N][];
for (int i = 0; i < N; i++) {
string[] str2 = Console.ReadLine().Split(' ');
zahyo[i] = str2.Select(int.Parse).ToArray();
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
double DisSq = 0;
double dis = 0;
for (int k = 0; k < D; k++) {
DisSq += Math.Pow(zahyo[i][k] - zahyo[j][k], 2);
dis = Math.Sqrt(DisSq);
}
// Console.WriteLine(dis);
if (Math.Pow(dis, 2) == DisSq) {
ans++;
}
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample {
class Sample {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int N = int.Parse(str[0]);
int D = int.Parse(str[1]);
int[][] zahyo = new int [N][];
for (int i = 0; i < N; i++) {
string[] str2 = Console.ReadLine().Split(' ');
zahyo[i] = str2.Select(int.Parse).ToArray();
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int DisSq = 0;
int dis = 0;
for (int k = 0; k < D; k++) {
DisSq += (int)Math.Pow(zahyo[i][k] - zahyo[j][k], 2);
dis = (int)Math.Sqrt(DisSq);
}
// Console.WriteLine(dis);
if (Math.Pow(dis, 2) == DisSq) {
ans++;
}
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25]]
| 8
| 270
| 10
|
// B - Good Distance
// 20190912
using System;
using System.Linq;
namespace B {
class Program {
static void Main(string[] args) {
int[] nd = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = nd[0];
int D = nd[1];
var X = new int [N][];
for (int i = 0; i < N; i++) {
X[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
}
int count = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; i < N; j++) {
double dist = 0;
for (int k = 0; k < X[i].Length; k++) {
dist += Math.Pow(X[i][k] - X[j][k], 2);
}
if (dist == (int)dist) {
count++;
}
}
}
Console.WriteLine(count);
}
}
}
|
// B - Good Distance
// 20190912
using System;
using System.Linq;
namespace B {
class Program {
static void Main(string[] args) {
int[] nd = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = nd[0];
int D = nd[1];
var X = new int [N][];
for (int i = 0; i < N; i++) {
X[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
}
int count = 0;
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
double dist = 0;
for (int k = 0; k < D; k++) {
dist += Math.Pow(X[i][k] - X[j][k], 2);
}
dist = Math.Sqrt(dist);
int distD = (int)dist;
if (dist == (int)dist) {
count++;
}
}
}
Console.WriteLine(count);
}
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 15, 16, 12, 214, 205, 204, 205, 22], ["-", 15, 16, 12, 214, 205, 204, 206, 207, 0, 70], ["-", 12, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 12, 214, 205, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 51, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35]]
| 8
| 235
| 28
|
using System;
using System.Text;
using System.Linq;
class Program {
static void Main(string[] args) {
System.Diagnostics.Debug.WriteLine("-----TextFile1");
System.Diagnostics.Debug.WriteLine(process("../TextFile1.txt"));
System.Diagnostics.Debug.WriteLine("-----TextFile2");
System.Diagnostics.Debug.WriteLine(process("../TextFile2.txt"));
System.Diagnostics.Debug.WriteLine("-----TextFile3");
System.Diagnostics.Debug.WriteLine(process("../TextFile3.txt"));
// String ret = process(new
// System.IO.StreamReader(Console.OpenStandardInput()));
// Console.WriteLine(ret);
}
static string processText(string input) {
return process(new System.IO.StringReader(input));
}
static string process(string filePath) {
using (var input = new System.IO.StreamReader(filePath)) {
return process(input);
}
}
static string process(System.IO.TextReader input) {
var s = input.ReadLine();
var spl = s.Split(' ');
int n = int.Parse(spl[0]);
int d = int.Parse(spl[1]);
int[][] ary = new int [n][];
for (int i = 0; i < n; i++) {
ary[i] = ToIntArray(input.ReadLine(), d);
}
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (i == j)
continue;
if (calc(ary[i], ary[j], d))
count++;
}
}
return count.ToString();
}
static bool calc(int[] xi, int[] xj, int size) {
int v = 0;
for (int i = 0; i < size; i++) {
int k = xi[i] - xj[i];
v += k * k;
}
for (int i = 0;; i++) {
int ii = i * i;
if (ii == v)
return true;
if (ii > v)
return false;
}
}
static int[] ToIntArray(string strs, int n) {
int[] ret = new int[n];
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
using System;
using System.Text;
using System.Linq;
class Program {
static void Main(string[] args) {
#if DEBUG
System.Diagnostics.Debug.WriteLine("-----TextFile1");
System.Diagnostics.Debug.WriteLine(process("../TextFile1.txt"));
System.Diagnostics.Debug.WriteLine("-----TextFile2");
System.Diagnostics.Debug.WriteLine(process("../TextFile2.txt"));
System.Diagnostics.Debug.WriteLine("-----TextFile3");
System.Diagnostics.Debug.WriteLine(process("../TextFile3.txt"));
#endif
String ret =
process(new System.IO.StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
}
static string processText(string input) {
return process(new System.IO.StringReader(input));
}
static string process(string filePath) {
using (var input = new System.IO.StreamReader(filePath)) {
return process(input);
}
}
static string process(System.IO.TextReader input) {
var s = input.ReadLine();
var spl = s.Split(' ');
int n = int.Parse(spl[0]);
int d = int.Parse(spl[1]);
int[][] ary = new int [n][];
for (int i = 0; i < n; i++) {
ary[i] = ToIntArray(input.ReadLine(), d);
}
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (i == j)
continue;
if (calc(ary[i], ary[j], d))
count++;
}
}
return count.ToString();
}
static bool calc(int[] xi, int[] xj, int size) {
int v = 0;
for (int i = 0; i < size; i++) {
int k = xi[i] - xj[i];
v += k * k;
}
for (int i = 0;; i++) {
int ii = i * i;
if (ii == v)
return true;
if (ii > v)
return false;
}
}
static int[] ToIntArray(string strs, int n) {
int[] ret = new int[n];
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
[["+", 0, 208, 0, 235, 8, 201, 0, 195, 8, 196], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 301], ["+", 8, 201, 0, 195, 8, 196, 0, 301, 0, 22], ["+", 0, 195, 8, 196, 0, 301, 0, 22, 0, 1], ["+", 8, 196, 0, 301, 0, 22, 0, 1, 0, 213], ["+", 0, 301, 0, 22, 0, 1, 0, 213, 63, 214], ["+", 0, 22, 0, 1, 0, 213, 63, 214, 3, 4], ["+", 0, 1, 0, 213, 63, 214, 3, 4, 0, 1], ["+", 0, 213, 63, 214, 3, 4, 0, 1, 0, 213], ["+", 63, 214, 3, 4, 0, 1, 0, 213, 63, 214], ["+", 3, 4, 0, 1, 0, 213, 63, 214, 3, 4], ["+", 0, 1, 0, 213, 63, 214, 3, 4, 0, 303], ["+", 0, 213, 63, 214, 3, 4, 0, 303, 0, 197], ["+", 63, 214, 3, 4, 0, 303, 0, 197, 0, 198], ["+", 3, 4, 0, 303, 0, 197, 0, 198, 39, 22], ["+", 0, 303, 0, 197, 0, 198, 39, 22, 0, 200], ["+", 0, 197, 0, 198, 39, 22, 0, 200, 0, 1], ["+", 0, 198, 39, 22, 0, 200, 0, 1, 0, 213], ["+", 39, 22, 0, 200, 0, 1, 0, 213, 63, 214], ["+", 0, 200, 0, 1, 0, 213, 63, 214, 3, 4], ["+", 8, 201, 0, 195, 8, 196, 0, 301, 0, 121], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 303], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 230, 0, 228], ["+", 0, 28, 0, 230, 39, 232, 234, 232, 234, 22], ["+", 0, 28, 0, 230, 39, 232, 234, 232, 0, 131], ["+", 0, 28, 0, 230, 39, 232, 234, 232, 141, 22], ["+", 3, 4, 0, 28, 0, 230, 39, 232, 0, 131], ["+", 3, 4, 0, 28, 0, 230, 39, 232, 141, 22], ["+", 3, 4, 0, 28, 0, 230, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 230, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 518
| 32
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
List<List<int>> pointList = new List<List<int>>();
List<int> point = new List<int>();
string[] initial = Console.ReadLine().Split();
string[] line;
double root = 0;
int answer = 0;
int N = int.Parse(initial[0]);
int D = int.Parse(initial[1]);
for (int i = 0; i < N; i++) {
line = Console.ReadLine().Split();
for (int j = 0; j < D; j++) {
point.Add(int.Parse(line[j]));
}
pointList.Add(point);
}
int rootNakami = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == j || j > i) {
continue;
}
for (int k = 0; k < D; k++) {
rootNakami += (pointList[i][k] * pointList[j][k]) ^ 2;
}
root = Math.Sqrt(rootNakami);
if (root == (int)root) {
answer++;
}
}
}
Console.Write(answer);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
List<List<int>> pointList = new List<List<int>>();
List<int> point = new List<int>();
string[] initial = Console.ReadLine().Split();
string[] line;
double root = 0;
int answer = 0;
int N = int.Parse(initial[0]);
int D = int.Parse(initial[1]);
for (int i = 0; i < N; i++) {
line = Console.ReadLine().Split();
for (int j = 0; j < D; j++) {
point.Add(int.Parse(line[j]));
}
pointList.Add(point);
point = new List<int>();
}
int rootNakami = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == j || j > i) {
continue;
}
for (int k = 0; k < D; k++) {
rootNakami += (pointList[i][k] - pointList[j][k]) *
(pointList[i][k] - pointList[j][k]);
}
root = Math.Sqrt(rootNakami);
if (root == (int)root) {
answer++;
}
rootNakami = 0;
root = 0;
}
}
Console.Write(answer);
}
}
|
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 230, 0, 228], ["+", 0, 1, 0, 11, 12, 230, 39, 236, 141, 22], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 23, 0, 16, 12, 204, 205, 204, 205, 22], ["+", 0, 16, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 16, 12, 204, 205, 204, 205, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 140], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 300
| 38
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int D = int.Parse(input[1]);
List<List<int>> X = new List<List<int>>();
int count = 0;
for (int i = 0; i < N; i++) {
string[] strPoint = Console.ReadLine().Split(' ');
List<int> y = new List<int>();
foreach (string item in strPoint) {
y.Add(int.Parse(item));
}
for (int j = 0; j < X.Count; j++) {
double sum = 0;
for (int k = 0; k < D; k++) {
sum += Math.Pow((double)(X[j][k] - y[k]), 2);
}
double sqrt = Math.Sqrt(sum);
Console.WriteLine($"{sqrt}, {(int)sqrt == sqrt}");
if ((int)sqrt == sqrt) {
count++;
}
}
X.Add(y);
}
Console.WriteLine(count);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int D = int.Parse(input[1]);
List<List<int>> X = new List<List<int>>();
int count = 0;
for (int i = 0; i < N; i++) {
string[] strPoint = Console.ReadLine().Split(' ');
List<int> y = new List<int>();
foreach (string item in strPoint) {
y.Add(int.Parse(item));
}
for (int j = 0; j < X.Count; j++) {
double sum = 0;
for (int k = 0; k < D; k++) {
double diff = X[j][k] - y[k];
sum += diff * diff;
}
double sqrt = Math.Sqrt(sum);
if ((int)sqrt == sqrt) {
count++;
}
}
X.Add(y);
}
Console.WriteLine(count);
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 0, 283, 0, 284, 0, 16, 31, 74, 0, 24], ["-", 0, 283, 0, 284, 0, 16, 31, 74, 39, 199], ["-", 0, 283, 0, 284, 0, 16, 31, 74, 0, 25], ["-", 0, 283, 0, 284, 0, 16, 31, 74, 51, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 17, 60], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62]]
| 8
| 287
| 20
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int D = int.Parse(input[1]);
List<List<int>> X = new List<List<int>>();
int count = 0;
for (int i = 0; i < N; i++) {
string[] strPoint = Console.ReadLine().Split(' ');
List<int> y = new List<int>();
foreach (string item in strPoint) {
y.Add(int.Parse(item));
}
for (int j = 0; j < X.Count; j++) {
double sum = 0;
for (int k = 0; k < D; k++) {
sum += Math.Pow((double)(X[j][k] - y[k]), 2);
}
double sqrt = Math.Sqrt(sum);
Console.WriteLine($"{sqrt}, {(int)sqrt == sqrt}");
if ((int)sqrt == sqrt) {
count++;
}
}
X.Add(y);
}
Console.WriteLine(count);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int D = int.Parse(input[1]);
List<List<int>> X = new List<List<int>>();
int count = 0;
for (int i = 0; i < N; i++) {
string[] strPoint = Console.ReadLine().Split(' ');
List<int> y = new List<int>();
foreach (string item in strPoint) {
y.Add(int.Parse(item));
}
for (int j = 0; j < X.Count; j++) {
double sum = 0;
for (int k = 0; k < D; k++) {
sum += Math.Pow((double)(X[j][k] - y[k]), 2);
}
double sqrt = Math.Sqrt(sum);
if ((int)sqrt == sqrt) {
count++;
}
}
X.Add(y);
}
Console.WriteLine(count);
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 0, 283, 0, 284, 0, 16, 31, 74, 0, 24], ["-", 0, 283, 0, 284, 0, 16, 31, 74, 39, 199], ["-", 0, 283, 0, 284, 0, 16, 31, 74, 0, 25], ["-", 0, 283, 0, 284, 0, 16, 31, 74, 51, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 17, 60], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 287
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var inputs =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var n = inputs[0];
var d = inputs[1];
var point = new int[n, d];
for (var i = 0; i < n; i++) // I点
{
var inputs2 =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
for (var j = 0; j < d; j++) // j次元
{
point[i, j] = inputs2[j];
}
}
var ans = 0;
double dis = 0;
for (var i = 0; i < n - 1; i++) // I点
{
for (var j = i + 1; j < n; j++) // J点
{
for (var k = 0; k < d; k++) // k次元
{
dis += Math.Pow(point[i, k] - point[j, k], 2);
}
dis = Math.Sqrt(dis);
if (Math.Floor(dis) == Math.Ceiling(dis)) {
ans++;
}
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var inputs =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var n = inputs[0];
var d = inputs[1];
var point = new int[n, d];
for (var i = 0; i < n; i++) // I点
{
var inputs2 =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
for (var j = 0; j < d; j++) // j次元
{
point[i, j] = inputs2[j];
}
}
var ans = 0;
for (var i = 0; i < n; i++) // I点
{
for (var j = i + 1; j < n; j++) // J点
{
double dis = 0; //あほすぎる
for (var k = 0; k < d; k++) // k次元
{
dis += Math.Pow(point[i, k] - point[j, k], 2);
}
dis = Math.Sqrt(dis);
if (Math.Floor(dis) == Math.Ceiling(dis)) {
ans++;
}
}
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35]]
| 8
| 292
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_20190707_1 {
class Program {
static void Main(string[] args) {
string[] input1 = Console.ReadLine().Split(' ');
int dotsCount = int.Parse(input1[0]);
int dimension = int.Parse(input1[1]);
List<string[]> dots = new List<string[]>();
for (int i = 0; i < dotsCount; i++) {
dots.Add(Console.ReadLine().Split(' '));
}
int answer = 0;
for (int i = 0; i < dots.Count; i++) {
for (int j = 0; j < dots.Count; j++) {
string[] dotsX;
string[] dotsY;
if (i == j) {
continue;
} else {
dotsX = dots[i];
dotsY = dots[j];
}
double distance = 0;
for (int k = 0; k < dimension; k++) {
distance += Math.Pow(int.Parse(dotsX[k]) - int.Parse(dotsY[k]), 2);
}
distance = Math.Sqrt(distance);
if (distance - Math.Floor(distance) == 0) {
answer++;
}
}
}
Console.WriteLine(answer);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_20190707_1 {
class Program {
static void Main(string[] args) {
string[] input1 = Console.ReadLine().Split(' ');
int dotsCount = int.Parse(input1[0]);
int dimension = int.Parse(input1[1]);
List<string[]> dots = new List<string[]>();
for (int i = 0; i < dotsCount; i++) {
dots.Add(Console.ReadLine().Split(' '));
}
int answer = 0;
for (int i = 0; i < dots.Count; i++) {
for (int j = 0; j < dots.Count; j++) {
string[] dotsX;
string[] dotsY;
if (i == j) {
continue;
} else {
dotsX = dots[i];
dotsY = dots[j];
}
double distance = 0;
for (int k = 0; k < dimension; k++) {
distance += Math.Pow(int.Parse(dotsX[k]) - int.Parse(dotsY[k]), 2);
}
distance = Math.Sqrt(distance);
if (distance - Math.Floor(distance) == 0) {
answer++;
}
}
}
Console.WriteLine((answer / 2).ToString());
}
}
}
|
[["+", 0, 28, 0, 213, 63, 214, 205, 23, 0, 24], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 17, 85], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 213, 63, 214, 205, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 304
| 8
|
using System;
namespace ATCODER123 {
class Program {
static void Main(string[] args) {
string[] S = Console.ReadLine().Split(' ');
int N = int.Parse(S[0]);
int D = int.Parse(S[1]);
string[] Xn;
int Ans = 0;
var X = new int[N, D];
for (int i = 0; i < N; i++) {
Xn = Console.ReadLine().Split(' ');
for (int j = 0; j < D; j++) {
X[i, j] = int.Parse(Xn[j]);
}
}
int Checker = 0;
double Dchecker;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < D; k++) {
Checker += (X[i, k] - X[j, k]) * (X[i, k] - X[j, k]);
}
Dchecker = Math.Sqrt((double)Checker);
if (Dchecker == (int)Dchecker) {
Ans++;
}
}
Ans--;
Checker = 0;
}
Console.WriteLine(Ans);
}
}
}
|
using System;
namespace ATCODER123 {
class Program {
static void Main(string[] args) {
string[] S = Console.ReadLine().Split(' ');
int N = int.Parse(S[0]);
int D = int.Parse(S[1]);
string[] Xn;
int Ans = 0;
var X = new int[N, D];
for (int i = 0; i < N; i++) {
Xn = Console.ReadLine().Split(' ');
for (int j = 0; j < D; j++) {
X[i, j] = int.Parse(Xn[j]);
}
}
int Checker = 0;
double Dchecker;
for (int i = 0; i < N; i++) {
for (int j = i; j < N; j++) {
for (int k = 0; k < D; k++) {
Checker += (X[i, k] - X[j, k]) * (X[i, k] - X[j, k]);
}
Dchecker = Math.Sqrt((double)Checker);
// Console.WriteLine(Dchecker);
if (Dchecker == (int)Dchecker) {
Ans++;
}
Checker = 0;
}
Ans--;
}
Console.WriteLine(Ans);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 68], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 68]]
| 8
| 281
| 10
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace codeTester.contest190707 {
class ProblemB {
static List<long> nd = new List<long>();
static List<List<long>> values = new List<List<long>>();
static int answer = 0;
public static void Main(string[] args) {
Input();
Logic();
Output();
}
static void Input() {
nd = ReadSpaceSeparatedValues();
values = ReadSpaceSeparatedLists((int)nd[0]);
}
public static List<List<long>> ReadSpaceSeparatedLists(int n) {
List<List<long>> returnValue = new List<List<long>>();
for (int i = 0; i < n; i++) {
returnValue.Add(ReadSpaceSeparatedValues());
}
return returnValue;
}
public static List<long> ReadSpaceSeparatedValues() {
List<long> values = new List<long>();
string[] inputs = Console.ReadLine().Split(' ');
foreach (string input in inputs) {
values.Add(long.Parse(input));
}
return values;
}
static void Logic() {
int squareDistanceCount = 0;
int n = (int)nd[0];
int d = (int)nd[1];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
long squaredDistance =
values[i]
.Zip(values[j], (iValue, jValue) => iValue - jValue)
.Aggregate((long)0, (sum, next) => sum + (next * next));
DebugPrint(squaredDistance.ToString());
if (isSquareNumber(squaredDistance)) {
squareDistanceCount++;
}
}
}
answer = squareDistanceCount;
}
static bool isSquareNumber(long value) {
if (value == Math.Pow(Math.Sqrt(value), 2)) {
return true;
}
return false;
}
static void Output() { Console.WriteLine(answer.ToString()); }
static void DebugPrint(string msg) {
// 提出時に消す
// Console.WriteLine(msg);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace codeTester.contest190707 {
class ProblemB {
static List<long> nd = new List<long>();
static List<List<long>> values = new List<List<long>>();
static int answer = 0;
public static void Main(string[] args) {
Input();
Logic();
Output();
}
static void Input() {
nd = ReadSpaceSeparatedValues();
values = ReadSpaceSeparatedLists((int)nd[0]);
}
public static List<List<long>> ReadSpaceSeparatedLists(int n) {
List<List<long>> returnValue = new List<List<long>>();
for (int i = 0; i < n; i++) {
returnValue.Add(ReadSpaceSeparatedValues());
}
return returnValue;
}
public static List<long> ReadSpaceSeparatedValues() {
List<long> values = new List<long>();
string[] inputs = Console.ReadLine().Split(' ');
foreach (string input in inputs) {
values.Add(long.Parse(input));
}
return values;
}
static void Logic() {
int squareDistanceCount = 0;
int n = (int)nd[0];
int d = (int)nd[1];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
long squaredDistance =
values[i]
.Zip(values[j], (iValue, jValue) => iValue - jValue)
.Aggregate((long)0, (sum, next) => sum + (next * next));
DebugPrint(squaredDistance.ToString());
if (isSquareNumber(squaredDistance)) {
squareDistanceCount++;
}
}
}
answer = squareDistanceCount;
}
static bool isSquareNumber(long value) {
if (value == Math.Pow((int)Math.Sqrt(value), 2)) {
DebugPrint("O");
return true;
}
DebugPrint("X");
return false;
}
static void Output() { Console.WriteLine(answer.ToString()); }
static void DebugPrint(string msg) {
// 提出時に消す
// Console.WriteLine(msg);
}
}
}
|
[["+", 12, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 12, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 458
| 17
|
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 nd = Console.ReadLine().Split().Select(int.Parse).ToArray();
var points =
Enumerable.Repeat(0, nd[0])
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
var res = 0;
for (int i = 0; i < points.Length; i++) {
for (int j = i + 1; j < points.Length; j++) {
var len =
points[i].Zip(points[j], (x, y) => Abs(x - y) * Abs(x - y)).Sum();
if (Abs(len - Sqrt(len) * Sqrt(len)) <= 0.000001)
res++;
}
}
Console.WriteLine(res);
}
}
|
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 nd = Console.ReadLine().Split().Select(int.Parse).ToArray();
var points =
Enumerable.Repeat(0, nd[0])
.Select(_ =>
Console.ReadLine().Split().Select(long.Parse).ToArray())
.ToArray();
var res = 0;
for (int i = 0; i < points.Length; i++) {
for (int j = i + 1; j < points.Length; j++) {
var len =
points[i].Zip(points[j], (x, y) => Abs(x - y) * Abs(x - y)).Sum();
var sqrtLen = (long)Sqrt(len);
if (sqrtLen * sqrtLen == len)
res++;
}
}
Console.WriteLine(res);
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 213, 63, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["-", 0, 28, 0, 16, 12, 16, 12, 213, 63, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 16, 12, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 250]]
| 8
| 245
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static int L, R;
static void INPUT() {
L = NextInt();
R = NextInt();
}
static void OUT() {
var min = int.MaxValue;
R = Math.Min(R, L + 2020);
for (int i = L; i <= R; i++)
for (int j = i + 1; j <= R; j++)
min = Math.Min(min, (i * j) % 2019);
Console.WriteLine(min);
}
static void Main(string[] args) {
#if DEBUG
// TESTINPUT();
INPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() {}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static long L, R;
static void INPUT() {
L = NextLong();
R = NextLong();
}
static void OUT() {
var min = long.MaxValue;
R = Math.Min(R, L + 2020);
for (var i = L; i <= R; i++)
for (var j = i + 1; j <= R; j++)
min = Math.Min(min, (i % 2019 * j % 2019) % 2019);
Console.WriteLine(min);
}
static void Main(string[] args) {
#if DEBUG
// TESTINPUT();
INPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() {}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {}
|
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 7, 8, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 7, 10, 198, 39, 216, 0, 217], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 17, 109], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 109], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203]]
| 8
| 492
| 16
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var rr = ReadSplit();
var l = rr[0].Long();
var r = rr[1].Long();
var dic = new Dictionary<long, int>();
long ans = mod;
for (long i = l; i <= r; i++) {
for (long j = i + 1; j <= r; j++) {
var tmp = i * j % 2019;
if (tmp == 0) {
WriteRead(0);
return;
} else {
dic.Add(tmp, 1);
ans = Math.Min(ans, tmp);
}
}
}
WriteRead(ans);
}
class ModCombination {
public long _mod = 1000000007;
public int _max = 1000000;
long[] fac;
long[] finv;
long[] inv;
public ModCombination() : this(1000000007, 1000000) {}
public ModCombination(long mod, int max) {
_mod = mod;
_max = max;
fac = new long[max];
finv = new long[max];
inv = new long[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
public long Combination(int n, int m) {
if (n < m)
return 0;
if (n < 0 || m < 0)
return 0;
return fac[n] * (finv[m] * finv[n - m] % _mod) % _mod;
}
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var rr = ReadSplit();
var l = rr[0].Long();
var r = rr[1].Long();
var dic = new Dictionary<long, int>();
long ans = mod;
for (long i = l; i <= r; i++) {
for (long j = i + 1; j <= r; j++) {
var tmp = i * j % 2019;
if (tmp == 0) {
Write(0);
return;
} else {
ans = Math.Min(ans, tmp);
}
}
}
WriteRead(ans);
}
class ModCombination {
public long _mod = 1000000007;
public int _max = 1000000;
long[] fac;
long[] finv;
long[] inv;
public ModCombination() : this(1000000007, 1000000) {}
public ModCombination(long mod, int max) {
_mod = mod;
_max = max;
fac = new long[max];
finv = new long[max];
inv = new long[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
public long Combination(int n, int m) {
if (n < m)
return 0;
if (n < 0 || m < 0)
return 0;
return fac[n] * (finv[m] * finv[n - m] % _mod) % _mod;
}
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 1,513
| 11
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC133.C(); }
class ABC133 {
public static void A() {
var N = Read.Int();
var A = Read.Int();
var B = Read.Int();
Console.WriteLine(Math.Min(N * A, B));
}
public static void B() {
var N = Read.Int();
var D = Read.Int();
var X = Enumerable.Range(0, N).Select(i => Read.IntN()).ToArray();
Func<int[], int[], bool> isZ = (a, b) => {
var dist2 = a.Select((x, i) => (x - b[i]) * (x - b[i])).Sum();
for (int i = 0; i < 200; ++i) {
if (i * i == dist2) {
return true;
}
}
return false;
};
int count = 0;
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
count += isZ(X[i], X[j]) ? 1 : 0;
}
}
Console.WriteLine(count);
}
public static void C() {
var L = Read.Int() % 2019;
var R = Read.Int() % 2019;
if (L >= R) {
R += 2019;
}
int min = 1000000000;
for (int i = L; i < R; ++i) {
for (int j = i + 1; j <= R; ++j) {
min = Math.Min(min, (i * j) % 2019);
}
}
Console.WriteLine(min);
}
public static void D() {
var N = Read.Int();
var A = Read.LongN();
var X = new long[N];
X[N - 1] =
A.Sum() - Enumerable.Range(0, N / 2).Select(i => A[i * 2] * 2).Sum();
for (int i = N - 2; i >= 0; --i) {
X[i] = A[i] * 2 - X[i + 1];
}
Console.WriteLine(String.Join(" ", X));
}
public static void E() {
var N = Read.Int();
var K = Read.Int();
var Adj = Read.AdjacencyList(N, N - 1);
MOD ans = K;
HashSet<int> done = new HashSet<int>();
done.Add(1);
Queue<int> queue = new Queue<int>();
queue.Enqueue(1);
while (queue.Count > 0) {
var v = queue.Dequeue();
int child = 0;
foreach (var w in Adj[v]) {
if (!done.Contains(w)) {
child++;
done.Add(w);
queue.Enqueue(w);
}
}
for (int i = 0; i < child; ++i) {
ans *= (K - (v == 1 ? 1 : 2) - i);
}
}
Console.WriteLine(ans.ToString());
}
}
class Util {}
struct MOD {
public static long P = 1000000007;
public readonly long V;
public MOD(long a) { this.V = a; }
public static implicit operator MOD(long a) { return new MOD(a); }
public static MOD operator +(MOD a, MOD b) {
return new MOD((a.V + b.V) % P);
}
public static MOD operator -(MOD a, MOD b) {
return new MOD((a.V - b.V + P) % P);
}
public static MOD operator *(MOD a, MOD b) {
return new MOD((a.V * b.V) % P);
}
public static MOD operator /(MOD a, MOD b) {
return new MOD((a.V * b.Inverse().V) % P);
}
// public MOD Inverse() { return Util.Inverse(V, P); }
public MOD Inverse() {
long a = V, p = P;
long b = p, c = 1, d = 0, e = 0, f = 0;
while (b != 0) {
e = a / b;
f = b;
b = a - e * b;
a = f;
f = d;
d = c - e * d;
c = f;
}
c %= p;
return c + (c < 0 ? p : 0);
}
// public MOD Power(long n) { return Util.Power(V, n, P); }
public MOD Power(long n) {
long a = V, p = P;
long res = 1;
long mult = a;
for (int i = 0; i < 40; ++i) {
if ((n & ((long)1 << i)) > 0) {
res = (res * mult) % p;
}
mult = (mult * mult) % p;
}
return res;
}
public override string ToString() { return V.ToString(); }
}
static class Read {
static Queue<string> queue = new Queue<string>();
static void Enqueue() {
var ss = Console.ReadLine().Split(' ');
foreach (var s in ss) {
queue.Enqueue(s);
}
}
public static int Int() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt32(queue.Dequeue());
}
public static long Long() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt64(queue.Dequeue());
}
public static string Str() {
if (queue.Count == 0) {
Enqueue();
}
return queue.Dequeue();
}
public static int[] IntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
public static long[] LongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = Read.IntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<long, long>[] TupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<string, string>[] TupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = Read.StrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<double, double>[] TupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
public static long[,] LongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = Read.LongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
public static Dictionary<int, HashSet<int>>
AdjacencyList(int N, int M, bool isDirectional = false) {
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new HashSet<int>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1]);
if (!isDirectional) {
dict[ab[1]].Add(ab[0]);
}
}
return dict;
}
public static Dictionary<int, Dictionary<int, long>>
AdjacencyListWithWeight(int N, int M) {
Dictionary<int, Dictionary<int, long>> dict =
new Dictionary<int, Dictionary<int, long>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new Dictionary<int, long>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1], ab[2]);
dict[ab[1]].Add(ab[0], ab[2]);
}
return dict;
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC133.C(); }
class ABC133 {
public static void A() {
var N = Read.Int();
var A = Read.Int();
var B = Read.Int();
Console.WriteLine(Math.Min(N * A, B));
}
public static void B() {
var N = Read.Int();
var D = Read.Int();
var X = Enumerable.Range(0, N).Select(i => Read.IntN()).ToArray();
Func<int[], int[], bool> isZ = (a, b) => {
var dist2 = a.Select((x, i) => (x - b[i]) * (x - b[i])).Sum();
for (int i = 0; i < 200; ++i) {
if (i * i == dist2) {
return true;
}
}
return false;
};
int count = 0;
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
count += isZ(X[i], X[j]) ? 1 : 0;
}
}
Console.WriteLine(count);
}
public static void C() {
var L = Read.Int();
var R = Read.Int();
if (L + 2019 < R) {
Console.WriteLine(0);
return;
}
int min = 1000000000;
for (int i = L; i < R; ++i) {
for (int j = i + 1; j <= R; ++j) {
min = Math.Min(min, ((i % 2019) * (j % 2019)) % 2019);
}
}
Console.WriteLine(min);
}
public static void D() {
var N = Read.Int();
var A = Read.LongN();
var X = new long[N];
X[N - 1] =
A.Sum() - Enumerable.Range(0, N / 2).Select(i => A[i * 2] * 2).Sum();
for (int i = N - 2; i >= 0; --i) {
X[i] = A[i] * 2 - X[i + 1];
}
Console.WriteLine(String.Join(" ", X));
}
public static void E() {
var N = Read.Int();
var K = Read.Int();
var Adj = Read.AdjacencyList(N, N - 1);
MOD ans = K;
HashSet<int> done = new HashSet<int>();
done.Add(1);
Queue<int> queue = new Queue<int>();
queue.Enqueue(1);
while (queue.Count > 0) {
var v = queue.Dequeue();
int child = 0;
foreach (var w in Adj[v]) {
if (!done.Contains(w)) {
child++;
done.Add(w);
queue.Enqueue(w);
}
}
for (int i = 0; i < child; ++i) {
ans *= (K - (v == 1 ? 1 : 2) - i);
}
}
Console.WriteLine(ans.ToString());
}
}
class Util {}
struct MOD {
public static long P = 1000000007;
public readonly long V;
public MOD(long a) { this.V = a; }
public static implicit operator MOD(long a) { return new MOD(a); }
public static MOD operator +(MOD a, MOD b) {
return new MOD((a.V + b.V) % P);
}
public static MOD operator -(MOD a, MOD b) {
return new MOD((a.V - b.V + P) % P);
}
public static MOD operator *(MOD a, MOD b) {
return new MOD((a.V * b.V) % P);
}
public static MOD operator /(MOD a, MOD b) {
return new MOD((a.V * b.Inverse().V) % P);
}
// public MOD Inverse() { return Util.Inverse(V, P); }
public MOD Inverse() {
long a = V, p = P;
long b = p, c = 1, d = 0, e = 0, f = 0;
while (b != 0) {
e = a / b;
f = b;
b = a - e * b;
a = f;
f = d;
d = c - e * d;
c = f;
}
c %= p;
return c + (c < 0 ? p : 0);
}
// public MOD Power(long n) { return Util.Power(V, n, P); }
public MOD Power(long n) {
long a = V, p = P;
long res = 1;
long mult = a;
for (int i = 0; i < 40; ++i) {
if ((n & ((long)1 << i)) > 0) {
res = (res * mult) % p;
}
mult = (mult * mult) % p;
}
return res;
}
public override string ToString() { return V.ToString(); }
}
static class Read {
static Queue<string> queue = new Queue<string>();
static void Enqueue() {
var ss = Console.ReadLine().Split(' ');
foreach (var s in ss) {
queue.Enqueue(s);
}
}
public static int Int() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt32(queue.Dequeue());
}
public static long Long() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt64(queue.Dequeue());
}
public static string Str() {
if (queue.Count == 0) {
Enqueue();
}
return queue.Dequeue();
}
public static int[] IntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
public static long[] LongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = Read.IntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<long, long>[] TupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<string, string>[] TupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = Read.StrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<double, double>[] TupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
public static long[,] LongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = Read.LongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
public static Dictionary<int, HashSet<int>>
AdjacencyList(int N, int M, bool isDirectional = false) {
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new HashSet<int>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1]);
if (!isDirectional) {
dict[ab[1]].Add(ab[0]);
}
}
return dict;
}
public static Dictionary<int, Dictionary<int, long>>
AdjacencyListWithWeight(int N, int M) {
Dictionary<int, Dictionary<int, long>> dict =
new Dictionary<int, Dictionary<int, long>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new Dictionary<int, long>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1], ab[2]);
dict[ab[1]].Add(ab[0], ab[2]);
}
return dict;
}
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 17, 109], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
| 8
| 2,154
| 27
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
static class CRemainderMinimization2019 {
static void Main(string[] args) {
var lr = Console.ReadLine().Split(' ').Select(y => long.Parse(y)).ToList();
long l = lr[0];
long r = lr[1];
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);
if (min == 0) {
Console.WriteLine(min);
Console.ReadLine();
return;
}
}
}
Console.WriteLine(min);
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
static class CRemainderMinimization2019 {
static void Main(string[] args) {
var lr = Console.ReadLine().Split(' ').Select(y => long.Parse(y)).ToList();
long l = lr[0];
long r = lr[1];
if (r - l >= 2019) {
Console.WriteLine(0);
Console.ReadLine();
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);
if (min == 0) {
Console.WriteLine(min);
Console.ReadLine();
return;
}
}
}
Console.WriteLine(min);
Console.ReadLine();
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
| 8
| 187
| 27
|
using System;
using System.Linq;
namespace ABC133C {
class MainClass {
public static void Main(string[] args) {
long[] lr = Console.ReadLine().Split().Select(long.Parse).ToArray();
int res = 2020;
if (lr[1] - lr[0] >= 2018) {
Console.WriteLine(0);
return;
}
for (long i = lr[0]; i <= lr[1]; i++) {
for (long j = i + 1; j <= lr[1]; j++) {
int tmp = (int)(i * j) % 2019;
res = Math.Min(res, tmp);
if (res == 0) {
break;
}
}
if (res == 0) {
break;
}
}
Console.WriteLine(res);
}
}
}
|
using System;
using System.Linq;
namespace ABC133C {
class MainClass {
public static void Main(string[] args) {
long[] lr = Console.ReadLine().Split().Select(long.Parse).ToArray();
long res = 2020;
if (lr[1] - lr[0] >= 2018) {
Console.WriteLine(0);
return;
}
for (long i = lr[0]; i <= lr[1]; i++) {
for (long j = i + 1; j <= lr[1]; j++) {
long tmp = (i * j) % 2019;
res = Math.Min(res, tmp);
}
}
Console.WriteLine(res);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["-", 0, 212, 0, 16, 31, 74, 51, 23, 0, 24], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 179
| 27
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
class DandA {
static void Main(string[] args) {
int[] lr = ReadLineIntArray();
int l = lr[0] % 2019;
int r = lr[1] % 2019;
if (l == 0 || r <= l) {
Console.WriteLine(0);
} else {
int rtn = 2019;
for (int i = l; i < r; i++) {
for (int j = i + 1; j < r + 1; j++) {
if ((i * j) % 2019 < rtn) {
rtn = (i * j) % 2019;
}
}
}
Console.WriteLine(rtn);
}
}
static string Alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
static string[] strAry = new string[] { "L", "R", "U", "D" };
static int[] intArray = new int[10];
static List<int> intList = new List<int>();
static Dictionary<string, int> myTable = new Dictionary<string, int>();
static HashSet<int>[] rtnArrAb = null;
static HashSet<int>[] rtnArrCd = null;
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private long ReadLineLong() { return long.Parse(Console.ReadLine()); }
static private double ReadLineDouble() {
return double.Parse(Console.ReadLine());
}
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private double[] ReadLineDoubleArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => double.Parse(a))
.ToArray();
}
static private decimal[] ReadLineDecimalArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => decimal.Parse(a))
.ToArray();
}
static private List<int> ReadLineIntList() {
return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList();
}
static private List<long> ReadLineLongList() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToList();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
static private string IntToNString(int x, int n) {
var nstring = "";
var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f" };
int r = 1;
int q = x;
while (q > 0) {
r = q % n;
nstring += numbers[r];
q = q / n;
}
return string.Join("", nstring.Reverse());
}
}
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
class DandA {
static void Main(string[] args) {
int[] lr = ReadLineIntArray();
int l = lr[0] % 2019;
int r = lr[1] % 2019;
if (l == 0 || (lr[0] / 2019) < (lr[1] / 2019)) {
Console.WriteLine(0);
} else {
int rtn = 2019;
for (int i = l; i < r; i++) {
for (int j = i + 1; j < r + 1; j++) {
if ((i * j) % 2019 < rtn) {
rtn = (i * j) % 2019;
}
}
}
Console.WriteLine(rtn);
}
}
static string Alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
static string[] strAry = new string[] { "L", "R", "U", "D" };
static int[] intArray = new int[10];
static List<int> intList = new List<int>();
static Dictionary<string, int> myTable = new Dictionary<string, int>();
static HashSet<int>[] rtnArrAb = null;
static HashSet<int>[] rtnArrCd = null;
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private long ReadLineLong() { return long.Parse(Console.ReadLine()); }
static private double ReadLineDouble() {
return double.Parse(Console.ReadLine());
}
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private double[] ReadLineDoubleArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => double.Parse(a))
.ToArray();
}
static private decimal[] ReadLineDecimalArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => decimal.Parse(a))
.ToArray();
}
static private List<int> ReadLineIntList() {
return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList();
}
static private List<long> ReadLineLongList() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToList();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
static private string IntToNString(int x, int n) {
var nstring = "";
var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f" };
int r = 1;
int q = x;
while (q > 0) {
r = q % n;
nstring += numbers[r];
q = q / n;
}
return string.Join("", nstring.Reverse());
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 85], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 12, 16, 12, 23, 0, 24], ["+", 12, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 17, 85], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 23, 0, 25]]
| 8
| 932
| 20
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp2 {
public class Program {
static long D = (long)Math.Pow(10, 9) + 7;
public static void Main(string[] args) {
int mod = 2019;
int[] LR = Read(Console.ReadLine());
int L = LR[0];
int R = LR[1];
if (R - L >= 2019) {
Console.WriteLine(0);
return;
}
int min = mod;
for (int i = L; i < R; i++) {
for (int j = i + 1; j <= R; j++) {
min = Math.Min(min, (int)((long)i * (long)j) % mod);
}
}
Console.WriteLine(min);
Console.ReadLine();
}
private static int[] Read(string input) {
string[] strings = input.Split(' ');
int num = strings.Length;
int[] ints = new int[num];
for (int i = 0; i < num; i++) {
ints[i] = int.Parse(strings[i]);
}
return ints;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp2 {
public class Program {
public static void Main(string[] args) {
int mod = 2019;
int[] LR = Read(Console.ReadLine());
int L = LR[0];
int R = LR[1];
if (R - L >= 2019) {
Console.WriteLine(0);
return;
}
int min = mod;
for (long i = L; i < R; i++) {
for (long j = i + 1; j <= R; j++) {
min = Math.Min(min, (int)((i * j) % mod));
}
}
Console.WriteLine(min);
Console.ReadLine();
}
private static int[] Read(string input) {
string[] strings = input.Split(' ');
int num = strings.Length;
int[] ints = new int[num];
for (int i = 0; i < num; i++) {
ints[i] = int.Parse(strings[i]);
}
return ints;
}
}
}
|
[["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 115], ["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["-", 0, 16, 31, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 16, 31, 74, 51, 213, 63, 214, 0, 131], ["-", 0, 16, 31, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 24], ["-", 31, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 21], ["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 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], ["-", 31, 74, 51, 23, 0, 16, 31, 74, 39, 199], ["-", 31, 74, 51, 23, 0, 16, 31, 74, 0, 25], ["-", 31, 74, 51, 23, 0, 16, 12, 74, 0, 24], ["-", 31, 74, 51, 23, 0, 16, 12, 74, 39, 199], ["-", 31, 74, 51, 23, 0, 16, 12, 74, 0, 25], ["+", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25]]
| 8
| 264
| 28
|
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert
#if true && UTAKA_LOCAL
//#if false
#define UTAKA_DEBUG
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;
namespace UtakaApp {
public partial class Program {
//=========================================================================================
// Answer
//=========================================================================================
public const string SiteName = "AtCoder";
public const string ContestName = "abc133";
public const string ProblemName = "C";
public const long Mod = 2019L;
public void Solve() {
long L = cin.ReadLong;
long R = cin.ReadLong;
L %= Mod;
R %= Mod;
if (R < L) {
R += Mod;
}
long min = 2018;
for (long i = L; i <= R; i++) {
for (long j = i + 1; j <= R; j++) {
min = LongMin(min, (i * j) % Mod);
}
}
cou.WriteLine(min);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
long LongMin(long x, long y) { return (x < y) ? x : y; }
}
//=========================================================================================
// Library
//=========================================================================================
//=========================================================================================
// Debug IO
//=========================================================================================
public partial class Program {
//=========================================================================================
// Main
//=========================================================================================
private readonly ConsoleInput cin;
private readonly IConsole cou;
public Program(ConsoleInput cin, IConsole cou) {
this.cin = cin;
this.cou = cou;
}
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems();
#else
var cin = new ConsoleInput(System.Console.In);
var console = new MyConsole();
new Program(cin, console).Solve();
console.Flush();
#endif
}
}
public class ConsoleInput {
private readonly char _separator = ' ';
private readonly TextReader _stream;
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => double.Parse(Read);
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i) {
ret[i] = Read;
}
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadInt;
}
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadLong;
}
return ret;
}
}
public interface IConsole {
void Flush();
void Write(object obj);
void Write(string str);
void WriteLine(object obj);
void WriteLine(string str);
void WriteLine();
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { Console.WriteLine(str); }
public void WriteLine() { Console.WriteLine(); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// 何もしない
}
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { mSb.Append(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public void WriteLine() { mSb.AppendLine(); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string GetDirectoryPath() {
var problemPart = string.IsNullOrEmpty(Program.ProblemName)
? ""
: $"/{Program.ProblemName}";
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
}
private string GetInputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
}
private string GetOutputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var cin = new ConsoleInput(inputStream);
var debugConsoleWriter = new DebugConsole();
new Program(cin, debugConsoleWriter).Solve();
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems(int targetTestCaseNumber = -1) {
if (targetTestCaseNumber >= 0) {
Console.WriteLine(
$"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
}
bool isSuccessAll = true;
int testCaseNumber = 0;
while (true) {
testCaseNumber++;
if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) {
continue;
}
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
#if UTAKA_LOCAL
public static class Dbg {
public static void WriteLine(string str) { Console.WriteLine(str); }
public static void Write(string str) { Console.Write(str); }
}
#else
public static class Dbg {
public static void WriteLine(string str) {}
public static void Write(string str) {}
}
#endif
}
|
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert
#if true && UTAKA_LOCAL
//#if false
#define UTAKA_DEBUG
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;
namespace UtakaApp {
public partial class Program {
//=========================================================================================
// Answer
//=========================================================================================
public const string SiteName = "AtCoder";
public const string ContestName = "abc133";
public const string ProblemName = "C";
public const long Mod = 2019L;
public void Solve() {
long L = cin.ReadLong;
long R = cin.ReadLong;
if (R - L >= 2018) {
cou.WriteLine(0);
return;
}
L %= Mod;
R %= Mod;
if (R < L) {
cou.WriteLine(0);
return;
// R += Mod;
}
long min = 2018;
for (long i = L; i <= R; i++) {
for (long j = i + 1; j <= R; j++) {
min = LongMin(min, (i * j) % Mod);
}
}
cou.WriteLine(min);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
long LongMin(long x, long y) { return (x < y) ? x : y; }
}
//=========================================================================================
// Library
//=========================================================================================
//=========================================================================================
// Debug IO
//=========================================================================================
public partial class Program {
//=========================================================================================
// Main
//=========================================================================================
private readonly ConsoleInput cin;
private readonly IConsole cou;
public Program(ConsoleInput cin, IConsole cou) {
this.cin = cin;
this.cou = cou;
}
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems();
#else
var cin = new ConsoleInput(System.Console.In);
var console = new MyConsole();
new Program(cin, console).Solve();
console.Flush();
#endif
}
}
public class ConsoleInput {
private readonly char _separator = ' ';
private readonly TextReader _stream;
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => double.Parse(Read);
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i) {
ret[i] = Read;
}
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadInt;
}
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadLong;
}
return ret;
}
}
public interface IConsole {
void Flush();
void Write(object obj);
void Write(string str);
void WriteLine(object obj);
void WriteLine(string str);
void WriteLine();
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { Console.WriteLine(str); }
public void WriteLine() { Console.WriteLine(); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// 何もしない
}
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { mSb.Append(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public void WriteLine() { mSb.AppendLine(); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string GetDirectoryPath() {
var problemPart = string.IsNullOrEmpty(Program.ProblemName)
? ""
: $"/{Program.ProblemName}";
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
}
private string GetInputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
}
private string GetOutputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var cin = new ConsoleInput(inputStream);
var debugConsoleWriter = new DebugConsole();
new Program(cin, debugConsoleWriter).Solve();
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems(int targetTestCaseNumber = -1) {
if (targetTestCaseNumber >= 0) {
Console.WriteLine(
$"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
}
bool isSuccessAll = true;
int testCaseNumber = 0;
while (true) {
testCaseNumber++;
if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) {
continue;
}
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
#if UTAKA_LOCAL
public static class Dbg {
public static void WriteLine(string str) { Console.WriteLine(str); }
public static void Write(string str) { Console.Write(str); }
}
#else
public static class Dbg {
public static void WriteLine(string str) {}
public static void Write(string str) {}
}
#endif
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 1,470
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static string InputPattern = "InputX";
static List<string> GetInputList() {
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("2020 2040");
// 2
} else if (InputPattern == "Input2") {
WillReturn.Add("4 5");
// 20
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
List<string> InputList = GetInputList();
int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
int L = wkArr[0];
int R = wkArr[1];
int Answer = int.MaxValue;
for (int I = L; I <= Math.Min(L + 2019, R); I++) {
for (int J = I + 1; J <= Math.Min(I + 2019, R); J++) {
Answer = Math.Min(Answer, (I * J) % 2019);
}
}
Console.WriteLine(Answer);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static string InputPattern = "InputX";
static List<string> GetInputList() {
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("2020 2040");
// 2
} else if (InputPattern == "Input2") {
WillReturn.Add("4 5");
// 20
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
List<string> InputList = GetInputList();
long[] wkArr = InputList[0].Split(' ').Select(X => long.Parse(X)).ToArray();
long L = wkArr[0];
long R = wkArr[1];
long Answer = long.MaxValue;
for (long I = L; I <= Math.Min(L + 2019, R); I++) {
for (long J = I + 1; J <= Math.Min(I + 2019, R); J++) {
Answer = Math.Min(Answer, (I * J) % 2019);
}
}
Console.WriteLine(Answer);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 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, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 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
| 268
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class Program {
static void Main(string[] args) {
int[] a = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
int L = a[0];
int R = a[1];
if (R - L >= 2018) {
// L〜Rの中に2019の倍数が含まれるので
Console.WriteLine("0");
} else {
int ans = 2020;
for (int i = L; i < R; i++) {
for (int j = i + 1; j <= R; j++) {
if (ans > (i * j) % 2019)
ans = (i * j) % 2019;
if (ans == 0)
break;
}
if (ans == 0)
break;
}
Console.WriteLine(ans + "");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class Program {
static void Main(string[] args) {
int[] a = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
int L = a[0];
int R = a[1];
if (R - L >= 2018) {
// L〜Rの中に2019の倍数が含まれるので
Console.WriteLine("0");
} else {
long ans = 2020;
long ij = 0;
for (int i = L; i < R; i++) {
for (int j = i + 1; j <= R; j++) {
ij = (long)i * (long)j;
if (ans > ij % 2019)
ans = ij % 2019;
if (ans == 0)
break;
}
if (ans == 0)
break;
}
Console.WriteLine(ans + "");
}
}
}
}
|
[["-", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25], ["-", 15, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 51, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 64, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 48], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["-", 64, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22]]
| 8
| 204
| 31
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split();
int L = int.Parse(s[0]);
int R = int.Parse(s[1]);
int min = 2019;
L = L % 2019;
R = R % 2019;
if (L >= R) {
min = 0;
}
for (int i = L; i < R; ++i) {
for (int j = i + 1; j <= R; ++j) {
if ((i * j) % 2019 < min) {
min = (i * j) % 2019;
}
}
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split();
int L = int.Parse(s[0]);
int R = int.Parse(s[1]);
int min = 2019;
if (R - L > 2019)
min = 0;
L = L % 2019;
R = R % 2019;
if (L >= R) {
min = 0;
}
for (int i = L; i < R; ++i) {
for (int j = i + 1; j <= R; ++j) {
if ((i * j) % 2019 < min) {
min = (i * j) % 2019;
}
}
}
Console.WriteLine(min);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 181
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int L = int.Parse(s.Split(' ')[0]);
int R = int.Parse(s.Split(' ')[1]);
int ans = 2020;
if (L % 2019 < R % 2019) {
L = L % 2019;
R = R % 2019;
} else {
ans = 0;
goto Go;
}
for (int i = L; i <= R; i++) {
for (int j = i + 1; j <= R; j++) {
int X = (i * j) % 2019;
ans = Math.Min(ans, X);
}
}
Go:
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int L = int.Parse(s.Split(' ')[0]);
int R = int.Parse(s.Split(' ')[1]);
int ans = 2020;
if (R - L >= 2019) {
ans = 0;
goto Go;
} else if (L % 2019 < R % 2019) {
L = L % 2019;
R = R % 2019;
} else {
ans = 0;
goto Go;
}
for (int i = L; i <= R - 1; i++) {
for (int j = i + 1; j <= R; j++) {
int X = (i * j) % 2019;
ans = Math.Min(ans, X);
}
}
Go:
Console.WriteLine(ans);
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 127], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 195
| 20
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Myon {
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
void calc() {
int l, r;
l = cin.nextInt();
r = cin.nextInt();
int ans;
if (l / 2019 != r / 2019) {
ans = 0;
} else {
l %= 2019;
r %= 2019;
Console.WriteLine(l + ", " + r);
if (l > r)
swap<int>(ref l, ref r);
int min = 2019;
for (int i = l; i <= r; i++) {
for (int j = i + 1; j <= r; j++) {
min = Math.Min(min, (i * j) % 2019);
}
}
ans = min;
}
Console.WriteLine(ans);
}
// swap
void swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
}
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.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Myon {
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
void calc() {
int l, r;
l = cin.nextInt();
r = cin.nextInt();
int ans;
if (l / 2019 != r / 2019) {
ans = 0;
} else {
l %= 2019;
r %= 2019;
if (l > r)
swap<int>(ref l, ref r);
int min = 2019;
for (int i = l; i <= r; i++) {
for (int j = i + 1; j <= r; j++) {
min = Math.Min(min, (i * j) % 2019);
}
}
ans = min;
}
Console.WriteLine(ans);
}
// swap
void swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
}
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;
}
}
|
[["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 606
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class Program {
static void Main() {
var LR = ReadLine().Split().Select(int.Parse).ToArray();
var L = LR[0];
var R = LR[1];
var l = L % 2019;
var r = R % 2019;
var ans = L == R ? l : l >= r ? 0 : 2018;
for (var i = l; i <= r; i++) {
for (var j = i + 1; j <= r; j++) {
ans = Min(ans, i * j % 2019);
}
}
WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class Program {
static void Main() {
var LR = ReadLine().Split().Select(int.Parse).ToArray();
var L = LR[0];
var R = LR[1];
var l = L % 2019;
var r = R % 2019;
var ans = R - L >= 2018 ? 0 : l > r ? 0 : 2018;
for (var i = l; i <= r; i++) {
for (var j = i + 1; j <= r; j++) {
ans = Min(ans, i * j % 2019);
}
}
WriteLine(ans);
}
}
|
[["-", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 17, 33], ["+", 0, 212, 0, 41, 15, 16, 31, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 20], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 64, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["-", 0, 212, 0, 41, 75, 41, 15, 16, 17, 20], ["+", 0, 212, 0, 41, 75, 41, 15, 16, 17, 47]]
| 8
| 159
| 10
|
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 L = cin.nextLong();
var R = cin.nextLong();
long ans = long.MaxValue;
for (long i = L; i < (L + 2019) && i < R; i++) {
long j = i + 1;
long ij = ((i % 2019) * (j % 2019));
long ijMod = ij % 2019;
if (ans >= ijMod) {
ans = ijMod;
}
}
Console.WriteLine(ans);
}
}
public static class Combination {
public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k,
bool withRepetition) {
if (k == 1) {
foreach (var item in items)
yield return new T[] { item };
yield break;
}
foreach (var item in items) {
var leftside = new T[] { item };
var unused = withRepetition
? items
: items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();
foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
yield return leftside.Concat(rightside).ToArray();
}
}
}
}
class Point {
public int x { get; set; }
public int y { get; set; }
}
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 L = cin.nextLong();
var R = cin.nextLong();
long ans = long.MaxValue;
for (long i = L; i < (L + 2018) && i < R; i++) {
for (long j = i + 1; j < (i + 2018) && j <= R; j++) {
long ij = ((i % 2019) * (j % 2019));
long ijMod = ij % 2019;
if (ans >= ijMod) {
ans = ijMod;
}
}
}
Console.WriteLine(ans);
}
}
public static class Combination {
public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k,
bool withRepetition) {
if (k == 1) {
foreach (var item in items)
yield return new T[] { item };
yield break;
}
foreach (var item in items) {
var leftside = new T[] { item };
var unused = withRepetition
? items
: items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();
foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
yield return leftside.Concat(rightside).ToArray();
}
}
}
}
class Point {
public int x { get; set; }
public int y { get; set; }
}
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;
}
}
}
|
[["-", 15, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 18], ["+", 0, 7, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 7, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 98], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 661
| 21
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
public class MainClass {
public static void Main(string[] args) {
if (args.Length > 0 && args[0] == "debug") {
var inputs = new[] { @"
2020 2040
",
@"
4 5
",
@"
2020 20400
" };
foreach (var str in inputs) {
var text = str.Trim();
if (text.Length == 0)
continue;
var reader = new System.IO.StringReader(text);
Console.SetIn(reader);
Main2(args);
Console.WriteLine();
Console.WriteLine("----------------------------------");
Console.WriteLine();
}
} else
Main2(args);
}
public static void Main2(string[] args) {
checked {
var paramsList = Console.ReadLine().Split(' ').ToList();
// LR
var L = long.Parse(paramsList[0]);
var R = long.Parse(paramsList[1]);
var res = long.MaxValue;
for (long l = L; l < R && l < L + 2020; ++l) {
for (long r = l + 1; r <= R && r < l + 2020; ++r) {
var val = (l * r) % 2019L;
if (res < val)
break;
else
res = val;
}
if (res == 0)
break;
}
Console.WriteLine(res);
}
}
}
public static class EnumerablePlus {
///< summary>出力文字列に変換。</summary>
public static string MkString<T>(this IEnumerable<T> list) {
return list
.Aggregate(new System.Text.StringBuilder(),
(a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b))
.ToString();
}
///< summary>添字付きfor。</summary>
public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a) {
int i = 0;
foreach (var item in list) {
a(item, i);
}
}
///< summary>指定回数デリゲートを呼び出す。</summary>
public static IEnumerable<T> Repeat<T>(int n, Func<T> f) {
for (int i = 0; i < n; i++) {
yield return f();
}
}
}
public static class MathPlus {
///< summary>約数。順番は不定。</summary>
public static List<long> Divisor(long n) {
var list =
Prime(n)
.GroupBy(id => id)
.Select(pair => new { prime = pair.Key, power = pair.Count() })
.ToList();
var result = list.Aggregate(new List<long>(), (left, pair) => {
var list2 = Enumerable.Range(0, pair.power + 1)
.Aggregate(new List<long>(), (res, l) => {
var next = res.Count > 0 ? res.Last() * pair.prime : 1L;
res.Add(next);
return res;
});
if (left.Count == 0)
return list2.ToList();
return list2.SelectMany(l => left.Select(m => l * m)).ToList();
});
return result;
}
///< summary>順列の数。</summary>
public static long Permutation(long n, long r) => Factorial(n, r);
///< summary>組合せの数。</summary>
public static long Combination(long n, long r) {
if (r == 0)
return 1;
return Factorial(n, r) / Factorial(r);
}
///< summary>階乗。カウントも指定可能。</summary>
public static long Factorial(long a, long count = long.MaxValue) {
long res = 1;
for (long i = 0; a > 0 && i < count; i++) {
checked { res *= a; }
--a;
}
return res;
}
///< summary>素因数分解。昇順。</summary>
public static List<long> Prime(long a) {
var res = new List<long>();
for (long b = 2, c = (long)Math.Ceiling(Math.Sqrt(a)); b <= c; ++b) {
while (a % b == 0) {
res.Add(b);
a = a / b;
}
}
return res;
}
///< summary>最小公倍数。</summary>
public static long Lcm(IEnumerable<long> list) {
return list.Aggregate((a, b) => Lcm(a, b));
}
///< summary>最小公倍数。</summary>
public static long Lcm(long a, long b) { return checked(a * b) / Gcd(a, b); }
///< summary>最大公約数。</summary>
public static long Gcd(IEnumerable<long> list) {
return list.Aggregate((a, b) => Gcd(a, b));
}
///< summary>最大公約数。</summary>
public static long Gcd(long a, long b) {
if (a < b)
Gcd(b, a);
while (b != 0) {
var rem = a % b;
a = b;
b = rem;
}
return a;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
public class MainClass {
public static void Main(string[] args) {
if (args.Length > 0 && args[0] == "debug") {
var inputs = new[] { @"
2020 2040
",
@"
4 5
",
@"
2020 20400
" };
foreach (var str in inputs) {
var text = str.Trim();
if (text.Length == 0)
continue;
var reader = new System.IO.StringReader(text);
Console.SetIn(reader);
Main2(args);
Console.WriteLine();
Console.WriteLine("----------------------------------");
Console.WriteLine();
}
} else
Main2(args);
}
public static void Main2(string[] args) {
checked {
var paramsList = Console.ReadLine().Split(' ').ToList();
// LR
var L = long.Parse(paramsList[0]);
var R = long.Parse(paramsList[1]);
var res = long.MaxValue;
for (long l = L; l < R && l < L + 2019; ++l) {
for (long r = l + 1; r <= R && r < l + 2019; ++r) {
var val = (l * r) % 2019L;
res = Math.Min(res, val);
if (res == 0)
break;
}
if (res == 0)
break;
}
Console.WriteLine(res);
}
}
}
public static class EnumerablePlus {
///< summary>出力文字列に変換。</summary>
public static string MkString<T>(this IEnumerable<T> list) {
return list
.Aggregate(new System.Text.StringBuilder(),
(a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b))
.ToString();
}
///< summary>添字付きfor。</summary>
public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a) {
int i = 0;
foreach (var item in list) {
a(item, i);
}
}
///< summary>指定回数デリゲートを呼び出す。</summary>
public static IEnumerable<T> Repeat<T>(int n, Func<T> f) {
for (int i = 0; i < n; i++) {
yield return f();
}
}
}
public static class MathPlus {
///< summary>約数。順番は不定。</summary>
public static List<long> Divisor(long n) {
var list =
Prime(n)
.GroupBy(id => id)
.Select(pair => new { prime = pair.Key, power = pair.Count() })
.ToList();
var result = list.Aggregate(new List<long>(), (left, pair) => {
var list2 = Enumerable.Range(0, pair.power + 1)
.Aggregate(new List<long>(), (res, l) => {
var next = res.Count > 0 ? res.Last() * pair.prime : 1L;
res.Add(next);
return res;
});
if (left.Count == 0)
return list2.ToList();
return list2.SelectMany(l => left.Select(m => l * m)).ToList();
});
return result;
}
///< summary>順列の数。</summary>
public static long Permutation(long n, long r) => Factorial(n, r);
///< summary>組合せの数。</summary>
public static long Combination(long n, long r) {
if (r == 0)
return 1;
return Factorial(n, r) / Factorial(r);
}
///< summary>階乗。カウントも指定可能。</summary>
public static long Factorial(long a, long count = long.MaxValue) {
long res = 1;
for (long i = 0; a > 0 && i < count; i++) {
checked { res *= a; }
--a;
}
return res;
}
///< summary>素因数分解。昇順。</summary>
public static List<long> Prime(long a) {
var res = new List<long>();
for (long b = 2, c = (long)Math.Ceiling(Math.Sqrt(a)); b <= c; ++b) {
while (a % b == 0) {
res.Add(b);
a = a / b;
}
}
return res;
}
///< summary>最小公倍数。</summary>
public static long Lcm(IEnumerable<long> list) {
return list.Aggregate((a, b) => Lcm(a, b));
}
///< summary>最小公倍数。</summary>
public static long Lcm(long a, long b) { return checked(a * b) / Gcd(a, b); }
///< summary>最大公約数。</summary>
public static long Gcd(IEnumerable<long> list) {
return list.Aggregate((a, b) => Gcd(a, b));
}
///< summary>最大公約数。</summary>
public static long Gcd(long a, long b) {
if (a < b)
Gcd(b, a);
while (b != 0) {
var rem = a % b;
a = b;
b = rem;
}
return a;
}
}
}
|
[["-", 0, 7, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94]]
| 8
| 1,013
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
private const int INF = 1000000007;
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
int L = NextInt() % 2019;
int R = NextInt() % 2019;
// 2019で全探索
long ans = INF;
if (L > R) {
int tmp = L;
L = R;
R = tmp;
}
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);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static char NextChar() {
Confirm();
return char.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
private const int INF = 1000000007;
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
long L = NextInt();
long R = NextInt();
// 2019で全探索
long ans = INF;
if (R - L >= 2019) {
ans = 0;
}
R %= 2019;
L %= 2019;
if (R < L) {
ans = 0;
}
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);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static char NextChar() {
Confirm();
return char.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["-", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 8, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 8, 7, 10, 198, 39, 199]]
| 8
| 533
| 41
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
const int MOD = 2019;
var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
int L = vals[0];
int R = vals[1];
long ans = 2020;
if (L % MOD < R % MOD && (R - L) < MOD) {
for (int i = L % MOD; i < R % MOD; i++) {
for (int j = i + 1; j <= R % MOD; j++) {
long tmp = i * j % MOD;
ans = Math.Min(tmp, ans);
}
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
const int MOD = 2019;
var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
int L = vals[0];
int R = vals[1];
long ans = 2020;
if (L % MOD < R % MOD && (R - L) < MOD) {
for (int i = L % MOD; i < R % MOD; i++) {
for (int j = i + 1; j <= R % MOD; j++) {
long tmp = i * j % MOD;
ans = Math.Min(tmp, ans);
}
}
} else {
ans = 0;
}
Console.WriteLine(ans);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 173
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var l = input[0];
var r = input[1];
var min = int.MaxValue;
//差が一周するならば 2019 以内の全組み合わせ
if (r - l >= 2019) {
for (int j = 2; j <= 2019; j++) {
for (int i = 1; i < j; i++) {
var mod = (i % 2019) * (j % 2019) % 2019;
if (mod < min) {
min = mod;
}
}
}
}
//一周しない場合、l mod 2019 から 差分 だけ試せばいい
else {
for (int j = l + 1; j < r + 1; j++) {
for (int i = l; i < j; i++) {
var mod = i * j % 2019;
if (mod < min) {
min = mod;
}
}
}
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var l = input[0];
var r = input[1];
var min = int.MaxValue;
//差が一周するならば 2019 以内の全組み合わせ
if (r - l >= 2019) {
for (int j = 1; j <= 2019; j++) {
for (int i = 0; i < j; i++) {
var mod = (i % 2019) * (j % 2019) % 2019;
if (mod < min) {
min = mod;
}
}
}
}
//一周しない場合、l mod 2019 から 差分 だけ試せばいい
else {
for (int j = l + 1; j < r + 1; j++) {
for (int i = l; i < j; i++) {
var mod = (i % 2019) * (j % 2019) % 2019;
if (mod < min) {
min = mod;
}
}
}
}
Console.WriteLine(min);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 109], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 212, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 16, 31, 16, 12, 23, 0, 25]]
| 8
| 237
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine().Split(' ');
var l = int.Parse(s[0]);
var r = int.Parse(s[1]);
if (r / 2019 * 2019 >= l || l >= r) {
// 2019を超えるとき
Console.WriteLine(0);
} else {
// 2019の倍数を通らないとき
int temp = 2018;
int savedi = 0;
int savedj = 0;
for (int i = l; i <= r; i++) {
for (int j = i + 1; j <= r; j++) {
temp = Math.Min(temp, ((i % 2019) * (j % 2019)) % 2019);
}
}
Console.WriteLine(temp);
Console.WriteLine(savedi + " * " + savedj + " = " + savedi * savedj);
}
#if DEBUG
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine().Split(' ');
var l = int.Parse(s[0]);
var r = int.Parse(s[1]);
if (r / 2019 * 2019 >= l || l >= r) {
// 2019を超えるとき
Console.WriteLine(0);
} else {
// 2019の倍数を通らないとき
int temp = 2018;
int savedi = 0;
int savedj = 0;
for (int i = l; i <= r; i++) {
for (int j = i + 1; j <= r; j++) {
temp = Math.Min(temp, ((i % 2019) * (j % 2019)) % 2019);
}
}
Console.WriteLine(temp);
}
#if DEBUG
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
}
|
[["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 72], ["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 238
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC133 {
class Program {
static void Main(string[] args) {
var lr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var l = lr[0];
var r = lr[1];
if (r - l > 2019) {
r = l + 2019;
}
var result = 2020;
for (int i = l; i < r; i++) {
for (int j = i + 1; j < r + 1; j++) {
result = Math.Min(result, (i * j) % 2019);
}
if (result == 0)
break;
}
Console.WriteLine(result);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC133 {
class Program {
static void Main(string[] args) {
var lr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var l = lr[0];
var r = lr[1];
if (r - l > 2019) {
r = l + 2019;
}
var result = 2018;
for (int i = l; i < r; i++) {
for (int j = i + 1; j < r + 1; j++) {
var x = i % 2019;
var y = j % 2019;
result = Math.Min(result, (x * y) % 2019);
}
if (result == 0)
break;
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22]]
| 8
| 178
| 20
|
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();
int L = a[0];
int R = a[1];
long nowr = 2018;
for (int i = L; i < R; i++) {
for (int j = i + 1; j <= R; j++) {
long t = (i * j) % 2019;
if (t == 0) {
nowr = 0;
i = R;
break;
} else {
nowr = (t < nowr) ? t : nowr;
}
}
}
Cout(nowr);
Cin();
}
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 S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { Console.WriteLine(s); }
static void DbShowE<Type>(IEnumerable<Type> types) {
foreach (var i in types) {
Console.Write(i + " ");
}
Console.WriteLine();
}
}
}
|
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 = CinLAr();
long L = a[0];
long R = a[1];
long nowr = 2100;
for (long i = L; i < R; i++) {
for (long j = i + 1; j <= R; j++) {
long t = (i * j) % 2019;
if (t == 0) {
nowr = 0;
i = R;
break;
} else {
nowr = Math.Min(nowr, t);
}
}
}
Cout(nowr);
}
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 S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { Console.WriteLine(s); }
static void DbShowE<Type>(IEnumerable<Type> types) {
foreach (var i in types) {
Console.Write(i + " ");
}
Console.WriteLine();
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 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], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 41, 15, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 41, 15, 23, 0, 16, 17, 18], ["-", 0, 1, 0, 11, 12, 41, 15, 23, 0, 25], ["-", 75, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 75, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["-", 75, 196, 0, 1, 0, 11, 12, 41, 75, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 466
| 27
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace A {
class Program {
public IEnumerable<string> Solve() {
// var ut = new Util();
var sc = new Scanner();
var l = sc.NumLong;
var r = sc.NumLong;
var lm = l % 2019;
var rm = r % 2019;
if (rm < lm)
rm += 2019;
var res = long.MaxValue;
for (long i = lm; i <= rm; i++) {
for (long j = i + 1; j <= rm; j++) {
var cd = (i * j) % 2019;
res = Math.Min(res, cd);
}
}
yield return res.ToString();
}
}
class StartingPoint {
static void Main(string[] args) {
if (args?.Any() == true) {
var assembly = Assembly.GetEntryAssembly();
var resourceName = "AtCoderCSharp.In.txt";
var stream = assembly.GetManifestResourceStream(resourceName);
var streamReader = new StreamReader(stream, Encoding.UTF8);
var str = streamReader.ReadToEnd();
var textReader = new StringReader(str);
Console.SetIn(textReader);
}
try {
foreach (var s in new Program().Solve()) {
Console.WriteLine(s);
}
} catch (Exception e) {
Console.WriteLine(e);
if (args?.Any() != true)
throw e;
}
if (args?.Any() == true)
Console.ReadKey();
}
}
class Scanner {
public int[] Nums(int count) =>
Enumerable.Range(0, count).Select(_ => Num).ToArray();
public int Num => int.Parse(Str);
public long NumLong => long.Parse(Str);
public double NumDouble => (double)NumLong;
StringBuilder sb = new StringBuilder();
public string Str => GetStr();
public string GetStr() {
sb.Clear();
int r = 0;
bool? b = null;
do {
r = Console.Read();
b = IsBreak(r);
} while (b == true);
if (b == null)
throw new Exception("input error: unexpected end of stream");
do {
sb.Append((char)r);
r = Console.Read();
b = IsBreak(r);
} while (b == false);
return sb.ToString();
}
bool? IsBreak(int c) {
switch (c) {
case -1:
return null;
case (int)' ':
case (int)'\n':
case (int)'\r':
return true;
default:
return false;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace A {
class Program {
public IEnumerable<string> Solve() {
// var ut = new Util();
var sc = new Scanner();
var l = sc.NumLong;
var r = sc.NumLong;
var lm = l;
var rm = (r - l) > 4038 ? r - ((r - l) / 2019 - 2) * 2019 : r;
var res = long.MaxValue;
for (long i = lm; i <= rm; i++) {
for (long j = i + 1; j <= rm; j++) {
long cd = (i * j) % 2019;
res = Math.Min(res, cd);
}
}
yield return res.ToString();
}
}
class StartingPoint {
static void Main(string[] args) {
if (args?.Any() == true) {
var assembly = Assembly.GetEntryAssembly();
var resourceName = "AtCoderCSharp.In.txt";
var stream = assembly.GetManifestResourceStream(resourceName);
var streamReader = new StreamReader(stream, Encoding.UTF8);
var str = streamReader.ReadToEnd();
var textReader = new StringReader(str);
Console.SetIn(textReader);
}
try {
foreach (var s in new Program().Solve()) {
Console.WriteLine(s);
}
} catch (Exception e) {
Console.WriteLine(e);
if (args?.Any() != true)
throw e;
}
if (args?.Any() == true)
Console.ReadKey();
}
}
class Scanner {
public int[] Nums(int count) =>
Enumerable.Range(0, count).Select(_ => Num).ToArray();
public int Num => int.Parse(Str);
public long NumLong => long.Parse(Str);
public double NumDouble => (double)NumLong;
StringBuilder sb = new StringBuilder();
public string Str => GetStr();
public string GetStr() {
sb.Clear();
int r = 0;
bool? b = null;
do {
r = Console.Read();
b = IsBreak(r);
} while (b == true);
if (b == null)
throw new Exception("input error: unexpected end of stream");
do {
sb.Append((char)r);
r = Console.Read();
b = IsBreak(r);
} while (b == false);
return sb.ToString();
}
bool? IsBreak(int c) {
switch (c) {
case -1:
return null;
case (int)' ':
case (int)'\n':
case (int)'\r':
return true;
default:
return false;
}
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 212, 0, 41, 15, 16, 31, 23, 0, 24], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 0, 41, 15, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 41, 15, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 212, 0, 41, 15, 16, 31, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 47], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 200, 0, 212, 0, 41, 64, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 64, 16, 17, 33], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 85], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 64, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 64, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 41, 64, 16, 12, 16, 31, 23, 0, 25], ["+", 0, 212, 0, 41, 64, 16, 12, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 75, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 570
| 34
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using static System.Math;
using System.Text;
namespace Program {
public static class ABC133C {
static public void Solve() {
var L = NN;
var R = NN;
var adjL = L % 2019;
var adjR = R % 2019;
var tgtNum = new List<long>();
if (adjL < adjR) {
for (var i = adjL; i <= adjR; i++) {
tgtNum.Add(i);
}
} else {
for (var i = 0; i <= adjR; i++) {
tgtNum.Add(i);
}
for (var i = adjL; i < 2019; i++) {
tgtNum.Add(i);
}
}
var ans = long.MaxValue;
tgtNum = tgtNum.Distinct().OrderBy(e => e).ToList();
for (var i = 0; i < tgtNum.Count; i++) {
for (var j = i + 1; j < tgtNum.Count; j++) {
ans = Min(ans, (tgtNum[i] * tgtNum[j]) % 2019);
}
}
Console.WriteLine(ans);
}
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// TEST _/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
class BT<T>
where T : IComparable {
private class Node {
public Node left;
public Node right;
public T val;
public bool isBlack;
}
private Comparison<T> c;
private Node root;
private bool change;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
private bool Red(Node n) => n != null && !n.isBlack;
private bool Black(Node n) => n != null && n.isBlack;
private Node RotateL(Node n) {
Node m = n.right, t = m.left;
m.left = n;
n.right = t;
return m;
}
private Node RotateR(Node n) {
Node m = n.left, t = m.right;
m.right = n;
n.left = t;
return m;
}
private Node RotateLR(Node n) {
n.left = RotateL(n.left);
return RotateR(n);
}
private Node RotateRL(Node n) {
n.right = RotateR(n.right);
return RotateL(n);
}
public void Add(T x) {
root = Add(root, x);
root.isBlack = true;
}
private Node Add(Node n, T x) {
if (n == null) {
change = true;
return new Node() { val = x };
}
var r = c(x, n.val);
if (r < 0) {
n.left = Add(n.left, x);
return Balance(n);
}
if (r > 0) {
n.right = Add(n.right, x);
return Balance(n);
}
change = false;
return n;
}
private Node Balance(Node n) {
if (!change)
return n;
if (!Black(n))
return n;
if (Red(n.left) && Red(n.left.left)) {
n = RotateR(n);
n.left.isBlack = true;
} else if (Red(n.left) && Red(n.left.right)) {
n = RotateLR(n);
n.left.isBlack = true;
} else if (Red(n.right) && Red(n.right.left)) {
n = RotateRL(n);
n.right.isBlack = true;
} else if (Red(n.right) && Red(n.right.right)) {
n = RotateL(n);
n.right.isBlack = true;
} else {
change = false;
}
return n;
}
public void Remove(T x) {
root = Remove(root, x);
if (root != null)
root.isBlack = true;
}
private Node Remove(Node n, T x) {
if (n == null) {
change = false;
return n;
}
var r = c(x, n.val);
if (r < 0) {
n.left = Remove(n.left, x);
return BalanceL(n);
}
if (r > 0) {
n.right = Remove(n.right, x);
return BalanceR(n);
}
if (n.left == null) {
change = n.isBlack;
return n.right;
}
n.left = RemoveMax(n.left);
n.val = lmax;
return BalanceL(n);
}
private T lmax;
private Node RemoveMax(Node n) {
if (n.right != null) {
n.right = RemoveMax(n.right);
return BalanceR(n);
}
lmax = n.val;
change = n.isBlack;
return n.left;
}
private Node BalanceL(Node n) {
if (!change)
return n;
if (Black(n.right) && Red(n.right.left)) {
var b = n.isBlack;
n = RotateRL(n);
n.isBlack = b;
n.left.isBlack = true;
change = false;
} else if (Black(n.right) && Red(n.right.right)) {
var b = n.isBlack;
n = RotateL(n);
n.isBlack = b;
n.right.isBlack = true;
n.left.isBlack = true;
change = false;
} else if (Black(n.right)) {
change = n.isBlack;
n.isBlack = true;
n.right.isBlack = false;
} else {
n = RotateL(n);
n.isBlack = true;
n.left.isBlack = false;
n.left = BalanceL(n.left);
change = false;
}
return n;
}
private Node BalanceR(Node n) {
if (!change)
return n;
if (Black(n.left) && Red(n.left.right)) {
var b = n.isBlack;
n = RotateLR(n);
n.isBlack = b;
n.right.isBlack = true;
change = false;
} else if (Black(n.left) && Red(n.left.left)) {
var b = n.isBlack;
n = RotateR(n);
n.isBlack = b;
n.left.isBlack = true;
n.right.isBlack = true;
change = false;
} else if (Black(n.left)) {
change = n.isBlack;
n.isBlack = true;
n.left.isBlack = false;
} else {
n = RotateR(n);
n.isBlack = true;
n.right.isBlack = false;
n.right = BalanceR(n.right);
change = false;
}
return n;
}
public bool Have(T x) {
var t = FindUpper(x);
return t.Item1 && t.Item2.CompareTo(x) == 0;
}
public Tuple<bool, T> FindUpper(T x) {
var v = FindUpper(root, x);
if (v == null)
return Tuple.Create(false, default(T));
return v;
}
private Tuple<bool, T> FindUpper(Node n, T x) {
if (n == null)
return null;
var r = c(x, n.val);
if (r < 0) {
var v = FindUpper(n.left, x);
if (v == null)
return Tuple.Create(true, n.val);
return v;
} else if (r > 0)
return FindUpper(n.right, x);
else
return Tuple.Create(true, x);
}
public Tuple<bool, T> FindLower(T x) {
var v = FindLower(root, x);
if (v == null)
return Tuple.Create(false, default(T));
return v;
}
private Tuple<bool, T> FindLower(Node n, T x) {
if (n == null)
return null;
var r = c(x, n.val);
if (r < 0)
return FindLower(n.left, x);
else if (r > 0) {
var v = FindLower(n.right, x);
if (v == null)
return Tuple.Create(true, n.val);
return v;
} else
return Tuple.Create(true, x);
}
public T Min() {
Node n = root, p = null;
while (n != null) {
p = n;
n = n.left;
}
return p == null ? default(T) : p.val;
}
public T Max() {
Node n = root, p = null;
while (n != null) {
p = n;
n = n.right;
}
return p == null ? default(T) : p.val;
}
public bool Any() => root != null;
public int CountSlow() => List(root).Count();
public IEnumerable<T> List() => List(root);
private IEnumerable<T> List(Node n) {
if (n == null)
yield break;
foreach (var i in List(n.left))
yield return i;
yield return n.val;
foreach (var i in List(n.right))
yield return i;
}
}
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// TEST END _/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
Solve();
Console.Out.Flush();
}
static Random rand = new Random();
static class Console_ {
private static Queue<string> param = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void RevSort<T>(T[] l)
where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void RevSort<T>(T[] l, Comparison<T> comp)
where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
class PQ<T>
where T : IComparable {
private List<T> h;
private Comparison<T> c;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Peek => h[0];
public int Count => h.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TKey, TValue>
where TKey : IComparable {
private PQ<Tuple<TKey, TValue>> q;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<TKey> c, bool asc = true) {
q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<TKey> c, bool asc = true) {
q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v));
public Tuple<TKey, TValue> Peek => q.Peek;
public int Count => q.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<TKey, TValue> Pop() => q.Pop();
}
public class UF {
private long[] d;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsSame(long x, long y) => Root(x) == Root(y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Count(long x) => -d[Root(d[x])];
}
struct Mod : IEquatable<object> {
static public long _mod = 1000000007;
private long _val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mod(long x) {
if (x < _mod && x >= 0)
_val = x;
else if ((_val = x % _mod) < 0)
_val += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator long(Mod x) => x._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(Mod x, Mod y) => x._val + y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(Mod x, Mod y) => x._val - y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator *(Mod x, Mod y) => x._val * y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(Mod x, Mod y) => x._val == y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(Mod x, Mod y) => x._val != y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IEquatable<object>.Equals(object obj) => obj == null
? false
: Equals((Mod)obj);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object obj) => obj == null ? false
: Equals((Mod)obj);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Mod obj) => obj == null ? false : _val == obj._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode() => _val.GetHashCode();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => _val.ToString();
static private List<Mod> _fact = new List<Mod>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static private void Build(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Comb(long n, long k) {
Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
}
struct Mat<T> {
private T[,] m;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mat(T[,] v) { m = (T[,])v.Clone(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v);
public T this[int r, int c] {
get { return m[r, c]; }
set { m[r, c] = value; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)b[r, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)b[r, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] *= (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, Mat<T> b) {
var nr = a.m.GetLength(0);
var nc = b.m.GetLength(1);
var tm = new T[nr, nc];
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j)
tm[i, j] = (dynamic)0;
for (int r = 0; r < nr; ++r)
for (int c = 0; c < nc; ++c)
for (int i = 0; i < a.m.GetLength(1); ++i)
tm[r, c] += a[r, i] * (dynamic)b[i, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> Pow(Mat<T> x, long y) {
var n = x.m.GetLength(0);
var t = (Mat<T>)new T[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i, j] = (dynamic)(i == j ? 1 : 0);
while (y != 0) {
if ((y & 1) == 1)
t *= x;
x *= x;
y >>= 1;
}
return t;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static T Pow<T>(T x, long y) {
T a = (dynamic)1;
while (y != 0) {
if ((y & 1) == 1)
a *= (dynamic)x;
x *= (dynamic)x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void _Build(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Comb(long n, long k) {
_Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using static System.Math;
using System.Text;
namespace Program {
public static class ABC133C {
static public void Solve() {
var L = NN;
var R = NN;
var adjL = L % 2019;
var adjR = R % 2019;
var tgtNum = new List<long>();
if (R - L > 2018) {
for (var i = 0; i < 2019; i++) {
tgtNum.Add(i);
}
} else if (adjL < adjR) {
for (var i = adjL; i <= adjR; i++) {
tgtNum.Add(i);
}
} else {
for (var i = 0; i <= adjR; i++) {
tgtNum.Add(i);
}
for (var i = adjL; i < 2019; i++) {
tgtNum.Add(i);
}
}
var ans = long.MaxValue;
tgtNum = tgtNum.Distinct().OrderBy(e => e).ToList();
for (var i = 0; i < tgtNum.Count; i++) {
for (var j = i + 1; j < tgtNum.Count; j++) {
ans = Min(ans, (tgtNum[i] * tgtNum[j]) % 2019);
}
}
Console.WriteLine(ans);
}
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// TEST _/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
class BT<T>
where T : IComparable {
private class Node {
public Node left;
public Node right;
public T val;
public bool isBlack;
}
private Comparison<T> c;
private Node root;
private bool change;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
private bool Red(Node n) => n != null && !n.isBlack;
private bool Black(Node n) => n != null && n.isBlack;
private Node RotateL(Node n) {
Node m = n.right, t = m.left;
m.left = n;
n.right = t;
return m;
}
private Node RotateR(Node n) {
Node m = n.left, t = m.right;
m.right = n;
n.left = t;
return m;
}
private Node RotateLR(Node n) {
n.left = RotateL(n.left);
return RotateR(n);
}
private Node RotateRL(Node n) {
n.right = RotateR(n.right);
return RotateL(n);
}
public void Add(T x) {
root = Add(root, x);
root.isBlack = true;
}
private Node Add(Node n, T x) {
if (n == null) {
change = true;
return new Node() { val = x };
}
var r = c(x, n.val);
if (r < 0) {
n.left = Add(n.left, x);
return Balance(n);
}
if (r > 0) {
n.right = Add(n.right, x);
return Balance(n);
}
change = false;
return n;
}
private Node Balance(Node n) {
if (!change)
return n;
if (!Black(n))
return n;
if (Red(n.left) && Red(n.left.left)) {
n = RotateR(n);
n.left.isBlack = true;
} else if (Red(n.left) && Red(n.left.right)) {
n = RotateLR(n);
n.left.isBlack = true;
} else if (Red(n.right) && Red(n.right.left)) {
n = RotateRL(n);
n.right.isBlack = true;
} else if (Red(n.right) && Red(n.right.right)) {
n = RotateL(n);
n.right.isBlack = true;
} else {
change = false;
}
return n;
}
public void Remove(T x) {
root = Remove(root, x);
if (root != null)
root.isBlack = true;
}
private Node Remove(Node n, T x) {
if (n == null) {
change = false;
return n;
}
var r = c(x, n.val);
if (r < 0) {
n.left = Remove(n.left, x);
return BalanceL(n);
}
if (r > 0) {
n.right = Remove(n.right, x);
return BalanceR(n);
}
if (n.left == null) {
change = n.isBlack;
return n.right;
}
n.left = RemoveMax(n.left);
n.val = lmax;
return BalanceL(n);
}
private T lmax;
private Node RemoveMax(Node n) {
if (n.right != null) {
n.right = RemoveMax(n.right);
return BalanceR(n);
}
lmax = n.val;
change = n.isBlack;
return n.left;
}
private Node BalanceL(Node n) {
if (!change)
return n;
if (Black(n.right) && Red(n.right.left)) {
var b = n.isBlack;
n = RotateRL(n);
n.isBlack = b;
n.left.isBlack = true;
change = false;
} else if (Black(n.right) && Red(n.right.right)) {
var b = n.isBlack;
n = RotateL(n);
n.isBlack = b;
n.right.isBlack = true;
n.left.isBlack = true;
change = false;
} else if (Black(n.right)) {
change = n.isBlack;
n.isBlack = true;
n.right.isBlack = false;
} else {
n = RotateL(n);
n.isBlack = true;
n.left.isBlack = false;
n.left = BalanceL(n.left);
change = false;
}
return n;
}
private Node BalanceR(Node n) {
if (!change)
return n;
if (Black(n.left) && Red(n.left.right)) {
var b = n.isBlack;
n = RotateLR(n);
n.isBlack = b;
n.right.isBlack = true;
change = false;
} else if (Black(n.left) && Red(n.left.left)) {
var b = n.isBlack;
n = RotateR(n);
n.isBlack = b;
n.left.isBlack = true;
n.right.isBlack = true;
change = false;
} else if (Black(n.left)) {
change = n.isBlack;
n.isBlack = true;
n.left.isBlack = false;
} else {
n = RotateR(n);
n.isBlack = true;
n.right.isBlack = false;
n.right = BalanceR(n.right);
change = false;
}
return n;
}
public bool Have(T x) {
var t = FindUpper(x);
return t.Item1 && t.Item2.CompareTo(x) == 0;
}
public Tuple<bool, T> FindUpper(T x) {
var v = FindUpper(root, x);
if (v == null)
return Tuple.Create(false, default(T));
return v;
}
private Tuple<bool, T> FindUpper(Node n, T x) {
if (n == null)
return null;
var r = c(x, n.val);
if (r < 0) {
var v = FindUpper(n.left, x);
if (v == null)
return Tuple.Create(true, n.val);
return v;
} else if (r > 0)
return FindUpper(n.right, x);
else
return Tuple.Create(true, x);
}
public Tuple<bool, T> FindLower(T x) {
var v = FindLower(root, x);
if (v == null)
return Tuple.Create(false, default(T));
return v;
}
private Tuple<bool, T> FindLower(Node n, T x) {
if (n == null)
return null;
var r = c(x, n.val);
if (r < 0)
return FindLower(n.left, x);
else if (r > 0) {
var v = FindLower(n.right, x);
if (v == null)
return Tuple.Create(true, n.val);
return v;
} else
return Tuple.Create(true, x);
}
public T Min() {
Node n = root, p = null;
while (n != null) {
p = n;
n = n.left;
}
return p == null ? default(T) : p.val;
}
public T Max() {
Node n = root, p = null;
while (n != null) {
p = n;
n = n.right;
}
return p == null ? default(T) : p.val;
}
public bool Any() => root != null;
public int CountSlow() => List(root).Count();
public IEnumerable<T> List() => List(root);
private IEnumerable<T> List(Node n) {
if (n == null)
yield break;
foreach (var i in List(n.left))
yield return i;
yield return n.val;
foreach (var i in List(n.right))
yield return i;
}
}
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// TEST END _/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
Solve();
Console.Out.Flush();
}
static Random rand = new Random();
static class Console_ {
private static Queue<string> param = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void RevSort<T>(T[] l)
where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void RevSort<T>(T[] l, Comparison<T> comp)
where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
class PQ<T>
where T : IComparable {
private List<T> h;
private Comparison<T> c;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Peek => h[0];
public int Count => h.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TKey, TValue>
where TKey : IComparable {
private PQ<Tuple<TKey, TValue>> q;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<TKey> c, bool asc = true) {
q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<TKey> c, bool asc = true) {
q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v));
public Tuple<TKey, TValue> Peek => q.Peek;
public int Count => q.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<TKey, TValue> Pop() => q.Pop();
}
public class UF {
private long[] d;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsSame(long x, long y) => Root(x) == Root(y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Count(long x) => -d[Root(d[x])];
}
struct Mod : IEquatable<object> {
static public long _mod = 1000000007;
private long _val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mod(long x) {
if (x < _mod && x >= 0)
_val = x;
else if ((_val = x % _mod) < 0)
_val += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator long(Mod x) => x._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(Mod x, Mod y) => x._val + y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(Mod x, Mod y) => x._val - y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator *(Mod x, Mod y) => x._val * y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(Mod x, Mod y) => x._val == y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(Mod x, Mod y) => x._val != y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IEquatable<object>.Equals(object obj) => obj == null
? false
: Equals((Mod)obj);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object obj) => obj == null ? false
: Equals((Mod)obj);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Mod obj) => obj == null ? false : _val == obj._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode() => _val.GetHashCode();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => _val.ToString();
static private List<Mod> _fact = new List<Mod>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static private void Build(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Comb(long n, long k) {
Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
}
struct Mat<T> {
private T[,] m;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mat(T[,] v) { m = (T[,])v.Clone(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v);
public T this[int r, int c] {
get { return m[r, c]; }
set { m[r, c] = value; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)b[r, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)b[r, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] *= (dynamic)x;
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, Mat<T> b) {
var nr = a.m.GetLength(0);
var nc = b.m.GetLength(1);
var tm = new T[nr, nc];
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j)
tm[i, j] = (dynamic)0;
for (int r = 0; r < nr; ++r)
for (int c = 0; c < nc; ++c)
for (int i = 0; i < a.m.GetLength(1); ++i)
tm[r, c] += a[r, i] * (dynamic)b[i, c];
return tm;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> Pow(Mat<T> x, long y) {
var n = x.m.GetLength(0);
var t = (Mat<T>)new T[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i, j] = (dynamic)(i == j ? 1 : 0);
while (y != 0) {
if ((y & 1) == 1)
t *= x;
x *= x;
y >>= 1;
}
return t;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static T Pow<T>(T x, long y) {
T a = (dynamic)1;
while (y != 0) {
if ((y & 1) == 1)
a *= (dynamic)x;
x *= (dynamic)x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void _Build(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Comb(long n, long k) {
_Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 24], ["+", 64, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["+", 64, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 35], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 25], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
| 8
| 5,807
| 34
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class GFG {
static public void Main() {
try {
var n = int.Parse(Console.ReadLine());
var aar =
Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
Dam(aar, n);
} catch (Exception ex) {
Console.Write(ex);
}
}
static void Dam(Int64[] arr, int n) {
long sum = 0;
long AltSum = 0;
for (int i = 0; i < n; i++) {
sum = sum + arr[i];
}
for (int i = 2; i <= n - 1; i += 2) {
AltSum = AltSum + arr[i];
}
long x1 = sum - 2 * (AltSum);
long[] dp = new long[n];
dp[0] = x1;
for (int i = 1; i < n; i++) {
dp[i] = 2 * arr[i] - dp[i - 1];
}
for (int i = 0; i < n; i++) {
Console.Write(dp[i] + " ");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class GFG {
static public void Main() {
try {
var n = int.Parse(Console.ReadLine());
var aar =
Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
Dam(aar, n);
} catch (Exception ex) {
Console.Write(ex);
}
}
static void Dam(Int64[] arr, int n) {
long sum = 0;
long AltSum = 0;
for (int i = 0; i < n; i++) {
sum = sum + arr[i];
}
for (int i = 2; i <= n - 1; i += 2) {
AltSum = AltSum + arr[i];
}
long x1 = sum - 2 * (AltSum);
long[] dp = new long[n];
dp[1] = x1;
for (int i = 2; i < n; i++) {
dp[i] = 2 * arr[i - 1] - dp[i - 1];
}
dp[0] = 2 * arr[n - 1] - dp[n - 1];
for (int i = 0; i < n; i++) {
Console.Write(dp[i] + " ");
}
}
}
|
[["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 0, 11, 12, 16, 31, 16, 12, 204, 205, 22], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 274
| 27
|
using System;
using System.Linq;
using System.Text;
namespace ABC133.D {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var totalD = a.Sum();
var mlist = new int[n];
mlist[0] = CalcM1(n, a, totalD);
for (int i = 1; i < n; i++)
mlist[i] = CalcM2(a[i - 1], mlist[i - 1]);
var s = new StringBuilder();
foreach (var item in mlist)
s.Append(item).Append(" ");
Console.WriteLine(s.ToString());
}
private static int CalcM1(int n, int[] a, int total) {
var tmp = 0;
for (int i = 1; i < n; i += 2)
tmp += a[i] * 2;
return total - tmp;
}
private static int CalcM2(int d, int mBefore) { return d * 2 - mBefore; }
}
}
|
using System;
using System.Linq;
using System.Text;
namespace ABC133.D {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
var totalD = a.Sum();
var mlist = new long[n];
mlist[0] = CalcM1(n, a, totalD);
for (int i = 1; i < n; i++)
mlist[i] = CalcM2(a[i - 1], mlist[i - 1]);
var s = new StringBuilder();
foreach (var item in mlist)
s.Append(item).Append(" ");
Console.WriteLine(s.ToString());
}
private static long CalcM1(int n, long[] a, long total) {
var tmp = 0L;
for (int i = 1; i < n; i += 2)
tmp += a[i] * 2;
return total - tmp;
}
private static long CalcM2(long d, long mBefore) { return d * 2 - mBefore; }
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 252
| 18
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Myon {
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
void calc() {
var N = cin.nextInt();
var A = cin.ArrayInt(N);
var amount = A.Sum();
var ret = new long[N];
long x = 0;
for (var i = 0; i < N; i++) {
if (i % 2 == 1) {
x -= A[i];
} else {
x += A[i];
}
}
ret[0] = x / 2;
for (var i = 0; i < N - 1; i++) {
ret[i + 1] = A[i] - ret[i];
}
for (var i = 0; i < N - 1; i++) {
Console.Write(ret[i] * 2);
Console.Write(" ");
}
Console.Write(ret[N - 1] * 2);
}
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;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Myon {
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
void calc() {
var N = cin.nextInt();
long[] A = cin.ArrayLong(N);
long[] ret = new long[N];
long x = 0;
for (var i = 0; i < N; i++) {
if (i % 2 == 1) {
x -= A[i];
} else {
x += A[i];
}
}
ret[0] = x / 2;
for (var i = 0; i < N - 1; i++) {
ret[i + 1] = A[i] - ret[i];
}
for (var i = 0; i < N - 1; i++) {
Console.Write(ret[i] * 2);
Console.Write(" ");
}
Console.Write(ret[N - 1] * 2);
}
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;
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
| 8
| 614
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
private const int INF = 1000000007;
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
int N = NextInt();
int[] A = LineInt();
int X = A.Sum();
for (int i = 1; i < N; i += 2)
X -= 2 * A[i];
int y = X / 2;
for (int i = 0; i < N; i++) {
Console.Write(y * 2 + " ");
y = A[i] - y;
}
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static char NextChar() {
Confirm();
return char.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
private const int INF = 1000000007;
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
int N = NextInt();
long[] A = LineLong();
long X = A.Sum();
for (int i = 1; i < N; i += 2)
X -= 2 * A[i];
long y = X / 2;
for (int i = 0; i < N; i++) {
Console.Write(y * 2 + " ");
y = A[i] - y;
}
Console.WriteLine();
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static char NextChar() {
Confirm();
return char.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 526
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSharp {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var rainOfDums =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
var rainSum = rainOfDums.Sum();
var mountainRains = new long[n];
//
var rainTransposedSum = 0L;
var transposeCoefficient = 1;
foreach (var i in Enumerable.Range(0, n)) {
rainTransposedSum += rainOfDums[i] * transposeCoefficient;
transposeCoefficient *= -1;
}
mountainRains[0] = rainTransposedSum;
//
Console.Write(mountainRains[0]);
//
foreach (var i in Enumerable.Range(1, n - 1)) {
mountainRains[i] = 2 * rainOfDums[i - 1] - mountainRains[i - 1];
Console.Write(mountainRains[i]);
if (i < n - 1)
Console.Write(' ');
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSharp {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var rainOfDums =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
var mountainRains = new long[n];
//
long rainTransposedSum = 0;
long transposeCoefficient = 1;
foreach (var i in Enumerable.Range(0, n)) {
rainTransposedSum += rainOfDums[i] * transposeCoefficient;
transposeCoefficient *= -1;
}
mountainRains[0] = rainTransposedSum;
//
Console.Write(mountainRains[0] + " ");
//
foreach (var i in Enumerable.Range(1, n - 1)) {
mountainRains[i] = 2 * rainOfDums[i - 1] - mountainRains[i - 1];
Console.Write(mountainRains[i] + " ");
}
}
}
}
|
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["-", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104]]
| 8
| 224
| 40
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace A {
class Program {
public IEnumerable<string> Solve() {
var ut = new Util();
var sc = new Scanner();
var n = sc.Num;
var a = sc.Nums(n).Cast<long>().ToArray();
var s = a.Sum();
var s2 = 0L;
for (int i = 1; i < n; i += 2) {
s2 += a[i] * 2;
}
var res = new List<long>();
res.Add(s - s2);
for (int i = 0; i < n - 1; i++) {
res.Add(a[i] * 2 - res[i]);
}
var sb = new StringBuilder();
foreach (var x in res) {
sb.Append(x);
sb.Append(" ");
}
yield return sb.ToString();
}
}
class StartingPoint {
static void Main(string[] args) {
if (args?.Any() == true) {
var assembly = Assembly.GetEntryAssembly();
var resourceName = "AtCoderCSharp.In.txt";
var stream = assembly.GetManifestResourceStream(resourceName);
var streamReader = new StreamReader(stream, Encoding.UTF8);
var str = streamReader.ReadToEnd();
var textReader = new StringReader(str);
Console.SetIn(textReader);
}
try {
foreach (var s in new Program().Solve()) {
Console.WriteLine(s);
}
} catch (Exception e) {
Console.WriteLine(e);
if (args?.Any() != true)
throw e;
}
if (args?.Any() == true)
Console.ReadKey();
}
}
class Scanner {
public int[] Nums(int count) =>
Enumerable.Range(0, count).Select(_ => Num).ToArray();
public int Num => int.Parse(Str);
public long NumLong => long.Parse(Str);
public double NumDouble => (double)NumLong;
StringBuilder sb = new StringBuilder();
public string Str => GetStr();
public string GetStr() {
sb.Clear();
int r = 0;
bool? b = null;
do {
r = Console.Read();
b = IsBreak(r);
} while (b == true);
if (b == null)
throw new Exception("input error: unexpected end of stream");
do {
sb.Append((char)r);
r = Console.Read();
b = IsBreak(r);
} while (b == false);
return sb.ToString();
}
bool? IsBreak(int c) {
switch (c) {
case -1:
return null;
case (int)' ':
case (int)'\n':
case (int)'\r':
return true;
default:
return false;
}
}
}
class Util {
public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count);
public IEnumerable<int> Loop(int from,
int to) => Enumerable.Range(from, to - from + 1);
public string YesNo(bool isYes) => isYes ? "Yes" : "No";
public int Gcm(int a, int b) {
if (a < b)
return GcmImpl(b, a);
else
return GcmImpl(a, b);
}
int GcmImpl(int a, int b) {
var remainder = a % b;
if (remainder == 0)
return b;
else
return GcmImpl(b, remainder);
}
public int Lcm(int a, int b) { return a / Gcm(a, b) * b; }
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace A {
class Program {
public IEnumerable<string> Solve() {
var ut = new Util();
var sc = new Scanner();
var n = sc.Num;
var a = sc.Nums(n).Select(x => (long)x).ToArray();
var s = a.Sum();
var s2 = 0L;
for (int i = 1; i < n; i += 2) {
s2 += a[i] * 2;
}
var res = new List<long>();
res.Add(s - s2);
for (int i = 0; i < n - 1; i++) {
res.Add(a[i] * 2 - res[i]);
}
var sb = new StringBuilder();
foreach (var x in res) {
sb.Append(x);
sb.Append(" ");
}
yield return sb.ToString();
}
}
class StartingPoint {
static void Main(string[] args) {
if (args?.Any() == true) {
var assembly = Assembly.GetEntryAssembly();
var resourceName = "AtCoderCSharp.In.txt";
var stream = assembly.GetManifestResourceStream(resourceName);
var streamReader = new StreamReader(stream, Encoding.UTF8);
var str = streamReader.ReadToEnd();
var textReader = new StringReader(str);
Console.SetIn(textReader);
}
try {
foreach (var s in new Program().Solve()) {
Console.WriteLine(s);
}
} catch (Exception e) {
Console.WriteLine(e);
if (args?.Any() != true)
throw e;
}
if (args?.Any() == true)
Console.ReadKey();
}
}
class Scanner {
public int[] Nums(int count) =>
Enumerable.Range(0, count).Select(_ => Num).ToArray();
public int Num => int.Parse(Str);
public long NumLong => long.Parse(Str);
public double NumDouble => (double)NumLong;
StringBuilder sb = new StringBuilder();
public string Str => GetStr();
public string GetStr() {
sb.Clear();
int r = 0;
bool? b = null;
do {
r = Console.Read();
b = IsBreak(r);
} while (b == true);
if (b == null)
throw new Exception("input error: unexpected end of stream");
do {
sb.Append((char)r);
r = Console.Read();
b = IsBreak(r);
} while (b == false);
return sb.ToString();
}
bool? IsBreak(int c) {
switch (c) {
case -1:
return null;
case (int)' ':
case (int)'\n':
case (int)'\r':
return true;
default:
return false;
}
}
}
class Util {
public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count);
public IEnumerable<int> Loop(int from,
int to) => Enumerable.Range(from, to - from + 1);
public string YesNo(bool isYes) => isYes ? "Yes" : "No";
public int Gcm(int a, int b) {
if (a < b)
return GcmImpl(b, a);
else
return GcmImpl(a, b);
}
int GcmImpl(int a, int b) {
var remainder = a % b;
if (remainder == 0)
return b;
else
return GcmImpl(b, remainder);
}
public int Lcm(int a, int b) { return a / Gcm(a, b) * b; }
}
}
|
[["-", 63, 214, 205, 213, 63, 214, 141, 236, 141, 22], ["-", 205, 213, 63, 214, 141, 236, 237, 238, 0, 18], ["-", 205, 213, 63, 214, 141, 236, 237, 238, 0, 199], ["-", 205, 213, 63, 214, 141, 236, 237, 238, 0, 47], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 25], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 51, 22]]
| 8
| 796
| 11
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AtCoder {
partial class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new AtCoder().Solve();
Console.Out.Flush();
Console.Read();
}
}
public partial class AtCoder {
long mod = 1000000007;
void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
//ここから
Dictionary<long, List<long>> G;
int[] seen;
long[] color;
long K;
public void Solve() {
int N;
Multi(out N, out K);
G = GetUnweightedAdjacencyList(N, N - 1, false, false);
var start = G.First(g => g.Value.Count == 1).Key;
seen = Enumerable.Repeat(0, N).ToArray();
color = Enumerable.Repeat(-1L, N).ToArray();
color[start] = K;
var ans = DFS(start);
Console.WriteLine(ans);
}
public long DFS(long now) {
long score = 1;
foreach (var next in G[now]) {
if (color[next] != -1)
continue;
color[next] = Math.Max(K - 1 - seen[now], 0);
seen[now]++;
seen[next] = 1;
score = score * DFS(next) % mod;
;
}
return score * color[now] % mod;
}
}
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class AtCoder {
public string GetStr() { return Console.ReadLine().Trim(); }
public char GetChar() { return Console.ReadLine().Trim()[0]; }
public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
Dictionary<long, List<long>>
GetUnweightedAdjacencyList(int N, int M, bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<long, List<long>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<long>());
}
for (int i = 0; i < M; i++) {
var input = GetLongArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
dic[a].Add(b);
if (isDirected == false)
dic[b].Add(a);
}
return dic;
}
Dictionary<long, List<Tuple<long, long>>>
GetWeightedAdjacencyList(int N, int M, bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<long, List<Tuple<long, long>>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<Tuple<long, long>>());
}
for (int i = 0; i < M; i++) {
var input = GetLongArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
var c = input[2];
dic[a].Add(new Tuple<long, long>(b, c));
if (isDirected == false)
dic[b].Add(new Tuple<long, long>(a, c));
}
return dic;
}
public void WriteObjects<T>(IReadOnlyCollection<T> values) {
var array = values.ToArray();
var num = array.Length;
if (num == 0)
return;
Console.Write(array[0]);
for (int i = 1; i < num; i++) {
Console.Write(" " + array[i]);
}
Console.WriteLine();
}
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
void Multi<T>(out T a) => a = cv<T>(GetStr());
void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e,
out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AtCoder {
partial class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new AtCoder().Solve();
Console.Out.Flush();
Console.Read();
}
}
public partial class AtCoder {
long mod = 1000000007;
void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
//ここから
Dictionary<long, List<long>> G;
int[] seen;
long[] color;
long K;
public void Solve() {
int N;
Multi(out N, out K);
if (N == 1) {
Console.WriteLine(K);
return;
}
G = GetUnweightedAdjacencyList(N, N - 1, false, false);
var start = G.First(g => g.Value.Count == 1).Key;
seen = Enumerable.Repeat(0, N).ToArray();
color = Enumerable.Repeat(-1L, N).ToArray();
color[start] = K;
var ans = DFS(start);
Console.WriteLine(ans);
}
public long DFS(long now) {
long score = 1;
foreach (var next in G[now]) {
if (color[next] != -1)
continue;
color[next] = Math.Max(K - 1 - seen[now], 0);
seen[now]++;
seen[next] = 1;
score = score * DFS(next) % mod;
;
}
return score * color[now] % mod;
}
}
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class AtCoder {
public string GetStr() { return Console.ReadLine().Trim(); }
public char GetChar() { return Console.ReadLine().Trim()[0]; }
public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
Dictionary<long, List<long>>
GetUnweightedAdjacencyList(int N, int M, bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<long, List<long>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<long>());
}
for (int i = 0; i < M; i++) {
var input = GetLongArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
dic[a].Add(b);
if (isDirected == false)
dic[b].Add(a);
}
return dic;
}
Dictionary<long, List<Tuple<long, long>>>
GetWeightedAdjacencyList(int N, int M, bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<long, List<Tuple<long, long>>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<Tuple<long, long>>());
}
for (int i = 0; i < M; i++) {
var input = GetLongArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
var c = input[2];
dic[a].Add(new Tuple<long, long>(b, c));
if (isDirected == false)
dic[b].Add(new Tuple<long, long>(a, c));
}
return dic;
}
public void WriteObjects<T>(IReadOnlyCollection<T> values) {
var array = values.ToArray();
var num = array.Length;
if (num == 0)
return;
Console.Write(array[0]);
for (int i = 1; i < num; i++) {
Console.Write(" " + array[i]);
}
Console.WriteLine();
}
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
void Multi<T>(out T a) => a = cv<T>(GetStr());
void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e,
out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,030
| 17
|
using AtCoderBeginnerContest133.Questions;
using AtCoderBeginnerContest133.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoderBeginnerContest133.Questions {
public class QuestionE : AtCoderQuestionBase {
int n;
int k;
List<int>[] edges;
public override IEnumerable<object> Solve(TextReader inputStream) {
var nk = inputStream.ReadIntArray();
n = nk[0];
k = nk[1];
edges = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
for (int i = 0; i < n - 1; i++) {
var ab = inputStream.ReadIntArray();
var a = ab[0] - 1;
var b = ab[1] - 1;
edges[a].Add(b);
edges[b].Add(a);
}
yield return (new Modular(k) * GetPaintVariation(0, null)).Value;
}
private Modular GetPaintVariation(int current, int? parent) {
var availableColor = parent.HasValue ? k - 2 : k - 1;
var childrenCount = edges[current].Count + (parent.HasValue ? -1 : 0);
if (childrenCount > availableColor) {
return new Modular(0);
}
// 使用可能な色の中から子の個数だけ選んで塗る
var variation = Modular.Permutation(availableColor, childrenCount);
foreach (var child in edges[current]) {
if (parent.HasValue && child == parent.Value) {
continue;
}
variation *= GetPaintVariation(child, current);
}
return variation;
}
}
[System.Runtime.InteropServices.StructLayout(
System.Runtime.InteropServices.LayoutKind.Auto)]
public struct Modular : IEquatable<Modular>, IComparable<Modular> {
private const int _defaultMod = 1000000007;
private readonly long _value; // 0 <= value < Mod の値をとる
public int Mod { get; }
public int Value => (int)_value;
public Modular(long value, int mod = _defaultMod) {
if (mod < 2) {
throw new ArgumentOutOfRangeException(
nameof(mod), $"{nameof(mod)}は2以上の素数でなければなりません。");
}
Mod = mod;
if (value >= 0 && value < mod) {
_value = value;
} else {
_value = value % mod;
if (Value < 0) {
_value += mod;
}
}
}
private static void CheckModEquals(Modular a, Modular b) {
if (a.Mod != b.Mod) {
throw new ArgumentException(
$"{nameof(a)}, {nameof(b)}",
$"両者の法({nameof(Mod)})は等しくなければなりません。");
}
}
public static Modular operator +(Modular a, Modular b) {
CheckModEquals(a, b);
var result = a._value + b._value;
if (result > a.Mod) {
result -= a.Mod; // 剰余演算を避ける
}
return new Modular(result, a.Mod);
}
public static Modular operator -(Modular a, Modular b) {
CheckModEquals(a, b);
var result = a._value - b._value;
if (result < 0) {
result += a.Mod; // 剰余演算を避ける
}
return new Modular(result, a.Mod);
}
public static Modular operator *(Modular a, Modular b) {
CheckModEquals(a, b);
return new Modular(a._value * b._value, a.Mod);
}
public static Modular
operator /(Modular a, Modular b) // こいつは値渡しの方が速いっぽい
{
CheckModEquals(a, b);
return a * Pow(b, a.Mod - 2);
}
// 需要は不明だけど一応
public static bool operator ==(Modular left,
Modular right) => left.Equals(right);
public static bool operator !=(Modular left,
Modular right) => !(left == right);
public static bool operator<(Modular left,
Modular right) => left.CompareTo(right) < 0;
public static bool operator <=(Modular left,
Modular right) => left.CompareTo(right) <= 0;
public static bool operator>(Modular left,
Modular right) => left.CompareTo(right) > 0;
public static bool operator >=(Modular left,
Modular right) => left.CompareTo(right) >= 0;
public static explicit operator int(Modular a) => a.Value;
public static explicit operator long(Modular a) => a._value;
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return new Modular(1, a.Mod);
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
private static Dictionary<int, List<int>> FactorialCache {
get;
} = new Dictionary<int, List<int>>();
private static Dictionary<int, List<int>> PermutationCache {
get;
} = new Dictionary<int, List<int>>();
public static Modular Factorial(int n, int mod = _defaultMod) {
if (n < 0) {
throw new ArgumentOutOfRangeException(
nameof(n), $"{nameof(n)}は0以上の整数でなければなりません。");
}
if (mod < 2) {
throw new ArgumentOutOfRangeException(
nameof(mod), $"{nameof(mod)}は2以上の素数でなければなりません。");
}
if (!FactorialCache.ContainsKey(mod)) {
FactorialCache.Add(mod, new List<int>() { 1 });
}
var cache = FactorialCache[mod];
for (int i = cache.Count; i <= n;
i++) // Countが1(0!までキャッシュ済み)のとき1!~n!まで計算
{
cache.Add((int)((long)cache[i - 1] * i % mod));
}
return new Modular(cache[n], mod);
}
public static Modular Permutation(int n, int r, int mod = _defaultMod) {
CheckNR(n, r);
if (!PermutationCache.ContainsKey(mod ^ n)) {
PermutationCache.Add(mod ^ n, new List<int>() { 1 });
}
var cache = PermutationCache[mod ^ n];
for (int i = cache.Count; i <= r;
i++) // Countが1(nP0までキャッシュ済み)のときnP1~nPrまで計算
{
cache.Add((int)((long)cache[i - 1] * (n - (i - 1)) % mod));
}
return new Modular(cache[r], mod);
}
public static Modular Combination(int n, int r, int mod = _defaultMod) {
CheckNR(n, r);
r = Math.Min(r, n - r);
return n == r ? new Modular(1, mod)
: Permutation(n, r, mod) /
Factorial(r, mod); // nCr = n! / (n-r)!r! = nPr / n!
}
private static void CheckNR(int n, int r) {
if (n <= 0) {
throw new ArgumentOutOfRangeException(
nameof(n), $"{nameof(n)}は正の整数でなければなりません。");
}
if (r < 0) {
throw new ArgumentOutOfRangeException(
nameof(r), $"{nameof(r)}は0以上の整数でなければなりません。");
}
if (n < r) {
throw new ArgumentOutOfRangeException(
$"{nameof(n)},{nameof(r)}",
$"{nameof(r)}は{nameof(n)}以下でなければなりません。");
}
}
public override string ToString() => $"{_value} (mod {Mod})";
public bool Equals(Modular other) => _value == other._value
&& Mod == other.Mod;
public int CompareTo(Modular other) => Mod == other.Mod
? _value.CompareTo(other._value)
: 0;
public override int GetHashCode() => Value ^ Mod;
}
}
namespace AtCoderBeginnerContest133 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace AtCoderBeginnerContest133.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace AtCoderBeginnerContest133.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
using AtCoderBeginnerContest133.Questions;
using AtCoderBeginnerContest133.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoderBeginnerContest133.Questions {
public class QuestionE : AtCoderQuestionBase {
int n;
int k;
List<int>[] edges;
public override IEnumerable<object> Solve(TextReader inputStream) {
var nk = inputStream.ReadIntArray();
n = nk[0];
k = nk[1];
edges = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
for (int i = 0; i < n - 1; i++) {
var ab = inputStream.ReadIntArray();
var a = ab[0] - 1;
var b = ab[1] - 1;
edges[a].Add(b);
edges[b].Add(a);
}
yield return (new Modular(k) * GetPaintVariation(0, null)).Value;
}
private Modular GetPaintVariation(int current, int? parent) {
var availableColor = parent.HasValue ? k - 2 : k - 1;
var childrenCount = edges[current].Count + (parent.HasValue ? -1 : 0);
if (childrenCount > availableColor) {
return new Modular(0);
} else if (availableColor == 0) {
return new Modular(1);
}
// 使用可能な色の中から子の個数だけ選んで塗る
var variation = Modular.Permutation(availableColor, childrenCount);
foreach (var child in edges[current]) {
if (parent.HasValue && child == parent.Value) {
continue;
}
variation *= GetPaintVariation(child, current);
}
return variation;
}
}
[System.Runtime.InteropServices.StructLayout(
System.Runtime.InteropServices.LayoutKind.Auto)]
public struct Modular : IEquatable<Modular>, IComparable<Modular> {
private const int _defaultMod = 1000000007;
private readonly long _value; // 0 <= value < Mod の値をとる
public int Mod { get; }
public int Value => (int)_value;
public Modular(long value, int mod = _defaultMod) {
if (mod < 2) {
throw new ArgumentOutOfRangeException(
nameof(mod), $"{nameof(mod)}は2以上の素数でなければなりません。");
}
Mod = mod;
if (value >= 0 && value < mod) {
_value = value;
} else {
_value = value % mod;
if (Value < 0) {
_value += mod;
}
}
}
private static void CheckModEquals(Modular a, Modular b) {
if (a.Mod != b.Mod) {
throw new ArgumentException(
$"{nameof(a)}, {nameof(b)}",
$"両者の法({nameof(Mod)})は等しくなければなりません。");
}
}
public static Modular operator +(Modular a, Modular b) {
CheckModEquals(a, b);
var result = a._value + b._value;
if (result > a.Mod) {
result -= a.Mod; // 剰余演算を避ける
}
return new Modular(result, a.Mod);
}
public static Modular operator -(Modular a, Modular b) {
CheckModEquals(a, b);
var result = a._value - b._value;
if (result < 0) {
result += a.Mod; // 剰余演算を避ける
}
return new Modular(result, a.Mod);
}
public static Modular operator *(Modular a, Modular b) {
CheckModEquals(a, b);
return new Modular(a._value * b._value, a.Mod);
}
public static Modular
operator /(Modular a, Modular b) // こいつは値渡しの方が速いっぽい
{
CheckModEquals(a, b);
return a * Pow(b, a.Mod - 2);
}
// 需要は不明だけど一応
public static bool operator ==(Modular left,
Modular right) => left.Equals(right);
public static bool operator !=(Modular left,
Modular right) => !(left == right);
public static bool operator<(Modular left,
Modular right) => left.CompareTo(right) < 0;
public static bool operator <=(Modular left,
Modular right) => left.CompareTo(right) <= 0;
public static bool operator>(Modular left,
Modular right) => left.CompareTo(right) > 0;
public static bool operator >=(Modular left,
Modular right) => left.CompareTo(right) >= 0;
public static explicit operator int(Modular a) => a.Value;
public static explicit operator long(Modular a) => a._value;
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return new Modular(1, a.Mod);
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
private static Dictionary<int, List<int>> FactorialCache {
get;
} = new Dictionary<int, List<int>>();
private static Dictionary<int, List<int>> PermutationCache {
get;
} = new Dictionary<int, List<int>>();
public static Modular Factorial(int n, int mod = _defaultMod) {
if (n < 0) {
throw new ArgumentOutOfRangeException(
nameof(n), $"{nameof(n)}は0以上の整数でなければなりません。");
}
if (mod < 2) {
throw new ArgumentOutOfRangeException(
nameof(mod), $"{nameof(mod)}は2以上の素数でなければなりません。");
}
if (!FactorialCache.ContainsKey(mod)) {
FactorialCache.Add(mod, new List<int>() { 1 });
}
var cache = FactorialCache[mod];
for (int i = cache.Count; i <= n;
i++) // Countが1(0!までキャッシュ済み)のとき1!~n!まで計算
{
cache.Add((int)((long)cache[i - 1] * i % mod));
}
return new Modular(cache[n], mod);
}
public static Modular Permutation(int n, int r, int mod = _defaultMod) {
CheckNR(n, r);
if (!PermutationCache.ContainsKey(mod ^ n)) {
PermutationCache.Add(mod ^ n, new List<int>() { 1 });
}
var cache = PermutationCache[mod ^ n];
for (int i = cache.Count; i <= r;
i++) // Countが1(nP0までキャッシュ済み)のときnP1~nPrまで計算
{
cache.Add((int)((long)cache[i - 1] * (n - (i - 1)) % mod));
}
return new Modular(cache[r], mod);
}
public static Modular Combination(int n, int r, int mod = _defaultMod) {
CheckNR(n, r);
r = Math.Min(r, n - r);
return n == r ? new Modular(1, mod)
: Permutation(n, r, mod) /
Factorial(r, mod); // nCr = n! / (n-r)!r! = nPr / n!
}
private static void CheckNR(int n, int r) {
if (n <= 0) {
throw new ArgumentOutOfRangeException(
nameof(n), $"{nameof(n)}は正の整数でなければなりません。");
}
if (r < 0) {
throw new ArgumentOutOfRangeException(
nameof(r), $"{nameof(r)}は0以上の整数でなければなりません。");
}
if (n < r) {
throw new ArgumentOutOfRangeException(
$"{nameof(n)},{nameof(r)}",
$"{nameof(r)}は{nameof(n)}以下でなければなりません。");
}
}
public override string ToString() => $"{_value} (mod {Mod})";
public bool Equals(Modular other) => _value == other._value
&& Mod == other.Mod;
public int CompareTo(Modular other) => Mod == other.Mod
? _value.CompareTo(other._value)
: 0;
public override int GetHashCode() => Value ^ Mod;
}
}
namespace AtCoderBeginnerContest133 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace AtCoderBeginnerContest133.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace AtCoderBeginnerContest133.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 0, 57, 75, 57, 64, 196, 0, 37, 0, 38], ["+", 75, 57, 64, 196, 0, 37, 0, 230, 0, 228], ["+", 75, 57, 64, 196, 0, 37, 0, 230, 39, 22], ["+", 64, 196, 0, 37, 0, 230, 3, 4, 0, 24], ["+", 0, 37, 0, 230, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 37, 0, 230, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 37, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46]]
| 8
| 1,954
| 16
|
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
int n = NextInt, k = NextInt;
List<int>[] neighbors =
Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
for (int i = 0; i < n - 1; i++) {
int a = NextInt - 1, b = NextInt - 1;
neighbors[a].Add(b);
neighbors[b].Add(a);
}
bool[] arrived = new bool[n];
ModInt res = Factorial(k) / Factorial(k - 1 - neighbors[0].Count);
arrived[0] = true;
Stack<int> stack = new Stack<int>(neighbors[0]);
for (int i = 0; i < neighbors[0].Count; i++)
arrived[neighbors[0][i]] = true;
while (stack.Count > 0) {
var elem = stack.Pop();
if (k - 1 - neighbors[elem].Count < 0) {
res = 0;
break;
}
res *= Factorial(k - 2) / Factorial(k - 1 - neighbors[elem].Count);
for (int i = 0; i < neighbors[elem].Count; i++) {
if (arrived[neighbors[elem][i]])
continue;
arrived[neighbors[elem][i]] = true;
stack.Push(neighbors[elem][i]);
}
}
Console.WriteLine(res);
}
static List<ModInt> factorialMemo = new List<ModInt>() { 1 };
static ModInt Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static readonly TextReader In = Console.In;
static int NextInt {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
int res = 0;
int next = In.Read();
int rev = 1;
while (45 > next || next > 57)
next = In.Read();
if (next == 45) {
next = In.Read();
rev = -1;
}
while (48 <= next && next <= 57) {
res = res * 10 + next - 48;
next = In.Read();
}
return res * rev;
}
}
}
struct ModInt {
const int MOD = 1000000007;
const long POSITIVIZER = ((long)MOD) << 31;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, int b) => new ModInt() {
Data = (a.Data + b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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;
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
int n = NextInt, k = NextInt;
List<int>[] neighbors =
Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
for (int i = 0; i < n - 1; i++) {
int a = NextInt - 1, b = NextInt - 1;
neighbors[a].Add(b);
neighbors[b].Add(a);
}
bool[] arrived = new bool[n];
if (neighbors.Any(x => k - 1 - x.Count < 0)) {
Console.WriteLine(0);
return;
}
ModInt res = Factorial(k) / Factorial(k - 1 - neighbors[0].Count);
arrived[0] = true;
Stack<int> stack = new Stack<int>(neighbors[0]);
for (int i = 0; i < neighbors[0].Count; i++)
arrived[neighbors[0][i]] = true;
while (stack.Count > 0) {
var elem = stack.Pop();
if (k - 1 - neighbors[elem].Count < 0) {
res = 0;
break;
}
res *= Factorial(k - 2) / Factorial(k - 1 - neighbors[elem].Count);
for (int i = 0; i < neighbors[elem].Count; i++) {
if (arrived[neighbors[elem][i]])
continue;
arrived[neighbors[elem][i]] = true;
stack.Push(neighbors[elem][i]);
}
}
Console.WriteLine(res);
}
static List<ModInt> factorialMemo = new List<ModInt>() { 1 };
static ModInt Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static readonly TextReader In = Console.In;
static int NextInt {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
int res = 0;
int next = In.Read();
int rev = 1;
while (45 > next || next > 57)
next = In.Read();
if (next == 45) {
next = In.Read();
rev = -1;
}
while (48 <= next && next <= 57) {
res = res * 10 + next - 48;
next = In.Read();
}
return res * rev;
}
}
}
struct ModInt {
const int MOD = 1000000007;
const long POSITIVIZER = ((long)MOD) << 31;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, int b) => new ModInt() {
Data = (a.Data + b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 15, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 218, 8, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 218, 8, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 218, 8, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 17, 33], ["+", 0, 218, 8, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 218, 8, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 218, 8, 16, 31, 16, 12, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,215
| 30
|
using System;
using System.Collections.Generic;
#region ModInt
/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt {
/// <summary>
/// 剰余を取る値.
/// </summary>
public const long Mod = (int)1e9 + 7;
/// <summary>
/// 実際の数値.
/// </summary>
public long num;
/// <summary>
/// 値が <paramref name="n"/> であるようなインスタンスを構築します.
/// </summary>
/// <param name="n">インスタンスが持つ値</param>
/// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref
/// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/>
/// を渡してください.このコンストラクタは O(1) で実行されます.</remarks>
public ModInt(long n) { num = n; }
/// <summary>
/// このインスタンスの数値を文字列に変換します.
/// </summary>
/// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10
/// 進表記したもの.</returns>
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
/// <summary>
/// 与えられた数の逆元を計算します.
/// </summary>
/// <param name="v">逆元を取る対象となる数</param>
/// <returns>逆元となるような値</returns>
/// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を
/// O(log N) で計算します.</remarks>
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
public class Program {
private int N, K;
private List<int>[] Edges;
private ModInt[] Fact;
public void Solve() {
var sc = new Scanner();
N = sc.NextInt();
K = sc.NextInt();
Edges = new List<int>[N];
for (int i = 0; i < N; i++) {
Edges[i] = new List<int>();
}
for (int i = 0; i < N - 1; i++) {
int a = sc.NextInt() - 1;
int b = sc.NextInt() - 1;
Edges[a].Add(b);
Edges[b].Add(a);
}
Fact = new ModInt[100001];
Fact[0] = 1;
for (int i = 1; i <= 100000; i++) {
Fact[i] = Fact[i - 1] * i;
}
Console.WriteLine(Calc(0, -1) * K);
}
private ModInt P(int n, int m) {
// n P m = n! / (n-m)!
return Fact[n] * ModInt.Inverse(Fact[n - m]);
}
private ModInt Calc(int n, int parent) {
ModInt ans;
if (parent == -1) {
ans = P(K - 1, Edges[n].Count);
} else {
ans = P(K - 2, Edges[n].Count - 1);
}
if (K < Edges[n].Count)
return 0;
foreach (var i in Edges[n]) {
if (i == parent) {
continue;
}
ans *= Calc(i, n);
}
return ans;
}
public static void Main(string[] args) { new Program().Solve(); }
}
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;
#region ModInt
/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt {
/// <summary>
/// 剰余を取る値.
/// </summary>
public const long Mod = (int)1e9 + 7;
/// <summary>
/// 実際の数値.
/// </summary>
public long num;
/// <summary>
/// 値が <paramref name="n"/> であるようなインスタンスを構築します.
/// </summary>
/// <param name="n">インスタンスが持つ値</param>
/// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref
/// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/>
/// を渡してください.このコンストラクタは O(1) で実行されます.</remarks>
public ModInt(long n) { num = n; }
/// <summary>
/// このインスタンスの数値を文字列に変換します.
/// </summary>
/// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10
/// 進表記したもの.</returns>
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
/// <summary>
/// 与えられた 2 つの数値からべき剰余を計算します.
/// </summary>
/// <param name="v">べき乗の底</param>
/// <param name="k">べき指数</param>
/// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns>
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
/// <summary>
/// 与えられた数の逆元を計算します.
/// </summary>
/// <param name="v">逆元を取る対象となる数</param>
/// <returns>逆元となるような値</returns>
/// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を
/// O(log N) で計算します.</remarks>
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
public class Program {
private int N, K;
private List<int>[] Edges;
private ModInt[] Fact;
public void Solve() {
var sc = new Scanner();
N = sc.NextInt();
K = sc.NextInt();
Edges = new List<int>[N];
for (int i = 0; i < N; i++) {
Edges[i] = new List<int>();
}
for (int i = 0; i < N - 1; i++) {
int a = sc.NextInt() - 1;
int b = sc.NextInt() - 1;
Edges[a].Add(b);
Edges[b].Add(a);
}
Fact = new ModInt[100001];
Fact[0] = 1;
for (int i = 1; i <= 100000; i++) {
Fact[i] = Fact[i - 1] * i;
}
Console.WriteLine(Calc(0, -1) * K);
}
private ModInt P(int n, int m) {
// n P m = n! / (n-m)!
if (n < m)
return 0;
return Fact[n] * ModInt.Inverse(Fact[n - m]);
}
private ModInt Calc(int n, int parent) {
ModInt ans;
if (parent == -1) {
ans = P(K - 1, Edges[n].Count);
} else {
ans = P(K - 2, Edges[n].Count - 1);
}
foreach (var i in Edges[n]) {
if (i == parent) {
continue;
}
ans *= Calc(i, n);
}
return ans;
}
public static void Main(string[] args) { new Program().Solve(); }
}
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
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 57, 15, 16, 12, 214, 205, 204, 205, 22], ["-", 15, 16, 12, 214, 205, 204, 206, 207, 0, 70], ["-", 12, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 12, 214, 205, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35]]
| 8
| 1,147
| 23
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
int N = NextInt();
long K = NextLong();
List<int>[] G =
Enumerable.Range(0, N + 1).Select(v => new List<int>()).ToArray();
for (int i = 0; i < N - 1; i++) {
int a = NextInt();
int b = NextInt();
G[a].Add(b);
G[b].Add(a);
}
int[] rel = new int[N + 1];
long[] col = new long[N + 1];
Stack<int> S = new Stack<int>();
S.Push(1);
while (S.Count() != 0) {
int now = S.Pop();
int M = 0;
rel[now]++;
foreach (int e in G[now]) {
M += rel[e];
rel[e]++;
if (col[e] == 0)
S.Push(e);
}
col[now] = (K - M);
col[now] %= MOD;
}
long ans = 1;
for (int i = 1; i <= N; i++) {
ans *= col[i];
ans %= MOD;
}
Console.WriteLine(ans);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
public long Abs(long a, long b) => Math.Abs(a - b);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
int N = NextInt();
long K = NextLong();
List<int>[] G =
Enumerable.Range(0, N + 1).Select(v => new List<int>()).ToArray();
for (int i = 0; i < N - 1; i++) {
int a = NextInt();
int b = NextInt();
G[a].Add(b);
G[b].Add(a);
}
int[] rel = new int[N + 1];
long[] col = Enumerable.Range(0, N + 1).Select(v => (long)-1).ToArray();
Stack<int> S = new Stack<int>();
S.Push(1);
while (S.Count() != 0) {
int now = S.Pop();
int M = 0;
rel[now]++;
foreach (int e in G[now]) {
M += rel[e];
rel[e]++;
if (col[e] == -1)
S.Push(e);
}
col[now] = (K - M);
col[now] %= MOD;
}
long ans = 1;
for (int i = 1; i <= N; i++) {
ans *= col[i];
ans %= MOD;
}
Console.WriteLine(ans);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
public long Abs(long a, long b) => Math.Abs(a - b);
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 25], ["+", 0, 28, 0, 218, 8, 74, 51, 241, 0, 33], ["+", 0, 28, 0, 218, 8, 74, 51, 241, 0, 203], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203]]
| 8
| 714
| 29
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
int N = NextInt();
long K = NextLong();
List<int>[] G =
Enumerable.Range(0, N + 1).Select(v => new List<int>()).ToArray();
for (int i = 0; i < N - 1; i++) {
int a = NextInt(), b = NextInt();
G[a].Add(b);
G[b].Add(a);
}
int[] rel = Enumerable.Range(0, N + 1).Select(v => 0).ToArray();
long[] ans = Enumerable.Range(0, N + 1).Select(v => (long)-1).ToArray();
Stack<int> S = new Stack<int>();
S.Push(1);
while (S.Count() != 0) {
int u = S.Pop();
long cou = 0;
foreach (var e in G[u]) {
cou += rel[e];
rel[e] += 1;
}
rel[u] += 1;
ans[u] = K - cou;
foreach (var e in G[u]) {
if (ans[e] == -1)
S.Push(e);
}
Console.WriteLine(u);
}
long sum = 1;
for (int i = 1; i <= N; i++) {
sum *= ans[i];
sum %= MOD;
}
Console.WriteLine(sum);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
public struct Pair {
public int x, y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void Solve() {
int N = NextInt();
long K = NextLong();
List<int>[] G =
Enumerable.Range(0, N + 1).Select(v => new List<int>()).ToArray();
for (int i = 0; i < N - 1; i++) {
int a = NextInt(), b = NextInt();
G[a].Add(b);
G[b].Add(a);
}
int[] rel = Enumerable.Range(0, N + 1).Select(v => 0).ToArray();
long[] ans = Enumerable.Range(0, N + 1).Select(v => (long)-1).ToArray();
Stack<int> S = new Stack<int>();
S.Push(1);
while (S.Count() != 0) {
int u = S.Pop();
long cou = 0;
foreach (var e in G[u]) {
cou += rel[e];
rel[e] += 1;
}
rel[u] += 1;
ans[u] = K - cou;
foreach (var e in G[u]) {
if (ans[e] == -1)
S.Push(e);
}
// Console.WriteLine(u);
}
long sum = 1;
for (int i = 1; i <= N; i++) {
sum *= ans[i];
sum %= MOD;
}
Console.WriteLine(sum);
}
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 738
| 7
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int N = int.Parse(str[0]);
long K = long.Parse(str[1]);
int[,] A = new int[N, 2];
long mod = 1000000007;
var list = new List<int>[N];
for (var i = 0; i < N; i++) {
list[i] = new List<int>();
}
for (var i = 0; i < N - 1; i++) {
string[] str2 = Console.ReadLine().Split();
A[i, 0] = int.Parse(str2[0]);
A[i, 1] = int.Parse(str2[1]);
list[A[i, 0] - 1].Add(A[i, 1] - 1);
list[A[i, 1] - 1].Add(A[i, 0] - 1);
}
var listB = new List<int>();
int[] F = new int[N];
for (var i = 0; i < N; i++) {
if (list[i].Count == 1) {
listB.Add(i);
F[i] = 1;
}
}
int t = -1;
while (listB.Count > 0) {
var listC = new List<int>(listB);
listB.Clear();
for (var i = 0; i < listC.Count; i++) {
for (var j = 0; j < list[listC[i]].Count; j++) {
if (F[list[listC[i]][j]] == 0) {
listB.Add(list[listC[i]][j]);
F[list[listC[i]][j]] = 1;
}
}
}
if (listB.Count == 0) {
t = listC[0];
}
}
long ans = K;
int[] G = new int[N];
G[t] = 1;
var list3 = new List<int>();
list3.Add(t);
while (list3.Count > 0) {
var list4 = new List<int>(list3);
list3.Clear();
for (var i = 0; i < list4.Count; i++) {
long ct = 0;
for (var j = 0; j < list[list4[i]].Count; j++) {
if (G[list[list4[i]][j]] == 0) {
ct++;
list3.Add(list[list4[i]][j]);
G[list[list4[i]][j]] = 1;
}
}
for (var j = 0; j < ct; j++) {
if (list4[0] == t) {
ans = (ans * (K - j - 1)) % mod;
} else {
ans = (ans * (K - j - 2)) % mod;
}
}
}
}
Console.Write(ans);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int N = int.Parse(str[0]);
long K = long.Parse(str[1]);
int[,] A = new int[N, 2];
long mod = 1000000007;
var list = new List<int>[N];
for (var i = 0; i < N; i++) {
list[i] = new List<int>();
}
for (var i = 0; i < N - 1; i++) {
string[] str2 = Console.ReadLine().Split();
A[i, 0] = int.Parse(str2[0]);
A[i, 1] = int.Parse(str2[1]);
list[A[i, 0] - 1].Add(A[i, 1] - 1);
list[A[i, 1] - 1].Add(A[i, 0] - 1);
}
var listB = new List<int>();
int[] F = new int[N];
for (var i = 0; i < N; i++) {
if (list[i].Count == 1) {
listB.Add(i);
F[i] = 1;
}
}
int t = -1;
if (N == 1) {
Console.Write(K);
} else {
while (listB.Count > 0) {
var listC = new List<int>(listB);
listB.Clear();
for (var i = 0; i < listC.Count; i++) {
for (var j = 0; j < list[listC[i]].Count; j++) {
if (F[list[listC[i]][j]] == 0) {
listB.Add(list[listC[i]][j]);
F[list[listC[i]][j]] = 1;
}
}
}
if (listB.Count == 0) {
t = listC[0];
}
}
long ans = K;
int[] G = new int[N];
G[t] = 1;
var list3 = new List<int>();
list3.Add(t);
while (list3.Count > 0) {
var list4 = new List<int>(list3);
list3.Clear();
for (var i = 0; i < list4.Count; i++) {
long ct = 0;
for (var j = 0; j < list[list4[i]].Count; j++) {
if (G[list[list4[i]][j]] == 0) {
ct++;
list3.Add(list[list4[i]][j]);
G[list[list4[i]][j]] = 1;
}
}
for (var j = 0; j < ct; j++) {
if (list4[0] == t) {
ans = (ans * (K - j - 1)) % mod;
} else {
ans = (ans * (K - j - 2)) % mod;
}
}
}
}
Console.Write(ans);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 691
| 18
|
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
List<char> list = new List<char>();
for (int i = 0; i < 4; i++) {
list.Add(S[i]);
}
list.Sort();
if (list[0] == list[1] && list[2] == list[3]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
List<char> list = new List<char>();
for (int i = 0; i < 4; i++) {
list.Add(S[i]);
}
list.Sort();
if (list[0] == list[1] && list[2] == list[3] && list[0] != list[3]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 147
| 10
|
using System;
namespace ABC_132_A_Csharp_ver {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
char a = S[0];
char b = S[1];
char c = S[2];
char d = S[3];
if (a == b && c == d || a == c && b == d || a == d && b == c)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
}
|
using System;
namespace ABC_132_A_Csharp_ver {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
char a = S[0];
char b = S[1];
char c = S[2];
char d = S[3];
if (a == b && c == d && a != c || a == c && b == d && a != b ||
a == d && b == c && a != b)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 79], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 98], ["+", 15, 16, 31, 16, 12, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 16, 12, 16, 17, 79], ["+", 15, 16, 31, 16, 12, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 22]]
| 8
| 108
| 12
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
class DandA {
static void Main(string[] args) {
string s = ReadLineStr();
if (CountChar(s, s.Substring(0, 1)) == CountChar(s, s.Substring(1, 1)) &&
CountChar(s, s.Substring(1, 1)) == CountChar(s, s.Substring(2, 1)) &&
CountChar(s, s.Substring(2, 1)) == CountChar(s, s.Substring(3, 1))) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
static private int CountChar(string s, string c) {
return s.Length - s.Replace(c, "").Length;
}
static string alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
static string[] strAry = new string[] { "L", "R", "U", "D" };
static int[] intArray = new int[10];
static List<int> intList = new List<int>();
static Dictionary<string, int> myTable = new Dictionary<string, int>();
static HashSet<int>[] rtnArrAb = null;
static HashSet<int>[] rtnArrCd = null;
static long[,] C = new long[2001, 2001];
static long div = 1000000007;
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private long ReadLineLong() { return long.Parse(Console.ReadLine()); }
static private double ReadLineDouble() {
return double.Parse(Console.ReadLine());
}
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private double[] ReadLineDoubleArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => double.Parse(a))
.ToArray();
}
static private decimal[] ReadLineDecimalArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => decimal.Parse(a))
.ToArray();
}
static private List<int> ReadLineIntList() {
return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList();
}
static private List<long> ReadLineLongList() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToList();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
static private string IntToNString(int x, int n) {
var nstring = "";
var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f" };
int r = 1;
int q = x;
while (q > 0) {
r = q % n;
nstring += numbers[r];
q = q / n;
}
return string.Join("", nstring.Reverse());
}
static private long Gcd(long m, long n) {
long temp;
while (m % n != 0) {
temp = n;
n = m % n;
m = temp;
}
return n;
}
static private long Combination(long n, long r) {
if (n < r) {
return 0;
}
if (n == r || r == 0) {
return 1;
} else if (C[n, r] == 0) {
C[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div;
}
return C[n, r];
}
}
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
class DandA {
static void Main(string[] args) {
string s = ReadLineStr();
if (CountChar(s, s.Substring(0, 1)) == 2 &&
CountChar(s, s.Substring(1, 1)) == 2 &&
CountChar(s, s.Substring(2, 1)) == 2 &&
CountChar(s, s.Substring(3, 1)) == 2) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
static private int CountChar(string s, string c) {
return s.Length - s.Replace(c, "").Length;
}
static string alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
static string[] strAry = new string[] { "L", "R", "U", "D" };
static int[] intArray = new int[10];
static List<int> intList = new List<int>();
static Dictionary<string, int> myTable = new Dictionary<string, int>();
static HashSet<int>[] rtnArrAb = null;
static HashSet<int>[] rtnArrCd = null;
static long[,] C = new long[2001, 2001];
static long div = 1000000007;
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private long ReadLineLong() { return long.Parse(Console.ReadLine()); }
static private double ReadLineDouble() {
return double.Parse(Console.ReadLine());
}
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private double[] ReadLineDoubleArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => double.Parse(a))
.ToArray();
}
static private decimal[] ReadLineDecimalArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => decimal.Parse(a))
.ToArray();
}
static private List<int> ReadLineIntList() {
return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList();
}
static private List<long> ReadLineLongList() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToList();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
static private string IntToNString(int x, int n) {
var nstring = "";
var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f" };
int r = 1;
int q = x;
while (q > 0) {
r = q % n;
nstring += numbers[r];
q = q / n;
}
return string.Join("", nstring.Reverse());
}
static private long Gcd(long m, long n) {
long temp;
while (m % n != 0) {
temp = n;
n = m % n;
m = temp;
}
return n;
}
static private long Combination(long n, long r) {
if (n < r) {
return 0;
}
if (n == r || r == 0) {
return 1;
} else if (C[n, r] == 0) {
C[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div;
}
return C[n, r];
}
}
|
[["-", 15, 16, 31, 16, 31, 16, 12, 213, 63, 22], ["-", 31, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["-", 31, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 31, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 31, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["-", 15, 16, 31, 16, 12, 16, 12, 213, 63, 22], ["-", 31, 16, 12, 16, 12, 213, 3, 4, 0, 24], ["-", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 31, 16, 12, 16, 12, 213, 3, 4, 0, 21], ["-", 31, 16, 12, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 1,111
| 30
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
const string Yes = "Yes";
const string No = "No";
const long Mod = 1000000007;
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// MyDebugger.Test(process, "../TextFile2.txt");
// MyDebugger.MakeTestCase("../TextFile2.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var s = input.ReadLine();
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
return Yes;
if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
return Yes;
return No;
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
const string Yes = "Yes";
const string No = "No";
const long Mod = 1000000007;
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// MyDebugger.Test(process, "../TextFile2.txt");
// MyDebugger.MakeTestCase("../TextFile2.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var s = input.ReadLine();
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
return Yes;
if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1])
return Yes;
if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1])
return Yes;
return No;
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 16, 31, 204, 205, 22], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["+", 31, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 12, 16, 31, 204, 205, 22], ["+", 31, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 15, 16, 31, 16, 12, 16, 12, 204, 205, 22], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38]]
| 8
| 201
| 35
|
using System;
namespace AtCoder_ABC_B {
class Program {
static void Main(string[] args) {
Boolean ans = false;
String inputLine = Console.ReadLine();
if (inputLine[0] == inputLine[1] && inputLine[2] == inputLine[3]) {
ans = true;
} else if (inputLine[0] == inputLine[2] && inputLine[1] == inputLine[3]) {
ans = true;
} else if (inputLine[0] == inputLine[3] && inputLine[1] == inputLine[2]) {
ans = true;
}
if (ans == true) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
namespace AtCoder_ABC_B {
class Program {
static void Main(string[] args) {
Boolean ans = false;
String inputLine = Console.ReadLine();
if (inputLine[0] == inputLine[1] && inputLine[2] == inputLine[3] &&
inputLine[0] != inputLine[2]) {
ans = true;
} else if (inputLine[0] == inputLine[2] && inputLine[1] == inputLine[3] &&
inputLine[0] != inputLine[3]) {
ans = true;
} else if (inputLine[0] == inputLine[3] && inputLine[1] == inputLine[2] &&
inputLine[0] != inputLine[1]) {
ans = true;
}
if (ans == true) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 12, 16, 12, 204, 205, 22], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 17, 79], ["+", 75, 57, 15, 16, 12, 16, 12, 204, 205, 22]]
| 8
| 151
| 30
|
using System;
class a {
public static void Main() {
string s = Console.ReadLine();
if (s[0] == s[1]) {
if (s[2] == s[3]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else if (s[0] == s[2]) {
if (s[1] == s[3]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else if (s[0] == s[3]) {
if (s[1] == s[2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
Console.WriteLine("No");
}
}
}
|
using System;
class a {
public static void Main() {
string s = Console.ReadLine();
if (s[0] == s[1]) {
if (s[2] == s[3] && s[0] != s[2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else if (s[0] == s[2]) {
if (s[1] == s[3] && s[0] != s[1]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else if (s[0] == s[3]) {
if (s[1] == s[2] && s[0] != s[1]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
Console.WriteLine("No");
}
}
}
|
[["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 185
| 30
|
using System;
using System.Linq;
namespace ABC132 {
class A {
static void Main(string[] args) {
string s = Console.ReadLine();
foreach (var c in s) {
int count = s.Where(x => x == c).Count();
if ((count % 2) != 0) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Linq;
namespace ABC132 {
class A {
static void Main(string[] args) {
string s = Console.ReadLine();
foreach (var c in s) {
int count = s.Where(x => x == c).Count();
if ((count % 2) != 0 || (count / 2) == 2) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
[["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 85], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25]]
| 8
| 95
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC132 {
class Program {
static void Main(string[] args) {
string Str = Console.ReadLine().Trim();
var barray = Encoding.ASCII.GetBytes(Str);
bool isOK = false;
if ((barray[0] == barray[1]) && (barray[2] == barray[3])) {
isOK = true;
} else if ((barray[0] == barray[2]) && (barray[1] == barray[3])) {
isOK = true;
} else if ((barray[0] == barray[3]) && (barray[1] == barray[2])) {
isOK = true;
}
if (isOK) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC132 {
class Program {
static void Main(string[] args) {
string Str = Console.ReadLine().Trim();
var barray = Encoding.ASCII.GetBytes(Str);
bool isOK = false;
// AABB ABAB ABBA
if ((barray[0] == barray[1]) && (barray[2] == barray[3])) {
isOK = true;
} else if ((barray[0] == barray[2]) && (barray[1] == barray[3])) {
isOK = true;
} else if ((barray[0] == barray[3]) && (barray[1] == barray[2])) {
isOK = true;
}
if ((barray[0] == barray[1]) && (barray[0] == barray[2])) {
isOK = false;
}
if (isOK) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 60], ["+", 15, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22]]
| 8
| 201
| 32
|
using System;
namespace abc132 {
class Program {
static void Main(string[] args) {
/* A */
var input = Console.ReadLine().Split(' ');
var c = input[0].ToCharArray();
if ((c[0] == c[1] && c[2] == c[3]) || (c[0] == c[2] && c[1] == c[3]) ||
(c[0] == c[3] && c[1] == c[2]))
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
}
|
using System;
namespace abc132 {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var c = input[0].ToCharArray();
if (((c[0] == c[1] && c[2] == c[3]) || (c[0] == c[2] && c[1] == c[3]) ||
(c[0] == c[3] && c[1] == c[2])) &&
!(c[0] == c[1] && c[0] == c[2]))
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
}
|
[["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 12, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 111], ["+", 0, 57, 15, 16, 12, 241, 0, 23, 0, 24], ["+", 0, 23, 0, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 241, 0, 23, 0, 16, 31, 16, 17, 60], ["+", 0, 23, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 241, 0, 23, 0, 16, 17, 98], ["+", 0, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 138
| 25
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using static System.Math;
class Program {
static void Main() {
char[] s = Console.ReadLine().ToCharArray();
Array.Sort(s);
bool f = s[0] == s[1] && s[2] == s[3];
Console.WriteLine(f ? "Yes" : "No");
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using static System.Math;
class Program {
static void Main() {
char[] s = Console.ReadLine().ToCharArray();
Array.Sort(s);
bool f = s[0] == s[1] && s[2] == s[3] && s[1] != s[2];
Console.WriteLine(f ? "Yes" : "No");
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 98], ["+", 0, 212, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 79], ["+", 0, 212, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 102
| 10
|
using System;
class Program {
static void Main(string[] args) {
char a, b, c, d;
string str = Console.ReadLine(); // 2つ以上のスペース区切り入力の取得
a = str[0]; //数値で受け取りたい場合は変換する
b = str[1];
c = str[2];
d = str[3];
if ((a == b && c == d) || (a == c && b == d) || (a == d && b == c)) {
Console.Write("Yes");
} else {
Console.Write("No");
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
char a, b, c, d;
string str = Console.ReadLine(); // 2つ以上のスペース区切り入力の取得
a = str[0]; //数値で受け取りたい場合は変換する
b = str[1];
c = str[2];
d = str[3];
if ((a == b && a != c && c == d) || (a == c && a != b && b == d) ||
(a == d && a != b && b == c)) {
Console.Write("Yes");
} else {
Console.Write("No");
}
string str2 = Console.ReadLine();
}
}
|
[["+", 31, 23, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 17, 79], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 98], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 17, 98], ["+", 12, 23, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 12, 23, 0, 16, 31, 16, 12, 16, 17, 79], ["+", 12, 23, 0, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
| 8
| 121
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC132A {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
char[] A = new char[4];
A[0] = S[0];
A[1] = S[1];
A[2] = S[2];
A[3] = S[3];
string ans = "No";
if (A[0] == A[1] && A[2] == A[3]) {
ans = "Yes";
}
if (A[0] == A[2] && A[1] == A[3]) {
ans = "Yes";
}
if (A[0] == A[3] && A[1] == A[2]) {
ans = "Yes";
}
Console.WriteLine(ans);
//入力例
// ASSA
// STOP
// FFEE
// FREE
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC132A {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
char[] A = new char[4];
A[0] = S[0];
A[1] = S[1];
A[2] = S[2];
A[3] = S[3];
string ans = "No";
if (A[0] == A[1] && A[2] == A[3] && A[0] != A[2]) {
ans = "Yes";
}
if (A[0] == A[2] && A[1] == A[3] && A[0] != A[1]) {
ans = "Yes";
}
if (A[0] == A[3] && A[1] == A[2] && A[0] != A[1]) {
ans = "Yes";
}
Console.WriteLine(ans);
//入力例
// ASSA
// STOP
// FFEE
// FREE
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 215
| 30
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCorder {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var s = cin.Read;
if ((s[1] == s[2] && s[0] == s[3]) || (s[0] == s[2] && s[1] == s[3]) ||
(s[0] == s[1] && s[2] == s[3])) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCorder {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var s = cin.Read;
if ((s[1] == s[2] && s[0] == s[3] && s[1] != s[0]) ||
(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ||
(s[0] == s[1] && s[2] == s[3] && s[0] != s[2])) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 98], ["+", 31, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 17, 79], ["+", 31, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 98], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 17, 79], ["+", 12, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 79]]
| 8
| 516
| 30
|
using System;
namespace Atcoder0629 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
for (int i = 1; i < 4; i++) {
if (S[0] == S[i]) {
S = S.Remove(i, 1);
S = S.Remove(0, 1);
break;
}
}
if (S[0] == S[1]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
return;
}
}
}
|
using System;
namespace Atcoder0629 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
char c = S[0];
for (int i = 1; i < 4; i++) {
if (S[0] == S[i]) {
S = S.Remove(i, 1);
S = S.Remove(0, 1);
break;
}
}
if (S[0] == S[1] && S[0] != c) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
Console.ReadLine();
return;
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 122
| 21
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
char[] S = cin.Read.ToCharArray();
var ans = false;
if (S[0] == S[1]) {
if (S[2] == S[3] && S[1] != S[2])
ans = true;
} else {
if (S[2] == S[3])
ans = true;
}
if (ans)
WriteLine("Yes");
else
WriteLine("No");
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; i++)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
char[] S = cin.Read.ToCharArray();
var ans = false;
if (S[0] == S[1]) {
if (S[2] == S[3] && S[1] != S[2])
ans = true;
} else {
if (S[1] == S[3] && S[0] == S[2])
ans = true;
if (S[1] == S[2] && S[0] == S[3])
ans = true;
}
if (ans)
WriteLine("Yes");
else
WriteLine("No");
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; i++)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 75, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 211, 0, 146], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70]]
| 8
| 520
| 36
|
using System;
public class Test {
public static void Main() {
// your code goes here
string s = Console.ReadLine();
string s1 = s.Substring(0, 1);
string s2 = s.Substring(1, 1);
string s3 = s.Substring(2, 1);
string s4 = s.Substring(3, 1);
if (s1 == s2) {
if (s3 == s4) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else if (s1 == s3) {
if (s2 == s4) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else if (s1 == s4) {
if (s2 == s3) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
Console.WriteLine("No");
}
}
}
|
using System;
public class Test {
public static void Main() {
// your code goes here
string s = Console.ReadLine();
string s1 = s.Substring(0, 1);
string s2 = s.Substring(1, 1);
string s3 = s.Substring(2, 1);
string s4 = s.Substring(3, 1);
if (s1 == s2) {
if (s3 == s4) {
if (s1 == s3) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
}
} else {
Console.WriteLine("No");
}
} else if (s1 == s3) {
if (s2 == s4) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else if (s1 == s4) {
if (s2 == s3) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
Console.WriteLine("No");
}
}
}
|
[["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 199
| 20
|
using System;
using System.IO;
using System.Collections.Generic;
namespace _132 {
class Program {
static void Main(string[] args) { solve_132A(); }
public static void solve_132A() {
string a = Console.ReadLine();
char[] str = a.ToCharArray();
Array.Sort(str);
string ansewr = "Yes";
if (str[0] != str[1] || str[2] != str[3]) {
ansewr = "No";
}
Console.WriteLine(ansewr);
}
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
namespace _132 {
class Program {
static void Main(string[] args) { solve_132A(); }
public static void solve_132A() {
string a = Console.ReadLine();
char[] str = a.ToCharArray();
Array.Sort(str);
string ansewr = "Yes";
if (str[0] != str[1] || str[2] != str[3] || str[0] == str[2]) {
ansewr = "No";
}
Console.WriteLine(ansewr);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 117
| 10
|
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) {
string s = ReadLine();
if (s[0] == s[1] && s[2] == s[3]) {
WriteLine("Yes");
} else if (s[0] == s[2] && s[1] == s[3]) {
WriteLine("Yes");
} else if (s[0] == s[3] && s[1] == s[2]) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
}
}
|
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) {
string s = ReadLine();
if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
WriteLine("Yes");
} else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) {
WriteLine("Yes");
} else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 79], ["+", 75, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 17, 79]]
| 8
| 163
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
//入力
string S = Console.ReadLine();
//検証
//出現している文字を取得する
char S1 = S[0];
char S2 = S[1];
char S3 = S[2];
char S4 = S[3];
//取得した文字を、配列に加える
char[] list = { S1, S2, S3, S4 };
//アルファベット順に並び替え
Array.Sort(list);
//出力
if (list[0] == list[1] && list[2] == list[3]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
//入力
string S = Console.ReadLine();
//検証
//出現している文字を取得する
char S1 = S[0];
char S2 = S[1];
char S3 = S[2];
char S4 = S[3];
//取得した文字を、配列に加える
char[] list = { S1, S2, S3, S4 };
//アルファベット順に並び替え
Array.Sort(list);
//出力
if (list[0] == list[1] && list[2] == list[3] && list[0] != list[2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 156
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Solver {
Scanner sc = new Scanner();
public void Solve() {
var S = sc.next().ToCharArray();
if ((S[0] == S[1] && S[2] == S[3]) || (S[0] == S[2] && S[1] == S[3]) ||
(S[0] == S[3] && S[1] == S[2])) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public 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 Program {
static void Main(string[] args) {
Solver s = new Solver();
s.Solve();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Solver {
Scanner sc = new Scanner();
public void Solve() {
var S = sc.next().ToCharArray();
if ((S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) ||
(S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) ||
(S[0] == S[3] && S[1] == S[2] && S[0] != S[1])) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public 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 Program {
static void Main(string[] args) {
Solver s = new Solver();
s.Solve();
}
}
|
[["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 98], ["+", 31, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 17, 79], ["+", 31, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 98], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 17, 79], ["+", 12, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 79]]
| 8
| 519
| 30
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
var S = Console.ReadLine().ToCharArray().OrderBy(x => x).ToArray();
var able = S[0] == S[1] && S[2] == S[3];
var ans = able ? "Yes" : "No";
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
var S = Console.ReadLine().ToCharArray().OrderBy(x => x).ToArray();
var able = S[0] == S[1] && S[2] == S[3] && S[0] != S[2];
var ans = able ? "Yes" : "No";
Console.WriteLine(ans);
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 98], ["+", 0, 212, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 79], ["+", 0, 212, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 93
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC132 {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
var r = s.OrderBy(x => x).ToArray();
if (r[0] == r[1] && r[2] == r[3]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC132 {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
var r = s.OrderBy(x => x).ToArray();
if (r[0] == r[1] && r[2] == r[3] && r[1] != r[2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 116
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var S = Read();
if (S[0] == S[1] && S[2] == S[3])
WriteLine("Yes");
else if (S[0] == S[2] && S[1] == S[3])
WriteLine("Yes");
else if (S[0] == S[3] && S[1] == S[2])
WriteLine("Yes");
else
WriteLine("No");
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
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);
}
//最大公約数
public static int Gcd(int a, int b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
var reminder = a % b;
a = b;
b = reminder;
}
return a;
}
//最小公倍数
public static int Lcm(int a, int b) { return a * b / Gcd(a, b); }
//文字数を数える
public static int CountChar(string s, char c) {
return s.Length - s.Replace(c.ToString(), "").Length;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var S = Read();
if (S[0] == S[1] && S[2] == S[3] && S[1] == S[2])
WriteLine("No");
else if (S[0] == S[1] && S[2] == S[3])
WriteLine("Yes");
else if (S[0] == S[2] && S[1] == S[3])
WriteLine("Yes");
else if (S[0] == S[3] && S[1] == S[2])
WriteLine("Yes");
else
WriteLine("No");
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
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);
}
//最大公約数
public static int Gcd(int a, int b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
var reminder = a % b;
a = b;
b = reminder;
}
return a;
}
//最小公倍数
public static int Lcm(int a, int b) { return a * b / Gcd(a, b); }
//文字数を数える
public static int CountChar(string s, char c) {
return s.Length - s.Replace(c.ToString(), "").Length;
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["+", 75, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["+", 75, 57, 15, 16, 12, 16, 12, 204, 205, 22]]
| 8
| 444
| 40
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Hayadoki20200309A {
class Input {
/// <summary>
/// 1行の入力を取得する
/// </summary>
/// <returns>文字列</returns>
public void String(out string s) { s = Console.ReadLine(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <returns>文字列の配列</returns>
public void String(long rowNumber, out string[] s) {
s = new String[rowNumber];
for (long i = 0; i < rowNumber; i++) {
String(out s[i]);
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の値</returns>
public void Int(out int i) {
string s;
String(out s);
i = int.Parse(s);
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <param name="a"></param>
public void Long(out long a) {
string s;
String(out s);
a = long.Parse(s);
}
/// <summary>
/// 2つの整数が1行に書かれている入力を、2つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public void Long(out long a, out long b) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
}
/// <summary>
/// 3つの整数が1行に書かれている入力を、3つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
public void Long(out long a, out long b, out long c) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
c = lArr[2];
}
/// <summary>
/// 4つの整数が1行に書かれている入力を、4つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="d"></param>
public void Long(out long a, out long b, out long c, out long d) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
c = lArr[2];
d = lArr[3];
}
public void Long(out long[] lArr) {
lArr = Split().Select(long.Parse).ToArray();
}
public void Long(long rowNumber, out long[] lArr) {
lArr = new long[rowNumber];
for (long i = 0; i < rowNumber; i++) {
Long(out lArr[i]);
}
}
/// <summary>
/// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
public void Long(long rowNumber, out long[] a, out long[] b) {
a = new long[rowNumber];
b = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i]);
}
}
/// <summary>
/// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i], out c[i]);
}
}
/// <summary>
/// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="d"></param>
public void Long(long rowNumber, out long[] a, out long[] b, out long[] c,
out long[] d) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
d = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i], out c[i], out d[i]);
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の値</returns>
public void Double(out double d) {
string s;
String(out s);
d = double.Parse(s);
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の配列</returns>
public void Double(out double[] dArr) {
dArr = Split().Select(double.Parse).ToArray();
}
private IEnumerable<string> Split() {
string s;
String(out s);
return s.Split(' ');
}
}
class Program {
static void Main(string[] args) {
Solver solver = new Solver();
solver.Solve();
}
}
class Solver {
private Input input = new Input();
private long N;
private long[] P;
public Solver() {
input.Long(out N);
input.Long(out P);
}
public void Solve() {
long before2 = P[0];
long before = P[1];
long ans = 0;
for (long i = 2; i < N; i++) {
if (before2 >= before && before >= P[i]) {
ans++;
continue;
}
if (before2 <= before && before <= P[i]) {
ans++;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Hayadoki20200309A {
class Input {
/// <summary>
/// 1行の入力を取得する
/// </summary>
/// <returns>文字列</returns>
public void String(out string s) { s = Console.ReadLine(); }
/// <summary>
/// 複数行の入力を取得
/// </summary>
/// <returns>文字列の配列</returns>
public void String(long rowNumber, out string[] s) {
s = new String[rowNumber];
for (long i = 0; i < rowNumber; i++) {
String(out s[i]);
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>int型の値</returns>
public void Int(out int i) {
string s;
String(out s);
i = int.Parse(s);
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <param name="a"></param>
public void Long(out long a) {
string s;
String(out s);
a = long.Parse(s);
}
/// <summary>
/// 2つの整数が1行に書かれている入力を、2つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public void Long(out long a, out long b) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
}
/// <summary>
/// 3つの整数が1行に書かれている入力を、3つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
public void Long(out long a, out long b, out long c) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
c = lArr[2];
}
/// <summary>
/// 4つの整数が1行に書かれている入力を、4つのlongで受け取る
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="d"></param>
public void Long(out long a, out long b, out long c, out long d) {
long[] lArr;
Long(out lArr);
a = lArr[0];
b = lArr[1];
c = lArr[2];
d = lArr[3];
}
public void Long(out long[] lArr) {
lArr = Split().Select(long.Parse).ToArray();
}
public void Long(long rowNumber, out long[] lArr) {
lArr = new long[rowNumber];
for (long i = 0; i < rowNumber; i++) {
Long(out lArr[i]);
}
}
/// <summary>
/// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
public void Long(long rowNumber, out long[] a, out long[] b) {
a = new long[rowNumber];
b = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i]);
}
}
/// <summary>
/// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i], out c[i]);
}
}
/// <summary>
/// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る
/// </summary>
/// <param name="rowNumber"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <param name="c"></param>
/// <param name="d"></param>
public void Long(long rowNumber, out long[] a, out long[] b, out long[] c,
out long[] d) {
a = new long[rowNumber];
b = new long[rowNumber];
c = new long[rowNumber];
d = new long[rowNumber];
for (int i = 0; i < rowNumber; i++) {
Long(out a[i], out b[i], out c[i], out d[i]);
}
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の値</returns>
public void Double(out double d) {
string s;
String(out s);
d = double.Parse(s);
}
/// <summary>
/// 1行の入力を取得
/// </summary>
/// <returns>double型の配列</returns>
public void Double(out double[] dArr) {
dArr = Split().Select(double.Parse).ToArray();
}
private IEnumerable<string> Split() {
string s;
String(out s);
return s.Split(' ');
}
}
class Program {
static void Main(string[] args) {
Solver solver = new Solver();
solver.Solve();
}
}
class Solver {
private Input input = new Input();
private long N;
private long[] P;
public Solver() {
input.Long(out N);
input.Long(out P);
}
public void Solve() {
long before2 = P[0];
long before = P[1];
long ans = 0;
for (long i = 2; i < N; i++) {
if (before2 > before && before > P[i]) {
ans++;
} else
if (before2 < before && before < P[i]) {
ans++;
}
before2 = before;
before = P[i];
}
Console.WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 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, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
| 8
| 948
| 22
|
using System;
using System.Linq;
namespace B___Ordinary_Number {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var pi = Console.ReadLine().Split().ToArray();
var cnt = 0;
for (int i = 1; i < n - 1; i++) {
if (pi[i - 1] == pi[i] || pi[i] == pi[i + 1])
continue;
if (pi[i - 1].CompareTo(pi[i]) == pi[i].CompareTo(pi[i + 1]))
cnt++;
}
Console.WriteLine(cnt);
}
}
}
|
using System;
using System.Linq;
namespace B___Ordinary_Number {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var pi = Console.ReadLine().Split().Select(int.Parse).ToArray();
var cnt = 0;
for (int i = 1; i < n - 1; i++) {
if (pi[i - 1] == pi[i] || pi[i] == pi[i + 1])
continue;
if (pi[i - 1].CompareTo(pi[i]) == pi[i].CompareTo(pi[i + 1]))
cnt++;
}
Console.WriteLine(cnt);
}
}
}
|
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131]]
| 8
| 151
| 7
|
using System;
using System.Collections.Generic;
class Program {
public class Node {
static void Main(string[] args) {
int mod = 1000000007;
string[] s = Console.ReadLine().Split(' ');
long n = long.Parse(s[0]);
int k = int.Parse(s[1]);
long rootN = (long)Math.Sqrt(n);
int arrSize = (int)rootN * 2;
if (rootN * rootN == n)
arrSize--;
long[] arr = new long[arrSize + 1];
for (int i = 1; i <= rootN; i++) {
arr[i] = i;
arr[arrSize + 1 - i] = n / i;
}
long[] comb_add = new long[arrSize + 1];
comb_add[1] = 1;
for (int i = 1; i < k; i++) {
// foreach(int x in comb_add) Console.Error.WriteLine(x);
long[] new_comb_add = new long[arrSize + 1];
long[] comb = new long[arrSize + 1];
for (int j = 1; j <= arrSize; j++) {
comb[j] = comb[j - 1] + comb_add[j];
comb[j] %= mod;
// Console.Error.WriteLine(arr[j] + " " + comb[j]);
}
for (int j = 1; j <= arrSize; j++) {
long num = comb[j] * (arr[j] - arr[j - 1]) % mod;
new_comb_add[1] += num;
new_comb_add[1] %= mod;
if (j > 1) {
new_comb_add[arrSize + 2 - j] -= num;
new_comb_add[arrSize + 2 - j] %= mod;
}
}
comb_add = new_comb_add;
}
long ans = 0;
long c = 0;
for (int i = 1; i <= arrSize; i++) {
c += comb_add[i] %= mod;
// Console.Error.WriteLine(arr[i] + " " + c);
ans += ((long)c * (arr[i] - arr[i - 1]) % mod);
ans %= mod;
}
if (ans < 0)
ans += mod;
Console.WriteLine(ans);
}
}
}
// mcs Main.cs
// mono Main.exe
|
using System;
using System.Collections.Generic;
class Program {
public class Node {
static void Main(string[] args) {
long mod = 1000000007;
string[] s = Console.ReadLine().Split(' ');
long n = long.Parse(s[0]);
int k = int.Parse(s[1]);
long rootN = (long)Math.Sqrt(n);
int arrSize = (int)rootN * 2;
if (rootN * rootN == n)
arrSize--;
long[] arr = new long[arrSize + 1];
for (int i = 1; i <= rootN; i++) {
arr[i] = i;
arr[arrSize + 1 - i] = n / i;
}
long[] comb_add = new long[arrSize + 1];
comb_add[1] = 1;
for (int i = 1; i < k; i++) {
// foreach(int x in comb_add) Console.Error.WriteLine(x);
long[] new_comb_add = new long[arrSize + 1];
long[] comb = new long[arrSize + 1];
for (int j = 1; j <= arrSize; j++) {
comb[j] = comb[j - 1] + comb_add[j];
comb[j] %= mod;
// Console.Error.WriteLine(arr[j] + " " + comb[j]);
}
for (int j = 1; j <= arrSize; j++) {
long num = comb[j] * (arr[j] - arr[j - 1]) % mod;
new_comb_add[1] += num;
new_comb_add[1] %= mod;
if (j > 1) {
new_comb_add[arrSize + 2 - j] -= num;
new_comb_add[arrSize + 2 - j] %= mod;
}
}
comb_add = new_comb_add;
}
long ans = 0;
long c = 0;
for (int i = 1; i <= arrSize; i++) {
c += comb_add[i];
c %= mod;
// Console.Error.WriteLine(arr[i] + " " + c);
ans += c * (arr[i] - arr[i - 1]) % mod;
ans %= mod;
}
if (ans < 0)
ans += mod;
Console.WriteLine(ans);
}
}
}
// mcs Main.cs
// mono Main.exe
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["-", 12, 23, 0, 16, 31, 16, 31, 74, 0, 24], ["-", 12, 23, 0, 16, 31, 16, 31, 74, 39, 199], ["-", 12, 23, 0, 16, 31, 16, 31, 74, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25]]
| 8
| 438
| 9
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.