buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
// 入力
long n = long.Parse(Console.ReadLine());
long ans = n - 1;
for (long i = 2; i * i < n; i++) {
if (n % i == 0) {
ans = Math.Min(ans, i + n / i - 2);
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
// 入力
long n = long.Parse(Console.ReadLine());
long ans = n - 1;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0) {
ans = Math.Min(ans, i + (n / i) - 2);
}
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 25]]
| 8
| 109
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cook {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long rowPoint = N;
long colPoint = 1;
while (N > colPoint * colPoint) {
if (N % colPoint == 0) {
rowPoint = N / colPoint;
}
colPoint++;
}
colPoint = N / rowPoint;
Console.WriteLine((colPoint - 1) + (rowPoint - 1));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cook {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long rowPoint = N;
long colPoint = 1;
while (N >= colPoint * colPoint) {
if (N % colPoint == 0) {
rowPoint = N / colPoint;
}
colPoint++;
}
colPoint = N / rowPoint;
Console.WriteLine((colPoint - 1) + (rowPoint - 1));
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20]]
| 8
| 122
| 2
|
using System;
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var ans = long.MaxValue;
for (long i = 1; i * i < n; i++) {
if (n % i == 0) {
ans = Math.Min(ans, i + n / i - 2);
}
}
Console.WriteLine(ans);
}
}
|
using System;
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var ans = long.MaxValue;
for (long i = 1; i * i <= n; i++) {
if (n % i == 0) {
ans = Math.Min(ans, i + n / i - 2);
}
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 91
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextLong();
var ans = long.MaxValue;
for (long i = 1; i < Math.Sqrt(n); i++) {
var a = i;
if (n % a == 0) {
var b = n / a;
ans = Math.Min(ans, a + b - 2);
}
}
Console.WriteLine(ans);
}
}
#region library
static class 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 UpperBound(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 partial class MathEx {
public static int GCD(int n, int m) { return (int)GCD((long)n, m); }
public static long GCD(long n, long m) {
n = Math.Abs(n);
m = Math.Abs(m);
while (n != 0) {
m %= n;
if (m == 0)
return n;
n %= m;
}
return m;
}
public static long LCM(long n, long m) { return (n / GCD(n, m)) * m; }
public static bool[] Sieve(int max, List<int> primes = null) {
var isPrime = new bool[max + 1];
for (int i = 2; i < isPrime.Length; i++)
isPrime[i] = true;
for (int i = 2; i * i <= max; i++)
if (!isPrime[i])
continue;
else
for (int j = i * i; j <= max; j += i)
isPrime[j] = false;
if (primes != null)
for (int i = 0; i <= max; i++)
if (isPrime[i])
primes.Add(i);
return isPrime;
}
}
public static class Combination {
public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k,
bool withRepetition) {
if (k == 1) {
foreach (var item in items)
yield return new T[] { item };
yield break;
}
foreach (var item in items) {
var leftside = new T[] { item };
var unused = withRepetition
? items
: items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();
foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
yield return leftside.Concat(rightside).ToArray();
}
}
}
}
static class Subsequence {
/// <summary>
/// 最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
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[C.LowerBound(dp, a[i])] = a[i];
}
return C.LowerBound(dp, long.MaxValue - 1);
}
/// <summary>
/// 重複を許さない最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long UniqueLIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.UpperBound(dp, a[i])] = a[i];
}
return C.UpperBound(dp, long.MaxValue - 1);
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
class DP {
public static void ChMin(ref int a, int b) {
long la = a;
long lb = b;
ChMin(ref la, lb);
}
public static bool ChMin(ref long a, long b) {
if (a > b) {
a = b;
return true;
}
return false;
}
public static void ChMax(ref int a, int b) {
long la = a;
long lb = b;
ChMax(ref la, lb);
}
public static bool ChMax(ref long a, long b) {
if (a < b) {
a = b;
return true;
}
return false;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
public class ModInt {
public static long Mod;
public long num;
public ModInt(long n, int mod = (int)1e9 + 7) {
num = n;
Mod = mod;
}
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextLong();
var ans = long.MaxValue;
for (long i = 1; i <= Math.Sqrt(n); i++) {
var a = i;
if (n % a == 0) {
var b = n / a;
ans = Math.Min(ans, (a + b) - 2);
}
}
Console.WriteLine(ans);
}
}
#region library
static class 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 UpperBound(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 partial class MathEx {
public static int GCD(int n, int m) { return (int)GCD((long)n, m); }
public static long GCD(long n, long m) {
n = Math.Abs(n);
m = Math.Abs(m);
while (n != 0) {
m %= n;
if (m == 0)
return n;
n %= m;
}
return m;
}
public static long LCM(long n, long m) { return (n / GCD(n, m)) * m; }
public static bool[] Sieve(int max, List<int> primes = null) {
var isPrime = new bool[max + 1];
for (int i = 2; i < isPrime.Length; i++)
isPrime[i] = true;
for (int i = 2; i * i <= max; i++)
if (!isPrime[i])
continue;
else
for (int j = i * i; j <= max; j += i)
isPrime[j] = false;
if (primes != null)
for (int i = 0; i <= max; i++)
if (isPrime[i])
primes.Add(i);
return isPrime;
}
}
public static class Combination {
public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k,
bool withRepetition) {
if (k == 1) {
foreach (var item in items)
yield return new T[] { item };
yield break;
}
foreach (var item in items) {
var leftside = new T[] { item };
var unused = withRepetition
? items
: items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();
foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
yield return leftside.Concat(rightside).ToArray();
}
}
}
}
static class Subsequence {
/// <summary>
/// 最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
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[C.LowerBound(dp, a[i])] = a[i];
}
return C.LowerBound(dp, long.MaxValue - 1);
}
/// <summary>
/// 重複を許さない最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long UniqueLIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.UpperBound(dp, a[i])] = a[i];
}
return C.UpperBound(dp, long.MaxValue - 1);
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
class DP {
public static void ChMin(ref int a, int b) {
long la = a;
long lb = b;
ChMin(ref la, lb);
}
public static bool ChMin(ref long a, long b) {
if (a > b) {
a = b;
return true;
}
return false;
}
public static void ChMax(ref int a, int b) {
long la = a;
long lb = b;
ChMax(ref la, lb);
}
public static bool ChMax(ref long a, long b) {
if (a < b) {
a = b;
return true;
}
return false;
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
public class ModInt {
public static long Mod;
public long num;
public ModInt(long n, int mod = (int)1e9 + 7) {
num = n;
Mod = mod;
}
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
| 8
| 2,195
| 4
|
using System;
namespace ABC144c_2 {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var sqrt = (long)Math.Sqrt(n);
for (var i = sqrt; i > 0; i--) {
if (n % i == 0) {
Console.WriteLine(i + n / i - 2);
}
}
}
}
}
|
using System;
namespace ABC144c_2 {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var sqrt = (long)Math.Sqrt(n);
for (var i = sqrt; i > 0; i--) {
if (n % i == 0) {
Console.WriteLine(i + n / i - 2);
return;
}
}
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 88
| 2
|
using System;
namespace testes {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
bool flag = false;
long A;
double B = N;
A = (long)Math.Sqrt(B) + 1;
long ansA = 0, ansB = 0;
for (long i = A; i > 0; i--) {
if (N % i == 0) {
ansA = i;
ansB = N / i;
flag = true;
break;
}
}
// Console.WriteLine($"{ansA}, {ansB}");
if (flag)
Console.WriteLine(ansA + ansB);
else
Console.WriteLine("No");
}
/*
public static int pow(int a, int b)
{
}
public static int LIS(int[] c)
{
// 部分数列和
int count = 1;
int N = c.Length;
int[] array = new int[N];
array[0] = c[0];
for (int i = 1; i < N; i++)
{
//for (int p = 0; p < N; p++) Console.Write($"{array[p]},");
// Console.WriteLine("");
if (array[count - 1] < c[i])
{
array[count] = c[i];
count++;
continue;
}
for (int j = count - 2; j >= 0; j--)
{
if (array[j] < c[i])
{
array[j + 1] = c[i];
break;
}
}
if (array[0] > c[i]) array[0] = c[i];
}
return count;
}
public static void Rotation(char[] array, int l, int r)
{
}
*/
}
}
/*
int a, b, c;
int a = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
int b = int.Parse(str[0]);
int c = int.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
string[] str = Console.ReadLine().Split(' ');
int[] a = new int[N];
for(int i = 0; i < N; i++) a[i] = int.Parse(str[i]);
*/
|
using System;
namespace testes {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
bool flag = false;
long A;
double B = N;
A = (long)Math.Sqrt(B) + 1;
long ansA = 0, ansB = 0;
for (long i = A; i > 0; i--) {
if (N % i == 0) {
ansA = i;
ansB = N / i;
flag = true;
break;
}
}
// Console.WriteLine($"{ansA}, {ansB}");
if (flag)
Console.WriteLine(ansA + ansB - 2);
else
Console.WriteLine("No");
}
/*
public static int pow(int a, int b)
{
}
public static int LIS(int[] c)
{
// 部分数列和
int count = 1;
int N = c.Length;
int[] array = new int[N];
array[0] = c[0];
for (int i = 1; i < N; i++)
{
//for (int p = 0; p < N; p++) Console.Write($"{array[p]},");
// Console.WriteLine("");
if (array[count - 1] < c[i])
{
array[count] = c[i];
count++;
continue;
}
for (int j = count - 2; j >= 0; j--)
{
if (array[j] < c[i])
{
array[j + 1] = c[i];
break;
}
}
if (array[0] > c[i]) array[0] = c[i];
}
return count;
}
public static void Rotation(char[] array, int l, int r)
{
}
*/
}
}
/*
int a, b, c;
int a = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
int b = int.Parse(str[0]);
int c = int.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
string[] str = Console.ReadLine().Split(' ');
int[] a = new int[N];
for(int i = 0; i < N; i++) a[i] = int.Parse(str[i]);
*/
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 140
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC144C {
class Program {
static void Main(string[] args) {
// var inputArr = Console.ReadLine().Split().Select(int.Parse).ToArray();
var inputLong = long.Parse(Console.ReadLine());
long ans = inputLong - 1;
// string ans = "";
for (long a = 1; a * a < inputLong; a++) {
if (inputLong % a == 0) {
long b = inputLong / a;
ans = Math.Min(a + b - 2, ans);
}
}
Console.WriteLine(ans);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC144C {
class Program {
static void Main(string[] args) {
// var inputArr = Console.ReadLine().Split().Select(int.Parse).ToArray();
var inputLong = long.Parse(Console.ReadLine());
long ans = inputLong - 1;
// string ans = "";
for (long a = 1; a * a <= inputLong; a++) {
if (inputLong % a == 0) {
long b = inputLong / a;
ans = Math.Min(a + b - 2, ans);
}
}
Console.WriteLine(ans);
Console.ReadKey();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 120
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest20191029 {
class Program {
static void Main(string[] args) {
double n = double.Parse(Console.ReadLine());
List<double> ans = new List<double>();
double k = n;
for (int i = 1; i < k; i++) {
if (n % i == 0) {
ans.Add(k - 1 + i - 1);
}
k = n / (i + 1);
k = Math.Ceiling(k);
}
ans.Sort();
Console.WriteLine(ans[0]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest20191029 {
class Program {
static void Main(string[] args) {
double n = double.Parse(Console.ReadLine());
List<double> ans = new List<double>();
double k = n;
for (int i = 1; i <= k; i++) {
if (n % i == 0) {
ans.Add(k - 1 + i - 1);
}
k = n / (i + 1);
k = Math.Ceiling(k);
}
ans.Sort();
Console.WriteLine(ans[0]);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 153
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
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 void Main() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
var c = new List<long>();
for (long i = 1; i < Math.Pow(n, 0.5); i++) {
if (n % i == 0) {
long a = n / i;
c.Add(i + a);
}
}
Console.WriteLine(c.Min() - 2);
Console.Out.Flush();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
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 void Main() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
var c = new List<long>();
for (long i = 1; i < Math.Pow(n, 0.5) + 1; i++) {
if (n % i == 0) {
long a = n / i;
c.Add(i + a);
}
}
Console.WriteLine(c.Min() - 2);
Console.Out.Flush();
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 197
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
//
public class ABC144_C // ←Class名変更!! Program
{
public static void Main() {
var n = Rl();
// var c = n / 2;
double root = Math.Sqrt(n);
var c = (int)Ceiling(root); //切り上げ
var min = n + 2;
for (long i = 1; i < c; i++) {
var a = n % i;
if (a == 0) {
var v = n / i;
if (i + v < min) {
min = i + v;
// if (min == n + 1)
//{
// min = min + 1;
//}
}
}
}
WriteLine($"{min - 2}");
return;
} // Main
public static string Rs() { return ReadLine(); }
public static char Rc() {
var c = ReadLine();
return c[0];
} //最初の1文字だけ返す
public static int Ri() { return int.Parse(ReadLine()); }
public static long Rl() { return long.Parse(ReadLine()); }
public static char[] Rca() { return ReadLine().ToCharArray(); }
public static int[] Ria() {
return Array.ConvertAll(ReadLine().Split(' '), int.Parse);
}
public static long[] Rla() {
return Array.ConvertAll(ReadLine().Split(' '), long.Parse);
}
} // Class
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
// C - Walk on Multiplication Table
// https://atcoder.jp/contests/abc144/tasks/abc144_c
public class ABC144_C // ←Class名変更!! Program
{
public static void Main() {
var n = Rl();
// var c = n / 2;
double root = Math.Sqrt(n);
var c = (int)Ceiling(root); //切り上げ
var min = n + 2;
for (long i = 1; i <= c; i++) {
var a = n % i;
if (a == 0) {
var v = n / i;
if (i + v < min) {
min = i + v;
}
}
}
WriteLine($"{min - 2}");
return;
} // Main
public static string Rs() { return ReadLine(); }
public static char Rc() {
var c = ReadLine();
return c[0];
} //最初の1文字だけ返す
public static int Ri() { return int.Parse(ReadLine()); }
public static long Rl() { return long.Parse(ReadLine()); }
public static char[] Rca() { return ReadLine().ToCharArray(); }
public static int[] Ria() {
return Array.ConvertAll(ReadLine().Split(' '), int.Parse);
}
public static long[] Rla() {
return Array.ConvertAll(ReadLine().Split(' '), long.Parse);
}
} // Class
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 309
| 2
|
using System;
namespace C {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
var s = Math.Sqrt(N);
long minMove = 100000000000000;
for (long i = 2; i <= s; i++) {
if (N % i == 0) {
var move = i + (N / i);
if (minMove > move)
minMove = move;
}
}
Console.WriteLine(minMove - 2);
}
}
}
|
using System;
namespace C {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
var s = Math.Sqrt(N);
long minMove = 10000000000000;
for (long i = 1; i <= s; i++) {
if (N % i == 0) {
var move = i + (N / i);
if (minMove > move)
minMove = move;
}
}
Console.WriteLine(minMove - 2);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 107
| 4
|
using System;
class p {
static void Main() {
long N = long.Parse(Console.ReadLine());
long move = long.MaxValue;
for (long i = 1; i <= 100; i++) {
if (N % i == 0) {
move = Math.Min(move, (i - 1) + ((N / i) - 1));
}
}
Console.WriteLine(move);
}
}
|
using System;
class p {
static void Main() {
long N = long.Parse(Console.ReadLine());
long move = long.MaxValue;
for (long i = 1; i <= Math.Sqrt(N); i++) {
if (N % i == 0) {
move = Math.Min(move, (i - 1) + ((N / i) - 1));
}
}
Console.WriteLine(move);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 93
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace AtCoder {
static class Program {
static void Main() {
//ここから
long N = IO.ReadLineToLong();
long min = long.MaxValue;
for (long i = 1; i < Math.Sqrt(N); i++) {
if (N % i == 0) {
min = Math.Min(min, i + N / i - 2);
}
}
//ここまで
Console.WriteLine(min);
Console.ReadKey();
}
}
static class Func {
static long mod = 1000000007;
static public void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
static public int Factorial(int a) {
return a == 1 ? a : a * Factorial(a - 1);
}
public static double ToAngle(this double radian) {
return (double)(radian * 180 / Math.PI);
}
public static double ToRadian(this double angle) {
return (double)(angle * Math.PI / 180);
}
static public long Conbination(int n, int m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * Conbination(n - 1, m - 1) / m;
}
static public void Factoring(long num, ref long[] vs) {
if (num == 1) {
vs[1]++;
}
for (long i = 2; i < Math.Sqrt(num); i++) {
if (num % i == 0) {
vs[i]++;
Factoring(num / i, ref vs);
}
}
vs[1]++;
}
}
static class IO {
static public string ReadLineToString() { return Console.ReadLine(); }
static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
static public List<string> ReadLineToStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> ReadLineToIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> ReadLineToLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public void WriteStrings(object[] strings) {
foreach (var o in strings) {
Console.Write(o + " ");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace AtCoder {
static class Program {
static void Main() {
//ここから
long N = IO.ReadLineToLong();
long min = long.MaxValue;
for (long i = 1; i <= Math.Sqrt(N); i++) {
if (N % i == 0) {
min = Math.Min(min, i + N / i - 2);
}
}
//ここまで
Console.WriteLine(min);
Console.ReadKey();
}
}
static class Func {
static long mod = 1000000007;
static public void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
static public int Factorial(int a) {
return a == 1 ? a : a * Factorial(a - 1);
}
public static double ToAngle(this double radian) {
return (double)(radian * 180 / Math.PI);
}
public static double ToRadian(this double angle) {
return (double)(angle * Math.PI / 180);
}
static public long Conbination(int n, int m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * Conbination(n - 1, m - 1) / m;
}
static public void Factoring(long num, ref long[] vs) {
if (num == 1) {
vs[1]++;
}
for (long i = 2; i < Math.Sqrt(num); i++) {
if (num % i == 0) {
vs[i]++;
Factoring(num / i, ref vs);
}
}
vs[1]++;
}
}
static class IO {
static public string ReadLineToString() { return Console.ReadLine(); }
static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
static public List<string> ReadLineToStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> ReadLineToIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> ReadLineToLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public void WriteStrings(object[] strings) {
foreach (var o in strings) {
Console.Write(o + " ");
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 625
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
long min = long.MaxValue;
var rootN = Math.Sqrt(N);
for (int i = 1; i < rootN; i++) {
var a = i;
var b = N / a;
var c = a + b - 2;
if (N % i == 0 && c < min) {
min = c;
}
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
long min = long.MaxValue;
var rootN = Math.Sqrt(N);
for (int i = 1; i <= rootN; i++) {
var a = i;
var b = N / a;
var c = a + b - 2;
if (N % i == 0 && c < min) {
min = c;
}
}
Console.WriteLine(min);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 137
| 2
|
using System;
using System.Collections;
public class KukuC {
public static void Main() {
int N = int.Parse(Console.ReadLine());
int so = (int)Math.Floor(Math.Sqrt(N));
int ans = N - 1;
for (int i = so; i > 1; i--) {
if (N % i == 0) {
ans = i + N / i - 2;
break;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections;
public class KukuC {
public static void Main() {
ulong N = ulong.Parse(Console.ReadLine());
ulong so = (ulong)Math.Floor(Math.Sqrt(N));
ulong ans = N - 1;
for (ulong i = so; i > 1; i--) {
if (N % i == 0) {
ans = i + N / i - 2;
break;
}
}
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], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 105
| 12
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace abc144 {
class Program {
static void Main(string[] args) {
// Console.SetIn(new StreamReader("input.txt"));
solve_abc144C();
}
public static void solve_abc144C() {
long n = Convert.ToInt64(Console.ReadLine());
long t = n;
long min = int.MaxValue;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0) {
long d = n / i;
min = Math.Min(min, d - 1 + i - 1);
}
}
Console.WriteLine(min == int.MaxValue ? n - 1 : min);
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
public static void solve_abc144B() {
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (i * j == n) {
Console.WriteLine("Yes");
return;
}
}
}
Console.WriteLine("No");
}
public static void solve_abc144A() {
int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int a = ab[0];
int b = ab[1];
Console.WriteLine(a < 10 && b < 10 ? a * b : -1);
}
/*
BinarySearchIterativeLeft
*/
public static int binarySearchIterativeLeft(long[] haystack, long needle) {
int left = -1;
int right = haystack.Length;
while (left < right - 1) {
int middle = left + (right - left) / 2;
if (haystack[middle] < needle) {
left = middle;
} else {
right = middle;
}
}
return right;
}
public static int binSearch(int[] haystack, int needle) {
int l = -1;
int r = haystack.Length;
while (l < r - 1) {
int mid = (r + l) / 2;
if (haystack[mid] <= needle) {
l = mid;
} else {
r = mid;
}
}
return r;
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace abc144 {
class Program {
static void Main(string[] args) {
// Console.SetIn(new StreamReader("input.txt"));
solve_abc144C();
}
public static void solve_abc144C() {
long n = Convert.ToInt64(Console.ReadLine());
long t = n;
long min = long.MaxValue;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0) {
long d = n / i;
min = Math.Min(min, d - 1 + i - 1);
}
}
Console.WriteLine(min == long.MaxValue ? n - 1 : min);
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
public static void solve_abc144B() {
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
if (i * j == n) {
Console.WriteLine("Yes");
return;
}
}
}
Console.WriteLine("No");
}
public static void solve_abc144A() {
int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int a = ab[0];
int b = ab[1];
Console.WriteLine(a < 10 && b < 10 ? a * b : -1);
}
/*
BinarySearchIterativeLeft
*/
public static int binarySearchIterativeLeft(long[] haystack, long needle) {
int left = -1;
int right = haystack.Length;
while (left < right - 1) {
int middle = left + (right - left) / 2;
if (haystack[middle] < needle) {
left = middle;
} else {
right = middle;
}
}
return right;
}
public static int binSearch(int[] haystack, int needle) {
int l = -1;
int r = haystack.Length;
while (l < r - 1) {
int mid = (r + l) / 2;
if (haystack[mid] <= needle) {
l = mid;
} else {
r = mid;
}
}
return r;
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 28, 0, 41, 15, 16, 12, 214, 205, 199], ["+", 0, 28, 0, 41, 15, 16, 12, 214, 205, 199]]
| 8
| 492
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C___Walk_on_Multiplication_Table {
class Program {
static void Main(string[] args) {
Int64 N = Int64.Parse(Console.ReadLine());
Int64 a = 100000000001;
Int64 j = 0;
for (Int64 i = 2; i <= Math.Sqrt(N); i++) {
if (N % i == 0) {
j = N / i;
if (a > (i - 1) + (j - 1)) {
a = (i - 1) + (j - 1);
}
}
}
if (a == 100000000001) {
a = N - 1;
}
Console.WriteLine(a);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C___Walk_on_Multiplication_Table {
class Program {
static void Main(string[] args) {
Int64 N = Int64.Parse(Console.ReadLine());
Int64 a = 1000000000000;
Int64 j = 0;
for (Int64 i = 2; i <= Math.Sqrt(N); i++) {
if (N % i == 0) {
j = N / i;
if (a > (i - 1) + (j - 1)) {
a = (i - 1) + (j - 1);
}
}
}
if (a == 1000000000000) {
a = N - 1;
}
Console.WriteLine(a);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 160
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
ulong N = ulong.Parse(Console.ReadLine());
ulong[] A = new ulong[1000000];
for (ulong i = 1; i <= 1000000; i++) {
A[i - 1] = 1000001;
if (N % i == 0) {
A[i - 1] = i + N / i - 2;
}
}
Console.WriteLine(A.Min());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
ulong N = ulong.Parse(Console.ReadLine());
ulong[] A = new ulong[1000000];
for (ulong i = 1; i <= 1000000; i++) {
A[i - 1] = 1000000000001;
if (N % i == 0) {
A[i - 1] = i + N / i - 2;
}
}
Console.WriteLine(A.Min());
}
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 132
| 2
|
using System;
class Program {
static void Main(string[] args) {
string input = Console.ReadLine();
double n = double.Parse(input);
double sho1 = n;
double sho2 = 0;
double i1 = 1;
double i2 = 0;
for (double i = 1; i < Math.Sqrt(n); i++) {
double amari = n % i;
if (amari == 0) {
sho2 = n / i;
i2 = n / sho2;
if (i1 + sho1 > i2 + sho2) {
i1 = i2;
sho1 = sho2;
} else {
continue;
}
} else {
continue;
}
}
Console.WriteLine(i1 + sho1 - 2);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string input = Console.ReadLine();
double n = double.Parse(input);
double sho1 = n;
double sho2 = 0;
double i1 = 1;
double i2 = 0;
for (double i = 1; i < Math.Sqrt(n) + 1; i++) {
double amari = n % i;
if (amari == 0) {
sho2 = n / i;
i2 = n / sho2;
if (i1 + sho1 > i2 + sho2) {
i1 = i2;
sho1 = sho2;
} else {
continue;
}
} else {
continue;
}
}
Console.WriteLine(i1 + sho1 - 2);
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 146
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
long length = long.MaxValue;
for (long i = 1; i < Math.Sqrt(n); i++) {
if (n % i == 0) {
if (n / i + i - 2 < length)
length = n / i + i - 2;
}
}
Console.WriteLine(length);
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
long length = long.MaxValue;
for (long i = 1; i <= Math.Sqrt(n); i++) {
if (n % i == 0) {
if (n / i + i - 2 < length)
length = n / i + i - 2;
}
}
Console.WriteLine(length);
return;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 117
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
Func cin2;
void calc() {
cin = new Scanner();
cin2 = new Func();
long n = cin.nextLong();
long a = 1;
long b = n;
long x = 0;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0)
x = i;
if (x != b && x != 0) {
a = x;
b = n / x;
} else
break;
}
Console.WriteLine(a + b - 2);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Answer {
public void Int2DArrayAns(int[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
}
public void Char2DArrayAns(char[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
}
}
class Func {
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
Func cin2;
void calc() {
cin = new Scanner();
cin2 = new Func();
long n = cin.nextLong();
long a = 1;
long b = n;
long x = 0;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0)
x = i;
if (x != b && x != 0) {
a = x;
b = n / x;
} else if (b == x)
break;
}
Console.WriteLine(a + b - 2);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Answer {
public void Int2DArrayAns(int[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
}
public void Char2DArrayAns(char[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
}
}
class Func {
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25]]
| 8
| 773
| 6
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long result = N;
for (long a = 1; a < Math.Sqrt(N); a++) {
if (N % a == 0) {
long b = N / a;
if (a + b - 2 < result) {
result = a + b - 2;
}
}
}
Console.WriteLine(result);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long result = N;
for (long a = 1; a <= Math.Sqrt(N); a++) {
if (N % a == 0) {
long b = N / a;
if (a + b - 2 < result) {
result = a + b - 2;
}
}
}
Console.WriteLine(result);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 109
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public static void Main(string[] args) {
var n = Console.ReadLine().ToLong();
var divisor = new List<long>();
for (long i = 1; i * i <= n; i++) {
if (n % i == 0) {
divisor.Add(i);
if (i * i != n)
divisor.Add(n / i);
}
}
long min = 999999999999;
for (int i = 0; i < divisor.Count; i++) {
for (int j = i + 1; j < divisor.Count; j++) {
if (divisor[i] * divisor[j] == n)
min = Math.Min(min,
Math.Abs(divisor[i] - 1) + Math.Abs(divisor[j] - 1));
}
}
Console.WriteLine(min);
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public static void Main(string[] args) {
var n = Console.ReadLine().ToLong();
var divisor = new List<long>();
for (long i = 1; i * i <= n; i++) {
if (n % i == 0) {
divisor.Add(i);
if (i * i != n)
divisor.Add(n / i);
}
}
long min = 9999999999999;
for (int i = 0; i < divisor.Count; i++) {
for (int j = 0; j < divisor.Count; j++) {
if (divisor[i] * divisor[j] == n) {
min = Math.Min(min,
Math.Abs(divisor[i] - 1) + Math.Abs(divisor[j] - 1));
}
}
}
Console.WriteLine(min);
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 442
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC144_C {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var ans = PrimeFactors(n);
Console.WriteLine(ans);
}
public static long PrimeFactors(long n) {
var ret = n - 1;
var m = (long)Math.Sqrt(n);
for (int i = 2; i < m; i++) {
if (n % i == 0) {
ret = Math.Min(ret, i + n / i - 2);
}
}
return ret;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC144_C {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var ans = PrimeFactors(n);
Console.WriteLine(ans);
}
public static long PrimeFactors(long n) {
var ret = n - 1;
var m = (long)Math.Sqrt(n);
for (int i = 2; i <= m; i++) {
if (n % i == 0) {
ret = Math.Min(ret, i + n / i - 2);
}
}
return ret;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 151
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public static List<long> GetDivisors(long n) {
var divisors = new List<long>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
divisors.Add(i);
if (i != n / i) {
divisors.Add(n / i);
}
}
}
return divisors;
}
public static void Main() {
var n = int.Parse(Console.ReadLine());
var divs = GetDivisors(n);
var min = divs.Min(d => d - 1 + n / d - 1);
Console.WriteLine(min);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public static List<long> GetDivisors(long n) {
var divisors = new List<long>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
divisors.Add(i);
if (i != n / i) {
divisors.Add(n / i);
}
}
}
return divisors;
}
public static void Main() {
var n = long.Parse(Console.ReadLine());
var divs = GetDivisors(n);
var min = divs.Min(d => d - 1 + n / d - 1);
Console.WriteLine(min);
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 163
| 2
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
double[] abx = doublea();
abx[2] /= abx[0];
double a = abx[0];
double b = abx[1];
double x = abx[2];
double ans = 0;
if (x / a >= b / 2) {
ans = Atan((b - (x / a)) / (a / 2));
} else {
ans = Atan(b / (x / b));
}
ans *= 180 / PI;
WriteLine(ans);
}
static long pricemid(long midd, long read0, long read1) {
long temp = midd;
int countk = 0;
while (temp > 0) {
temp /= 10;
countk++;
}
return (midd * read0) + (countk * read1);
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// A/B小数点以下切上
static int divideup(int divided, int divid) {
int temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
}
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
double[] abx = doublea();
abx[2] /= abx[0];
double a = abx[0];
double b = abx[1];
double x = abx[2];
double ans = 0;
if (x / a >= b / 2) {
ans = Atan((b - (x / a)) / (a / 2));
} else {
ans = Atan((b / 2) / (x / b));
}
ans *= 180 / PI;
WriteLine(ans);
}
static long pricemid(long midd, long read0, long read1) {
long temp = midd;
int countk = 0;
while (temp > 0) {
temp /= 10;
countk++;
}
return (midd * read0) + (countk * read1);
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// A/B小数点以下切上
static int divideup(int divided, int divid) {
int temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
}
|
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 85], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
| 8
| 600
| 4
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace AtCoder.Contest.C {
static class Program {
public static void Solve(Scanner cin) {
const double pi = Math.PI;
var (a, b, x) = cin.ReadValue<int, int, int>();
if (x == 0)
Console.WriteLine(0);
else if (x == a * a * b)
Console.WriteLine(90);
else if (x <= a * a * b / 2.0) {
Console.WriteLine(Math.Atan2(b, (2.0 * x) / (a * b)) * 180 / pi);
} else {
Console.WriteLine(Math.Atan2(2.0 * b - 2.0 * x / (a * a), a) * 180 /
pi);
}
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
Solve(cin);
Console.Out.Flush();
}
public static void YESNO(bool condition) {
if (condition)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
public static void YesNo(bool condition) {
if (condition)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
public static void yesno(bool condition) {
if (condition)
Console.WriteLine("yes");
else
Console.WriteLine("no");
}
}
class Scanner {
string[] s;
int i;
char[] separator = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Read() => ReadString();
public string ReadString() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return ReadString();
i = 0;
return s[i++];
}
public string[] ReadStringArray(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadString();
}
return Array;
}
public int ReadInt() { return int.Parse(ReadString()); }
public int[] ReadIntArray(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadInt() + add;
}
return Array;
}
public long ReadLong() { return long.Parse(ReadString()); }
public long[] ReadLongArray(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadLong() + add;
}
return Array;
}
public double ReadDouble() { return double.Parse(ReadString()); }
public double[] ReadDoubleArray(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadDouble() + add;
}
return Array;
}
public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(),
typeof(T1));
public (T1, T2) ReadValue<T1, T2>() {
var inputs = ReadStringArray(2);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
return (v1, v2);
}
public (T1, T2, T3) ReadValue<T1, T2, T3>() {
var inputs = ReadStringArray(3);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
return (v1, v2, v3);
}
public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var inputs = ReadStringArray(4);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
return (v1, v2, v3, v4);
}
public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var inputs = ReadStringArray(5);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
return (v1, v2, v3, v4, v5);
}
public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() {
var inputs = ReadStringArray(6);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
return (v1, v2, v3, v4, v5, v6);
}
public (T1, T2, T3, T4, T5, T6,
T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() {
var inputs = ReadStringArray(7);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7));
return (v1, v2, v3, v4, v5, v6, v7);
}
public T1[] ReadValueArray<T1>(int N) {
var v1 = new T1[N];
for (int i = 0; i < N; i++) {
v1[i] = ReadValue<T1>();
}
return v1;
}
public (T1[], T2[]) ReadValueArray<T1, T2>(int N) {
var (v1, v2) = (new T1[N], new T2[N]);
for (int i = 0; i < N; i++) {
var (t1, t2) = ReadValue<T1, T2>();
v1[i] = t1;
v2[i] = t2;
}
return (v1, v2);
}
public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) {
var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3) = ReadValue<T1, T2, T3>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
}
return (v1, v2, v3);
}
public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) {
var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
}
return (v1, v2, v3, v4);
}
public (T1[], T2[], T3[], T4[],
T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) {
var (v1, v2, v3, v4, v5) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
}
return (v1, v2, v3, v4, v5);
}
public (T1[], T2[], T3[], T4[], T5[],
T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) {
var (v1, v2, v3, v4, v5, v6) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
}
return (v1, v2, v3, v4, v5, v6);
}
public (T1[], T2[], T3[], T4[], T5[], T6[],
T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) {
var (v1, v2, v3, v4, v5, v6, v7) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N],
new T7[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6, t7) =
ReadValue<T1, T2, T3, T4, T5, T6, T7>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
v7[i] = t7;
}
return (v1, v2, v3, v4, v5, v6, v7);
}
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace AtCoder.Contest.C {
static class Program {
public static void Solve(Scanner cin) {
const double pi = Math.PI;
var (a, b, x) = cin.ReadValue<int, int, int>();
if (x == 0)
Console.WriteLine(90);
else if (x == a * a * b)
Console.WriteLine(0);
else if (x <= a * a * b / 2.0) {
Console.WriteLine(Math.Atan2(b, (2.0 * x) / (a * b)) * 180 / pi);
} else {
Console.WriteLine(Math.Atan2(2.0 * b - 2.0 * x / (a * a), a) * 180 /
pi);
}
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
Solve(cin);
Console.Out.Flush();
}
public static void YESNO(bool condition) {
if (condition)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
public static void YesNo(bool condition) {
if (condition)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
public static void yesno(bool condition) {
if (condition)
Console.WriteLine("yes");
else
Console.WriteLine("no");
}
}
class Scanner {
string[] s;
int i;
char[] separator = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Read() => ReadString();
public string ReadString() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return ReadString();
i = 0;
return s[i++];
}
public string[] ReadStringArray(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadString();
}
return Array;
}
public int ReadInt() { return int.Parse(ReadString()); }
public int[] ReadIntArray(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadInt() + add;
}
return Array;
}
public long ReadLong() { return long.Parse(ReadString()); }
public long[] ReadLongArray(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadLong() + add;
}
return Array;
}
public double ReadDouble() { return double.Parse(ReadString()); }
public double[] ReadDoubleArray(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadDouble() + add;
}
return Array;
}
public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(),
typeof(T1));
public (T1, T2) ReadValue<T1, T2>() {
var inputs = ReadStringArray(2);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
return (v1, v2);
}
public (T1, T2, T3) ReadValue<T1, T2, T3>() {
var inputs = ReadStringArray(3);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
return (v1, v2, v3);
}
public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var inputs = ReadStringArray(4);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
return (v1, v2, v3, v4);
}
public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var inputs = ReadStringArray(5);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
return (v1, v2, v3, v4, v5);
}
public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() {
var inputs = ReadStringArray(6);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
return (v1, v2, v3, v4, v5, v6);
}
public (T1, T2, T3, T4, T5, T6,
T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() {
var inputs = ReadStringArray(7);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7));
return (v1, v2, v3, v4, v5, v6, v7);
}
public T1[] ReadValueArray<T1>(int N) {
var v1 = new T1[N];
for (int i = 0; i < N; i++) {
v1[i] = ReadValue<T1>();
}
return v1;
}
public (T1[], T2[]) ReadValueArray<T1, T2>(int N) {
var (v1, v2) = (new T1[N], new T2[N]);
for (int i = 0; i < N; i++) {
var (t1, t2) = ReadValue<T1, T2>();
v1[i] = t1;
v2[i] = t2;
}
return (v1, v2);
}
public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) {
var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3) = ReadValue<T1, T2, T3>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
}
return (v1, v2, v3);
}
public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) {
var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
}
return (v1, v2, v3, v4);
}
public (T1[], T2[], T3[], T4[],
T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) {
var (v1, v2, v3, v4, v5) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
}
return (v1, v2, v3, v4, v5);
}
public (T1[], T2[], T3[], T4[], T5[],
T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) {
var (v1, v2, v3, v4, v5, v6) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
}
return (v1, v2, v3, v4, v5, v6);
}
public (T1[], T2[], T3[], T4[], T5[], T6[],
T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) {
var (v1, v2, v3, v4, v5, v6, v7) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N],
new T7[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6, t7) =
ReadValue<T1, T2, T3, T4, T5, T6, T7>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
v7[i] = t7;
}
return (v1, v2, v3, v4, v5, v6, v7);
}
}
}
|
[["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 2,656
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
public static List<Pair>[
,
] pairs;
public static int[,] ans;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
int a = scan.Integer();
int b = scan.Integer();
int x = scan.Integer();
double height = x * 2 / (a * a * 1.0) - b;
if (height >= 0) {
double theta = Math.Atan(a / (b - h));
Console.WriteLine(90 - theta * 180 / Math.PI);
} else {
height = x * 2 / (b * a * 1.0);
double theta = Math.Atan(height / b);
Console.WriteLine(90 - theta * 180 / Math.PI);
}
}
static int[] Togo;
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
public static List<Pair>[
,
] pairs;
public static int[,] ans;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
int a = scan.Integer();
int b = scan.Integer();
int x = scan.Integer();
double height = x * 2 / (a * a * 1.0) - b;
if (height >= 0) {
double theta = Math.Atan(a / (b - height));
Console.WriteLine(90 - theta * 180 / Math.PI);
} else {
height = x * 2 / (b * a * 1.0);
double theta = Math.Atan(height / b);
Console.WriteLine(90 - theta * 180 / Math.PI);
}
}
static int[] Togo;
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static List<CPair<long, long>> SoinsuBunkai(long num) {
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++) {
if (num % i != 0) {
continue;
}
yakusu.Add(i);
if (i * i != num) {
yakusu2.Add(num / i);
}
}
for (int i = 0; i < yakusu.Count; i++) {
if (num % yakusu[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++) {
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--) {
if (num % yakusu2[i] != 0) {
continue;
}
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++) {
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
}
|
[["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22]]
| 8
| 9,636
| 2
|
using System;
public class Hello {
public static void Main() {
// Your code here!
var stArrayData = System.Console.ReadLine().Split(' ');
var a = double.Parse(stArrayData[0]);
var b = double.Parse(stArrayData[1]);
var v = double.Parse(stArrayData[2]);
var V = a * a * b;
if (v >= V / 2) {
double x = (V - v) / (a * a) * 2;
var theta = Math.Atan(x / a) / Math.PI * 180.0;
System.Console.WriteLine(theta);
} else {
var x = (v) / (a * b) * 2;
var theta = Math.Atan(a / x) / Math.PI * 180.0;
System.Console.WriteLine(theta);
}
}
}
|
using System;
public class Hello {
public static void Main() {
// Your code here!
var stArrayData = System.Console.ReadLine().Split(' ');
var a = double.Parse(stArrayData[0]);
var b = double.Parse(stArrayData[1]);
var v = double.Parse(stArrayData[2]);
var V = a * a * b;
if (v >= V / 2) {
double x = (V - v) / (a * a) * 2;
var theta = Math.Atan(x / a) / Math.PI * 180.0;
System.Console.WriteLine(theta);
} else {
var x = (v) / (a * b) * 2;
var theta = Math.Atan(b / x) / Math.PI * 180.0;
System.Console.WriteLine(theta);
}
}
}
|
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
| 8
| 182
| 2
|
using System;
class waterbottle {
public static void Main() {
String[] str = Console.ReadLine().Split(' ');
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
int x = int.Parse(str[2]);
double s = Math.Atan((double)(2 * a * a * b - 2 * x) / (a * a * a));
if (b < a * Math.Tan(s)) {
s = Math.Atan((b * b * a) / (2 * x));
}
Console.WriteLine((180 * s) / Math.PI);
}
}
|
using System;
class waterbottle {
public static void Main() {
String[] str = Console.ReadLine().Split(' ');
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
int x = int.Parse(str[2]);
double s = Math.Atan((double)(2 * a * a * b - 2 * x) / (a * a * a));
if (b < a * Math.Tan(s)) {
s = Math.Atan((double)(b * b * a) / (2 * x));
}
Console.WriteLine((180 * s) / Math.PI);
}
}
|
[["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["+", 0, 28, 0, 16, 31, 74, 51, 23, 0, 24]]
| 8
| 156
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC144D_Water_Bottle {
class Program {
static void Main(string[] args) {
double[] input =
Console.ReadLine().Split(' ').Select(z => double.Parse(z)).ToArray();
double a = input[0];
double b = input[1];
double x = input[2];
if (a * a * b / 2 <= x) {
double theta =
(Math.Atan((2 / a) * (b - (x / (a * a))))) * (180 / Math.PI);
Console.WriteLine(theta);
} else {
double theta = (Math.Atan((b * b * b) / (2 * x))) * (180 / Math.PI);
Console.WriteLine(theta);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC144D_Water_Bottle {
class Program {
static void Main(string[] args) {
double[] input =
Console.ReadLine().Split(' ').Select(z => double.Parse(z)).ToArray();
double a = input[0];
double b = input[1];
double x = input[2];
if (a * a * b / 2 <= x) {
double theta =
(Math.Atan((2 / a) * (b - (x / (a * a))))) * (180 / Math.PI);
Console.WriteLine(theta);
} else {
double theta = (Math.Atan(a * b * b / (2 * x))) * (180 / Math.PI);
Console.WriteLine(theta);
}
}
}
}
|
[["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
| 8
| 205
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
// using System.Threading.Tasks;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
readonly Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
readonly int dom = 998244353;
bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (b.CompareTo(a) < 0) {
a = b;
return true;
}
return false;
}
void solve() {
int N = cin.nextint;
var B = cin.scanint;
long ans = B.Last();
for (int i = 0; i < B.Length - 1; i++) {
ans += Min(B[i], B[i + 1]);
}
WriteLine(ans);
}
}
static class Ex {
public static void join<T>(this IEnumerable<T> values, string sep = " ") =>
WriteLine(string.Join(sep, values));
public static string
concat<T>(this IEnumerable<T> values) => string.Concat(values);
public static string reverse(this string s) {
var t = s.ToCharArray();
Array.Reverse(t);
return t.concat();
}
public static int lower_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int upper_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
}
class Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T f;
public U s;
public Pair(T f, U s) {
this.f = f;
this.s = s;
}
public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0
? f.CompareTo(a.f)
: s.CompareTo(a.s);
public override string ToString() => $"{f} {s}";
}
class Scanner {
string[] s;
int i;
readonly char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan => ReadLine().Split();
public int[] scanint => Array.ConvertAll(scan, int.Parse);
public long[] scanlong => Array.ConvertAll(scan, long.Parse);
public double[] scandouble => Array.ConvertAll(scan, double.Parse);
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint => int.Parse(next);
public long nextlong => long.Parse(next);
public double nextdouble => double.Parse(next);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
// using System.Threading.Tasks;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
readonly Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
readonly int dom = 998244353;
bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (b.CompareTo(a) < 0) {
a = b;
return true;
}
return false;
}
void solve() {
int N = cin.nextint;
var B = cin.scanint;
long ans = B.First() + B.Last();
for (int i = 0; i < B.Length - 1; i++) {
ans += Min(B[i], B[i + 1]);
}
WriteLine(ans);
}
}
static class Ex {
public static void join<T>(this IEnumerable<T> values, string sep = " ") =>
WriteLine(string.Join(sep, values));
public static string
concat<T>(this IEnumerable<T> values) => string.Concat(values);
public static string reverse(this string s) {
var t = s.ToCharArray();
Array.Reverse(t);
return t.concat();
}
public static int lower_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int upper_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
}
class Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T f;
public U s;
public Pair(T f, U s) {
this.f = f;
this.s = s;
}
public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0
? f.CompareTo(a.f)
: s.CompareTo(a.s);
public override string ToString() => $"{f} {s}";
}
class Scanner {
string[] s;
int i;
readonly char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan => ReadLine().Split();
public int[] scanint => Array.ConvertAll(scan, int.Parse);
public long[] scanlong => Array.ConvertAll(scan, long.Parse);
public double[] scandouble => Array.ConvertAll(scan, double.Parse);
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint => int.Parse(next);
public long nextlong => long.Parse(next);
public double nextdouble => double.Parse(next);
}
|
[["+", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 0, 131]]
| 8
| 898
| 6
|
using System;
using System.Linq;
namespace abc140_c {
static class Program {
static void Main(string[] args) {
var n = Console.ReadLine().ToInteger();
// var a = new int[n];
var b = Console.ReadLine().ToIntArray();
// b[i] >= Math.Max(a[i], a[i + 1]);
var ans = 0L;
// a[0] = b[0];
for (int i = 0; i < b.Length; i++) {
if (i + 1 < b.Length && b[i] > b[i + 1]) {
// ただし、i > i + 1 の時はi + 1を入れる
// a[i + 1] = b[i + 1];
ans += b[i + 1];
} else {
// 基本的にはbの値を入れる
// a[i + 1] = b[i];
ans += b[i];
}
}
// Console.WriteLine($"{string.Join(" ", a)}");
Console.WriteLine($"{ans}");
}
static int ToInteger(this string s) { return int.Parse(s); }
static int[] ToIntArray(this string s, char separator = ' ') {
return s.Split(separator).Select(m => m.ToInteger()).ToArray();
}
}
}
|
using System;
using System.Linq;
namespace abc140_c {
static class Program {
static void Main(string[] args) {
var n = Console.ReadLine().ToInteger();
// var a = new int[n];
var b = Console.ReadLine().ToIntArray();
// b[i] >= Math.Max(a[i], a[i + 1]);
var ans = b[0];
// a[0] = b[0];
for (int i = 0; i < b.Length; i++) {
if (i + 1 < b.Length && b[i] > b[i + 1]) {
// ただし、i > i + 1 の時はi + 1を入れる
// a[i + 1] = b[i + 1];
ans += b[i + 1];
} else {
// 基本的にはbの値を入れる
// a[i + 1] = b[i];
ans += b[i];
}
}
// Console.WriteLine($"{string.Join(" ", a)}");
Console.WriteLine($"{ans}");
}
static int ToInteger(this string s) { return int.Parse(s); }
static int[] ToIntArray(this string s, char separator = ' ') {
return s.Split(separator).Select(m => m.ToInteger()).ToArray();
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73]]
| 8
| 199
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const int INF = 1 << 30;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
//ここから
var o = cin.LongM;
var N = o[0];
var K = o[1];
var S = cin.Str;
int first = 0;
for (int i = 0; i < N - 1; ++i) {
if (S[i] == S[i + 1])
first++;
}
cout.wri(Math.Max(first + 2 * K, N - 1));
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const int INF = 1 << 30;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
//ここから
var o = cin.LongM;
var N = o[0];
var K = o[1];
var S = cin.Str;
int first = 0;
for (int i = 0; i < N - 1; ++i) {
if (S[i] == S[i + 1])
first++;
}
cout.wri(Math.Min(first + 2 * K, N - 1));
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
| 8
| 1,430
| 2
|
using System;
public class D {
static void Main() {
var w = Console.ReadLine().Split(' ');
int n = int.Parse(w[0]);
int k = int.Parse(w[1]);
var s = Console.ReadLine();
int a = 0;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1])
a++;
}
Console.WriteLine(n - a / 2 <= k ? n - 1 : a + k * 2);
}
}
|
using System;
public class D {
static void Main() {
var w = Console.ReadLine().Split(' ');
int n = int.Parse(w[0]);
int k = int.Parse(w[1]);
var s = Console.ReadLine();
int a = 0;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1])
a++;
}
Console.WriteLine((n - a) / 2 <= k ? n - 1 : a + k * 2);
}
}
|
[["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 25]]
| 8
| 127
| 2
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
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 = 100001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
int n = Input.NextInt();
var k = Input.NextInt();
string s = Input.Next();
char[] ca = s.ToCharArray();
int score = CalcHappiness(ca);
int ans = Math.Min(score + 2 * k, n - 1);
Console.WriteLine(ans);
}
private static int CalcHappiness(char[] ca) {
int ans = 0;
for (int i = 0; i < ca.Length; ++i) {
if (ca[i] == ca[i + 1]) {
ans++;
}
}
return ans;
}
#region よく使う便利関数
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;
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 = 100001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
int n = Input.NextInt();
var k = Input.NextInt();
string s = Input.Next();
char[] ca = s.ToCharArray();
int score = CalcHappiness(ca);
int ans = Math.Min(score + 2 * k, n - 1);
Console.WriteLine(ans);
}
private static int CalcHappiness(char[] ca) {
int ans = 0;
for (int i = 0; i < ca.Length - 1; ++i) {
if (ca[i] == ca[i + 1]) {
ans++;
}
}
return ans;
}
#region よく使う便利関数
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;
}
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 2,395
| 2
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCorder {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
var K = cin.ReadInt;
var _S = cin.Read;
var S = _S.ToCharArray();
var start = new List<int>();
var end = new List<int>();
var ans = 0;
for (int i = 0; i < N - 1; i++) {
if (S[i] == S[i + 1])
ans++;
if (S[i] == 'L' && S[i + 1] == 'R')
start.Add(i + 1);
if (S[i] == 'R' && S[i + 1] == 'L')
end.Add(i + 1);
}
var towc = Min(start.Count, end.Count);
if (towc < K) {
WriteLine(N);
return;
} else {
ans += K * 2;
}
WriteLine(ans);
}
public long C(long n, long r) {
long[,] Pascal = new long[n + 1, n + 1];
Pascal[0, 0] = 1;
for (long i = 1; i <= n; i++) {
Pascal[i, 0] = 1;
Pascal[i, i] = 1;
for (long j = 1; j < n; j++) {
Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
}
}
return Pascal[n, r];
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCorder {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
var K = cin.ReadInt;
var _S = cin.Read;
var S = _S.ToCharArray();
var start = new List<int>();
var end = new List<int>();
var ans = 0;
for (int i = 0; i < N - 1; i++) {
if (S[i] == S[i + 1])
ans++;
if (S[i] == 'L' && S[i + 1] == 'R')
start.Add(i + 1);
if (S[i] == 'R' && S[i + 1] == 'L')
end.Add(i + 1);
}
var towc = Min(start.Count, end.Count);
if (towc < K) {
WriteLine(N - 1);
return;
} else {
ans += K * 2;
}
WriteLine(ans);
}
public long C(long n, long r) {
long[,] Pascal = new long[n + 1, n + 1];
Pascal[0, 0] = 1;
for (long i = 1; i <= n; i++) {
Pascal[i, 0] = 1;
Pascal[i, i] = 1;
for (long j = 1; j < n; j++) {
Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
}
}
return Pascal[n, r];
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 743
| 2
|
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
//入力を受け取る
string[] tmp = Console.ReadLine().Split(' ');
int N = int.Parse(tmp[0]);
int K = int.Parse(tmp[1]);
string S = Console.ReadLine();
int cnt = 0;
if (S[0] == 'R' && S[1] == 'R') {
cnt++;
}
if (S[N - 1] == 'L' && S[N - 2] == 'L') {
cnt++;
}
for (int i = 1; i < N - 1; i++) {
if (S[i] == 'R' && S[i] == S[i + 1]) {
cnt++;
} else if (S[i] == 'L' && S[i] == S[i - 1]) {
cnt++;
}
}
if (cnt + K * 2 >= N - 1) {
System.Console.WriteLine(N - 1);
} else {
System.Console.WriteLine(cnt + K * 2);
}
}
}
|
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
//入力を受け取る
string[] tmp = Console.ReadLine().Split(' ');
int N = int.Parse(tmp[0]);
int K = int.Parse(tmp[1]);
string S = Console.ReadLine();
int cnt = 0;
if (S[0] == 'R' && S[1] == 'R') {
cnt++;
}
if (S[N - 1] == 'L' && N > 1 && S[N - 2] == 'L') {
cnt++;
}
for (int i = 1; i < N - 1; i++) {
if (S[i] == 'R' && S[i] == S[i + 1]) {
cnt++;
} else if (S[i] == 'L' && S[i] == S[i - 1]) {
cnt++;
}
}
if (cnt + K * 2 >= N - 1) {
System.Console.WriteLine(N - 1);
} else {
System.Console.WriteLine(cnt + K * 2);
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 264
| 4
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using E = System.Linq.Enumerable;
partial class Solver {
public void Run() {
var N = ni();
var P = ni(N);
var perm = P.Select((p, index) => new { Index = index, Value = p })
.OrderByDescending(p => p.Value)
.Select(p => p.Index)
.ToArray();
var tree = new LeftLeaningRedBlackTree<int, int>();
long ans = 0;
foreach (var index in perm) {
var right1 = tree.IndexOfLowerBound(index);
var right2 = right1 + 1;
var left1 = right1 - 1;
var left2 = right1 - 2;
long left1Area = 1;
long right1Area = 1;
long left2Area = 0;
long right2Area = 0;
if (left1 >= 0)
left1Area = index - tree.At(left1);
else
left1Area = index + 1;
if (right1 < tree.Count)
right1Area = tree.At(right1) - index;
else
right1Area = P.Length - index;
if (left2 >= 0)
left2Area = tree.At(left1) - tree.At(left2);
else if (left1 >= 0)
left2Area = left1 + 1;
if (right2 < tree.Count)
right2Area = tree.At(right2) - tree.At(right1);
else if (right1 < tree.Count)
right2Area = P.Length - tree.At(right1);
ans += (left1Area * right2Area + left2Area * right1Area) * 1L * P[index];
tree.Add(index, index);
}
cout.WriteLine(ans);
}
}
public partial class LeftLeaningRedBlackTree<TKey, TValue> {
private Node root = null;
private readonly IComparer<TKey> _comparer;
public LeftLeaningRedBlackTree() : this(Comparer<TKey>.Default) {}
public LeftLeaningRedBlackTree(IComparer<TKey> comparer) {
_comparer = comparer;
}
public TValue this[TKey key] {
get { return Find(key); }
set { Add(key, value); }
}
public TValue Find(TKey key) { return Find(root, key); }
public int Count {
get { return root == null ? 0 : root.Count; }
}
private TValue Find(Node h, TKey key) {
while (h != null) {
int cmp = _comparer.Compare(key, h.Key);
if (cmp == 0) {
return h.Value;
}
h = (cmp < 0) ? h.Left : h.Right;
}
throw new KeyNotFoundException();
}
public int IndexOfLowerBound(TKey key) {
var node = root;
int index = 0;
while (node != null) {
int leftCount = node.Left == null ? 0 : node.Left.Count;
int cmp = _comparer.Compare(key, node.Key);
if (cmp == 0) {
index += leftCount;
break;
} else if (cmp < 0) {
node = node.Left;
} else {
index += leftCount + 1;
node = node.Right;
}
}
return index;
}
public TValue At(int index) {
var node = root;
while (node != null) {
int leftCount = node.Left == null ? 0 : node.Left.Count;
if (index == leftCount)
return node.Value;
if (index < leftCount) {
node = node.Left;
} else {
node = node.Right;
index -= leftCount + 1;
}
}
throw new ArgumentOutOfRangeException("index");
}
public void Add(TKey key, TValue value) {
root = Add(root, key, value);
root.Color = Node.BLACK;
}
private Node Add(Node h, TKey key, TValue value) {
if (h == null) {
return new Node(key, value);
}
if (IsRed(h.Left) && IsRed(h.Right)) {
ColorFlip(h);
}
int cmp = _comparer.Compare(key, h.Key);
if (cmp == 0) {
h.Value = value;
} else if (cmp < 0) {
h.Left = Add(h.Left, key, value);
h.FixCount();
} else {
h.Right = Add(h.Right, key, value);
h.FixCount();
}
if (IsRed(h.Right) && !IsRed(h.Left)) {
h = RotateLeft(h);
}
if (IsRed(h.Left) && IsRed(h.Left.Left)) {
h = RotateRight(h);
}
return h;
}
public void RemoveMin() {
root = RemoveMin(root);
if (root != null) {
root.Color = Node.BLACK;
}
}
private Node RemoveMin(Node h) {
if (h.Left == null) {
return null;
}
if (!IsRed(h.Left) && !IsRed(h.Left.Left)) {
h = MoveRedLeft(h);
}
h.Left = RemoveMin(h.Left);
h.FixCount();
return FixUp(h);
}
public void Remove(TKey key) {
root = Remove(root, key);
if (root != null) {
root.Color = Node.BLACK;
}
}
private Node Remove(Node h, TKey key) {
if (_comparer.Compare(key, h.Key) < 0) {
if (h.Left == null) {
throw new KeyNotFoundException("key");
}
if (!IsRed(h.Left) && !IsRed(h.Left.Left)) {
h = MoveRedLeft(h);
}
h.Left = Remove(h.Left, key);
h.FixCount();
} else {
if (IsRed(h.Left)) {
h = RotateRight(h);
}
if (h.Right == null) {
if (_comparer.Compare(key, h.Key) == 0) {
return null;
}
throw new KeyNotFoundException("key");
}
if (!IsRed(h.Right) && !IsRed(h.Right.Left)) {
h = MoveRedRight(h);
}
if (_comparer.Compare(key, h.Key) == 0) {
h.Value = Find(h.Right, Min(h.Right).Key);
h.Key = Min(h.Right).Key;
h.Right = RemoveMin(h.Right);
h.FixCount();
} else {
h.Right = Remove(h.Right, key);
h.FixCount();
}
}
return FixUp(h);
}
private static Node MoveRedLeft(Node h) {
ColorFlip(h);
if (IsRed(h.Right.Left)) {
h.Right = RotateRight(h.Right);
h.FixCount();
h = RotateLeft(h);
ColorFlip(h);
}
return h;
}
private static Node MoveRedRight(Node h) {
ColorFlip(h);
if (IsRed(h.Left.Left)) {
h = RotateRight(h);
ColorFlip(h);
}
return h;
}
static private Node RotateLeft(Node h) {
Node x = h.Right;
h.Right = x.Left;
x.Left = h;
x.Color = h.Color;
h.Color = Node.RED;
h.FixCount();
x.FixCount();
return x;
}
private static Node RotateRight(Node h) {
Node x = h.Left;
h.Left = x.Right;
x.Right = h;
x.Color = h.Color;
h.Color = Node.RED;
h.FixCount();
x.FixCount();
return x;
}
private static bool IsRed(Node h) { return h != null && h.Color == Node.RED; }
static private void ColorFlip(Node h) {
h.Color = !h.Color;
h.Left.Color = !h.Left.Color;
h.Right.Color = !h.Right.Color;
}
static private Node Min(Node h) {
while (h.Left != null) {
h = h.Left;
}
return h;
}
static private Node FixUp(Node h) {
if (IsRed(h.Right)) {
h = RotateLeft(h);
}
if (h.Left != null && IsRed(h.Left) && IsRed(h.Left.Left)) {
h = RotateRight(h);
}
if (IsRed(h.Left) && IsRed(h.Right)) {
ColorFlip(h);
}
return h;
}
private class Node {
public static readonly bool RED = true;
public static readonly bool BLACK = false;
public TKey Key;
public TValue Value;
public bool Color = RED;
public Node Left = null;
public Node Right = null;
public int Count = 1;
public Node(TKey key, TValue value) {
this.Key = key;
this.Value = value;
}
public void FixCount() {
this.Count = 1;
if (Left != null)
Count += Left.Count;
if (Right != null)
Count += Right.Count;
}
}
}
// PREWRITEN CODE BEGINS FROM HERE
partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
new Solver(Console.In, Console.Out).Run();
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
this.cin = reader;
this.cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
public static class LinqPadExtension {
static public T Dump<T>(this T obj) {
#if LOCAL
return LINQPad.Extensions.Dump(obj);
#else
return obj;
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { this.Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
var array = new string[size];
for (int i = 0; i < size; i++)
array[i] = Next();
return array;
}
public int[] NextIntArray(int size) {
var array = new int[size];
for (int i = 0; i < size; i++)
array[i] = NextInt();
return array;
}
public long[] NextLongArray(int size) {
var array = new long[size];
for (int i = 0; i < size; i++)
array[i] = NextLong();
return array;
}
public double[] NextDoubleArray(int size) {
var array = new double[size];
for (int i = 0; i < size; i++)
array[i] = NextDouble();
return array;
}
public string Next() {
if (TokenQueue.Count == 0) {
if (!StockTokens())
throw new InvalidOperationException();
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0)
return true;
return StockTokens();
}
static readonly char[] _separator = new[] { ' ' };
private bool StockTokens() {
while (true) {
var line = Reader.ReadLine();
if (line == null)
return false;
var tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0)
continue;
foreach (var token in tokens)
TokenQueue.Enqueue(token);
return true;
}
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using E = System.Linq.Enumerable;
partial class Solver {
public void Run() {
var N = ni();
var P = ni(N);
var perm = P.Select((p, index) => new { Index = index, Value = p })
.OrderByDescending(p => p.Value)
.Select(p => p.Index)
.ToArray();
var tree = new LeftLeaningRedBlackTree<int, int>();
long ans = 0;
foreach (var index in perm) {
var right1 = tree.IndexOfLowerBound(index);
var right2 = right1 + 1;
var left1 = right1 - 1;
var left2 = right1 - 2;
long left1Area = 1;
long right1Area = 1;
long left2Area = 0;
long right2Area = 0;
if (left1 >= 0)
left1Area = index - tree.At(left1);
else
left1Area = index + 1;
if (right1 < tree.Count)
right1Area = tree.At(right1) - index;
else
right1Area = P.Length - index;
if (left2 >= 0)
left2Area = tree.At(left1) - tree.At(left2);
else if (left1 >= 0)
left2Area = tree.At(left1) + 1;
if (right2 < tree.Count)
right2Area = tree.At(right2) - tree.At(right1);
else if (right1 < tree.Count)
right2Area = P.Length - tree.At(right1);
ans += (left1Area * right2Area + left2Area * right1Area) * 1L * P[index];
tree.Add(index, index);
}
cout.WriteLine(ans);
}
}
public partial class LeftLeaningRedBlackTree<TKey, TValue> {
private Node root = null;
private readonly IComparer<TKey> _comparer;
public LeftLeaningRedBlackTree() : this(Comparer<TKey>.Default) {}
public LeftLeaningRedBlackTree(IComparer<TKey> comparer) {
_comparer = comparer;
}
public TValue this[TKey key] {
get { return Find(key); }
set { Add(key, value); }
}
public TValue Find(TKey key) { return Find(root, key); }
public int Count {
get { return root == null ? 0 : root.Count; }
}
private TValue Find(Node h, TKey key) {
while (h != null) {
int cmp = _comparer.Compare(key, h.Key);
if (cmp == 0) {
return h.Value;
}
h = (cmp < 0) ? h.Left : h.Right;
}
throw new KeyNotFoundException();
}
public int IndexOfLowerBound(TKey key) {
var node = root;
int index = 0;
while (node != null) {
int leftCount = node.Left == null ? 0 : node.Left.Count;
int cmp = _comparer.Compare(key, node.Key);
if (cmp == 0) {
index += leftCount;
break;
} else if (cmp < 0) {
node = node.Left;
} else {
index += leftCount + 1;
node = node.Right;
}
}
return index;
}
public TValue At(int index) {
var node = root;
while (node != null) {
int leftCount = node.Left == null ? 0 : node.Left.Count;
if (index == leftCount)
return node.Value;
if (index < leftCount) {
node = node.Left;
} else {
node = node.Right;
index -= leftCount + 1;
}
}
throw new ArgumentOutOfRangeException("index");
}
public void Add(TKey key, TValue value) {
root = Add(root, key, value);
root.Color = Node.BLACK;
}
private Node Add(Node h, TKey key, TValue value) {
if (h == null) {
return new Node(key, value);
}
if (IsRed(h.Left) && IsRed(h.Right)) {
ColorFlip(h);
}
int cmp = _comparer.Compare(key, h.Key);
if (cmp == 0) {
h.Value = value;
} else if (cmp < 0) {
h.Left = Add(h.Left, key, value);
h.FixCount();
} else {
h.Right = Add(h.Right, key, value);
h.FixCount();
}
if (IsRed(h.Right) && !IsRed(h.Left)) {
h = RotateLeft(h);
}
if (IsRed(h.Left) && IsRed(h.Left.Left)) {
h = RotateRight(h);
}
return h;
}
public void RemoveMin() {
root = RemoveMin(root);
if (root != null) {
root.Color = Node.BLACK;
}
}
private Node RemoveMin(Node h) {
if (h.Left == null) {
return null;
}
if (!IsRed(h.Left) && !IsRed(h.Left.Left)) {
h = MoveRedLeft(h);
}
h.Left = RemoveMin(h.Left);
h.FixCount();
return FixUp(h);
}
public void Remove(TKey key) {
root = Remove(root, key);
if (root != null) {
root.Color = Node.BLACK;
}
}
private Node Remove(Node h, TKey key) {
if (_comparer.Compare(key, h.Key) < 0) {
if (h.Left == null) {
throw new KeyNotFoundException("key");
}
if (!IsRed(h.Left) && !IsRed(h.Left.Left)) {
h = MoveRedLeft(h);
}
h.Left = Remove(h.Left, key);
h.FixCount();
} else {
if (IsRed(h.Left)) {
h = RotateRight(h);
}
if (h.Right == null) {
if (_comparer.Compare(key, h.Key) == 0) {
return null;
}
throw new KeyNotFoundException("key");
}
if (!IsRed(h.Right) && !IsRed(h.Right.Left)) {
h = MoveRedRight(h);
}
if (_comparer.Compare(key, h.Key) == 0) {
h.Value = Find(h.Right, Min(h.Right).Key);
h.Key = Min(h.Right).Key;
h.Right = RemoveMin(h.Right);
h.FixCount();
} else {
h.Right = Remove(h.Right, key);
h.FixCount();
}
}
return FixUp(h);
}
private static Node MoveRedLeft(Node h) {
ColorFlip(h);
if (IsRed(h.Right.Left)) {
h.Right = RotateRight(h.Right);
h.FixCount();
h = RotateLeft(h);
ColorFlip(h);
}
return h;
}
private static Node MoveRedRight(Node h) {
ColorFlip(h);
if (IsRed(h.Left.Left)) {
h = RotateRight(h);
ColorFlip(h);
}
return h;
}
static private Node RotateLeft(Node h) {
Node x = h.Right;
h.Right = x.Left;
x.Left = h;
x.Color = h.Color;
h.Color = Node.RED;
h.FixCount();
x.FixCount();
return x;
}
private static Node RotateRight(Node h) {
Node x = h.Left;
h.Left = x.Right;
x.Right = h;
x.Color = h.Color;
h.Color = Node.RED;
h.FixCount();
x.FixCount();
return x;
}
private static bool IsRed(Node h) { return h != null && h.Color == Node.RED; }
static private void ColorFlip(Node h) {
h.Color = !h.Color;
h.Left.Color = !h.Left.Color;
h.Right.Color = !h.Right.Color;
}
static private Node Min(Node h) {
while (h.Left != null) {
h = h.Left;
}
return h;
}
static private Node FixUp(Node h) {
if (IsRed(h.Right)) {
h = RotateLeft(h);
}
if (h.Left != null && IsRed(h.Left) && IsRed(h.Left.Left)) {
h = RotateRight(h);
}
if (IsRed(h.Left) && IsRed(h.Right)) {
ColorFlip(h);
}
return h;
}
private class Node {
public static readonly bool RED = true;
public static readonly bool BLACK = false;
public TKey Key;
public TValue Value;
public bool Color = RED;
public Node Left = null;
public Node Right = null;
public int Count = 1;
public Node(TKey key, TValue value) {
this.Key = key;
this.Value = value;
}
public void FixCount() {
this.Count = 1;
if (Left != null)
Count += Left.Count;
if (Right != null)
Count += Right.Count;
}
}
}
// PREWRITEN CODE BEGINS FROM HERE
partial class Solver : Scanner {
public static void Main(string[] args) {
#if LOCAL
new Solver(Console.In, Console.Out).Run();
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
this.cin = reader;
this.cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
public static class LinqPadExtension {
static public T Dump<T>(this T obj) {
#if LOCAL
return LINQPad.Extensions.Dump(obj);
#else
return obj;
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { this.Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
var array = new string[size];
for (int i = 0; i < size; i++)
array[i] = Next();
return array;
}
public int[] NextIntArray(int size) {
var array = new int[size];
for (int i = 0; i < size; i++)
array[i] = NextInt();
return array;
}
public long[] NextLongArray(int size) {
var array = new long[size];
for (int i = 0; i < size; i++)
array[i] = NextLong();
return array;
}
public double[] NextDoubleArray(int size) {
var array = new double[size];
for (int i = 0; i < size; i++)
array[i] = NextDouble();
return array;
}
public string Next() {
if (TokenQueue.Count == 0) {
if (!StockTokens())
throw new InvalidOperationException();
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0)
return true;
return StockTokens();
}
static readonly char[] _separator = new[] { ' ' };
private bool StockTokens() {
while (true) {
var line = Reader.ReadLine();
if (line == null)
return false;
var tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0)
continue;
foreach (var token in tokens)
TokenQueue.Enqueue(token);
return true;
}
}
}
|
[["+", 0, 11, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 25]]
| 8
| 2,691
| 5
|
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 = 2;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
long A = inputArray[0];
long B = inputArray[1];
//最大公約数を求める
var gcd = getGcd(A, B);
if (gcd == 1) {
Console.WriteLine(2);
return;
}
//各素数で何回割れるか
var primeSet = new HashSet<long>();
long k = 2;
var tmp = gcd;
var kMax = Math.Ceiling(Math.Sqrt(long.MaxValue));
while (k * k <= gcd) {
if (tmp % k == 0) {
tmp /= k;
if (!primeSet.Contains(k)) {
primeSet.Add(k);
}
} else {
k++;
if (k > kMax) { // N<long.maxなのでk<ルート(long.max)
break;
}
}
}
if (tmp != 1) { //最後に残る素数(=Nが素数の場合など)
if (!primeSet.Contains(tmp)) {
primeSet.Add(tmp);
}
}
//答えの出力
var ans = primeSet.Count() + 1;
Console.WriteLine(ans);
}
/// <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();
}
/// <summary>
/// 最大公約数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
private static long getGcd(long a, long b) {
if (a < b) {
return getGcd(b, a);
}
if (b > 0) {
return getGcd(b, a % b);
} else {
return a;
}
}
}
}
|
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 = 2;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
long A = inputArray[0];
long B = inputArray[1];
//最大公約数を求める
var gcd = getGcd(A, B);
if (gcd == 1) {
Console.WriteLine(1);
return;
}
//各素数で何回割れるか
var primeSet = new HashSet<long>();
long k = 2;
var tmp = gcd;
var kMax = Math.Ceiling(Math.Sqrt(long.MaxValue));
while (k * k <= gcd) {
if (tmp % k == 0) {
tmp /= k;
if (!primeSet.Contains(k)) {
primeSet.Add(k);
}
} else {
k++;
if (k > kMax) { // N<long.maxなのでk<ルート(long.max)
break;
}
}
}
if (tmp != 1) { //最後に残る素数(=Nが素数の場合など)
if (!primeSet.Contains(tmp)) {
primeSet.Add(tmp);
}
}
//答えの出力
var ans = primeSet.Count() + 1;
Console.WriteLine(ans);
}
/// <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();
}
/// <summary>
/// 最大公約数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
private static long getGcd(long a, long b) {
if (a < b) {
return getGcd(b, a);
}
if (b > 0) {
return getGcd(b, a % b);
} else {
return a;
}
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 416
| 2
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections; //ハッシュテーブル用
using System.Linq;
class Program {
// Hashtable ht = new Hashtable();
static List<int> A = new List<int>();
static decimal result;
static int N, K;
// StringBuilder strresult= new StringBuilder("");//Append(str
// ○○)関数で文字を追加していく
static void Main() {
// Modular mo = new
// Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)
// Node no = new
// Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける
// Permutation pe = new
// Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
Treap<int> tr = new Treap<
int>(); //平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
// delegate int
// CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名を入れる。
PriorityQueue<int, int> pr = new PriorityQueue<
int,
int>(); //優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read1();
Read2(N);
//★素直にやると10^5の三重ループになるので計算過多。ループを何とか1重に。
//各値について、全体を見て自分より大きな数字をセーブして、それをピッタリ1跨ぎする(自分より大きいのが1コだけある)区間が、答えがその数になる区間といえる。
//なので、(求めた区間の数)*(自分自身)を足しこんで行けば答えが出る。
int before2, before1, after1, after2;
decimal num;
int k;
int count = 0;
//優先キューで、大きなものから処理するように並べ替える。(=処理済みの場所がそのまま跨ぎカウントの場所となるため、跨ぎ箇所を毎回探査しなくて済む)
for (int i = 0; i < N; i++) {
pr.Add(-A[i], i);
}
for (int i = 0; i < N; i++) {
k = pr.Dequeue().Value;
//初期の区切り位置は、配列の外の部分
before2 = -1;
before1 = -1;
after1 = N;
after2 = N;
num = 0;
if (i == 0) {
} else {
int ind = tr.FindIndex(A[k]);
//前方チェック
if (ind <= 0) {
} else if (ind == 1) {
before2 = tr[ind - 1];
} else {
before2 = tr[ind - 1];
before1 = tr[ind - 2];
}
//後方チェック
if (ind >= count) {
} else if (ind == count - 1) {
after2 = tr[ind];
} else {
after2 = tr[ind];
after1 = tr[ind + 1];
}
}
num += (before2 - before1) * (after2 - k);
num += (after1 - after2) * (k - before2);
result += num * (A[k]);
tr.Insert(k);
count++; //二分木を使って、現在地の最傍の処理済み(大きなもの)を低コストで探せるようにする
}
Console.WriteLine(result.ToString());
}
static void Read1() {
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2(int kosuu) {
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
A.Add(int.Parse(tmp[i]));
}
}
}
class PriorityQueue<TKey, TValue> {
SortedDictionary<TKey, Queue<TValue>> dict =
new SortedDictionary<TKey, Queue<TValue>>();
int count = 0;
public int Count {
get { return count; }
}
public void Add(TKey key, TValue value) {
if (!dict.ContainsKey(key)) {
dict[key] = new Queue<TValue>();
}
dict[key].Enqueue(value);
count++;
}
public KeyValuePair<TKey, TValue> Dequeue() {
var queue = dict.First();
if (queue.Value.Count <= 1) {
dict.Remove(queue.Key);
}
count--;
return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue());
}
}
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
|
using System;
using System.Collections.Generic; // list用
using System.Text; // StringBuilder用
using System.Collections; //ハッシュテーブル用
using System.Linq;
class Program {
// Hashtable ht = new Hashtable();
static List<int> A = new List<int>();
static decimal result;
static int N, K;
// StringBuilder strresult= new StringBuilder("");//Append(str
// ○○)関数で文字を追加していく
static void Main() {
// Modular mo = new
// Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)
// Node no = new
// Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける
// Permutation pe = new
// Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
Treap<int> tr = new Treap<
int>(); //平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
// delegate int
// CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名を入れる。
PriorityQueue<int, int> pr = new PriorityQueue<
int,
int>(); //優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read1();
Read2(N);
//★素直にやると10^5の三重ループになるので計算過多。ループを何とか1重に。
//各値について、全体を見て自分より大きな数字をセーブして、それをピッタリ1跨ぎする(自分より大きいのが1コだけある)区間が、答えがその数になる区間といえる。
//なので、(求めた区間の数)*(自分自身)を足しこんで行けば答えが出る。
int before2, before1, after1, after2;
decimal num;
int k;
int count = 0;
//優先キューで、大きなものから処理するように並べ替える。(=処理済みの場所がそのまま跨ぎカウントの場所となるため、跨ぎ箇所を毎回探査しなくて済む)
for (int i = 0; i < N; i++) {
pr.Add(-A[i], i);
}
for (int i = 0; i < N; i++) {
k = pr.Dequeue().Value;
//初期の区切り位置は、配列の外の部分
before2 = -1;
before1 = -1;
after1 = N;
after2 = N;
num = 0;
if (i == 0) {
} else {
int ind = tr.FindIndex(k);
//前方チェック
if (ind <= 0) {
} else if (ind == 1) {
before2 = tr[ind - 1];
} else {
before2 = tr[ind - 1];
before1 = tr[ind - 2];
}
//後方チェック
if (ind >= count) {
} else if (ind == count - 1) {
after2 = tr[ind];
} else {
after2 = tr[ind];
after1 = tr[ind + 1];
}
}
num += (before2 - before1) * (after2 - k);
num += (after1 - after2) * (k - before2);
result += num * (A[k]);
tr.Insert(k);
count++; //二分木を使って、現在地の最傍の処理済み(大きなもの)を低コストで探せるようにする
}
Console.WriteLine(result.ToString());
}
static void Read1() {
string tmp = Console.ReadLine();
N = int.Parse(tmp);
}
static void Read2(int kosuu) {
string[] tmp = Console.ReadLine().Split(' ');
for (int i = 0; i < N; i++) {
A.Add(int.Parse(tmp[i]));
}
}
}
class PriorityQueue<TKey, TValue> {
SortedDictionary<TKey, Queue<TValue>> dict =
new SortedDictionary<TKey, Queue<TValue>>();
int count = 0;
public int Count {
get { return count; }
}
public void Add(TKey key, TValue value) {
if (!dict.ContainsKey(key)) {
dict[key] = new Queue<TValue>();
}
dict[key].Enqueue(value);
count++;
}
public KeyValuePair<TKey, TValue> Dequeue() {
var queue = dict.First();
if (queue.Value.Count <= 1) {
dict.Remove(queue.Key);
}
count--;
return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue());
}
}
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
| 8
| 1,262
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderD {
static void Main() {
long a;
long b;
{
var line = Console.ReadLine();
var words = line.Split(' ');
a = long.Parse(words[0]);
b = long.Parse(words[1]);
}
long gcd = Gcd(a, b);
int count = 0;
double sqrt = Math.Sqrt(gcd);
for (int i = 1; i <= gcd; i++) {
if (gcd % i == 0) {
long c = i;
long d = gcd / i;
if (IsPrime(c)) {
count++;
}
if (c != d && IsPrime(d)) {
count++;
}
}
}
Console.WriteLine(count);
}
// 最大公約数(long)
private static long Gcd(long a, long b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
long r = a % b;
a = b;
b = r;
}
return a;
}
// 最小公倍数(long)
private static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
// 素数判定
private static bool IsPrime(long num) {
if (num <= 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrt = Math.Sqrt(num);
for (int i = 3; i <= sqrt; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderD {
static void Main() {
long a;
long b;
{
var line = Console.ReadLine();
var words = line.Split(' ');
a = long.Parse(words[0]);
b = long.Parse(words[1]);
}
long gcd = Gcd(a, b);
int count = 0;
double sqrt = Math.Sqrt(gcd);
for (int i = 1; i <= sqrt; i++) {
if (gcd % i == 0) {
long c = i;
long d = gcd / i;
if (IsPrime(c)) {
count++;
}
if (c != d && IsPrime(d)) {
count++;
}
}
}
Console.WriteLine(count);
}
// 最大公約数(long)
private static long Gcd(long a, long b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
long r = a % b;
a = b;
b = r;
}
return a;
}
// 最小公倍数(long)
private static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
// 素数判定
private static bool IsPrime(long num) {
if (num <= 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrt = Math.Sqrt(num);
for (int i = 3; i <= sqrt; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 343
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ここから
static void Solve() {
long A;
long B;
Multi(out A, out B);
var gcd = GCD(A, B);
var ans = Factoring(gcd).Keys.Count() + 1;
Console.WriteLine(ans);
}
static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public Dictionary<long, int> Factoring(long num) {
Dictionary<long, int> vs = new Dictionary<long, int>();
if (num == 1) {
vs.Add(1, 1);
return vs;
}
while (num % 2 == 0) {
if (vs.ContainsKey(2) == false) {
vs.Add(2, 0);
}
vs[2]++;
num /= 2;
}
if (num == 1) {
return vs;
}
int i = 3;
while (i <= Math.Sqrt(num)) {
if (num % i == 0) {
if (vs.ContainsKey(i) == false) {
vs.Add(i, 0);
}
vs[i]++;
num /= i;
} else {
i += 2;
}
}
if (vs.ContainsKey(num) == false) {
vs.Add(num, 1);
} else {
vs[num]++;
}
return vs;
}
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public void WriteObjects<T>(IList<T> values) {
var num = values.Count;
for (int i = 0; i < num; i++) {
Console.Write(values[i]);
if (i < num - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
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))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Swap<T>(ref T a, ref T b) {
T temp = a;
a = b;
b = temp;
}
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ここから
static void Solve() {
long A;
long B;
Multi(out A, out B);
var gcd = GCD(A, B);
var ans = gcd == 1 ? 1 : Factoring(gcd).Keys.Count() + 1;
Console.WriteLine(ans);
}
static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public Dictionary<long, int> Factoring(long num) {
Dictionary<long, int> vs = new Dictionary<long, int>();
if (num == 1) {
vs.Add(1, 1);
return vs;
}
while (num % 2 == 0) {
if (vs.ContainsKey(2) == false) {
vs.Add(2, 0);
}
vs[2]++;
num /= 2;
}
if (num == 1) {
return vs;
}
int i = 3;
while (i <= Math.Sqrt(num)) {
if (num % i == 0) {
if (vs.ContainsKey(i) == false) {
vs.Add(i, 0);
}
vs[i]++;
num /= i;
} else {
i += 2;
}
}
if (vs.ContainsKey(num) == false) {
vs.Add(num, 1);
} else {
vs[num]++;
}
return vs;
}
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public void WriteObjects<T>(IList<T> values) {
var num = values.Count;
for (int i = 0; i < num; i++) {
Console.Write(values[i]);
if (i < num - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
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))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102]]
| 8
| 1,408
| 6
|
using System;
class Program {
static void Main(string[] args) {
var ab = Console.ReadLine().Split();
var a = long.Parse(ab[0]);
var b = long.Parse(ab[1]);
var g = gcd(a, b);
var ans = m1(g) + 1;
Console.WriteLine(ans);
}
static long m1(long n) {
var ans = 0L;
for (long i = 2; i * i <= n; i++) {
if (n % i == 1)
continue;
ans++;
while (n % i == 0)
n /= i;
}
if (n != 1)
ans++;
return ans;
}
static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
}
|
using System;
class Program {
static void Main(string[] args) {
var ab = Console.ReadLine().Split();
var a = long.Parse(ab[0]);
var b = long.Parse(ab[1]);
var g = gcd(a, b);
var ans = m1(g) + 1;
Console.WriteLine(ans);
}
static long m1(long n) {
var ans = 0L;
for (long i = 2; i * i <= n; i++) {
if (n % i != 0)
continue;
ans++;
while (n % i == 0)
n /= i;
}
if (n != 1)
ans++;
return ans;
}
static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 181
| 4
|
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Diagnostics;
namespace ConsoleApplication1 {
internal class Program {
public static void Main(string[] args) {
var nums = ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
long A = nums[0];
long B = nums[1];
WriteLine(factorize(gcd(A, B)).Count);
}
static long gcd(long x, long y) { return (y == 0) ? x : gcd(y, y % x); }
static List<ValueTuple<long, int>> factorize(long n) {
var list = new List<ValueTuple<long, int>>();
list.Add(new ValueTuple<long, int>(1, 1));
for (long i = 2; i * i < n; i++) {
if (n % i != 0)
continue;
int divideCount = 0;
while (n % i == 0) {
n /= i;
divideCount++;
}
list.Add(new ValueTuple<long, int>(i, divideCount));
}
if (n != 1)
list.Add(new ValueTuple<long, int>(n, 1));
return list;
}
public struct ValueTuple<T1, T2> {
public T1 item1;
public T2 item2;
public ValueTuple(T1 a, T2 b) {
item1 = a;
item2 = b;
}
}
}
}
|
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Diagnostics;
namespace ConsoleApplication1 {
internal class Program {
public static void Main(string[] args) {
var nums = ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
long A = nums[0];
long B = nums[1];
WriteLine(factorize(gcd(A, B)).Count);
}
static long gcd(long x, long y) { return (y == 0) ? x : gcd(y, x % y); }
static List<ValueTuple<long, int>> factorize(long n) {
var list = new List<ValueTuple<long, int>>();
list.Add(new ValueTuple<long, int>(1, 1));
for (long i = 2; i * i < n; i++) {
if (n % i != 0)
continue;
int divideCount = 0;
while (n % i == 0) {
n /= i;
divideCount++;
}
list.Add(new ValueTuple<long, int>(i, divideCount));
}
if (n != 1)
list.Add(new ValueTuple<long, int>(n, 1));
return list;
}
public struct ValueTuple<T1, T2> {
public T1 item1;
public T2 item2;
public ValueTuple(T1 a, T2 b) {
item1 = a;
item2 = b;
}
}
}
}
|
[["-", 75, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 75, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 75, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 75, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 331
| 4
|
using System;
using System.Collections.Generic;
namespace AtCoderBeginnerContest142_D {
class Program {
static void Main(string[] args) {
string[] ab = Console.ReadLine().Split(' ');
long A = long.Parse(ab[0]);
long B = long.Parse(ab[1]);
List<long> ans = new List<long>();
long gcd = GreatestCommonDivisor(A, B);
Dictionary<long, int> fac = Factorize(gcd);
Console.WriteLine(fac.Count + 1);
// Console.WriteLine(string.Join(' ', fac.Keys));
// Console.ReadKey();
}
public static Dictionary<long, int> Factorize(long n) {
Dictionary<long, int> res = new Dictionary<long, int>();
for (long i = 2; i * i < n; i++) {
if (n % i == 1)
continue;
res.Add(i, 1);
while (n % i == 0) {
n /= i;
res[i]++;
}
}
if (n != 1)
res.Add(n, 1);
return res;
}
public static long GreatestCommonDivisor(long a, long b) {
if (b == 0) {
return a;
}
return GreatestCommonDivisor(b, a % b);
}
}
}
|
using System;
using System.Collections.Generic;
namespace AtCoderBeginnerContest142_D {
class Program {
static void Main(string[] args) {
string[] ab = Console.ReadLine().Split(' ');
long A = long.Parse(ab[0]);
long B = long.Parse(ab[1]);
List<long> ans = new List<long>();
long gcd = GreatestCommonDivisor(A, B);
// Console.WriteLine(gcd);
Dictionary<long, int> fac = Factorize(gcd);
Console.WriteLine(fac.Count + 1);
// Console.WriteLine(string.Join(' ', fac.Keys));
// Console.ReadKey();
}
public static Dictionary<long, int> Factorize(long n) {
Dictionary<long, int> res = new Dictionary<long, int>();
for (long i = 2; i * i < n; i++) {
if (n % i != 0)
continue;
res.Add(i, 0);
while (n % i == 0) {
n /= i;
res[i]++;
}
}
if (n != 1)
res.Add(n, 1);
return res;
}
public static long GreatestCommonDivisor(long a, long b) {
if (b == 0) {
return a;
}
return GreatestCommonDivisor(b, a % b);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 265
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
public static void Main() {
long A = 0, B = 0;
new readlong(ref A, ref B);
long gcd = Util.GCD(A, B);
long data_gcd = gcd;
var couldDivide = Util.PrimeFactorization(gcd);
var l = new List<long>();
foreach (var d in couldDivide.Skip(1)) {
if (l.TrueForAll(x => d % x != 0))
l.Add(d);
}
Console.WriteLine(l.Count());
}
}
class readint {
public readint(ref int i) { i = int.Parse(Console.ReadLine()); }
public readint(ref int a, ref int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(ref int a, ref int b, ref int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(ref int a, ref int b, ref int c, ref int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(ref long i) { i = long.Parse(Console.ReadLine()); }
public readlong(ref long a, ref long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(ref long a, ref long b, ref long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(ref long a, ref long b, ref long c, ref long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class Util {
public static long[] PrimeFactorization(long v) {
var d = new List<long>();
var c = 0;
for (long i = 1, j, rv = (long)Math.Sqrt(v); i <= rv; i++)
if (v % i == 0) {
d.Insert(c, i);
if ((j = v / i) != i)
d.Insert(++c, j);
}
return d.ToArray();
}
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
public static int GCD(int a, int b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
public static int Factorial(int n) { return factorial_modM[n]; }
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
public static int nCr_modM(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
}
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
static class Permutation<T> {
private static void Search(List<T[]> perms, Stack<T> stack, T[] a) {
int N = a.Length;
if (N == 0) {
perms.Add(stack.Reverse().ToArray());
} else {
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i) {
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) {
b[i] = a[i];
}
stack.Pop();
}
}
}
public static IEnumerable<T[]> All(IEnumerable<T> src) {
var perms = new List<T[]>();
Search(perms, new Stack<T>(), src.ToArray());
return perms;
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
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]; }
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
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));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
public static void Main() {
long A = 0, B = 0;
new readlong(ref A, ref B);
long gcd = Util.GCD(A, B);
long data_gcd = gcd;
var couldDivide = Util.PrimeFactorization(gcd);
var l = new List<long>();
foreach (var d in couldDivide.Skip(1)) {
if (l.TrueForAll(x => d % x != 0))
l.Add(d);
}
Console.WriteLine(l.Count() + 1);
}
}
class readint {
public readint(ref int i) { i = int.Parse(Console.ReadLine()); }
public readint(ref int a, ref int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(ref int a, ref int b, ref int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(ref int a, ref int b, ref int c, ref int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(ref long i) { i = long.Parse(Console.ReadLine()); }
public readlong(ref long a, ref long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(ref long a, ref long b, ref long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(ref long a, ref long b, ref long c, ref long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class Util {
public static long[] PrimeFactorization(long v) {
var d = new List<long>();
var c = 0;
for (long i = 1, j, rv = (long)Math.Sqrt(v); i <= rv; i++)
if (v % i == 0) {
d.Insert(c, i);
if ((j = v / i) != i)
d.Insert(++c, j);
}
return d.ToArray();
}
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
public static int GCD(int a, int b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
public static int Factorial(int n) { return factorial_modM[n]; }
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
public static int nCr_modM(int n, int r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
}
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
static class Permutation<T> {
private static void Search(List<T[]> perms, Stack<T> stack, T[] a) {
int N = a.Length;
if (N == 0) {
perms.Add(stack.Reverse().ToArray());
} else {
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i) {
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) {
b[i] = a[i];
}
stack.Pop();
}
}
}
public static IEnumerable<T[]> All(IEnumerable<T> src) {
var perms = new List<T[]>();
Search(perms, new Stack<T>(), src.ToArray());
return perms;
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
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]; }
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
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));
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 3,223
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Numerics;
class Myon {
// chokudaiさんのコードをコピペ
static Scanner cin;
public Myon() {}
public static int Main() {
// Console.SetOut(new Printer(Console.OpenStandardOutput()));
cin = new Scanner();
new Myon().calc();
Console.Read();
return 0;
}
public static long gcd(long a, long b) {
if (a <= 0)
return -1;
// if (a > b) return gcd(b, a);
if (a == 0)
return b;
return gcd(b, a % b);
}
public static long gcd2(long a, long b) {
if (a <= 0)
return -1;
if (a == 0)
return b;
return gcd2(b, a % b);
}
public void calc() {
long a = cin.nextLong();
long b = cin.nextLong();
long temp = gcd(a, b);
long max = (long)Math.Sqrt(temp);
int i = 2;
int ans = 1;
while (temp > 1) {
if (temp % i == 0) {
while (temp % i == 0)
temp /= i;
ans++;
} else if (i > max) {
ans++; // temp != 0 max以降に必ず一つだけ
break;
}
}
Console.WriteLine(ans);
}
// public void calcD()
//{
// long a = cin.nextLong();
// long b = cin.nextLong();
// long gcd2 = Gcd(a, b);
// int count = 0; //公約数のもつ素因数の数 ただし重複は数えない 12 なら
// 2(2^2 3 )だが3でない int temp = 1; long max = (long)Math.Sqrt(gcd2);
// while (gcd2 != 1)
// {
// temp++;
// if (gcd2 % temp == 0)
// {
// count++;
// while (gcd2 % temp == 0) gcd2 /= temp;
// }
// else if (temp > max) { count++; break; }
// }
// showL(count + 1);
//}
public void backetSort(ref int[] a) {
// max a << a.len に対して有効なソート
//よってa = int[] とする
long n = a.Length;
var count = new int[n];
var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index]
// = loc[i]
for (long i = 0; i < n; i++)
count[a[i]]++;
loc[0] = count[0] - 1;
for (long i = 0; i < n - 1; i++)
loc[i + 1] = loc[i] + count[i + 1];
long index = 0;
for (int i = 0; i < n; i++) {
while (index <= loc[i])
a[index++] = i; // incex <= loc[i] == index < loc[i] + 1
}
}
public static void showL(long n) { Console.WriteLine(n); }
public static void showL(string s) { Console.WriteLine(s); }
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
while (i >= s.Length) {
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
}
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Numerics;
class Myon {
// chokudaiさんのコードをコピペ
static Scanner cin;
public Myon() {}
public static int Main() {
// Console.SetOut(new Printer(Console.OpenStandardOutput()));
cin = new Scanner();
new Myon().calc();
Console.Read();
return 0;
}
public static long gcd(long a, long b) {
if (a <= 0)
return -1;
// if (a > b) return gcd(b, a);
if (b == 0)
return a;
return gcd(b, a % b);
}
public static long gcd2(long a, long b) {
if (a <= 0)
return -1;
if (a == 0)
return b;
return gcd2(b, a % b);
}
public void calc() {
long a = cin.nextLong();
long b = cin.nextLong();
long temp = gcd(a, b);
// Console.WriteLine(temp);
long max = (long)Math.Sqrt(temp);
int i = 2;
int ans = 1;
while (temp > 1) {
if (temp % i == 0) {
while (temp % i == 0)
temp /= i;
ans++;
} else if (i > max) {
ans++; // temp != 0 max以降に必ず一つだけ
break;
}
i++;
}
Console.WriteLine(ans);
}
// public void calcD()
//{
// long a = cin.nextLong();
// long b = cin.nextLong();
// long gcd2 = Gcd(a, b);
// int count = 0; //公約数のもつ素因数の数 ただし重複は数えない 12 なら
// 2(2^2 3 )だが3でない int temp = 1; long max = (long)Math.Sqrt(gcd2);
// while (gcd2 != 1)
// {
// temp++;
// if (gcd2 % temp == 0)
// {
// count++;
// while (gcd2 % temp == 0) gcd2 /= temp;
// }
// else if (temp > max) { count++; break; }
// }
// showL(count + 1);
//}
public void backetSort(ref int[] a) {
// max a << a.len に対して有効なソート
//よってa = int[] とする
long n = a.Length;
var count = new int[n];
var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index]
// = loc[i]
for (long i = 0; i < n; i++)
count[a[i]]++;
loc[0] = count[0] - 1;
for (long i = 0; i < n - 1; i++)
loc[i + 1] = loc[i] + count[i + 1];
long index = 0;
for (int i = 0; i < n; i++) {
while (index <= loc[i])
a[index++] = i; // incex <= loc[i] == index < loc[i] + 1
}
}
public static void showL(long n) { Console.WriteLine(n); }
public static void showL(string s) { Console.WriteLine(s); }
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
while (i >= s.Length) {
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
}
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 710
| 7
|
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
public static void Main() {
var a = NextLong;
var b = NextLong;
var gcd = GCD(a, b);
long i = 2;
int res = 1;
var sqrt = (int)Ceiling(Sqrt(gcd));
while (i <= sqrt) {
if (gcd % i == 0) {
res++;
while (gcd % i == 0)
gcd /= i;
}
i++;
}
if (gcd != 1)
i++;
Console.WriteLine(res);
}
static long GCD(long a, long b) {
while (true) {
if (b == 0)
return a;
a %= b;
if (a == 0)
return b;
b %= a;
}
}
static long NextLong {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
long res = 0;
int next = Console.In.Read();
int sign = 1;
while (45 > next || next > 57)
next = Console.In.Read();
if (next == 45) {
next = Console.In.Read();
sign = -1;
}
while (48 <= next && next <= 57) {
res = res * 10 + next - 48;
next = Console.In.Read();
}
return res * sign;
}
}
}
|
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
public static void Main() {
var a = NextLong;
var b = NextLong;
var gcd = GCD(a, b);
long i = 2;
int res = 1;
var sqrt = (int)Ceiling(Sqrt(gcd));
while (i <= sqrt) {
if (gcd % i == 0) {
res++;
while (gcd % i == 0)
gcd /= i;
}
i++;
}
if (gcd != 1)
res++;
Console.WriteLine(res);
}
static long GCD(long a, long b) {
while (true) {
if (b == 0)
return a;
a %= b;
if (a == 0)
return b;
b %= a;
}
}
static long NextLong {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
long res = 0;
int next = Console.In.Read();
int sign = 1;
while (45 > next || next > 57)
next = Console.In.Read();
if (next == 45) {
next = Console.In.Read();
sign = -1;
}
while (48 <= next && next <= 57) {
res = res * 10 + next - 48;
next = Console.In.Read();
}
return res * sign;
}
}
}
|
[["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22]]
| 8
| 355
| 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;
private static long max = 999999999999;
static void Main(string[] args) {
var r1 = ReadSplit();
var n = r1[0].Long();
var m = r1[1].Long();
var dp = new long [m + 1][];
var INF = 9999999999;
for (int i = 0; i <= m; i++) {
dp[i] = new long[5000];
for (int j = 0; j < 5000; j++) {
dp[i][j] = INF;
}
}
var cl = new long[m];
var kl = new long[m];
for (int i = 0; i < m; i++) {
var r2 = ReadSplit();
var a = r2[0].Long();
var b = r2[1].Long();
var r3 = ReadSplit();
var c = 0D;
for (int k = 0; k < b; k++) {
var no = r3[k].Long();
c += Math.Pow(2, no - 1);
}
kl[i] = (long)c;
cl[i] = (long)a;
}
dp[0][0] = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < Math.Pow(2, n); j++) {
ChangeMin(ref dp[i + 1][j], dp[i][j]);
ChangeMin(ref dp[i + 1][j | (int)kl[i]], dp[i][j] + cl[i]);
}
}
var ans = max;
var all = 0;
for (int i = 0; i < n; i++) {
all += (int)Math.Pow(2, i);
}
for (int i = 1; i < m; i++) {
ans = Math.Min(dp[i][all], ans);
}
if (ans >= max) {
ans = -1;
}
WriteRead(ans);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
// using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var r1 = ReadSplit();
var n = r1[0].Long();
var m = r1[1].Long();
var dp = new long [m + 1][];
var INF = 9999999999;
for (int i = 0; i <= m; i++) {
dp[i] = new long[5000];
for (int j = 0; j < 5000; j++) {
dp[i][j] = INF;
}
}
var cl = new long[m];
var kl = new long[m];
for (int i = 0; i < m; i++) {
var r2 = ReadSplit();
var a = r2[0].Long();
var b = r2[1].Long();
var r3 = ReadSplit();
var c = 0D;
for (int k = 0; k < b; k++) {
var no = r3[k].Long();
c += Math.Pow(2, no - 1);
}
kl[i] = (long)c;
cl[i] = (long)a;
}
dp[0][0] = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < Math.Pow(2, n); j++) {
ChangeMin(ref dp[i + 1][j], dp[i][j]);
ChangeMin(ref dp[i + 1][j | (int)kl[i]], dp[i][j] + cl[i]);
}
}
var ans = INF;
var all = 0;
for (int i = 0; i < n; i++) {
all += (int)Math.Pow(2, i);
}
for (int i = 1; i <= m; i++) {
ans = Math.Min(dp[i][all], ans);
}
if (ans >= INF) {
ans = -1;
}
WriteRead(ans);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 1,562
| 6
|
// optional
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
public static class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var nm = ReadLib.ReadAsIntArray();
var n = nm[0];
var m = nm[1];
var costs = new int[m + 1];
var opens = new int[m + 1];
for (int i = 1; i <= m; i++) {
var ab = ReadLib.ReadAsIntArray();
costs[i] = ab[0];
var cs = ReadLib.ReadAsIntArray();
opens[i] = cs.Select(c => 1 << (c - 1)).Sum();
}
// 2次元目:
// 2進数のn桁目(配列として見たときの**n-1**番目)は宝箱の開閉を示す
var dp = new int[m + 1, 1 << n];
dp.Initialize(int.MaxValue);
dp[0, 0] = 0;
for (int key = 1; key <= m; key++) {
for (int open = 0; open < 1 << n; open++) {
dp[key, open] = Math.Min(dp[key, open], dp[key - 1, open]);
var afterOpen = open | opens[key];
dp[key, afterOpen] =
Math.Min(dp[key, afterOpen],
dp[key - 1, open] == int.MaxValue
? int.MaxValue
: dp[key - 1, open] + costs[key] // オーバーフロー対策
);
}
}
var score = dp[m, 1 << n - 1] != int.MaxValue ? dp[m, 1 << n - 1] : -1;
Console.WriteLine(score);
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class ReadLib {
public static long ReadAsLong() { return long.Parse(Console.ReadLine()); }
public static int ReadAsInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadAsIntArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) + step)
.ToArray();
}
public static long[] ReadAsLongArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => long.Parse(s) + step)
.ToArray();
}
public static ulong[] ReadAsULongArray() {
return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
}
public static string[] ReadAsStringArray() {
return Console.ReadLine().Split(' ');
}
public static int[] ReadNTimesAsInt(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => int.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static char[][] ReadNTimesAsCharArray(int n) {
return Enumerable.Range(1, n)
.Select(i => Console.ReadLine().ToArray())
.ToArray();
}
public static long[] ReadNTimesAsLong(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => long.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static int[][] ReadNTimesAsIntArray(int n, int step = 0) {
return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray();
}
public static string[] ReadNTimesAsString(int n) {
return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray();
}
}
namespace Heaps {
/// <summary>優先度付きキュー</summary>
public class PriorityQueue<T> : IEnumerable<T>, IReadOnlyCollection<T>
where T : IComparable<T> {
public List<T> HeapArray { get; }
public T NIL { get; }
public bool IsMax { get; }
public int Count => HeapArray.Count;
/// <param name="heapArray">ヒープ</param>
/// <param name="NIL">NILの値</param>
/// <param
/// name="IsMax">True時:大きい方から取り出す、False時:小さい方から取り出す</param>
public PriorityQueue(T NIL, IEnumerable<T> heapArray = null,
bool IsMax = true) {
this.HeapArray = heapArray == null ? new List<T>() : heapArray.ToList();
this.NIL = NIL;
this.IsMax = IsMax;
Update();
}
/// <summary>KeyのValueを取得</summary>
public T this[int id] {
get {
if (id <= 0 || id > HeapArray.Count) {
return NIL;
}
return HeapArray[id - 1];
}
}
class Node {
public int Key { get; }
public T Value => outer[Key];
readonly PriorityQueue<T> outer;
public Node(int key, PriorityQueue<T> outer) {
Key = key;
this.outer = outer;
}
public Node Left {
get {
var leftKey = 2 * Key;
return new Node(leftKey, outer);
}
}
public Node Right {
get {
var rightkey = 2 * Key + 1;
return new Node(rightkey, outer);
}
}
public Node Parent {
get {
var parentKey = Key / 2;
return new Node(parentKey, outer);
}
}
}
private Node GetNode(int key) { return new Node(key, this); }
/// <summary>max Heap木とする O(N)</summary>
public void Update() {
var n = HeapArray.Count() / 2;
/// <summary>葉から順に処理を行う</summary>
for (int i = n; i >= 1; i--) {
Heapify(i);
}
}
/// <summary>idを根とする部分木について、Heap木を維持したまま、idを下降させる</summary>
private void Heapify(int key) {
var current = GetNode(key);
var left = current.Left;
var right = current.Right;
var largest = current;
var sign = IsMax ? 1 : -1;
if (left.Value.CompareTo(NIL) != 0 &&
left.Value.CompareTo(current.Value) * sign > 0) {
largest = left;
}
if (right.Value.CompareTo(NIL) != 0 &&
right.Value.CompareTo(largest.Value) * sign > 0) {
largest = right;
}
if (largest.Key != key) {
HeapArray.Swap(key - 1, largest.Key - 1); // 元と異なるときはSwapする
Heapify(
largest
.Key); // largest.Key は元のkeyの場所。葉で更にMaxHeaptyを行う。
}
}
/// <summary>keyの値を挿入する</summary>
public void Enqueue(T value) {
HeapArray.Add(value);
var inserted = GetNode(HeapArray.Count); // 末尾に挿入
var parent = inserted.Parent;
var sign = IsMax ? 1 : -1;
// 挿入Nodeが根になる or 親 > 子になるまで親とNodeを交換
while (inserted.Key > 1 && value.CompareTo(parent.Value) * sign > 0) {
HeapArray.Swap(inserted.Key - 1, parent.Key - 1);
inserted = parent;
parent = inserted.Parent;
}
}
public T Dequeue() {
if (HeapArray.Count == 0) {
return NIL;
}
var popVal = HeapArray.First();
var newRootVal = HeapArray.Last(); // 新しい根となる。
HeapArray.RemoveAt(HeapArray.Count - 1); // del last
if (HeapArray.Count > 0) {
HeapArray[0] = newRootVal;
Heapify(1);
}
return popVal;
}
public T Peek() { return HeapArray.First(); }
public IEnumerator<T> GetEnumerator() {
while (HeapArray.Count > 0) {
yield return Dequeue();
}
}
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
public void Clear() { HeapArray.Clear(); }
public bool Contains(T val) { return HeapArray.Contains(val); }
public PriorityQueue<T> Clone() {
return new PriorityQueue<T>(NIL, HeapArray.DeepCopy());
}
}
}
/// <summary>拡張メソッドs</summary>
static class MyExtention {
/// <summary>iとjを入れ替える</summary>
public static void Swap<T>(this T[] arr, int i, int j) {
var buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
}
public static void Swap<T>(this List<T> list, int i, int j) {
var buf = list[i];
list[i] = list[j];
list[j] = buf;
}
/// <summary>
/// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。
/// </summary>
/// <param name="sArr"></param>
/// <param name="p">partitionの先頭の添字</param>
/// <param name="r">partitionの末尾の添字</param>
/// <returns>partitionの基準が存在する添字</returns>
public static int Partition(this int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
/// <summary>深いコピーをする</summary>
public static T DeepCopy<T>(this T obj) {
T result;
var b = new BinaryFormatter();
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
public static string Left(this string str, int length) {
return str.Substring(0, length);
}
public static string Right(this string str, int length) {
return str.Substring(str.Length - length, length);
}
public static int Find<T>(this T[] array, T obj) {
return Array.IndexOf(array, obj);
}
public static int LastFind<T>(this T[] array, T obj) {
return Array.LastIndexOf(array, obj);
}
/// <summary>同一の値で埋める</summary>
public static void Initialize<T>(this T[] array, T value) {
for (int i = 0; i < array.Length; i++) {
array[i] = value;
}
}
/// <summary>同一の値で埋める</summary>
public static void Initialize<T>(this T[,] array, T value) {
for (int i = 0; i < array.GetLength(0); i++) {
for (int j = 0; j < array.GetLength(1); j++) {
array[i, j] = value;
}
}
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
public static ModCombination ModCombination(int maxN, int mod = 1000000007) {
return new ModCombination(maxN, mod);
}
/// <summary>a^n mod</summary>
public static int ModPow(long a, long n, int mod = 1000000007) {
long res = 1;
long pow = a;
while (n > 0) {
if ((n & 1) == 1) {
res = (pow * res) % mod; // resにaをかける
}
pow = (pow * pow) % mod; // 次のaはa^2
n >>= 1;
}
return (int)res;
}
/// <summary>約数を列挙</summary>
public static long[] Divisors(long n) {
var ret = new List<long>();
var sqrt = Math.Ceiling(Math.Sqrt(n));
for (long i = 1; i <= sqrt; i++) {
if (i * i > n) {
continue;
}
if (n % i != 0) {
continue;
}
ret.Add(i);
if (n / i == i) {
continue;
}
ret.Add(n / i);
}
return ret.ToArray();
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
/// <summary>ある要素を持つindexをすべて返す</summary>
public static int[] InducesOfValue<T>(this T[] arr, T searchValue) {
return arr.Select((v, i) => new { v, i })
.Where(o => searchValue.Equals(o.v))
.Select(o => o.i)
.ToArray();
}
/// <summary>ある要素を持つindexをすべて返す</summary>
public static int[] Induces<T>(this IEnumerable<T> arr, T searchValue) {
return arr.ToArray().InducesOfValue(searchValue);
}
}
/// <summary>組み合わせ</summary>
class ModCombination {
private int mod;
private int[] fac;
private int[] finv;
private int[] inv;
public ModCombination(int max, int mod = 1000000007) {
this.mod = mod;
fac = new int[max]; // modが法のn!の列
inv = new int[max]; // indexの逆元の列
finv = new int[max]; // modを法とした、invの累積の累積
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める
var s = Math.BigMul(inv[mod % i], mod / i) % mod;
inv[i] = (int)(mod - s);
// iに対する逆元を求める
finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod);
}
}
/// <summary>nCk</summary>
public int Calculation(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (int)(Math.BigMul(fac[n],
(int)(Math.BigMul(finv[k], finv[n - k]) % mod)) %
mod);
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator -(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value - item2.Value;
if (value < 0) {
value += item1.Mod;
}
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
return item1 + new ModInt(item2, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
return item1 * new ModInt(item2, item1.Mod);
}
public static ModInt operator -(ModInt item1, int item2) {
return item1 - new ModInt(item2, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
// optional
namespace Graph {
/// <summary>無向グラフ</summary>
class UndirectedGraph {
public Dictionary<int, List<int>> Graph { get; }
/// <param name="graphArr">point1 to point2</param>
/// <param name="n">グラフの全要素数</param>
public UndirectedGraph(int[][] graphArr, int n) {
Graph = new Dictionary<int, List<int>>();
for (int i = 1; i <= n; i++) {
Graph.Add(i, new List<int>());
}
foreach (var arr in graphArr) {
Graph[arr[0]].Add(arr[1]);
Graph[arr[1]].Add(arr[0]);
}
}
}
/// <summary>有向グラフの隣接行列表現</summary>
class AdjacencyMatrixCreator {
public int[][] Matrix { get; }
public AdjacencyMatrixCreator(int[][] matrix) { this.Matrix = matrix; }
/// <summary>ノード数nの隣接行列表現を生成.1オリジン</summary>
public AdjacencyMatrixCreator(int n, int defaultVal = 0) {
Matrix = new int [n + 1][];
for (int i = 0; i <= n; i++) {
Matrix[i] = new int[n + 1];
for (int j = 0; j <= n; j++) {
Matrix[i][j] = defaultVal;
}
}
}
/// <summary>
/// 辺の追加 (行列に1を足す)
/// </summary>
/// <param name="nodeNo">元ノードのNo</param>
/// <param name="outDegree">出次数</param>
/// <param name="outNodeNos">向かう先のノードNo</param>
public void AddEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) {
foreach (var outNodeNo in outNodeNos) {
Matrix[nodeNo][outNodeNo] = 1;
}
}
/// <summary>
/// 辺の削除 (行列を0にする)
/// </summary>
/// <param name="nodeNo">元ノードのNo</param>
/// <param name="outDegree">出次数</param>
/// <param name="outNodeNos">向かう先のノードNo</param>
public void DelEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) {
foreach (var outNodeNo in outNodeNos) {
Matrix[nodeNo][outNodeNo] = 0;
}
}
}
}
namespace Sort {
static class MergeSort {
/// <summary>ソートを行う(mutable)</summary>
public static void Sort(long[] arr) { Sort(arr, 0, arr.Count()); }
private static void Sort(long[] sArr, int left, int right) {
if (left + 1 < right) {
var mid = (left + right) / 2;
Sort(sArr, left, mid); // left ~ mid-1をソート
Sort(sArr, mid, right); // mid ~ rightをソート
Merge(sArr, left, mid, right); // 昇順に並んだ2つの列を結合する。
}
}
// arrのleftとrightは昇順に並ぶのでO(n1+n2)
private static void Merge(long[] arr, int left, int mid, int right) {
var lArr = new long[mid - left + 1];
var rArr = new long[right - mid + 1];
for (int i = 0; i < mid - left; i++) {
lArr[i] = arr[left + i];
}
lArr[mid - left] = long.MaxValue;
for (int i = 0; i < right - mid; i++) {
rArr[i] = arr[mid + i];
}
rArr[right - mid] = long.MaxValue;
int l = 0, r = 0;
// arrを並び替える
for (int i = left; i < right; i++) {
if (lArr[l] > rArr[r]) {
arr[i] = rArr[r];
r++;
} else {
arr[i] = lArr[l];
l++;
}
}
}
}
static class QuickSort {
internal static void Sort(int[] ts) { Sort(ts, 0, ts.Count() - 1); }
/// <summary>Quickソート</summary>
private static void Sort(int[] ts, int p, int r) {
if (p < r) {
var q = Partition(ts, p, r);
Sort(ts, p, q - 1);
Sort(ts, q + 1, r);
}
}
public static int Partition(int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
}
/// <summary>計数ソート</summary>
static class CountingSort {
public static int[] Sort(int[] aArr, int k) {
int[] b, c;
var n = aArr.Length;
b = new int[n];
c = Enumerable.Repeat(0, k + 1).ToArray();
for (int i = 0; i < n; i++) {
c[aArr[i]]++;
}
for (int i = 1; i <= k; i++) {
c[i] += c[i - 1];
}
for (int i = n - 1; i >= 0; i--) {
b[c[aArr[i]] - 1] = aArr[i];
c[aArr[i]]--;
}
return b;
}
}
}
namespace Tree {
/// <summary>UnionFind木</summary>
public class UnionFind {
Dictionary<int, int> nodeToRoot;
Dictionary<int, int> rank; // その根が配下に何個nodeがぶら下がっているか
public UnionFind(int n, int startAt = 0) {
nodeToRoot = Enumerable.Range(startAt, n)
.ToDictionary(i => i, i => i); // n個根を作る
rank = Enumerable.Range(startAt, n).ToDictionary(i => i, i => 0);
}
/// <summary>根を得る</summary>
public int GetRoot(int x) {
if (nodeToRoot[x] == x) { // 渡されたノードが根
return x;
}
nodeToRoot[x] =
GetRoot(nodeToRoot[x]); // parentの根を得てset。調べるたびに最適化。
return nodeToRoot[x];
}
/// <summary>xとyの木を併合 => 根を同一にする</summary>
public void Unite(int x, int y) {
var rootX = GetRoot(x);
var rootY = GetRoot(y);
if (rootX == rootY) {
return; // pass
}
if (rank[rootX] < rank[rootY]) { // yをxへ併合
nodeToRoot[rootX] = nodeToRoot[rootY];
} else {
nodeToRoot[rootX] = nodeToRoot[rootY];
if (rank[rootX] == rank[rootY]) {
rank[rootX]++; // yの下に配下が1つ追加される。
}
}
}
public bool AreSameRoot(int x, int y) { return GetRoot(x) == GetRoot(y); }
}
/// <summary>根付き木</summary>
public class RootedTree {
readonly Dictionary<int, Node> nodes;
const int NIL = -1;
int startAt;
int nNode;
class Node {
/// <summary>親のID</summary>
public int Parent { get; set; }
/// <summary>子の最左端</summary>
public int LeftChild { get; set; }
/// <summary>右の兄弟</summary>
public int RightBrother { get; set; }
/// <summary>深さ</summary>
public int Depth { get; set; }
public Node() {
Parent = NIL;
LeftChild = NIL;
RightBrother = NIL;
Depth = 0;
}
}
/// <summary>根付き木</summary>
public RootedTree(int n, int startAt = 0) {
this.nodes =
Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node());
this.startAt = startAt;
this.nNode = n;
}
/// <summary>Nodeに子を追加</summary>
public void SetChilds(int id, int[] childs) {
if (childs.Length == 0) {
return;
}
nodes[id].LeftChild = childs.First();
for (int i = 0; i < childs.Length - 1; i++) {
int childId = childs[i];
nodes[childId].Parent = id;
nodes[childId].RightBrother = childs[i + 1];
}
nodes[childs.Last()].Parent = id;
}
/// <summary>親Idを取得</summary>
public int GetParentId(int id) { return nodes[id].Parent; }
/// <summary>子のidを取得</summary>
public int[] GetChilds(int id) {
var childs = new List<int>();
var child = nodes[id].LeftChild;
while (child != NIL) {
childs.Add(child);
child = nodes[child].RightBrother;
}
return childs.ToArray();
}
int Root = NIL;
public int GetRoot() {
if (Root == NIL) {
var current = nodes.First().Key; // 何でもいい
var parent = nodes[current].Parent;
while (parent != NIL) {
current = parent;
parent = nodes[current].Parent;
}
Root = current;
}
return Root;
}
bool isSetedDepth = false;
/// <summary>深さを取得</summary>
public int GetDepth(int id) {
if (!isSetedDepth) {
var root = GetRoot();
SetDepth(root, depth: 0);
isSetedDepth = true;
}
var current = id;
var parent = nodes[id].Parent;
var depth = 0;
while (parent != NIL) {
current = parent;
parent = nodes[current].Parent;
depth++;
}
return depth;
}
private void SetDepth(int id, int depth) {
var node = nodes[id];
node.Depth = depth;
if (node.RightBrother != NIL) {
SetDepth(node.RightBrother, depth);
}
if (node.LeftChild != NIL) {
SetDepth(node.LeftChild, depth + 1);
}
}
public int NodesCount() { return nodes.Count(); }
}
/// <summary>二分木</summary>
public class BinaryTree {
const int NIL = int.MinValue;
readonly int startAt;
readonly int nNode;
class Node {
public int Parent { get; set; }
public int LeftChild { get; set; }
public int RightChild { get; set; }
public int Depth { get; set; }
public int Height { get; set; }
/// <summary>唯一の兄弟</summary>
public int Sibling { get; set; }
public Node() {
Parent = NIL;
LeftChild = NIL;
RightChild = NIL;
Sibling = NIL;
Depth = 0;
Height = 0;
}
}
Dictionary<int, Node> nodes;
public BinaryTree(int n, int startAt) {
this.nodes =
Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node());
this.startAt = startAt;
this.nNode = n;
}
/// <summary>
/// 子をセットする
/// </summary>
/// <param name="id">ノードのID</param>
/// <param name="left">左子ID。存在しない場合は-1</param>
/// <param name="right">右子ID。存在しない場合は-1</param>
public void SetChilds(int id, int left, int right) {
nodes[id].LeftChild = left;
nodes[id].RightChild = right;
if (left != NIL) {
nodes[left].Parent = id;
nodes[left].Sibling = right;
}
if (right != NIL) {
nodes[right].Parent = id;
nodes[right].Sibling = left;
}
}
/// <summary>Root</summary>
int Root = NIL;
public int GetRoot() {
if (Root == NIL) {
var current = nodes.First().Key;
var parent = nodes[current].Parent;
while (parent != NIL) {
current = parent;
parent = nodes[current].Parent;
}
Root = current;
}
return Root;
}
#region Depth
bool isSetDepth = false;
public int GetDepth(int id) {
if (!isSetDepth) {
var root = GetRoot();
SetDepth(root, 0);
isSetDepth = true;
}
return nodes[id].Depth;
}
private void SetDepth(int id, int depth) {
nodes[id].Depth = depth;
if (nodes[id].LeftChild != NIL) {
SetDepth(nodes[id].LeftChild, depth + 1);
}
if (nodes[id].RightChild != NIL) {
SetDepth(nodes[id].RightChild, depth + 1);
}
}
#endregion
#region Height
bool isSetHeight = false;
/// <summary>高さを得る</summary>
public int GetHeight(int id) {
if (!isSetHeight) {
var root = GetRoot();
SetHeight(root);
isSetHeight = true;
}
return nodes[id].Height;
}
public int SetHeight(int id) {
var node = nodes[id];
int hLeft = 0;
int hRight = 0;
if (node.LeftChild != NIL) {
hLeft = SetHeight(node.LeftChild) + 1;
}
if (node.RightChild != NIL) {
hRight = SetHeight(node.RightChild) + 1;
}
node.Height = Math.Max(hLeft, hRight);
return node.Height;
}
#endregion
/// <summary>兄弟を得る</summary>
public int GetSibling(int id) { return nodes[id].Sibling; }
/// <summary>親IDを得る</summary>
public int GetParent(int id) { return nodes[id].Parent; }
public int[] GetChilds(int id) {
var ids = new List<int>();
if (nodes[id].LeftChild != NIL) {
ids.Add(nodes[id].LeftChild);
}
if (nodes[id].RightChild != NIL) {
ids.Add(nodes[id].RightChild);
}
return ids.ToArray();
}
/// <summary>左子を取得。存在しない時はint.MinValue</summary>
public int GetLeft(int id) { return nodes[id].LeftChild; }
/// <summary>右子を取得。存在しない時はint.MinValue</summary>
public int GetRight(int id) { return nodes[id].RightChild; }
public int NodesCount() { return nodes.Count(); }
#region 巡回
private enum OrderType { Pre, In, Post }
/// <summary>先行順巡回のNodeIdを取得</summary>
public IEnumerable<int> GetPreOrder() { return Process(OrderType.Pre); }
/// <summary>中間順巡回のNodeIdを取得</summary>
public IEnumerable<int> GetInOrder() { return Process(OrderType.In); }
/// <summary>後方順巡回のNodeIdを取得</summary>
public IEnumerable<int> GetPostOrder() { return Process(OrderType.Post); }
/// <summary>巡回を出力。O(N)</summary>
private IEnumerable<int> Process(OrderType orderType) {
var order = new List<int>();
var stack = new Stack<int>();
var passed = Enumerable.Range(startAt, nNode)
.ToDictionary(i => i, i => false); // 巡回済
var orderAdded = Enumerable.Range(startAt, nNode)
.ToDictionary(i => i, i => false); // 処理済
Action<int> addOrder = id => {
if (!orderAdded[id]) {
order.Add(id);
orderAdded[id] = true;
}
};
stack.Push(GetRoot());
while (stack.Count > 0) {
var current = stack.First();
passed[current] = true;
if (orderType == OrderType.Pre) {
addOrder(current); // 先行順巡回
}
int left = GetLeft(current);
if (left != -1 && !passed[left]) {
stack.Push(left);
continue;
}
if (orderType == OrderType.In) {
addOrder(current); // 中間順巡回
}
int right = GetRight(current);
if (right != -1 && !passed[right]) {
stack.Push(right);
continue;
}
if (orderType == OrderType.Post) {
addOrder(current);
// 後方順巡回
}
stack.Pop();
}
return order;
}
#endregion
}
/// <summary>二分探索木</summary>
public class BinarySearchTree {
static readonly Node NIL = new Node(int.MinValue);
class Node {
public int Key { get; set; }
public Node Parent { get; set; }
public Node Left { get; set; }
public Node Right { get; set; }
public Node(int key) {
this.Key = key;
this.Parent = NIL;
this.Left = NIL;
this.Right = NIL;
}
}
Node root = NIL;
#region Operate
public void Insert(int key) {
var z = new Node(key);
var y = NIL; // xの親
var x = root; // Treeの根
while (x != NIL) {
y = x;
if (z.Key < x.Key) {
x = x.Left;
} else {
x = x.Right;
}
}
z.Parent = y;
if (y == NIL) {
root = z;
} else if (z.Key < y.Key) {
y.Left = z;
} else {
y.Right = z;
}
}
public bool Find(int key) {
var nearLeaf = GetNearLeaf(key);
return nearLeaf.Key == key;
}
private Node GetNearLeaf(int key) {
var x = this.root;
while (x != NIL && x.Key != key) {
if (x.Key < key) {
x = x.Right;
} else {
x = x.Left;
}
}
return x;
}
public void Delete(int key) {
var cand = GetNearLeaf(key);
if (cand.Key != key) {
throw new KeyNotFoundException();
}
DeleteNode(cand);
}
private void DeleteNode(Node target) {
// 削除対象ノードを選択
Node delTarget;
if (target.Left == NIL || target.Right == NIL) {
delTarget = target;
} else {
delTarget = NextInOrder(target);
}
// DelTargetの親の新規子を決める
Node newChild;
if (delTarget.Left != NIL) {
newChild = delTarget.Left;
} else {
newChild = delTarget.Right;
}
// 新規子 => 親をつなぐ
if (newChild != NIL) {
newChild.Parent = delTarget.Parent;
}
// 親 => 新規子をつなぐ
var parent = delTarget.Parent;
if (parent == NIL) {
root = newChild;
} else if (parent.Left == delTarget) {
parent.Left = newChild;
} else if (parent.Right == delTarget) {
parent.Right = newChild;
}
// 消したノードの値を渡されたNodeに入れる
if (delTarget != target) {
target.Key = delTarget.Key;
}
}
/// <summary>次の中間順巡回のNodeを取得</summary>
/// <returns>NILの時は木が空</returns>
private Node NextInOrder(Node node) {
if (node.Right == NIL) {
var current = node;
var parent = node.Parent;
// 親をたどっていき、初めて左子となっているNodeを取得
while (parent != NIL && current == parent.Right) {
current = parent;
parent = current.Parent;
}
return node.Parent;
}
// 右部分木より最左を取得
var root = node.Right;
while (root.Left != NIL) {
root = root.Left;
}
return root;
}
/// <summary>
/// targetの親の子を、新しい子につなぎ替える
/// </summary>
/// <param name="target">対象のTarget</param>
/// <param name="newChild">つなぎ変えた先の子</param>
private static void ChangeParentOfChild(Node target, Node newChild) {
var parent = target.Parent;
if (parent.Left == target) {
parent.Left = newChild;
} else if (parent.Right == target) {
parent.Right = newChild;
} else {
throw new KeyNotFoundException();
}
}
#endregion
#region Order
public IEnumerable<int> GetInOrder() {
var orderGetter = new OrderGetter();
return orderGetter.GetInOrder(root);
}
public IEnumerable<int> GetPreOrder() {
var orderGetter = new OrderGetter();
return orderGetter.GetPreOrder(root);
}
class OrderGetter {
private List<int> process = new List<int>();
public IEnumerable<int> GetInOrder(Node root) {
SetInOrder(root);
return process;
}
public IEnumerable<int> GetPreOrder(Node root) {
SetPreOrder(root);
return process;
}
private void SetInOrder(Node node) {
if (node == NIL) {
return;
}
SetInOrder(node.Left);
process.Add(node.Key);
SetInOrder(node.Right);
}
private void SetPreOrder(Node node) {
if (node == NIL) {
return;
}
process.Add(node.Key);
SetPreOrder(node.Left);
SetPreOrder(node.Right);
}
}
#endregion
}
}
|
// optional
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
public static class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var nm = ReadLib.ReadAsIntArray();
var n = nm[0];
var m = nm[1];
var costs = new int[m + 1];
var opens = new int[m + 1];
for (int i = 1; i <= m; i++) {
var ab = ReadLib.ReadAsIntArray();
costs[i] = ab[0];
var cs = ReadLib.ReadAsIntArray();
opens[i] = cs.Select(c => 1 << (c - 1)).Sum();
}
// 2次元目:
// 2進数のn桁目(配列として見たときの**n-1**番目)は宝箱の開閉を示す
var dp = new int[m + 1, 1 << n];
dp.Initialize(int.MaxValue);
dp[0, 0] = 0;
for (int key = 1; key <= m; key++) {
for (int open = 0; open < 1 << n; open++) {
dp[key, open] = Math.Min(dp[key, open], dp[key - 1, open]);
var afterOpen = open | opens[key];
dp[key, afterOpen] =
Math.Min(dp[key, afterOpen],
dp[key - 1, open] == int.MaxValue
? int.MaxValue
: dp[key - 1, open] + costs[key] // オーバーフロー対策
);
}
}
var score = dp[m, (1 << n) - 1] != int.MaxValue ? dp[m, (1 << n) - 1] : -1;
Console.WriteLine(score);
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class ReadLib {
public static long ReadAsLong() { return long.Parse(Console.ReadLine()); }
public static int ReadAsInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadAsIntArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) + step)
.ToArray();
}
public static long[] ReadAsLongArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => long.Parse(s) + step)
.ToArray();
}
public static ulong[] ReadAsULongArray() {
return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
}
public static string[] ReadAsStringArray() {
return Console.ReadLine().Split(' ');
}
public static int[] ReadNTimesAsInt(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => int.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static char[][] ReadNTimesAsCharArray(int n) {
return Enumerable.Range(1, n)
.Select(i => Console.ReadLine().ToArray())
.ToArray();
}
public static long[] ReadNTimesAsLong(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => long.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static int[][] ReadNTimesAsIntArray(int n, int step = 0) {
return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray();
}
public static string[] ReadNTimesAsString(int n) {
return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray();
}
}
namespace Heaps {
/// <summary>優先度付きキュー</summary>
public class PriorityQueue<T> : IEnumerable<T>, IReadOnlyCollection<T>
where T : IComparable<T> {
public List<T> HeapArray { get; }
public T NIL { get; }
public bool IsMax { get; }
public int Count => HeapArray.Count;
/// <param name="heapArray">ヒープ</param>
/// <param name="NIL">NILの値</param>
/// <param
/// name="IsMax">True時:大きい方から取り出す、False時:小さい方から取り出す</param>
public PriorityQueue(T NIL, IEnumerable<T> heapArray = null,
bool IsMax = true) {
this.HeapArray = heapArray == null ? new List<T>() : heapArray.ToList();
this.NIL = NIL;
this.IsMax = IsMax;
Update();
}
/// <summary>KeyのValueを取得</summary>
public T this[int id] {
get {
if (id <= 0 || id > HeapArray.Count) {
return NIL;
}
return HeapArray[id - 1];
}
}
class Node {
public int Key { get; }
public T Value => outer[Key];
readonly PriorityQueue<T> outer;
public Node(int key, PriorityQueue<T> outer) {
Key = key;
this.outer = outer;
}
public Node Left {
get {
var leftKey = 2 * Key;
return new Node(leftKey, outer);
}
}
public Node Right {
get {
var rightkey = 2 * Key + 1;
return new Node(rightkey, outer);
}
}
public Node Parent {
get {
var parentKey = Key / 2;
return new Node(parentKey, outer);
}
}
}
private Node GetNode(int key) { return new Node(key, this); }
/// <summary>max Heap木とする O(N)</summary>
public void Update() {
var n = HeapArray.Count() / 2;
/// <summary>葉から順に処理を行う</summary>
for (int i = n; i >= 1; i--) {
Heapify(i);
}
}
/// <summary>idを根とする部分木について、Heap木を維持したまま、idを下降させる</summary>
private void Heapify(int key) {
var current = GetNode(key);
var left = current.Left;
var right = current.Right;
var largest = current;
var sign = IsMax ? 1 : -1;
if (left.Value.CompareTo(NIL) != 0 &&
left.Value.CompareTo(current.Value) * sign > 0) {
largest = left;
}
if (right.Value.CompareTo(NIL) != 0 &&
right.Value.CompareTo(largest.Value) * sign > 0) {
largest = right;
}
if (largest.Key != key) {
HeapArray.Swap(key - 1, largest.Key - 1); // 元と異なるときはSwapする
Heapify(
largest
.Key); // largest.Key は元のkeyの場所。葉で更にMaxHeaptyを行う。
}
}
/// <summary>keyの値を挿入する</summary>
public void Enqueue(T value) {
HeapArray.Add(value);
var inserted = GetNode(HeapArray.Count); // 末尾に挿入
var parent = inserted.Parent;
var sign = IsMax ? 1 : -1;
// 挿入Nodeが根になる or 親 > 子になるまで親とNodeを交換
while (inserted.Key > 1 && value.CompareTo(parent.Value) * sign > 0) {
HeapArray.Swap(inserted.Key - 1, parent.Key - 1);
inserted = parent;
parent = inserted.Parent;
}
}
public T Dequeue() {
if (HeapArray.Count == 0) {
return NIL;
}
var popVal = HeapArray.First();
var newRootVal = HeapArray.Last(); // 新しい根となる。
HeapArray.RemoveAt(HeapArray.Count - 1); // del last
if (HeapArray.Count > 0) {
HeapArray[0] = newRootVal;
Heapify(1);
}
return popVal;
}
public T Peek() { return HeapArray.First(); }
public IEnumerator<T> GetEnumerator() {
while (HeapArray.Count > 0) {
yield return Dequeue();
}
}
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
public void Clear() { HeapArray.Clear(); }
public bool Contains(T val) { return HeapArray.Contains(val); }
public PriorityQueue<T> Clone() {
return new PriorityQueue<T>(NIL, HeapArray.DeepCopy());
}
}
}
/// <summary>拡張メソッドs</summary>
static class MyExtention {
/// <summary>iとjを入れ替える</summary>
public static void Swap<T>(this T[] arr, int i, int j) {
var buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
}
public static void Swap<T>(this List<T> list, int i, int j) {
var buf = list[i];
list[i] = list[j];
list[j] = buf;
}
/// <summary>
/// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。
/// </summary>
/// <param name="sArr"></param>
/// <param name="p">partitionの先頭の添字</param>
/// <param name="r">partitionの末尾の添字</param>
/// <returns>partitionの基準が存在する添字</returns>
public static int Partition(this int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
/// <summary>深いコピーをする</summary>
public static T DeepCopy<T>(this T obj) {
T result;
var b = new BinaryFormatter();
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
public static string Left(this string str, int length) {
return str.Substring(0, length);
}
public static string Right(this string str, int length) {
return str.Substring(str.Length - length, length);
}
public static int Find<T>(this T[] array, T obj) {
return Array.IndexOf(array, obj);
}
public static int LastFind<T>(this T[] array, T obj) {
return Array.LastIndexOf(array, obj);
}
/// <summary>同一の値で埋める</summary>
public static void Initialize<T>(this T[] array, T value) {
for (int i = 0; i < array.Length; i++) {
array[i] = value;
}
}
/// <summary>同一の値で埋める</summary>
public static void Initialize<T>(this T[,] array, T value) {
for (int i = 0; i < array.GetLength(0); i++) {
for (int j = 0; j < array.GetLength(1); j++) {
array[i, j] = value;
}
}
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
public static ModCombination ModCombination(int maxN, int mod = 1000000007) {
return new ModCombination(maxN, mod);
}
/// <summary>a^n mod</summary>
public static int ModPow(long a, long n, int mod = 1000000007) {
long res = 1;
long pow = a;
while (n > 0) {
if ((n & 1) == 1) {
res = (pow * res) % mod; // resにaをかける
}
pow = (pow * pow) % mod; // 次のaはa^2
n >>= 1;
}
return (int)res;
}
/// <summary>約数を列挙</summary>
public static long[] Divisors(long n) {
var ret = new List<long>();
var sqrt = Math.Ceiling(Math.Sqrt(n));
for (long i = 1; i <= sqrt; i++) {
if (i * i > n) {
continue;
}
if (n % i != 0) {
continue;
}
ret.Add(i);
if (n / i == i) {
continue;
}
ret.Add(n / i);
}
return ret.ToArray();
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
/// <summary>ある要素を持つindexをすべて返す</summary>
public static int[] InducesOfValue<T>(this T[] arr, T searchValue) {
return arr.Select((v, i) => new { v, i })
.Where(o => searchValue.Equals(o.v))
.Select(o => o.i)
.ToArray();
}
/// <summary>ある要素を持つindexをすべて返す</summary>
public static int[] Induces<T>(this IEnumerable<T> arr, T searchValue) {
return arr.ToArray().InducesOfValue(searchValue);
}
}
/// <summary>組み合わせ</summary>
class ModCombination {
private int mod;
private int[] fac;
private int[] finv;
private int[] inv;
public ModCombination(int max, int mod = 1000000007) {
this.mod = mod;
fac = new int[max]; // modが法のn!の列
inv = new int[max]; // indexの逆元の列
finv = new int[max]; // modを法とした、invの累積の累積
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める
var s = Math.BigMul(inv[mod % i], mod / i) % mod;
inv[i] = (int)(mod - s);
// iに対する逆元を求める
finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod);
}
}
/// <summary>nCk</summary>
public int Calculation(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (int)(Math.BigMul(fac[n],
(int)(Math.BigMul(finv[k], finv[n - k]) % mod)) %
mod);
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator -(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value - item2.Value;
if (value < 0) {
value += item1.Mod;
}
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
return item1 + new ModInt(item2, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
return item1 * new ModInt(item2, item1.Mod);
}
public static ModInt operator -(ModInt item1, int item2) {
return item1 - new ModInt(item2, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
// optional
namespace Graph {
/// <summary>無向グラフ</summary>
class UndirectedGraph {
public Dictionary<int, List<int>> Graph { get; }
/// <param name="graphArr">point1 to point2</param>
/// <param name="n">グラフの全要素数</param>
public UndirectedGraph(int[][] graphArr, int n) {
Graph = new Dictionary<int, List<int>>();
for (int i = 1; i <= n; i++) {
Graph.Add(i, new List<int>());
}
foreach (var arr in graphArr) {
Graph[arr[0]].Add(arr[1]);
Graph[arr[1]].Add(arr[0]);
}
}
}
/// <summary>有向グラフの隣接行列表現</summary>
class AdjacencyMatrixCreator {
public int[][] Matrix { get; }
public AdjacencyMatrixCreator(int[][] matrix) { this.Matrix = matrix; }
/// <summary>ノード数nの隣接行列表現を生成.1オリジン</summary>
public AdjacencyMatrixCreator(int n, int defaultVal = 0) {
Matrix = new int [n + 1][];
for (int i = 0; i <= n; i++) {
Matrix[i] = new int[n + 1];
for (int j = 0; j <= n; j++) {
Matrix[i][j] = defaultVal;
}
}
}
/// <summary>
/// 辺の追加 (行列に1を足す)
/// </summary>
/// <param name="nodeNo">元ノードのNo</param>
/// <param name="outDegree">出次数</param>
/// <param name="outNodeNos">向かう先のノードNo</param>
public void AddEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) {
foreach (var outNodeNo in outNodeNos) {
Matrix[nodeNo][outNodeNo] = 1;
}
}
/// <summary>
/// 辺の削除 (行列を0にする)
/// </summary>
/// <param name="nodeNo">元ノードのNo</param>
/// <param name="outDegree">出次数</param>
/// <param name="outNodeNos">向かう先のノードNo</param>
public void DelEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) {
foreach (var outNodeNo in outNodeNos) {
Matrix[nodeNo][outNodeNo] = 0;
}
}
}
}
namespace Sort {
static class MergeSort {
/// <summary>ソートを行う(mutable)</summary>
public static void Sort(long[] arr) { Sort(arr, 0, arr.Count()); }
private static void Sort(long[] sArr, int left, int right) {
if (left + 1 < right) {
var mid = (left + right) / 2;
Sort(sArr, left, mid); // left ~ mid-1をソート
Sort(sArr, mid, right); // mid ~ rightをソート
Merge(sArr, left, mid, right); // 昇順に並んだ2つの列を結合する。
}
}
// arrのleftとrightは昇順に並ぶのでO(n1+n2)
private static void Merge(long[] arr, int left, int mid, int right) {
var lArr = new long[mid - left + 1];
var rArr = new long[right - mid + 1];
for (int i = 0; i < mid - left; i++) {
lArr[i] = arr[left + i];
}
lArr[mid - left] = long.MaxValue;
for (int i = 0; i < right - mid; i++) {
rArr[i] = arr[mid + i];
}
rArr[right - mid] = long.MaxValue;
int l = 0, r = 0;
// arrを並び替える
for (int i = left; i < right; i++) {
if (lArr[l] > rArr[r]) {
arr[i] = rArr[r];
r++;
} else {
arr[i] = lArr[l];
l++;
}
}
}
}
static class QuickSort {
internal static void Sort(int[] ts) { Sort(ts, 0, ts.Count() - 1); }
/// <summary>Quickソート</summary>
private static void Sort(int[] ts, int p, int r) {
if (p < r) {
var q = Partition(ts, p, r);
Sort(ts, p, q - 1);
Sort(ts, q + 1, r);
}
}
public static int Partition(int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
}
/// <summary>計数ソート</summary>
static class CountingSort {
public static int[] Sort(int[] aArr, int k) {
int[] b, c;
var n = aArr.Length;
b = new int[n];
c = Enumerable.Repeat(0, k + 1).ToArray();
for (int i = 0; i < n; i++) {
c[aArr[i]]++;
}
for (int i = 1; i <= k; i++) {
c[i] += c[i - 1];
}
for (int i = n - 1; i >= 0; i--) {
b[c[aArr[i]] - 1] = aArr[i];
c[aArr[i]]--;
}
return b;
}
}
}
namespace Tree {
/// <summary>UnionFind木</summary>
public class UnionFind {
Dictionary<int, int> nodeToRoot;
Dictionary<int, int> rank; // その根が配下に何個nodeがぶら下がっているか
public UnionFind(int n, int startAt = 0) {
nodeToRoot = Enumerable.Range(startAt, n)
.ToDictionary(i => i, i => i); // n個根を作る
rank = Enumerable.Range(startAt, n).ToDictionary(i => i, i => 0);
}
/// <summary>根を得る</summary>
public int GetRoot(int x) {
if (nodeToRoot[x] == x) { // 渡されたノードが根
return x;
}
nodeToRoot[x] =
GetRoot(nodeToRoot[x]); // parentの根を得てset。調べるたびに最適化。
return nodeToRoot[x];
}
/// <summary>xとyの木を併合 => 根を同一にする</summary>
public void Unite(int x, int y) {
var rootX = GetRoot(x);
var rootY = GetRoot(y);
if (rootX == rootY) {
return; // pass
}
if (rank[rootX] < rank[rootY]) { // yをxへ併合
nodeToRoot[rootX] = nodeToRoot[rootY];
} else {
nodeToRoot[rootX] = nodeToRoot[rootY];
if (rank[rootX] == rank[rootY]) {
rank[rootX]++; // yの下に配下が1つ追加される。
}
}
}
public bool AreSameRoot(int x, int y) { return GetRoot(x) == GetRoot(y); }
}
/// <summary>根付き木</summary>
public class RootedTree {
readonly Dictionary<int, Node> nodes;
const int NIL = -1;
int startAt;
int nNode;
class Node {
/// <summary>親のID</summary>
public int Parent { get; set; }
/// <summary>子の最左端</summary>
public int LeftChild { get; set; }
/// <summary>右の兄弟</summary>
public int RightBrother { get; set; }
/// <summary>深さ</summary>
public int Depth { get; set; }
public Node() {
Parent = NIL;
LeftChild = NIL;
RightBrother = NIL;
Depth = 0;
}
}
/// <summary>根付き木</summary>
public RootedTree(int n, int startAt = 0) {
this.nodes =
Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node());
this.startAt = startAt;
this.nNode = n;
}
/// <summary>Nodeに子を追加</summary>
public void SetChilds(int id, int[] childs) {
if (childs.Length == 0) {
return;
}
nodes[id].LeftChild = childs.First();
for (int i = 0; i < childs.Length - 1; i++) {
int childId = childs[i];
nodes[childId].Parent = id;
nodes[childId].RightBrother = childs[i + 1];
}
nodes[childs.Last()].Parent = id;
}
/// <summary>親Idを取得</summary>
public int GetParentId(int id) { return nodes[id].Parent; }
/// <summary>子のidを取得</summary>
public int[] GetChilds(int id) {
var childs = new List<int>();
var child = nodes[id].LeftChild;
while (child != NIL) {
childs.Add(child);
child = nodes[child].RightBrother;
}
return childs.ToArray();
}
int Root = NIL;
public int GetRoot() {
if (Root == NIL) {
var current = nodes.First().Key; // 何でもいい
var parent = nodes[current].Parent;
while (parent != NIL) {
current = parent;
parent = nodes[current].Parent;
}
Root = current;
}
return Root;
}
bool isSetedDepth = false;
/// <summary>深さを取得</summary>
public int GetDepth(int id) {
if (!isSetedDepth) {
var root = GetRoot();
SetDepth(root, depth: 0);
isSetedDepth = true;
}
var current = id;
var parent = nodes[id].Parent;
var depth = 0;
while (parent != NIL) {
current = parent;
parent = nodes[current].Parent;
depth++;
}
return depth;
}
private void SetDepth(int id, int depth) {
var node = nodes[id];
node.Depth = depth;
if (node.RightBrother != NIL) {
SetDepth(node.RightBrother, depth);
}
if (node.LeftChild != NIL) {
SetDepth(node.LeftChild, depth + 1);
}
}
public int NodesCount() { return nodes.Count(); }
}
/// <summary>二分木</summary>
public class BinaryTree {
const int NIL = int.MinValue;
readonly int startAt;
readonly int nNode;
class Node {
public int Parent { get; set; }
public int LeftChild { get; set; }
public int RightChild { get; set; }
public int Depth { get; set; }
public int Height { get; set; }
/// <summary>唯一の兄弟</summary>
public int Sibling { get; set; }
public Node() {
Parent = NIL;
LeftChild = NIL;
RightChild = NIL;
Sibling = NIL;
Depth = 0;
Height = 0;
}
}
Dictionary<int, Node> nodes;
public BinaryTree(int n, int startAt) {
this.nodes =
Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node());
this.startAt = startAt;
this.nNode = n;
}
/// <summary>
/// 子をセットする
/// </summary>
/// <param name="id">ノードのID</param>
/// <param name="left">左子ID。存在しない場合は-1</param>
/// <param name="right">右子ID。存在しない場合は-1</param>
public void SetChilds(int id, int left, int right) {
nodes[id].LeftChild = left;
nodes[id].RightChild = right;
if (left != NIL) {
nodes[left].Parent = id;
nodes[left].Sibling = right;
}
if (right != NIL) {
nodes[right].Parent = id;
nodes[right].Sibling = left;
}
}
/// <summary>Root</summary>
int Root = NIL;
public int GetRoot() {
if (Root == NIL) {
var current = nodes.First().Key;
var parent = nodes[current].Parent;
while (parent != NIL) {
current = parent;
parent = nodes[current].Parent;
}
Root = current;
}
return Root;
}
#region Depth
bool isSetDepth = false;
public int GetDepth(int id) {
if (!isSetDepth) {
var root = GetRoot();
SetDepth(root, 0);
isSetDepth = true;
}
return nodes[id].Depth;
}
private void SetDepth(int id, int depth) {
nodes[id].Depth = depth;
if (nodes[id].LeftChild != NIL) {
SetDepth(nodes[id].LeftChild, depth + 1);
}
if (nodes[id].RightChild != NIL) {
SetDepth(nodes[id].RightChild, depth + 1);
}
}
#endregion
#region Height
bool isSetHeight = false;
/// <summary>高さを得る</summary>
public int GetHeight(int id) {
if (!isSetHeight) {
var root = GetRoot();
SetHeight(root);
isSetHeight = true;
}
return nodes[id].Height;
}
public int SetHeight(int id) {
var node = nodes[id];
int hLeft = 0;
int hRight = 0;
if (node.LeftChild != NIL) {
hLeft = SetHeight(node.LeftChild) + 1;
}
if (node.RightChild != NIL) {
hRight = SetHeight(node.RightChild) + 1;
}
node.Height = Math.Max(hLeft, hRight);
return node.Height;
}
#endregion
/// <summary>兄弟を得る</summary>
public int GetSibling(int id) { return nodes[id].Sibling; }
/// <summary>親IDを得る</summary>
public int GetParent(int id) { return nodes[id].Parent; }
public int[] GetChilds(int id) {
var ids = new List<int>();
if (nodes[id].LeftChild != NIL) {
ids.Add(nodes[id].LeftChild);
}
if (nodes[id].RightChild != NIL) {
ids.Add(nodes[id].RightChild);
}
return ids.ToArray();
}
/// <summary>左子を取得。存在しない時はint.MinValue</summary>
public int GetLeft(int id) { return nodes[id].LeftChild; }
/// <summary>右子を取得。存在しない時はint.MinValue</summary>
public int GetRight(int id) { return nodes[id].RightChild; }
public int NodesCount() { return nodes.Count(); }
#region 巡回
private enum OrderType { Pre, In, Post }
/// <summary>先行順巡回のNodeIdを取得</summary>
public IEnumerable<int> GetPreOrder() { return Process(OrderType.Pre); }
/// <summary>中間順巡回のNodeIdを取得</summary>
public IEnumerable<int> GetInOrder() { return Process(OrderType.In); }
/// <summary>後方順巡回のNodeIdを取得</summary>
public IEnumerable<int> GetPostOrder() { return Process(OrderType.Post); }
/// <summary>巡回を出力。O(N)</summary>
private IEnumerable<int> Process(OrderType orderType) {
var order = new List<int>();
var stack = new Stack<int>();
var passed = Enumerable.Range(startAt, nNode)
.ToDictionary(i => i, i => false); // 巡回済
var orderAdded = Enumerable.Range(startAt, nNode)
.ToDictionary(i => i, i => false); // 処理済
Action<int> addOrder = id => {
if (!orderAdded[id]) {
order.Add(id);
orderAdded[id] = true;
}
};
stack.Push(GetRoot());
while (stack.Count > 0) {
var current = stack.First();
passed[current] = true;
if (orderType == OrderType.Pre) {
addOrder(current); // 先行順巡回
}
int left = GetLeft(current);
if (left != -1 && !passed[left]) {
stack.Push(left);
continue;
}
if (orderType == OrderType.In) {
addOrder(current); // 中間順巡回
}
int right = GetRight(current);
if (right != -1 && !passed[right]) {
stack.Push(right);
continue;
}
if (orderType == OrderType.Post) {
addOrder(current);
// 後方順巡回
}
stack.Pop();
}
return order;
}
#endregion
}
/// <summary>二分探索木</summary>
public class BinarySearchTree {
static readonly Node NIL = new Node(int.MinValue);
class Node {
public int Key { get; set; }
public Node Parent { get; set; }
public Node Left { get; set; }
public Node Right { get; set; }
public Node(int key) {
this.Key = key;
this.Parent = NIL;
this.Left = NIL;
this.Right = NIL;
}
}
Node root = NIL;
#region Operate
public void Insert(int key) {
var z = new Node(key);
var y = NIL; // xの親
var x = root; // Treeの根
while (x != NIL) {
y = x;
if (z.Key < x.Key) {
x = x.Left;
} else {
x = x.Right;
}
}
z.Parent = y;
if (y == NIL) {
root = z;
} else if (z.Key < y.Key) {
y.Left = z;
} else {
y.Right = z;
}
}
public bool Find(int key) {
var nearLeaf = GetNearLeaf(key);
return nearLeaf.Key == key;
}
private Node GetNearLeaf(int key) {
var x = this.root;
while (x != NIL && x.Key != key) {
if (x.Key < key) {
x = x.Right;
} else {
x = x.Left;
}
}
return x;
}
public void Delete(int key) {
var cand = GetNearLeaf(key);
if (cand.Key != key) {
throw new KeyNotFoundException();
}
DeleteNode(cand);
}
private void DeleteNode(Node target) {
// 削除対象ノードを選択
Node delTarget;
if (target.Left == NIL || target.Right == NIL) {
delTarget = target;
} else {
delTarget = NextInOrder(target);
}
// DelTargetの親の新規子を決める
Node newChild;
if (delTarget.Left != NIL) {
newChild = delTarget.Left;
} else {
newChild = delTarget.Right;
}
// 新規子 => 親をつなぐ
if (newChild != NIL) {
newChild.Parent = delTarget.Parent;
}
// 親 => 新規子をつなぐ
var parent = delTarget.Parent;
if (parent == NIL) {
root = newChild;
} else if (parent.Left == delTarget) {
parent.Left = newChild;
} else if (parent.Right == delTarget) {
parent.Right = newChild;
}
// 消したノードの値を渡されたNodeに入れる
if (delTarget != target) {
target.Key = delTarget.Key;
}
}
/// <summary>次の中間順巡回のNodeを取得</summary>
/// <returns>NILの時は木が空</returns>
private Node NextInOrder(Node node) {
if (node.Right == NIL) {
var current = node;
var parent = node.Parent;
// 親をたどっていき、初めて左子となっているNodeを取得
while (parent != NIL && current == parent.Right) {
current = parent;
parent = current.Parent;
}
return node.Parent;
}
// 右部分木より最左を取得
var root = node.Right;
while (root.Left != NIL) {
root = root.Left;
}
return root;
}
/// <summary>
/// targetの親の子を、新しい子につなぎ替える
/// </summary>
/// <param name="target">対象のTarget</param>
/// <param name="newChild">つなぎ変えた先の子</param>
private static void ChangeParentOfChild(Node target, Node newChild) {
var parent = target.Parent;
if (parent.Left == target) {
parent.Left = newChild;
} else if (parent.Right == target) {
parent.Right = newChild;
} else {
throw new KeyNotFoundException();
}
}
#endregion
#region Order
public IEnumerable<int> GetInOrder() {
var orderGetter = new OrderGetter();
return orderGetter.GetInOrder(root);
}
public IEnumerable<int> GetPreOrder() {
var orderGetter = new OrderGetter();
return orderGetter.GetPreOrder(root);
}
class OrderGetter {
private List<int> process = new List<int>();
public IEnumerable<int> GetInOrder(Node root) {
SetInOrder(root);
return process;
}
public IEnumerable<int> GetPreOrder(Node root) {
SetPreOrder(root);
return process;
}
private void SetInOrder(Node node) {
if (node == NIL) {
return;
}
SetInOrder(node.Left);
process.Add(node.Key);
SetInOrder(node.Right);
}
private void SetPreOrder(Node node) {
if (node == NIL) {
return;
}
process.Add(node.Key);
SetPreOrder(node.Left);
SetPreOrder(node.Right);
}
}
#endregion
}
}
|
[["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 25]]
| 8
| 7,571
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int32;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var m = ri;
var G = Enumerate(n, x => new List<int>());
for (int i = 0; i < m; i++) {
var u = ri - 1;
var v = ri - 1;
G[u].Add(v);
}
var min = n + 1;
var mid = -1;
for (int i = 0; i < n; i++) {
var d = Enumerate(n, x => 100000);
var prev = Enumerate(n, x => -1);
d[i] = 0;
var q = new Queue<int>();
q.Enqueue(i);
while (q.Any()) {
var p = q.Dequeue();
foreach (var t in G[p]) {
Debug.WriteLine($"{p} -> {t}");
if (d[t] > d[p] + 1) {
d[t] = d[p] + 1;
prev[t] = p;
q.Enqueue(t);
} else if (t == i && min > d[p] + 1) {
min = d[p] + 1;
mid = i;
}
}
}
}
if (min == n) {
Console.WriteLine(-1);
return;
}
for (int i = mid; i <= mid; i++) {
var d = Enumerate(n, x => 100000);
var prev = Enumerate(n, x => -1);
d[i] = 0;
var q = new Queue<int>();
q.Enqueue(i);
while (q.Any()) {
var p = q.Dequeue();
foreach (var t in G[p]) {
Debug.WriteLine($"{p} -> {t}");
if (d[t] > d[p] + 1) {
d[t] = d[p] + 1;
prev[t] = p;
q.Enqueue(t);
} else if (t == i && min == d[p] + 1) {
Debug.WriteLine($"{i} {t}");
var ans = new List<int>();
ans.Add(p);
while (ans.Last() != i) {
Debug.WriteLine(ans.Last());
ans.Add(prev[ans.Last()]);
}
Console.WriteLine(ans.Count);
foreach (var x in ans)
Console.WriteLine(x + 1);
return;
}
}
}
}
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < a.Length; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
/*
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
//*/
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int32;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var m = ri;
var G = Enumerate(n, x => new List<int>());
for (int i = 0; i < m; i++) {
var u = ri - 1;
var v = ri - 1;
G[u].Add(v);
}
var min = n + 1;
var mid = -1;
for (int i = 0; i < n; i++) {
var d = Enumerate(n, x => 100000);
var prev = Enumerate(n, x => -1);
d[i] = 0;
var q = new Queue<int>();
q.Enqueue(i);
while (q.Any()) {
var p = q.Dequeue();
foreach (var t in G[p]) {
Debug.WriteLine($"{p} -> {t}");
if (d[t] > d[p] + 1) {
d[t] = d[p] + 1;
prev[t] = p;
q.Enqueue(t);
} else if (t == i && min > d[p] + 1) {
min = d[p] + 1;
mid = i;
}
}
}
}
if (min > n) {
Console.WriteLine(-1);
return;
}
for (int i = mid; i <= mid; i++) {
var d = Enumerate(n, x => 100000);
var prev = Enumerate(n, x => -1);
d[i] = 0;
var q = new Queue<int>();
q.Enqueue(i);
while (q.Any()) {
var p = q.Dequeue();
foreach (var t in G[p]) {
Debug.WriteLine($"{p} -> {t}");
if (d[t] > d[p] + 1) {
d[t] = d[p] + 1;
prev[t] = p;
q.Enqueue(t);
} else if (t == i && min == d[p] + 1) {
Debug.WriteLine($"{i} {t}");
var ans = new List<int>();
ans.Add(p);
while (ans.Last() != i) {
Debug.WriteLine(ans.Last());
ans.Add(prev[ans.Last()]);
}
Console.WriteLine(ans.Count);
foreach (var x in ans)
Console.WriteLine(x + 1);
return;
}
}
}
}
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < a.Length; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
/*
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
//*/
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 1,387
| 2
|
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace 水色コーダーに俺はなる {
class PriorityQueue<T>
where T : IComparable<T> {
private List<T> list = new List<T>();
public long Count {
get { return list.Count; }
}
public void Enqueue(T elem) {
int c = list.Count;
list.Add(elem);
while (c != 0) {
int i = (c - 1) / 2;
if (list[c].CompareTo(list[i]) > 0) {
T tmp = list[c];
list[c] = list[i];
list[i] = tmp;
}
c = i;
}
}
public T Dequeue() {
int c = list.Count - 1;
T pop = list[0];
list[0] = list[c];
list.RemoveAt(c);
for (int i = 0, j = 1; j < c;) {
if ((j != c - 1) && (list[j].CompareTo(list[j + 1]) < 0)) {
j++;
}
if (list[i].CompareTo(list[j]) < 0) {
T tmp = list[j];
list[j] = list[i];
list[i] = tmp;
}
i = j;
j = 2 * i + 1;
}
return pop;
}
}
class Inonoa {
/* ここに書け */
static void Main() {
long[] nk = ILongs();
long[] p = ILongs();
SortedSet<long> ma = new SortedSet<long>();
for (int i = 0; i < nk[1]; i++) {
ma.Add(p[i]);
}
long id = 0;
long ans = 1;
for (int i = 1; i < nk[0] - nk[1] + 1; i++) {
long mn = ma.Min;
bool changed = false;
if (p[i - 1] != mn) {
changed = true;
}
ma.Remove(p[i - 1]);
ma.Add(p[i + nk[1] - 1]);
if (p[i + nk[1] - 1] != ma.Max) {
changed = true;
}
if (changed)
ans++;
}
long nochage = 0;
long syoujun = 1;
for (int i = 1; i < nk[0]; i++) {
if (p[i] > p[i - 1]) {
syoujun++;
if (syoujun >= nk[1]) {
nochage++;
}
} else {
syoujun = 1;
}
}
WriteLine(ans - Max(nochage - 1, 0));
}
static readonly long MOD = 1000000007;
///< summary>a_1, a_2, a_3, ...みたいなの</summary>
static long[] ILongs() {
string[] s = ReadLine().Split();
long[] re = new long[s.Length];
for (long i = 0; i < s.Length; i++) {
re[i] = long.Parse(s[i]);
}
return re;
}
///< summary>xooxoxoxxoxo...みたいなの</summary>
static char[] IChars() { return ReadLine().ToCharArray(); }
///< summary>n m とかをちょっとはやくかくだけ</summary>
static string[] IStrings() { return ReadLine().Split(); }
///< summary>n行の入力を取ったり</summary>
static long[][] ILongLongs(long n) {
long[][] re = new long [n][];
for (long i = 0; i < n; i++) {
string[] s = ReadLine().Split();
re[i] = new long[s.Length];
for (long j = 0; j < s.Length; j++) {
re[i][j] = long.Parse(s[j]);
}
}
return re;
}
///< summary>n行の文字列を取ったり</summary>
static char[][] ICharsChars(long n) {
char[][] re = new char [n][];
for (long i = 0; i < n; i++) {
re[i] = ReadLine().ToCharArray();
}
return re;
}
}
}
|
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace 水色コーダーに俺はなる {
class PriorityQueue<T>
where T : IComparable<T> {
private List<T> list = new List<T>();
public long Count {
get { return list.Count; }
}
public void Enqueue(T elem) {
int c = list.Count;
list.Add(elem);
while (c != 0) {
int i = (c - 1) / 2;
if (list[c].CompareTo(list[i]) > 0) {
T tmp = list[c];
list[c] = list[i];
list[i] = tmp;
}
c = i;
}
}
public T Dequeue() {
int c = list.Count - 1;
T pop = list[0];
list[0] = list[c];
list.RemoveAt(c);
for (int i = 0, j = 1; j < c;) {
if ((j != c - 1) && (list[j].CompareTo(list[j + 1]) < 0)) {
j++;
}
if (list[i].CompareTo(list[j]) < 0) {
T tmp = list[j];
list[j] = list[i];
list[i] = tmp;
}
i = j;
j = 2 * i + 1;
}
return pop;
}
}
class Inonoa {
/* ここに書け */
static void Main() {
long[] nk = ILongs();
long[] p = ILongs();
SortedSet<long> ma = new SortedSet<long>();
for (int i = 0; i < nk[1]; i++) {
ma.Add(p[i]);
}
long id = 0;
long ans = 1;
for (int i = 1; i < nk[0] - nk[1] + 1; i++) {
long mn = ma.Min;
bool changed = false;
if (p[i - 1] != mn) {
changed = true;
}
ma.Remove(p[i - 1]);
ma.Add(p[i + nk[1] - 1]);
if (p[i + nk[1] - 1] != ma.Max) {
changed = true;
}
if (changed)
ans++;
}
long nochage = 0;
long syoujun = 1;
for (int i = 1; i < nk[0]; i++) {
if (p[i] > p[i - 1]) {
syoujun++;
if (syoujun == nk[1]) {
nochage++;
}
} else {
syoujun = 1;
}
}
WriteLine(ans - Max(nochage - 1, 0));
}
static readonly long MOD = 1000000007;
///< summary>a_1, a_2, a_3, ...みたいなの</summary>
static long[] ILongs() {
string[] s = ReadLine().Split();
long[] re = new long[s.Length];
for (long i = 0; i < s.Length; i++) {
re[i] = long.Parse(s[i]);
}
return re;
}
///< summary>xooxoxoxxoxo...みたいなの</summary>
static char[] IChars() { return ReadLine().ToCharArray(); }
///< summary>n m とかをちょっとはやくかくだけ</summary>
static string[] IStrings() { return ReadLine().Split(); }
///< summary>n行の入力を取ったり</summary>
static long[][] ILongLongs(long n) {
long[][] re = new long [n][];
for (long i = 0; i < n; i++) {
string[] s = ReadLine().Split();
re[i] = new long[s.Length];
for (long j = 0; j < s.Length; j++) {
re[i][j] = long.Parse(s[j]);
}
}
return re;
}
///< summary>n行の文字列を取ったり</summary>
static char[][] ICharsChars(long n) {
char[][] re = new char [n][];
for (long i = 0; i < n; i++) {
re[i] = ReadLine().ToCharArray();
}
return re;
}
}
}
|
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60]]
| 8
| 887
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample {
class Sample {
static void Main(string[] args) {
string str = Console.ReadLine();
if (str == "Sunny") {
Console.WriteLine("Cloudy");
} else if (str == "Cloudy") {
Console.WriteLine("Rainy");
} else {
Console.WriteLine("Rainy");
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample {
class Sample {
static void Main(string[] args) {
string str = Console.ReadLine();
if (str == "Sunny") {
Console.WriteLine("Cloudy");
} else if (str == "Cloudy") {
Console.WriteLine("Rainy");
} else {
Console.WriteLine("Sunny");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 94
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace atcoder {
class Program {
static void Main(string[] args) {
var forecast = new[] { "Sunny", "Cloudy", "Rainy" };
var today = Console.ReadLine();
var index = 0;
for (; index < 3; index++) {
if (forecast[index] == today)
break;
}
Console.WriteLine(forecast[(index + 1 % 3)]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace atcoder {
class Program {
static void Main(string[] args) {
var forecast = new[] { "Sunny", "Cloudy", "Rainy" };
var today = Console.ReadLine();
var index = 0;
for (; index < 3; index++) {
if (forecast[index] == today)
break;
}
Console.WriteLine(forecast[(index + 1) % 3]);
}
}
}
|
[["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 25], ["-", 0, 204, 206, 207, 0, 28, 0, 23, 0, 25]]
| 8
| 112
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
public const ulong mod = 1000000007;
static void Main(string[] args)
{
var s = Console.ReadLine();
var ans = string.Empty;
if (s == "Sunny")
ans = "Cloudy";
else if (s == "Cloudy")
ans = "Rainly";
else
ans = "Sunny";
Console.WriteLine(ans);
}
static public long Input() { return long.Parse(Console.ReadLine()); }
static public string[] Input2() { return Console.ReadLine().Split(); }
static public long[] Input3() {
string[] data = Console.ReadLine().Split();
long[] res = new long[data.LongLength];
for (long i = 0; i < data.LongLength; i++) {
res[i] = long.Parse(data[i]);
}
return res;
}
public static long Choose(long n, long a) {
long x = 1;
long y = 1;
for (long i = 0; i < a; i++) {
x *= n - i;
y *= i + 1;
}
return x / y;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
public const ulong mod = 1000000007;
static void Main(string[] args)
{
var s = Console.ReadLine();
var ans = string.Empty;
if (s == "Sunny")
ans = "Cloudy";
else if (s == "Cloudy")
ans = "Rainy";
else
ans = "Sunny";
Console.WriteLine(ans);
}
static public long Input() { return long.Parse(Console.ReadLine()); }
static public string[] Input2() { return Console.ReadLine().Split(); }
static public long[] Input3() {
string[] data = Console.ReadLine().Split();
long[] res = new long[data.LongLength];
for (long i = 0; i < data.LongLength; i++) {
res[i] = long.Parse(data[i]);
}
return res;
}
public static long Choose(long n, long a) {
long x = 1;
long y = 1;
for (long i = 0; i < a; i++) {
x *= n - i;
y *= i + 1;
}
return x / y;
}
}
}
|
[["-", 75, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 57, 64, 1, 0, 11, 12, 5, 0, 222]]
| 8
| 283
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var S = IO.GetString();
var ans = "";
if (S[0] == 'S') {
ans = "Cloudy";
}
if (S[0] == 'C') {
ans = "Rainy";
} else {
ans = "Sunny";
}
Console.WriteLine(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var S = IO.GetString();
var ans = "";
if (S[0] == 'S') {
ans = "Cloudy";
} else if (S[0] == 'C') {
ans = "Rainy";
} else {
ans = "Sunny";
}
Console.WriteLine(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 362
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
public static void Main(string[] args) {
const string S = "Sunny";
const string C = "Cloudy";
const string R = "Rainy";
var a = args[0];
if (a == S) {
Console.WriteLine(C);
}
if (a == C) {
Console.WriteLine(R);
}
if (a == R) {
Console.WriteLine(S);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
public static void Main(string[] args) {
const string S = "Sunny";
const string C = "Cloudy";
const string R = "Rainy";
var a = Console.ReadLine();
if (a == S) {
Console.WriteLine(C);
}
if (a == C) {
Console.WriteLine(R);
}
if (a == R) {
Console.WriteLine(S);
}
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 125
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
string a = Console.ReadLine();
if (a == "Sunny") {
Console.WriteLine("Cloudy");
} else if (a == "Cloudy") {
Console.WriteLine("Cloudy");
} else if (a == "Rainy") {
Console.WriteLine("Sunny");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Hello {
static void Main() {
string a = Console.ReadLine();
if (a == "Sunny") {
Console.WriteLine("Cloudy");
} else if (a == "Cloudy") {
Console.WriteLine("Rainy");
} else if (a == "Rainy") {
Console.WriteLine("Sunny");
}
}
}
|
[["+", 36, 36, 0, 208, 0, 235, 0, 251, 0, 259], ["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 106
| 5
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
if (S == "Sunny")
Console.WriteLine("Cloudy");
if (S == "Cloudy")
Console.WriteLine("Rainy ");
if (S == "Rainy ")
Console.WriteLine("Sunny");
}
String S;
public Sol() { S = rs(); }
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
if (S == "Sunny")
Console.WriteLine("Cloudy");
if (S == "Cloudy")
Console.WriteLine("Rainy");
if (S == "Rainy")
Console.WriteLine("Sunny");
}
String S;
public Sol() { S = rs(); }
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222]]
| 8
| 348
| 4
|
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
var count = 0;
ModInt res = 1;
foreach (var c in s) {
if ((c == 'B' && count % 2 == 1) || (c == 'W' && count % 2 == 0)) {
if (count == 0) {
Console.WriteLine(0);
return;
}
res *= count;
count--;
} else {
count++;
}
}
if (count != 0)
Console.WriteLine(-1);
else
Console.WriteLine(res * Factorial(n));
}
static List<ModInt> factorialMemo = new List<ModInt>() { 1 };
static ModInt Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
}
struct ModInt {
const int MOD = 1000000007;
const long POSITIVIZER = ((long)MOD) << 31;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, int b) => new ModInt() {
Data = (a.Data + b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div, p = MOD, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + MOD;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + MOD;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Debug = System.Diagnostics.Debug;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
var count = 0;
ModInt res = 1;
foreach (var c in s) {
if ((c == 'B' && count % 2 == 1) || (c == 'W' && count % 2 == 0)) {
if (count == 0) {
Console.WriteLine(0);
return;
}
res *= count;
count--;
} else {
count++;
}
}
if (count != 0)
Console.WriteLine(0);
else
Console.WriteLine(res * Factorial(n));
}
static List<ModInt> factorialMemo = new List<ModInt>() { 1 };
static ModInt Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
}
struct ModInt {
const int MOD = 1000000007;
const long POSITIVIZER = ((long)MOD) << 31;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, int b) => new ModInt() {
Data = (a.Data + b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => new ModInt(a.Data + b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, int b) => new ModInt() {
Data = (a.Data - b + POSITIVIZER) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => new ModInt(a.Data - b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, int b) => new ModInt(a.Data * b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, long b) => a * new ModInt(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * GetInverse(b) % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div, p = MOD, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + MOD;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + MOD;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 910
| 3
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int answer = 1;
int ansMemo = 2;
int[][] answers = new int [n][];
int[] pairs = new int[n];
for (int i = 0; i < n; i++) {
answers[i] = new int[n];
}
while (true) {
if (ansMemo >= n)
break;
ansMemo *= 2;
answer++;
}
// Console.WriteLine(2);
for (int i = 0; i < n; i++) {
if (i % 2 == 1)
pairs[i] = 1;
}
for (int i = 0; i < answer; i++) {
for (int j = 0; j < n; j++) {
for (int k = j + 1; k < n; k++) {
// Console.WriteLine(k);
if (pairs[j] + pairs[k] == 1 && answers[j][k] == 0) {
answers[j][k] = i + 1;
// Console.WriteLine(i+" "+j+" "+k);
}
}
}
for (int j = 0; j < n; j++) {
if (j % Math.Pow(2, (i + 2)) <= Math.Pow(2, i + 1) - 1) {
pairs[j] = 1 - pairs[j];
}
}
}
// Console.WriteLine("aa");
int[][] answersSub = new int [n - 1][];
for (int i = 0; i < n - 1; i++) {
answersSub[i] = new int[n - 1 - i];
for (int j = 0; j < n - 1 - i; j++) {
answersSub[i][j] = answers[i][j];
}
}
// Console.WriteLine("aaa");
for (int i = 0; i < n - 1; i++) {
Console.WriteLine(string.Join(" ", answersSub[i]));
}
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int answer = 1;
int ansMemo = 2;
int[][] answers = new int [n][];
int[] pairs = new int[n];
for (int i = 0; i < n; i++) {
answers[i] = new int[n];
}
while (true) {
if (ansMemo >= n)
break;
ansMemo *= 2;
answer++;
}
// Console.WriteLine(2);
for (int i = 0; i < n; i++) {
if (i % 2 == 1)
pairs[i] = 1;
}
for (int i = 0; i < answer; i++) {
for (int j = 0; j < n; j++) {
for (int k = j; k < n; k++) {
// Console.WriteLine(k);
if (pairs[j] + pairs[k] == 1 && answers[j][k] == 0) {
answers[j][k] = i + 1;
// Console.WriteLine(i+" "+j+" "+k);
}
}
}
for (int j = 0; j < n; j++) {
if (j % Math.Pow(2, (i + 2)) <= Math.Pow(2, i + 1) - 1) {
pairs[j] = 1 - pairs[j];
}
}
}
// Console.WriteLine("aa");
int[][] answersSub = new int [n - 1][];
for (int i = 0; i < n - 1; i++) {
answersSub[i] = new int[n - 1 - i];
for (int j = 0; j < n - 1 - i; j++) {
answersSub[i][j] = answers[i][j + i + 1];
}
}
// Console.WriteLine("aaa");
for (int i = 0; i < n - 1; i++) {
Console.WriteLine(string.Join(" ", answersSub[i]));
}
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 438
| 6
|
using System;
using System.Linq;
namespace Sample {
class Sample {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a < 3200) {
Console.WriteLine(s);
} else {
Console.WriteLine("red");
}
}
}
}
|
using System;
using System.Linq;
namespace Sample {
class Sample {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a >= 3200) {
Console.WriteLine(s);
} else {
Console.WriteLine("red");
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 77
| 2
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
class DandA {
static void Main(string[] args) {
int a = ReadLineInt();
if (a > 3200) {
Console.WriteLine(ReadLineStr());
} else {
Console.WriteLine("red");
}
}
static string Alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
static string[] strAry = new string[] { "L", "R", "U", "D" };
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private long ReadLineLong() { return long.Parse(Console.ReadLine()); }
static private double ReadLineDouble() {
return double.Parse(Console.ReadLine());
}
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private double[] ReadLineDoubleArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => double.Parse(a))
.ToArray();
}
static private decimal[] ReadLineDecimalArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => decimal.Parse(a))
.ToArray();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
}
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
class DandA {
static void Main(string[] args) {
int a = ReadLineInt();
if (a >= 3200) {
Console.WriteLine(ReadLineStr());
} else {
Console.WriteLine("red");
}
}
static string Alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
static string[] strAry = new string[] { "L", "R", "U", "D" };
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private long ReadLineLong() { return long.Parse(Console.ReadLine()); }
static private double ReadLineDouble() {
return double.Parse(Console.ReadLine());
}
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private double[] ReadLineDoubleArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => double.Parse(a))
.ToArray();
}
static private decimal[] ReadLineDecimalArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => decimal.Parse(a))
.ToArray();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 549
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var a = IO.GetInt();
var s = IO.GetString();
var ans = a >= 3200 ? "red" : s;
Console.WriteLine(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main() {
Solve();
Console.ReadKey();
}
static void Solve() {
var a = IO.GetInt();
var s = IO.GetString();
var ans = a < 3200 ? "red" : s;
Console.WriteLine(ans);
}
}
static class IO {
static public string GetString() { return Console.ReadLine(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public List<string> GetStringList() {
return Console.ReadLine().Split(' ').ToList();
}
static public List<int> GetIntList() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
}
static public List<long> GetLongList() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteStrings<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
}
}
|
[["-", 0, 200, 0, 212, 0, 41, 15, 16, 17, 20], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 18]]
| 8
| 330
| 2
|
namespace AtCoder {
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static Util;
class AtCoder {
/*------------------------------------------------------------------*/
void Solve() { (io.Int >= 3200 ? "pink" : "red").Prt(); }
/*------------------------------------------------------------------*/
void Test() {
//--- TEST ---//
}
public static void Main(string[] _) => new AtCoder().Stream();
IO io = new IO();
private void Stream() {
/*
var exStdIn = new System.IO.StreamReader("stdin.txt");
SetIn(exStdIn);
Test();
*/
Solve();
io.Flush();
}
}
class IO {
#region INPUT
#region FastRead
private const int Size = 1 << 12;
private readonly Stream _stream = OpenStandardInput();
private readonly byte[] _buffer = new byte[Size];
private int _ptr = 0, _buffLen = 0;
private bool HasNextByte() {
if (_ptr < _buffLen)
return true;
_ptr = 0;
_buffLen = _stream.Read(_buffer, 0, Size);
return _buffLen > 0;
}
private byte ReadByte() {
if (HasNextByte())
return _buffer[_ptr++];
else
// inputの末尾の改行がないとerror
throw new EndOfStreamException();
}
private bool IsAscii(int c) => '!' <= c && c <= '~';
private char NextChar() {
var b = ReadByte();
while (!IsAscii(b))
b = ReadByte();
return (char)b;
}
private string Next() {
var sb = new StringBuilder();
for (var b = NextChar(); IsAscii(b); b = (char)ReadByte())
sb.Append(b);
return sb.ToString();
}
public string String => Next();
public char Char => NextChar();
public int Int => int.Parse(Next());
public long Long => long.Parse(Next());
public double Double => double.Parse(Next());
#endregion
#region LazyRead
private void scan<T>(ref T x) {
if (x is int)
__refvalue(__makeref(x), int) = int.Parse(Next());
else if (x is long)
__refvalue(__makeref(x), long) = long.Parse(Next());
else if (x is double)
__refvalue(__makeref(x), double) = double.Parse(Next());
else if (x is char)
__refvalue(__makeref(x), char) = NextChar();
else
__refvalue(__makeref(x), string) = Next();
}
public void i<T>(out T t) {
t = default(T);
scan(ref t);
}
public void i<T, TU>(out T t, out TU u) {
i(out t);
i(out u);
}
public void i<T, TU, TV>(out T t, out TU u, out TV v) {
i(out t, out u);
i(out v);
}
public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
i(out t, out u);
i(out v, out w);
}
public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
i(out t, out u, out v);
i(out w, out x);
}
public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w,
out TX x, out TY y) {
i(out t, out u, out v);
i(out w, out x, out y);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
i<T>(out a[i]);
}
public void ini<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i)
i<T, TU>(out a[i], out b[i]);
}
public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (var i = 0; i < n; ++i)
i<T, TU, TV>(out a[i], out b[i], out c[i]);
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
i<T>(out a[i, j]);
}
#endregion
#endregion
#region OUTPUT
private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public void Flush() => Out.Flush();
public void YN(bool f) => yn(f, "YES", "NO");
public void Yn(bool f) => yn(f, "Yes", "No");
public void yn(bool f, string y = "yes",
string n = "no") => WriteLine(f ? y : n);
#endregion
public IO() { SetOut(_sw); }
}
static class Util {
public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f);
public static void FOR(int a, int b, int n, Action<int> f) {
for (int i = a; i < b; i += n)
f(i);
}
public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1,
n, f);
public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f);
public static void REP(int a, Action<int> f) => FOR(0, a, f);
public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f);
public static IEnumerable<TResult>
ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys,
Func<T1, T2, TResult> f = null) {
using (var e1 = xs.GetEnumerator()) using (
var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext())
yield return f(e1.Current, e2.Current);
}
public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs,
IEnumerable<T2> ys) =>
ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y));
public static IEnumerable<TResult>
ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys,
IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) {
using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using (
var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() &&
e3.MoveNext())
yield return f(e1.Current, e2.Current, e3.Current);
}
public static IEnumerable<Tuple<T1, T2, T3>>
ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) =>
ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z));
public static bool ODD(int x) => x % 2 != 0;
public static bool ODD(long x) => x % 2L != 0L;
public static int SUM(params int[] xs) => xs.Sum();
public static long SUM(params long[] xs) => xs.Sum();
public struct IndexedItem<T> {
public int Idx;
public T Val;
public IndexedItem(int idx, T val) {
Idx = idx;
Val = val;
}
}
public class Counts<T> : Dictionary<T, int> {
public Counts() {}
public Counts(params T[] xs) : this() { Add(xs); }
public new int this[T key] { get { int v;
return this.TryGetValue(key, out v) ? v : 0;
}
}
public void Add(T key) {
if (!base.ContainsKey(key))
base.Add(key, 0);
base[key]++;
}
public void Add(params T[] xs) => xs.Iter(Add);
public void
SortByCount(bool isAsc) => (isAsc ? (this.OrderBy(kp => kp.Value))
: (this.OrderByDescending(kp => kp.Value)))
.ThenBy(kp => kp.Key);
}
public class PriorityQueue<T>
where T : IComparable<T> {
private List<T> heap;
private readonly bool isAsc;
private int size;
public T Peek => heap[0];
public int Count => size;
public bool Any => size > 0;
public bool Empty => !Any;
public IEnumerable<T> Values => heap;
public PriorityQueue(bool isAsc = true) {
this.isAsc = isAsc;
size = 0;
heap = new List<T>();
}
public void Enqueue(T item) {
heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) / 2;
if (Compare(heap[p], item) <= 0)
break;
heap[i] = heap[p];
i = p;
}
heap[i] = item;
}
public T Dequeue() {
var ret = heap[0];
var x = heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
private int Compare(T x, T y) => isAsc ? x.CompareTo(y) : y.CompareTo(x);
}
}
static class Ex {
public static Tuple<IEnumerable<T>, IEnumerable<T>>
Split<T>(this IEnumerable<T> xs, Func<T, bool> f) {
var ys = xs.Where(f);
var zs = xs.Where(x => !f(x));
return Tuple.Create(ys, zs);
}
public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) {
foreach (var x in xs)
f(x);
}
public static void Prt<T>(this T x) => WriteLine(x);
public static void
Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x));
public static void Log<T>(this T x) {
#if DEBUG
WriteLine($"LOG [{nameof(x)}] : {x}");
#endif
}
public static IEnumerable<IndexedItem<T>>
Indexed<T>(this IEnumerable<T> xs) =>
xs.Select((x, idx) => new IndexedItem<T>(idx, x));
public static IEnumerable<T>
UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val);
public static IEnumerable<Tuple<T, T>>
Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1));
}
}
|
namespace AtCoder {
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static Util;
class AtCoder {
/*------------------------------------------------------------------*/
void Solve() { (io.Int >= 3200 ? io.String : "red").Prt(); }
/*------------------------------------------------------------------*/
void Test() {
//--- TEST ---//
}
public static void Main(string[] _) => new AtCoder().Stream();
IO io = new IO();
private void Stream() {
/*
var exStdIn = new System.IO.StreamReader("stdin.txt");
SetIn(exStdIn);
Test();
*/
Solve();
io.Flush();
}
}
class IO {
#region INPUT
#region FastRead
private const int Size = 1 << 12;
private readonly Stream _stream = OpenStandardInput();
private readonly byte[] _buffer = new byte[Size];
private int _ptr = 0, _buffLen = 0;
private bool HasNextByte() {
if (_ptr < _buffLen)
return true;
_ptr = 0;
_buffLen = _stream.Read(_buffer, 0, Size);
return _buffLen > 0;
}
private byte ReadByte() {
if (HasNextByte())
return _buffer[_ptr++];
else
// inputの末尾の改行がないとerror
throw new EndOfStreamException();
}
private bool IsAscii(int c) => '!' <= c && c <= '~';
private char NextChar() {
var b = ReadByte();
while (!IsAscii(b))
b = ReadByte();
return (char)b;
}
private string Next() {
var sb = new StringBuilder();
for (var b = NextChar(); IsAscii(b); b = (char)ReadByte())
sb.Append(b);
return sb.ToString();
}
public string String => Next();
public char Char => NextChar();
public int Int => int.Parse(Next());
public long Long => long.Parse(Next());
public double Double => double.Parse(Next());
#endregion
#region LazyRead
private void scan<T>(ref T x) {
if (x is int)
__refvalue(__makeref(x), int) = int.Parse(Next());
else if (x is long)
__refvalue(__makeref(x), long) = long.Parse(Next());
else if (x is double)
__refvalue(__makeref(x), double) = double.Parse(Next());
else if (x is char)
__refvalue(__makeref(x), char) = NextChar();
else
__refvalue(__makeref(x), string) = Next();
}
public void i<T>(out T t) {
t = default(T);
scan(ref t);
}
public void i<T, TU>(out T t, out TU u) {
i(out t);
i(out u);
}
public void i<T, TU, TV>(out T t, out TU u, out TV v) {
i(out t, out u);
i(out v);
}
public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
i(out t, out u);
i(out v, out w);
}
public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
i(out t, out u, out v);
i(out w, out x);
}
public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w,
out TX x, out TY y) {
i(out t, out u, out v);
i(out w, out x, out y);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
i<T>(out a[i]);
}
public void ini<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i)
i<T, TU>(out a[i], out b[i]);
}
public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (var i = 0; i < n; ++i)
i<T, TU, TV>(out a[i], out b[i], out c[i]);
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
i<T>(out a[i, j]);
}
#endregion
#endregion
#region OUTPUT
private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public void Flush() => Out.Flush();
public void YN(bool f) => yn(f, "YES", "NO");
public void Yn(bool f) => yn(f, "Yes", "No");
public void yn(bool f, string y = "yes",
string n = "no") => WriteLine(f ? y : n);
#endregion
public IO() { SetOut(_sw); }
}
static class Util {
public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f);
public static void FOR(int a, int b, int n, Action<int> f) {
for (int i = a; i < b; i += n)
f(i);
}
public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1,
n, f);
public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f);
public static void REP(int a, Action<int> f) => FOR(0, a, f);
public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f);
public static IEnumerable<TResult>
ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys,
Func<T1, T2, TResult> f = null) {
using (var e1 = xs.GetEnumerator()) using (
var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext())
yield return f(e1.Current, e2.Current);
}
public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs,
IEnumerable<T2> ys) =>
ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y));
public static IEnumerable<TResult>
ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys,
IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) {
using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using (
var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() &&
e3.MoveNext())
yield return f(e1.Current, e2.Current, e3.Current);
}
public static IEnumerable<Tuple<T1, T2, T3>>
ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) =>
ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z));
public static bool ODD(int x) => x % 2 != 0;
public static bool ODD(long x) => x % 2L != 0L;
public static int SUM(params int[] xs) => xs.Sum();
public static long SUM(params long[] xs) => xs.Sum();
public struct IndexedItem<T> {
public int Idx;
public T Val;
public IndexedItem(int idx, T val) {
Idx = idx;
Val = val;
}
}
public class Counts<T> : Dictionary<T, int> {
public Counts() {}
public Counts(params T[] xs) : this() { Add(xs); }
public new int this[T key] { get { int v;
return this.TryGetValue(key, out v) ? v : 0;
}
}
public void Add(T key) {
if (!base.ContainsKey(key))
base.Add(key, 0);
base[key]++;
}
public void Add(params T[] xs) => xs.Iter(Add);
public void
SortByCount(bool isAsc) => (isAsc ? (this.OrderBy(kp => kp.Value))
: (this.OrderByDescending(kp => kp.Value)))
.ThenBy(kp => kp.Key);
}
public class PriorityQueue<T>
where T : IComparable<T> {
private List<T> heap;
private readonly bool isAsc;
private int size;
public T Peek => heap[0];
public int Count => size;
public bool Any => size > 0;
public bool Empty => !Any;
public IEnumerable<T> Values => heap;
public PriorityQueue(bool isAsc = true) {
this.isAsc = isAsc;
size = 0;
heap = new List<T>();
}
public void Enqueue(T item) {
heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) / 2;
if (Compare(heap[p], item) <= 0)
break;
heap[i] = heap[p];
i = p;
}
heap[i] = item;
}
public T Dequeue() {
var ret = heap[0];
var x = heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
private int Compare(T x, T y) => isAsc ? x.CompareTo(y) : y.CompareTo(x);
}
}
static class Ex {
public static Tuple<IEnumerable<T>, IEnumerable<T>>
Split<T>(this IEnumerable<T> xs, Func<T, bool> f) {
var ys = xs.Where(f);
var zs = xs.Where(x => !f(x));
return Tuple.Create(ys, zs);
}
public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) {
foreach (var x in xs)
f(x);
}
public static void Prt<T>(this T x) => WriteLine(x);
public static void
Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x));
public static void Log<T>(this T x) {
#if DEBUG
WriteLine($"LOG [{nameof(x)}] : {x}");
#endif
}
public static IEnumerable<IndexedItem<T>>
Indexed<T>(this IEnumerable<T> xs) =>
xs.Select((x, idx) => new IndexedItem<T>(idx, x));
public static IEnumerable<T>
UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val);
public static IEnumerable<Tuple<T, T>>
Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1));
}
}
|
[["-", 63, 214, 205, 23, 0, 41, 64, 5, 0, 62], ["-", 63, 214, 205, 23, 0, 41, 64, 5, 0, 222], ["+", 63, 214, 205, 23, 0, 41, 64, 214, 205, 22], ["+", 63, 214, 205, 23, 0, 41, 64, 214, 0, 131], ["+", 63, 214, 205, 23, 0, 41, 64, 214, 141, 22]]
| 8
| 2,696
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string color = Console.ReadLine();
//出力
Console.WriteLine(N >= 3200 ? "red" : color);
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string color = Console.ReadLine();
//出力
Console.WriteLine(N < 3200 ? "red" : color);
Console.ReadLine();
}
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18]]
| 8
| 91
| 2
|
#if DEBUG
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace Contest {
class Program {
static void Main(string[] args) {
var scanner = new IO.StreamScanner(Console.OpenStandardInput());
var a = scanner.Integer();
var s = scanner.ScanLine();
var ans = a >= 3200 ? s : "Red";
IO.Printer.Out.WriteLine(ans);
IO.Printer.Out.Flush();
}
}
#if DEBUG
[TestClass]
public class Test {
[TestMethod]
public void Test1() {}
public bool IsEq<T>(List<T> l1, List<T> l2) {
if (l1.Count() != l2.Count())
return false;
for (int i = 0; i < l1.Count(); i++) {
if (!l1[i].Equals(l2[i]))
return false;
}
return true;
}
}
#endif
}
namespace IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
static Printer() {
Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
}
public static Printer Out { get; set; }
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
}
|
#if DEBUG
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace Contest {
class Program {
static void Main(string[] args) {
var scanner = new IO.StreamScanner(Console.OpenStandardInput());
var a = scanner.Integer();
var s = scanner.ScanLine();
var ans = a >= 3200 ? s : "red";
IO.Printer.Out.WriteLine(ans);
IO.Printer.Out.Flush();
}
}
#if DEBUG
[TestClass]
public class Test {
[TestMethod]
public void Test1() {}
public bool IsEq<T>(List<T> l1, List<T> l2) {
if (l1.Count() != l2.Count())
return false;
for (int i = 0; i < l1.Count(); i++) {
if (!l1[i].Equals(l2[i]))
return false;
}
return true;
}
}
#endif
}
namespace IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
static Printer() {
Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
}
public static Printer Out { get; set; }
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
}
|
[["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
| 8
| 1,053
| 2
|
using System;
class Program {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
// int a = int.Parse(vals[0]);
// string s = vals[1];
if (a > 3200) {
Console.WriteLine(s);
} else {
Console.WriteLine("red");
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
// int a = int.Parse(vals[0]);
// string s = vals[1];
if (a >= 3200) {
Console.WriteLine(s);
} else {
Console.WriteLine("red");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 70
| 2
|
using System;
public class Hello {
public static void Main() {
var a = int.Parse(Console.ReadLine().Trim());
var s = Console.ReadLine().Trim();
Console.WriteLine(a >= 2800 ? s : "red");
}
}
|
using System;
public class Hello {
public static void Main() {
var a = int.Parse(Console.ReadLine().Trim());
var s = Console.ReadLine().Trim();
Console.WriteLine(a >= 3200 ? s : "red");
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203]]
| 8
| 62
| 2
|
using System;
class a {
public static void Main() {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a < 3200) {
Console.WriteLine("red");
} else {
Console.WriteLine("s");
}
}
}
|
using System;
class a {
public static void Main() {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a < 3200) {
Console.WriteLine("red");
} else {
Console.WriteLine(s);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62]]
| 8
| 67
| 2
|
using System;
class Program {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a >= 3200)
Console.WriteLine("red");
else
Console.WriteLine(s);
}
}
|
using System;
class Program {
static void Main(string[] args) {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a < 3200)
Console.WriteLine("red");
else
Console.WriteLine(s);
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 64
| 2
|
using System;
namespace ConsoleApp1 {
internal class Program {
private static void Main(string[] args) {
var a = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
if (a <= 3200) {
Console.WriteLine(s);
} else {
Console.WriteLine("red");
}
}
}
}
|
using System;
namespace ConsoleApp1 {
internal class Program {
private static void Main(string[] args) {
var a = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
if (a >= 3200) {
Console.WriteLine(s);
} else {
Console.WriteLine("red");
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 74
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace AtcoderC {
class Program {
/*static void Main(string[] args)
{
}*/
// ABC132C
//全探索法
/*static void Main()
{
BigInteger N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int min = input.Min();
int max = input.Max();
int countARC = 0;
int countABC = 0;
int Answer = 0;
for (int i = min; i <= max; i++)
{
countABC = 0;
countARC = 0;
foreach (int n in input)
{
if (n > i)
{
countARC++;
}
else
{
countABC++;
}
}
if (countABC == countARC)
{
Answer++;
}
}
Console.WriteLine(Answer);
}*/
// 2回目
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(input);
int min = input[(N / 2) - 1];
int max = input[N / 2];
Console.WriteLine(max - min);
}*/
// ABC131C
//ユーグリッドの互除法の応用
/*static void Main()
{
BigInteger[] input =
Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A =
input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D =
input[3]; BigInteger ans = (B / C) + (B / D);
//最小公倍数
var ans2 = C * D / lcm(C, D);
BigInteger ans3 = B / ans2;
var BB = B - ans + ans3;
ans = (A - 1) / C + (A - 1) / D;
ans3 = (A - 1) / ans2;
var AA = (A - 1) - ans + ans3;
Console.WriteLine(BB - AA);
}
static public BigInteger lcm(BigInteger a, BigInteger b)
{
var r = a % b;
while (r != 0)
{
a = b;
b = r;
r = a % b;
}
return b;
}*/
// 129C
//動的計画法
// TLEになる時間がかかり過ぎる
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int> ttt = new List<int>();
for (int i = 0;i < M;i++)
{
var temp = int.Parse(Console.ReadLine());
ttt.Add(temp);
}
int[] dparray = new int[N+2];
dparray[N] = 1;
dparray[N - 1] = 1;
for (int i = N-1; i >= 0; i--)
{
if (ttt.Contains(i))
{
dparray[i] = 0;
}
dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007;
}
Console.WriteLine(dparray[0]);
}*/
// ABC128
/*static void Main()
{
}*/
// ABC134A
/*static void Main()
{
int r = int.Parse(Console.ReadLine());
var ans = 3 * r * r;
Console.WriteLine(ans);
}*/
// ABC134B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int D = input[1];
int count = 0;
int ans = N;
while (true)
{
ans = ans - (D * 2 + 1);
count++;
if (ans <= 0)
{
break;
}
}
Console.WriteLine(count);
}*/
// ABC134C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<int> array = new List<int>();
for (int i =0;i<N; i++)
{
array.Add(int.Parse(Console.ReadLine()));
}
List<int> ans = new List<int>();
int max = array.Max();
var temp = new List<int>();
foreach (int n in array)
{
temp.Add(n);
}
temp.Sort();
temp.Reverse();
int second = temp[1];
foreach (int nn in array)
{
if (nn == max)
{
Console.WriteLine(second);
}
else
{
Console.WriteLine(max);
}
}
}*/
// 134ABCD
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int count = 0;
int ans = 0;
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0;i<N;i++)
{
for (int j =0;j<N; j++)
{
if ((j+1)%(i+1)==0)
{
count += input[j];
}
}
if (count % 2 == input[i])
{
ans++;
}
count = 0;
}
if (ans != 0)
{
}
}*/
// AGC036
/*static void Main()
{
long S = long.Parse(Console.ReadLine());
long X1 = 1000000000;
long Y1 = 0;
/*while (true)
{
Y1 = S / X1 + S % X1;
}
Y1 = S / X1 + S % X1;
Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1);
/*int tempX = 0;
List<long> ss = new List<long>();
while (tempX < S)
{
var ans = S % tempX;
if (ans == 0)
{
ss.Add(ans);
}
tempX++;
}
Console.WriteLine(tempX);*/
/*long X1 = 0;
long Y1 = 1;
while (true)
{
X1 = S % Y1;
if (X1 <= 1000000000)
{
break;
}
Y1++;
}
Console.WriteLine("0 0 "+X1+" 0 0 "+Y1);
}*/
// ABC82A
/*static void Main()
{
double[] input =
Console.ReadLine().Split().Select(double.Parse).ToArray(); double a =
input[0]; double b = input[1]; double sum = (a + b) / 2;
Console.WriteLine(Math.Ceiling(sum));
}*/
// ABC128C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
int ans = 0;
List<int[]> K = new List<int[]>();
for (int i = 0;i<M;i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
K.Add(temp);
}
int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] light = new int[M];
for (int i = 0;i < Math.Pow(2,N);i++)
{
var isrow = 0;
var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000");
for (int j =0;j < M;j++)
{
var ison = 0;
for (int k = 0; k < K[j][0];k++)
{
var index = K[j][k] - 1;
if (temp[9-index] == '1')
{
ison++;
}
}
if (ison % 2 == P[j])
{
isrow++;
}
else
{
break;
}
}
if (isrow == M)
{
ans++;
}
}
Console.WriteLine(ans);*/
/*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int a = input[0];
int b = input[1];
var temp = a * b % 2;
if (temp == 0)
{
Console.WriteLine("even");
}
else
{
Console.WriteLine("odd");
}
}*/
// ABC127C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
if (M == 1)
{
Console.WriteLine(N);
}
else
{
List<int> card = new List<int>();
for (int i = gate[0][0]; i <= gate[0][1]; i++)
{
card.Add(i);
}
for (int j = 1; j < gate.Count; j++)
{
List<int> ans = new List<int>();
var count = 0;
for (int i = gate[j][0]; i <= gate[j][1]; i++)
{
if (card.Contains(i))
{
count++;
ans.Add(i);
}
}
if (count == 0)
{
break;
}
card = new List<int>(ans);
}
Console.WriteLine(card.Count());
}
}*/
// 127C Revenge TLE
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
int Ans = 0;
for (int i =1;i<=N;i++)
{
var count = 0;
for (int j = 0;j < gate.Count;j++)
{
if (gate[j][0] <= i && i <= gate[j][1])
{
count++;
}
}
if (count == gate.Count)
{
Ans++;
}
}
Console.WriteLine(Ans);
}*/
// 127C RevengeVer2
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
List<int> Max = new List<int>();
List<int> Min = new List<int>();
for (int i =0;i< M;i++)
{
Max.Add(gate[i][1]);
Min.Add(gate[i][0]);
}
int max = Max.Min();
int min = Min.Max();
if (min <= max)
{
Console.WriteLine(max - min + 1);
}
else
{
Console.WriteLine("0");
}
}*/
// ABC126C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
double ans = 0.0;
for (int i = 1; i<= N;i++)
{
double tempP = (double)1 / N;
int point = i;
while (point<M)
{
tempP = tempP * 1 / 2;
point *= 2;
}
ans += tempP;
}
Console.WriteLine(ans);
}*/
// ABC125C ユーグリッド互除法
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(A);
int lcmr, lcml = 0;
List<int> answer = new List<int>();
for (int i =0;i<A.Length;i++)
{
lcmr = 0;
for (int x = 0;x < i;x++)
{
if (lcmr - A[x] >= 0)
{
lcmr = lcm(lcmr, A[x]);
}
else
{
lcmr = lcm(A[x], lcmr);
}
}
lcml = 0;
for (int y = i+1; y < A.Length; y++)
{
if (lcml - A[y] >= 0)
{
lcml = lcm(lcml, A[y]);
}
else
{
lcml = lcm(A[y],lcml);
}
}
var tempans = 0;
if (lcmr > lcml)
{
tempans = lcm(lcmr, lcml);
}
else
{
tempans = lcm(lcml, lcmr);
}
answer.Add(tempans);
}
Console.WriteLine(answer.Max());
}
static public int lcm(int a, int b)
{
if (b == 0)
{
return a;
}
var r = a % b;
while (r != 0)
{
a = b;
b = r;
r = a % b;
}
return b;
}*/
// 124C
/*static void Main()
{
string inputstr = Console.ReadLine();
int count = 0;
if (inputstr[0] == '0')
{
for (int i = 0; i < inputstr.Length; i++)
{
if (i % 2 == 0)
{
if (inputstr[i] == '1')
{
count++;
}
}
else
{
if (inputstr[i] == '0')
{
count++;
}
}
}
}
else
{
for (int i = 0; i < inputstr.Length; i++)
{
if (i % 2 == 1)
{
if (inputstr[i] == '1')
{
count++;
}
}
else
{
if (inputstr[i] == '0')
{
count++;
}
}
}
}
Console.WriteLine(count);
}*/
// 123C
/*static void Main()
{
double N = double.Parse(Console.ReadLine());
List<double> city = new List<double>();
for (int i = 0; i < 5; i++)
{
city.Add(double.Parse(Console.ReadLine()));
}
var ans = Math.Ceiling(N / city.Min()) + 4;
Console.WriteLine(ans);
}*/
// 82C
/*static void Main()
{
double[] input =
Console.ReadLine().Split().Select(double.Parse).ToArray(); double a =
input[0]; double b = input[1]; double answer = (a + b) / 2;
Console.WriteLine(Math.Ceiling(answer));
}*/
// 128B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int P = input[1];
var ans = (P + A * 3) / 2;
Console.WriteLine(ans);
int a,b
cin << a << b;
cout >> (P + A * 3) / 2 >> endl;
}*/
// 119A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
if (B % A == 0)
{
Console.WriteLine(A + B);
}
else
{
Console.WriteLine(B-A);
}
}*/
// 116A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int C = input[2];
Console.WriteLine((A*B)/2);
}*/
// ABC31B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = int.Parse(Console.ReadLine());
List<int> array = new List<int>();
for (int i =0;i<N;i++)
{
array.Add(int.Parse(Console.ReadLine()));
}
foreach (int a in array)
{
if (a < input[0])
{
Console.WriteLine(input[0] - a);
}
else if (input[1] < a)
{
Console.WriteLine("-1");
}
else
{
Console.WriteLine("0");
}
}
}*/
// ABC36B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<string> map = new List<string>();
for (int i =0;i< N;i++)
{
map.Add(Console.ReadLine());
}
List<string> ans = new List<string>();
for(int j = 0; j < N;j++)
{
var temp = "";
for (int i = N-1; i >= 0; i--)
{
temp += map[i][j];
}
ans.Add(temp);
}
foreach (string a in ans)
{
Console.WriteLine(a);
}
}*/
// ABC40B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int A = 0;
int temp = N;
if (N == 1)
{
Console.WriteLine("0");
}
else
{
while (true)
{
double root = Math.Sqrt(N);
if (root != (int)root)
{
N--;
}
else
{
A = (int)root;
break;
}
}
List<int> answer = new List<int>();
bool flag = false;
while (A > 0)
{
var a = A;
while (A * a <= temp)
{
var ans = temp - (A * a) + Math.Abs(A - a);
if (ans == 0)
{
flag = true;
break;
}
a++;
answer.Add(ans);
}
if (flag == true)
{
break;
}
A--;
}
if (flag)
{
Console.WriteLine("0");
}
else
{
Console.WriteLine(answer.Min());
}
}
}*/
// ABC122C
// TLE
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string S = Console.ReadLine();
List<int[]> array = new List<int[]>();
for (int i = 0; i < input[1]; i++)
{
array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
List<int> answer = new List<int>();
foreach (int[] n in array)
{
var tempstr = S.Substring(n[0]-1,n[1]-n[0]+1);
var count = tempstr.Length - tempstr.Replace("AC","").Length;
var ans = count / 2;
answer.Add(ans);
}
foreach (int a in answer)
{
Console.WriteLine(a);
}
}*/
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string S = Console.ReadLine();
List<int[]> array = new List<int[]>();
for (int i = 0; i < input[1]; i++)
{
array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
for (int i = 0;i < S.Length-1;i++)
{
if (S[i] == 'A')
{
if (S[i + 1] == 'C')
{
S = S.Replace(S[i],'a');
}
}
}
int count = 0;
List<int> ansstr = new List<int>();
for (int i = 0; i < S.Length;i++)
{
count = 0;
for (int j = 0;j <= i;j++)
{
if (S[j] == 'a')
{
count++;
}
}
ansstr.Add(count);
}
List<int> anss = new List<int>();
for (int i = 0; i < input[1];i++)
{
anss.Add(ansstr[array[i][1]-2] - ansstr[array[i][0]-1]);
}
foreach (int a in anss)
{
Console.WriteLine(a);
}
}*/
// ABC39B
/*static void Main()
{
int X = int.Parse(Console.ReadLine());
var ans = Math.Sqrt(X);
var ans2 = Math.Sqrt(ans);
Console.WriteLine(ans2);
}*/
// ABC38B
/*static void Main()
{
int[] input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] input2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
bool flag1 = false;
foreach (int a in input1)
{
foreach (int b in input2)
{
if (a == b)
{
flag1 = true;
}
}
}
if (flag1 == true)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC35B
/*static void Main()
{
string S = Console.ReadLine();
int T = int.Parse(Console.ReadLine());
int[] pos = { 0, 0 };
foreach (char a in S)
{
}
}*/
// ABC34B
/*static void Main()
{
}*/
//技術ProgramContest4Day1
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
}*/
// ABC135A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
var temp = B - A;
if (temp % 2 == 0)
{
Console.WriteLine(A + (temp/2));
}
else
{
Console.WriteLine("IMPOSSIBLE");
}
}*/
// ABC135B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] AnsN = new int[N];
for (int i = 0;i <N;i++)
{
AnsN[i] = i + 1;
}
int count = 0;
for(int i = 0;i < N;i++)
{
if (P[i] != AnsN[i])
{
count++;
}
}
if (count <= 2)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC135C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray();
/*int count = 0;
for (int i = N;i>0;i--)
{
var tempA = A[i] + A[i - 1];
if (tempA <= B[i - 1])
{
A[i - 1] = 0;
count += tempA;
}
else
{
if (A[i] <= B[i - 1])
{
A[i - 1] = tempA - B[i - 1];
count += B[i - 1];
}
else
{
count += B[i - 1];
}
}
}*/
/*int count = 0;
for (int i = 0;i < N;i++)
{
var tempA = A[i] + A[i + 1];
if (tempA <= B[i])
{
A[i + 1] = 0;
count += tempA;
}
else
{
if (B[i] >= A[i])
{
A[i + 1] = A[i + 1] - (B[i] - A[i]);
count += B[i];
}
else
{
count += B[i];
}
}
}
//このやり方
int count = 0;
for (int i = 0; i < N;i++)
{
List<int> temp = new List<int>();
temp.Add(A[i]);
temp.Add(B[i]);
count += temp.Min();
}
Console.WriteLine(count);
}*/
// ABC135D
// ABC127A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string inputstr = Console.ReadLine();
char[] temp = inputstr.ToCharArray();
temp[input[1]-1] = Char.ToLower(temp[input[1] -1]);
inputstr = new string(temp);
Console.WriteLine(inputstr);
}*/
// ABC35
/*static void Main()
{
string S = Console.ReadLine();
int T = int.Parse(Console.ReadLine());
int[] ans = { 0, 0 };
int count = 0;
for (int i = 0; i < S.Length;i++)
{
if (S[i] == 'U')
{
ans[1]++;
}
else if (S[i] == 'D')
{
ans[1]--;
}
else if (S[i] == 'R')
{
ans[0]++;
}
else if (S[i] == 'L')
{
ans[0]--;
}
else
{
count++;
}
}
List<int[]> answer = new List<int[]>();
answer.Add(ans);
answer.Add(ans);
answer.Add(ans);
answer.Add(ans);
foreach (int[] n in answer)
{
}
}*/
// ABC114A
/*static void Main()
{
int x = int.Parse(Console.ReadLine());
if (x == 7 || x == 5 || x == 3)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC121C
// TLE
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long M = input[1];
List<long[]> shop = new List<long[]>();
for (int i = 0;i < n;i++)
{
shop.Add(Console.ReadLine().Split().Select(long.Parse) .ToArray());
}
List<long[]> answer = new List<long[]>(Sort(shop));
long price = 0;
long count = 0;
foreach (long[] temp in answer)
{
var tempcount = count;
if (count + temp[1] <= M)
{
count += temp[1];
}
else
{
count = M;
}
price += (count-tempcount) * temp[0];
if (M<=count)
{
break;
}
}
Console.WriteLine(price);
}
static List<long[]> Sort(List<long[]> A)
{
for (int i = 0;i < A.Count;i++)
{
for (int j = A.Count-1;j >i;j-- )
{
if (A[j][0] < A[j-1][0])
{
var temp = A[j];
A[j] = A[j - 1];
A[j - 1] = temp;
}
}
}
return A;
}*/
// Sortはライブラリを使った方が早い
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long M = input[1];
List<long[]> shops = new List<long[]>();
for (int i = 0; i < n; i++)
{
shops.Add(Console.ReadLine().Split().Select(long.Parse).ToArray());
}
long count = 0;
long ans = 0;
foreach (long[] shop in shops.OrderBy(a => a[0]))
{
var i = Math.Min(M - count, shop[1]);
ans += shop[0] * i;
count += i;
if (count >= M)
{
break;
}
}
Console.WriteLine(ans);
}*/
// 120C
// TLE
/*static void Main()
{
/*string input = Console.ReadLine();
int len = input.Length;
int count = 0;
while (input.Contains("01") || input.Contains("10"))
{
input = input.Replace("01", "").Replace("10", "");
count += len - input.Length;
len = input.Length;
}
Console.WriteLine(count);
string s = Console.ReadLine();
int zero = s.Replace("1", "").Length;
int one = s.Replace("0", "").Length;
Console.WriteLine((zero < one ? zero : one) * 2);
}*/
// 119
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
List<int> goal = new List<int>();
List<int> list = new List<int>();
for (int i =1;i<=N-1;i++)
{
goal.Add(input[i]);
}
for (int i = 0;i<N;i++)
{
list.Add(int.Parse(Console.ReadLine()));
}
}*/
// 118C
// 37B
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long k = input[1];
List<long[]> list = new List<long[]>();
for (int i = 0;i < k;i++)
{
long[] temp = Console.ReadLine().Split().Select(long.Parse).ToArray();
list.Add(temp);
}
long[] Ans = new long[n];
foreach (long[] m in list)
{
for (int i =0;i < Ans.Length;i++)
{
if (m[0]-1 <= i && i <= m[1]-1)
{
Ans[i] = m[2];
}
}
}
foreach (int a in Ans)
{
Console.WriteLine(a);
}
}*/
//大手前プロコン2019
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
if (A + 0.5f >= B)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
}*/
// E
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = input[0];
long Q = input[1];
List<long> D = new List<long>();
for (long i = 0;i < N;i++)
{
D.Add(long.Parse(Console.ReadLine()));
}
List<long[]> TLR = new List<long[]>();
for (long i = 0;i < Q;i++)
{
TLR.Add(Console.ReadLine().Split().Select(long.Parse).ToArray());
}
foreach (long[] tlr in TLR)
{
var count = 0;
var tempara = new List<long>();
var a = tlr[0];
tempara.Add(a);
for (long i = 1;i <= N;i++)
{
if (Math.Abs(a - (-1 * i)) > D[(int)i - 1])
{
a = a - D[(int)i - 1];
}
else
{
a = -1*i;
}
tempara.Add(a);
}
foreach (long n in tempara)
{
if ( tlr[1]<= n && tlr[2] >= n)
{
count++;
}
}
Console.WriteLine(count);
}
}*/
// AtCoderBeginnerContest136
// 136A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int C = input[2];
var a = A - B;
var ans = C - a;
if (ans >= 0)
{
Console.WriteLine(ans);
}
else
{
Console.WriteLine("0");
}
}*/
// 136B
/*static void Main()
{
string N = Console.ReadLine();
int n = int.Parse(N);
int ocun = 0;
for (int i = 1; i<=n;i++)
{
if (i.ToString().Length % 2 == 1)
{
ocun++;
}
}
Console.WriteLine(ocun);
}*/
// 136C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] list = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count = 0;
int max = 0;
bool flag = false;
foreach (int a in list)
{
if (a >= max)
{
max = a;
}
else if (max - a >= 2)
{
flag = true;
break;
}
else { }
}
if (flag)
{
Console.WriteLine("No");
}
else
{
Console.WriteLine("Yes");
}
}*/
// 113C-ID
/*static void Main()
{
string S = Console.ReadLine();
Console.WriteLine(S.Length);
}*/
// 113A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
Console.WriteLine(A + (B/2));
}*/
// 112A
/*static void Main()
{
}*/
// 137A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
List<int> answer = new List<int>();
var ans1 = A + B;
answer.Add(ans1);
var ans2 = A - B;
answer.Add(ans2);
var ans3 = A * B;
answer.Add(ans3);
Console.WriteLine(answer.Max());
}*/
// 137B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int K = input[0];
int X = input[1];
for (int i = X - (K-1);i<= X + (K-1);i++)
{int
if (i >= -1000000 && i <= 1000000)
{
Console.Write(i+" ");
}
}
Console.WriteLine();
}*/
// 137C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<string[]> list = new List<string[]>();
for (int i = 0; i < N;i++)
{
list.Add(Console.ReadLine().Split());
}
foreach (string[] n in list)
{
Array.Sort(n);
}
long ans = 0;
for (int i = 0; i< list.Count;i++)
{
for (int j = i+1;j < list.Count;j++)
{
if (list[i].Equals(list[j]))
{
ans++;
}
}
}
Console.WriteLine(ans);
}*/
/*static void Main(string[] args)
{
int N = Convert.ToInt32(Console.ReadLine());
string[] S = new string[N];
for (var i = 0; i < N; i++)
{
char[] c = Console.ReadLine().ToCharArray();
Array.Sort(c);
S[i] = new string(c);
}
Dictionary<string, long> dict = new Dictionary<string, long>();
for (var i = 0; i < N; i++)
{
if (dict.ContainsKey(S[i]))
{
dict[S[i]]++;
}
else
{
dict[S[i]] = 1L;
}
}
long res = 0L;
foreach (var i in dict)
{
if (i.Value > 1)
{
res += i.Value * (i.Value - 1) / 2;
}
}
Console.WriteLine(res);
}*/
// 138A
static void Main() {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a > 3200) {
Console.WriteLine("red");
} else {
Console.WriteLine(s);
}
}
// 138B
// 138C
}
}
// 125C難しい
/*namespace CSharp
{
class Program
{
static IEnumerable<long> EnumerateDivisors(long n)
{
for (long i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
yield return i;
if (n / i != i)
{
yield return n / i;
}
}
}
}
static void Main(string[] args)
{
ReadString();
long[] A = ReadLongArray();
long[] divisors = Enumerable.Concat(EnumerateDivisors(A[0]),
EnumerateDivisors(A[1])) .Distinct().ToArray(); long ans = divisors.Select(x =>
new { Value = x, Count = A.Count(v => v % x == 0) }) .Where(x => x.Count >=
A.Length - 1) .OrderByDescending(x => x.Value) .First().Value;
Console.WriteLine(ans);
}
#region Helpers
static int[] ReadIntArray() => Console.ReadLine().Split().Select(s =>
int.Parse(s)).ToArray(); static long[] ReadLongArray() =>
Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0,
count).Select(_ => int.Parse(Console.ReadLine())).ToArray(); static long[]
ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ =>
long.Parse(Console.ReadLine())).ToArray();
static string ReadString() => Console.ReadLine();
static int ReadInt() => int.Parse(Console.ReadLine());
static long ReadLong() => long.Parse(Console.ReadLine());
static void ReadInt(out int first)
{
var array = ReadIntArray();
first = array[0];
}
static void ReadInt(out int first, out int second)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
}
static void ReadInt(out int first, out int second, out int third)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadInt(out int first, out int second, out int third, out
int fourth)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
static void ReadLong(out long first)
{
var array = ReadLongArray();
first = array[0];
}
static void ReadLong(out long first, out long second)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
}
static void ReadLong(out long first, out long second, out long third)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadLong(out long first, out long second, out long third,
out long fourth)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
#endregion
}
}*/
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace AtcoderC {
class Program {
/*static void Main(string[] args)
{
}*/
// ABC132C
//全探索法
/*static void Main()
{
BigInteger N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int min = input.Min();
int max = input.Max();
int countARC = 0;
int countABC = 0;
int Answer = 0;
for (int i = min; i <= max; i++)
{
countABC = 0;
countARC = 0;
foreach (int n in input)
{
if (n > i)
{
countARC++;
}
else
{
countABC++;
}
}
if (countABC == countARC)
{
Answer++;
}
}
Console.WriteLine(Answer);
}*/
// 2回目
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(input);
int min = input[(N / 2) - 1];
int max = input[N / 2];
Console.WriteLine(max - min);
}*/
// ABC131C
//ユーグリッドの互除法の応用
/*static void Main()
{
BigInteger[] input =
Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A =
input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D =
input[3]; BigInteger ans = (B / C) + (B / D);
//最小公倍数
var ans2 = C * D / lcm(C, D);
BigInteger ans3 = B / ans2;
var BB = B - ans + ans3;
ans = (A - 1) / C + (A - 1) / D;
ans3 = (A - 1) / ans2;
var AA = (A - 1) - ans + ans3;
Console.WriteLine(BB - AA);
}
static public BigInteger lcm(BigInteger a, BigInteger b)
{
var r = a % b;
while (r != 0)
{
a = b;
b = r;
r = a % b;
}
return b;
}*/
// 129C
//動的計画法
// TLEになる時間がかかり過ぎる
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int> ttt = new List<int>();
for (int i = 0;i < M;i++)
{
var temp = int.Parse(Console.ReadLine());
ttt.Add(temp);
}
int[] dparray = new int[N+2];
dparray[N] = 1;
dparray[N - 1] = 1;
for (int i = N-1; i >= 0; i--)
{
if (ttt.Contains(i))
{
dparray[i] = 0;
}
dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007;
}
Console.WriteLine(dparray[0]);
}*/
// ABC128
/*static void Main()
{
}*/
// ABC134A
/*static void Main()
{
int r = int.Parse(Console.ReadLine());
var ans = 3 * r * r;
Console.WriteLine(ans);
}*/
// ABC134B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int D = input[1];
int count = 0;
int ans = N;
while (true)
{
ans = ans - (D * 2 + 1);
count++;
if (ans <= 0)
{
break;
}
}
Console.WriteLine(count);
}*/
// ABC134C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<int> array = new List<int>();
for (int i =0;i<N; i++)
{
array.Add(int.Parse(Console.ReadLine()));
}
List<int> ans = new List<int>();
int max = array.Max();
var temp = new List<int>();
foreach (int n in array)
{
temp.Add(n);
}
temp.Sort();
temp.Reverse();
int second = temp[1];
foreach (int nn in array)
{
if (nn == max)
{
Console.WriteLine(second);
}
else
{
Console.WriteLine(max);
}
}
}*/
// 134ABCD
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int count = 0;
int ans = 0;
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0;i<N;i++)
{
for (int j =0;j<N; j++)
{
if ((j+1)%(i+1)==0)
{
count += input[j];
}
}
if (count % 2 == input[i])
{
ans++;
}
count = 0;
}
if (ans != 0)
{
}
}*/
// AGC036
/*static void Main()
{
long S = long.Parse(Console.ReadLine());
long X1 = 1000000000;
long Y1 = 0;
/*while (true)
{
Y1 = S / X1 + S % X1;
}
Y1 = S / X1 + S % X1;
Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1);
/*int tempX = 0;
List<long> ss = new List<long>();
while (tempX < S)
{
var ans = S % tempX;
if (ans == 0)
{
ss.Add(ans);
}
tempX++;
}
Console.WriteLine(tempX);*/
/*long X1 = 0;
long Y1 = 1;
while (true)
{
X1 = S % Y1;
if (X1 <= 1000000000)
{
break;
}
Y1++;
}
Console.WriteLine("0 0 "+X1+" 0 0 "+Y1);
}*/
// ABC82A
/*static void Main()
{
double[] input =
Console.ReadLine().Split().Select(double.Parse).ToArray(); double a =
input[0]; double b = input[1]; double sum = (a + b) / 2;
Console.WriteLine(Math.Ceiling(sum));
}*/
// ABC128C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
int ans = 0;
List<int[]> K = new List<int[]>();
for (int i = 0;i<M;i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
K.Add(temp);
}
int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] light = new int[M];
for (int i = 0;i < Math.Pow(2,N);i++)
{
var isrow = 0;
var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000");
for (int j =0;j < M;j++)
{
var ison = 0;
for (int k = 0; k < K[j][0];k++)
{
var index = K[j][k] - 1;
if (temp[9-index] == '1')
{
ison++;
}
}
if (ison % 2 == P[j])
{
isrow++;
}
else
{
break;
}
}
if (isrow == M)
{
ans++;
}
}
Console.WriteLine(ans);*/
/*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int a = input[0];
int b = input[1];
var temp = a * b % 2;
if (temp == 0)
{
Console.WriteLine("even");
}
else
{
Console.WriteLine("odd");
}
}*/
// ABC127C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
if (M == 1)
{
Console.WriteLine(N);
}
else
{
List<int> card = new List<int>();
for (int i = gate[0][0]; i <= gate[0][1]; i++)
{
card.Add(i);
}
for (int j = 1; j < gate.Count; j++)
{
List<int> ans = new List<int>();
var count = 0;
for (int i = gate[j][0]; i <= gate[j][1]; i++)
{
if (card.Contains(i))
{
count++;
ans.Add(i);
}
}
if (count == 0)
{
break;
}
card = new List<int>(ans);
}
Console.WriteLine(card.Count());
}
}*/
// 127C Revenge TLE
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
int Ans = 0;
for (int i =1;i<=N;i++)
{
var count = 0;
for (int j = 0;j < gate.Count;j++)
{
if (gate[j][0] <= i && i <= gate[j][1])
{
count++;
}
}
if (count == gate.Count)
{
Ans++;
}
}
Console.WriteLine(Ans);
}*/
// 127C RevengeVer2
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
List<int> Max = new List<int>();
List<int> Min = new List<int>();
for (int i =0;i< M;i++)
{
Max.Add(gate[i][1]);
Min.Add(gate[i][0]);
}
int max = Max.Min();
int min = Min.Max();
if (min <= max)
{
Console.WriteLine(max - min + 1);
}
else
{
Console.WriteLine("0");
}
}*/
// ABC126C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
double ans = 0.0;
for (int i = 1; i<= N;i++)
{
double tempP = (double)1 / N;
int point = i;
while (point<M)
{
tempP = tempP * 1 / 2;
point *= 2;
}
ans += tempP;
}
Console.WriteLine(ans);
}*/
// ABC125C ユーグリッド互除法
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(A);
int lcmr, lcml = 0;
List<int> answer = new List<int>();
for (int i =0;i<A.Length;i++)
{
lcmr = 0;
for (int x = 0;x < i;x++)
{
if (lcmr - A[x] >= 0)
{
lcmr = lcm(lcmr, A[x]);
}
else
{
lcmr = lcm(A[x], lcmr);
}
}
lcml = 0;
for (int y = i+1; y < A.Length; y++)
{
if (lcml - A[y] >= 0)
{
lcml = lcm(lcml, A[y]);
}
else
{
lcml = lcm(A[y],lcml);
}
}
var tempans = 0;
if (lcmr > lcml)
{
tempans = lcm(lcmr, lcml);
}
else
{
tempans = lcm(lcml, lcmr);
}
answer.Add(tempans);
}
Console.WriteLine(answer.Max());
}
static public int lcm(int a, int b)
{
if (b == 0)
{
return a;
}
var r = a % b;
while (r != 0)
{
a = b;
b = r;
r = a % b;
}
return b;
}*/
// 124C
/*static void Main()
{
string inputstr = Console.ReadLine();
int count = 0;
if (inputstr[0] == '0')
{
for (int i = 0; i < inputstr.Length; i++)
{
if (i % 2 == 0)
{
if (inputstr[i] == '1')
{
count++;
}
}
else
{
if (inputstr[i] == '0')
{
count++;
}
}
}
}
else
{
for (int i = 0; i < inputstr.Length; i++)
{
if (i % 2 == 1)
{
if (inputstr[i] == '1')
{
count++;
}
}
else
{
if (inputstr[i] == '0')
{
count++;
}
}
}
}
Console.WriteLine(count);
}*/
// 123C
/*static void Main()
{
double N = double.Parse(Console.ReadLine());
List<double> city = new List<double>();
for (int i = 0; i < 5; i++)
{
city.Add(double.Parse(Console.ReadLine()));
}
var ans = Math.Ceiling(N / city.Min()) + 4;
Console.WriteLine(ans);
}*/
// 82C
/*static void Main()
{
double[] input =
Console.ReadLine().Split().Select(double.Parse).ToArray(); double a =
input[0]; double b = input[1]; double answer = (a + b) / 2;
Console.WriteLine(Math.Ceiling(answer));
}*/
// 128B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int P = input[1];
var ans = (P + A * 3) / 2;
Console.WriteLine(ans);
int a,b
cin << a << b;
cout >> (P + A * 3) / 2 >> endl;
}*/
// 119A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
if (B % A == 0)
{
Console.WriteLine(A + B);
}
else
{
Console.WriteLine(B-A);
}
}*/
// 116A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int C = input[2];
Console.WriteLine((A*B)/2);
}*/
// ABC31B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = int.Parse(Console.ReadLine());
List<int> array = new List<int>();
for (int i =0;i<N;i++)
{
array.Add(int.Parse(Console.ReadLine()));
}
foreach (int a in array)
{
if (a < input[0])
{
Console.WriteLine(input[0] - a);
}
else if (input[1] < a)
{
Console.WriteLine("-1");
}
else
{
Console.WriteLine("0");
}
}
}*/
// ABC36B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<string> map = new List<string>();
for (int i =0;i< N;i++)
{
map.Add(Console.ReadLine());
}
List<string> ans = new List<string>();
for(int j = 0; j < N;j++)
{
var temp = "";
for (int i = N-1; i >= 0; i--)
{
temp += map[i][j];
}
ans.Add(temp);
}
foreach (string a in ans)
{
Console.WriteLine(a);
}
}*/
// ABC40B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int A = 0;
int temp = N;
if (N == 1)
{
Console.WriteLine("0");
}
else
{
while (true)
{
double root = Math.Sqrt(N);
if (root != (int)root)
{
N--;
}
else
{
A = (int)root;
break;
}
}
List<int> answer = new List<int>();
bool flag = false;
while (A > 0)
{
var a = A;
while (A * a <= temp)
{
var ans = temp - (A * a) + Math.Abs(A - a);
if (ans == 0)
{
flag = true;
break;
}
a++;
answer.Add(ans);
}
if (flag == true)
{
break;
}
A--;
}
if (flag)
{
Console.WriteLine("0");
}
else
{
Console.WriteLine(answer.Min());
}
}
}*/
// ABC122C
// TLE
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string S = Console.ReadLine();
List<int[]> array = new List<int[]>();
for (int i = 0; i < input[1]; i++)
{
array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
List<int> answer = new List<int>();
foreach (int[] n in array)
{
var tempstr = S.Substring(n[0]-1,n[1]-n[0]+1);
var count = tempstr.Length - tempstr.Replace("AC","").Length;
var ans = count / 2;
answer.Add(ans);
}
foreach (int a in answer)
{
Console.WriteLine(a);
}
}*/
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string S = Console.ReadLine();
List<int[]> array = new List<int[]>();
for (int i = 0; i < input[1]; i++)
{
array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
for (int i = 0;i < S.Length-1;i++)
{
if (S[i] == 'A')
{
if (S[i + 1] == 'C')
{
S = S.Replace(S[i],'a');
}
}
}
int count = 0;
List<int> ansstr = new List<int>();
for (int i = 0; i < S.Length;i++)
{
count = 0;
for (int j = 0;j <= i;j++)
{
if (S[j] == 'a')
{
count++;
}
}
ansstr.Add(count);
}
List<int> anss = new List<int>();
for (int i = 0; i < input[1];i++)
{
anss.Add(ansstr[array[i][1]-2] - ansstr[array[i][0]-1]);
}
foreach (int a in anss)
{
Console.WriteLine(a);
}
}*/
// ABC39B
/*static void Main()
{
int X = int.Parse(Console.ReadLine());
var ans = Math.Sqrt(X);
var ans2 = Math.Sqrt(ans);
Console.WriteLine(ans2);
}*/
// ABC38B
/*static void Main()
{
int[] input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] input2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
bool flag1 = false;
foreach (int a in input1)
{
foreach (int b in input2)
{
if (a == b)
{
flag1 = true;
}
}
}
if (flag1 == true)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC35B
/*static void Main()
{
string S = Console.ReadLine();
int T = int.Parse(Console.ReadLine());
int[] pos = { 0, 0 };
foreach (char a in S)
{
}
}*/
// ABC34B
/*static void Main()
{
}*/
//技術ProgramContest4Day1
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
}*/
// ABC135A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
var temp = B - A;
if (temp % 2 == 0)
{
Console.WriteLine(A + (temp/2));
}
else
{
Console.WriteLine("IMPOSSIBLE");
}
}*/
// ABC135B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] AnsN = new int[N];
for (int i = 0;i <N;i++)
{
AnsN[i] = i + 1;
}
int count = 0;
for(int i = 0;i < N;i++)
{
if (P[i] != AnsN[i])
{
count++;
}
}
if (count <= 2)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC135C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray();
/*int count = 0;
for (int i = N;i>0;i--)
{
var tempA = A[i] + A[i - 1];
if (tempA <= B[i - 1])
{
A[i - 1] = 0;
count += tempA;
}
else
{
if (A[i] <= B[i - 1])
{
A[i - 1] = tempA - B[i - 1];
count += B[i - 1];
}
else
{
count += B[i - 1];
}
}
}*/
/*int count = 0;
for (int i = 0;i < N;i++)
{
var tempA = A[i] + A[i + 1];
if (tempA <= B[i])
{
A[i + 1] = 0;
count += tempA;
}
else
{
if (B[i] >= A[i])
{
A[i + 1] = A[i + 1] - (B[i] - A[i]);
count += B[i];
}
else
{
count += B[i];
}
}
}
//このやり方
int count = 0;
for (int i = 0; i < N;i++)
{
List<int> temp = new List<int>();
temp.Add(A[i]);
temp.Add(B[i]);
count += temp.Min();
}
Console.WriteLine(count);
}*/
// ABC135D
// ABC127A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string inputstr = Console.ReadLine();
char[] temp = inputstr.ToCharArray();
temp[input[1]-1] = Char.ToLower(temp[input[1] -1]);
inputstr = new string(temp);
Console.WriteLine(inputstr);
}*/
// ABC35
/*static void Main()
{
string S = Console.ReadLine();
int T = int.Parse(Console.ReadLine());
int[] ans = { 0, 0 };
int count = 0;
for (int i = 0; i < S.Length;i++)
{
if (S[i] == 'U')
{
ans[1]++;
}
else if (S[i] == 'D')
{
ans[1]--;
}
else if (S[i] == 'R')
{
ans[0]++;
}
else if (S[i] == 'L')
{
ans[0]--;
}
else
{
count++;
}
}
List<int[]> answer = new List<int[]>();
answer.Add(ans);
answer.Add(ans);
answer.Add(ans);
answer.Add(ans);
foreach (int[] n in answer)
{
}
}*/
// ABC114A
/*static void Main()
{
int x = int.Parse(Console.ReadLine());
if (x == 7 || x == 5 || x == 3)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC121C
// TLE
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long M = input[1];
List<long[]> shop = new List<long[]>();
for (int i = 0;i < n;i++)
{
shop.Add(Console.ReadLine().Split().Select(long.Parse) .ToArray());
}
List<long[]> answer = new List<long[]>(Sort(shop));
long price = 0;
long count = 0;
foreach (long[] temp in answer)
{
var tempcount = count;
if (count + temp[1] <= M)
{
count += temp[1];
}
else
{
count = M;
}
price += (count-tempcount) * temp[0];
if (M<=count)
{
break;
}
}
Console.WriteLine(price);
}
static List<long[]> Sort(List<long[]> A)
{
for (int i = 0;i < A.Count;i++)
{
for (int j = A.Count-1;j >i;j-- )
{
if (A[j][0] < A[j-1][0])
{
var temp = A[j];
A[j] = A[j - 1];
A[j - 1] = temp;
}
}
}
return A;
}*/
// Sortはライブラリを使った方が早い
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long M = input[1];
List<long[]> shops = new List<long[]>();
for (int i = 0; i < n; i++)
{
shops.Add(Console.ReadLine().Split().Select(long.Parse).ToArray());
}
long count = 0;
long ans = 0;
foreach (long[] shop in shops.OrderBy(a => a[0]))
{
var i = Math.Min(M - count, shop[1]);
ans += shop[0] * i;
count += i;
if (count >= M)
{
break;
}
}
Console.WriteLine(ans);
}*/
// 120C
// TLE
/*static void Main()
{
/*string input = Console.ReadLine();
int len = input.Length;
int count = 0;
while (input.Contains("01") || input.Contains("10"))
{
input = input.Replace("01", "").Replace("10", "");
count += len - input.Length;
len = input.Length;
}
Console.WriteLine(count);
string s = Console.ReadLine();
int zero = s.Replace("1", "").Length;
int one = s.Replace("0", "").Length;
Console.WriteLine((zero < one ? zero : one) * 2);
}*/
// 119
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
List<int> goal = new List<int>();
List<int> list = new List<int>();
for (int i =1;i<=N-1;i++)
{
goal.Add(input[i]);
}
for (int i = 0;i<N;i++)
{
list.Add(int.Parse(Console.ReadLine()));
}
}*/
// 118C
// 37B
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long k = input[1];
List<long[]> list = new List<long[]>();
for (int i = 0;i < k;i++)
{
long[] temp = Console.ReadLine().Split().Select(long.Parse).ToArray();
list.Add(temp);
}
long[] Ans = new long[n];
foreach (long[] m in list)
{
for (int i =0;i < Ans.Length;i++)
{
if (m[0]-1 <= i && i <= m[1]-1)
{
Ans[i] = m[2];
}
}
}
foreach (int a in Ans)
{
Console.WriteLine(a);
}
}*/
//大手前プロコン2019
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
if (A + 0.5f >= B)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
}*/
// E
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = input[0];
long Q = input[1];
List<long> D = new List<long>();
for (long i = 0;i < N;i++)
{
D.Add(long.Parse(Console.ReadLine()));
}
List<long[]> TLR = new List<long[]>();
for (long i = 0;i < Q;i++)
{
TLR.Add(Console.ReadLine().Split().Select(long.Parse).ToArray());
}
foreach (long[] tlr in TLR)
{
var count = 0;
var tempara = new List<long>();
var a = tlr[0];
tempara.Add(a);
for (long i = 1;i <= N;i++)
{
if (Math.Abs(a - (-1 * i)) > D[(int)i - 1])
{
a = a - D[(int)i - 1];
}
else
{
a = -1*i;
}
tempara.Add(a);
}
foreach (long n in tempara)
{
if ( tlr[1]<= n && tlr[2] >= n)
{
count++;
}
}
Console.WriteLine(count);
}
}*/
// AtCoderBeginnerContest136
// 136A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int C = input[2];
var a = A - B;
var ans = C - a;
if (ans >= 0)
{
Console.WriteLine(ans);
}
else
{
Console.WriteLine("0");
}
}*/
// 136B
/*static void Main()
{
string N = Console.ReadLine();
int n = int.Parse(N);
int ocun = 0;
for (int i = 1; i<=n;i++)
{
if (i.ToString().Length % 2 == 1)
{
ocun++;
}
}
Console.WriteLine(ocun);
}*/
// 136C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] list = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count = 0;
int max = 0;
bool flag = false;
foreach (int a in list)
{
if (a >= max)
{
max = a;
}
else if (max - a >= 2)
{
flag = true;
break;
}
else { }
}
if (flag)
{
Console.WriteLine("No");
}
else
{
Console.WriteLine("Yes");
}
}*/
// 113C-ID
/*static void Main()
{
string S = Console.ReadLine();
Console.WriteLine(S.Length);
}*/
// 113A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
Console.WriteLine(A + (B/2));
}*/
// 112A
/*static void Main()
{
}*/
// 137A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
List<int> answer = new List<int>();
var ans1 = A + B;
answer.Add(ans1);
var ans2 = A - B;
answer.Add(ans2);
var ans3 = A * B;
answer.Add(ans3);
Console.WriteLine(answer.Max());
}*/
// 137B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int K = input[0];
int X = input[1];
for (int i = X - (K-1);i<= X + (K-1);i++)
{int
if (i >= -1000000 && i <= 1000000)
{
Console.Write(i+" ");
}
}
Console.WriteLine();
}*/
// 137C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<string[]> list = new List<string[]>();
for (int i = 0; i < N;i++)
{
list.Add(Console.ReadLine().Split());
}
foreach (string[] n in list)
{
Array.Sort(n);
}
long ans = 0;
for (int i = 0; i< list.Count;i++)
{
for (int j = i+1;j < list.Count;j++)
{
if (list[i].Equals(list[j]))
{
ans++;
}
}
}
Console.WriteLine(ans);
}*/
/*static void Main(string[] args)
{
int N = Convert.ToInt32(Console.ReadLine());
string[] S = new string[N];
for (var i = 0; i < N; i++)
{
char[] c = Console.ReadLine().ToCharArray();
Array.Sort(c);
S[i] = new string(c);
}
Dictionary<string, long> dict = new Dictionary<string, long>();
for (var i = 0; i < N; i++)
{
if (dict.ContainsKey(S[i]))
{
dict[S[i]]++;
}
else
{
dict[S[i]] = 1L;
}
}
long res = 0L;
foreach (var i in dict)
{
if (i.Value > 1)
{
res += i.Value * (i.Value - 1) / 2;
}
}
Console.WriteLine(res);
}*/
// 138A
static void Main() {
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a < 3200) {
Console.WriteLine("red");
} else {
Console.WriteLine(s);
}
}
// 138B
// 138C
}
}
// 125C難しい
/*namespace CSharp
{
class Program
{
static IEnumerable<long> EnumerateDivisors(long n)
{
for (long i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
yield return i;
if (n / i != i)
{
yield return n / i;
}
}
}
}
static void Main(string[] args)
{
ReadString();
long[] A = ReadLongArray();
long[] divisors = Enumerable.Concat(EnumerateDivisors(A[0]),
EnumerateDivisors(A[1])) .Distinct().ToArray(); long ans = divisors.Select(x =>
new { Value = x, Count = A.Count(v => v % x == 0) }) .Where(x => x.Count >=
A.Length - 1) .OrderByDescending(x => x.Value) .First().Value;
Console.WriteLine(ans);
}
#region Helpers
static int[] ReadIntArray() => Console.ReadLine().Split().Select(s =>
int.Parse(s)).ToArray(); static long[] ReadLongArray() =>
Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0,
count).Select(_ => int.Parse(Console.ReadLine())).ToArray(); static long[]
ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ =>
long.Parse(Console.ReadLine())).ToArray();
static string ReadString() => Console.ReadLine();
static int ReadInt() => int.Parse(Console.ReadLine());
static long ReadLong() => long.Parse(Console.ReadLine());
static void ReadInt(out int first)
{
var array = ReadIntArray();
first = array[0];
}
static void ReadInt(out int first, out int second)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
}
static void ReadInt(out int first, out int second, out int third)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadInt(out int first, out int second, out int third, out
int fourth)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
static void ReadLong(out long first)
{
var array = ReadLongArray();
first = array[0];
}
static void ReadLong(out long first, out long second)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
}
static void ReadLong(out long first, out long second, out long third)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadLong(out long first, out long second, out long third,
out long fourth)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
#endregion
}
}*/
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 228
| 2
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
double m = 0;
for (int i = 0; i < n; i++) {
m += 1 / a[i];
}
Console.WriteLine(1 / m);
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
double m = 0;
for (int i = 0; i < n; i++) {
m += 1d / a[i];
}
Console.WriteLine(1d / m);
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 250], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 250]]
| 8
| 105
| 4
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
int N = cin.ReadInt;
decimal sum = 0;
for (int i = 0; i < N; i++) {
decimal k = cin.ReadDecimal;
sum += sum + 1 / k;
}
WriteLine(Round(1 / sum, 5, MidpointRounding.AwayFromZero));
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public decimal ReadDecimal {
get { return decimal.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
int N = cin.ReadInt;
decimal sum = 0;
for (int i = 0; i < N; i++) {
decimal k = cin.ReadDecimal;
sum += 1 / k;
}
WriteLine(Round(1 / sum, 5, MidpointRounding.AwayFromZero));
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public decimal ReadDecimal {
get { return decimal.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
| 8
| 499
| 2
|
using System;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
var a = ab[0];
var b = ab[1];
int answer = 1;
for (int sum = a; sum < b; sum += a, b++)
answer++;
var writer =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(writer);
Console.WriteLine(answer);
Console.Out.Flush();
}
}
|
using System;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
var a = ab[0];
var b = ab[1];
int answer = 0;
for (int soc = 1; soc < b; soc += a, b++)
answer++;
var writer =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(writer);
Console.WriteLine(answer);
Console.Out.Flush();
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 11, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 31, 22]]
| 8
| 134
| 10
|
using System;
class main {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(" ");
int tap = int.Parse(s[0]) - 1;
int sockets = int.Parse(s[1]);
for (int i = 0; i != 0; i++) {
if (tap * i + 1 >= sockets) {
Console.Write(i);
break;
}
}
}
}
|
using System;
class main {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(" ");
int tap = int.Parse(s[0]) - 1;
int sockets = int.Parse(s[1]);
for (int i = 0; i != -1; i++) {
if (tap * i + 1 >= sockets) {
Console.Write(i);
break;
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 241, 0, 203]]
| 8
| 101
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long[] inputLongArray =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long A = inputLongArray[0];
long B = inputLongArray[1];
long result = A;
long cnt = 0;
if (B == 1) {
Console.WriteLine(0);
return;
}
while (true) {
if (B <= result) {
break;
}
cnt++;
result += (A - 1);
}
Console.WriteLine(cnt);
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long[] inputLongArray =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long A = inputLongArray[0];
long B = inputLongArray[1];
long result = A;
long cnt = 0;
if (B == 1) {
Console.WriteLine(0);
return;
}
while (true) {
cnt++;
if (B <= result) {
break;
}
result += (A - 1);
}
Console.WriteLine(cnt);
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
[["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 173
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest01_B {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = Convert.ToInt32(input[0]);
int B = Convert.ToInt32(input[1]);
int count = 1;
int sum = A;
while (sum < B) {
sum = sum + A - 1;
count = count + 1;
}
Console.WriteLine(count);
Console.Read();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest01_B {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = Convert.ToInt32(input[0]);
int B = Convert.ToInt32(input[1]);
int count = 0;
int sum = 1;
while (sum < B) {
sum = sum + A - 1;
count = count + 1;
}
Console.WriteLine(count);
Console.Read();
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
| 8
| 135
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc139 {
class Program {
public static int hantei(int x, int y) {
int count = 1;
for (int i = x; i < y; i = i + x - 1) {
count += 1;
}
return count;
}
static void Main(string[] args) {
string[] P = Console.ReadLine().Split(' ');
int A = int.Parse(P[0]);
int B = int.Parse(P[1]);
Console.WriteLine(hantei(A, B));
Console.Read();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc139 {
class Program {
public static int hantei(int x, int y) {
int count = 0;
for (int i = 1; i < y; i = i + x - 1) {
count += 1;
}
return count;
}
static void Main(string[] args) {
string[] P = Console.ReadLine().Split(' ');
int A = int.Parse(P[0]);
int B = int.Parse(P[1]);
Console.WriteLine(hantei(A, B));
Console.Read();
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 154
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc139_Virtual {
class Program {
static void Main(string[] args) {
string[] AB = Console.ReadLine().Split(' ');
int A = Convert.ToInt32(AB[0]);
int B = Convert.ToInt32(AB[1]);
int tap = A;
int get = 1;
while (tap < B) {
tap = tap + A;
get++;
}
Console.WriteLine(get);
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc139_Virtual {
class Program {
static void Main(string[] args) {
string[] AB = Console.ReadLine().Split(' ');
int A = Convert.ToInt32(AB[0]);
int B = Convert.ToInt32(AB[1]);
int tap = 1;
int get = 0;
while (tap < B) {
tap = tap + A - 1;
get++;
}
Console.WriteLine(get);
Console.ReadLine();
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 130
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoderB {
static void Main() {
int a;
int b;
{
var line = Console.ReadLine();
var words = line.Split(' ');
a = int.Parse(words[0]);
b = int.Parse(words[1]);
}
int nums = 1;
int count = 0;
while (nums >= b) {
count++;
nums += a - 1;
}
Console.WriteLine(count);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoderB {
static void Main() {
int a;
int b;
{
var line = Console.ReadLine();
var words = line.Split(' ');
a = int.Parse(words[0]);
b = int.Parse(words[1]);
}
int nums = 1;
int count = 0;
while (nums < b) {
count++;
nums += (a - 1);
}
Console.WriteLine(count);
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25]]
| 8
| 114
| 4
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
class DandA {
static void Main(string[] args) {
int[] ab = ReadLineIntArray();
int rtn = 1;
int n = ab[1] - ab[0];
while (n > 0) {
n -= ab[0] - 1;
rtn++;
}
Console.WriteLine(rtn);
}
static string Alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
static string[] strAry = new string[] { "L", "R", "U", "D" };
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private long ReadLineLong() { return long.Parse(Console.ReadLine()); }
static private double ReadLineDouble() {
return double.Parse(Console.ReadLine());
}
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private double[] ReadLineDoubleArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => double.Parse(a))
.ToArray();
}
static private decimal[] ReadLineDecimalArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => decimal.Parse(a))
.ToArray();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
static private string IntToNString(int x, int n) {
var nstring = "";
var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f" };
int r = 1;
int q = x;
while (q > 0) {
r = q % n;
nstring += numbers[r];
q = q / n;
}
return string.Join("", nstring.Reverse());
}
}
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
class DandA {
static void Main(string[] args) {
int[] ab = ReadLineIntArray();
int rtn = 0;
int n = ab[1] - 1;
while (n > 0) {
n -= ab[0] - 1;
rtn++;
}
Console.WriteLine(rtn);
}
static string Alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
static string[] strAry = new string[] { "L", "R", "U", "D" };
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private long ReadLineLong() { return long.Parse(Console.ReadLine()); }
static private double ReadLineDouble() {
return double.Parse(Console.ReadLine());
}
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private double[] ReadLineDoubleArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => double.Parse(a))
.ToArray();
}
static private decimal[] ReadLineDecimalArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => decimal.Parse(a))
.ToArray();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
static private string IntToNString(int x, int n) {
var nstring = "";
var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f" };
int r = 1;
int q = x;
while (q > 0) {
r = q % n;
nstring += numbers[r];
q = q / n;
}
return string.Join("", nstring.Reverse());
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 711
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]B - Power Socket
var line = ReadLine();
int A = line[0];
int B = line[1];
int sockets = A;
int i = 1;
while (sockets < B) {
sockets += A - 1;
i++;
}
Console.WriteLine(i);
}
static List<int> ReadLine() {
var line = Console.ReadLine();
var arr = line.Split(' ');
return arr.Select(x => int.Parse(x)).ToList();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]B - Power Socket
var line = ReadLine();
int A = line[0];
int B = line[1];
int sockets = 1;
int i = 0;
while (sockets < B) {
sockets += A - 1;
i++;
}
Console.WriteLine(i);
}
static List<int> ReadLine() {
var line = Console.ReadLine();
var arr = line.Split(' ');
return arr.Select(x => int.Parse(x)).ToList();
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 142
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Contest {
class ABC {
static void Main() { Solve(); }
private static void Solve() {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int a = 1;
int b = input[1];
int res = 1;
while (a < b) {
a += input[0] - 1;
res++;
}
Console.WriteLine(res);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Contest {
class ABC {
static void Main() { Solve(); }
private static void Solve() {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int a = 1;
int b = input[1];
int tap = 0;
while (a < b) {
a += input[0] - 1;
tap++;
}
Console.WriteLine(tap);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 118
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace AtcoderC {
class Program {
/*static void Main(string[] args)
{
}*/
// ABC132C
//全探索法
/*static void Main()
{
BigInteger N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int min = input.Min();
int max = input.Max();
int countARC = 0;
int countABC = 0;
int Answer = 0;
for (int i = min; i <= max; i++)
{
countABC = 0;
countARC = 0;
foreach (int n in input)
{
if (n > i)
{
countARC++;
}
else
{
countABC++;
}
}
if (countABC == countARC)
{
Answer++;
}
}
Console.WriteLine(Answer);
}*/
// 2回目
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(input);
int min = input[(N / 2) - 1];
int max = input[N / 2];
Console.WriteLine(max - min);
}*/
// ABC131C
//ユーグリッドの互除法の応用
/*static void Main()
{
BigInteger[] input =
Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A =
input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D =
input[3]; BigInteger ans = (B / C) + (B / D);
//最小公倍数
var ans2 = C * D / lcm(C, D);
BigInteger ans3 = B / ans2;
var BB = B - ans + ans3;
ans = (A - 1) / C + (A - 1) / D;
ans3 = (A - 1) / ans2;
var AA = (A - 1) - ans + ans3;
Console.WriteLine(BB - AA);
}
static public BigInteger lcm(BigInteger a, BigInteger b)
{
var r = a % b;
while (r != 0)
{
a = b;
b = r;
r = a % b;
}
return b;
}*/
// 129C
//動的計画法
// TLEになる時間がかかり過ぎる
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int> ttt = new List<int>();
for (int i = 0;i < M;i++)
{
var temp = int.Parse(Console.ReadLine());
ttt.Add(temp);
}
int[] dparray = new int[N+2];
dparray[N] = 1;
dparray[N - 1] = 1;
for (int i = N-1; i >= 0; i--)
{
if (ttt.Contains(i))
{
dparray[i] = 0;
}
dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007;
}
Console.WriteLine(dparray[0]);
}*/
// ABC128
/*static void Main()
{
}*/
// ABC134A
/*static void Main()
{
int r = int.Parse(Console.ReadLine());
var ans = 3 * r * r;
Console.WriteLine(ans);
}*/
// ABC134B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int D = input[1];
int count = 0;
int ans = N;
while (true)
{
ans = ans - (D * 2 + 1);
count++;
if (ans <= 0)
{
break;
}
}
Console.WriteLine(count);
}*/
// ABC134C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<int> array = new List<int>();
for (int i =0;i<N; i++)
{
array.Add(int.Parse(Console.ReadLine()));
}
List<int> ans = new List<int>();
int max = array.Max();
var temp = new List<int>();
foreach (int n in array)
{
temp.Add(n);
}
temp.Sort();
temp.Reverse();
int second = temp[1];
foreach (int nn in array)
{
if (nn == max)
{
Console.WriteLine(second);
}
else
{
Console.WriteLine(max);
}
}
}*/
// 134ABCD
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int count = 0;
int ans = 0;
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0;i<N;i++)
{
for (int j =0;j<N; j++)
{
if ((j+1)%(i+1)==0)
{
count += input[j];
}
}
if (count % 2 == input[i])
{
ans++;
}
count = 0;
}
if (ans != 0)
{
}
}*/
// AGC036
/*static void Main()
{
long S = long.Parse(Console.ReadLine());
long X1 = 1000000000;
long Y1 = 0;
/*while (true)
{
Y1 = S / X1 + S % X1;
}
Y1 = S / X1 + S % X1;
Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1);
/*int tempX = 0;
List<long> ss = new List<long>();
while (tempX < S)
{
var ans = S % tempX;
if (ans == 0)
{
ss.Add(ans);
}
tempX++;
}
Console.WriteLine(tempX);*/
/*long X1 = 0;
long Y1 = 1;
while (true)
{
X1 = S % Y1;
if (X1 <= 1000000000)
{
break;
}
Y1++;
}
Console.WriteLine("0 0 "+X1+" 0 0 "+Y1);
}*/
// ABC82A
/*static void Main()
{
double[] input =
Console.ReadLine().Split().Select(double.Parse).ToArray(); double a =
input[0]; double b = input[1]; double sum = (a + b) / 2;
Console.WriteLine(Math.Ceiling(sum));
}*/
// ABC128C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
int ans = 0;
List<int[]> K = new List<int[]>();
for (int i = 0;i<M;i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
K.Add(temp);
}
int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] light = new int[M];
for (int i = 0;i < Math.Pow(2,N);i++)
{
var isrow = 0;
var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000");
for (int j =0;j < M;j++)
{
var ison = 0;
for (int k = 0; k < K[j][0];k++)
{
var index = K[j][k] - 1;
if (temp[9-index] == '1')
{
ison++;
}
}
if (ison % 2 == P[j])
{
isrow++;
}
else
{
break;
}
}
if (isrow == M)
{
ans++;
}
}
Console.WriteLine(ans);*/
/*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int a = input[0];
int b = input[1];
var temp = a * b % 2;
if (temp == 0)
{
Console.WriteLine("even");
}
else
{
Console.WriteLine("odd");
}
}*/
// ABC127C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
if (M == 1)
{
Console.WriteLine(N);
}
else
{
List<int> card = new List<int>();
for (int i = gate[0][0]; i <= gate[0][1]; i++)
{
card.Add(i);
}
for (int j = 1; j < gate.Count; j++)
{
List<int> ans = new List<int>();
var count = 0;
for (int i = gate[j][0]; i <= gate[j][1]; i++)
{
if (card.Contains(i))
{
count++;
ans.Add(i);
}
}
if (count == 0)
{
break;
}
card = new List<int>(ans);
}
Console.WriteLine(card.Count());
}
}*/
// 127C Revenge TLE
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
int Ans = 0;
for (int i =1;i<=N;i++)
{
var count = 0;
for (int j = 0;j < gate.Count;j++)
{
if (gate[j][0] <= i && i <= gate[j][1])
{
count++;
}
}
if (count == gate.Count)
{
Ans++;
}
}
Console.WriteLine(Ans);
}*/
// 127C RevengeVer2
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
List<int> Max = new List<int>();
List<int> Min = new List<int>();
for (int i =0;i< M;i++)
{
Max.Add(gate[i][1]);
Min.Add(gate[i][0]);
}
int max = Max.Min();
int min = Min.Max();
if (min <= max)
{
Console.WriteLine(max - min + 1);
}
else
{
Console.WriteLine("0");
}
}*/
// ABC126C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
double ans = 0.0;
for (int i = 1; i<= N;i++)
{
double tempP = (double)1 / N;
int point = i;
while (point<M)
{
tempP = tempP * 1 / 2;
point *= 2;
}
ans += tempP;
}
Console.WriteLine(ans);
}*/
// ABC125C ユーグリッド互除法
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(A);
int lcmr, lcml = 0;
List<int> answer = new List<int>();
for (int i =0;i<A.Length;i++)
{
lcmr = 0;
for (int x = 0;x < i;x++)
{
if (lcmr - A[x] >= 0)
{
lcmr = lcm(lcmr, A[x]);
}
else
{
lcmr = lcm(A[x], lcmr);
}
}
lcml = 0;
for (int y = i+1; y < A.Length; y++)
{
if (lcml - A[y] >= 0)
{
lcml = lcm(lcml, A[y]);
}
else
{
lcml = lcm(A[y],lcml);
}
}
var tempans = 0;
if (lcmr > lcml)
{
tempans = lcm(lcmr, lcml);
}
else
{
tempans = lcm(lcml, lcmr);
}
answer.Add(tempans);
}
Console.WriteLine(answer.Max());
}
static public int lcm(int a, int b)
{
if (b == 0)
{
return a;
}
var r = a % b;
while (r != 0)
{
a = b;
b = r;
r = a % b;
}
return b;
}*/
// 124C
/*static void Main()
{
string inputstr = Console.ReadLine();
int count = 0;
if (inputstr[0] == '0')
{
for (int i = 0; i < inputstr.Length; i++)
{
if (i % 2 == 0)
{
if (inputstr[i] == '1')
{
count++;
}
}
else
{
if (inputstr[i] == '0')
{
count++;
}
}
}
}
else
{
for (int i = 0; i < inputstr.Length; i++)
{
if (i % 2 == 1)
{
if (inputstr[i] == '1')
{
count++;
}
}
else
{
if (inputstr[i] == '0')
{
count++;
}
}
}
}
Console.WriteLine(count);
}*/
// 123C
/*static void Main()
{
double N = double.Parse(Console.ReadLine());
List<double> city = new List<double>();
for (int i = 0; i < 5; i++)
{
city.Add(double.Parse(Console.ReadLine()));
}
var ans = Math.Ceiling(N / city.Min()) + 4;
Console.WriteLine(ans);
}*/
// 82C
/*static void Main()
{
double[] input =
Console.ReadLine().Split().Select(double.Parse).ToArray(); double a =
input[0]; double b = input[1]; double answer = (a + b) / 2;
Console.WriteLine(Math.Ceiling(answer));
}*/
// 128B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int P = input[1];
var ans = (P + A * 3) / 2;
Console.WriteLine(ans);
int a,b
cin << a << b;
cout >> (P + A * 3) / 2 >> endl;
}*/
// 119A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
if (B % A == 0)
{
Console.WriteLine(A + B);
}
else
{
Console.WriteLine(B-A);
}
}*/
// 116A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int C = input[2];
Console.WriteLine((A*B)/2);
}*/
// ABC31B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = int.Parse(Console.ReadLine());
List<int> array = new List<int>();
for (int i =0;i<N;i++)
{
array.Add(int.Parse(Console.ReadLine()));
}
foreach (int a in array)
{
if (a < input[0])
{
Console.WriteLine(input[0] - a);
}
else if (input[1] < a)
{
Console.WriteLine("-1");
}
else
{
Console.WriteLine("0");
}
}
}*/
// ABC36B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<string> map = new List<string>();
for (int i =0;i< N;i++)
{
map.Add(Console.ReadLine());
}
List<string> ans = new List<string>();
for(int j = 0; j < N;j++)
{
var temp = "";
for (int i = N-1; i >= 0; i--)
{
temp += map[i][j];
}
ans.Add(temp);
}
foreach (string a in ans)
{
Console.WriteLine(a);
}
}*/
// ABC40B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int A = 0;
int temp = N;
if (N == 1)
{
Console.WriteLine("0");
}
else
{
while (true)
{
double root = Math.Sqrt(N);
if (root != (int)root)
{
N--;
}
else
{
A = (int)root;
break;
}
}
List<int> answer = new List<int>();
bool flag = false;
while (A > 0)
{
var a = A;
while (A * a <= temp)
{
var ans = temp - (A * a) + Math.Abs(A - a);
if (ans == 0)
{
flag = true;
break;
}
a++;
answer.Add(ans);
}
if (flag == true)
{
break;
}
A--;
}
if (flag)
{
Console.WriteLine("0");
}
else
{
Console.WriteLine(answer.Min());
}
}
}*/
// ABC122C
// TLE
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string S = Console.ReadLine();
List<int[]> array = new List<int[]>();
for (int i = 0; i < input[1]; i++)
{
array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
List<int> answer = new List<int>();
foreach (int[] n in array)
{
var tempstr = S.Substring(n[0]-1,n[1]-n[0]+1);
var count = tempstr.Length - tempstr.Replace("AC","").Length;
var ans = count / 2;
answer.Add(ans);
}
foreach (int a in answer)
{
Console.WriteLine(a);
}
}*/
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string S = Console.ReadLine();
List<int[]> array = new List<int[]>();
for (int i = 0; i < input[1]; i++)
{
array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
for (int i = 0;i < S.Length-1;i++)
{
if (S[i] == 'A')
{
if (S[i + 1] == 'C')
{
S = S.Replace(S[i],'a');
}
}
}
int count = 0;
List<int> ansstr = new List<int>();
for (int i = 0; i < S.Length;i++)
{
count = 0;
for (int j = 0;j <= i;j++)
{
if (S[j] == 'a')
{
count++;
}
}
ansstr.Add(count);
}
List<int> anss = new List<int>();
for (int i = 0; i < input[1];i++)
{
anss.Add(ansstr[array[i][1]-2] - ansstr[array[i][0]-1]);
}
foreach (int a in anss)
{
Console.WriteLine(a);
}
}*/
// ABC39B
/*static void Main()
{
int X = int.Parse(Console.ReadLine());
var ans = Math.Sqrt(X);
var ans2 = Math.Sqrt(ans);
Console.WriteLine(ans2);
}*/
// ABC38B
/*static void Main()
{
int[] input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] input2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
bool flag1 = false;
foreach (int a in input1)
{
foreach (int b in input2)
{
if (a == b)
{
flag1 = true;
}
}
}
if (flag1 == true)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC35B
/*static void Main()
{
string S = Console.ReadLine();
int T = int.Parse(Console.ReadLine());
int[] pos = { 0, 0 };
foreach (char a in S)
{
}
}*/
// ABC34B
/*static void Main()
{
}*/
//技術ProgramContest4Day1
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
}*/
// ABC135A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
var temp = B - A;
if (temp % 2 == 0)
{
Console.WriteLine(A + (temp/2));
}
else
{
Console.WriteLine("IMPOSSIBLE");
}
}*/
// ABC135B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] AnsN = new int[N];
for (int i = 0;i <N;i++)
{
AnsN[i] = i + 1;
}
int count = 0;
for(int i = 0;i < N;i++)
{
if (P[i] != AnsN[i])
{
count++;
}
}
if (count <= 2)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC135C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray();
/*int count = 0;
for (int i = N;i>0;i--)
{
var tempA = A[i] + A[i - 1];
if (tempA <= B[i - 1])
{
A[i - 1] = 0;
count += tempA;
}
else
{
if (A[i] <= B[i - 1])
{
A[i - 1] = tempA - B[i - 1];
count += B[i - 1];
}
else
{
count += B[i - 1];
}
}
}*/
/*int count = 0;
for (int i = 0;i < N;i++)
{
var tempA = A[i] + A[i + 1];
if (tempA <= B[i])
{
A[i + 1] = 0;
count += tempA;
}
else
{
if (B[i] >= A[i])
{
A[i + 1] = A[i + 1] - (B[i] - A[i]);
count += B[i];
}
else
{
count += B[i];
}
}
}
//このやり方
int count = 0;
for (int i = 0; i < N;i++)
{
List<int> temp = new List<int>();
temp.Add(A[i]);
temp.Add(B[i]);
count += temp.Min();
}
Console.WriteLine(count);
}*/
// ABC135D
// ABC127A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string inputstr = Console.ReadLine();
char[] temp = inputstr.ToCharArray();
temp[input[1]-1] = Char.ToLower(temp[input[1] -1]);
inputstr = new string(temp);
Console.WriteLine(inputstr);
}*/
// ABC35
/*static void Main()
{
string S = Console.ReadLine();
int T = int.Parse(Console.ReadLine());
int[] ans = { 0, 0 };
int count = 0;
for (int i = 0; i < S.Length;i++)
{
if (S[i] == 'U')
{
ans[1]++;
}
else if (S[i] == 'D')
{
ans[1]--;
}
else if (S[i] == 'R')
{
ans[0]++;
}
else if (S[i] == 'L')
{
ans[0]--;
}
else
{
count++;
}
}
List<int[]> answer = new List<int[]>();
answer.Add(ans);
answer.Add(ans);
answer.Add(ans);
answer.Add(ans);
foreach (int[] n in answer)
{
}
}*/
// ABC114A
/*static void Main()
{
int x = int.Parse(Console.ReadLine());
if (x == 7 || x == 5 || x == 3)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC121C
// TLE
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long M = input[1];
List<long[]> shop = new List<long[]>();
for (int i = 0;i < n;i++)
{
shop.Add(Console.ReadLine().Split().Select(long.Parse) .ToArray());
}
List<long[]> answer = new List<long[]>(Sort(shop));
long price = 0;
long count = 0;
foreach (long[] temp in answer)
{
var tempcount = count;
if (count + temp[1] <= M)
{
count += temp[1];
}
else
{
count = M;
}
price += (count-tempcount) * temp[0];
if (M<=count)
{
break;
}
}
Console.WriteLine(price);
}
static List<long[]> Sort(List<long[]> A)
{
for (int i = 0;i < A.Count;i++)
{
for (int j = A.Count-1;j >i;j-- )
{
if (A[j][0] < A[j-1][0])
{
var temp = A[j];
A[j] = A[j - 1];
A[j - 1] = temp;
}
}
}
return A;
}*/
// Sortはライブラリを使った方が早い
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long M = input[1];
List<long[]> shops = new List<long[]>();
for (int i = 0; i < n; i++)
{
shops.Add(Console.ReadLine().Split().Select(long.Parse).ToArray());
}
long count = 0;
long ans = 0;
foreach (long[] shop in shops.OrderBy(a => a[0]))
{
var i = Math.Min(M - count, shop[1]);
ans += shop[0] * i;
count += i;
if (count >= M)
{
break;
}
}
Console.WriteLine(ans);
}*/
// 120C
// TLE
/*static void Main()
{
/*string input = Console.ReadLine();
int len = input.Length;
int count = 0;
while (input.Contains("01") || input.Contains("10"))
{
input = input.Replace("01", "").Replace("10", "");
count += len - input.Length;
len = input.Length;
}
Console.WriteLine(count);
string s = Console.ReadLine();
int zero = s.Replace("1", "").Length;
int one = s.Replace("0", "").Length;
Console.WriteLine((zero < one ? zero : one) * 2);
}*/
// 119
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
List<int> goal = new List<int>();
List<int> list = new List<int>();
for (int i =1;i<=N-1;i++)
{
goal.Add(input[i]);
}
for (int i = 0;i<N;i++)
{
list.Add(int.Parse(Console.ReadLine()));
}
}*/
// 118C
// 37B
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long k = input[1];
List<long[]> list = new List<long[]>();
for (int i = 0;i < k;i++)
{
long[] temp = Console.ReadLine().Split().Select(long.Parse).ToArray();
list.Add(temp);
}
long[] Ans = new long[n];
foreach (long[] m in list)
{
for (int i =0;i < Ans.Length;i++)
{
if (m[0]-1 <= i && i <= m[1]-1)
{
Ans[i] = m[2];
}
}
}
foreach (int a in Ans)
{
Console.WriteLine(a);
}
}*/
//大手前プロコン2019
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
if (A + 0.5f >= B)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
}*/
// E
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = input[0];
long Q = input[1];
List<long> D = new List<long>();
for (long i = 0;i < N;i++)
{
D.Add(long.Parse(Console.ReadLine()));
}
List<long[]> TLR = new List<long[]>();
for (long i = 0;i < Q;i++)
{
TLR.Add(Console.ReadLine().Split().Select(long.Parse).ToArray());
}
foreach (long[] tlr in TLR)
{
var count = 0;
var tempara = new List<long>();
var a = tlr[0];
tempara.Add(a);
for (long i = 1;i <= N;i++)
{
if (Math.Abs(a - (-1 * i)) > D[(int)i - 1])
{
a = a - D[(int)i - 1];
}
else
{
a = -1*i;
}
tempara.Add(a);
}
foreach (long n in tempara)
{
if ( tlr[1]<= n && tlr[2] >= n)
{
count++;
}
}
Console.WriteLine(count);
}
}*/
// AtCoderBeginnerContest136
// 136A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int C = input[2];
var a = A - B;
var ans = C - a;
if (ans >= 0)
{
Console.WriteLine(ans);
}
else
{
Console.WriteLine("0");
}
}*/
// 136B
/*static void Main()
{
string N = Console.ReadLine();
int n = int.Parse(N);
int ocun = 0;
for (int i = 1; i<=n;i++)
{
if (i.ToString().Length % 2 == 1)
{
ocun++;
}
}
Console.WriteLine(ocun);
}*/
// 136C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] list = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count = 0;
int max = 0;
bool flag = false;
foreach (int a in list)
{
if (a >= max)
{
max = a;
}
else if (max - a >= 2)
{
flag = true;
break;
}
else { }
}
if (flag)
{
Console.WriteLine("No");
}
else
{
Console.WriteLine("Yes");
}
}*/
// 113C-ID
/*static void Main()
{
string S = Console.ReadLine();
Console.WriteLine(S.Length);
}*/
// 113A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
Console.WriteLine(A + (B/2));
}*/
// 112A
/*static void Main()
{
}*/
// 137A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
List<int> answer = new List<int>();
var ans1 = A + B;
answer.Add(ans1);
var ans2 = A - B;
answer.Add(ans2);
var ans3 = A * B;
answer.Add(ans3);
Console.WriteLine(answer.Max());
}*/
// 137B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int K = input[0];
int X = input[1];
for (int i = X - (K-1);i<= X + (K-1);i++)
{int
if (i >= -1000000 && i <= 1000000)
{
Console.Write(i+" ");
}
}
Console.WriteLine();
}*/
// 137C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<string[]> list = new List<string[]>();
for (int i = 0; i < N;i++)
{
list.Add(Console.ReadLine().Split());
}
foreach (string[] n in list)
{
Array.Sort(n);
}
long ans = 0;
for (int i = 0; i< list.Count;i++)
{
for (int j = i+1;j < list.Count;j++)
{
if (list[i].Equals(list[j]))
{
ans++;
}
}
}
Console.WriteLine(ans);
}*/
/*static void Main(string[] args)
{
int N = Convert.ToInt32(Console.ReadLine());
string[] S = new string[N];
for (var i = 0; i < N; i++)
{
char[] c = Console.ReadLine().ToCharArray();
Array.Sort(c);
S[i] = new string(c);
}
Dictionary<string, long> dict = new Dictionary<string, long>();
for (var i = 0; i < N; i++)
{
if (dict.ContainsKey(S[i]))
{
dict[S[i]]++;
}
else
{
dict[S[i]] = 1L;
}
}
long res = 0L;
foreach (var i in dict)
{
if (i.Value > 1)
{
res += i.Value * (i.Value - 1) / 2;
}
}
Console.WriteLine(res);
}*/
// 138A
/*static void Main()
{
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a < 3200)
{
Console.WriteLine("red");
}
else
{
Console.WriteLine(s);
}
}*/
// 138B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
double[] A = Console.ReadLine().Split().Select(double.Parse).ToArray();
double ans = 0;
for (int i = 0;i<A.Length;i++)
{
ans += 1 / A[i];
}
Console.WriteLine(1/ans);
}*/
// 138C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
double[] v = Console.ReadLine().Split().Select(double.Parse).ToArray();
double ans = 0;
Array.Sort(v);
ans = (v[0] + v[1]) / 2;
for (int i = 2; i < N;i++)
{
ans = (ans + v[i]) / 2;
}
Console.WriteLine(ans);
}*/
// 138D
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int Q = input[1];
List<Data> datalist = new List<Data>();
List<int[]> listQ = new List<int[]>();
for (int i = 0; i < N-1;i++)
{
Data data = new Data();
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
data.a = temp[0];
data.b = temp[1];
datalist.Add(data);
}
datalist = datalist.OrderBy(n => n.a).OrderBy(m => m.b).ToList();
for (int i = 0;i < Q;i++)
{
listQ.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
int[] Answer = new int[datalist[datalist.Count()].b];
var tempA = 0;
foreach (Data aa in datalist)
{
if (aa.a > tempA)
{
tempA = aa.a;
}
}
foreach (int[] temp in listQ)
{
if (temp[0] < tempA)
{
for (int i = temp[0]; i < Answer.Length; i++)
{
Answer[i] += temp[1];
}
}
else
{
Answer[temp[0]] += Answer[1];
}
}
foreach (int a in Answer)
{
Console.Write(a);
}
Console.WriteLine();
}*/
//最強プログラマ―選手権
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int M = input[0];
int D = input[1];
int ans = 0;
for (int i = 1;i <= M;i++)
{
for (int j = 1; j <= D; j++)
{
int d1 = j / 10;
int d2 = j % 10;
if (d1 >= 2 && d2 >= 2)
{
var temp = d1 * d2;
if (temp == i)
{
ans++;
}
}
}
}
Console.WriteLine(ans);
}*/
// B
/*static void Main()
{
var tem = 1000000007;
var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
var N = input[0];
var K = input[1];
var array = Console.ReadLine().Split().Select(long.Parse).ToArray();
var invert = new long[N];
for (int i =0;i<N;i++)
{
for (int j = i+1;j < N;j++)
{
if (array[i] > array[j])
{
invert[i]++;
}
}
}
var less = new long[N];
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (array[i] > array[j])
{
less[i]++;
}
}
}
long ans = 0;
for (int i = 0;i < N;i++)
{
ans = (ans + (invert[i] * K) % tem) % tem;
ans = (ans + (less[i] * ((K * (K-1))/ 2 % tem)) % tem) % tem;
//K*(K-1)/2
}
Console.WriteLine(ans %tem);
}*/
// 139A
/*static void Main()
{
string input = Console.ReadLine();
string input2 = Console.ReadLine();
int ans = 0;
for (int i = 0;i < input.Length;i++)
{
if (input[i] == input2[i])
{
ans++;
}
}
Console.WriteLine(ans);
}*/
// 139B
static void Main() {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
var ans = 0;
var temp = 1;
while (temp < B) {
--temp;
temp += A;
++ans;
}
Console.WriteLine(temp);
}
// 139C
/*static void Main()
{
}*/
}
/*class Data
{
public int a { get; set; }
public int b { get; set; }
}*/
}
// 125C難しい
/*namespace CSharp
{
class Program
{
static IEnumerable<long> EnumerateDivisors(long n)
{
for (long i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
yield return i;
if (n / i != i)
{
yield return n / i;
}
}
}
}
static void Main(string[] args)
{
ReadString();
long[] A = ReadLongArray();
long[] divisors = Enumerable.Concat(EnumerateDivisors(A[0]),
EnumerateDivisors(A[1])) .Distinct().ToArray(); long ans = divisors.Select(x =>
new { Value = x, Count = A.Count(v => v % x == 0) }) .Where(x => x.Count >=
A.Length - 1) .OrderByDescending(x => x.Value) .First().Value;
Console.WriteLine(ans);
}
#region Helpers
static int[] ReadIntArray() => Console.ReadLine().Split().Select(s =>
int.Parse(s)).ToArray(); static long[] ReadLongArray() =>
Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0,
count).Select(_ => int.Parse(Console.ReadLine())).ToArray(); static long[]
ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ =>
long.Parse(Console.ReadLine())).ToArray();
static string ReadString() => Console.ReadLine();
static int ReadInt() => int.Parse(Console.ReadLine());
static long ReadLong() => long.Parse(Console.ReadLine());
static void ReadInt(out int first)
{
var array = ReadIntArray();
first = array[0];
}
static void ReadInt(out int first, out int second)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
}
static void ReadInt(out int first, out int second, out int third)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadInt(out int first, out int second, out int third, out
int fourth)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
static void ReadLong(out long first)
{
var array = ReadLongArray();
first = array[0];
}
static void ReadLong(out long first, out long second)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
}
static void ReadLong(out long first, out long second, out long third)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadLong(out long first, out long second, out long third,
out long fourth)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
#endregion
}
}*/
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace AtcoderC {
class Program {
/*static void Main(string[] args)
{
}*/
// ABC132C
//全探索法
/*static void Main()
{
BigInteger N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int min = input.Min();
int max = input.Max();
int countARC = 0;
int countABC = 0;
int Answer = 0;
for (int i = min; i <= max; i++)
{
countABC = 0;
countARC = 0;
foreach (int n in input)
{
if (n > i)
{
countARC++;
}
else
{
countABC++;
}
}
if (countABC == countARC)
{
Answer++;
}
}
Console.WriteLine(Answer);
}*/
// 2回目
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(input);
int min = input[(N / 2) - 1];
int max = input[N / 2];
Console.WriteLine(max - min);
}*/
// ABC131C
//ユーグリッドの互除法の応用
/*static void Main()
{
BigInteger[] input =
Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A =
input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D =
input[3]; BigInteger ans = (B / C) + (B / D);
//最小公倍数
var ans2 = C * D / lcm(C, D);
BigInteger ans3 = B / ans2;
var BB = B - ans + ans3;
ans = (A - 1) / C + (A - 1) / D;
ans3 = (A - 1) / ans2;
var AA = (A - 1) - ans + ans3;
Console.WriteLine(BB - AA);
}
static public BigInteger lcm(BigInteger a, BigInteger b)
{
var r = a % b;
while (r != 0)
{
a = b;
b = r;
r = a % b;
}
return b;
}*/
// 129C
//動的計画法
// TLEになる時間がかかり過ぎる
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int> ttt = new List<int>();
for (int i = 0;i < M;i++)
{
var temp = int.Parse(Console.ReadLine());
ttt.Add(temp);
}
int[] dparray = new int[N+2];
dparray[N] = 1;
dparray[N - 1] = 1;
for (int i = N-1; i >= 0; i--)
{
if (ttt.Contains(i))
{
dparray[i] = 0;
}
dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007;
}
Console.WriteLine(dparray[0]);
}*/
// ABC128
/*static void Main()
{
}*/
// ABC134A
/*static void Main()
{
int r = int.Parse(Console.ReadLine());
var ans = 3 * r * r;
Console.WriteLine(ans);
}*/
// ABC134B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int D = input[1];
int count = 0;
int ans = N;
while (true)
{
ans = ans - (D * 2 + 1);
count++;
if (ans <= 0)
{
break;
}
}
Console.WriteLine(count);
}*/
// ABC134C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<int> array = new List<int>();
for (int i =0;i<N; i++)
{
array.Add(int.Parse(Console.ReadLine()));
}
List<int> ans = new List<int>();
int max = array.Max();
var temp = new List<int>();
foreach (int n in array)
{
temp.Add(n);
}
temp.Sort();
temp.Reverse();
int second = temp[1];
foreach (int nn in array)
{
if (nn == max)
{
Console.WriteLine(second);
}
else
{
Console.WriteLine(max);
}
}
}*/
// 134ABCD
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int count = 0;
int ans = 0;
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0;i<N;i++)
{
for (int j =0;j<N; j++)
{
if ((j+1)%(i+1)==0)
{
count += input[j];
}
}
if (count % 2 == input[i])
{
ans++;
}
count = 0;
}
if (ans != 0)
{
}
}*/
// AGC036
/*static void Main()
{
long S = long.Parse(Console.ReadLine());
long X1 = 1000000000;
long Y1 = 0;
/*while (true)
{
Y1 = S / X1 + S % X1;
}
Y1 = S / X1 + S % X1;
Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1);
/*int tempX = 0;
List<long> ss = new List<long>();
while (tempX < S)
{
var ans = S % tempX;
if (ans == 0)
{
ss.Add(ans);
}
tempX++;
}
Console.WriteLine(tempX);*/
/*long X1 = 0;
long Y1 = 1;
while (true)
{
X1 = S % Y1;
if (X1 <= 1000000000)
{
break;
}
Y1++;
}
Console.WriteLine("0 0 "+X1+" 0 0 "+Y1);
}*/
// ABC82A
/*static void Main()
{
double[] input =
Console.ReadLine().Split().Select(double.Parse).ToArray(); double a =
input[0]; double b = input[1]; double sum = (a + b) / 2;
Console.WriteLine(Math.Ceiling(sum));
}*/
// ABC128C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
int ans = 0;
List<int[]> K = new List<int[]>();
for (int i = 0;i<M;i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
K.Add(temp);
}
int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] light = new int[M];
for (int i = 0;i < Math.Pow(2,N);i++)
{
var isrow = 0;
var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000");
for (int j =0;j < M;j++)
{
var ison = 0;
for (int k = 0; k < K[j][0];k++)
{
var index = K[j][k] - 1;
if (temp[9-index] == '1')
{
ison++;
}
}
if (ison % 2 == P[j])
{
isrow++;
}
else
{
break;
}
}
if (isrow == M)
{
ans++;
}
}
Console.WriteLine(ans);*/
/*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int a = input[0];
int b = input[1];
var temp = a * b % 2;
if (temp == 0)
{
Console.WriteLine("even");
}
else
{
Console.WriteLine("odd");
}
}*/
// ABC127C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
if (M == 1)
{
Console.WriteLine(N);
}
else
{
List<int> card = new List<int>();
for (int i = gate[0][0]; i <= gate[0][1]; i++)
{
card.Add(i);
}
for (int j = 1; j < gate.Count; j++)
{
List<int> ans = new List<int>();
var count = 0;
for (int i = gate[j][0]; i <= gate[j][1]; i++)
{
if (card.Contains(i))
{
count++;
ans.Add(i);
}
}
if (count == 0)
{
break;
}
card = new List<int>(ans);
}
Console.WriteLine(card.Count());
}
}*/
// 127C Revenge TLE
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
int Ans = 0;
for (int i =1;i<=N;i++)
{
var count = 0;
for (int j = 0;j < gate.Count;j++)
{
if (gate[j][0] <= i && i <= gate[j][1])
{
count++;
}
}
if (count == gate.Count)
{
Ans++;
}
}
Console.WriteLine(Ans);
}*/
// 127C RevengeVer2
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
List<int[]> gate = new List<int[]>();
for (int i = 0; i < M; i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
gate.Add(temp);
}
List<int> Max = new List<int>();
List<int> Min = new List<int>();
for (int i =0;i< M;i++)
{
Max.Add(gate[i][1]);
Min.Add(gate[i][0]);
}
int max = Max.Min();
int min = Min.Max();
if (min <= max)
{
Console.WriteLine(max - min + 1);
}
else
{
Console.WriteLine("0");
}
}*/
// ABC126C
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
double ans = 0.0;
for (int i = 1; i<= N;i++)
{
double tempP = (double)1 / N;
int point = i;
while (point<M)
{
tempP = tempP * 1 / 2;
point *= 2;
}
ans += tempP;
}
Console.WriteLine(ans);
}*/
// ABC125C ユーグリッド互除法
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(A);
int lcmr, lcml = 0;
List<int> answer = new List<int>();
for (int i =0;i<A.Length;i++)
{
lcmr = 0;
for (int x = 0;x < i;x++)
{
if (lcmr - A[x] >= 0)
{
lcmr = lcm(lcmr, A[x]);
}
else
{
lcmr = lcm(A[x], lcmr);
}
}
lcml = 0;
for (int y = i+1; y < A.Length; y++)
{
if (lcml - A[y] >= 0)
{
lcml = lcm(lcml, A[y]);
}
else
{
lcml = lcm(A[y],lcml);
}
}
var tempans = 0;
if (lcmr > lcml)
{
tempans = lcm(lcmr, lcml);
}
else
{
tempans = lcm(lcml, lcmr);
}
answer.Add(tempans);
}
Console.WriteLine(answer.Max());
}
static public int lcm(int a, int b)
{
if (b == 0)
{
return a;
}
var r = a % b;
while (r != 0)
{
a = b;
b = r;
r = a % b;
}
return b;
}*/
// 124C
/*static void Main()
{
string inputstr = Console.ReadLine();
int count = 0;
if (inputstr[0] == '0')
{
for (int i = 0; i < inputstr.Length; i++)
{
if (i % 2 == 0)
{
if (inputstr[i] == '1')
{
count++;
}
}
else
{
if (inputstr[i] == '0')
{
count++;
}
}
}
}
else
{
for (int i = 0; i < inputstr.Length; i++)
{
if (i % 2 == 1)
{
if (inputstr[i] == '1')
{
count++;
}
}
else
{
if (inputstr[i] == '0')
{
count++;
}
}
}
}
Console.WriteLine(count);
}*/
// 123C
/*static void Main()
{
double N = double.Parse(Console.ReadLine());
List<double> city = new List<double>();
for (int i = 0; i < 5; i++)
{
city.Add(double.Parse(Console.ReadLine()));
}
var ans = Math.Ceiling(N / city.Min()) + 4;
Console.WriteLine(ans);
}*/
// 82C
/*static void Main()
{
double[] input =
Console.ReadLine().Split().Select(double.Parse).ToArray(); double a =
input[0]; double b = input[1]; double answer = (a + b) / 2;
Console.WriteLine(Math.Ceiling(answer));
}*/
// 128B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int P = input[1];
var ans = (P + A * 3) / 2;
Console.WriteLine(ans);
int a,b
cin << a << b;
cout >> (P + A * 3) / 2 >> endl;
}*/
// 119A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
if (B % A == 0)
{
Console.WriteLine(A + B);
}
else
{
Console.WriteLine(B-A);
}
}*/
// 116A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int C = input[2];
Console.WriteLine((A*B)/2);
}*/
// ABC31B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = int.Parse(Console.ReadLine());
List<int> array = new List<int>();
for (int i =0;i<N;i++)
{
array.Add(int.Parse(Console.ReadLine()));
}
foreach (int a in array)
{
if (a < input[0])
{
Console.WriteLine(input[0] - a);
}
else if (input[1] < a)
{
Console.WriteLine("-1");
}
else
{
Console.WriteLine("0");
}
}
}*/
// ABC36B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<string> map = new List<string>();
for (int i =0;i< N;i++)
{
map.Add(Console.ReadLine());
}
List<string> ans = new List<string>();
for(int j = 0; j < N;j++)
{
var temp = "";
for (int i = N-1; i >= 0; i--)
{
temp += map[i][j];
}
ans.Add(temp);
}
foreach (string a in ans)
{
Console.WriteLine(a);
}
}*/
// ABC40B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int A = 0;
int temp = N;
if (N == 1)
{
Console.WriteLine("0");
}
else
{
while (true)
{
double root = Math.Sqrt(N);
if (root != (int)root)
{
N--;
}
else
{
A = (int)root;
break;
}
}
List<int> answer = new List<int>();
bool flag = false;
while (A > 0)
{
var a = A;
while (A * a <= temp)
{
var ans = temp - (A * a) + Math.Abs(A - a);
if (ans == 0)
{
flag = true;
break;
}
a++;
answer.Add(ans);
}
if (flag == true)
{
break;
}
A--;
}
if (flag)
{
Console.WriteLine("0");
}
else
{
Console.WriteLine(answer.Min());
}
}
}*/
// ABC122C
// TLE
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string S = Console.ReadLine();
List<int[]> array = new List<int[]>();
for (int i = 0; i < input[1]; i++)
{
array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
List<int> answer = new List<int>();
foreach (int[] n in array)
{
var tempstr = S.Substring(n[0]-1,n[1]-n[0]+1);
var count = tempstr.Length - tempstr.Replace("AC","").Length;
var ans = count / 2;
answer.Add(ans);
}
foreach (int a in answer)
{
Console.WriteLine(a);
}
}*/
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string S = Console.ReadLine();
List<int[]> array = new List<int[]>();
for (int i = 0; i < input[1]; i++)
{
array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
for (int i = 0;i < S.Length-1;i++)
{
if (S[i] == 'A')
{
if (S[i + 1] == 'C')
{
S = S.Replace(S[i],'a');
}
}
}
int count = 0;
List<int> ansstr = new List<int>();
for (int i = 0; i < S.Length;i++)
{
count = 0;
for (int j = 0;j <= i;j++)
{
if (S[j] == 'a')
{
count++;
}
}
ansstr.Add(count);
}
List<int> anss = new List<int>();
for (int i = 0; i < input[1];i++)
{
anss.Add(ansstr[array[i][1]-2] - ansstr[array[i][0]-1]);
}
foreach (int a in anss)
{
Console.WriteLine(a);
}
}*/
// ABC39B
/*static void Main()
{
int X = int.Parse(Console.ReadLine());
var ans = Math.Sqrt(X);
var ans2 = Math.Sqrt(ans);
Console.WriteLine(ans2);
}*/
// ABC38B
/*static void Main()
{
int[] input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] input2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
bool flag1 = false;
foreach (int a in input1)
{
foreach (int b in input2)
{
if (a == b)
{
flag1 = true;
}
}
}
if (flag1 == true)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC35B
/*static void Main()
{
string S = Console.ReadLine();
int T = int.Parse(Console.ReadLine());
int[] pos = { 0, 0 };
foreach (char a in S)
{
}
}*/
// ABC34B
/*static void Main()
{
}*/
//技術ProgramContest4Day1
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
}*/
// ABC135A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
var temp = B - A;
if (temp % 2 == 0)
{
Console.WriteLine(A + (temp/2));
}
else
{
Console.WriteLine("IMPOSSIBLE");
}
}*/
// ABC135B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] AnsN = new int[N];
for (int i = 0;i <N;i++)
{
AnsN[i] = i + 1;
}
int count = 0;
for(int i = 0;i < N;i++)
{
if (P[i] != AnsN[i])
{
count++;
}
}
if (count <= 2)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC135C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray();
/*int count = 0;
for (int i = N;i>0;i--)
{
var tempA = A[i] + A[i - 1];
if (tempA <= B[i - 1])
{
A[i - 1] = 0;
count += tempA;
}
else
{
if (A[i] <= B[i - 1])
{
A[i - 1] = tempA - B[i - 1];
count += B[i - 1];
}
else
{
count += B[i - 1];
}
}
}*/
/*int count = 0;
for (int i = 0;i < N;i++)
{
var tempA = A[i] + A[i + 1];
if (tempA <= B[i])
{
A[i + 1] = 0;
count += tempA;
}
else
{
if (B[i] >= A[i])
{
A[i + 1] = A[i + 1] - (B[i] - A[i]);
count += B[i];
}
else
{
count += B[i];
}
}
}
//このやり方
int count = 0;
for (int i = 0; i < N;i++)
{
List<int> temp = new List<int>();
temp.Add(A[i]);
temp.Add(B[i]);
count += temp.Min();
}
Console.WriteLine(count);
}*/
// ABC135D
// ABC127A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
string inputstr = Console.ReadLine();
char[] temp = inputstr.ToCharArray();
temp[input[1]-1] = Char.ToLower(temp[input[1] -1]);
inputstr = new string(temp);
Console.WriteLine(inputstr);
}*/
// ABC35
/*static void Main()
{
string S = Console.ReadLine();
int T = int.Parse(Console.ReadLine());
int[] ans = { 0, 0 };
int count = 0;
for (int i = 0; i < S.Length;i++)
{
if (S[i] == 'U')
{
ans[1]++;
}
else if (S[i] == 'D')
{
ans[1]--;
}
else if (S[i] == 'R')
{
ans[0]++;
}
else if (S[i] == 'L')
{
ans[0]--;
}
else
{
count++;
}
}
List<int[]> answer = new List<int[]>();
answer.Add(ans);
answer.Add(ans);
answer.Add(ans);
answer.Add(ans);
foreach (int[] n in answer)
{
}
}*/
// ABC114A
/*static void Main()
{
int x = int.Parse(Console.ReadLine());
if (x == 7 || x == 5 || x == 3)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
// ABC121C
// TLE
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long M = input[1];
List<long[]> shop = new List<long[]>();
for (int i = 0;i < n;i++)
{
shop.Add(Console.ReadLine().Split().Select(long.Parse) .ToArray());
}
List<long[]> answer = new List<long[]>(Sort(shop));
long price = 0;
long count = 0;
foreach (long[] temp in answer)
{
var tempcount = count;
if (count + temp[1] <= M)
{
count += temp[1];
}
else
{
count = M;
}
price += (count-tempcount) * temp[0];
if (M<=count)
{
break;
}
}
Console.WriteLine(price);
}
static List<long[]> Sort(List<long[]> A)
{
for (int i = 0;i < A.Count;i++)
{
for (int j = A.Count-1;j >i;j-- )
{
if (A[j][0] < A[j-1][0])
{
var temp = A[j];
A[j] = A[j - 1];
A[j - 1] = temp;
}
}
}
return A;
}*/
// Sortはライブラリを使った方が早い
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long M = input[1];
List<long[]> shops = new List<long[]>();
for (int i = 0; i < n; i++)
{
shops.Add(Console.ReadLine().Split().Select(long.Parse).ToArray());
}
long count = 0;
long ans = 0;
foreach (long[] shop in shops.OrderBy(a => a[0]))
{
var i = Math.Min(M - count, shop[1]);
ans += shop[0] * i;
count += i;
if (count >= M)
{
break;
}
}
Console.WriteLine(ans);
}*/
// 120C
// TLE
/*static void Main()
{
/*string input = Console.ReadLine();
int len = input.Length;
int count = 0;
while (input.Contains("01") || input.Contains("10"))
{
input = input.Replace("01", "").Replace("10", "");
count += len - input.Length;
len = input.Length;
}
Console.WriteLine(count);
string s = Console.ReadLine();
int zero = s.Replace("1", "").Length;
int one = s.Replace("0", "").Length;
Console.WriteLine((zero < one ? zero : one) * 2);
}*/
// 119
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
List<int> goal = new List<int>();
List<int> list = new List<int>();
for (int i =1;i<=N-1;i++)
{
goal.Add(input[i]);
}
for (int i = 0;i<N;i++)
{
list.Add(int.Parse(Console.ReadLine()));
}
}*/
// 118C
// 37B
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long n = input[0];
long k = input[1];
List<long[]> list = new List<long[]>();
for (int i = 0;i < k;i++)
{
long[] temp = Console.ReadLine().Split().Select(long.Parse).ToArray();
list.Add(temp);
}
long[] Ans = new long[n];
foreach (long[] m in list)
{
for (int i =0;i < Ans.Length;i++)
{
if (m[0]-1 <= i && i <= m[1]-1)
{
Ans[i] = m[2];
}
}
}
foreach (int a in Ans)
{
Console.WriteLine(a);
}
}*/
//大手前プロコン2019
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
if (A + 0.5f >= B)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
}*/
// E
/*static void Main()
{
long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = input[0];
long Q = input[1];
List<long> D = new List<long>();
for (long i = 0;i < N;i++)
{
D.Add(long.Parse(Console.ReadLine()));
}
List<long[]> TLR = new List<long[]>();
for (long i = 0;i < Q;i++)
{
TLR.Add(Console.ReadLine().Split().Select(long.Parse).ToArray());
}
foreach (long[] tlr in TLR)
{
var count = 0;
var tempara = new List<long>();
var a = tlr[0];
tempara.Add(a);
for (long i = 1;i <= N;i++)
{
if (Math.Abs(a - (-1 * i)) > D[(int)i - 1])
{
a = a - D[(int)i - 1];
}
else
{
a = -1*i;
}
tempara.Add(a);
}
foreach (long n in tempara)
{
if ( tlr[1]<= n && tlr[2] >= n)
{
count++;
}
}
Console.WriteLine(count);
}
}*/
// AtCoderBeginnerContest136
// 136A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int C = input[2];
var a = A - B;
var ans = C - a;
if (ans >= 0)
{
Console.WriteLine(ans);
}
else
{
Console.WriteLine("0");
}
}*/
// 136B
/*static void Main()
{
string N = Console.ReadLine();
int n = int.Parse(N);
int ocun = 0;
for (int i = 1; i<=n;i++)
{
if (i.ToString().Length % 2 == 1)
{
ocun++;
}
}
Console.WriteLine(ocun);
}*/
// 136C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] list = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count = 0;
int max = 0;
bool flag = false;
foreach (int a in list)
{
if (a >= max)
{
max = a;
}
else if (max - a >= 2)
{
flag = true;
break;
}
else { }
}
if (flag)
{
Console.WriteLine("No");
}
else
{
Console.WriteLine("Yes");
}
}*/
// 113C-ID
/*static void Main()
{
string S = Console.ReadLine();
Console.WriteLine(S.Length);
}*/
// 113A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
Console.WriteLine(A + (B/2));
}*/
// 112A
/*static void Main()
{
}*/
// 137A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
List<int> answer = new List<int>();
var ans1 = A + B;
answer.Add(ans1);
var ans2 = A - B;
answer.Add(ans2);
var ans3 = A * B;
answer.Add(ans3);
Console.WriteLine(answer.Max());
}*/
// 137B
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int K = input[0];
int X = input[1];
for (int i = X - (K-1);i<= X + (K-1);i++)
{int
if (i >= -1000000 && i <= 1000000)
{
Console.Write(i+" ");
}
}
Console.WriteLine();
}*/
// 137C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
List<string[]> list = new List<string[]>();
for (int i = 0; i < N;i++)
{
list.Add(Console.ReadLine().Split());
}
foreach (string[] n in list)
{
Array.Sort(n);
}
long ans = 0;
for (int i = 0; i< list.Count;i++)
{
for (int j = i+1;j < list.Count;j++)
{
if (list[i].Equals(list[j]))
{
ans++;
}
}
}
Console.WriteLine(ans);
}*/
/*static void Main(string[] args)
{
int N = Convert.ToInt32(Console.ReadLine());
string[] S = new string[N];
for (var i = 0; i < N; i++)
{
char[] c = Console.ReadLine().ToCharArray();
Array.Sort(c);
S[i] = new string(c);
}
Dictionary<string, long> dict = new Dictionary<string, long>();
for (var i = 0; i < N; i++)
{
if (dict.ContainsKey(S[i]))
{
dict[S[i]]++;
}
else
{
dict[S[i]] = 1L;
}
}
long res = 0L;
foreach (var i in dict)
{
if (i.Value > 1)
{
res += i.Value * (i.Value - 1) / 2;
}
}
Console.WriteLine(res);
}*/
// 138A
/*static void Main()
{
int a = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
if (a < 3200)
{
Console.WriteLine("red");
}
else
{
Console.WriteLine(s);
}
}*/
// 138B
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
double[] A = Console.ReadLine().Split().Select(double.Parse).ToArray();
double ans = 0;
for (int i = 0;i<A.Length;i++)
{
ans += 1 / A[i];
}
Console.WriteLine(1/ans);
}*/
// 138C
/*static void Main()
{
int N = int.Parse(Console.ReadLine());
double[] v = Console.ReadLine().Split().Select(double.Parse).ToArray();
double ans = 0;
Array.Sort(v);
ans = (v[0] + v[1]) / 2;
for (int i = 2; i < N;i++)
{
ans = (ans + v[i]) / 2;
}
Console.WriteLine(ans);
}*/
// 138D
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int Q = input[1];
List<Data> datalist = new List<Data>();
List<int[]> listQ = new List<int[]>();
for (int i = 0; i < N-1;i++)
{
Data data = new Data();
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
data.a = temp[0];
data.b = temp[1];
datalist.Add(data);
}
datalist = datalist.OrderBy(n => n.a).OrderBy(m => m.b).ToList();
for (int i = 0;i < Q;i++)
{
listQ.Add(Console.ReadLine().Split().Select(int.Parse).ToArray());
}
int[] Answer = new int[datalist[datalist.Count()].b];
var tempA = 0;
foreach (Data aa in datalist)
{
if (aa.a > tempA)
{
tempA = aa.a;
}
}
foreach (int[] temp in listQ)
{
if (temp[0] < tempA)
{
for (int i = temp[0]; i < Answer.Length; i++)
{
Answer[i] += temp[1];
}
}
else
{
Answer[temp[0]] += Answer[1];
}
}
foreach (int a in Answer)
{
Console.Write(a);
}
Console.WriteLine();
}*/
//最強プログラマ―選手権
// A
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int M = input[0];
int D = input[1];
int ans = 0;
for (int i = 1;i <= M;i++)
{
for (int j = 1; j <= D; j++)
{
int d1 = j / 10;
int d2 = j % 10;
if (d1 >= 2 && d2 >= 2)
{
var temp = d1 * d2;
if (temp == i)
{
ans++;
}
}
}
}
Console.WriteLine(ans);
}*/
// B
/*static void Main()
{
var tem = 1000000007;
var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
var N = input[0];
var K = input[1];
var array = Console.ReadLine().Split().Select(long.Parse).ToArray();
var invert = new long[N];
for (int i =0;i<N;i++)
{
for (int j = i+1;j < N;j++)
{
if (array[i] > array[j])
{
invert[i]++;
}
}
}
var less = new long[N];
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (array[i] > array[j])
{
less[i]++;
}
}
}
long ans = 0;
for (int i = 0;i < N;i++)
{
ans = (ans + (invert[i] * K) % tem) % tem;
ans = (ans + (less[i] * ((K * (K-1))/ 2 % tem)) % tem) % tem;
//K*(K-1)/2
}
Console.WriteLine(ans %tem);
}*/
// 139A
/*static void Main()
{
string input = Console.ReadLine();
string input2 = Console.ReadLine();
int ans = 0;
for (int i = 0;i < input.Length;i++)
{
if (input[i] == input2[i])
{
ans++;
}
}
Console.WriteLine(ans);
}*/
// 139B
static void Main() {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
var ans = 0;
var temp = 1;
while (temp < B) {
--temp;
temp += A;
++ans;
}
Console.WriteLine(ans);
}
// 139C
/*static void Main()
{
}*/
}
/*class Data
{
public int a { get; set; }
public int b { get; set; }
}*/
}
// 125C難しい
/*namespace CSharp
{
class Program
{
static IEnumerable<long> EnumerateDivisors(long n)
{
for (long i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
yield return i;
if (n / i != i)
{
yield return n / i;
}
}
}
}
static void Main(string[] args)
{
ReadString();
long[] A = ReadLongArray();
long[] divisors = Enumerable.Concat(EnumerateDivisors(A[0]),
EnumerateDivisors(A[1])) .Distinct().ToArray(); long ans = divisors.Select(x =>
new { Value = x, Count = A.Count(v => v % x == 0) }) .Where(x => x.Count >=
A.Length - 1) .OrderByDescending(x => x.Value) .First().Value;
Console.WriteLine(ans);
}
#region Helpers
static int[] ReadIntArray() => Console.ReadLine().Split().Select(s =>
int.Parse(s)).ToArray(); static long[] ReadLongArray() =>
Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0,
count).Select(_ => int.Parse(Console.ReadLine())).ToArray(); static long[]
ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ =>
long.Parse(Console.ReadLine())).ToArray();
static string ReadString() => Console.ReadLine();
static int ReadInt() => int.Parse(Console.ReadLine());
static long ReadLong() => long.Parse(Console.ReadLine());
static void ReadInt(out int first)
{
var array = ReadIntArray();
first = array[0];
}
static void ReadInt(out int first, out int second)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
}
static void ReadInt(out int first, out int second, out int third)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadInt(out int first, out int second, out int third, out
int fourth)
{
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
static void ReadLong(out long first)
{
var array = ReadLongArray();
first = array[0];
}
static void ReadLong(out long first, out long second)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
}
static void ReadLong(out long first, out long second, out long third)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadLong(out long first, out long second, out long third,
out long fourth)
{
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
#endregion
}
}*/
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 271
| 2
|
using System;
using System.Linq;
namespace atcoder {
class Program {
static void Main(string[] args) { ABC139.PowerSocket(); }
}
class ABC139 {
public static void PowerSocket() {
var s = Input.getIntArray();
int a = s[0];
int b = s[1];
int tap = 0;
if (b == 0) {
tap = 0;
} else if (b <= a) {
tap = 1;
} else {
tap = (int)Math.Ceiling((double)(b - a) / (a - 1)) + 1;
}
Console.WriteLine(tap);
}
}
class Input {
public static int[] getIntArray() {
string[] s = Console.ReadLine().Split(' ');
int[] num = s.Select(x => int.Parse(x)).ToArray();
return num;
}
public static long[] getLongArray() {
string[] s = Console.ReadLine().Split(' ');
long[] num = s.Select(x => long.Parse(x)).ToArray();
return num;
}
public static string[] getStringArray(int n) {
var s = new string[n];
for (int i = 0; i < n; i++) {
s[i] = Console.ReadLine();
}
return s;
}
}
}
|
using System;
using System.Linq;
namespace atcoder {
class Program {
static void Main(string[] args) { ABC139.PowerSocket(); }
}
class ABC139 {
public static void PowerSocket() {
var s = Input.getIntArray();
int a = s[0];
int b = s[1];
int tap = 0;
if (b == 1) {
tap = 0;
} else if (b <= a) {
tap += 1;
} else {
tap = (int)Math.Ceiling((double)(b - a) / (a - 1)) + 1;
}
Console.WriteLine(tap);
}
}
class Input {
public static int[] getIntArray() {
string[] s = Console.ReadLine().Split(' ');
int[] num = s.Select(x => int.Parse(x)).ToArray();
return num;
}
public static long[] getLongArray() {
string[] s = Console.ReadLine().Split(' ');
long[] num = s.Select(x => long.Parse(x)).ToArray();
return num;
}
public static string[] getStringArray(int n) {
var s = new string[n];
for (int i = 0; i < n; i++) {
s[i] = Console.ReadLine();
}
return s;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 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
| 300
| 4
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
List<string> input = new List<string>();
input.AddRange(Console.ReadLine().Split(' '));
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = 1;
if (B == 1) {
Console.WriteLine(1);
} else {
B -= A;
while (B > 0) {
B -= (A - 1);
C++;
}
Console.WriteLine(C);
}
}
}
|
using System;
using System.Collections.Generic;
namespace Test {
class Program {
static void Main(string[] args) {
List<string> input = new List<string>();
input.AddRange(Console.ReadLine().Split(' '));
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = 1;
if (B == 1) {
Console.WriteLine(0);
} else {
B -= A;
while (B > 0) {
B -= (A - 1);
C++;
}
Console.WriteLine(C);
}
}
}
}
|
[["+", 36, 36, 36, 36, 0, 208, 0, 209, 0, 256], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 0, 208, 0, 209, 8, 201, 0, 45], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 136
| 6
|
using System;
using System.Text;
using System.Collections.Generic;
class Program {
const int MOD = (int)1e9 + 7;
// const int MOD = (int) 998244353;
const int INT_MAX = 2147483647;
static void Main(string[] args) {
int cnt = 1;
int res = 1;
int[] ab = Scan.IntArray(2);
int a, b;
a = ab[0];
b = ab[1];
while (b > cnt) {
cnt += (a - 1);
res++;
}
Out.Ln(res);
}
}
public class Scan {
public static string Strln() { return Console.ReadLine(); }
public static int Int() { return int.Parse(Console.ReadLine()); }
public static long Long() { return long.Parse(Console.ReadLine()); }
public static string[] StringArray(int lines) {
string[] str = new string[lines];
for (int i = 0; i < lines; i++) {
str[i] = Console.ReadLine();
}
return str;
}
public static int[] IntArray(int t) {
string[] str = Console.ReadLine().Split(' ');
int[] ar = new int[t];
for (int i = 0; i < t; i++) {
ar[i] = int.Parse(str[i]);
}
return ar;
}
public static string[] StringArrayInLine(int t) {
string[] str = Console.ReadLine().Split(' ');
return str;
}
public static Tuple<int, int> Tuple() {
int[] tmp = Scan.IntArray(2);
return new Tuple<int, int>(tmp[0], tmp[1]);
}
public static long[] LongArray(int t) {
string[] str = Console.ReadLine().Split(' ');
long[] ar = new long[t];
for (int i = 0; i < t; i++) {
ar[i] = long.Parse(str[i]);
}
return ar;
}
public static double[] DoubleArray(int t) {
string[] str = Console.ReadLine().Split(' ');
double[] ar = new double[t];
for (int i = 0; i < t; i++) {
ar[i] = double.Parse(str[i]);
}
return ar;
}
public static int[,] IntSquareArray(int h, int w) {
int[,] resAr = new int[h, w];
for (int i = 0; i < h; i++) {
int[] ar = Scan.IntArray(w);
for (int j = 0; j < w; j++) {
resAr[i, j] = ar[j];
}
}
return resAr;
}
}
public class Out {
public static void Str(string s) { Console.Write(s); }
public static void Ln<T>(T s) { Console.WriteLine(s); }
public static void YESNO(bool f) { Console.WriteLine(f ? "YES" : "NO"); }
public static void YesNo(bool f) { Console.WriteLine(f ? "Yes" : "No"); }
public static void Array<T>(T[] a) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < a.Length; i++) {
sb.Append(a[i]);
if (i != a.Length - 1) {
sb.Append(" ");
}
}
string s = sb.ToString();
Console.WriteLine(s);
}
public static void List<T>(List<T> a) {
for (int i = 0; i < a.Count; i++) {
Console.Write(a[i]);
if (i != a.Count - 1) {
Console.Write(" ");
}
}
Console.WriteLine("");
}
}
public class Str {
public static string Connect(string a, string b) {
StringBuilder sb = new StringBuilder(a);
sb.Append(b);
return sb.ToString();
}
}
public class UnionFind {
public int[] parent;
public int[] rank;
public long[] weightDiff;
public void Init(int size) {
parent = new int[size + 5];
rank = new int[size + 5];
weightDiff = new long[size + 5];
for (int i = 0; i < size; i++) {
parent[i] = i;
rank[i] = 0;
weightDiff[i] = 0;
}
}
public int Root(int x) {
if (parent[x] == x) {
return x;
} else {
int r = Root(parent[x]);
weightDiff[x] += weightDiff[parent[x]];
return parent[x] = r;
}
}
public bool Unite(int x, int y, long w) // Add edge x <- y (weight: w)
{
w = w + GetWeight(x) - GetWeight(y);
x = Root(x);
y = Root(y);
if (x == y)
return false;
if (rank[x] < rank[y]) {
int tmp = x;
x = y;
y = tmp;
w *= -1;
}
if (rank[x] == rank[y]) {
++rank[x];
}
parent[y] = x;
weightDiff[y] = w;
return true;
}
public bool Same(int x, int y) { return Root(x) == Root(y); }
public long GetWeight(int x) {
Root(x);
return weightDiff[x];
}
public long Diff(int x, int y) // x -> y
{
return GetWeight(y) - GetWeight(x);
}
}
public class SegmentTree<Monoid> {
private bool debug = false;
// 0-indexed SegmentTree
public int size;
Monoid[] segTree;
Monoid unit;
public SegmentTree(int inSize, Monoid unit) {
this.unit = unit;
size = 2;
while (size < inSize)
size *= 2;
segTree = new Monoid[2 * size];
for (int i = 0; i < segTree.Length; i++) {
segTree[i] = unit;
// 単位元なので全部に代入しておけばよい
}
}
public int BinarySearch(int x) {
int high = size;
int low = 0;
int mid = (high + low) / 2;
while (low < high) {
// Console.WriteLine(low + " " + high);
Monoid cmp = NonRecursiveQuery(0, mid);
// Console.WriteLine("[ 0, " + mid + " ] -> " + cmp);
if ((dynamic)cmp >= x) {
high = mid;
} else if ((dynamic)cmp < x) {
low = mid + 1;
}
mid = (high + low) / 2;
}
return mid;
}
public void set(int iter, Monoid val) { segTree[iter + size - 1] = val; }
public Monoid GetMonoid(int index) { return segTree[index + size - 1]; }
public void add(int iter, Monoid val) {
update(iter, (dynamic)segTree[iter + size - 1] + (dynamic)val);
}
public void build() {
// 2段目より上の構築
for (int k = size - 2; k >= 0; k--) {
segTree[k] = F(segTree[2 * k + 1], segTree[2 * k + 2]);
}
}
public Monoid F(Monoid m1, Monoid m2) {
Monoid res = Algo.GCD(m1, m2);
return res;
}
public Monoid Query(int ql, int qr, int index, int nl, int nr) {
// Recursive
// [ql, qr)について考える
// index に対応する範囲 nl <= x <= nr
if (nr <= ql || qr <= nl) {
if (debug)
Console.WriteLine("Out: [l , r), [" + nl + " ," + nr + "), " +
"index: " + index + " ,unit:" + unit);
return unit;
}
if (ql <= nl && nr <= qr) {
if (debug)
Console.WriteLine("All in [l , r): [" + nl + " ," + nr + "), " +
"index: " + index + ",rangeAns:" + segTree[index]);
return segTree[index];
} else {
Monoid vl = Query(ql, qr, index * 2 + 1, nl, (nl + nr) / 2);
Monoid vr = Query(ql, qr, index * 2 + 2, (nl + nr) / 2, nr);
if (debug)
Console.WriteLine("Recursive: [l , r),+: [" + nl + ", " + nr +
"), index->" + index);
if (debug)
Console.WriteLine("(vl, vr): (" + vl + ", " + vr + ")");
return F(vl, vr);
}
}
public Monoid NonRecursiveQuery(int l, int r) {
// 区間 -> [ l , r ]
// 非再帰
int L = l + size - 1;
int R = r + size - 1;
Monoid s = unit;
while (L <= R) {
if (L % 2 == 0) {
s = F(s, segTree[L]);
L++;
}
if (R % 2 == 1) {
s = F(s, segTree[R]);
}
L /= 2;
R /= 2;
R--;
}
return s;
}
public void update(int k, Monoid x) {
k += size - 1;
segTree[k] = x;
while (true) {
k = (k - 1) / 2;
segTree[k] = F(segTree[k * 2 + 1], segTree[k * 2 + 2]);
if (k == 0) {
break;
}
}
}
public void print() {
Console.Write("Print:");
for (int i = 0; i < segTree.Length; i++) {
Console.Write(segTree[i] + " ");
}
Console.WriteLine("");
}
}
// 計算量: Push -> O(logN), Peek -> O(1)。Clear() -> O(logN)
// ToArray()で配列化
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;
}
/*
-> Item: _heap(ヒープを持つ.sizeはmaxSize)
-> Item: _type -> 0:asc(昇順), 1:desc(降順)
*/
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);
// typeが0なら昇順, 1なら降順にソートするCompare
}
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() // O(1)
{
return _count;
}
public T Peek() // O(1)
{
return _heap[0];
}
public bool Contains(T x) // O(N)なので注意
{
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (Count() > 0)
Pop();
}
public IEnumerator<T> GetEnumerator() // なにこれ
{
var ret = new List<T>();
while (Count() > 0) {
ret.Add(Pop());
}
foreach (var r in ret) {
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 Algo {
public const long MOD = (long)1e9 + 7;
public static int[,] CombModMake() {
int[,] res = new int[2005, 2005];
for (int i = 0; i < 2005; i++) {
for (int j = 0; j < 2005; j++) {
if (i == 0 || i < j) {
res[i, j] = 0;
} else if (j == 0 || i == j) {
res[i, j] = 1;
} else {
res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % (int)MOD;
}
}
}
return res;
}
public static bool IsPrime(int a) // O(sqrt N)
{
int max = (int)Math.Sqrt(a);
if (a <= 1)
return false;
for (int i = 2; i <= max; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
public static T GCD<T>(T a, T b) {
if ((dynamic)b == 0) {
return a;
} else {
return Algo.GCD((dynamic)b, (dynamic)a % (dynamic)b);
}
}
static int Nibutan(long[] array, long k) {
int low = 0;
int high = array.Length - 1;
int mid = high;
while (low < high) {
mid = (low + high) / 2;
if (array[mid] >= k) // k以上の最小index.ココを変えるだけ
{
high = mid;
} else {
low = mid + 1;
}
mid = (low + high) / 2;
}
return mid;
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
class Program {
const int MOD = (int)1e9 + 7;
// const int MOD = (int) 998244353;
const int INT_MAX = 2147483647;
static void Main(string[] args) {
int cnt = 1;
int res = 0;
int[] ab = Scan.IntArray(2);
int a, b;
a = ab[0];
b = ab[1];
while (cnt < b) {
cnt += (a - 1);
res++;
}
Out.Ln(res);
}
}
public class Scan {
public static string Strln() { return Console.ReadLine(); }
public static int Int() { return int.Parse(Console.ReadLine()); }
public static long Long() { return long.Parse(Console.ReadLine()); }
public static string[] StringArray(int lines) {
string[] str = new string[lines];
for (int i = 0; i < lines; i++) {
str[i] = Console.ReadLine();
}
return str;
}
public static int[] IntArray(int t) {
string[] str = Console.ReadLine().Split(' ');
int[] ar = new int[t];
for (int i = 0; i < t; i++) {
ar[i] = int.Parse(str[i]);
}
return ar;
}
public static string[] StringArrayInLine(int t) {
string[] str = Console.ReadLine().Split(' ');
return str;
}
public static Tuple<int, int> Tuple() {
int[] tmp = Scan.IntArray(2);
return new Tuple<int, int>(tmp[0], tmp[1]);
}
public static long[] LongArray(int t) {
string[] str = Console.ReadLine().Split(' ');
long[] ar = new long[t];
for (int i = 0; i < t; i++) {
ar[i] = long.Parse(str[i]);
}
return ar;
}
public static double[] DoubleArray(int t) {
string[] str = Console.ReadLine().Split(' ');
double[] ar = new double[t];
for (int i = 0; i < t; i++) {
ar[i] = double.Parse(str[i]);
}
return ar;
}
public static int[,] IntSquareArray(int h, int w) {
int[,] resAr = new int[h, w];
for (int i = 0; i < h; i++) {
int[] ar = Scan.IntArray(w);
for (int j = 0; j < w; j++) {
resAr[i, j] = ar[j];
}
}
return resAr;
}
}
public class Out {
public static void Str(string s) { Console.Write(s); }
public static void Ln<T>(T s) { Console.WriteLine(s); }
public static void YESNO(bool f) { Console.WriteLine(f ? "YES" : "NO"); }
public static void YesNo(bool f) { Console.WriteLine(f ? "Yes" : "No"); }
public static void Array<T>(T[] a) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < a.Length; i++) {
sb.Append(a[i]);
if (i != a.Length - 1) {
sb.Append(" ");
}
}
string s = sb.ToString();
Console.WriteLine(s);
}
public static void List<T>(List<T> a) {
for (int i = 0; i < a.Count; i++) {
Console.Write(a[i]);
if (i != a.Count - 1) {
Console.Write(" ");
}
}
Console.WriteLine("");
}
}
public class Str {
public static string Connect(string a, string b) {
StringBuilder sb = new StringBuilder(a);
sb.Append(b);
return sb.ToString();
}
}
public class UnionFind {
public int[] parent;
public int[] rank;
public long[] weightDiff;
public void Init(int size) {
parent = new int[size + 5];
rank = new int[size + 5];
weightDiff = new long[size + 5];
for (int i = 0; i < size; i++) {
parent[i] = i;
rank[i] = 0;
weightDiff[i] = 0;
}
}
public int Root(int x) {
if (parent[x] == x) {
return x;
} else {
int r = Root(parent[x]);
weightDiff[x] += weightDiff[parent[x]];
return parent[x] = r;
}
}
public bool Unite(int x, int y, long w) // Add edge x <- y (weight: w)
{
w = w + GetWeight(x) - GetWeight(y);
x = Root(x);
y = Root(y);
if (x == y)
return false;
if (rank[x] < rank[y]) {
int tmp = x;
x = y;
y = tmp;
w *= -1;
}
if (rank[x] == rank[y]) {
++rank[x];
}
parent[y] = x;
weightDiff[y] = w;
return true;
}
public bool Same(int x, int y) { return Root(x) == Root(y); }
public long GetWeight(int x) {
Root(x);
return weightDiff[x];
}
public long Diff(int x, int y) // x -> y
{
return GetWeight(y) - GetWeight(x);
}
}
public class SegmentTree<Monoid> {
private bool debug = false;
// 0-indexed SegmentTree
public int size;
Monoid[] segTree;
Monoid unit;
public SegmentTree(int inSize, Monoid unit) {
this.unit = unit;
size = 2;
while (size < inSize)
size *= 2;
segTree = new Monoid[2 * size];
for (int i = 0; i < segTree.Length; i++) {
segTree[i] = unit;
// 単位元なので全部に代入しておけばよい
}
}
public int BinarySearch(int x) {
int high = size;
int low = 0;
int mid = (high + low) / 2;
while (low < high) {
// Console.WriteLine(low + " " + high);
Monoid cmp = NonRecursiveQuery(0, mid);
// Console.WriteLine("[ 0, " + mid + " ] -> " + cmp);
if ((dynamic)cmp >= x) {
high = mid;
} else if ((dynamic)cmp < x) {
low = mid + 1;
}
mid = (high + low) / 2;
}
return mid;
}
public void set(int iter, Monoid val) { segTree[iter + size - 1] = val; }
public Monoid GetMonoid(int index) { return segTree[index + size - 1]; }
public void add(int iter, Monoid val) {
update(iter, (dynamic)segTree[iter + size - 1] + (dynamic)val);
}
public void build() {
// 2段目より上の構築
for (int k = size - 2; k >= 0; k--) {
segTree[k] = F(segTree[2 * k + 1], segTree[2 * k + 2]);
}
}
public Monoid F(Monoid m1, Monoid m2) {
Monoid res = Algo.GCD(m1, m2);
return res;
}
public Monoid Query(int ql, int qr, int index, int nl, int nr) {
// Recursive
// [ql, qr)について考える
// index に対応する範囲 nl <= x <= nr
if (nr <= ql || qr <= nl) {
if (debug)
Console.WriteLine("Out: [l , r), [" + nl + " ," + nr + "), " +
"index: " + index + " ,unit:" + unit);
return unit;
}
if (ql <= nl && nr <= qr) {
if (debug)
Console.WriteLine("All in [l , r): [" + nl + " ," + nr + "), " +
"index: " + index + ",rangeAns:" + segTree[index]);
return segTree[index];
} else {
Monoid vl = Query(ql, qr, index * 2 + 1, nl, (nl + nr) / 2);
Monoid vr = Query(ql, qr, index * 2 + 2, (nl + nr) / 2, nr);
if (debug)
Console.WriteLine("Recursive: [l , r),+: [" + nl + ", " + nr +
"), index->" + index);
if (debug)
Console.WriteLine("(vl, vr): (" + vl + ", " + vr + ")");
return F(vl, vr);
}
}
public Monoid NonRecursiveQuery(int l, int r) {
// 区間 -> [ l , r ]
// 非再帰
int L = l + size - 1;
int R = r + size - 1;
Monoid s = unit;
while (L <= R) {
if (L % 2 == 0) {
s = F(s, segTree[L]);
L++;
}
if (R % 2 == 1) {
s = F(s, segTree[R]);
}
L /= 2;
R /= 2;
R--;
}
return s;
}
public void update(int k, Monoid x) {
k += size - 1;
segTree[k] = x;
while (true) {
k = (k - 1) / 2;
segTree[k] = F(segTree[k * 2 + 1], segTree[k * 2 + 2]);
if (k == 0) {
break;
}
}
}
public void print() {
Console.Write("Print:");
for (int i = 0; i < segTree.Length; i++) {
Console.Write(segTree[i] + " ");
}
Console.WriteLine("");
}
}
// 計算量: Push -> O(logN), Peek -> O(1)。Clear() -> O(logN)
// ToArray()で配列化
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;
}
/*
-> Item: _heap(ヒープを持つ.sizeはmaxSize)
-> Item: _type -> 0:asc(昇順), 1:desc(降順)
*/
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);
// typeが0なら昇順, 1なら降順にソートするCompare
}
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() // O(1)
{
return _count;
}
public T Peek() // O(1)
{
return _heap[0];
}
public bool Contains(T x) // O(N)なので注意
{
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (Count() > 0)
Pop();
}
public IEnumerator<T> GetEnumerator() // なにこれ
{
var ret = new List<T>();
while (Count() > 0) {
ret.Add(Pop());
}
foreach (var r in ret) {
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 Algo {
public const long MOD = (long)1e9 + 7;
public static int[,] CombModMake() {
int[,] res = new int[2005, 2005];
for (int i = 0; i < 2005; i++) {
for (int j = 0; j < 2005; j++) {
if (i == 0 || i < j) {
res[i, j] = 0;
} else if (j == 0 || i == j) {
res[i, j] = 1;
} else {
res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % (int)MOD;
}
}
}
return res;
}
public static bool IsPrime(int a) // O(sqrt N)
{
int max = (int)Math.Sqrt(a);
if (a <= 1)
return false;
for (int i = 2; i <= max; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
public static T GCD<T>(T a, T b) {
if ((dynamic)b == 0) {
return a;
} else {
return Algo.GCD((dynamic)b, (dynamic)a % (dynamic)b);
}
}
static int Nibutan(long[] array, long k) {
int low = 0;
int high = array.Length - 1;
int mid = high;
while (low < high) {
mid = (low + high) / 2;
if (array[mid] >= k) // k以上の最小index.ココを変えるだけ
{
high = mid;
} else {
low = mid + 1;
}
mid = (low + high) / 2;
}
return mid;
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 22]]
| 8
| 3,002
| 6
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Numerics;
namespace abc139 {
class Program {
static void Main(string[] args) {
// Console.SetIn(new StreamReader("input.txt"));
solve_abc139B();
}
public static void solve_abc139B() {
string[] ab = Console.ReadLine().Split(' ');
int a = Convert.ToInt32(ab[0]);
int b = Convert.ToInt32(ab[1]);
/*
Предположение полностью не правильное
Визуальное представление, что у нас розетка и пилиоты, которые
подключаются по цепочке, не соответствует тому, что задано в
условии. Поэтому в данном случае додумывание было ошыбочным.
Даже если условие задачи тяжело представить в голове, его надо
воспринимать, как есть. Без опасных додумываний.
Один свободный слот по условию нужно воспринимать, как есть. Это
один свободный слот. Далее, Один пауэр стрип по условию это A свободных
слотов из которых один не свободный. То есть У нас A - 1 свободных слотов,
при добавлении одного пауэр стрипа.
Теперь, нам надо иметь хотя бы B свободных слотов. Но по условию у нас один
слот свободный уже есть. Тогда получается надо иметь хотябы B - 1 свободных
слотов. В моем же случае, я сам себя обманул и считал, что один свободный
слот у нас всегда становится занятым, если мы добавляем новый пауэр стрим. И
это неправда по условию.
*/
Console.WriteLine(((b - 1) - (a - 1) + 1) / (a - 1));
/*int w = 1;
if (a <= b)
{
w = ((b - 1) + a - 1) / a;
int d = w - 1;
int r = a * w - d;
if (r < b - 1)
{
w++;
}
}
Console.WriteLine(w);
*/
/*
//Округление вверх не работает. Узнать почему
int t = (b + a - 1) / a;
int d = t - 1;
if (b > a * t - d)
{
t++;
}
Console.WriteLine(t);
*/
}
public static void solve_abc139A() {
string s1 = Console.ReadLine();
string s2 = Console.ReadLine();
int c = 0;
if (s1[0] == s2[0]) {
c++;
}
if (s1[1] == s2[1]) {
c++;
}
if (s1[2] == s2[2]) {
c++;
}
Console.WriteLine(c);
}
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Numerics;
namespace abc139 {
class Program {
static void Main(string[] args) {
// Console.SetIn(new StreamReader("input.txt"));
solve_abc139B();
}
public static void solve_abc139B() {
string[] ab = Console.ReadLine().Split(' ');
int a = Convert.ToInt32(ab[0]);
int b = Convert.ToInt32(ab[1]);
/*
Предположение полностью не правильное
Визуальное представление, что у нас розетка и пилиоты, которые
подключаются по цепочке, не соответствует тому, что задано в
условии. Поэтому в данном случае додумывание было ошыбочным.
Даже если условие задачи тяжело представить в голове, его надо
воспринимать, как есть. Без опасных додумываний.
Один свободный слот по условию нужно воспринимать, как есть. Это
один свободный слот. Далее, Один пауэр стрип по условию это A свободных
слотов из которых один не свободный. То есть У нас A - 1 свободных слотов,
при добавлении одного пауэр стрипа.
Теперь, нам надо иметь хотя бы B свободных слотов. Но по условию у нас один
слот свободный уже есть. Тогда получается надо иметь хотябы B - 1 свободных
слотов. В моем же случае, я сам себя обманул и считал, что один свободный
слот у нас всегда становится занятым, если мы добавляем новый пауэр стрим. И
это неправда по условию.
*/
Console.WriteLine(((b - 1) + (a - 1) - 1) / (a - 1));
/*int w = 1;
if (a <= b)
{
w = ((b - 1) + a - 1) / a;
int d = w - 1;
int r = a * w - d;
if (r < b - 1)
{
w++;
}
}
Console.WriteLine(w);
*/
/*
//Округление вверх не работает. Узнать почему
int t = (b + a - 1) / a;
int d = t - 1;
if (b > a * t - d)
{
t++;
}
Console.WriteLine(t);
*/
}
public static void solve_abc139A() {
string s1 = Console.ReadLine();
string s2 = Console.ReadLine();
int c = 0;
if (s1[0] == s2[0]) {
c++;
}
if (s1[1] == s2[1]) {
c++;
}
if (s1[2] == s2[2]) {
c++;
}
Console.WriteLine(c);
}
}
}
|
[["-", 0, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33]]
| 8
| 215
| 4
|
using System;
class Program {
static void Main(string[] args) {
string[] a1 = Console.ReadLine().Split(' ');
int[] s1 = new int[2];
for (int i = 0; i < 2; i++) {
s1[i] = int.Parse(a1[i]);
}
int hole = s1[0];
int count = 1;
while (hole < s1[1]) {
hole += s1[0];
hole -= 1;
count += 1;
}
Console.WriteLine(count);
Console.ReadLine();
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] a1 = Console.ReadLine().Split(' ');
int[] s1 = new int[2];
for (int i = 0; i < 2; i++) {
s1[i] = int.Parse(a1[i]);
}
int hole = 1;
int count = 0;
while (hole < s1[1]) {
hole += s1[0];
hole -= 1;
count += 1;
}
Console.WriteLine(count);
Console.ReadLine();
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 130
| 7
|
using System;
using System.Linq;
class Hello {
static void Main(string[] args) {
int count = 0;
var AB = Console.ReadLine().Split(' ');
var AC = int.Parse(AB[0]);
var BB = int.Parse(AB[1]);
for (int i = 1; i < BB; i++) {
if (AC * i >= BB) {
count = count + i;
break;
}
}
Console.WriteLine(count);
}
}
|
using System;
using System.Linq;
class Hello {
static void Main(string[] args) {
int count = 0;
var AB = Console.ReadLine().Split(' ');
var AC = int.Parse(AB[0]);
var BB = int.Parse(AB[1]);
for (int i = 1; i < BB; i++) {
if ((AC - 1) * i + 1 >= BB) {
count = count + i;
break;
}
}
Console.WriteLine(count);
}
}
|
[["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 111
| 6
|
using System;
namespace abc139_b {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int result = 1;
while (((a - 1) * (result - 1) + a) < b) {
result++;
}
Console.WriteLine(result);
}
}
}
|
using System;
namespace abc139_b {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int result = 0;
while (((a - 1) * (result - 1) + a) < b) {
result++;
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 103
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A {
class Program {
/// <summary>
/// The main entry point for the application
/// </summary>
[STAThread]
public static void Main(string[] args) {
string[] str =
Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
int use = 1;
int now = 1;
while (true) {
if (b <= now) {
Console.Write("{0}", use);
break;
}
now = now - 1 + a;
use++;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A {
class Program {
/// <summary>
/// The main entry point for the application
/// </summary>
[STAThread]
public static void Main(string[] args) {
string[] str =
Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
int use = 0;
int now = 1;
while (true) {
if (b <= now) {
Console.Write("{0}", use);
break;
}
now = now - 1 + a;
use++;
}
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 146
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace A {
class Program {
static void Main(string[] args) {
var AB = Io.ReadSplit<int>();
var A = AB[0];
var B = AB[1];
var c = A;
var output = 1;
while (true) {
if (c >= B)
break;
c = c - 1 + A;
output++;
}
Console.WriteLine(output);
}
}
class Io {
public static string Read() { return Console.ReadLine(); }
public static IEnumerable<string> ReadRepeat(int count) {
return Enumerable.Range(0, count).Select(_ => Read());
}
public static T Read<T>() { return (T)Convert.ChangeType(Read(), typeof(T)); }
public static IEnumerable<T> ReadRepeat<T>(int count) {
return Enumerable.Range(0, count).Select(_ => Read<T>());
}
public static string[] ReadSplit(char devide = ' ') {
return Read().Split(devide);
}
public static T[] ReadSplit<T>(char devide = ' ') {
return ReadSplit(devide)
.Select(s => (T)Convert.ChangeType(s, typeof(T)))
.ToArray();
}
public static IEnumerable<T[]> ReadSplitRepeat<T>(int count,
char devide = ' ') {
return Enumerable.Range(0, count).Select(_ => ReadSplit<T>(devide));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace A {
class Program {
static void Main(string[] args) {
var AB = Io.ReadSplit<int>();
var A = AB[0];
var B = AB[1];
var c = 1;
var tapCount = 0;
while (true) {
if (c >= B)
break;
c = c - 1 + A;
tapCount++;
}
Console.WriteLine(tapCount);
}
}
class Io {
public static string Read() { return Console.ReadLine(); }
public static IEnumerable<string> ReadRepeat(int count) {
return Enumerable.Range(0, count).Select(_ => Read());
}
public static T Read<T>() { return (T)Convert.ChangeType(Read(), typeof(T)); }
public static IEnumerable<T> ReadRepeat<T>(int count) {
return Enumerable.Range(0, count).Select(_ => Read<T>());
}
public static string[] ReadSplit(char devide = ' ') {
return Read().Split(devide);
}
public static T[] ReadSplit<T>(char devide = ' ') {
return ReadSplit(devide)
.Select(s => (T)Convert.ChangeType(s, typeof(T)))
.ToArray();
}
public static IEnumerable<T[]> ReadSplitRepeat<T>(int count,
char devide = ' ') {
return Enumerable.Range(0, count).Select(_ => ReadSplit<T>(devide));
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 345
| 10
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
if (B == 1) {
Console.WriteLine(0);
}
int open = 1;
int tot = 1;
for (int i = 1; i < 200; i++) {
if (open > 1) {
tot += A - 1;
open--;
} else {
open = tot;
tot += A - 1;
open--;
}
if (tot >= B) {
Console.WriteLine(i);
return;
}
}
}
int A, B;
public Sol() {
var d = ria();
A = d[0];
B = d[1];
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
if (B == 1) {
Console.WriteLine(0);
return;
}
int open = 1;
int tot = 1;
for (int i = 1; i < 200; i++) {
if (open > 1) {
tot += A - 1;
open--;
} else {
open = tot;
tot += A - 1;
open--;
}
if (tot >= B) {
Console.WriteLine(i);
return;
}
}
}
int A, B;
public Sol() {
var d = ria();
A = d[0];
B = d[1];
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 405
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace test {
class Program {
static void Main(string[] args) {
var input = ReadArrayInt();
var A = input[0];
var B = input[1];
if (B == 0) {
Console.WriteLine(0);
return;
}
var ans = 0;
while (B > 0) {
if (A >= B) {
ans++;
B -= A;
} else if (A < B) {
ans++;
B -= A - 1;
}
}
Console.WriteLine(ans);
Console.ReadLine();
}
static string Read() { return Console.ReadLine(); }
static int ReadInt() { return int.Parse(Read()); }
static long ReadLong() { return long.Parse(Read()); }
static int[] ReadArrayInt() {
return Read().Split(' ').Select(s => int.Parse(s)).ToArray();
}
static long[] ReadArrayLong() {
return Read().Split(' ').Select(s => long.Parse(s)).ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace test {
class Program {
static void Main(string[] args) {
var input = ReadArrayInt();
var A = input[0];
var B = input[1];
if (B == 1) {
Console.WriteLine(0);
return;
}
var ans = 0;
while (B > 0) {
if (A >= B) {
ans++;
B -= A;
} else if (A < B) {
ans++;
B -= A - 1;
}
}
Console.WriteLine(ans);
Console.ReadLine();
}
static string Read() { return Console.ReadLine(); }
static int ReadInt() { return int.Parse(Read()); }
static long ReadLong() { return long.Parse(Read()); }
static int[] ReadArrayInt() {
return Read().Split(' ').Select(s => int.Parse(s)).ToArray();
}
static long[] ReadArrayLong() {
return Read().Split(' ').Select(s => long.Parse(s)).ToArray();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 255
| 2
|
using System;
namespace B {
class Program {
static void Main(string[] args) {
var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var A = ab[0];
var B = ab[1];
var count = 1;
while (A + (count - 1) * (A - 1) < B)
count++;
Console.WriteLine(count);
}
}
}
|
using System;
namespace B {
class Program {
static void Main(string[] args) {
var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var A = ab[0];
var B = ab[1];
var count = 1;
while (A + (count - 1) * (A - 1) < B)
count++;
Console.WriteLine(B == 1 ? 0 : count);
}
}
}
|
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102]]
| 8
| 96
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
partial class Program {
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 long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
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;
}
}
static void Main(string[] args) {
//↓
var ab = ReadIntArray();
var a = ab[0];
var b = ab[1];
var i = 1;
while (true) {
if (1 + (a - 1) * i >= b) {
Console.WriteLine(i);
return;
}
i++;
}
//↑
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
partial class Program {
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 long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
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;
}
}
static void Main(string[] args) {
//↓
var ab = ReadIntArray();
var a = ab[0];
var b = ab[1];
var i = 0;
while (true) {
if (1 + (a - 1) * i >= b) {
Console.WriteLine(i);
return;
}
i++;
}
//↑
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 756
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.