buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Console.ReadLine();
var vals =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
long ans = 1;
foreach (var item in vals) {
checked {
if (((long)1e18 + ans - 1) / ans < item) {
ans = -1;
break;
}
ans *= item;
if (ans == 0)
break;
if (ans > (long)1e18) {
ans = -1;
break;
}
}
}
if (vals.Any(x => x == 0)) {
ans = -1;
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Console.ReadLine();
var vals =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
long ans = 1;
foreach (var item in vals) {
checked {
if (((long)1e18 + ans - 1) / ans < item) {
ans = -1;
break;
}
ans *= item;
if (ans == 0)
break;
if (ans > (long)1e18) {
ans = -1;
break;
}
}
}
if (vals.Any(x => x == 0)) {
ans = 0;
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 219
| 3
|
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
class StringComparator2 : IComparer<string> {
int IComparer<string>.Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
class StringComparator3 : IEqualityComparer<string> {
public bool Equals(string b1, string b2) { return Compare(b1, b2) == 0; }
public int GetHashCode(string bx) { return bx.GetHashCode(); }
int Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class Class1 {
// static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long,
// long>, long>();
static long mod = 1000000007;
static long[] factorial = new long[1000001];
static long[] invFactorial = new long[1000001];
private static void calcFanctorial(long N) {
factorial[0] = 1;
for (int i = 1; i < N + 1; i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
invFactorial[N] = inv(factorial[N]);
for (int i = (int)N; i > 0; i--) {
invFactorial[i - 1] = invFactorial[i] * i % mod;
}
}
class Tree {
public HashSet<long> conn = new HashSet<long>();
}
static long bin(long a, long x, long n) {
long y = a;
long res = 1;
while (x > 0) {
if (x % 2 == 1) {
res = res * y % n;
}
x /= 2;
y = y * y % n;
}
return res;
}
int cmp(string a, string b) {
for (var i = 0; i < Math.Min(a.Length, b.Length); i++)
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
if (a.Length == b.Length)
return 0;
if (a.Length > b.Length)
return 1;
else
return -1;
}
private static long nCm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod;
}
private static long nPm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod);
}
private static long nCm2(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
long res = 1;
for (long i = n; i > n - m; i--) {
res *= i;
res %= mod;
}
return res * invFactorial[m] % mod;
}
public static long pow(long a, long b, long mod) {
a %= mod;
if (b <= 0)
return 1;
var t = pow(a, b / 2, mod);
if ((b & 1) == 0)
return t * t % mod;
return t * t % mod * a % mod;
}
public static long Lcm(long a, long b) {
return a * b % mod * inv(Gcd(a, b)) % mod;
}
public static long Lcm(long[] a) {
List<long> vect = new List<long>();
long lcm = 1;
for (int i = 0; i < a.Count(); i++) {
var factor = a[i] / GcdVector(vect, a[i]);
vect.Add(factor);
lcm = lcm * factor % mod;
}
return lcm;
}
static long GcdVector(List<long> a, long b) {
long ma = 1;
for (int i = 0; i < a.Count; i++)
ma = ma * a[i] % b;
return Gcd(b, ma);
}
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static long pow(long a, long b) => pow(a, b, mod);
public static long inv(long a) => pow(a, mod - 2);
private static char[][] ReadCharMatrix(long h) {
char[][] mtx = new char [h][];
for (int i = 0; i < h; i++) {
var s = ReadString();
mtx[i] = s.ToCharArray();
}
return mtx;
}
private static int[][] CreateIntMatrix(long h, long w) {
int[][] mtx = new int [h][];
for (int i = 0; i < h; i++) {
mtx[i] = new int[w];
}
return mtx;
}
private static string ReadString() { return Console.ReadLine(); }
private static string[] ReadStringArr() {
return Console.ReadLine().Split(' ');
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static long[] ReadLongArr() {
string[] s = ReadStringArr();
long[] l = new long[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = long.Parse(s[i]);
}
return l;
}
private static int[] ReadIntArr() {
string[] s = ReadStringArr();
int[] l = new int[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = int.Parse(s[i]);
}
return l;
}
private static double[] ReadDoubleArr() {
string[] s = ReadStringArr();
double[] l = new double[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = double.Parse(s[i]);
}
return l;
}
/*
static void Main(string[] args)
{
var AA = ReadStringArr();
long A = long.Parse(AA[0]);
long B = (long)(double.Parse(AA[1]) * 100);
long res = A * B;
Console.WriteLine(res/100);
}
*/
static void Main(string[] args) {
var N = ReadLong();
var AA = ReadLongArr();
foreach (var a in AA) {
if (a == 0) {
Console.WriteLine("0");
return;
}
}
long res = 1;
for (long i = 0; i < N; i++) {
if (1000000000000000000 / AA[i] > res) {
Console.WriteLine("-1");
return;
}
res *= AA[i];
}
if (res >= 0 && res <= 1000000000000000000) {
Console.WriteLine(res);
} else {
Console.WriteLine("-1");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
class StringComparator2 : IComparer<string> {
int IComparer<string>.Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
class StringComparator3 : IEqualityComparer<string> {
public bool Equals(string b1, string b2) { return Compare(b1, b2) == 0; }
public int GetHashCode(string bx) { return bx.GetHashCode(); }
int Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class Class1 {
// static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long,
// long>, long>();
static long mod = 1000000007;
static long[] factorial = new long[1000001];
static long[] invFactorial = new long[1000001];
private static void calcFanctorial(long N) {
factorial[0] = 1;
for (int i = 1; i < N + 1; i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
invFactorial[N] = inv(factorial[N]);
for (int i = (int)N; i > 0; i--) {
invFactorial[i - 1] = invFactorial[i] * i % mod;
}
}
class Tree {
public HashSet<long> conn = new HashSet<long>();
}
static long bin(long a, long x, long n) {
long y = a;
long res = 1;
while (x > 0) {
if (x % 2 == 1) {
res = res * y % n;
}
x /= 2;
y = y * y % n;
}
return res;
}
int cmp(string a, string b) {
for (var i = 0; i < Math.Min(a.Length, b.Length); i++)
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
if (a.Length == b.Length)
return 0;
if (a.Length > b.Length)
return 1;
else
return -1;
}
private static long nCm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod;
}
private static long nPm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod);
}
private static long nCm2(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
long res = 1;
for (long i = n; i > n - m; i--) {
res *= i;
res %= mod;
}
return res * invFactorial[m] % mod;
}
public static long pow(long a, long b, long mod) {
a %= mod;
if (b <= 0)
return 1;
var t = pow(a, b / 2, mod);
if ((b & 1) == 0)
return t * t % mod;
return t * t % mod * a % mod;
}
public static long Lcm(long a, long b) {
return a * b % mod * inv(Gcd(a, b)) % mod;
}
public static long Lcm(long[] a) {
List<long> vect = new List<long>();
long lcm = 1;
for (int i = 0; i < a.Count(); i++) {
var factor = a[i] / GcdVector(vect, a[i]);
vect.Add(factor);
lcm = lcm * factor % mod;
}
return lcm;
}
static long GcdVector(List<long> a, long b) {
long ma = 1;
for (int i = 0; i < a.Count; i++)
ma = ma * a[i] % b;
return Gcd(b, ma);
}
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static long pow(long a, long b) => pow(a, b, mod);
public static long inv(long a) => pow(a, mod - 2);
private static char[][] ReadCharMatrix(long h) {
char[][] mtx = new char [h][];
for (int i = 0; i < h; i++) {
var s = ReadString();
mtx[i] = s.ToCharArray();
}
return mtx;
}
private static int[][] CreateIntMatrix(long h, long w) {
int[][] mtx = new int [h][];
for (int i = 0; i < h; i++) {
mtx[i] = new int[w];
}
return mtx;
}
private static string ReadString() { return Console.ReadLine(); }
private static string[] ReadStringArr() {
return Console.ReadLine().Split(' ');
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static long[] ReadLongArr() {
string[] s = ReadStringArr();
long[] l = new long[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = long.Parse(s[i]);
}
return l;
}
private static int[] ReadIntArr() {
string[] s = ReadStringArr();
int[] l = new int[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = int.Parse(s[i]);
}
return l;
}
private static double[] ReadDoubleArr() {
string[] s = ReadStringArr();
double[] l = new double[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = double.Parse(s[i]);
}
return l;
}
/*
static void Main(string[] args)
{
var AA = ReadStringArr();
long A = long.Parse(AA[0]);
long B = (long)(double.Parse(AA[1]) * 100);
long res = A * B;
Console.WriteLine(res/100);
}
*/
static void Main(string[] args) {
var N = ReadLong();
var AA = ReadLongArr();
foreach (var a in AA) {
if (a == 0) {
Console.WriteLine("0");
return;
}
}
long res = 1;
for (long i = 0; i < N; i++) {
if (1000000000000000000 / AA[i] < res) {
Console.WriteLine("-1");
return;
}
res *= AA[i];
}
if (res >= 0 && res <= 1000000000000000000) {
Console.WriteLine(res);
} else {
Console.WriteLine("-1");
}
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 2,245
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine();
var inputs = Console.ReadLine().Split(' ');
ulong ans = 1;
var flag = true;
foreach (var n in inputs) {
if (flag) {
if (n.ToCharArray().Length + ans.ToString().ToCharArray().Length > 21) {
ans = 1000000000000000001;
flag = false;
} else {
ans *= ulong.Parse(n);
if (ans > (ulong)Math.Pow(10, 18)) {
flag = false;
}
}
} else {
if (long.Parse(n) == 0) {
ans = 0;
}
}
}
if (ans > (ulong)Math.Pow(10, 18)) {
Console.WriteLine(-1);
} else {
Console.WriteLine(ans);
}
Console.Read();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine();
var inputs = Console.ReadLine().Split(' ');
decimal ans = 1;
var flag = true;
foreach (var n in inputs) {
if (flag) {
if (n.ToCharArray().Length + ans.ToString().ToCharArray().Length > 24) {
ans = 1000000000000000001;
flag = false;
} else {
ans *= decimal.Parse(n);
if (ans > (decimal)Math.Pow(10, 18)) {
flag = false;
}
}
} else {
if (decimal.Parse(n) == 0) {
ans = 0;
}
}
}
if (ans > (decimal)Math.Pow(10, 18)) {
Console.WriteLine(-1);
} else {
Console.WriteLine(ans);
}
Console.Read();
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 75, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["+", 75, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 39, 199]]
| 8
| 210
| 12
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public void Solve() {
var N = int.Parse(Console.ReadLine());
var items =
Console.ReadLine().Split().Select(elem => ulong.Parse(elem)).ToArray();
try {
var answer = 0UL;
if (!items.Contains(0UL)) {
foreach (var item in items.Select(
(elem, idx) => new { Index = idx, Data = elem })) {
if (item.Index == 0) {
answer = item.Data;
} else {
answer *= item.Data;
}
if (answer > 1000000000000000000) {
throw new OverflowException();
}
}
}
Console.WriteLine(answer);
} catch (Exception) {
Console.WriteLine("-1");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public void Solve() {
var N = int.Parse(Console.ReadLine());
var items = Console.ReadLine()
.Split()
.Select(elem => decimal.Parse(elem))
.ToArray();
try {
var answer = (decimal)0;
if (!items.Contains(0UL)) {
foreach (var item in items.Select(
(elem, idx) => new { Index = idx, Data = elem })) {
if (item.Index == 0) {
answer = item.Data;
} else {
answer *= item.Data;
}
if (answer > 1000000000000000000) {
throw new OverflowException();
}
}
}
Console.WriteLine(answer);
} catch (Exception) {
Console.WriteLine("-1");
}
}
}
}
|
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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, 203]]
| 8
| 273
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static void Main() {
long N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
long ans = 1;
if (A.Any(x => x == 0)) {
Console.WriteLine(0);
return;
}
foreach (var x in A) {
try {
ans *= x;
if (ans > 1000000000000000000) {
Console.WriteLine(-1);
return;
}
} catch (Exception) {
Console.WriteLine(-1);
return;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static void Main() {
long N = long.Parse(Console.ReadLine());
var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
long ans = 1;
if (A.Any(x => x == 0)) {
Console.WriteLine(0);
return;
}
foreach (var x in A) {
try {
checked {
ans *= x;
if (ans > 1000000000000000000) {
Console.WriteLine(-1);
return;
}
}
} catch (OverflowException) {
Console.WriteLine(-1);
return;
}
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 210, 8, 196, 0, 246, 8, 196, 0, 46], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22]]
| 8
| 151
| 7
|
using System;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
int a = int.Parse(System.Console.ReadLine());
long[] nm =
Array.ConvertAll(System.Console.ReadLine().Split(' '), long.Parse);
long mal = nm[0];
for (int i = 0; i < a; i++) {
if (nm[i] == 0) {
Console.WriteLine(-1);
return;
}
}
for (int i = 1; i < a; i++) {
try {
checked {
if (mal > 1000000000000000000) {
Console.WriteLine(-1);
return;
}
mal *= nm[i];
if (mal > 1000000000000000000) {
Console.WriteLine(-1);
return;
}
}
} catch (OverflowException ex) {
Console.WriteLine(-1);
return;
}
}
System.Console.WriteLine(mal);
}
}
}
|
using System;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
int a = int.Parse(System.Console.ReadLine());
long[] nm =
Array.ConvertAll(System.Console.ReadLine().Split(' '), long.Parse);
long mal = nm[0];
for (int i = 0; i < a; i++) {
if (nm[i] == 0) {
Console.WriteLine(0);
return;
}
}
for (int i = 1; i < a; i++) {
try {
checked {
if (mal > 1000000000000000000) {
Console.WriteLine(-1);
return;
}
mal *= nm[i];
if (mal > 1000000000000000000) {
Console.WriteLine(-1);
return;
}
}
} catch (OverflowException ex) {
Console.WriteLine(-1);
return;
}
}
System.Console.WriteLine(mal);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 203
| 3
|
using System;
namespace abc169 {
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var aList = ReadNumList();
foreach (var a in aList) {
if (a == 0) {
Console.WriteLine(0);
}
}
Decimal total = 1;
try {
foreach (var a in aList) {
total = Decimal.Multiply(total, a);
}
if (total > 1000000000000000000L) {
Console.WriteLine(-1);
} else {
Console.WriteLine(total);
}
} catch (OverflowException) {
Console.WriteLine(-1);
}
}
static long[] ReadNumList() {
var line = Console.ReadLine().Split(' ');
var numList = new long[line.Length];
for (var i = 0; i < line.Length; ++i) {
numList[i] = long.Parse(line[i]);
}
return numList;
}
}
}
|
using System;
namespace abc169 {
class B {
static void Main() {
var n = int.Parse(Console.ReadLine());
var aList = ReadNumList();
foreach (var a in aList) {
if (a == 0) {
Console.WriteLine(0);
return;
}
}
Decimal total = 1;
try {
foreach (var a in aList) {
total = Decimal.Multiply(total, a);
}
if (total > 1000000000000000000L) {
Console.WriteLine(-1);
} else {
Console.WriteLine(total);
}
} catch (OverflowException) {
Console.WriteLine(-1);
}
}
static long[] ReadNumList() {
var line = Console.ReadLine().Split(' ');
var numList = new long[line.Length];
for (var i = 0; i < line.Length; ++i) {
numList[i] = long.Parse(line[i]);
}
return numList;
}
}
}
|
[["-", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["+", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 203
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public static void Main() {
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
if (A.Contains(0)) {
Console.WriteLine(0);
return;
}
long v = 1;
foreach (var a in A) {
try {
v *= a;
if (v > 1000000000000000000) {
v = -1;
break;
}
} catch (OverflowException) {
v = -1;
break;
}
}
Console.WriteLine(v);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public static void Main() {
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
if (A.Contains(0)) {
Console.WriteLine(0);
return;
}
long v = 1;
foreach (var a in A) {
checked {
try {
v *= a;
if (v > 1000000000000000000) {
v = -1;
break;
}
} catch (OverflowException) {
v = -1;
break;
}
}
}
Console.WriteLine(v);
}
}
|
[["+", 8, 196, 0, 210, 8, 196, 0, 287, 0, 292], ["+", 0, 210, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 196, 0, 246, 0, 248, 8, 196, 0, 46]]
| 8
| 145
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public long a;
public long b;
public long kosu;
public Pair(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Pair2 : IComparable {
public long a;
public long b;
public long kosu;
public long teki;
public Mlong jikkou = 1;
public Pair2(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair2 kore = (Pair2)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Program {
static bool[] visited;
static List<int>[] togo;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long n = scan.Long();
long[] a = scan.Long(n);
long mul = 1;
long max = (long)Math.Pow(10, 18);
if (a.Contains(0)) {
Console.WriteLine(0);
return;
}
long togo = max;
for (long i = 0; i < n; i++) {
if (a[i] > togo) {
Console.WriteLine(-1);
}
togo /= a[i];
togo++;
if (a[i] > max || mul > max || mul < 0) {
Console.WriteLine(-1);
return;
}
if (a[i] * mul > max || a[i] * mul < 0) {
Console.WriteLine(-1);
return;
}
mul = a[i] * mul;
}
Console.WriteLine(mul);
}
static void shuffle(Pair2[] ary) {
System.Random rng = new System.Random();
int n = ary.Length;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
var tmp = new Pair2(ary[k].a, ary[k].b);
ary[k] = new Pair2(ary[n].a, ary[n].b);
ary[n] = new Pair2(tmp.a, tmp.b);
}
}
static bool DFS(int now, int last) {
visited[now] = true;
for (int i = 0; i < togo[now].Count; i++) {
if (togo[now][i] == last) {
continue;
}
if (visited[togo[now][i]]) {
return false;
}
if (!DFS(togo[now][i], now)) {
return false;
}
}
return true;
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public List<int> Topological_Sort(List<List<Edge>> G) {
var ret = new List<int>();
var Nodes = new Queue<int>();
int N = G.Count();
var Link = new int[N];
for (var i = 0; i < N; i++) {
Link[i] = 0;
}
for (var i = 0; i < N; i++) {
foreach (var nx in G[i]) {
Link[nx.to]++;
}
}
for (var i = 0; i < N; i++) {
if (Link[i] == 0) {
Nodes.Enqueue(i);
}
}
while (Nodes.Any()) {
var nd = Nodes.Dequeue();
ret.Add(nd);
foreach (var nx in G[nd]) {
Link[nx.to]--;
if (Link[nx.to] == 0) {
Nodes.Enqueue(nx.to);
}
}
}
return ret;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(long n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(long n, long m) {
char[,] kore = new char[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public long a;
public long b;
public long kosu;
public Pair(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Pair2 : IComparable {
public long a;
public long b;
public long kosu;
public long teki;
public Mlong jikkou = 1;
public Pair2(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair2 kore = (Pair2)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Program {
static bool[] visited;
static List<int>[] togo;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long n = scan.Long();
long[] a = scan.Long(n);
long mul = 1;
long max = (long)Math.Pow(10, 18);
if (a.Contains(0)) {
Console.WriteLine(0);
return;
}
long togo = max + 1;
for (long i = 0; i < n; i++) {
if (a[i] > togo) {
Console.WriteLine(-1);
return;
}
togo /= a[i];
togo++;
if (a[i] > max || mul > max || mul < 0) {
Console.WriteLine(-1);
return;
}
if (a[i] * mul > max || a[i] * mul < 0) {
Console.WriteLine(-1);
return;
}
mul = a[i] * mul;
}
Console.WriteLine(mul);
}
static void shuffle(Pair2[] ary) {
System.Random rng = new System.Random();
int n = ary.Length;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
var tmp = new Pair2(ary[k].a, ary[k].b);
ary[k] = new Pair2(ary[n].a, ary[n].b);
ary[n] = new Pair2(tmp.a, tmp.b);
}
}
static bool DFS(int now, int last) {
visited[now] = true;
for (int i = 0; i < togo[now].Count; i++) {
if (togo[now][i] == last) {
continue;
}
if (visited[togo[now][i]]) {
return false;
}
if (!DFS(togo[now][i], now)) {
return false;
}
}
return true;
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public List<int> Topological_Sort(List<List<Edge>> G) {
var ret = new List<int>();
var Nodes = new Queue<int>();
int N = G.Count();
var Link = new int[N];
for (var i = 0; i < N; i++) {
Link[i] = 0;
}
for (var i = 0; i < N; i++) {
foreach (var nx in G[i]) {
Link[nx.to]++;
}
}
for (var i = 0; i < N; i++) {
if (Link[i] == 0) {
Nodes.Enqueue(i);
}
}
while (Nodes.Any()) {
var nd = Nodes.Dequeue();
ret.Add(nd);
foreach (var nx in G[nd]) {
Link[nx.to]--;
if (Link[nx.to] == 0) {
Nodes.Enqueue(nx.to);
}
}
}
return ret;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(long n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(long n, long m) {
char[,] kore = new char[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 12,082
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var ab =
Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
Console.WriteLine((long)Math.Floor(ab[0] * ab[1]));
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var ab =
Console.ReadLine().Trim().Split(' ').Select(decimal.Parse).ToArray();
Console.WriteLine(Math.Floor(ab[0] * ab[1]));
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25]]
| 8
| 144
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(" ");
var A = long.Parse(input[0]);
var B = (long)Math.Round(double.Parse(input[1])) * 100;
Console.WriteLine(A * B / 100);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(" ");
var A = long.Parse(input[0]);
var B = (long)Math.Round(double.Parse(input[1]) * 100);
Console.WriteLine(A * B / 100);
}
}
|
[["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 25], ["+", 0, 212, 0, 74, 51, 213, 3, 4, 0, 25]]
| 8
| 93
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long a, long b) {
if (a < b)
gcd(b, a);
while (b > 0) {
long z = b;
b = a % b;
a = z;
}
return a;
}
public static long lcm(long a, long b) { return a * b / gcd(a, b); }
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var ab = ReadLine().Split();
var a = long.Parse(ab[0]);
var b1 = long.Parse(ab[0].Split('.')[0]) * 100;
var b2 = long.Parse(ab[0].Split('.')[1]);
WriteLine(a * (b1 + b2) / 100);
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long a, long b) {
if (a < b)
gcd(b, a);
while (b > 0) {
long z = b;
b = a % b;
a = z;
}
return a;
}
public static long lcm(long a, long b) { return a * b / gcd(a, b); }
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var ab = ReadLine().Split();
var a = long.Parse(ab[0]);
var b1 = long.Parse(ab[1].Split('.')[0]) * 100;
var b2 = long.Parse(ab[1].Split('.')[1]);
WriteLine(a * (b1 + b2) / 100);
Console.Out.Flush();
}
}
}
|
[["-", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 292
| 4
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
private static void Main(string[] args) {
var a = double.Parse(Scanner.Scan());
var b = double.Parse(Scanner.Scan());
var val = a * b;
Console.WriteLine(Math.Floor((decimal)val));
}
#region Utility
static readonly StreamScanner Scanner =
new StreamScanner(Console.OpenStandardInput());
/// <summary> 一括出力 </summary>
private static void OutAllLine(IEnumerable<dynamic> items) {
var sb = new StringBuilder();
foreach (var result in items) {
sb.Append(result + "\n");
}
sb = sb.Remove(sb.Length - 1, 1);
Console.WriteLine(sb);
}
#endregion
}
#region Utility Class
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
/// <summary> 数値読み込み </summary>
public List<long> ArrayLong(int count = 0) {
var scan = new List<long>();
for (int i = 0; i < count; i++) {
scan.Add(Long());
}
return scan;
}
/// <summary> 数値読み込み </summary>
public List<int> ArrayInt(int count = 0) {
var scan = new List<int>();
for (int i = 0; i < count; i++) {
scan.Add(Integer());
}
return scan;
}
}
public class Primer {
/// <summary> 素数判定 </summary>
public static bool IsPrime(int num) {
if (num < 2) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static IEnumerable<int> GetPrimeFactors(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
}
public class Mod109 {
public const int _7 = 1000000007;
public const int _9 = 1000000009;
public const int _3 = 998244353;
private readonly int ModValue;
public Mod109(int modValue = Mod109._7) { ModValue = modValue; }
/// <summary> 和 </summary>
public long Addition(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current + num) % ModValue));
}
/// <summary> 差 </summary>
public long Subtraction(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current - num) % ModValue));
}
/// <summary> 積 </summary>
public long Multiplication(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
1, (current, num) => ModifyPositive((current * num) % ModValue));
}
private long ModifyPositive(long value) {
return value < 0 ? (value + ModValue) : value;
}
}
public class BitArrayMaker {
public List<int> Integer(int bitValue, int length) {
var list = new List<int>();
for (int i = 0; i < length; i++) {
if (bitValue % 2 == 1) {
list.Add(i);
}
bitValue /= 2;
}
return list;
}
public bool[] Boolean(int bitValue, int length) {
var list = new bool[length];
for (int i = 0; i < length; i++) {
list[i] = bitValue % 2 == 1;
bitValue /= 2;
}
return list;
}
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
private static void Main(string[] args) {
var a = decimal.Parse(Scanner.Scan());
var b = decimal.Parse(Scanner.Scan());
var val = a * b;
Console.WriteLine(Math.Floor(val));
}
#region Utility
static readonly StreamScanner Scanner =
new StreamScanner(Console.OpenStandardInput());
/// <summary> 一括出力 </summary>
private static void OutAllLine(IEnumerable<dynamic> items) {
var sb = new StringBuilder();
foreach (var result in items) {
sb.Append(result + "\n");
}
sb = sb.Remove(sb.Length - 1, 1);
Console.WriteLine(sb);
}
#endregion
}
#region Utility Class
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
/// <summary> 数値読み込み </summary>
public List<long> ArrayLong(int count = 0) {
var scan = new List<long>();
for (int i = 0; i < count; i++) {
scan.Add(Long());
}
return scan;
}
/// <summary> 数値読み込み </summary>
public List<int> ArrayInt(int count = 0) {
var scan = new List<int>();
for (int i = 0; i < count; i++) {
scan.Add(Integer());
}
return scan;
}
}
public class Primer {
/// <summary> 素数判定 </summary>
public static bool IsPrime(int num) {
if (num < 2) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static IEnumerable<int> GetPrimeFactors(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
}
public class Mod109 {
public const int _7 = 1000000007;
public const int _9 = 1000000009;
public const int _3 = 998244353;
private readonly int ModValue;
public Mod109(int modValue = Mod109._7) { ModValue = modValue; }
/// <summary> 和 </summary>
public long Addition(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current + num) % ModValue));
}
/// <summary> 差 </summary>
public long Subtraction(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current - num) % ModValue));
}
/// <summary> 積 </summary>
public long Multiplication(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
1, (current, num) => ModifyPositive((current * num) % ModValue));
}
private long ModifyPositive(long value) {
return value < 0 ? (value + ModValue) : value;
}
}
public class BitArrayMaker {
public List<int> Integer(int bitValue, int length) {
var list = new List<int>();
for (int i = 0; i < length; i++) {
if (bitValue % 2 == 1) {
list.Add(i);
}
bitValue /= 2;
}
return list;
}
public bool[] Boolean(int bitValue, int length) {
var list = new bool[length];
for (int i = 0; i < length; i++) {
list[i] = bitValue % 2 == 1;
bitValue /= 2;
}
return list;
}
}
#endregion
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25]]
| 8
| 1,159
| 7
|
using System;
namespace Contest {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(" ");
var a = decimal.Parse(input[0]);
var b = decimal.Parse(input[1]);
Console.WriteLine(Decimal.Round(a * b - (decimal)0.5));
}
}
}
|
using System;
namespace Contest {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(" ");
var a = decimal.Parse(input[0]);
var b = decimal.Parse(input[1]);
Console.WriteLine(Decimal.Floor(a * b));
}
}
}
|
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 12, 74, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 12, 74, 39, 199], ["-", 3, 4, 0, 28, 0, 16, 12, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 12, 74, 51, 250]]
| 8
| 83
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoder {
public static void Main() {
//入力を保持する
var AB = Console.ReadLine().Split().Select(e => double.Parse(e)).ToArray();
var A = AB[0];
var B = AB[1];
var ans = Math.Truncate(A * B);
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
//入力を保持する
var AB = Console.ReadLine().Split().Select(e => decimal.Parse(e)).ToArray();
var A = AB[0];
var B = AB[1];
var ans = Math.Truncate(A * B);
Console.WriteLine(ans);
}
}
|
[["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199]]
| 8
| 93
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_C.Lib_IO;
using static Contest_C.Lib_Minifunc;
public static class Contest_C
{
public static void Main() {
checked{
double n, m;
Lib_IO.rm(out n, out m);
long ans = (ll)(n*m+EPS1);
Lib_IO.wm(ans);
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換
[MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新
[MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c);
[MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
public struct P<T,U>
{
public T A; public U B;
public P(T a,U b) { A = a; B = b; }
public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B);
public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value);
}
public struct P<T,U,V>
{
public T A; public U B; public V C;
public P(T a,U b,V c) { A = a; B = b; C = c; }
}
public struct P<T,U,V,W>
{
public T A; public U B; public V C; public W D;
public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; }
}
public static class Lib_IO
{
class Prt : System.IO.StreamWriter
{
public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {}
public Prt(System.IO.Stream s,Encoding e) : base(s,e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[MethodImpl(256)] static T cv<T>(string s) =>
eq<T,int>() ? ct<T,int>(int.Parse(s))
: eq<T,long>() ? ct<T,long>(long.Parse(s))
: eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture))
: eq<T,char>() ? ct<T,char>(s[0])
: ct<T,string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T,U>(out T a,out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T,U,V>(out T a,out U b,out V c) {
var z = rm<T,U>(out a,out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) {
var z = rm<T,U,V>(out a,out b,out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) {
var z = rm<T,U,V,W>(out a,out b,out c,out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) {
var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = z.Select(cv<T>).ToArray();
return z;
}
public static string[][] rl<T>(long n,out T[] a) {
a = new T[n];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T,U>(long n,out P<T,U>[] a) {
a = new P<T,U>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p;
y[i] = rm(out o,out p);
a[i] = new P<T,U>(o,p);
}
return y;
}
public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) {
a = new P<T,U,V>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q;
y[i] = rm(out o,out p,out q);
a[i] = new P<T,U,V>(o,p,q);
}
return y;
}
public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) {
a = new P<T,U,V,W>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q; W r;
y[i] = rm(out o,out p,out q,out r);
a[i] = new P<T,U,V,W>(o,p,q,r);
}
return y;
}
public static string[][] rx<T>(long n,out T[][] a) {
a = new T[n][];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act){
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(()=>{
for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]);
Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); }
public static void wl<T>(IList<T> a) {
wwp(()=>{
var f = wfm(typeof(T));
foreach(T x in a) Console.WriteLine(f,x);
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(()=>{
var f = wfm(typeof(T));
var g = f + s;
foreach(var b in a) {
for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]);
Console.WriteLine(f,b[b.Count-1]);
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_C.Lib_IO;
using static Contest_C.Lib_Minifunc;
public static class Contest_C
{
public static void Main() {
checked{
decimal n, m;
Lib_IO.rm(out n, out m);
long ans = (ll)(n*m+(decimal)EPS1);
Lib_IO.wm(ans);
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換
[MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新
[MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c);
[MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
public struct P<T,U>
{
public T A; public U B;
public P(T a,U b) { A = a; B = b; }
public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B);
public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value);
}
public struct P<T,U,V>
{
public T A; public U B; public V C;
public P(T a,U b,V c) { A = a; B = b; C = c; }
}
public struct P<T,U,V,W>
{
public T A; public U B; public V C; public W D;
public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; }
}
public static class Lib_IO
{
class Prt : System.IO.StreamWriter
{
public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {}
public Prt(System.IO.Stream s,Encoding e) : base(s,e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[MethodImpl(256)] static T cv<T>(string s) =>
eq<T,int>() ? ct<T,int>(int.Parse(s))
: eq<T,long>() ? ct<T,long>(long.Parse(s))
: eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture))
: eq<T,char>() ? ct<T,char>(s[0])
: ct<T,string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T,U>(out T a,out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T,U,V>(out T a,out U b,out V c) {
var z = rm<T,U>(out a,out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) {
var z = rm<T,U,V>(out a,out b,out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) {
var z = rm<T,U,V,W>(out a,out b,out c,out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) {
var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = z.Select(cv<T>).ToArray();
return z;
}
public static string[][] rl<T>(long n,out T[] a) {
a = new T[n];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T,U>(long n,out P<T,U>[] a) {
a = new P<T,U>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p;
y[i] = rm(out o,out p);
a[i] = new P<T,U>(o,p);
}
return y;
}
public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) {
a = new P<T,U,V>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q;
y[i] = rm(out o,out p,out q);
a[i] = new P<T,U,V>(o,p,q);
}
return y;
}
public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) {
a = new P<T,U,V,W>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q; W r;
y[i] = rm(out o,out p,out q,out r);
a[i] = new P<T,U,V,W>(o,p,q,r);
}
return y;
}
public static string[][] rx<T>(long n,out T[][] a) {
a = new T[n][];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act){
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(()=>{
for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]);
Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); }
public static void wl<T>(IList<T> a) {
wwp(()=>{
var f = wfm(typeof(T));
foreach(T x in a) Console.WriteLine(f,x);
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(()=>{
var f = wfm(typeof(T));
var g = f + s;
foreach(var b in a) {
for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]);
Console.WriteLine(f,b[b.Count-1]);
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
[["-", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 74, 51, 23, 0, 16, 12, 74, 0, 24], ["+", 0, 74, 51, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 74, 51, 23, 0, 16, 12, 74, 0, 25]]
| 8
| 2,910
| 5
|
using System;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
var s = ReadLine().Split();
double a = double.Parse(s[0]);
double b = double.Parse(s[1]);
double ans = Truncate(a * b);
WriteLine(ans);
}
}
}
|
using System;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
var s = ReadLine().Split();
decimal a = decimal.Parse(s[0]);
decimal b = decimal.Parse(s[1]);
var ans = Truncate(a * b);
WriteLine(ans);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217]]
| 8
| 88
| 10
|
using System;
namespace TEST {
class Program {
private static void Main(string[] arg) {
string[] x = Console.ReadLine().Split();
ulong a = ulong.Parse(x[0]);
double b = double.Parse(x[1]);
double y = a * b;
Console.WriteLine(Math.Truncate(y));
}
}
}
|
using System;
namespace TEST {
class Program {
private static void Main(string[] arg) {
string[] x = Console.ReadLine().Split();
ulong a = ulong.Parse(x[0]);
decimal b = decimal.Parse(x[1]);
decimal y = a * b;
Console.WriteLine(Math.Truncate(y));
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 83
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// https://atcoder.jp/contests/abc169/tasks/abc169_c
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数配列の入力
var inputArray = Console.ReadLine().Split(' ');
var a = long.Parse(inputArray[0]);
var b = double.Parse(inputArray[1]);
long ret = Convert.ToInt64(Math.Floor(a * b));
Console.WriteLine(ret);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
// https://atcoder.jp/contests/abc169/tasks/abc169_c
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数配列の入力
var inputArray = Console.ReadLine().Split(' ');
var a = decimal.Parse(inputArray[0]);
var b = decimal.Parse(inputArray[1]);
long ret = Convert.ToInt64(Math.Floor(a * b));
Console.WriteLine(ret);
Console.Out.Flush();
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 154
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class ABC169 {
static void Main() {
// int A = 198;
// double B = 1.10;
// dynamic ans = A * B;
// long[] num_array = Array.ConvertAll(Console.ReadLine().Split(' '),
// long.Parse);
string[] num_array =
Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
long A = long.Parse(num_array[0]);
double B = double.Parse(num_array[1]);
// double ans = Math.Floor(A * B);
Console.WriteLine(Math.Floor(A * B));
// System.Diagnostics.Debug.WriteLine(Math.Floor(A * B));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class ABC169 {
static void Main() {
// int A = 198;
// double B = 1.10;
// dynamic ans = A * B;
// long[] num_array = Array.ConvertAll(Console.ReadLine().Split(' '),
// long.Parse);
string[] num_array =
Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
decimal A = decimal.Parse(num_array[0]);
decimal B = decimal.Parse(num_array[1]);
// double ans = Math.Floor(A * B);
Console.WriteLine(Math.Floor(A * B));
// System.Diagnostics.Debug.WriteLine(Math.Floor(A * B));
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 107
| 8
|
using System;
namespace AtCoderBeginnerContest169 {
class Multiplication3_3 {
static void Main(string[] args) {
string[] c = Console.ReadLine().Split();
ulong a = ulong.Parse(c[0]);
double b = double.Parse(c[1]);
Console.WriteLine((ulong)(a * b));
}
}
}
|
using System;
namespace AtCoderBeginnerContest169 {
class Multiplication3_3 {
static void Main(string[] args) {
string[] c = Console.ReadLine().Split();
ulong a = ulong.Parse(c[0]);
decimal b = decimal.Parse(c[1]);
Console.WriteLine((ulong)(a * b));
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 77
| 4
|
using System;
using System.IO;
using System.Collections.Generic;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string[] arr = Console.ReadLine().Split(' ');
var a = int.Parse(arr[0]);
var b = double.Parse(arr[1]);
var sum = (int)(a * b);
Console.WriteLine(sum);
}
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string[] arr = Console.ReadLine().Split(' ');
var a = ulong.Parse(arr[0]);
var b = decimal.Parse(arr[1]);
var sum = (ulong)(a * b);
Console.WriteLine(sum);
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199]]
| 8
| 97
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
var list = new List<double>();
foreach (string s in input) {
list.Add(double.Parse(s));
}
double result = Math.Truncate(list[0] * list[1]);
Console.WriteLine(result);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
var list = new List<decimal>();
foreach (string s in input) {
list.Add(decimal.Parse(s));
}
decimal result = Math.Truncate(list[0] * list[1]);
Console.WriteLine(result);
}
}
|
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 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]]
| 8
| 105
| 6
|
using System;
class Program {
static void Main() {
// int N = Int32.Parse(Console.ReadLine());
string[] sarr =
Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
long A = Int64.Parse(sarr[0]);
double B = Convert.ToDouble(sarr[1]);
long C = A * (long)(B * 100);
Console.Write((long)(C / 100));
}
}
|
using System;
class Program {
static void Main() {
// int N = Int32.Parse(Console.ReadLine());
string[] sarr =
Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
long A = Int64.Parse(sarr[0]);
decimal B = Convert.ToDecimal(sarr[1]);
long C = A * (long)(B * 100);
Console.Write((long)(C / 100));
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 91
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC169C {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long A = long.Parse(input[0]);
double b = double.Parse(input[1]);
b = b * 100.0;
double kirisute = Math.Truncate(b);
// Console.WriteLine(kirisute);
string bstr = kirisute.ToString();
long B = long.Parse(bstr);
// Console.WriteLine(B);
long prod = A * B;
string ans = prod.ToString();
string str = ans.ToString();
int N = str.Length;
if (N > 2) {
string str2 = str.Remove(N - 2, 2);
Console.WriteLine(str2);
} else {
Console.WriteLine("0");
}
// Console.WriteLine(str);
// Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC169C {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long A = long.Parse(input[0]);
decimal b = decimal.Parse(input[1]);
// Console.WriteLine(b);
b = b * 100;
// Console.WriteLine(b);
decimal kirisute = Math.Floor(b);
// Console.WriteLine(kirisute);
string bstr = kirisute.ToString();
long B = long.Parse(bstr);
// Console.WriteLine(B);
long prod = A * B;
string ans = prod.ToString();
string str = ans.ToString();
int N = str.Length;
if (N > 2) {
string str2 = str.Remove(N - 2, 2);
Console.WriteLine(str2);
} else {
Console.WriteLine("0");
}
// Console.WriteLine(str);
// Console.WriteLine(ans);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 250], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 202
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace easy_Atcoder {
class Program {
static void Main(string[] args) {
double[] AB = Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
Console.WriteLine(Math.Floor(AB[0] * AB[1]));
// Console.WriteLine(AB[0]*AB[1]);
}
// float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
// long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// long N = NK[0];
// long K = NK[1];
// long K = long.Parse(Console.ReadLine());
// int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// string S = Console.ReadLine();
// int x = int.Parse(Console.ReadLine());
// int b = int.Parse(Console.ReadLine());
// int N = int.Parse(Console.ReadLine());
// float N = float.Parse(Console.ReadLine());
// string c = Console.ReadLine();
// string B = Console.ReadLine();
// string[] s = Console.ReadLine().Split();
// var s = (new string[] { Console.ReadLine(), Console.ReadLine(),
// Console.ReadLine() }).Select(float.Parse); float[] a =
// Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X =
// Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new
// int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[]
// s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new
// Dictionary<long,long>(); for(int i=0;i<s[0];i++){
// long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
// else{hs.Add(q[0],q[1]);}
// }
// //最小公倍数
// static long Lcm(long a, long b)
// {
// return a/Gcd(a,b)*b;
// }
// //最大公約数
// static long Gcd(long m, long n)
// {
// if(n==0)return m;
// return Gcd(n,m%n);
// }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace easy_Atcoder {
class Program {
static void Main(string[] args) {
decimal[] AB = Array.ConvertAll(Console.ReadLine().Split(), decimal.Parse);
Console.WriteLine(Math.Floor(AB[0] * AB[1]));
// Console.WriteLine(AB[0]*AB[1]);
}
// float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
// long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// long N = NK[0];
// long K = NK[1];
// long K = long.Parse(Console.ReadLine());
// int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// string S = Console.ReadLine();
// int x = int.Parse(Console.ReadLine());
// int b = int.Parse(Console.ReadLine());
// int N = int.Parse(Console.ReadLine());
// float N = float.Parse(Console.ReadLine());
// string c = Console.ReadLine();
// string B = Console.ReadLine();
// string[] s = Console.ReadLine().Split();
// var s = (new string[] { Console.ReadLine(), Console.ReadLine(),
// Console.ReadLine() }).Select(float.Parse); float[] a =
// Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X =
// Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new
// int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[]
// s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new
// Dictionary<long,long>(); for(int i=0;i<s[0];i++){
// long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
// else{hs.Add(q[0],q[1]);}
// }
// //最小公倍数
// static long Lcm(long a, long b)
// {
// return a/Gcd(a,b)*b;
// }
// //最大公約数
// static long Gcd(long m, long n)
// {
// if(n==0)return m;
// return Gcd(n,m%n);
// }
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
| 8
| 115
| 4
|
using System;
using System.Linq;
namespace ProblemC {
class Program {
static void Main() {
var temp = Console.ReadLine().Split(' ').ToArray();
long A = long.Parse(temp[0]);
double B = double.Parse(temp[1]);
long LB = (long)(B * 100);
long ans = LB * A;
Console.WriteLine(ans / 100);
}
}
}
|
using System;
using System.Linq;
namespace ProblemC {
class Program {
static void Main() {
var temp = Console.ReadLine().Split(' ').ToArray();
long A = long.Parse(temp[0]);
double B = double.Parse(temp[1]);
long LB = (long)(B * 100.000001);
long ans = LB * A;
Console.WriteLine(ans / 100);
}
}
}
|
[["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 250]]
| 8
| 97
| 4
|
using System;
using System.Linq;
namespace ProblemC {
class Program {
static void Main() {
var temp = Console.ReadLine().Split(' ').ToArray();
long A = long.Parse(temp[0]);
double B = double.Parse(temp[1]);
long LB = (long)(B * 100);
long ans = LB * A;
Console.WriteLine(ans / 100);
}
}
}
|
using System;
using System.Linq;
namespace ProblemC {
class Program {
static void Main() {
var temp = Console.ReadLine().Split(' ').ToArray();
long A = long.Parse(temp[0]);
decimal B = decimal.Parse(temp[1]);
long LB = (long)(B * 100);
long ans = LB * A;
Console.WriteLine(ans / 100);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 97
| 4
|
using System;
namespace fight3 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long A = long.Parse(input[0]);
double B = double.Parse(input[1]);
double C = Math.Floor(A * B);
Console.WriteLine(C);
}
}
}
|
using System;
namespace fight3 {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long A = long.Parse(input[0]);
decimal B = decimal.Parse(input[1]);
decimal C = Math.Floor(A * B);
Console.WriteLine(C);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 85
| 6
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
Console.WriteLine(
Math.Floor(double.Parse(input[0]) * double.Parse(input[1])));
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
Console.WriteLine(
Math.Floor(decimal.Parse(input[0]) * decimal.Parse(input[1])));
}
}
|
[["-", 0, 28, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 199], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 199]]
| 8
| 66
| 4
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
namespace hello_world {
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(" ");
int a = int.Parse(s[0]);
double b = double.Parse(s[1]);
double c = Math.Truncate(a * b);
Console.WriteLine(c);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
namespace hello_world {
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(" ");
decimal a = decimal.Parse(s[0]);
decimal b = decimal.Parse(s[1]);
decimal c = Math.Truncate(a * b);
Console.WriteLine(c);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 142
| 10
|
using System;
class Program {
static void Main() {
string[] In = Console.ReadLine().Split(' ');
double a = double.Parse(In[0]);
double b = double.Parse(In[1]);
Console.WriteLine(Math.Floor(a * b));
}
}
|
using System;
class Program {
static void Main() {
string[] In = Console.ReadLine().Split(' ');
decimal a = decimal.Parse(In[0]);
decimal b = decimal.Parse(In[1]);
Console.WriteLine(Decimal.Floor(a * b));
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22]]
| 8
| 72
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class {
static void Main(string[] args) {
var N = RL<string>();
long A = long.Parse(N[0]);
double B = double.Parse(N[1]);
long ans = (long)((A * (B * 100)) / 100);
Console.Write(ans);
}
static T[] RL<T>()
where T : IComparable {
if (typeof(T) == typeof(int)) {
return (T[])(object)Console.ReadLine()
.Trim()
.Split()
.Select(int.Parse)
.ToArray();
}
if (typeof(T) == typeof(long)) {
return (T[])(object)Console.ReadLine()
.Trim()
.Split()
.Select(long.Parse)
.ToArray();
}
if (typeof(T) == typeof(double)) {
return (T[])(object)Console.ReadLine()
.Trim()
.Split()
.Select(double.Parse)
.ToArray();
}
if (typeof(T) == typeof(decimal)) {
return (T[])(object)Console.ReadLine()
.Trim()
.Split()
.Select(decimal.Parse)
.ToArray();
}
return (T[])(object)Console.ReadLine().Trim().Split().ToArray();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class {
static void Main(string[] args) {
var N = RL<string>();
long A = long.Parse(N[0]);
decimal B = decimal.Parse(N[1]);
long ans = (long)((A * (B * 100)) / 100);
Console.Write(ans);
}
static T[] RL<T>()
where T : IComparable {
if (typeof(T) == typeof(int)) {
return (T[])(object)Console.ReadLine()
.Trim()
.Split()
.Select(int.Parse)
.ToArray();
}
if (typeof(T) == typeof(long)) {
return (T[])(object)Console.ReadLine()
.Trim()
.Split()
.Select(long.Parse)
.ToArray();
}
if (typeof(T) == typeof(double)) {
return (T[])(object)Console.ReadLine()
.Trim()
.Split()
.Select(double.Parse)
.ToArray();
}
if (typeof(T) == typeof(decimal)) {
return (T[])(object)Console.ReadLine()
.Trim()
.Split()
.Select(decimal.Parse)
.ToArray();
}
return (T[])(object)Console.ReadLine().Trim().Split().ToArray();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 333
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
double[] arr =
Console.ReadLine().Split(' ').Select(v => double.Parse(v)).ToArray();
double a = arr[0];
double b = arr[1];
b *= 100;
long al = (long)a;
long bl = (long)b;
long ansl = al * bl;
ansl /= 100;
Console.WriteLine(ansl);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
double[] arr =
Console.ReadLine().Split(' ').Select(v => double.Parse(v)).ToArray();
double a = arr[0];
double b = arr[1];
b = b * 100 + 0.5;
long al = (long)a;
long bl = (long)b;
long ansl = al * bl;
ansl /= 100;
Console.WriteLine(ansl);
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 250]]
| 8
| 123
| 6
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public void Solve() {
var items = Console.ReadLine().Split().ToArray();
var A = long.Parse(items[0]);
var B = (long)(double.Parse(items[1]) * 100);
var answer = (A * B).ToString("000");
Console.WriteLine(answer.Substring(0, answer.Length - 2));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public void Solve() {
var items = Console.ReadLine().Split().ToArray();
var A = decimal.Parse(items[0]);
var B = (decimal)(double.Parse(items[1]) * 100);
var answer = (A * B).ToString("000");
Console.WriteLine(answer.Substring(0, answer.Length - 2));
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199]]
| 8
| 204
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var A = sc.ReadLong();
var B = sc.ReadDouble();
var ans = (long)(A * B);
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var A = sc.ReadLong();
var B = (decimal)sc.ReadDouble();
var ans = (long)(A * B);
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25]]
| 8
| 1,097
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// int n = int.Parse(Console.ReadLine());
// 文字列配列の入力
string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// var inputintArray = Console.ReadLine().Split(' ').Select(i =>
// int.Parse(i)).ToArray();
var strA = inputStrArray[0];
long A = long.Parse(strA);
var strB = inputStrArray[1];
double B2 = double.Parse(strB);
long B = (long)(B2 * 100);
long result = A * B / 100;
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// int n = int.Parse(Console.ReadLine());
// 文字列配列の入力
string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// var inputintArray = Console.ReadLine().Split(' ').Select(i =>
// int.Parse(i)).ToArray();
var strA = inputStrArray[0];
long A = long.Parse(strA);
var strB = inputStrArray[1];
double B2 = double.Parse(strB);
long B = (long)(B2 * 100 + 0.5);
long result = A * B / 100;
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
[["+", 0, 212, 0, 74, 51, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 250]]
| 8
| 176
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderB {
static void Main() {
var sc = new Scanner();
decimal a = (decimal)sc.NextLong();
double b = sc.NextDouble();
decimal c = (decimal)(b * 100);
decimal answer = a * c / 100;
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderB {
static void Main() {
var sc = new Scanner();
decimal a = (decimal)sc.NextLong();
double b = sc.NextDouble();
decimal c = (decimal)(b * 100);
decimal answer = a * c / 100;
Console.WriteLine((long)answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25]]
| 8
| 383
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Abc169C {
public static void Main() {
var ab = Console.ReadLine().Split(' ').ToArray();
long a = long.Parse(ab[0]);
long b = (long)(double.Parse(ab[1]) * 100);
Console.WriteLine(a * b / 100);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Abc169C {
public static void Main() {
var ab = Console.ReadLine().Split(' ').ToArray();
long a = long.Parse(ab[0]);
long b = (long)(double.Parse(ab[1]) * 100 + 0.5);
Console.WriteLine(a * b / 100);
}
}
}
|
[["+", 0, 212, 0, 74, 51, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 250]]
| 8
| 95
| 2
|
//
// ABC169C
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_c
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace AtCoder {
class ABC169C {
public static readonly long MOD_CONST =
1000000007; //(long)Math.Pow(10, 9) + 7;
static void Main(string[] args) {
//出力高速化
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
string[] inputStrArray = Console.ReadLine().Split(' ');
long A = long.Parse(inputStrArray[0]);
double B = double.Parse(inputStrArray[1]);
Console.WriteLine(Math.Floor(A * B));
}
//---------------------------------------------------------------------------------
#region MyLib
/// <summary>
/// グラフ系
/// </summary>
public class Node {
public Node(long val) {
this.Value = val;
this.Children = new List<Node>();
}
public Node(long val, List<Node> children) {
this.Value = val;
this.Children = children;
}
public long Value { get; set; }
public List<Node> Children { get; set; }
}
/// <summary>
/// Clamping
/// </summary>
/// <typeparam name="T">比較型</typeparam>
/// <param name="x">clampしたい値</param>
/// <param name="min">最小値</param>
/// <param name="max">最大値</param>
/// <returns>clamp済みの値</returns>
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T> {
if (x.CompareTo(min) < 0) {
return min;
} else if (x.CompareTo(max) > 0) {
return max;
} else
return x;
// return Math.Max(Math.Min(x, max), min);
}
/// <summary>
/// 指定された底log_baseでの, 対数を計算
/// </summary>
/// <param name="x"></param>
/// <param name="log_base">指定の底</param>
/// <returns></returns>
public static double LogBase(double x, double log_base) {
// log_b(N) = log_a(N) / log_a(B)より
return Math.Log(x) / Math.Log(log_base);
}
/// <summary>
/// 初項a, 公差d, 項数nの数列の和
/// </summary>
/// <param name="n">求めたいところ</param>
/// <returns>初項からxまで足した値</returns>
static long SumSeries(long a, long d, long n) {
return (2 * a + (n - 1) * d) * n / 2;
}
/// <summary>
/// 累積和の配列を計算する
/// Sum[ a[0], a[i] )がs[i+1]に入っている
/// s[0] : 0 //一切和を取らない場合
/// s[1] : ls[0] //a[0] + s[0] = a[0]
/// s[2] : ls[1] + s[1] //a[1] + a[0]
/// ...
/// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0]
/// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0]
///
/// 例: [1, 7)の和(a[1] + ... + a[6])
/// s[1] = a[0] //[0, 1)
/// s[7] = a[0] + a[1] + ... + a[6] //[0, 7)
/// よってs[7] - s[1]);
/// </summary>
/// <param name="ls">計算したい配列</param>
/// <returns>累積和配列</returns>
static List<long> AggregateSumList(List<long> a) {
var s = new List<long>(a.Count + 1);
if (a.Count == 0) {
return s;
}
s.Add(0); // s[0] = 0
for (int i = 0; i < a.Count; ++i) {
s.Add(a[i] + s[i]);
}
return s;
}
/// <summary>
/// 与えられた数が素数かどうかを計算する
/// </summary>
/// <param name="num">対象数</param>
/// <returns>true:素数, false:素数ではない(合成数)</returns>
public static bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
/// <summary>
/// 順列mPnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Permutation(long m, long n) {
long ret = 1;
for (var i = 0; i < n; ++i) {
ret *= m - i;
}
return ret;
}
/// <summary>
/// 組み合わせmCnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Combination(long m, long n) {
if (m == n || n == 0) {
return 1;
}
long ans = 1;
for (var i = 1; i <= n; ++i) {
ans = ans * (m - i + 1) / i;
}
return ans;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
static long Lcm(long m, long n) {
var gcd = Gcd(m, n);
// return (m * n) / gcd;
return m / gcd * n; //桁あふれ対策
}
#endregion MyLib
}
}
|
//
// ABC169C
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_c
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace AtCoder {
class ABC169C {
public static readonly long MOD_CONST =
1000000007; //(long)Math.Pow(10, 9) + 7;
static void Main(string[] args) {
//出力高速化
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
string[] inputStrArray = Console.ReadLine().Split(' ');
var A = decimal.Parse(inputStrArray[0]);
var B = decimal.Parse(inputStrArray[1]);
Console.WriteLine(Math.Floor(A * B));
}
//---------------------------------------------------------------------------------
#region MyLib
/// <summary>
/// グラフ系
/// </summary>
public class Node {
public Node(long val) {
this.Value = val;
this.Children = new List<Node>();
}
public Node(long val, List<Node> children) {
this.Value = val;
this.Children = children;
}
public long Value { get; set; }
public List<Node> Children { get; set; }
}
/// <summary>
/// Clamping
/// </summary>
/// <typeparam name="T">比較型</typeparam>
/// <param name="x">clampしたい値</param>
/// <param name="min">最小値</param>
/// <param name="max">最大値</param>
/// <returns>clamp済みの値</returns>
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T> {
if (x.CompareTo(min) < 0) {
return min;
} else if (x.CompareTo(max) > 0) {
return max;
} else
return x;
// return Math.Max(Math.Min(x, max), min);
}
/// <summary>
/// 指定された底log_baseでの, 対数を計算
/// </summary>
/// <param name="x"></param>
/// <param name="log_base">指定の底</param>
/// <returns></returns>
public static double LogBase(double x, double log_base) {
// log_b(N) = log_a(N) / log_a(B)より
return Math.Log(x) / Math.Log(log_base);
}
/// <summary>
/// 初項a, 公差d, 項数nの数列の和
/// </summary>
/// <param name="n">求めたいところ</param>
/// <returns>初項からxまで足した値</returns>
static long SumSeries(long a, long d, long n) {
return (2 * a + (n - 1) * d) * n / 2;
}
/// <summary>
/// 累積和の配列を計算する
/// Sum[ a[0], a[i] )がs[i+1]に入っている
/// s[0] : 0 //一切和を取らない場合
/// s[1] : ls[0] //a[0] + s[0] = a[0]
/// s[2] : ls[1] + s[1] //a[1] + a[0]
/// ...
/// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0]
/// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0]
///
/// 例: [1, 7)の和(a[1] + ... + a[6])
/// s[1] = a[0] //[0, 1)
/// s[7] = a[0] + a[1] + ... + a[6] //[0, 7)
/// よってs[7] - s[1]);
/// </summary>
/// <param name="ls">計算したい配列</param>
/// <returns>累積和配列</returns>
static List<long> AggregateSumList(List<long> a) {
var s = new List<long>(a.Count + 1);
if (a.Count == 0) {
return s;
}
s.Add(0); // s[0] = 0
for (int i = 0; i < a.Count; ++i) {
s.Add(a[i] + s[i]);
}
return s;
}
/// <summary>
/// 与えられた数が素数かどうかを計算する
/// </summary>
/// <param name="num">対象数</param>
/// <returns>true:素数, false:素数ではない(合成数)</returns>
public static bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
/// <summary>
/// 順列mPnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Permutation(long m, long n) {
long ret = 1;
for (var i = 0; i < n; ++i) {
ret *= m - i;
}
return ret;
}
/// <summary>
/// 組み合わせmCnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Combination(long m, long n) {
if (m == n || n == 0) {
return 1;
}
long ans = 1;
for (var i = 1; i <= n; ++i) {
ans = ans * (m - i + 1) / i;
}
return ans;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
static long Lcm(long m, long n) {
var gcd = Gcd(m, n);
// return (m * n) / gcd;
return m / gcd * n; //桁あふれ対策
}
#endregion MyLib
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 772
| 8
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
double a, b;
a = double.Parse(input[0]);
b = double.Parse(input[1]);
Console.WriteLine("{0:D}", (long)Math.Floor(a * b));
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
decimal a, b;
a = decimal.Parse(input[0]);
b = decimal.Parse(input[1]);
Console.WriteLine("{0:D}", (long)Math.Floor(a * b));
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
| 8
| 86
| 6
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtCoder.ABC169 {
public class Problem3 {
public static void Main(string[] args) {
var a = Console.ReadLine().Split(" ");
var i = double.Parse(a[0]) * double.Parse(a[1]);
Console.WriteLine(Math.Floor(i).ToString());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtCoder.ABC169 {
public class Problem3 {
public static void Main(string[] args) {
var a = Console.ReadLine().Split(" ");
var i = decimal.Parse(a[0]) * decimal.Parse(a[1]);
Console.WriteLine(Math.Floor(i).ToString());
}
}
}
|
[["-", 0, 212, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 205, 199], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 205, 199], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 205, 199]]
| 8
| 93
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;
namespace AtCoderTemplate {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
double A = double.Parse(str[0]);
double B = double.Parse(str[1]);
Console.WriteLine(Math.Floor(A * B));
}
}
class MyLibrary {
// 自作の関数
public static int MyFunction(int n) { return 0; }
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;
namespace AtCoderTemplate {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
decimal A = Decimal.Parse(str[0]);
decimal B = Decimal.Parse(str[1]);
Console.WriteLine(Math.Floor(A * B));
}
}
class MyLibrary {
// 自作の関数
public static int MyFunction(int n) { return 0; }
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22]]
| 8
| 138
| 8
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace C {
class Program {
static void Main(string[] args) {
String[] AB = Console.ReadLine().Split(' ');
ulong A = ulong.Parse(AB[0]);
double B = double.Parse(AB[1]);
ulong ans = (ulong)((decimal)(A * B));
Console.WriteLine(ans);
Console.ReadLine();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace C {
class Program {
static void Main(string[] args) {
String[] AB = Console.ReadLine().Split(' ');
ulong A = ulong.Parse(AB[0]);
decimal B = decimal.Parse(AB[1]);
ulong ans = (ulong)((decimal)(A * B));
Console.WriteLine(ans);
Console.ReadLine();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 113
| 4
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
string[] AB = Console.ReadLine().Split(' ');
double A = double.Parse(AB[0]);
double B = double.Parse(AB[1]);
double C = 0;
C = A * B;
C = Math.Floor(C);
Console.WriteLine(C);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
string[] AB = Console.ReadLine().Split(' ');
decimal A = decimal.Parse(AB[0]);
decimal B = decimal.Parse(AB[1]);
decimal C = 0;
C = A * B;
C = Math.Floor(C);
Console.WriteLine(C);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 92
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC169 {
class C {
static void Main(string[] args) {
// var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
// var CA = Enumerable.Repeat(0, (int)N).Select(_ =>
// Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
// var N = long.Parse(Console.ReadLine());
var AB = Console.ReadLine().Split().Select(double.Parse).ToArray();
Console.WriteLine((long)Math.Floor(AB[0] * AB[1]));
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC169 {
class C {
static void Main(string[] args) {
// var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
// var CA = Enumerable.Repeat(0, (int)N).Select(_ =>
// Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
// var N = long.Parse(Console.ReadLine());
var AB = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
Console.WriteLine((decimal)Math.Floor(AB[0] * AB[1]));
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199]]
| 8
| 85
| 4
|
using System;
using System.Linq;
public class Test {
public static void Main() {
var x = Console.ReadLine().Split().ToArray();
long a = long.Parse(x[0]);
double c = double.Parse(x[1]);
c *= 100;
long b = (long)c;
long ans = a * b;
ans /= 100;
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
public class Test {
public static void Main() {
var x = Console.ReadLine().Split().ToArray();
long a = long.Parse(x[0]);
decimal c = decimal.Parse(x[1]);
c *= 100;
long b = (long)c;
long ans = a * b;
ans /= 100;
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 94
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static void Main() {
var AB = Console.ReadLine().Split();
long A = long.Parse(AB[0]);
double B = double.Parse(AB[1]);
double ans = Math.Floor(A * B);
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static void Main() {
var AB = Console.ReadLine().Split();
long A = long.Parse(AB[0]);
decimal B = decimal.Parse(AB[1]);
var ans = Math.Floor(A * B);
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217]]
| 8
| 85
| 6
|
using System;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var sp = Console.ReadLine().Split(' ');
var a = long.Parse(sp[0]);
var b = double.Parse(sp[1]);
var ans = (long)(a * b);
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
using System;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var sp = Console.ReadLine().Split(' ');
var a = decimal.Parse(sp[0]);
var b = decimal.Parse(sp[1]);
var ans = (long)(a * b);
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 123
| 4
|
using System;
using static System.Console;
using System.Linq;
namespace AC {
public class shiokara {
static void Main(string[] args) {
string[] s = ReadLine().Split(' ').ToArray();
double A = double.Parse(s[0]);
double B = double.Parse(s[1]);
WriteLine(Math.Floor(A * B));
}
}
}
|
using System;
using static System.Console;
using System.Linq;
namespace AC {
public class shiokara {
static void Main(string[] args) {
string[] s = ReadLine().Split(' ').ToArray();
decimal A = decimal.Parse(s[0]);
decimal B = decimal.Parse(s[1]);
WriteLine(Math.Truncate(A * B));
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
| 8
| 92
| 10
|
using System;
namespace ABC {
public class C {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
double A = double.Parse(input[0]);
double B = double.Parse(input[1]);
double C = A * B;
double D = Math.Floor(C);
Console.WriteLine(D);
}
}
}
|
using System;
namespace ABC {
public class C {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
decimal A = decimal.Parse(input[0]);
decimal B = decimal.Parse(input[1]);
decimal C = A * B;
decimal D = Math.Floor(C);
Console.WriteLine(D);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 87
| 12
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
using System.IO;
namespace paiza {
class Program {
static void Main(string[] args) {
var A = GetLong();
var B = GetDouble();
long Bd = (long)(B + 0.001) * 100;
long ans = (A * Bd) / 100;
Console.WriteLine(ans);
return;
}
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(int N) =>
Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
public static long[] GetLongs(int N) =>
Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
public static double[] GetDoubles(int N) =>
Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
public static string[] GetStrings(int N) =>
Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
using System.IO;
namespace paiza {
class Program {
static void Main(string[] args) {
var A = GetLong();
var B = GetDouble();
long Bd = (long)((B + 0.001) * 100);
long ans = (A * Bd) / 100;
Console.WriteLine(ans);
return;
}
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(int N) =>
Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
public static long[] GetLongs(int N) =>
Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
public static double[] GetDoubles(int N) =>
Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
public static string[] GetStrings(int N) =>
Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}
|
[["+", 0, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 74, 51, 23, 0, 25]]
| 8
| 385
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.At_Coder_Beginner_Contest_169 {
class C {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long A = long.Parse(input[0]);
double B = double.Parse(input[1]);
Console.WriteLine(Math.Truncate(A * B));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.At_Coder_Beginner_Contest_169 {
class C {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long A = long.Parse(input[0]);
decimal B = decimal.Parse(input[1]);
Console.WriteLine(Math.Truncate(A * B));
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 106
| 4
|
using System;
using System.Linq;
namespace ABC169C {
class Program {
static void Main(string[] args) {
var AB = Console.ReadLine().Split().Select(double.Parse).ToArray();
var A = AB[0];
var B = AB[1];
Console.WriteLine(Math.Truncate(A * B).ToString("0"));
}
}
}
|
using System;
using System.Linq;
namespace ABC169C {
class Program {
static void Main(string[] args) {
var AB = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
var A = AB[0];
var B = AB[1];
Console.WriteLine(Math.Truncate(A * B).ToString("0"));
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
| 8
| 88
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProconTemplate {
// https://atcoder.jp/contests/abc141/tasks/abc141_c
class abc169_b {
public static void Main(string[] args) {
// string s = Console.ReadLine();
string[] asInput = Console.ReadLine().Split(' ');
long A = long.Parse(asInput[0]);
float B = float.Parse(asInput[1]);
Console.WriteLine(A * (long)(100 * B) / 100);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProconTemplate {
// https://atcoder.jp/contests/abc141/tasks/abc141_c
class abc169_b {
public static void Main(string[] args) {
// string s = Console.ReadLine();
string[] asInput = Console.ReadLine().Split(' ');
long A = long.Parse(asInput[0]);
decimal B = decimal.Parse(asInput[1]);
Console.WriteLine(A * (long)(100 * B) / 100);
// Console.WriteLine(A * B);
// return;
////int Q = int.Parse(asInput[2]);
// Console.ReadLine();
// long[] p = Console.ReadLine().Split(' ').Select(s =>
// long.Parse(s)).ToArray(); long lAns = p[0];
// for (int i = 1; i < p.Length; i++)
//{
// if (1000000000000000000 / lAns < p[i])
// {
// lAns = -1;
// break;
// }
// lAns *= p[i];
//}
// Console.WriteLine(lAns);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 111
| 4
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
string[] ab = Console.ReadLine().Split(' ');
long a = long.Parse(ab[0]);
double b = double.Parse(ab[1]);
double res = a * b;
Console.WriteLine((long)res);
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
string[] ab = Console.ReadLine().Split(' ');
long a = long.Parse(ab[0]);
decimal b = decimal.Parse(ab[1]);
decimal res = a * b;
Console.WriteLine((long)res);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 84
| 6
|
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.IO.Enumeration;
using System.Linq;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Extensions;
using DSA;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
ulong a = (ulong)(long)Cin;
double b = Cin;
ulong c = (ulong)(b * 100);
Coutln(a * c / 100);
}
}
// Other Classes Here
class Node {
public int Index { get; set; }
public List<Node> Connections { get; } = new List<Node>();
public void AddConnection(Node n) {
this.Connections.Add(n);
n.Connections.Add(this);
}
}
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
namespace DSA {
/// <summary>
/// 二分ヒープによる優先度付きキュー
/// </summary>
/// <typeparam name="T">内部に格納するデータ型</typeparam>
public class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count => _list.Count;
public PriorityQueue() {}
/// <summary>
/// 要素をひとつ入力する
/// O(logN)
/// </summary>
/// <param name="item">要素</param>
/// <param name="priority">優先度</param>
public void Push(T item, int priority) {
_list.Add(Tuple.Create(priority, item));
int itemIndex = Count - 1, parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > _list[parentIndex].Item1) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return Tuple.Create(item1, item2);
}
/// <summary>
/// 優先度の一番大きい要素を取得し削除する
/// O(logN)
/// </summary>
/// <returns>優先度の一番大きい要素</returns>
/// <exception
/// cref="IndexOutOfRangeException">キューが空だった場合</exception>
public T Pop() {
if (Count <= 0)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = _list[Count - 1];
_list.RemoveAt(Count - 1);
int index = 0;
Tuple<int, int> childrenIndex = GetChildrenIndex(index);
while (childrenIndex.Item1 < Count || childrenIndex.Item2 < Count) {
if (childrenIndex.Item2 >= Count ||
_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) {
if (_list[childrenIndex.Item1].Item1 <= _list[index].Item1)
return item;
Swap(index, childrenIndex.Item1);
index = childrenIndex.Item1;
} else {
if (_list[childrenIndex.Item2].Item1 <= _list[index].Item1)
return item;
Swap(index, childrenIndex.Item2);
index = childrenIndex.Item2;
}
childrenIndex = GetChildrenIndex(index);
}
return item;
}
/// <summary>
/// 優先度の一番大きい要素を取得する(削除はしない)
/// O(1)
/// </summary>
/// <returns>優先度の一番大きい要素</returns>
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
/// <summary>
/// マージをサポートするUnionFind木
/// </summary>
public class UnionFind {
private readonly int[] _array;
/// <summary>
/// 要素数を指定しUnionFind木を初期化する
/// O(N)
/// </summary>
/// <param name="size">UnionFind木の要素数</param>
public UnionFind(int size) {
_array = new int[size];
for (int i = 0; i < size; i++) {
_array[i] = i;
}
}
/// <summary>
/// 根を取得する
/// 同じグループに属する要素は同じ要素を根として持つ
/// O(α(n))
/// </summary>
/// <param name="n">根を取得したい要素</param>
/// <returns>根となる要素</returns>
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
/// <summary>
/// ふたつの要素が所属するグループを併合する
/// O(α(N))
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
/// <summary>
/// ふたつの要素が同じグループに所属するかを確かめる
/// O(α(N))
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns>ふたつの要素が同じグループに所属する⇔true</returns>
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
}
public delegate T SegTreeCombiner<T>(T item1, T item2);
public class SegTree<T> {
private readonly T _defaultItem;
private readonly SegTreeCombiner<T> _func;
private T[] List;
private int size;
public SegTree(T[] list, T defaultItem, SegTreeCombiner<T> func) {
_defaultItem = defaultItem;
_func = func;
size = 1;
while (size < list.Length)
size <<= 1;
List = new T[2 * size - 1];
for (int i = 0; i < list.Length; i++)
List[i + size - 1] = list[i];
for (int i = list.Length; i < size; i++)
List[i + size - 1] = defaultItem;
for (int i = size - 1 - 1; i >= 0; i--) {
List[i] = _func(List[2 * i + 1], List[2 * i + 2]);
}
}
public void Update(int index, T value) {
index += size - 1;
List[index] = value;
while (index > 0) {
index = (index - 1) >> 1;
List[index] = _func(List[2 * index + 1], List[2 * index + 2]);
}
}
public T Query(int a, int b) { return Query(a, b, 0, 0, size); }
private T Query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return _defaultItem;
if (a <= l && r <= b)
return List[k];
return _func(Query(a, b, k * 2 + 1, l, (l + r) >> 1),
Query(a, b, k * 2 + 2, (l + r) >> 1, r));
}
}
public static class BinarySearch {
public delegate bool Terms<T>(T i);
public static int UpperBound(int initLeft, int initRight, Terms<int> term) {
// TODO:範囲内に条件を満たす区間が存在しない場合に対応する
int left = initLeft - 1, right = initRight;
while (right - left > 1) {
int mid = (left + right) >> 1;
if (mid != initLeft - 1 && term(mid))
left = mid;
else
right = mid;
}
return left;
}
public static long UpperBound(long initLeft, long initRight,
Terms<long> term) {
long left = initLeft - 1, right = initRight;
while (right - left > 1) {
long mid = (left + right) >> 1;
if (mid != initLeft - 1 && term(mid))
left = mid;
else
right = mid;
}
return left;
}
public static int LowerBound(int initLeft, int initRight, Terms<int> term) {
int left = initLeft - 1, right = initRight;
while (right - left > 1) {
int mid = (left + right) >> 1;
if (mid != initRight && term(mid))
right = mid;
else
left = mid;
}
return right;
}
public static long LowerBound(long initLeft, long initRight,
Terms<long> term) {
long left = initLeft - 1, right = initRight;
while (right - left > 1) {
long mid = (left + right) >> 1;
if (term(mid))
right = mid;
else
left = mid;
}
return right;
}
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static implicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
if (b == 0)
return a;
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
if (b == 0)
return a;
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.IO.Enumeration;
using System.Linq;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Extensions;
using DSA;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
ulong a = (ulong)(long)Cin;
double b = Cin;
ulong c = (ulong)(Round(b * 1000));
Coutln(a * c / 1000);
}
}
// Other Classes Here
class Node {
public int Index { get; set; }
public List<Node> Connections { get; } = new List<Node>();
public void AddConnection(Node n) {
this.Connections.Add(n);
n.Connections.Add(this);
}
}
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
namespace DSA {
/// <summary>
/// 二分ヒープによる優先度付きキュー
/// </summary>
/// <typeparam name="T">内部に格納するデータ型</typeparam>
public class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count => _list.Count;
public PriorityQueue() {}
/// <summary>
/// 要素をひとつ入力する
/// O(logN)
/// </summary>
/// <param name="item">要素</param>
/// <param name="priority">優先度</param>
public void Push(T item, int priority) {
_list.Add(Tuple.Create(priority, item));
int itemIndex = Count - 1, parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > _list[parentIndex].Item1) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return Tuple.Create(item1, item2);
}
/// <summary>
/// 優先度の一番大きい要素を取得し削除する
/// O(logN)
/// </summary>
/// <returns>優先度の一番大きい要素</returns>
/// <exception
/// cref="IndexOutOfRangeException">キューが空だった場合</exception>
public T Pop() {
if (Count <= 0)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = _list[Count - 1];
_list.RemoveAt(Count - 1);
int index = 0;
Tuple<int, int> childrenIndex = GetChildrenIndex(index);
while (childrenIndex.Item1 < Count || childrenIndex.Item2 < Count) {
if (childrenIndex.Item2 >= Count ||
_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) {
if (_list[childrenIndex.Item1].Item1 <= _list[index].Item1)
return item;
Swap(index, childrenIndex.Item1);
index = childrenIndex.Item1;
} else {
if (_list[childrenIndex.Item2].Item1 <= _list[index].Item1)
return item;
Swap(index, childrenIndex.Item2);
index = childrenIndex.Item2;
}
childrenIndex = GetChildrenIndex(index);
}
return item;
}
/// <summary>
/// 優先度の一番大きい要素を取得する(削除はしない)
/// O(1)
/// </summary>
/// <returns>優先度の一番大きい要素</returns>
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
/// <summary>
/// マージをサポートするUnionFind木
/// </summary>
public class UnionFind {
private readonly int[] _array;
/// <summary>
/// 要素数を指定しUnionFind木を初期化する
/// O(N)
/// </summary>
/// <param name="size">UnionFind木の要素数</param>
public UnionFind(int size) {
_array = new int[size];
for (int i = 0; i < size; i++) {
_array[i] = i;
}
}
/// <summary>
/// 根を取得する
/// 同じグループに属する要素は同じ要素を根として持つ
/// O(α(n))
/// </summary>
/// <param name="n">根を取得したい要素</param>
/// <returns>根となる要素</returns>
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
/// <summary>
/// ふたつの要素が所属するグループを併合する
/// O(α(N))
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
/// <summary>
/// ふたつの要素が同じグループに所属するかを確かめる
/// O(α(N))
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns>ふたつの要素が同じグループに所属する⇔true</returns>
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
}
public delegate T SegTreeCombiner<T>(T item1, T item2);
public class SegTree<T> {
private readonly T _defaultItem;
private readonly SegTreeCombiner<T> _func;
private T[] List;
private int size;
public SegTree(T[] list, T defaultItem, SegTreeCombiner<T> func) {
_defaultItem = defaultItem;
_func = func;
size = 1;
while (size < list.Length)
size <<= 1;
List = new T[2 * size - 1];
for (int i = 0; i < list.Length; i++)
List[i + size - 1] = list[i];
for (int i = list.Length; i < size; i++)
List[i + size - 1] = defaultItem;
for (int i = size - 1 - 1; i >= 0; i--) {
List[i] = _func(List[2 * i + 1], List[2 * i + 2]);
}
}
public void Update(int index, T value) {
index += size - 1;
List[index] = value;
while (index > 0) {
index = (index - 1) >> 1;
List[index] = _func(List[2 * index + 1], List[2 * index + 2]);
}
}
public T Query(int a, int b) { return Query(a, b, 0, 0, size); }
private T Query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return _defaultItem;
if (a <= l && r <= b)
return List[k];
return _func(Query(a, b, k * 2 + 1, l, (l + r) >> 1),
Query(a, b, k * 2 + 2, (l + r) >> 1, r));
}
}
public static class BinarySearch {
public delegate bool Terms<T>(T i);
public static int UpperBound(int initLeft, int initRight, Terms<int> term) {
// TODO:範囲内に条件を満たす区間が存在しない場合に対応する
int left = initLeft - 1, right = initRight;
while (right - left > 1) {
int mid = (left + right) >> 1;
if (mid != initLeft - 1 && term(mid))
left = mid;
else
right = mid;
}
return left;
}
public static long UpperBound(long initLeft, long initRight,
Terms<long> term) {
long left = initLeft - 1, right = initRight;
while (right - left > 1) {
long mid = (left + right) >> 1;
if (mid != initLeft - 1 && term(mid))
left = mid;
else
right = mid;
}
return left;
}
public static int LowerBound(int initLeft, int initRight, Terms<int> term) {
int left = initLeft - 1, right = initRight;
while (right - left > 1) {
int mid = (left + right) >> 1;
if (mid != initRight && term(mid))
right = mid;
else
left = mid;
}
return right;
}
public static long LowerBound(long initLeft, long initRight,
Terms<long> term) {
long left = initLeft - 1, right = initRight;
while (right - left > 1) {
long mid = (left + right) >> 1;
if (term(mid))
right = mid;
else
left = mid;
}
return right;
}
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static implicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
if (b == 0)
return a;
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
if (b == 0)
return a;
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
[["+", 0, 212, 0, 74, 51, 23, 0, 213, 63, 22], ["+", 0, 74, 51, 23, 0, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 74, 51, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 2,670
| 7
|
using System;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
double[] nm =
Array.ConvertAll(System.Console.ReadLine().Split(' '), double.Parse);
long n = (long)nm[0];
int m = (int)(nm[1] * 100);
System.Console.WriteLine(n * m / 100);
}
}
}
|
using System;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
decimal[] nm =
Array.ConvertAll(System.Console.ReadLine().Split(' '), decimal.Parse);
long n = (long)nm[0];
int m = (int)(nm[1] * 100);
System.Console.WriteLine(n * m / 100);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
| 8
| 90
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string[] Input = Console.ReadLine().Split(' ');
double A = double.Parse(Input[0]);
double B = double.Parse(Input[1]);
Console.WriteLine(Math.Floor(A * B));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string[] Input = Console.ReadLine().Split(' ');
decimal A = decimal.Parse(Input[0]);
decimal B = decimal.Parse(Input[1]);
Console.WriteLine(Math.Floor(A * B));
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 100
| 8
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.C {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var t = ReadTexts();
var A = double.Parse(t[0]);
var B = double.Parse(t[1]);
return Math.Floor(A * B);
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.C {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var t = ReadTexts();
var A = decimal.Parse(t[0]);
var B = decimal.Parse(t[1]);
return Math.Floor(A * B);
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 391
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var Stemp = Console.ReadLine().Split(' ');
long A = long.Parse(Stemp[0]);
long B = (long)(double.Parse(Stemp[1]) * 100);
Console.WriteLine((long)Math.Floor((double)(A * B) / 100));
}
// 1000000007
}
// dotnet run --project test
|
using System;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var Stemp = Console.ReadLine().Split(' ');
long A = long.Parse(Stemp[0]);
long B = (long)(Decimal.Parse(Stemp[1]) * 100);
Console.WriteLine((long)Math.Floor((Decimal)(A * B) / 100));
}
// 1000000007
}
// dotnet run --project test
|
[["-", 51, 23, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 51, 23, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 22]]
| 8
| 105
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public decimal[] Sarray() {
return ReadLine().Split().Select(decimal.Parse).ToArray();
}
static public List<int> Slist() {
return new List<int>(ReadLine().Split().Select(int.Parse));
}
static void Main(string[] args) {
var AN = Sarray();
var tmp = (AN[0] * 100) * (AN[1] * 100);
WriteLine(tmp / 10000);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public decimal[] Sarray() {
return ReadLine().Split().Select(decimal.Parse).ToArray();
}
static public List<int> Slist() {
return new List<int>(ReadLine().Split().Select(int.Parse));
}
static void Main(string[] args) {
var AN = Sarray();
var tmp = (AN[0] * 100) * (AN[1] * 100);
WriteLine(Math.Floor(tmp / 10000));
}
}
}
|
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 171
| 5
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
long A = long.Parse(str[0]);
double B = double.Parse(str[1]);
long C = (long)(B * 100);
long ans = A * C / 100;
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
long A = long.Parse(str[0]);
double B = double.Parse(str[1]);
long C = (long)(B * 100 + 0.0001);
long ans = A * C / 100;
Console.WriteLine(ans);
}
}
|
[["+", 0, 212, 0, 74, 51, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 250]]
| 8
| 94
| 2
|
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;
static void Main(string[] args) {
var r = ReadSplit();
var a = r[0].Double();
var b = r[1].Double();
var ans = Math.Floor(a * b);
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;
}
}
}
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;
static void Main(string[] args) {
var r = ReadSplit();
var a = r[0].Decimal();
var b = r[1].Decimal();
long ans = (long)(a * b);
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;
}
}
}
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, 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, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 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]]
| 8
| 673
| 12
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var line =
ReadLine().Split(' ').Select(value => double.Parse(value)).ToArray();
WriteLine((long)(line[0] * line[1]));
}
}
}
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var line =
ReadLine().Split(' ').Select(value => decimal.Parse(value)).ToArray();
WriteLine((long)(line[0] * line[1]));
}
}
}
|
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199]]
| 8
| 96
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class C {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() { WriteLine((long)Floor(GetDouble() * GetDouble())); }
}
public static class MyIO {
private static string[] args = new string[0];
private static int cnt = 0;
private static IEnumerable<string>
getArgs(long N) => Range(0, N).Select(_ => getArg());
private static string getArg() {
if (cnt == args.Length) {
args = Console.ReadLine().Split();
cnt = 0;
}
return args[cnt++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static decimal GetDecimal() => decimal.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
public static long[] GetLongs(long N) =>
getArgs(N).Select(long.Parse).ToArray();
public static double[] GetDoubles(long N) =>
getArgs(N).Select(double.Parse).ToArray();
public static decimal[] GetDecimals(long N) =>
getArgs(N).Select(decimal.Parse).ToArray();
public static string[] GetStrings(long N) => getArgs(N).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
public static long rightShift(long x, long y) => (x >> (int)y);
public static long leftShift(long x, long y) => (x << (int)y);
public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
public static long lcm(long x, long y) => (x / gcd(x, y)) * y;
public static IEnumerable<int>
Range(long start, long count) => Enumerable.Range((int)start, (int)count);
public static void
Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;
public class C {
public static void Main() => (new Solver()).Solve();
}
public class Solver {
public void Solve() { WriteLine((long)Floor(GetDecimal() * GetDecimal())); }
}
public static class MyIO {
private static string[] args = new string[0];
private static int cnt = 0;
private static IEnumerable<string>
getArgs(long N) => Range(0, N).Select(_ => getArg());
private static string getArg() {
if (cnt == args.Length) {
args = Console.ReadLine().Split();
cnt = 0;
}
return args[cnt++];
}
public static int GetInt() => int.Parse(getArg());
public static long GetLong() => long.Parse(getArg());
public static double GetDouble() => double.Parse(getArg());
public static decimal GetDecimal() => decimal.Parse(getArg());
public static string GetString() => getArg();
public static char GetChar() => getArg()[0];
public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
public static long[] GetLongs(long N) =>
getArgs(N).Select(long.Parse).ToArray();
public static double[] GetDoubles(long N) =>
getArgs(N).Select(double.Parse).ToArray();
public static decimal[] GetDecimals(long N) =>
getArgs(N).Select(decimal.Parse).ToArray();
public static string[] GetStrings(long N) => getArgs(N).ToArray();
}
public static class MyUtil {
public static void chmax<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) < 0)
x = y;
}
public static void chmin<T>(ref T x, T y)
where T : IComparable<T> {
if (x.CompareTo(y) > 0)
x = y;
}
public static void swap<T>(ref T x, ref T y) {
T tmp = x;
x = y;
y = tmp;
}
public static long rightShift(long x, long y) => (x >> (int)y);
public static long leftShift(long x, long y) => (x << (int)y);
public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
public static long lcm(long x, long y) => (x / gcd(x, y)) * y;
public static IEnumerable<int>
Range(long start, long count) => Enumerable.Range((int)start, (int)count);
public static void
Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}
|
[["-", 3, 4, 0, 28, 0, 16, 31, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 213, 63, 22]]
| 8
| 699
| 4
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
#else
checked {
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
}
#endif
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var a = double.Parse(spl[0]);
var b = double.Parse(spl[1]);
return (long)(a * b);
}
static long[] ToIntArray(string strs, int n) {
var ret = new long[n];
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = long.Parse(spl[i]);
return ret;
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
#else
checked {
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
}
#endif
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var a = decimal.Parse(spl[0]);
var b = decimal.Parse(spl[1]);
return (long)(a * b);
}
static long[] ToIntArray(string strs, int n) {
var ret = new long[n];
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = long.Parse(spl[i]);
return ret;
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 269
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class362 {
static void Main() {
long N = long.Parse(Console.ReadLine());
var dic = new Dictionary<long, int>();
for (long i = 2; i <= (int)Math.Sqrt(N); i++) {
while (N % i == 0) {
N /= i;
if (!dic.ContainsKey(i)) {
dic[i] = 1;
} else {
dic[i]++;
}
}
}
if (N != 1)
dic[N] = 1;
long count = 0;
foreach (int i in dic.Keys) {
long s = 0;
long c = 0;
for (c = 1; s <= dic[i]; c++) {
s += c;
}
count += c - 2;
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class362 {
static void Main() {
long N = long.Parse(Console.ReadLine());
var dic = new Dictionary<long, int>();
for (long i = 2; i <= (int)Math.Sqrt(N); i++) {
while (N % i == 0) {
N /= i;
if (!dic.ContainsKey(i)) {
dic[i] = 1;
} else {
dic[i]++;
}
}
}
if (N != 1)
dic[N] = 1;
long count = 0;
foreach (long i in dic.Keys) {
long s = 0;
long c = 0;
for (c = 1; s <= dic[i]; c++) {
s += c;
}
count += c - 2;
}
Console.WriteLine(count);
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199]]
| 8
| 209
| 2
|
using System;
namespace atcoder_practice1 {
class _169D {
static void Main() {
long N;
int count;
int answer = 0;
string x = Console.ReadLine();
N = long.Parse(x);
long max_iter = (long)Math.Sqrt(N);
for (long i = 2; i <= max_iter; i++) {
count = 0;
while (N % i == 0) {
N /= i;
count++;
}
answer += (int)((-1 + Math.Sqrt(1 + 8 * count)) / 2);
}
if (answer == 0) {
answer = 1;
}
Console.WriteLine(answer);
}
}
}
|
using System;
namespace atcoder_practice1 {
class _169D {
static void Main() {
long N;
int count;
int answer = 0;
string x = Console.ReadLine();
N = long.Parse(x);
long max_iter = (long)Math.Sqrt(N);
for (long i = 2; i <= max_iter; i++) {
count = 0;
while (N % i == 0) {
N /= i;
count++;
}
answer += (int)((-1 + Math.Sqrt(1 + 8 * count)) / 2);
}
if (N != 1) {
answer += 1;
}
Console.WriteLine(answer);
}
}
}
|
[["-", 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], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
| 8
| 141
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleAppTest {
class DivGame {
static void Main(string[] args) {
ulong num = ulong.Parse(Console.ReadLine());
// ulong num = 4;
ulong checkNum = (ulong)Math.Sqrt(num);
int methodNum = 0;
if (num < 2) {
Console.WriteLine(0);
} else {
for (ulong i = 2; i <= checkNum; i += 2) {
int powCnt = 0;
int popCnt = 1;
while (num % i == 0) {
powCnt++;
num /= i;
if (powCnt == popCnt) {
methodNum++;
popCnt++;
powCnt = 0;
}
}
if (i == 2) {
i--;
}
}
if (methodNum == 0) {
methodNum = 1;
}
Console.WriteLine(methodNum);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleAppTest {
class DivGame {
static void Main(string[] args) {
ulong num = ulong.Parse(Console.ReadLine());
// ulong num = 24;
ulong checkNum = (ulong)Math.Sqrt(num);
int methodNum = 0;
if (num < 2) {
Console.WriteLine(methodNum);
} else {
for (ulong i = 2; i <= checkNum; i += 2) {
int powCnt = 0;
int popCnt = 1;
while (num % i == 0) {
powCnt++;
num /= i;
if (powCnt == popCnt) {
methodNum++;
popCnt++;
powCnt = 0;
}
}
if (i == 2) {
i--;
}
}
if (num > checkNum) {
methodNum++;
}
Console.WriteLine(methodNum);
}
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29]]
| 8
| 189
| 11
|
using System;
using System.Collections.Generic;
namespace ABC169test {
class Program {
static void Main(string[] args) {
long N = Convert.ToInt64(Console.ReadLine());
if (N == 1) {
Console.WriteLine(0);
return;
}
// Prime.soinsuu(N);
var list = Prime.PrimeFactors(N);
var list2 = new List<long>();
long count = 0;
long tmp = list[0];
int i = 0;
list2.Add(1);
for (int j = 0; j < list.Count; j++) {
if (list[j] == tmp)
list2[i]++;
else {
tmp = list[j];
i++;
list2.Add(1);
}
}
for (int j = 0; j < list2.Count; j++) {
for (int k = 1; k <= list2[j]; k++) {
list2[j] -= k;
count++;
}
}
Console.WriteLine(count);
/*
int count = 0;
bool check = false;
long _z;
for (long z=2; z<=N; z++)
{
//Console.WriteLine("N {0}, z {1}", N, z);
//z判定
for(long p=2; p<=z; p++)
{
check = false;
if (IsPrime(p))
{
_z = z;
while (true)
{
if (_z % p != 0)
break;
_z /= p;
if(_z == 1)//z判定OK
check = true;
//Console.WriteLine("p {0}", p);
}
}
if (check)
break;
}
if (check)
{
if (N % z == 0)
{
N /= z;
count++;
}
}
}
Console.Write(count);*/
}
public static bool IsPrime(long num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
}
public class Prime {
public static void soinsuu(long n) {
// long n = long.Parse(Console.ReadLine());
Console.WriteLine("{0} = {1}", n, string.Join(" x ", PrimeFactors(n)));
}
public static List<long> PrimeFactors(long n) {
long i = 2;
long tmp = n;
var list = new List<long>();
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
list.Add(i);
} else {
i++;
}
}
if (tmp != 1)
list.Add(tmp);
return list;
// if (tmp != 1) yield return tmp;//最後の素数も返す
}
}
}
|
using System;
using System.Collections.Generic;
namespace ABC169test {
class Program {
static void Main(string[] args) {
long N = Convert.ToInt64(Console.ReadLine());
if (N == 1) {
Console.WriteLine(0);
return;
}
// Prime.soinsuu(N);
var list = Prime.PrimeFactors(N);
var list2 = new List<long>();
long count = 0;
long tmp = list[0];
int i = 0;
list2.Add(0);
for (int j = 0; j < list.Count; j++) {
if (list[j] == tmp)
list2[i]++;
else {
tmp = list[j];
i++;
list2.Add(1);
}
}
for (int j = 0; j < list2.Count; j++) {
for (int k = 1; k <= list2[j]; k++) {
list2[j] -= k;
count++;
}
}
Console.WriteLine(count);
/*
int count = 0;
bool check = false;
long _z;
for (long z=2; z<=N; z++)
{
//Console.WriteLine("N {0}, z {1}", N, z);
//z判定
for(long p=2; p<=z; p++)
{
check = false;
if (IsPrime(p))
{
_z = z;
while (true)
{
if (_z % p != 0)
break;
_z /= p;
if(_z == 1)//z判定OK
check = true;
//Console.WriteLine("p {0}", p);
}
}
if (check)
break;
}
if (check)
{
if (N % z == 0)
{
N /= z;
count++;
}
}
}
Console.Write(count);*/
}
public static bool IsPrime(long num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
}
public class Prime {
public static void soinsuu(long n) {
// long n = long.Parse(Console.ReadLine());
Console.WriteLine("{0} = {1}", n, string.Join(" x ", PrimeFactors(n)));
}
public static List<long> PrimeFactors(long n) {
long i = 2;
long tmp = n;
var list = new List<long>();
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
list.Add(i);
} else {
i++;
}
}
if (tmp != 1)
list.Add(tmp);
return list;
// if (tmp != 1) yield return tmp;//最後の素数も返す
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 432
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
internal class QuestionD {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
long n = long.Parse(Console.ReadLine());
var primeFactors = PrimeFactors.PrimeFactorsImpl(n);
var a = primeFactors.GroupBy(v => v).Select(
x => new { Factor = x.Key, Count = x.Count() });
string result = a.Select(v => {
var i = 1;
var count = v.Count;
while (true) {
count -= i;
if (count >= i) {
i++;
} else {
break;
}
}
return i;
})
.Sum()
.ToString();
Console.WriteLine(result);
Console.Out.Flush();
}
}
internal class PrimeFactors {
/// <summary>
/// 素因数分解。
/// 出展:https://qiita.com/y_miyoshi/items/da814d96e8890224aad3
/// </summary>
public static IEnumerable<long> PrimeFactorsImpl(long n) {
long i = 2;
long tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp; //最後の素数も返す
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
internal class QuestionD {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
long n = long.Parse(Console.ReadLine());
var primeFactors = PrimeFactors.PrimeFactorsImpl(n);
var a = primeFactors.GroupBy(v => v).Select(
x => new { Factor = x.Key, Count = x.Count() });
string result = a.Select(v => {
var i = 1;
var count = v.Count;
while (true) {
count -= i;
if (count > i) {
i++;
} else {
break;
}
}
return i;
})
.Sum()
.ToString();
Console.WriteLine(result);
Console.Out.Flush();
}
}
internal class PrimeFactors {
/// <summary>
/// 素因数分解。
/// 出展:https://qiita.com/y_miyoshi/items/da814d96e8890224aad3
/// </summary>
public static IEnumerable<long> PrimeFactorsImpl(long n) {
long i = 2;
long tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp; //最後の素数も返す
}
}
}
|
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 292
| 2
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
long n = Input.NextLong();
Dictionary<long, long> p = new Dictionary<long, long>();
long m = n;
for (long i = 2; i * i <= n; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
p.Add(i, ex);
}
}
if (m >= 1) {
p.Add(m, 1);
}
HashSet<long> divLog = new HashSet<long>();
long ans = 0;
foreach (var kv in p) {
long max = kv.Value;
long cnt = 0;
for (int i = 1; cnt + i <= max; i++) {
for (int j = 0; j < i; j++) {
n /= kv.Key;
}
cnt += i;
ans += 1;
}
}
Console.WriteLine(ans);
}
#region よく使う便利関数
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
long n = Input.NextLong();
Dictionary<long, long> p = new Dictionary<long, long>();
long m = n;
for (long i = 2; i * i <= n; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
p.Add(i, ex);
}
}
if (m >= 2) {
p.Add(m, 1);
}
HashSet<long> divLog = new HashSet<long>();
long ans = 0;
foreach (var kv in p) {
long max = kv.Value;
long cnt = 0;
for (int i = 1; cnt + i <= max; i++) {
for (int j = 0; j < i; j++) {
n /= kv.Key;
}
cnt += i;
ans += 1;
}
}
Console.WriteLine(ans);
}
#region よく使う便利関数
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 2,590
| 2
|
using System;
using System.Collections.Generic;
namespace ProblemD {
class Program {
static void Main() {
long N = long.Parse(Console.ReadLine());
var list = new List<long>();
if (N == 1) {
Console.WriteLine(0);
return;
} else {
foreach (long factor in PrimeFactors(N)) {
list.Add(factor);
}
var used = new List<long>();
long count = 0;
long number = 1;
for (int i = 0; i < list.Count;) {
if (number == 1 || number % list[i - 1] == 0) {
number *= list[i];
} else {
number = list[i];
}
if (used.Contains(number)) {
i++;
} else {
count++;
list.RemoveAt(i);
used.Add(number);
number = 1;
}
}
Console.WriteLine(count);
}
}
public static IEnumerable<long> PrimeFactors(long n) {
long i = 2;
long tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
}
}
|
using System;
using System.Collections.Generic;
namespace ProblemD {
class Program {
static void Main() {
long N = long.Parse(Console.ReadLine());
var list = new List<long>();
if (N == 1) {
Console.WriteLine(0);
return;
} else {
foreach (long factor in PrimeFactors(N)) {
list.Add(factor);
}
var used = new List<long>();
long count = 0;
long number = 1;
for (int i = 0; i < list.Count;) {
if (number == 1 || number % list[i] == 0) {
number *= list[i];
} else {
number = list[i];
}
if (used.Contains(number)) {
i++;
} else {
count++;
list.RemoveAt(i);
used.Add(number);
number = 1;
}
}
Console.WriteLine(count);
}
}
public static IEnumerable<long> PrimeFactors(long n) {
long i = 2;
long tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
}
}
|
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 274
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public int x;
public int a;
public int b;
public int c;
public Pair(int X, int Y, int Z, int D) {
x = X;
a = Y;
b = Z;
c = D;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.a <= p2.a;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.a >= p2.a;
}
}
}
class Program {
static bool[] visited;
static List<int>[] togo;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long n = scan.Long();
if (n == 1) {
Console.WriteLine(0);
return;
}
long m = n;
long ans = 0;
for (long i = 2; i * i <= m; i++) {
long kosu = 0;
for (kosu = 0; kosu < m; kosu++) {
if (n % i == 0) {
n /= i;
} else {
break;
}
}
long sum = 0;
long j = 0;
for (j = 1; j < m; j++) {
sum += j;
if (kosu < sum) {
break;
}
}
ans += j - 1;
}
if (m != 1) {
ans += 1;
}
/* List< CPair<long,long>> kore = SoinsuBunkai(n);
for (int i = 0; i < kore.Count; i++)
{
long kosu = kore[i].Item2;
long sum = 0;
long j = 1;
for ( j = 1; j < n; j++)
{
sum += j;
if(kosu < sum) { break; }
}
ans += j-1;
}*/
Console.WriteLine(ans);
}
static bool Isprime(long n) {
for (long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
static bool DFS(int now, int last) {
visited[now] = true;
for (int i = 0; i < togo[now].Count; i++) {
if (togo[now][i] == last) {
continue;
}
if (visited[togo[now][i]]) {
return false;
}
if (!DFS(togo[now][i], now)) {
return false;
}
}
return true;
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public List<int> Topological_Sort(List<List<Edge>> G) {
var ret = new List<int>();
var Nodes = new Queue<int>();
int N = G.Count();
var Link = new int[N];
for (var i = 0; i < N; i++) {
Link[i] = 0;
}
for (var i = 0; i < N; i++) {
foreach (var nx in G[i]) {
Link[nx.to]++;
}
}
for (var i = 0; i < N; i++) {
if (Link[i] == 0) {
Nodes.Enqueue(i);
}
}
while (Nodes.Any()) {
var nd = Nodes.Dequeue();
ret.Add(nd);
foreach (var nx in G[nd]) {
Link[nx.to]--;
if (Link[nx.to] == 0) {
Nodes.Enqueue(nx.to);
}
}
}
return ret;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(int n, int m) {
char[,] kore = new char[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
public static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public int x;
public int a;
public int b;
public int c;
public Pair(int X, int Y, int Z, int D) {
x = X;
a = Y;
b = Z;
c = D;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.a <= p2.a;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.a >= p2.a;
}
}
}
class Program {
static bool[] visited;
static List<int>[] togo;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long n = scan.Long();
if (n == 1) {
Console.WriteLine(0);
return;
}
long m = n;
long ans = 0;
for (long i = 2; i * i <= m; i++) {
long kosu = 0;
for (kosu = 0; kosu < m; kosu++) {
if (n % i == 0) {
n /= i;
} else {
break;
}
}
long sum = 0;
long j = 0;
for (j = 1; j < m; j++) {
sum += j;
if (kosu < sum) {
break;
}
}
ans += j - 1;
}
if (n != 1) {
ans += 1;
}
/* List< CPair<long,long>> kore = SoinsuBunkai(n);
for (int i = 0; i < kore.Count; i++)
{
long kosu = kore[i].Item2;
long sum = 0;
long j = 1;
for ( j = 1; j < n; j++)
{
sum += j;
if(kosu < sum) { break; }
}
ans += j-1;
}*/
Console.WriteLine(ans);
}
static bool Isprime(long n) {
for (long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
static bool DFS(int now, int last) {
visited[now] = true;
for (int i = 0; i < togo[now].Count; i++) {
if (togo[now][i] == last) {
continue;
}
if (visited[togo[now][i]]) {
return false;
}
if (!DFS(togo[now][i], now)) {
return false;
}
}
return true;
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public List<int> Topological_Sort(List<List<Edge>> G) {
var ret = new List<int>();
var Nodes = new Queue<int>();
int N = G.Count();
var Link = new int[N];
for (var i = 0; i < N; i++) {
Link[i] = 0;
}
for (var i = 0; i < N; i++) {
foreach (var nx in G[i]) {
Link[nx.to]++;
}
}
for (var i = 0; i < N; i++) {
if (Link[i] == 0) {
Nodes.Enqueue(i);
}
}
while (Nodes.Any()) {
var nd = Nodes.Dequeue();
ret.Add(nd);
foreach (var nx in G[nd]) {
Link[nx.to]--;
if (Link[nx.to] == 0) {
Nodes.Enqueue(nx.to);
}
}
}
return ret;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(int n, int m) {
char[,] kore = new char[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
public static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
| 8
| 11,977
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder.Contests.ABC169 {
/// <summary>
///
/// </summary>
static class D {
static void Main(string[] args) {
var n = NextLong();
var count = 0;
var f = Math.Floor(Math.Sqrt((double)n));
for (int i = 2; i <= f; i++) {
if (n % i != 0) {
continue;
}
var p = i;
while (n % p == 0) {
count++;
n = n / p;
p *= i;
}
while (n % i == 0) {
n = n / i;
}
}
if (count == 0 && n > 1) {
count++;
}
Console.WriteLine(count);
}
#region Console
static int _index = 0;
static string[] _buffer;
static string Next() {
if (_buffer == null || _index >= _buffer.Length) {
_buffer = Console.ReadLine().Split();
_index = 0;
}
return _buffer[_index++];
}
static int NextInt() { return int.Parse(Next()); }
static long NextLong() { return long.Parse(Next()); }
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
#endregion
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder.Contests.ABC169 {
/// <summary>
///
/// </summary>
static class D {
static void Main(string[] args) {
var n = NextLong();
var count = 0;
var f = Math.Floor(Math.Sqrt((double)n));
for (int i = 2; i <= f + 1; i++) {
if (n % i != 0) {
continue;
}
var p = i;
while (n % p == 0) {
count++;
n = n / p;
p *= i;
}
while (n % i == 0) {
n = n / i;
}
}
if (n > 1) {
count++;
}
Console.WriteLine(count);
}
#region Console
static int _index = 0;
static string[] _buffer;
static string Next() {
if (_buffer == null || _index >= _buffer.Length) {
_buffer = Console.ReadLine().Split();
_index = 0;
}
return _buffer[_index++];
}
static int NextInt() { return int.Parse(Next()); }
static long NextLong() { return long.Parse(Next()); }
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
#endregion
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 616
| 6
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Contest.E {
static class Program {
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
int n = cin.NextInt();
var a = new int[n];
var b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = cin.NextInt();
b[i] = cin.NextInt();
}
Array.Sort(a);
Array.Sort(b);
long ans = 0;
if (n % 2 == 0) {
double midmin = (a[(n + 1) / 2 - 1] + a[(n + 1) / 2]) / 2;
double midmax = (b[(n + 1) / 2 - 1] + b[(n + 1) / 2]) / 2;
ans = (long)((midmax - midmin) * 2) + 1;
} else {
long midmin = a[n / 2];
long midmax = b[n / 2];
ans = midmax - midmin + 1;
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
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.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Contest.E {
static class Program {
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
int n = cin.NextInt();
var a = new int[n];
var b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = cin.NextInt();
b[i] = cin.NextInt();
}
Array.Sort(a);
Array.Sort(b);
long ans = 0;
if (n % 2 == 0) {
double midmin = (double)(a[(n + 1) / 2 - 1] + a[(n + 1) / 2]) / 2;
double midmax = (double)(b[(n + 1) / 2 - 1] + b[(n + 1) / 2]) / 2;
ans = (long)((midmax - midmin) * 2) + 1;
} else {
long midmin = a[n / 2];
long midmax = b[n / 2];
ans = midmax - midmin + 1;
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return Next();
i = 0;
return s[i++];
}
public int NextInt() { return int.Parse(Next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = NextInt() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
}
}
|
[["+", 0, 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], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24]]
| 8
| 659
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class363 {
static void Main() {
int N = int.Parse(Console.ReadLine());
var A = new int[N];
var B = new int[N];
for (int i = 0; i < N; i++) {
var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
A[i] = ab[0];
B[i] = ab[1];
}
Array.Sort(A);
Array.Sort(B);
double min = 0;
double max = 0;
if (N % 2 == 0) {
min = (double)(A[N / 2 - 1] + A[N / 2]) / 2;
max = (double)(B[N / 2 - 1] + B[N / 2]) / 2;
Console.WriteLine(Math.Ceiling(max - min) * 2 + 1);
} else {
min = A[N / 2];
max = B[N / 2];
Console.WriteLine(Math.Ceiling(max - min) + 1);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class363 {
static void Main() {
int N = int.Parse(Console.ReadLine());
var A = new int[N];
var B = new int[N];
for (int i = 0; i < N; i++) {
var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
A[i] = ab[0];
B[i] = ab[1];
}
Array.Sort(A);
Array.Sort(B);
double min = 0;
double max = 0;
if (N % 2 == 0) {
min = (double)(A[N / 2 - 1] + A[N / 2]) / 2;
max = (double)(B[N / 2 - 1] + B[N / 2]) / 2;
Console.WriteLine((long)((max - min) * 2 + 1));
} else {
min = A[N / 2];
max = B[N / 2];
Console.WriteLine(Math.Ceiling(max - min) + 1);
}
}
}
}
|
[["-", 0, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 51, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25]]
| 8
| 271
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
static double Median(long[] x) {
x = x.OrderBy(xx => xx).ToArray();
var n = x.Length;
if (n % 2 == 0) {
return (x[n / 2 - 1] + x[n / 2]) / 2;
} else {
return x[n / 2];
}
}
public static void Main() {
var N = int.Parse(Console.ReadLine());
var min = new long[N];
var max = new long[N];
for (int i = 0; i < N; i++) {
var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
min[i] = vals[0];
max[i] = vals[1];
}
var left = Median(min);
var right = Median(max);
var answer = right - left;
if (N % 2 == 0) {
answer *= 2;
}
answer++;
Console.WriteLine(answer);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
static double Median(long[] x) {
x = x.OrderBy(xx => xx).ToArray();
var n = x.Length;
if (n % 2 == 0) {
return (x[n / 2 - 1] + (double)x[n / 2]) / 2;
} else {
return x[n / 2];
}
}
public static void Main() {
var N = int.Parse(Console.ReadLine());
var min = new long[N];
var max = new long[N];
for (int i = 0; i < N; i++) {
var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
min[i] = vals[0];
max[i] = vals[1];
}
var left = Median(min);
var right = Median(max);
var answer = right - left;
if (N % 2 == 0) {
answer *= 2;
}
answer++;
Console.WriteLine(answer);
}
}
|
[["+", 0, 16, 31, 23, 0, 16, 12, 74, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 16, 31, 23, 0, 16, 12, 74, 0, 25]]
| 8
| 245
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProblemE {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var As = new List<int>();
var Bs = new List<int>();
for (int i = 0; i < N; i++) {
var read =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
As.Add(read[0]);
Bs.Add(read[1]);
}
As.Sort();
Bs = Bs.OrderBy(x => x).ToList();
if (N % 2 == 0) {
var median_ind1 = (N / 2) - 1;
var median_ind2 = (N / 2 + 1) - 1;
var lower1 = As[median_ind1];
var lower2 = As[median_ind2];
var upper1 = Bs[median_ind1];
var upper2 = Bs[median_ind2];
var res = (lower2 + upper2) - (lower1 + upper1) + 1;
Console.WriteLine(res);
} else {
var median_ind = (N + 1) / 2 - 1;
var lower = As[median_ind];
var upper = Bs[median_ind];
Console.WriteLine(upper - lower + 1);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProblemE {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var As = new List<int>();
var Bs = new List<int>();
for (int i = 0; i < N; i++) {
var read =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
As.Add(read[0]);
Bs.Add(read[1]);
}
As.Sort();
Bs = Bs.OrderBy(x => x).ToList();
if (N % 2 == 0) {
var median_ind1 = (N / 2) - 1;
var median_ind2 = (N / 2 + 1) - 1;
var lower1 = As[median_ind1];
var lower2 = As[median_ind2];
var upper1 = Bs[median_ind1];
var upper2 = Bs[median_ind2];
var res = (upper1 + upper2) - (lower1 + lower2) + 1;
Console.WriteLine(res);
} else {
var median_ind = (N + 1) / 2 - 1;
var lower = As[median_ind];
var upper = Bs[median_ind];
Console.WriteLine(upper - lower + 1);
}
}
}
}
|
[["-", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 12, 22]]
| 8
| 304
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
var inputArray = retreiveLongArray();
var inputCount = 1;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
int N = (int)inputArray[0];
var Aarray = new List<long>();
var Barray = new List<long>();
for (int i = 0; i < N; i++) {
var input = retreiveLongArray();
Aarray.Add(input[0]);
Barray.Add(input[1]);
}
var Asorted = Aarray.OrderBy(x => x).ToList();
var Bsorted = Barray.OrderBy(x => x).ToList();
var Amid = getMedian(N, Asorted);
var Bmid = getMedian(N, Bsorted);
//答えの出力
var ans = N % 2 == 0 ? (Bmid - Amid) * 2 + 1 : (Bmid - Amid) + 1;
Console.WriteLine(ans);
}
private static long getMedian(int N, List<long> sorted) {
if (N % 2 == 0) {
return (sorted[N / 2 - 1] + sorted[N / 2]) / 2;
} else {
return sorted[N / 2];
}
}
/// <summary>
/// スペースで区切られた文字列配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// スペースで区切られた整数配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
var inputArray = retreiveLongArray();
var inputCount = 1;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
int N = (int)inputArray[0];
var Aarray = new List<long>();
var Barray = new List<long>();
for (int i = 0; i < N; i++) {
var input = retreiveLongArray();
Aarray.Add(input[0]);
Barray.Add(input[1]);
}
var Asorted = Aarray.OrderBy(x => x).ToList();
var Bsorted = Barray.OrderBy(x => x).ToList();
var Amid = getMedian(N, Asorted);
var Bmid = getMedian(N, Bsorted);
//答えの出力
var ans = N % 2 == 0 ? (Bmid - Amid) * 2 + 1 : (Bmid - Amid) + 1;
Console.WriteLine(ans);
}
private static double getMedian(int N, List<long> sorted) {
if (N % 2 == 0) {
return (sorted[N / 2 - 1] + sorted[N / 2]) / 2.0;
} else {
return sorted[N / 2];
}
}
/// <summary>
/// スペースで区切られた文字列配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// スペースで区切られた整数配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
}
}
|
[["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 0, 57, 64, 196, 0, 37, 0, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 37, 0, 16, 12, 250]]
| 8
| 388
| 4
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[][] A = new int [N][];
for (var i = 0; i < N; i++) {
A[i] = new int[2];
}
for (var i = 0; i < N; i++) {
string[] str = Console.ReadLine().Split();
A[i][0] = int.Parse(str[0]);
A[i][1] = int.Parse(str[1]);
}
Array.Sort(A, (x, y) => x[0] - y[0]);
int ans = 0;
if (N % 2 == 1) {
int a1 = A[N / 2][0];
Array.Sort(A, (x, y) => x[1] - y[1]);
int a2 = A[N / 2][1];
ans = a2 - a1 + 1;
} else {
int a1 = A[N / 2 - 1][0];
int a2 = A[N / 2][0];
Array.Sort(A, (x, y) => x[1] - y[1]);
int b1 = A[N / 2 - 1][1];
int b2 = A[N / 2][1];
ans = a2 + b2 - (a1 + b1) + 1;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[][] A = new int [N][];
for (var i = 0; i < N; i++) {
A[i] = new int[2];
}
for (var i = 0; i < N; i++) {
string[] str = Console.ReadLine().Split();
A[i][0] = int.Parse(str[0]);
A[i][1] = int.Parse(str[1]);
}
Array.Sort(A, (x, y) => x[0] - y[0]);
int ans = 0;
if (N % 2 == 1) {
int a1 = A[N / 2][0];
Array.Sort(A, (x, y) => x[1] - y[1]);
int a2 = A[N / 2][1];
ans = a2 - a1 + 1;
} else {
int a1 = A[N / 2 - 1][0];
int a2 = A[N / 2][0];
Array.Sort(A, (x, y) => x[1] - y[1]);
int b1 = A[N / 2 - 1][1];
int b2 = A[N / 2][1];
ans = b1 + b2 - (a2 + a1) + 1;
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 11, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 22]]
| 8
| 346
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Numerics;
using System.Threading;
using static System.Math;
using static System.Array;
using static AtCoder.IO_ShortCut;
using static AtCoder.Tool;
using static AtCoder.ModInt;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
// const int MOD = 998244353;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 };
static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 };
// static List<List<int>> G = new List<List<int>>();
static List<List<Edge>> G = new List<List<Edge>>();
// static List<Edge> E = new List<Edge>();
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
/*var th = new Thread(Run, 1 << 26);
th.Start();
th.Join();*/
Run();
Console.Out.Flush();
}
static void Run() {
int Testcase = 1;
for (var _ = 0; _ < Testcase; _++)
Solve();
}
static void Solve() {
int N, S;
Input(out N, out S);
var A = _ReadSplitInt;
var dp = new ModInt[N + 1, S + 1];
dp[0, 0] = 1;
for (var i = 0; i < N; i++) {
for (var j = 0; j <= S; j++) {
dp[i + 1, j] += dp[i, j] * 2;
if (j + A[i] <= S)
dp[i + 1, j + A[i]] += dp[i, j];
}
}
OutL(dp[N, S].value);
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
}
struct ModInt {
public long value;
private const int MOD = 1000000007;
// private const int MOD = 998244353;
public ModInt(long value) { this.value = value; }
public static implicit operator ModInt(long a) {
var ret = a % MOD;
return new ModInt(ret < 0 ? (ret + MOD) : ret);
}
public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value);
public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value);
public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value);
public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2);
public static ModInt operator <<(ModInt a, int n) => (a.value << n);
public static ModInt operator>>(ModInt a, int n) => (a.value >> n);
public static ModInt operator ++(ModInt a) => a.value + 1;
public static ModInt operator --(ModInt a) => a.value - 1;
public static ModInt Modpow(ModInt a, long n) {
var k = a;
ModInt ret = 1;
while (n > 0) {
if ((n & 1) != 0)
ret *= k;
k *= k;
n >>= 1;
}
return ret;
}
private static readonly List<long> Factorials = new List<long>() { 1 };
public static ModInt Fac(long n) {
for (var i = Factorials.Count(); i <= n; i++) {
Factorials.Add((Factorials[i - 1] * i) % MOD);
}
return Factorials[(int)n];
}
public static ModInt nCr(long n, long r) {
return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(ModInt a) => (int)a.value;
}
static class IO_ShortCut {
public static string[] _ReadSplit => Console.ReadLine().Split();
public static int[] _ReadSplitInt =>
ConvertAll(Console.ReadLine().Split(), int.Parse);
public static long[] _ReadSplitLong =>
ConvertAll(Console.ReadLine().Split(), long.Parse);
public static double[] _ReadSplit_Double =>
ConvertAll(Console.ReadLine().Split(), double.Parse);
public static string Str => Console.ReadLine();
public static int Int => int.Parse(Console.ReadLine());
public static long Long => long.Parse(Console.ReadLine());
public static double Double => double.Parse(Console.ReadLine());
public static T Conv<T>(string input) {
if (typeof(T).Equals(typeof(ModInt))) {
return (T)(dynamic)(long.Parse(input));
}
return (T)Convert.ChangeType(input, typeof(T));
}
public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine());
public static void Input<T, U>(out T a, out U b) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
}
public static void Input<T, U, V>(out T a, out U b, out V c) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
}
public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
d = Conv<W>(q[3]);
}
public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
d = Conv<W>(q[3]);
e = Conv<X>(q[4]);
}
public static void OutL(object s) => Console.WriteLine(s);
public static void
Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s));
public static void Out_Sep<T>(IEnumerable<T> s, string sep) =>
Console.WriteLine(string.Join($"{sep}", s));
public static void
Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s));
public static void Out_One(object s) => Console.Write($"{s} ");
public static void Out_One(object s,
string sep) => Console.Write($"{s}{sep}");
public static void Endl() => Console.WriteLine();
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = ConvertAll(array, x => initialvalue);
}
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Display<T>(T[,] array2d, int n, int m) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
Console.Write($"{array2d[i, j]} ");
}
Console.WriteLine();
}
}
static public long Gcd(long a, long b) {
if (a == 0 || b == 0)
return Max(a, b);
return a % b == 0 ? b : Gcd(b, a % b);
}
static public long LPow(int a, int b) => (long)Pow(a, b);
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Numerics;
using System.Threading;
using static System.Math;
using static System.Array;
using static AtCoder.IO_ShortCut;
using static AtCoder.Tool;
using static AtCoder.ModInt;
namespace AtCoder {
class AC {
// const int MOD = 1000000007;
const int MOD = 998244353;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 };
static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 };
// static List<List<int>> G = new List<List<int>>();
static List<List<Edge>> G = new List<List<Edge>>();
// static List<Edge> E = new List<Edge>();
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
/*var th = new Thread(Run, 1 << 26);
th.Start();
th.Join();*/
Run();
Console.Out.Flush();
}
static void Run() {
int Testcase = 1;
for (var _ = 0; _ < Testcase; _++)
Solve();
}
static void Solve() {
int N, S;
Input(out N, out S);
var A = _ReadSplitInt;
var dp = new ModInt[N + 1, S + 1];
dp[0, 0] = 1;
for (var i = 0; i < N; i++) {
for (var j = 0; j <= S; j++) {
dp[i + 1, j] += dp[i, j] * 2;
if (j + A[i] <= S)
dp[i + 1, j + A[i]] += dp[i, j];
}
}
OutL(dp[N, S].value);
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
}
struct ModInt {
public long value;
// private const int MOD = 1000000007;
private const int MOD = 998244353;
public ModInt(long value) { this.value = value; }
public static implicit operator ModInt(long a) {
var ret = a % MOD;
return new ModInt(ret < 0 ? (ret + MOD) : ret);
}
public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value);
public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value);
public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value);
public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2);
public static ModInt operator <<(ModInt a, int n) => (a.value << n);
public static ModInt operator>>(ModInt a, int n) => (a.value >> n);
public static ModInt operator ++(ModInt a) => a.value + 1;
public static ModInt operator --(ModInt a) => a.value - 1;
public static ModInt Modpow(ModInt a, long n) {
var k = a;
ModInt ret = 1;
while (n > 0) {
if ((n & 1) != 0)
ret *= k;
k *= k;
n >>= 1;
}
return ret;
}
private static readonly List<long> Factorials = new List<long>() { 1 };
public static ModInt Fac(long n) {
for (var i = Factorials.Count(); i <= n; i++) {
Factorials.Add((Factorials[i - 1] * i) % MOD);
}
return Factorials[(int)n];
}
public static ModInt nCr(long n, long r) {
return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(ModInt a) => (int)a.value;
}
static class IO_ShortCut {
public static string[] _ReadSplit => Console.ReadLine().Split();
public static int[] _ReadSplitInt =>
ConvertAll(Console.ReadLine().Split(), int.Parse);
public static long[] _ReadSplitLong =>
ConvertAll(Console.ReadLine().Split(), long.Parse);
public static double[] _ReadSplit_Double =>
ConvertAll(Console.ReadLine().Split(), double.Parse);
public static string Str => Console.ReadLine();
public static int Int => int.Parse(Console.ReadLine());
public static long Long => long.Parse(Console.ReadLine());
public static double Double => double.Parse(Console.ReadLine());
public static T Conv<T>(string input) {
if (typeof(T).Equals(typeof(ModInt))) {
return (T)(dynamic)(long.Parse(input));
}
return (T)Convert.ChangeType(input, typeof(T));
}
public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine());
public static void Input<T, U>(out T a, out U b) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
}
public static void Input<T, U, V>(out T a, out U b, out V c) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
}
public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
d = Conv<W>(q[3]);
}
public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
d = Conv<W>(q[3]);
e = Conv<X>(q[4]);
}
public static void OutL(object s) => Console.WriteLine(s);
public static void
Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s));
public static void Out_Sep<T>(IEnumerable<T> s, string sep) =>
Console.WriteLine(string.Join($"{sep}", s));
public static void
Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s));
public static void Out_One(object s) => Console.Write($"{s} ");
public static void Out_One(object s,
string sep) => Console.Write($"{s}{sep}");
public static void Endl() => Console.WriteLine();
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = ConvertAll(array, x => initialvalue);
}
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Display<T>(T[,] array2d, int n, int m) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
Console.Write($"{array2d[i, j]} ");
}
Console.WriteLine();
}
}
static public long Gcd(long a, long b) {
if (a == 0 || b == 0)
return Max(a, b);
return a % b == 0 ? b : Gcd(b, a % b);
}
static public long LPow(int a, int b) => (long)Pow(a, b);
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a));
}
}
|
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 1,870
| 4
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var s = sc.Ia;
var a = sc.Ia;
var dp = new Mint[s[1] + 1];
dp[0] = Fp(2, s[0]);
for (int i = 0; i < s[0]; i++) {
for (int j = s[1]; j >= a[i]; j--) {
dp[j] += dp[j - a[i]] / 2;
}
}
Console.WriteLine("{0}", dp[s[1]]);
}
static long Fp(long x, long e) {
long r = 1;
while (e > 0) {
if ((e & 1) > 0) {
r *= x;
r %= mod;
}
x = (x * x) % mod;
e >>= 1;
}
return r;
}
}
public struct Mint {
const int mod = 998244353;
private long d;
public Mint(long d) { this.d = d; }
public static implicit operator Mint(long d) { return new Mint(d % mod); }
public static explicit operator long(Mint d) { return d.d; }
public override string ToString() { return d.ToString(); }
public static Mint operator +(Mint a, long b) {
a.d = (a.d + b) % mod;
return a;
}
public static Mint operator +(Mint a, Mint b) {
a.d = (a.d + b.d) % mod;
return a;
}
public static Mint operator -(Mint a, long b) {
a.d = (mod + a.d - b) % mod;
return a;
}
public static Mint operator -(Mint a, Mint b) {
a.d = (mod + a.d - b.d) % mod;
return a;
}
public static Mint operator *(Mint a, long b) {
a.d = (a.d * b) % mod;
return a;
}
public static Mint operator *(Mint a, Mint b) {
a.d = (a.d * b.d) % mod;
return a;
}
public static Mint operator /(Mint a, long b) {
a.d = (a.d * Mi(b)) % mod;
return a;
}
public static Mint operator /(Mint a, Mint b) {
a.d = (a.d * Mi(b.d)) % mod;
return a;
}
private static long Mi(long a) {
a = (a + mod) % mod;
long b = mod, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
a ^= b;
b ^= a;
a ^= b;
u -= t * v;
u ^= v;
v ^= u;
u ^= v;
}
u %= mod;
if (u < 0) {
u += mod;
}
return u % mod;
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
double.Parse);
}
public double[] Da3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = 998244353;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var s = sc.Ia;
var a = sc.Ia;
var dp = new Mint[s[1] + 1];
dp[0] = Fp(2, s[0]);
for (int i = 0; i < s[0]; i++) {
for (int j = s[1]; j >= a[i]; j--) {
dp[j] += dp[j - a[i]] / 2;
}
}
Console.WriteLine("{0}", dp[s[1]]);
}
static long Fp(long x, long e) {
long r = 1;
while (e > 0) {
if ((e & 1) > 0) {
r *= x;
r %= mod;
}
x = (x * x) % mod;
e >>= 1;
}
return r;
}
}
public struct Mint {
const int mod = 998244353;
private long d;
public Mint(long d) { this.d = d; }
public static implicit operator Mint(long d) { return new Mint(d % mod); }
public static explicit operator long(Mint d) { return d.d; }
public override string ToString() { return d.ToString(); }
public static Mint operator +(Mint a, long b) {
a.d = (a.d + b) % mod;
return a;
}
public static Mint operator +(Mint a, Mint b) {
a.d = (a.d + b.d) % mod;
return a;
}
public static Mint operator -(Mint a, long b) {
a.d = (mod + a.d - b) % mod;
return a;
}
public static Mint operator -(Mint a, Mint b) {
a.d = (mod + a.d - b.d) % mod;
return a;
}
public static Mint operator *(Mint a, long b) {
a.d = (a.d * b) % mod;
return a;
}
public static Mint operator *(Mint a, Mint b) {
a.d = (a.d * b.d) % mod;
return a;
}
public static Mint operator /(Mint a, long b) {
a.d = (a.d * Mi(b)) % mod;
return a;
}
public static Mint operator /(Mint a, Mint b) {
a.d = (a.d * Mi(b.d)) % mod;
return a;
}
private static long Mi(long a) {
a = (a + mod) % mod;
long b = mod, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
a ^= b;
b ^= a;
a ^= b;
u -= t * v;
u ^= v;
v ^= u;
u ^= v;
}
u %= mod;
if (u < 0) {
u += mod;
}
return u % mod;
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
double.Parse);
}
public double[] Da3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
[["-", 0, 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, 200, 0, 212, 0, 16, 31, 74, 51, 250], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 1,671
| 7
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramF a = new ProgramF();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
// a*bを出す
Console.WriteLine(a * b);
}
}
class ProgramB {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long ans = 1;
long[] a = new long[n];
long INF = 1000000000000000000;
for (int i = 0; i < n; i++)
a[i] = long.Parse(s[i]);
//小さい順に並べる
Array.Sort(a);
//試しに小さい順に割ってみてもし0になるなら10の18乗超えるんで-1を出す。
for (int i = 0; i < n; i++) {
if (a[i] == 0)
break;
INF /= a[i];
if (INF == 0) {
Console.WriteLine("-1");
return;
}
}
//普通にかけていく
for (int i = 0; i < n; i++) {
ans *= a[i];
}
//答え出力
Console.WriteLine(ans);
}
}
class ProgramC {
public void main() {
//入力(decimal型だと桁精度が27桁ぐらいまである
string[] s = Console.ReadLine().Split(' ');
decimal a = decimal.Parse(s[0]);
decimal b = decimal.Parse(s[1]);
//かけてlong型で出せば切り捨て
Console.WriteLine((long)(a * b));
}
}
class ProgramD {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
long temp = n;
long ans = 0;
//平方根をとって素因数分解
for (int i = 2; i <= Math.Sqrt(n); i++) {
//もし割り切れるならその回数を考える
if (temp % i == 0) {
int count = 0;
int count2 = 1;
int ans_temp = 1;
//割り切れなくなるまで続ける
while (temp % i == 0) {
count++; //割った回数
temp /= i;
if (ans_temp == count) {
count2++; //ここに入ってきた回数
ans_temp +=
count2; //入ってきた数を足す(すると次に入るべき数になる1→3→6→10...)
ans++; //ここに入れば答えなので足す
}
}
}
}
//あまったのが平方根以上であればそれも素因数なので加算する
if (temp > Math.Sqrt(n))
ans++;
//答え出力
Console.WriteLine(ans);
}
}
class ProgramE {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
long[] a = new long[n];
long[] b = new long[n];
//下限をa,上限をbとする
for (int i = 0; i < n; i++) {
string[] s = Console.ReadLine().Split(' ');
a[i] = long.Parse(s[0]);
b[i] = long.Parse(s[1]);
}
// a,bを小さい順に並べる
Array.Sort(a);
Array.Sort(b);
long min = 0;
long max = 0;
//偶数個のときは中央二つの和を考える、奇数個は中央を考える
if (n % 2 == 0) {
min = a[n / 2] + a[n / 2 - 1];
max = b[n / 2] + b[n / 2 - 1];
} else {
min = a[n / 2];
max = b[n / 2];
}
// minからmaxまでは全部中央値として取れるのでそれで出力する
Console.WriteLine(max - min + 1);
}
}
class ProgramF {
public void main() {
string[] s = Console.ReadLine().Split(' ');
int n = int.Parse(s[0]);
int num = int.Parse(s[1]);
long MOD = 9982444353;
string[] a = Console.ReadLine().Split(' ');
long[,] dp = new long[n + 1, num + 1];
dp[0, 0] = 1;
// i番目までで、選び方によって出てくる和(j)を求める
for (int i = 0; i < n; i++)
for (int j = 0; j < num + 1; j++) {
long temp = j + long.Parse(a[i]);
// 3001以上は答にならないので省く
//入れる場合は、集合として幾つ成り立つか考える
if (temp <= num) {
dp[i + 1, temp] += dp[i, j];
dp[i + 1, temp] %= MOD;
}
//いれない場合は集合として成立しているので2倍して拡張
dp[i + 1, j] += (dp[i, j] * 2) % MOD;
dp[i + 1, j] %= MOD;
}
Console.WriteLine(dp[n, num]);
}
}
}
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramF a = new ProgramF();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
// a*bを出す
Console.WriteLine(a * b);
}
}
class ProgramB {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long ans = 1;
long[] a = new long[n];
long INF = 1000000000000000000;
for (int i = 0; i < n; i++)
a[i] = long.Parse(s[i]);
//小さい順に並べる
Array.Sort(a);
//試しに小さい順に割ってみてもし0になるなら10の18乗超えるんで-1を出す。
for (int i = 0; i < n; i++) {
if (a[i] == 0)
break;
INF /= a[i];
if (INF == 0) {
Console.WriteLine("-1");
return;
}
}
//普通にかけていく
for (int i = 0; i < n; i++) {
ans *= a[i];
}
//答え出力
Console.WriteLine(ans);
}
}
class ProgramC {
public void main() {
//入力(decimal型だと桁精度が27桁ぐらいまである
string[] s = Console.ReadLine().Split(' ');
decimal a = decimal.Parse(s[0]);
decimal b = decimal.Parse(s[1]);
//かけてlong型で出せば切り捨て
Console.WriteLine((long)(a * b));
}
}
class ProgramD {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
long temp = n;
long ans = 0;
//平方根をとって素因数分解
for (int i = 2; i <= Math.Sqrt(n); i++) {
//もし割り切れるならその回数を考える
if (temp % i == 0) {
int count = 0;
int count2 = 1;
int ans_temp = 1;
//割り切れなくなるまで続ける
while (temp % i == 0) {
count++; //割った回数
temp /= i;
if (ans_temp == count) {
count2++; //ここに入ってきた回数
ans_temp +=
count2; //入ってきた数を足す(すると次に入るべき数になる1→3→6→10...)
ans++; //ここに入れば答えなので足す
}
}
}
}
//あまったのが平方根以上であればそれも素因数なので加算する
if (temp > Math.Sqrt(n))
ans++;
//答え出力
Console.WriteLine(ans);
}
}
class ProgramE {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
long[] a = new long[n];
long[] b = new long[n];
//下限をa,上限をbとする
for (int i = 0; i < n; i++) {
string[] s = Console.ReadLine().Split(' ');
a[i] = long.Parse(s[0]);
b[i] = long.Parse(s[1]);
}
// a,bを小さい順に並べる
Array.Sort(a);
Array.Sort(b);
long min = 0;
long max = 0;
//偶数個のときは中央二つの和を考える、奇数個は中央を考える
if (n % 2 == 0) {
min = a[n / 2] + a[n / 2 - 1];
max = b[n / 2] + b[n / 2 - 1];
} else {
min = a[n / 2];
max = b[n / 2];
}
// minからmaxまでは全部中央値として取れるのでそれで出力する
Console.WriteLine(max - min + 1);
}
}
class ProgramF {
public void main() {
string[] s = Console.ReadLine().Split(' ');
int n = int.Parse(s[0]);
int num = int.Parse(s[1]);
long MOD = 998244353;
string[] a = Console.ReadLine().Split(' ');
long[,] dp = new long[n + 1, num + 1];
dp[0, 0] = 1;
// i番目までで、選び方によって出てくる和(j)を求める
for (int i = 0; i < n; i++)
for (int j = 0; j < num + 1; j++) {
long temp = j + long.Parse(a[i]);
// 3001以上は答にならないので省く
//入れる場合は、集合として幾つ成り立つか考える
if (temp <= num) {
dp[i + 1, temp] += dp[i, j];
dp[i + 1, temp] %= MOD;
}
//いれない場合は集合として成立しているので2倍して拡張
dp[i + 1, j] += (dp[i, j] * 2) % MOD;
dp[i + 1, j] %= MOD;
}
Console.WriteLine(dp[n, num]);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 991
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Math;
namespace CSharpSpiral {
class Program {
static void Main(string[] args) {
var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
#if DEBUG
true
#else
false
#endif
};
Console.SetOut(sw);
new Program().Solve(new ConsoleInput(
#if DEBUG
new StreamReader("../../../inputData.txt")
#else
Console.In
#endif
,
' '));
Console.Out.Flush();
}
public void Solve(ConsoleInput cin) {
var F = new QuotientRing(998244353);
const int modulo = 998244353;
var N = cin.ReadInt;
var S = cin.ReadInt;
var A = cin.ReadIntArray(N);
var dp = new long [N + 1][];
for (int i = 0; i < N + 1; i++) {
dp[i] = new long[S + 1];
}
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
var a = A[i];
for (int s = 0; s < a; s++) {
dp[i + 1][s] = dp[i][s] * 2;
if (dp[i + 1][s] >= modulo)
dp[i + 1][s] %= modulo;
}
for (int s = 0; s + a <= S; s++) {
long below = dp[i][s] + dp[i][s + a] * 2;
if (below >= modulo)
below %= modulo;
dp[i + 1][s + a] = below;
}
}
Console.WriteLine(dp[N][S]);
}
}
static class ExtendClass {
public static string Join<T>(this IEnumerable<T> X,
string separator = " ") => string.Join(separator,
X);
}
class ConsoleInput {
private readonly TextReader _stream;
private readonly char _separator = ' ';
private readonly Queue<string> inputStream;
public ConsoleInput(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;
}
public double[] ReadDoubleArray(long N) {
var ret = new double[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadDouble;
return ret;
}
public bool isEOF {
get { return _stream.Peek() == -1; }
}
}
class QuotientRing {
public readonly long modulo;
public QuotientRing(int mModulo = 1000 * 1000 * 1000 + 7) {
modulo = mModulo;
}
private long[] factorialTable = { 1 };
private int factorialTableLastIndex {
get { return factorialTable.Length - 1; }
}
public long mod(long x) => x < 0 ? x % modulo + modulo : x % modulo;
public long Add(long a, long b) => mod(a + b);
public long Sub(long a, long b) => mod(a - b);
public long Mul(long a, long b) => mod(a * b);
public long Pow(long a, long n) {
if (n == 0)
return 1;
var R = 1L;
n = n < 0 ? n % (modulo - 1) + (modulo - 1) : n % (modulo - 1);
for (; n > 0; a = Mul(a, a), n >>= 1) {
if ((n & 1) != 0)
R = Mul(R, a);
}
return R;
}
private void ExpandFactorialTable(int N) {
var k = factorialTableLastIndex;
Array.Resize(ref factorialTable, N + 1);
for (int i = k + 1; i <= N; i++) {
if (i == 0) {
factorialTable[i] = 1;
continue;
}
factorialTable[i] = Mul(factorialTable[i - 1], i);
}
}
public long Factorial(int n) {
if (n > factorialTableLastIndex)
ExpandFactorialTable(n);
return factorialTable[n];
}
public long Permutation(int n, int k) {
if (k < 0 || k > n)
return 0;
var Res = 1L;
for (int i = 0; i < k; i++)
Res = Mul(Res, n - i);
return Res;
}
public virtual long Calculate(params object[] RPN) {
var S = new Stack<long>();
foreach (var token in RPN) {
var type = token.GetType();
if (type == typeof(int) || type == typeof(long)) {
S.Push((long)token);
} else if (type == typeof(char)) {
long v1 = 0L, v2 = 0L;
v2 = S.Pop();
HashSet<char> unaries = new HashSet<char>() { '!' };
if (!unaries.Contains((char)token))
v1 = S.Pop();
long res;
switch ((char)token) {
case '+':
res = Add(v1, v2);
break;
case '-':
res = Sub(v1, v2);
break;
case '*':
res = Mul(v1, v2);
break;
case '^':
res = Pow(v1, v2);
break;
case '!':
res = Factorial((int)v2);
break;
default:
throw new InvalidOperationException();
}
S.Push(res);
} else
throw new InvalidOperationException();
}
return S.Peek();
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Math;
namespace CSharpSpiral {
class Program {
static void Main(string[] args) {
var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
#if DEBUG
true
#else
false
#endif
};
Console.SetOut(sw);
new Program().Solve(new ConsoleInput(
#if DEBUG
new StreamReader("../../../inputData.txt")
#else
Console.In
#endif
,
' '));
Console.Out.Flush();
}
public void Solve(ConsoleInput cin) {
var F = new QuotientRing(998244353);
const int modulo = 998244353;
var N = cin.ReadInt;
var S = cin.ReadInt;
var A = cin.ReadIntArray(N);
var dp = new long [N + 1][];
for (int i = 0; i < N + 1; i++) {
dp[i] = new long[S + 1];
}
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
var a = A[i];
for (int s = 0; s < a && s <= S; s++) {
dp[i + 1][s] = dp[i][s] * 2;
if (dp[i + 1][s] >= modulo)
dp[i + 1][s] %= modulo;
}
for (int s = 0; s + a <= S; s++) {
long below = dp[i][s] + dp[i][s + a] * 2;
if (below >= modulo)
below %= modulo;
dp[i + 1][s + a] = below;
}
}
Console.WriteLine(dp[N][S]);
}
}
static class ExtendClass {
public static string Join<T>(this IEnumerable<T> X,
string separator = " ") => string.Join(separator,
X);
}
class ConsoleInput {
private readonly TextReader _stream;
private readonly char _separator = ' ';
private readonly Queue<string> inputStream;
public ConsoleInput(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;
}
public double[] ReadDoubleArray(long N) {
var ret = new double[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadDouble;
return ret;
}
public bool isEOF {
get { return _stream.Peek() == -1; }
}
}
class QuotientRing {
public readonly long modulo;
public QuotientRing(int mModulo = 1000 * 1000 * 1000 + 7) {
modulo = mModulo;
}
private long[] factorialTable = { 1 };
private int factorialTableLastIndex {
get { return factorialTable.Length - 1; }
}
public long mod(long x) => x < 0 ? x % modulo + modulo : x % modulo;
public long Add(long a, long b) => mod(a + b);
public long Sub(long a, long b) => mod(a - b);
public long Mul(long a, long b) => mod(a * b);
public long Pow(long a, long n) {
if (n == 0)
return 1;
var R = 1L;
n = n < 0 ? n % (modulo - 1) + (modulo - 1) : n % (modulo - 1);
for (; n > 0; a = Mul(a, a), n >>= 1) {
if ((n & 1) != 0)
R = Mul(R, a);
}
return R;
}
private void ExpandFactorialTable(int N) {
var k = factorialTableLastIndex;
Array.Resize(ref factorialTable, N + 1);
for (int i = k + 1; i <= N; i++) {
if (i == 0) {
factorialTable[i] = 1;
continue;
}
factorialTable[i] = Mul(factorialTable[i - 1], i);
}
}
public long Factorial(int n) {
if (n > factorialTableLastIndex)
ExpandFactorialTable(n);
return factorialTable[n];
}
public long Permutation(int n, int k) {
if (k < 0 || k > n)
return 0;
var Res = 1L;
for (int i = 0; i < k; i++)
Res = Mul(Res, n - i);
return Res;
}
public virtual long Calculate(params object[] RPN) {
var S = new Stack<long>();
foreach (var token in RPN) {
var type = token.GetType();
if (type == typeof(int) || type == typeof(long)) {
S.Push((long)token);
} else if (type == typeof(char)) {
long v1 = 0L, v2 = 0L;
v2 = S.Pop();
HashSet<char> unaries = new HashSet<char>() { '!' };
if (!unaries.Contains((char)token))
v1 = S.Pop();
long res;
switch ((char)token) {
case '+':
res = Add(v1, v2);
break;
case '-':
res = Sub(v1, v2);
break;
case '*':
res = Mul(v1, v2);
break;
case '^':
res = Pow(v1, v2);
break;
case '!':
res = Factorial((int)v2);
break;
default:
throw new InvalidOperationException();
}
S.Push(res);
} else
throw new InvalidOperationException();
}
return S.Peek();
}
}
}
|
[["+", 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
| 1,476
| 4
|
using System;
using System.Linq;
using CompLib.Util;
public class Program {
public void Solve() {
var sc = new Scanner();
int h = sc.NextInt();
int m = sc.NextInt();
int h2 = sc.NextInt();
int m2 = sc.NextInt();
int k = sc.NextInt();
int mm1 = h * 60 + m;
int mm2 = h2 * 60 + m;
Console.WriteLine(mm2 - mm1 - k);
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Linq;
using CompLib.Util;
public class Program {
public void Solve() {
var sc = new Scanner();
int h = sc.NextInt();
int m = sc.NextInt();
int h2 = sc.NextInt();
int m2 = sc.NextInt();
int k = sc.NextInt();
int mm1 = h * 60 + m;
int mm2 = h2 * 60 + m2;
Console.WriteLine(mm2 - mm1 - k);
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
| 8
| 435
| 2
|
using System;
using static System.Console;
using System.Linq;
namespace AC {
public class shiokara {
static void Main(string[] args) {
var tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
int hour1 = tmp[0], min1 = tmp[1];
int hour2 = tmp[2], min2 = tmp[3];
int k = tmp[4];
int sum = (hour2 * 60) + min2 - (hour1 * 60) - min1;
WriteLine(k - sum);
}
}
}
|
using System;
using static System.Console;
using System.Linq;
namespace AC {
public class shiokara {
static void Main(string[] args) {
var tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
int hour1 = tmp[0], min1 = tmp[1];
int hour2 = tmp[2], min2 = tmp[3];
int k = tmp[4];
int sum = (hour2 * 60) + min2 - (hour1 * 60) - min1;
WriteLine(sum - k);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 123
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace contest_Csharp {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
int H1 = vals[0];
int M1 = vals[1];
int H2 = vals[2];
int M2 = vals[3];
int K = vals[4];
int ans = H2 * 60 + M2 - (H1 * 60 - M1) - K;
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace contest_Csharp {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
int H1 = vals[0];
int M1 = vals[1];
int H2 = vals[2];
int M2 = vals[3];
int K = vals[4];
int ans = H2 * 60 + M2 - (H1 * 60 + M1) - K;
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
[["-", 0, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 72]]
| 8
| 174
| 2
|
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
class StringComparator2 : IComparer<string> {
int IComparer<string>.Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
class StringComparator3 : IEqualityComparer<string> {
public bool Equals(string b1, string b2) { return Compare(b1, b2) == 0; }
public int GetHashCode(string bx) { return bx.GetHashCode(); }
int Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class Class1 {
// static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long,
// long>, long>();
static long mod = 1000000007;
static long[] factorial = new long[1000001];
static long[] invFactorial = new long[1000001];
private static void calcFanctorial(long N) {
factorial[0] = 1;
for (int i = 1; i < N + 1; i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
invFactorial[N] = inv(factorial[N]);
for (int i = (int)N; i > 0; i--) {
invFactorial[i - 1] = invFactorial[i] * i % mod;
}
}
class Tree {
public HashSet<long> conn = new HashSet<long>();
}
static long bin(long a, long x, long n) {
long y = a;
long res = 1;
while (x > 0) {
if (x % 2 == 1) {
res = res * y % n;
}
x /= 2;
y = y * y % n;
}
return res;
}
int cmp(string a, string b) {
for (var i = 0; i < Math.Min(a.Length, b.Length); i++)
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
if (a.Length == b.Length)
return 0;
if (a.Length > b.Length)
return 1;
else
return -1;
}
private static long nCm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod;
}
private static long nPm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod);
}
private static long nCm2(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
long res = 1;
for (long i = n; i > n - m; i--) {
res *= i;
res %= mod;
}
return res * invFactorial[m] % mod;
}
public static long pow(long a, long b, long mod) {
a %= mod;
if (b <= 0)
return 1;
var t = pow(a, b / 2, mod);
if ((b & 1) == 0)
return t * t % mod;
return t * t % mod * a % mod;
}
public static long Lcm(long a, long b) {
return a * b % mod * inv(Gcd(a, b)) % mod;
}
public static long Lcm(long[] a) {
List<long> vect = new List<long>();
long lcm = 1;
for (int i = 0; i < a.Count(); i++) {
var factor = a[i] / GcdVector(vect, a[i]);
vect.Add(factor);
lcm = lcm * factor % mod;
}
return lcm;
}
static long GcdVector(List<long> a, long b) {
long ma = 1;
for (int i = 0; i < a.Count; i++)
ma = ma * a[i] % b;
return Gcd(b, ma);
}
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static long pow(long a, long b) => pow(a, b, mod);
public static long inv(long a) => pow(a, mod - 2);
private static char[][] ReadCharMatrix(long h) {
char[][] mtx = new char [h][];
for (int i = 0; i < h; i++) {
var s = ReadString();
mtx[i] = s.ToCharArray();
}
return mtx;
}
private static int[][] CreateIntMatrix(long h, long w) {
int[][] mtx = new int [h][];
for (int i = 0; i < h; i++) {
mtx[i] = new int[w];
}
return mtx;
}
private static string ReadString() { return Console.ReadLine(); }
private static string[] ReadStringArr() {
return Console.ReadLine().Split(' ');
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static long[] ReadLongArr() {
string[] s = ReadStringArr();
long[] l = new long[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = long.Parse(s[i]);
}
return l;
}
private static int[] ReadIntArr() {
string[] s = ReadStringArr();
int[] l = new int[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = int.Parse(s[i]);
}
return l;
}
class Pair {
public long A1;
public long A2;
public bool f;
}
static void Main(string[] args) {
var NN = ReadLongArr();
var h = NN[2] - NN[0];
var m = NN[3] - NN[1];
var awake = h * 60 - m;
Console.WriteLine(awake - NN[4]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
namespace ClassLibrary1 {
public class ListNode {
public int val;
public ListNode next;
public ListNode(int x) { val = x; }
}
class StringComparator2 : IComparer<string> {
int IComparer<string>.Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
class StringComparator3 : IEqualityComparer<string> {
public bool Equals(string b1, string b2) { return Compare(b1, b2) == 0; }
public int GetHashCode(string bx) { return bx.GetHashCode(); }
int Compare(string a, string b) {
int length = Math.Min(a.Length, b.Length);
// Console.WriteLine("Comparing with length {0}", length);
for (int i = 0; i < length; i++) {
if (a[i] < b[i]) {
// Console.WriteLine("returning -1");
return -1;
} else if (a[i] > b[i])
return 1;
}
if (a.Length < b.Length)
return -1;
if (a.Length > b.Length)
return 1;
// Console.WriteLine("Why are we at the end?");
return 0;
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
public class Class1 {
// static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long,
// long>, long>();
static long mod = 1000000007;
static long[] factorial = new long[1000001];
static long[] invFactorial = new long[1000001];
private static void calcFanctorial(long N) {
factorial[0] = 1;
for (int i = 1; i < N + 1; i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= mod;
}
invFactorial[N] = inv(factorial[N]);
for (int i = (int)N; i > 0; i--) {
invFactorial[i - 1] = invFactorial[i] * i % mod;
}
}
class Tree {
public HashSet<long> conn = new HashSet<long>();
}
static long bin(long a, long x, long n) {
long y = a;
long res = 1;
while (x > 0) {
if (x % 2 == 1) {
res = res * y % n;
}
x /= 2;
y = y * y % n;
}
return res;
}
int cmp(string a, string b) {
for (var i = 0; i < Math.Min(a.Length, b.Length); i++)
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
if (a.Length == b.Length)
return 0;
if (a.Length > b.Length)
return 1;
else
return -1;
}
private static long nCm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod;
}
private static long nPm(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
return (factorial[n] * invFactorial[m] % mod);
}
private static long nCm2(long n, long m) {
if (n < m)
return 0;
if (m < 0)
return 0;
long res = 1;
for (long i = n; i > n - m; i--) {
res *= i;
res %= mod;
}
return res * invFactorial[m] % mod;
}
public static long pow(long a, long b, long mod) {
a %= mod;
if (b <= 0)
return 1;
var t = pow(a, b / 2, mod);
if ((b & 1) == 0)
return t * t % mod;
return t * t % mod * a % mod;
}
public static long Lcm(long a, long b) {
return a * b % mod * inv(Gcd(a, b)) % mod;
}
public static long Lcm(long[] a) {
List<long> vect = new List<long>();
long lcm = 1;
for (int i = 0; i < a.Count(); i++) {
var factor = a[i] / GcdVector(vect, a[i]);
vect.Add(factor);
lcm = lcm * factor % mod;
}
return lcm;
}
static long GcdVector(List<long> a, long b) {
long ma = 1;
for (int i = 0; i < a.Count; i++)
ma = ma * a[i] % b;
return Gcd(b, ma);
}
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static long pow(long a, long b) => pow(a, b, mod);
public static long inv(long a) => pow(a, mod - 2);
private static char[][] ReadCharMatrix(long h) {
char[][] mtx = new char [h][];
for (int i = 0; i < h; i++) {
var s = ReadString();
mtx[i] = s.ToCharArray();
}
return mtx;
}
private static int[][] CreateIntMatrix(long h, long w) {
int[][] mtx = new int [h][];
for (int i = 0; i < h; i++) {
mtx[i] = new int[w];
}
return mtx;
}
private static string ReadString() { return Console.ReadLine(); }
private static string[] ReadStringArr() {
return Console.ReadLine().Split(' ');
}
private static long ReadLong() { return long.Parse(Console.ReadLine()); }
private static long[] ReadLongArr() {
string[] s = ReadStringArr();
long[] l = new long[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = long.Parse(s[i]);
}
return l;
}
private static int[] ReadIntArr() {
string[] s = ReadStringArr();
int[] l = new int[s.Length];
for (int i = 0; i < l.Length; i++) {
l[i] = int.Parse(s[i]);
}
return l;
}
class Pair {
public long A1;
public long A2;
public bool f;
}
static void Main(string[] args) {
var NN = ReadLongArr();
var h = NN[2] - NN[0];
var m = NN[3] - NN[1];
var awake = (h * 60) + m;
Console.WriteLine(awake - NN[4]);
}
}
}
|
[["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72]]
| 8
| 2,121
| 4
|
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
namespace AtCoder {
class Program {
const int BiggestMod = 1000000007;
public static void Main() {
var args =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var start = args[0] * 60 + args[1];
var end = args[2] * 60 + args[3];
if (end - start + args[4] <= 0)
Console.WriteLine(0);
else
Console.WriteLine(end - start + args[4]);
}
}
}
|
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
namespace AtCoder {
class Program {
const int BiggestMod = 1000000007;
public static void Main() {
var args =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var start = args[0] * 60 + args[1];
var end = args[2] * 60 + args[3];
if (end - (start + args[4]) <= 0)
Console.WriteLine(0);
else
Console.WriteLine(end - (start + args[4]));
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 163
| 4
|
using System;
using System.Linq;
class IDONTKNOWCSHARP {
public static void Main() {
int K = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
if (K > S.Length) {
Console.WriteLine(S.Substring(0, K) + "...");
} else {
Console.WriteLine(S);
}
}
}
|
using System;
using System.Linq;
class IDONTKNOWCSHARP {
public static void Main() {
int K = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
if (K < S.Length) {
Console.WriteLine(S.Substring(0, K) + "...");
} else {
Console.WriteLine(S);
}
// Console.ReadLine();
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 81
| 2
|
using System;
namespace abc168_b {
class Program {
static void Main(string[] args) {
var maxNum = int.Parse(Console.ReadLine());
var inputText = Console.ReadLine();
// 入力された文字列が指定文字数以上の場合切り取る
Console.WriteLine(AcquireDisplayText(maxNum, inputText));
Console.Read();
}
/// <summary>
/// 入力された文字が指定文字数以上の場合、先頭から指定文字数分のみ切り取り「...」を加える
/// </summary>
/// <param name="maxNum"></param>
/// <param name="inputText"></param>
/// <returns></returns>
private static string AcquireDisplayText(int maxNum, string inputText) {
if (inputText.Length >= maxNum) {
var resultText = "";
for (int i = 0; i < maxNum; i++) {
resultText += inputText[i];
}
resultText += "...";
return resultText;
}
return inputText;
}
}
}
|
using System;
namespace abc168_b {
class Program {
static void Main(string[] args) {
var maxNum = int.Parse(Console.ReadLine());
var inputText = Console.ReadLine();
// 入力された文字列が指定文字数以上の場合切り取る
Console.WriteLine(AcquireDisplayText(maxNum, inputText));
Console.Read();
}
/// <summary>
/// 入力された文字が指定文字数以上の場合、先頭から指定文字数分のみ切り取り「...」を加える
/// </summary>
/// <param name="maxNum"></param>
/// <param name="inputText"></param>
/// <returns></returns>
private static string AcquireDisplayText(int maxNum, string inputText) {
if (inputText.Length > maxNum) {
var resultText = "";
for (int i = 0; i < maxNum; i++) {
resultText += inputText[i];
}
resultText += "...";
return resultText;
}
return inputText;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 134
| 2
|
using System;
using System.Linq;
class program {
static void Main() {
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
string a = "";
int len = s.Length;
if (k > len) {
Console.Write(s);
} else {
for (int i = 0; i < k; i++) {
a += s[i];
}
a += "...";
Console.Write(a);
}
}
}
|
using System;
using System.Linq;
class program {
static void Main() {
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
string a = "";
int len = s.Length;
if (k >= len) {
Console.Write(s);
} else {
for (int i = 0; i < k; i++) {
a += s[i];
}
a += "...";
Console.Write(a);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 109
| 2
|
using System;
class Triple_Dots {
static void Main(string[] args) {
int input = int.Parse(Console.ReadLine());
var str = Console.ReadLine();
int length = str.Length;
string output = "";
if (input > length) {
Console.WriteLine(str);
} else {
for (int i = 0; i < input; i++) {
output += str[i];
}
Console.WriteLine($"{output}...");
}
}
}
|
using System;
class Triple_Dots {
static void Main(string[] args) {
int input = int.Parse(Console.ReadLine());
var str = Console.ReadLine();
int length = str.Length;
string output = "";
if (input >= length) {
Console.WriteLine(str);
} else {
for (int i = 0; i < input; i++) {
output += str[i];
}
Console.WriteLine($"{output}...");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 107
| 2
|
using System;
class Program {
static void Main(string[] args) {
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (k > s.Length) {
Console.WriteLine(s);
} else {
Console.WriteLine(s.Substring(0, k) + "...");
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
int k = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (s.Length <= k) {
Console.WriteLine(s);
} else {
Console.WriteLine(s.Substring(0, k) + "...");
}
}
}
|
[["-", 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, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 79
| 4
|
using System;
namespace b {
class MainClass {
public static void Main(string[] args) {
var K = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
int len = S.Length;
string ans = "";
if (len < K) {
ans += S;
} else {
ans += S.Substring(0, K) + "...";
}
Console.WriteLine(ans);
}
}
}
|
using System;
namespace b {
class MainClass {
public static void Main(string[] args) {
var K = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
int len = S.Length;
string ans = "";
if (len <= K) {
ans += S;
} else {
ans += S.Substring(0, K) + "...";
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 96
| 2
|
using System;
namespace atcorder {
class Program {
static void Main() {
var k = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
if (s.Length <= k) {
Console.WriteLine(s);
} else {
Console.WriteLine(s.Substring(0, 7) + "...");
}
}
}
}
|
using System;
namespace atcorder {
class Program {
static void Main() {
var k = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
if (s.Length <= k) {
Console.WriteLine(s);
} else {
Console.WriteLine(s.Substring(0, k) + "...");
}
}
}
}
|
[["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 79
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] arg) {
// string[] input = Console.ReadLine().Split(' ');
int K = int.Parse(Console.ReadLine());
string n = Console.ReadLine();
if (n.Length < K) {
Console.WriteLine(n);
return;
} else {
Console.WriteLine(n.Substring(0, K) + "...");
return;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] arg) {
// string[] input = Console.ReadLine().Split(' ');
int K = int.Parse(Console.ReadLine());
string n = Console.ReadLine();
if (n.Length <= K) {
Console.WriteLine(n);
return;
} else {
Console.WriteLine(n.Substring(0, K) + "...");
return;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 96
| 2
|
using System;
class Program {
static void Main(string[] args) {
int K = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
if (S.Length >= K) {
S = S.Substring(0, K) + "...";
}
Console.WriteLine(S);
}
}
|
using System;
class Program {
static void Main(string[] args) {
int K = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
if (S.Length > K) {
S = S.Substring(0, K) + "...";
}
Console.WriteLine(S);
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 73
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.