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.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace atPra98A {
class Class1 {
static void Main() {
var N = int.Parse(Console.ReadLine());
if (N < 999)
Console.WriteLine("ABC");
else
Console.WriteLine("ABD");
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace atPra98A {
class Class1 {
static void Main() {
var N = int.Parse(Console.ReadLine());
if (N <= 999)
Console.WriteLine("ABC");
else
Console.WriteLine("ABD");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 91
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
int a;
string answer;
a = int.Parse(Console.ReadLine());
if (a < 1000) {
answer = "ABC";
} else {
answer = "ABD";
}
Console.Write(a);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
int a;
string answer;
a = int.Parse(Console.ReadLine());
if (a < 1000) {
answer = "ABC";
} else {
answer = "ABD";
}
Console.Write(answer);
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 95
| 2
|
using System;
namespace ert89er8uer8 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
if (N <= 1000) {
Console.WriteLine("ABC");
} else {
Console.WriteLine("ABD");
}
}
}
}
|
using System;
namespace ert89er8uer8 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
if (N <= 999) {
Console.WriteLine("ABC");
} else {
Console.WriteLine("ABD");
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 65
| 2
|
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program {
static void Main(string[] args) {
string str1;
str1 = Console.ReadLine(); //標準入力
int count = int.Parse(str1);
if (count < 1000) {
Console.WriteLine("abc");
} else {
Console.WriteLine("abd");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program {
static void Main(string[] args) {
string str1;
str1 = Console.ReadLine(); //標準入力
int count = int.Parse(str1);
if (count < 1000) {
Console.WriteLine("ABC");
} else {
Console.WriteLine("ABD");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 83
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main() {
var N = int.Parse(ReadLine());
if (N < 1000)
WriteLine($"ABC{N:000}");
else
WriteLine($"ABD{N-999:000}");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main() {
var N = int.Parse(ReadLine());
if (N < 1000)
WriteLine($"ABC");
else
WriteLine($"ABD");
}
}
|
[["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 298, 0, 102], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 31, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 17, 33], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 12, 203]]
| 8
| 77
| 12
|
using System;
class ABD {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
if (n > 1000) {
Console.WriteLine("ABD");
} else {
Console.WriteLine("ABC");
}
}
}
|
using System;
class ABD {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
if (n > 999) {
Console.WriteLine("ABD");
} else {
Console.WriteLine("ABC");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 61
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace B {
class Program {
static void Main(string[] args) {
var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
var dist = ab[1] - ab[0];
var list = new List<int>();
list.Add(1);
for (int i = 1; i < 1000; i++)
list.Add(i + list.Last());
var ans = list[dist] - ab[1];
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace B {
class Program {
static void Main(string[] args) {
var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
var dist = ab[1] - ab[0];
var list = new List<int>();
list.Add(1);
for (int i = 2; i < 1000; i++)
list.Add(i + list.Last());
var ans = list[dist - 1] - ab[1];
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 136
| 4
|
using System;
public class Hello {
public static void Main() {
var array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int A = array[0];
int B = array[1];
int X = A - B;
int ans = X * (X + 1) / 2 - B;
Console.WriteLine(ans);
}
}
|
using System;
public class Hello {
public static void Main() {
var array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int A = array[0];
int B = array[1];
int X = B - A;
int ans = X * (X + 1) / 2 - B;
Console.WriteLine(ans);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
| 8
| 86
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var list = new List<int>();
for (int i = 1; i <= Math.Log(N, 6); i++) {
list.Add((int)Math.Pow(6, i));
}
for (int i = 1; i <= Math.Log(N, 9); i++) {
list.Add((int)Math.Pow(9, i));
}
list.Add(1);
var dp = new int[N + 1];
for (int i = 0; i < N + 1; i++) {
dp[i] = -1;
}
dp[N] = 0;
foreach (var x in list.OrderByDescending(a => a)) {
var nextDP = new int[N + 1];
for (int i = N; i >= 1; i--) {
if (dp[i] >= 0) {
if (i - x >= 0) {
if (dp[i - x] >= 0) {
dp[i - x] = Math.Min(dp[i - x], dp[i] + 1);
} else {
dp[i - x] = dp[i] + 1;
}
}
}
}
}
Console.WriteLine(dp[0]);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var list = new List<int>();
for (int i = 1; i < Math.Log(N, 6) + 1; i++) {
list.Add((int)Math.Pow(6, i));
}
for (int i = 1; i < Math.Log(N, 9) + 1; i++) {
list.Add((int)Math.Pow(9, i));
}
list.Add(1);
var dp = new int[N + 1];
for (int i = 0; i < N + 1; i++) {
dp[i] = -1;
}
dp[N] = 0;
foreach (var x in list.OrderByDescending(a => a)) {
var nextDP = new int[N + 1];
for (int i = N; i >= 1; i--) {
if (dp[i] >= 0) {
if (i - x >= 0) {
if (dp[i - x] >= 0) {
dp[i - x] = Math.Min(dp[i - x], dp[i] + 1);
} else {
dp[i - x] = dp[i] + 1;
}
}
}
}
}
Console.WriteLine(dp[0]);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 1,282
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var list = new List<int>();
for (int i = 1; i <= Math.Log(100000, 9); i++) {
list.Add((int)Math.Pow(100000, i));
}
for (int i = 1; i <= Math.Log(N, 6); i++) {
list.Add((int)Math.Pow(6, i));
}
list.Add(1);
list = list.OrderByDescending(x => x).ToList();
var dp = new int[N + 1];
for (int i = 0; i < N + 1; i++) {
dp[i] = int.MaxValue;
}
dp[0] = 0;
foreach (var x in list) {
for (int i = 0; i < N + 1; i++) {
if (dp[i] < int.MaxValue) {
var next = i + x;
if (next <= N) {
dp[next] = Math.Min(dp[next], dp[i] + 1);
}
}
}
}
var ans = dp[N];
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var list = new List<int>();
for (int i = 1; i <= Math.Log(100000, 9); i++) {
list.Add((int)Math.Pow(9, i));
}
for (int i = 1; i <= Math.Log(100000, 6); i++) {
list.Add((int)Math.Pow(6, i));
}
list.Add(1);
list = list.OrderByDescending(x => x).ToList();
var dp = new int[N + 1];
for (int i = 0; i < N + 1; i++) {
dp[i] = int.MaxValue;
}
dp[0] = 0;
foreach (var x in list) {
for (int i = 0; i < N + 1; i++) {
if (dp[i] < int.MaxValue) {
var next = i + x;
if (next <= N) {
dp[next] = Math.Min(dp[next], dp[i] + 1);
}
}
}
}
var ans = dp[N];
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["-", 0, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 1,260
| 4
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
var n = long.Parse(Console.ReadLine());
// long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray();
var ans = n;
for (long i = 0; i < n; i++) {
long count = 0;
long tmp = i;
while (tmp > 0) {
count += tmp % 6;
tmp /= 6;
}
tmp = n - i;
while (tmp > 0) {
count += tmp % 9;
tmp /= 9;
}
ans = Math.Min(ans, count);
}
// 出力
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
var n = long.Parse(Console.ReadLine());
// long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray();
var ans = n;
for (long i = 0; i <= n; i++) {
long count = 0;
long tmp = i;
while (tmp > 0) {
count += tmp % 6;
tmp /= 6;
}
tmp = n - i;
while (tmp > 0) {
count += tmp % 9;
tmp /= 9;
}
ans = Math.Min(ans, count);
}
// 出力
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 149
| 2
|
using System;
namespace ABC099C {
internal class Program {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int res = n;
for (int i = 0; i < n; i++) {
int count = 0;
int t = i;
while (t > 0) {
count += t % 6;
t /= 6;
}
t = n - i;
while (t > 0) {
count += t % 9;
t /= 9;
}
if (res > count)
res = count;
}
Console.Write(res);
}
}
}
|
using System;
namespace ABC099C {
internal class Program {
public static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int res = n;
for (int i = 0; i <= n; i++) {
int count = 0;
int t = i;
while (t > 0) {
count += t % 6;
t /= 6;
}
t = n - i;
while (t > 0) {
count += t % 9;
t /= 9;
}
if (res > count)
res = count;
}
Console.Write(res);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 128
| 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) {
int n = Console.ReadLine().ToInt();
int max6 = (int)Math.Log(n, 6) + 1;
int max9 = (int)Math.Log(n, 9) + 1;
long[] dp = new long[n + 2];
for (int i = 0; i < n + 1; i++)
dp[i] = 999999999;
dp[0] = 0;
// dp[i] = i会の操作で最小の回数
for (int i = 0; i <= n; i++) {
dp[i + 1] = Math.Min(dp[i] + 1, dp[i + 1]);
int pow = 1;
for (int j = 1; j < max6; j++) {
pow *= 6;
int k = pow;
if (i + k >= n + 1)
break;
dp[i + k] = Math.Min(dp[i] + 1, dp[i + k]);
}
pow = 1;
for (int j = 1; j < max9; j++) {
pow *= 9;
int k = pow;
if (i + k >= n + 1)
break;
dp[i + k] = Math.Min(dp[i] + 1, dp[i + k]);
}
}
Console.WriteLine(dp[n]);
}
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) {
int[] 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) {
int n = Console.ReadLine().ToInt();
int max6 = (int)Math.Log(n, 6) + 2;
int max9 = (int)Math.Log(n, 9) + 2;
long[] dp = new long[n + 2];
for (int i = 0; i < n + 1; i++)
dp[i] = 999999999;
dp[0] = 0;
// dp[i] = i会の操作で最小の回数
for (int i = 0; i <= n; i++) {
dp[i + 1] = Math.Min(dp[i] + 1, dp[i + 1]);
int pow = 1;
for (int j = 1; j < max6; j++) {
pow *= 6;
int k = pow;
if (i + k >= n + 1)
break;
dp[i + k] = Math.Min(dp[i] + 1, dp[i + k]);
}
pow = 1;
for (int j = 1; j < max9; j++) {
pow *= 9;
int k = pow;
if (i + k >= n + 1)
break;
dp[i + k] = Math.Min(dp[i] + 1, dp[i + k]);
}
}
Console.WriteLine(dp[n]);
}
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) {
int[] r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 549
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSharpSample01 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int ans = N;
for (int i = 1; i <= N; i++) {
int t = i;
int cc = 0;
while (t > 0) {
cc += t % 6;
t = t / 6;
}
t = N - i;
while (t > 0) {
cc += t % 9;
t = t / 9;
}
if (ans > cc)
ans = cc;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSharpSample01 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int ans = N;
for (int i = 0; i <= N; i++) {
int t = i;
int cc = 0;
while (t > 0) {
cc += t % 6;
t = t / 6;
}
t = N - i;
while (t > 0) {
cc += t % 9;
t = t / 9;
}
if (ans > cc)
ans = cc;
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 142
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
// using static System.Globalization.CultureInfo;
class Program {
static void Main(string[] args) {
var num = Input.num;
var res = (int)1e5;
for (var i = 0; i < num; i++) {
var re = num - i;
var ct = 0;
var ct1 = i / 6;
while (ct1 > 5) {
ct += ct1 % 6;
ct1 /= 6;
}
ct += i % 6 + ct1;
var ct2 = re / 9;
while (ct2 > 8) {
ct += ct2 % 9;
ct2 /= 9;
}
ct += re % 9 + ct2;
res = Min(res, ct);
}
WriteLine(res);
}
}
public class Input {
public static string read => ReadLine();
public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
public static int num => ToInt32(read);
public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
public static long numL => ToInt64(read);
public static string[] gred(int h) =>
Enumerable.Repeat(0, h).Select(v => read).ToArray();
public static int[][] twodim(int num) =>
Enumerable.Repeat(0, num).Select(v => ar).ToArray();
public static long[][] twodimL(int num) =>
Enumerable.Repeat(0, num).Select(v => arL).ToArray();
public const long Inf = (long)1e18;
public const double eps = 1e-11;
public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
public const int MOD = 1000000007;
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
// using static System.Globalization.CultureInfo;
class Program {
static void Main(string[] args) {
var num = Input.num;
var res = (int)1e5;
for (var i = 0; i <= num; i++) {
var re = num - i;
var ct = 0;
var ct1 = i / 6;
while (ct1 > 5) {
ct += ct1 % 6;
ct1 /= 6;
}
ct += i % 6 + ct1;
var ct2 = re / 9;
while (ct2 > 8) {
ct += ct2 % 9;
ct2 /= 9;
}
ct += re % 9 + ct2;
res = Min(res, ct);
}
WriteLine(res);
}
}
public class Input {
public static string read => ReadLine();
public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
public static int num => ToInt32(read);
public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
public static long numL => ToInt64(read);
public static string[] gred(int h) =>
Enumerable.Repeat(0, h).Select(v => read).ToArray();
public static int[][] twodim(int num) =>
Enumerable.Repeat(0, num).Select(v => ar).ToArray();
public static long[][] twodimL(int num) =>
Enumerable.Repeat(0, num).Select(v => arL).ToArray();
public const long Inf = (long)1e18;
public const double eps = 1e-11;
public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
public const int MOD = 1000000007;
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 412
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var num = ToInt32(ReadLine());
var res = num;
for (var i = 0; i < num; i++) {
var cc = 0;
var t = i;
while (t > 0) {
cc += t % 6;
t /= 6;
}
t = num - i;
while (t > 0) {
cc += t % 9;
t /= 9;
}
res = Min(res, cc);
}
WriteLine(res);
}
private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
private const int MOD = 1000000007;
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var num = ToInt32(ReadLine());
var res = num;
for (var i = 0; i <= num; i++) {
var cc = 0;
var t = i;
while (t > 0) {
cc += t % 6;
t /= 6;
}
t = num - i;
while (t > 0) {
cc += t % 9;
t /= 9;
}
res = Min(res, cc);
}
WriteLine(res);
}
private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
private const int MOD = 1000000007;
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 161
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var sc = new Scanner();
int n = sc.NextInt();
int ans = n;
for (int i = 0; i < n; i++) {
int c = 0;
int r = i;
// iまでの金額を6^p円で引き出す回数
while (r > 0) {
c += r % 6;
r /= 6;
}
// n - iの金額を9^p円で引き出す回数
r = n - i;
while (r > 0) {
c += r % 9;
r /= 9;
}
if (c < ans)
ans = c;
}
Console.WriteLine(ans);
}
}
class Scanner {
int index = -1;
string[] buf;
public Scanner() {}
public int NextInt() {
CheckNext();
return int.Parse(buf[index++]);
}
public long NextLong() {
CheckNext();
return long.Parse(buf[index++]);
}
public double NextDouble() {
CheckNext();
return double.Parse(buf[index++]);
}
public string NextString() {
CheckNext();
return buf[index++];
}
private void CheckNext() {
if (index >= 0 && index < buf.Length)
return;
buf = Console.ReadLine().Split(' ');
index = 0;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var sc = new Scanner();
int n = sc.NextInt();
int ans = n;
for (int i = 0; i <= n; i++) {
int c = 0;
int r = i;
// iまでの金額を6^p円で引き出す回数
while (r > 0) {
c += r % 6;
r /= 6;
}
// n - iの金額を9^p円で引き出す回数
r = n - i;
while (r > 0) {
c += r % 9;
r /= 9;
}
if (c < ans)
ans = c;
}
Console.WriteLine(ans);
}
}
class Scanner {
int index = -1;
string[] buf;
public Scanner() {}
public int NextInt() {
CheckNext();
return int.Parse(buf[index++]);
}
public long NextLong() {
CheckNext();
return long.Parse(buf[index++]);
}
public double NextDouble() {
CheckNext();
return double.Parse(buf[index++]);
}
public string NextString() {
CheckNext();
return buf[index++];
}
private void CheckNext() {
if (index >= 0 && index < buf.Length)
return;
buf = Console.ReadLine().Split(' ');
index = 0;
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 299
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.Virtual {
class ABC099_C {
static void Main(string[] args) {
Method(args);
ReadLine();
}
static void Method(string[] args) {
int n = ReadInt();
int length = n / 9 + 1;
List<int> sixes = new List<int>();
int val = 1;
while (val < n) {
val *= 6;
sixes.Add(val * 6);
}
List<int> nines = new List<int>();
val = 1;
while (val < n) {
val *= 9;
nines.Add(val);
}
int res = int.MaxValue;
for (int i = 0; i < length; i++) {
int now = n - 9 * i;
int cnt = 0;
for (int j = sixes.Count - 1; j >= 0; j--) {
cnt += now / sixes[j];
now %= sixes[j];
}
cnt += now;
now = 9 * i;
for (int j = nines.Count - 1; j >= 0; j--) {
cnt += now / nines[j];
now %= nines[j];
}
res = Min(res, cnt);
}
WriteLine(res);
}
private static string Read() { return ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.Virtual {
class ABC099_C {
static void Main(string[] args) {
Method(args);
ReadLine();
}
static void Method(string[] args) {
int n = ReadInt();
int length = n / 9 + 1;
List<int> sixes = new List<int>();
int val = 1;
while (val < n) {
val *= 6;
sixes.Add(val);
}
List<int> nines = new List<int>();
val = 1;
while (val < n) {
val *= 9;
nines.Add(val);
}
int res = int.MaxValue;
for (int i = 0; i < length; i++) {
int now = n - 9 * i;
int cnt = 0;
for (int j = sixes.Count - 1; j >= 0; j--) {
cnt += now / sixes[j];
now %= sixes[j];
}
cnt += now;
now = 9 * i;
for (int j = nines.Count - 1; j >= 0; j--) {
cnt += now / nines[j];
now %= nines[j];
}
res = Min(res, cnt);
}
WriteLine(res);
}
private static string Read() { return ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 450
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
// using static System.Linq.Enumerable;
using static System.Console;
using static AtCoder.Util;
using static AtCoder.Cin;
using static System.Math;
using static AtCoder.MyMath;
using static AtCoder.StreamExtensions;
using static AtCoder.Matrix;
namespace AtCoder {
using VI = VectorInt2;
static class Program {
static void Main() {
// var n = ReadInt();
var n = 14248;
var sixes = 1L.Iterate(Mul(6L)).TakeWhile(Leq((long)n));
var nines = 1L.Iterate(Mul(9L)).TakeWhile(Leq((long)n));
// 可能な引き出し方一覧
var coins = sixes.Concat(nines).ToList();
coins.Sort();
var dp = new int[n + 1]; // dp[x] ... x円引き出すのに最小何回かかるか
FromTo(1, n).ForEach(
i => dp[i] =
coins.TakeWhile(Leq((long)i)).Select(x => 1 + dp[i - x]).Min());
dp[n].WriteLine();
}
}
}
/* ***************** Following Contents are my common library ******** */
namespace AtCoder {
static class Algorithm {
public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger,
long width) =>
BinSearch(range, isBigger, x => range.Right - range.Left < width);
public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger,
Func<LongRange, bool> stopCondition) {
if (stopCondition(range))
return range;
var middle = range.Left + (range.Right - range.Left) / 2;
return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle),
isBigger, stopCondition)
: BinSearch(new LongRange(middle, range.Right),
isBigger, stopCondition);
}
}
static class MyMath {
public static int DivRoundUp(int a, int b) {
var q = a / b;
if (a % b != 0)
q++;
return q;
}
public static long GCD(long a,
long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a;
public static long
GCD(this IEnumerable<long> source) => source.Aggregate(GCD);
public static long LCM(long a, long b) {
var g = GCD(a, b);
var a1 = a / g;
var b1 = b / g;
return g * a1 * b1;
}
public static long
LCM(this IEnumerable<long> source) => source.Aggregate(LCM);
public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Mul);
public static long nPr(int n, int r) => r < 0 || r > n? 0
: FromTo(n - r + 1, n)
.Select(x => (long)x)
.Aggregate(1L, Mul);
public static long nCr(int n, int r) => nPr(n, r) / Factorial(r);
public static long Inc(long i) => i + 1;
public static long Dec(long i) => i - 1;
public static long Plus(long i, long j) => i + j;
public static Func<long, long> Plus(long j) => i => i + j;
public static long Minus(long i, long j) => i - j;
public static Func<long, long> Minus(long j) => i => i - j;
public static long Mul(long i, long j) => i * j;
public static Func<long, long> Mul(long j) => i => i * j;
public static long Div(long i, long j) => j / j;
public static Func<long, long> Div(long j) => i => i * j;
public static long Mod(long i, long j) => i % j;
public static Func<long, long> Mod(long j) => i => i % j;
public static Func<long, bool> Leq(long j) => i => i <= j;
public static Func<long, bool> Gt(long j) => i => i > j;
public static Func<long, bool> Geq(long j) => i => i >= j;
public static Func<long, bool> Eq(long j) => i => i == j;
public static Func<long, bool> Neq(long j) => i => i != j;
public static int Plus(int i, int j) => i + j;
public static Func<int, int> Plus(int j) => i => i + j;
public static int Minus(int i, int j) => i - j;
public static Func<int, int> Minus(int j) => i => i - j;
public static int Mul(int i, int j) => i * j;
public static Func<int, int> Mul(int j) => i => i * j;
public static int Div(int i, int j) => j / j;
public static Func<int, int> Div(int j) => i => i * j;
public static int Mod(int i, int j) => i % j;
public static Func<int, int> Mod(int j) => i => i % j;
public static Func<int, bool> Lt(int j) => i => i < j;
public static Func<int, bool> Leq(int j) => i => i <= j;
public static Func<int, bool> Gt(int j) => i => i > j;
public static Func<int, bool> Geq(int j) => i => i >= j;
public static Func<int, bool> Eq(int j) => i => i == j;
public static Func<int, bool> Neq(int j) => i => i != j;
public static long Max(params long[] ns) => ns.Max();
public static long LowerBound(this long m, long lbound) => Max(m, lbound);
public static long UpperBound(this long m, long ubound) => Min(m, ubound);
public static long Bound(this long m, long lowerBound, long UpperBound) =>
m.LowerBound(lowerBound).UpperBound(UpperBound);
public static long LowerBound(this int m, long lbound) => Max(m, lbound);
public static long UpperBound(this int m, long ubound) => Min(m, ubound);
public static long Bound(this int m, long lowerBound, long UpperBound) =>
m.LowerBound(lowerBound).UpperBound(UpperBound);
public static bool InRange(this long x, long min, long max) => min <= x
&& x <= max;
public static bool IsEven(this int x) => x % 2 == 0;
public static bool IsOdd(this int x) => x % 2 != 0;
public static bool IsEven(this long x) => x % 2 == 0;
public static bool IsOdd(this long x) => x % 2 != 0;
public static IEnumerable<int>
ToDigits(this long n) => n.ToString().Select(x => x.ToInt());
public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits();
public static IEnumerable<int> Factors(this int n) {
for (int i = 1; i <= n; i++)
if (n % i == 0)
yield return i;
}
public static IEnumerable<long> Factors(this long n) {
for (long i = 1; i <= n; i++)
if (n % i == 0)
yield return i;
}
public static MultiSet<long> Factorize(this long n) {
var factors = new MultiSet<long>();
for (long i = 2; i * i <= n; i++) {
while (n % i == 0) {
n /= i;
factors[i]++;
}
}
if (n > 1)
factors.Add(n);
return factors;
}
public static IEnumerable<int> Natural() {
for (int i = 0;; i++)
yield return i;
}
public static IEnumerable<int> Positive() => Natural().Skip(1);
public static long Pow(this long i,
long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1);
public static long Pow(this int i,
long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1);
public static int IntLog(this long n, long baseNum) {
int count = 0;
while (n >= baseNum) {
n /= baseNum;
count++;
}
return count;
}
}
static class Util {
public static InvalidOperationException UnreachableException =
new InvalidOperationException("unreachable.");
public static string
Show(this IEnumerable<char> source) => new string(source.ToArray());
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source);
public static MultiSet<T>
ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t);
public static bool IsPalindrome(string s) {
for (int i = 0; i < s.Length / 2; i++) {
if (s[i] != s[s.Length - 1 - i])
return false;
}
return true;
}
public readonly static VectorInt2[] Dir8 = {
new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1),
new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1),
new VectorInt2(1, 0), new VectorInt2(1, 1)
};
public const long MODCONST = 1000000007;
public static T debug<T>(this T value) {
Console.Error.WriteLine($"debug:{value}");
return value;
}
public static T Id<T>(T t) => t;
public static long ToLong(this String s) => long.Parse(s);
public static long ToLong(this char c) => c - '0';
public static int ToInt(this String s) => int.Parse(s);
public static int ToInt(this char c) => c - '0';
public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(),
ReadInt());
public static VectorDouble2
ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt());
public static string ReplaceX(this string input, string pattern,
string replace) => Regex.Replace(input, pattern,
replace);
public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j);
public static IEnumerable<long> Range(long i, long j) {
for (long k = i; k < i + j; k++)
yield return k;
}
public static void Swap<T>(this IList<T> enumerable, int i, int j) {
var buf = enumerable[i];
enumerable[i] = enumerable[j];
enumerable[j] = buf;
}
public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t);
}
static class ParametricExtensions {
public static Func<S, U> Then<S, T, U>(this Func<S, T> f,
Func<T, U> g) => x => g(f(x));
public static Func<S, U> Compose<S, T, U>(this Func<T, U> f,
Func<S, T> g) => x => f(g(x));
public static void Call<T>(this T t, Action<T> action) => action(t);
public static void WriteLine<T>(this T t) => Console.WriteLine(t);
public static void Write<T>(this T t) => Console.Write(t);
public static T Call<S, T>(this S s, Func<S, T> func) => func(s);
public static S Call<S>(this S s, Func<S, S> func,
int times) => times == 0
? s
: Call(func(s), func, times - 1);
}
static class StreamExtensions {
public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) {
int half = (j - i) / 2;
for (int k = 0; k <= half; k++)
enumerable.Swap(i + k, j - k);
}
public static bool
isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any();
public static void Times(this int n, Action action) {
for (int i = 0; i < n; i++)
action();
}
public static void Times(this long n, Action action) {
for (long i = 0; i < n; i++)
action();
}
public static IEnumerable<T> Times<T>(this int n, Func<T> func) {
for (long i = 0; i < n; i++)
yield return func();
}
public static IEnumerable<T> Times<T>(this long n, Func<T> func) {
for (long i = 0; i < n; i++)
yield return func();
}
public static IEnumerable<T> Iterate<T>(this T init, Func<T, T> f) {
yield return init;
foreach (var item in Iterate(f(init), f))
yield return item;
}
public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) {
foreach (var v in e)
action(v);
}
public static long
Prod(this IEnumerable<long> source) => source.Aggregate(Mul);
public static IEnumerable<int> FromTo(int a,
int b) => Range(a, Max(b - a + 1, 0));
public static IEnumerable<T> Repeat<T>(T t) {
while (true)
yield return t;
}
public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n);
public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) {
while (true)
foreach (var v in e)
yield return v;
}
public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init,
Func<T, S, T> accumulator) {
var result = init;
foreach (var item in source) {
result = accumulator(result, item);
yield return result;
}
}
public static T[] ToArray<T>(params T[] ns) => ns;
public static List<T> ToList<T>(params T[] ns) => ns.ToList();
public static Dictionary<T1, T2>
ToDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) {
var dict = new Dictionary<T1, T2>();
source.ForEach(x => dict.Add(x.Key, x.Value));
return dict;
}
public static SortedDictionary<T1, T2>
ToSortedDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) =>
new SortedDictionary<T1, T2>(source.ToDictionary());
public static MultiSet<T>
ToMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) =>
new MultiSet<T>(source);
public static SortedMultiSet<T>
ToSortedMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) =>
new SortedMultiSet<T>(source);
public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init,
Func<T, S, T> accumulator) {
yield return init;
foreach (var item in Scan(source, init, accumulator))
yield return item;
}
public static IEnumerable<Tuple<T1, T2>>
Cartesian<T1, T2>(IEnumerable<T1> s1,
IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select
new Tuple<T1, T2>(v1, v2);
public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>(
IEnumerable<T1> s1, IEnumerable<T2> s2,
IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select
new Tuple<T1, T2, T3>(v1, v2, v3);
public static IEnumerable<Tuple<T1, T2, T3, T4>>
Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2,
IEnumerable<T3> s3, IEnumerable<T4> s4) =>
from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select
new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4);
public static IEnumerable<Tuple<int, T>> Enumerate<T>(IEnumerable<T> source) {
int i = 0;
foreach (var item in source) {
yield return new Tuple<int, T>(i, item);
i++;
}
}
public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source,
int length) {
while (source.Any()) {
yield return source.Take(length).ToList();
source = source.Skip(length);
}
}
public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) {
T max = source.First();
foreach (var item in source)
if (selector(item) > selector(max))
max = item;
return max;
}
public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) {
T min = source.First();
foreach (var item in source)
if (selector(item) < selector(min))
min = item;
return min;
}
public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) {
for (int i = 0; i < source.Count; i++)
if (condition(source[i]))
return i;
return -1;
}
public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) =>
ChunkBy(source, Id, EqualityComparer<T>.Default);
public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source,
Func<T, S> selector) =>
ChunkBy(source, selector, EqualityComparer<S>.Default);
public static IEnumerable<List<T>>
ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector,
IEqualityComparer<S> comparer) {
while (source.Any()) {
var v = selector(source.First());
var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList();
yield return l;
source = source.Skip(l.Count());
}
}
}
static class Matrix {
public static List<List<T>> Transpose<T>(this List<List<T>> source) =>
Range(0, source[0].Count)
.Select(i => source.Select(x => x[i]).ToList())
.ToList();
public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) {
foreach (var line in source)
line.Show().WriteLine();
}
public static List<List<long>>
ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList();
public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source,
Func<S, T> f) =>
source.Select(x => x.Select(f).ToList()).ToList();
}
static class Cin {
private static Queue<string> tokens;
static Cin() {
string line;
tokens = new Queue<string>();
while ((line = Console.ReadLine()) != null) {
foreach (var token in line.Split(' ')) {
tokens.Enqueue(token);
}
}
}
static public int ReadInt() => int.Parse(tokens.Dequeue());
static public List<int> ReadInt(long n) {
var list = new List<int>();
n.Times(() => list.Add(ReadInt()));
return list;
}
static public long ReadLong() => long.Parse(tokens.Dequeue());
static public List<long> ReadLong(long n) {
var list = new List<long>();
n.Times(() => list.Add(ReadLong()));
return list;
}
static public string ReadString() => tokens.Dequeue();
static public List<string> ReadString(long n) {
var list = new List<string>();
n.Times(() => list.Add(ReadString()));
return list;
}
static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine();
static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine();
}
public struct VectorInt2 {
public int X { get; set; }
public int Y { get; set; }
public VectorInt2(int x, int y) {
X = x;
Y = y;
}
static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X + v2.X, v1.Y + v2.Y);
static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X - v2.X, v1.Y - v2.Y);
static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X * v2.X, v1.Y *v2.Y);
static public VectorInt2
operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i);
static public VectorInt2
operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y);
static public VectorInt2
operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i);
public override string ToString() => $"({X}, {Y})";
}
struct VectorDouble2 {
public double X { get; set; }
public double Y { get; set; }
public VectorDouble2(double x, double y) {
X = x;
Y = y;
}
static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y);
static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y);
static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y);
static public VectorDouble2
operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i);
static public VectorDouble2
operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y);
static public VectorDouble2 operator /(VectorDouble2 v1, double i) =>
new VectorDouble2(v1.X / i, v1.Y / i);
public override string ToString() => $"({X}, {Y})";
public VectorDouble2
Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian),
X *Sin(radian) + Y * Cos(radian));
}
public struct LongRange {
public long Left;
public long Right;
public LongRange(long left, long right) {
Left = left;
Right = right;
}
}
public struct LongFromToVector {
public VectorInt2 Start;
public VectorInt2 End;
public LongFromToVector(VectorInt2 start, VectorInt2 end) {
Start = start;
End = end;
}
}
}
namespace AtCoder {
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System;
class MultiSet<T> : ICollection<T> {
// TODO: 順番がグチャグチャなので整理する
Dictionary<T, long> occurrence;
public MultiSet() { occurrence = new Dictionary<T, long>(); }
public MultiSet(MultiSet<T> source) : this(source.occurrence) {}
public MultiSet(Dictionary<T, long> source) {
occurrence = new Dictionary<T, long>(source);
Validate();
}
public MultiSet(IEnumerable<T> source) {
occurrence = new Dictionary<T, long>();
AddRange(source);
}
public MultiSet(IEnumerable<KeyValuePair<T, long>> source) {
occurrence = new Dictionary<T, long>();
foreach (var item in source)
this[item.Key] += item.Value;
}
public void Add(T data) {
if (!occurrence.ContainsKey(data)) {
occurrence[data] = 1;
return;
}
occurrence[data]++;
}
public void Clear() => occurrence.Clear();
public void Add(T key, int value) {
if (value <= 0)
throw new ArgumentException();
if (!occurrence.ContainsKey(key)) {
occurrence[key] = value;
return;
}
occurrence[key] += value;
}
public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value);
public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add);
public bool Remove(T data) {
if (!occurrence.ContainsKey(data))
return false;
occurrence[data]--;
if (occurrence[data] == 0)
occurrence.Remove(data);
return true;
}
// IDictionary
public long this[T key] {
get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; }
set {
if (value <= 0)
throw new ArgumentException();
occurrence[key] = value;
}
}
public ICollection<T> Keys {
get { return occurrence.Keys; }
}
public ICollection<long> Values {
get { return occurrence.Values; }
}
public IEnumerable<KeyValuePair<T, long>> KeyValuePairs {
get {
foreach (var pair in occurrence)
yield return pair;
}
}
public bool ContainsKey(T key) => occurrence.ContainsKey(key);
public bool Contains(T key) => ContainsKey(key);
public bool TryGetValue(T key, out long value) {
value = this[key];
return true;
}
// /IDictionary
public long LongCount() => occurrence.Values.Sum();
public int Count => (int)occurrence.Values.Sum();
public bool IsReadOnly => false;
public void CopyTo(T[] array, int index) {
foreach (var pair in occurrence) {
for (int i = 0; i < pair.Value; i++) {
array[index] = pair.Key;
index++;
}
}
}
public IEnumerator<T> GetEnumerator() {
foreach (var pair in occurrence)
for (int i = 0; i < pair.Value; i++)
yield return pair.Key;
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public void Validate() {
if (occurrence.Values.Any(x => x <= 0))
throw new ArgumentException();
}
}
class SortedMultiSet<T> : ICollection<T> {
// TODO: 順番がグチャグチャなので整理する
SortedDictionary<T, long> occurrence;
public SortedMultiSet() { occurrence = new SortedDictionary<T, long>(); }
public SortedMultiSet(SortedMultiSet<T> source) : this(source.occurrence) {}
public SortedMultiSet(SortedDictionary<T, long> source) {
occurrence = new SortedDictionary<T, long>(source);
Validate();
}
public SortedMultiSet(IEnumerable<T> source) {
occurrence = new SortedDictionary<T, long>();
AddRange(source);
}
public SortedMultiSet(IEnumerable<KeyValuePair<T, long>> source) {
occurrence = new SortedDictionary<T, long>();
foreach (var item in source)
this[item.Key] += item.Value;
}
public void Add(T data) {
if (!occurrence.ContainsKey(data)) {
occurrence[data] = 1;
return;
}
occurrence[data]++;
}
public void Clear() => occurrence.Clear();
public void Add(T key, int value) {
if (value <= 0)
throw new ArgumentException();
if (!occurrence.ContainsKey(key)) {
occurrence[key] = value;
return;
}
occurrence[key] += value;
}
public long LongCount() => occurrence.Values.Sum();
public int Count => (int)occurrence.Values.Sum();
public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value);
public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add);
public bool Remove(T data) {
if (!occurrence.ContainsKey(data))
return false;
occurrence[data]--;
if (occurrence[data] == 0)
occurrence.Remove(data);
return true;
}
// IDictionary
public long this[T key] {
get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; }
set {
if (value <= 0)
throw new ArgumentException();
occurrence[key] = value;
}
}
public ICollection<T> Keys => occurrence.Keys;
public ICollection<long> Values => occurrence.Values;
public bool ContainsKey(T key) => occurrence.ContainsKey(key);
public bool Contains(T key) => ContainsKey(key);
public bool TryGetValue(T key, out long value) {
value = this[key];
return true;
}
// /IDictionary
public bool IsReadOnly => false;
public void CopyTo(T[] array, int index) {
foreach (var pair in occurrence) {
for (int i = 0; i < pair.Value; i++) {
array[index] = pair.Key;
index++;
}
}
}
public IEnumerator<T> GetEnumerator() {
foreach (var pair in occurrence)
for (int i = 0; i < pair.Value; i++)
yield return pair.Key;
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public void Validate() {
if (occurrence.Values.Any(x => x <= 0))
throw new ArgumentException();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
// using static System.Linq.Enumerable;
using static System.Console;
using static AtCoder.Util;
using static AtCoder.Cin;
using static System.Math;
using static AtCoder.MyMath;
using static AtCoder.StreamExtensions;
using static AtCoder.Matrix;
namespace AtCoder {
using VI = VectorInt2;
static class Program {
static void Main() {
var n = ReadInt();
var sixes = 1L.Iterate(Mul(6L)).TakeWhile(Leq((long)n));
var nines = 1L.Iterate(Mul(9L)).TakeWhile(Leq((long)n));
// 可能な引き出し方一覧
var coins = sixes.Concat(nines).ToList();
coins.Sort();
var dp = new int[n + 1]; // dp[x] ... x円引き出すのに最小何回かかるか
FromTo(1, n).ForEach(
i => dp[i] =
coins.TakeWhile(Leq((long)i)).Select(x => 1 + dp[i - x]).Min());
dp[n].WriteLine();
}
}
}
/* ***************** Following Contents are my common library ******** */
namespace AtCoder {
static class Algorithm {
public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger,
long width) =>
BinSearch(range, isBigger, x => range.Right - range.Left < width);
public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger,
Func<LongRange, bool> stopCondition) {
if (stopCondition(range))
return range;
var middle = range.Left + (range.Right - range.Left) / 2;
return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle),
isBigger, stopCondition)
: BinSearch(new LongRange(middle, range.Right),
isBigger, stopCondition);
}
}
static class MyMath {
public static int DivRoundUp(int a, int b) {
var q = a / b;
if (a % b != 0)
q++;
return q;
}
public static long GCD(long a,
long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a;
public static long
GCD(this IEnumerable<long> source) => source.Aggregate(GCD);
public static long LCM(long a, long b) {
var g = GCD(a, b);
var a1 = a / g;
var b1 = b / g;
return g * a1 * b1;
}
public static long
LCM(this IEnumerable<long> source) => source.Aggregate(LCM);
public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Mul);
public static long nPr(int n, int r) => r < 0 || r > n? 0
: FromTo(n - r + 1, n)
.Select(x => (long)x)
.Aggregate(1L, Mul);
public static long nCr(int n, int r) => nPr(n, r) / Factorial(r);
public static long Inc(long i) => i + 1;
public static long Dec(long i) => i - 1;
public static long Plus(long i, long j) => i + j;
public static Func<long, long> Plus(long j) => i => i + j;
public static long Minus(long i, long j) => i - j;
public static Func<long, long> Minus(long j) => i => i - j;
public static long Mul(long i, long j) => i * j;
public static Func<long, long> Mul(long j) => i => i * j;
public static long Div(long i, long j) => j / j;
public static Func<long, long> Div(long j) => i => i * j;
public static long Mod(long i, long j) => i % j;
public static Func<long, long> Mod(long j) => i => i % j;
public static Func<long, bool> Leq(long j) => i => i <= j;
public static Func<long, bool> Gt(long j) => i => i > j;
public static Func<long, bool> Geq(long j) => i => i >= j;
public static Func<long, bool> Eq(long j) => i => i == j;
public static Func<long, bool> Neq(long j) => i => i != j;
public static int Plus(int i, int j) => i + j;
public static Func<int, int> Plus(int j) => i => i + j;
public static int Minus(int i, int j) => i - j;
public static Func<int, int> Minus(int j) => i => i - j;
public static int Mul(int i, int j) => i * j;
public static Func<int, int> Mul(int j) => i => i * j;
public static int Div(int i, int j) => j / j;
public static Func<int, int> Div(int j) => i => i * j;
public static int Mod(int i, int j) => i % j;
public static Func<int, int> Mod(int j) => i => i % j;
public static Func<int, bool> Lt(int j) => i => i < j;
public static Func<int, bool> Leq(int j) => i => i <= j;
public static Func<int, bool> Gt(int j) => i => i > j;
public static Func<int, bool> Geq(int j) => i => i >= j;
public static Func<int, bool> Eq(int j) => i => i == j;
public static Func<int, bool> Neq(int j) => i => i != j;
public static long Max(params long[] ns) => ns.Max();
public static long LowerBound(this long m, long lbound) => Max(m, lbound);
public static long UpperBound(this long m, long ubound) => Min(m, ubound);
public static long Bound(this long m, long lowerBound, long UpperBound) =>
m.LowerBound(lowerBound).UpperBound(UpperBound);
public static long LowerBound(this int m, long lbound) => Max(m, lbound);
public static long UpperBound(this int m, long ubound) => Min(m, ubound);
public static long Bound(this int m, long lowerBound, long UpperBound) =>
m.LowerBound(lowerBound).UpperBound(UpperBound);
public static bool InRange(this long x, long min, long max) => min <= x
&& x <= max;
public static bool IsEven(this int x) => x % 2 == 0;
public static bool IsOdd(this int x) => x % 2 != 0;
public static bool IsEven(this long x) => x % 2 == 0;
public static bool IsOdd(this long x) => x % 2 != 0;
public static IEnumerable<int>
ToDigits(this long n) => n.ToString().Select(x => x.ToInt());
public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits();
public static IEnumerable<int> Factors(this int n) {
for (int i = 1; i <= n; i++)
if (n % i == 0)
yield return i;
}
public static IEnumerable<long> Factors(this long n) {
for (long i = 1; i <= n; i++)
if (n % i == 0)
yield return i;
}
public static MultiSet<long> Factorize(this long n) {
var factors = new MultiSet<long>();
for (long i = 2; i * i <= n; i++) {
while (n % i == 0) {
n /= i;
factors[i]++;
}
}
if (n > 1)
factors.Add(n);
return factors;
}
public static IEnumerable<int> Natural() {
for (int i = 0;; i++)
yield return i;
}
public static IEnumerable<int> Positive() => Natural().Skip(1);
public static long Pow(this long i,
long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1);
public static long Pow(this int i,
long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1);
public static int IntLog(this long n, long baseNum) {
int count = 0;
while (n >= baseNum) {
n /= baseNum;
count++;
}
return count;
}
}
static class Util {
public static InvalidOperationException UnreachableException =
new InvalidOperationException("unreachable.");
public static string
Show(this IEnumerable<char> source) => new string(source.ToArray());
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source);
public static MultiSet<T>
ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t);
public static bool IsPalindrome(string s) {
for (int i = 0; i < s.Length / 2; i++) {
if (s[i] != s[s.Length - 1 - i])
return false;
}
return true;
}
public readonly static VectorInt2[] Dir8 = {
new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1),
new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1),
new VectorInt2(1, 0), new VectorInt2(1, 1)
};
public const long MODCONST = 1000000007;
public static T debug<T>(this T value) {
Console.Error.WriteLine($"debug:{value}");
return value;
}
public static T Id<T>(T t) => t;
public static long ToLong(this String s) => long.Parse(s);
public static long ToLong(this char c) => c - '0';
public static int ToInt(this String s) => int.Parse(s);
public static int ToInt(this char c) => c - '0';
public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(),
ReadInt());
public static VectorDouble2
ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt());
public static string ReplaceX(this string input, string pattern,
string replace) => Regex.Replace(input, pattern,
replace);
public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j);
public static IEnumerable<long> Range(long i, long j) {
for (long k = i; k < i + j; k++)
yield return k;
}
public static void Swap<T>(this IList<T> enumerable, int i, int j) {
var buf = enumerable[i];
enumerable[i] = enumerable[j];
enumerable[j] = buf;
}
public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t);
}
static class ParametricExtensions {
public static Func<S, U> Then<S, T, U>(this Func<S, T> f,
Func<T, U> g) => x => g(f(x));
public static Func<S, U> Compose<S, T, U>(this Func<T, U> f,
Func<S, T> g) => x => f(g(x));
public static void Call<T>(this T t, Action<T> action) => action(t);
public static void WriteLine<T>(this T t) => Console.WriteLine(t);
public static void Write<T>(this T t) => Console.Write(t);
public static T Call<S, T>(this S s, Func<S, T> func) => func(s);
public static S Call<S>(this S s, Func<S, S> func,
int times) => times == 0
? s
: Call(func(s), func, times - 1);
}
static class StreamExtensions {
public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) {
int half = (j - i) / 2;
for (int k = 0; k <= half; k++)
enumerable.Swap(i + k, j - k);
}
public static bool
isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any();
public static void Times(this int n, Action action) {
for (int i = 0; i < n; i++)
action();
}
public static void Times(this long n, Action action) {
for (long i = 0; i < n; i++)
action();
}
public static IEnumerable<T> Times<T>(this int n, Func<T> func) {
for (long i = 0; i < n; i++)
yield return func();
}
public static IEnumerable<T> Times<T>(this long n, Func<T> func) {
for (long i = 0; i < n; i++)
yield return func();
}
public static IEnumerable<T> Iterate<T>(this T init, Func<T, T> f) {
yield return init;
foreach (var item in Iterate(f(init), f))
yield return item;
}
public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) {
foreach (var v in e)
action(v);
}
public static long
Prod(this IEnumerable<long> source) => source.Aggregate(Mul);
public static IEnumerable<int> FromTo(int a,
int b) => Range(a, Max(b - a + 1, 0));
public static IEnumerable<T> Repeat<T>(T t) {
while (true)
yield return t;
}
public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n);
public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) {
while (true)
foreach (var v in e)
yield return v;
}
public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init,
Func<T, S, T> accumulator) {
var result = init;
foreach (var item in source) {
result = accumulator(result, item);
yield return result;
}
}
public static T[] ToArray<T>(params T[] ns) => ns;
public static List<T> ToList<T>(params T[] ns) => ns.ToList();
public static Dictionary<T1, T2>
ToDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) {
var dict = new Dictionary<T1, T2>();
source.ForEach(x => dict.Add(x.Key, x.Value));
return dict;
}
public static SortedDictionary<T1, T2>
ToSortedDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) =>
new SortedDictionary<T1, T2>(source.ToDictionary());
public static MultiSet<T>
ToMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) =>
new MultiSet<T>(source);
public static SortedMultiSet<T>
ToSortedMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) =>
new SortedMultiSet<T>(source);
public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init,
Func<T, S, T> accumulator) {
yield return init;
foreach (var item in Scan(source, init, accumulator))
yield return item;
}
public static IEnumerable<Tuple<T1, T2>>
Cartesian<T1, T2>(IEnumerable<T1> s1,
IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select
new Tuple<T1, T2>(v1, v2);
public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>(
IEnumerable<T1> s1, IEnumerable<T2> s2,
IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select
new Tuple<T1, T2, T3>(v1, v2, v3);
public static IEnumerable<Tuple<T1, T2, T3, T4>>
Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2,
IEnumerable<T3> s3, IEnumerable<T4> s4) =>
from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select
new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4);
public static IEnumerable<Tuple<int, T>> Enumerate<T>(IEnumerable<T> source) {
int i = 0;
foreach (var item in source) {
yield return new Tuple<int, T>(i, item);
i++;
}
}
public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source,
int length) {
while (source.Any()) {
yield return source.Take(length).ToList();
source = source.Skip(length);
}
}
public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) {
T max = source.First();
foreach (var item in source)
if (selector(item) > selector(max))
max = item;
return max;
}
public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) {
T min = source.First();
foreach (var item in source)
if (selector(item) < selector(min))
min = item;
return min;
}
public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) {
for (int i = 0; i < source.Count; i++)
if (condition(source[i]))
return i;
return -1;
}
public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) =>
ChunkBy(source, Id, EqualityComparer<T>.Default);
public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source,
Func<T, S> selector) =>
ChunkBy(source, selector, EqualityComparer<S>.Default);
public static IEnumerable<List<T>>
ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector,
IEqualityComparer<S> comparer) {
while (source.Any()) {
var v = selector(source.First());
var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList();
yield return l;
source = source.Skip(l.Count());
}
}
}
static class Matrix {
public static List<List<T>> Transpose<T>(this List<List<T>> source) =>
Range(0, source[0].Count)
.Select(i => source.Select(x => x[i]).ToList())
.ToList();
public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) {
foreach (var line in source)
line.Show().WriteLine();
}
public static List<List<long>>
ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList();
public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source,
Func<S, T> f) =>
source.Select(x => x.Select(f).ToList()).ToList();
}
static class Cin {
private static Queue<string> tokens;
static Cin() {
string line;
tokens = new Queue<string>();
while ((line = Console.ReadLine()) != null) {
foreach (var token in line.Split(' ')) {
tokens.Enqueue(token);
}
}
}
static public int ReadInt() => int.Parse(tokens.Dequeue());
static public List<int> ReadInt(long n) {
var list = new List<int>();
n.Times(() => list.Add(ReadInt()));
return list;
}
static public long ReadLong() => long.Parse(tokens.Dequeue());
static public List<long> ReadLong(long n) {
var list = new List<long>();
n.Times(() => list.Add(ReadLong()));
return list;
}
static public string ReadString() => tokens.Dequeue();
static public List<string> ReadString(long n) {
var list = new List<string>();
n.Times(() => list.Add(ReadString()));
return list;
}
static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine();
static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine();
}
public struct VectorInt2 {
public int X { get; set; }
public int Y { get; set; }
public VectorInt2(int x, int y) {
X = x;
Y = y;
}
static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X + v2.X, v1.Y + v2.Y);
static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X - v2.X, v1.Y - v2.Y);
static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X * v2.X, v1.Y *v2.Y);
static public VectorInt2
operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i);
static public VectorInt2
operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y);
static public VectorInt2
operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i);
public override string ToString() => $"({X}, {Y})";
}
struct VectorDouble2 {
public double X { get; set; }
public double Y { get; set; }
public VectorDouble2(double x, double y) {
X = x;
Y = y;
}
static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y);
static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y);
static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y);
static public VectorDouble2
operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i);
static public VectorDouble2
operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y);
static public VectorDouble2 operator /(VectorDouble2 v1, double i) =>
new VectorDouble2(v1.X / i, v1.Y / i);
public override string ToString() => $"({X}, {Y})";
public VectorDouble2
Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian),
X *Sin(radian) + Y * Cos(radian));
}
public struct LongRange {
public long Left;
public long Right;
public LongRange(long left, long right) {
Left = left;
Right = right;
}
}
public struct LongFromToVector {
public VectorInt2 Start;
public VectorInt2 End;
public LongFromToVector(VectorInt2 start, VectorInt2 end) {
Start = start;
End = end;
}
}
}
namespace AtCoder {
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System;
class MultiSet<T> : ICollection<T> {
// TODO: 順番がグチャグチャなので整理する
Dictionary<T, long> occurrence;
public MultiSet() { occurrence = new Dictionary<T, long>(); }
public MultiSet(MultiSet<T> source) : this(source.occurrence) {}
public MultiSet(Dictionary<T, long> source) {
occurrence = new Dictionary<T, long>(source);
Validate();
}
public MultiSet(IEnumerable<T> source) {
occurrence = new Dictionary<T, long>();
AddRange(source);
}
public MultiSet(IEnumerable<KeyValuePair<T, long>> source) {
occurrence = new Dictionary<T, long>();
foreach (var item in source)
this[item.Key] += item.Value;
}
public void Add(T data) {
if (!occurrence.ContainsKey(data)) {
occurrence[data] = 1;
return;
}
occurrence[data]++;
}
public void Clear() => occurrence.Clear();
public void Add(T key, int value) {
if (value <= 0)
throw new ArgumentException();
if (!occurrence.ContainsKey(key)) {
occurrence[key] = value;
return;
}
occurrence[key] += value;
}
public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value);
public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add);
public bool Remove(T data) {
if (!occurrence.ContainsKey(data))
return false;
occurrence[data]--;
if (occurrence[data] == 0)
occurrence.Remove(data);
return true;
}
// IDictionary
public long this[T key] {
get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; }
set {
if (value <= 0)
throw new ArgumentException();
occurrence[key] = value;
}
}
public ICollection<T> Keys {
get { return occurrence.Keys; }
}
public ICollection<long> Values {
get { return occurrence.Values; }
}
public IEnumerable<KeyValuePair<T, long>> KeyValuePairs {
get {
foreach (var pair in occurrence)
yield return pair;
}
}
public bool ContainsKey(T key) => occurrence.ContainsKey(key);
public bool Contains(T key) => ContainsKey(key);
public bool TryGetValue(T key, out long value) {
value = this[key];
return true;
}
// /IDictionary
public long LongCount() => occurrence.Values.Sum();
public int Count => (int)occurrence.Values.Sum();
public bool IsReadOnly => false;
public void CopyTo(T[] array, int index) {
foreach (var pair in occurrence) {
for (int i = 0; i < pair.Value; i++) {
array[index] = pair.Key;
index++;
}
}
}
public IEnumerator<T> GetEnumerator() {
foreach (var pair in occurrence)
for (int i = 0; i < pair.Value; i++)
yield return pair.Key;
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public void Validate() {
if (occurrence.Values.Any(x => x <= 0))
throw new ArgumentException();
}
}
class SortedMultiSet<T> : ICollection<T> {
// TODO: 順番がグチャグチャなので整理する
SortedDictionary<T, long> occurrence;
public SortedMultiSet() { occurrence = new SortedDictionary<T, long>(); }
public SortedMultiSet(SortedMultiSet<T> source) : this(source.occurrence) {}
public SortedMultiSet(SortedDictionary<T, long> source) {
occurrence = new SortedDictionary<T, long>(source);
Validate();
}
public SortedMultiSet(IEnumerable<T> source) {
occurrence = new SortedDictionary<T, long>();
AddRange(source);
}
public SortedMultiSet(IEnumerable<KeyValuePair<T, long>> source) {
occurrence = new SortedDictionary<T, long>();
foreach (var item in source)
this[item.Key] += item.Value;
}
public void Add(T data) {
if (!occurrence.ContainsKey(data)) {
occurrence[data] = 1;
return;
}
occurrence[data]++;
}
public void Clear() => occurrence.Clear();
public void Add(T key, int value) {
if (value <= 0)
throw new ArgumentException();
if (!occurrence.ContainsKey(key)) {
occurrence[key] = value;
return;
}
occurrence[key] += value;
}
public long LongCount() => occurrence.Values.Sum();
public int Count => (int)occurrence.Values.Sum();
public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value);
public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add);
public bool Remove(T data) {
if (!occurrence.ContainsKey(data))
return false;
occurrence[data]--;
if (occurrence[data] == 0)
occurrence.Remove(data);
return true;
}
// IDictionary
public long this[T key] {
get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; }
set {
if (value <= 0)
throw new ArgumentException();
occurrence[key] = value;
}
}
public ICollection<T> Keys => occurrence.Keys;
public ICollection<long> Values => occurrence.Values;
public bool ContainsKey(T key) => occurrence.ContainsKey(key);
public bool Contains(T key) => ContainsKey(key);
public bool TryGetValue(T key, out long value) {
value = this[key];
return true;
}
// /IDictionary
public bool IsReadOnly => false;
public void CopyTo(T[] array, int index) {
foreach (var pair in occurrence) {
for (int i = 0; i < pair.Value; i++) {
array[index] = pair.Key;
index++;
}
}
}
public IEnumerator<T> GetEnumerator() {
foreach (var pair in occurrence)
for (int i = 0; i < pair.Value; i++)
yield return pair.Key;
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public void Validate() {
if (occurrence.Values.Any(x => x <= 0))
throw new ArgumentException();
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 6,558
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static List<int[]> list = new List<int[]>();
static int[] yMove = new int[] { -1, 1, 0, 0 };
static int[] xMove = new int[] { 0, 0, -1, 1 };
static bool[,] miz;
static int cnt = 0;
static void Main(string[] args) {
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var N = line1[0];
// var M = line1[1];
// var a = new long[M];
// var b = new long[M];
// int bridge = 0;
// int[,] dag = new int[N,N];
// for (int i = 0; i < M; i++)
//{
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// a[i] = line2[0]-1;
// b[i] = line2[1]-1;
// dag[a[i], b[i]] = 1;
// dag[b[i], a[i]] = 1;
//}
// for (int i = 0; i < M; i++)
//{
// bool[] visited = new bool[N];
// dag[a[i], b[i]] = 0;
// dag[b[i], a[i]] = 0;
// DFS(0,visited,dag);
// if (visited.Where(n => n == true).Count() != N)
// {
// bridge++;
// }
// dag[a[i], b[i]] = 1;
// dag[b[i], a[i]] = 1;
//}
// Console.WriteLine(bridge);
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var A = line1[0];
// var B = line1[1];
// var C = line1[2];
// var D = line1[3];
// var E = line1[4];
// var F = line1[5];
// var N = int.Parse(Console.ReadLine());
// char[] mozi = new char[N];
// long[] MARCH = new long[5];
// long cnt = 0;
// for (int i = 0; i < N; i++)
//{
// mozi[i] = Console.ReadLine().ToCharArray()[0];
//}
// MARCH[0] = mozi.Where(n => n == 'M').Count();
// MARCH[1] = mozi.Where(n => n == 'A').Count();
// MARCH[2] = mozi.Where(n => n == 'R').Count();
// MARCH[3] = mozi.Where(n => n == 'C').Count();
// MARCH[4] = mozi.Where(n => n == 'H').Count();
// for (int i = 0; i < 3; i++)
//{
// for (int j = i + 1; j < 4; j++)
// {
// for (int k = j + 1; k < 5; k++)
// {
// cnt += MARCH[i] * MARCH[j] * MARCH[k];
// }
// }
//}
// Console.WriteLine(cnt);
// var N = int.Parse(Console.ReadLine());
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int candy = 0;
// int MAX = 0;
// for (int i = 0; i < N; i++)
//{
// for (int k = 0; k <= i; k++)
// {
// candy += line1[k];
// }
// for (int j = N - 1; j >= i; j--)
// {
// candy += line2[j];
// }
// MAX = Math.Max(candy,MAX);
// candy = 0;
//}
// Console.WriteLine(MAX);
// var N = int.Parse(Console.ReadLine());
// List<int[]> list = new List<int[]>();
// int t = 0;
// int x = 0;
// int y = 0;
// for (int i = 0; i < N; i++)
//{
// var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// list.Add(txy);
//}
// foreach (var item in list)
//{
// if (item[0] - t >= Math.Abs(item[1] + item[2] - x - y))
// {
// if (((item[0] - t) % 2 == 1 && Math.Abs(x + y - item[1] - item[2])
// % 2 == 1) ||
// ((item[0] - t) % 2 == 0 && Math.Abs(x + y - item[1] - item[2])
// % 2 == 0))
// {
// t = item[0];
// x = item[1];
// y = item[2];
// }
// else
// {
// Console.WriteLine("No");
// return;
// }
// }
// else
// {
// Console.WriteLine("No");
// return;
// }
//}
// Console.WriteLine("Yes");
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// if (line1[1] >= 10000)
//{
// for (int i = 0; i <= line1[1]/10000; i++)
// {
// for (int j = 0; j <= line1[1] / 5000; j++)
// {
// if (10000 * i + 5000 * j + (line1[0] - i - j) * 1000 ==
// line1[1] && line1[0] - i - j >= 0)
// {
// Console.WriteLine("{0} {1} {2}",i,j,line1[0] - i - j);
// return;
// }
// }
// }
//}
// else
//{
// for (int i = 0; i < 2; i++)
// {
// for (int j = 0; j <= 9; j++)
// {
// if (5000 * i + 1000 * j == line1[1] && i + j == line1[0])
// {
// Console.WriteLine("{0} {1} {2}", 0, i, j);
// return;
// }
// }
// }
//}
// Console.WriteLine("{0} {1} {2}", -1, -1, -1);
// var N = int.Parse(Console.ReadLine());
// int[,] station = new int[N,3];
// long sum = 0;
// for (int i = 0; i < N - 1; i++)
//{
// var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// station[i, 0] = line[0];
// station[i, 1] = line[1];
// station[i, 2] = line[2];
//}
// for (int j = 0; j < N -1; j++)
//{
// for (int i = j; i < N - 1; i++)
// {
// var F = station[i, 2];
// var S = station[i, 1];
// if (i == j)
// {
// sum += station[i, 0] + station[i, 1];
// }
// else
// {
// if (sum < S)
// {
// sum = S + station[i, 0];
// }
// else if (sum % F == 0)
// {
// sum += station[i, 0];
// }
// else
// {
// sum += F - (sum % F) + station[i, 0];
// }
// }
// }
// Console.WriteLine(sum);
// sum = 0;
//}
// Console.WriteLine(sum);
// var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// long A = line[0];
// int i = 0;
// while (A <= line[1])
//{
// A *=2;
// i++;
//}
// Console.WriteLine(i);
// var N = long.Parse(Console.ReadLine());
// var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// Dictionary<long, long> dic = new Dictionary<long, long>();
// long sum = 0;
// for (int i = 0; i < N; i++)
//{
// if (dic.ContainsKey(line[i]))
// {
// dic[line[i]]++;
// }
// else
// {
// dic.Add(line[i], 1);
// }
//}
// foreach (var item in dic)
//{
// if (item.Key == item.Value)
// {
// }
// else if (item.Key < item.Value)
// {
// sum += item.Value - item.Key;
// }
// else
// {
// sum += item.Value;
// }
//}
// Console.WriteLine(sum);
// var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// var N = line[0];
// var K = line[1];
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// long cnt = 0;
// long sum = 0;
// long[] lngarray = new long[N];
// for (int i = 0; i < N; i++)
//{
// lngarray[line2[i]-1]++;
//}
// if (lngarray.Where(n => n !=0).Count() <= K)
//{
// Console.WriteLine(0);
// return;
//}
// var orderlng = lngarray.Where(n => n != 0).OrderBy(n => n).ToArray();
// for (int i = 0; i < orderlng.Length; i++)
//{
// if (cnt == orderlng.Length - K)
// {
// Console.WriteLine(sum);
// return;
// }
// else
// {
// sum += orderlng[i];
// cnt++;
// }
//}
// int soe = 0;
// saiki(soe, new int[10]);
// var N = int.Parse(Console.ReadLine());
// var F = new List<int[]>();
// var P = new List<int[]>();
// for (int i = 0; i < N; i++)
//{
// var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// F.Add(line);
//}
// for (int i = 0; i < N; i++)
//{
// var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// P.Add(line);
//}
// int sum = int.MinValue;
// list.RemoveAt(0);
// foreach (var item in list)
//{
// int tmpsum = 0;
// for (int i = 0; i < N; i++)
// {
// int c = 0;
// for (int j = 0; j < 10; j++)
// {
// if (item[j] == 1 && F[i][j] == 1)
// {
// c++;
// }
// }
// tmpsum += P[i][c];
// }
// sum = Math.Max(sum, tmpsum);
//}
// Console.WriteLine(sum);
// var line = Console.ReadLine().ToCharArray();
// int[] hai = new int[7];
// hai[0] = int.Parse(line[0].ToString());
// hai[2] = int.Parse(line[1].ToString());
// hai[4] = int.Parse(line[2].ToString());
// hai[6] = int.Parse(line[3].ToString());
// saikiseven(1,0, hai);
// string ope1 = list[0][1] == 0 ? "+" : "-";
// string ope2 = list[0][3] == 0 ? "+" : "-";
// string ope3 = list[0][5] == 0 ? "+" : "-";
// Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}=7", list[0][0],ope1, list[0][2],
// ope2,list[0][4], ope3,list[0][6]);
// var N = long.Parse(Console.ReadLine());
// var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// long[] A = new long[N];
// for (int i = 0; i < N; i++)
//{
// A[i] = Math.Abs(i - (N - i -1));
//}
// var tmp1 = line.OrderBy(n => n).ToArray();
// var tmp2 = A.OrderBy(n => n).ToArray();
// for (int i = 0; i < N; i++)
//{
// if (tmp1[i] != tmp2[i])
// {
// Console.WriteLine(0);
// return;
// }
//}
// long X = 1;
// for (int i = 0; i < N/2; i++)
//{
// X *= 2;
// X %= 1000000007;
//}
// Console.WriteLine(X);
// var line =Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// var sx = line[0];
// var sy = line[1];
// var tx = line[2];
// var ty = line[3];
// var path1 = new string('U', ty - sy) + new string('R',tx - sx);
// var path2 = new string('D', ty - sy) + new string('L', tx - sx);
// var path3 = new string('L', 1) + new string('U', ty - sy + 1) + new
// string('R', tx - sx + 1) + new string('D', 1); var path4 = new string('R',
// 1) + new string('D', ty - sy + 1) + new string('L', tx - sx + 1) + new
// string('U', 1); Console.WriteLine(path1 + path2 + path3 + path4); int[]
// sosuu = new int[1000];
// var N = int.Parse(Console.ReadLine());
// int[] sosuu = new int[1001];
// long ans = 1;
// for (int i = 1; i < N + 1; i++)
//{
// PrimeFactors(i, sosuu);
//}
// for (int i = 2; i < N + 1; i++)
//{
// ans *= sosuu[i] + 1;
// ans %= 1000000007;
//}
// Console.WriteLine(ans);
// var N = long.Parse(Console.ReadLine());
// long X = 0;
// long Y = 0;
// X = N / 11;
// if ((N - (11 * X)) == 0)
//{
// Y = 0;
//}
// else if ((N - (11 * X)) <= 6)
//{
// Y = 1;
//}
// else
//{
// Y = 2;
//}
// Console.WriteLine(X * 2 + Y);
// var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var N = line[0];
// var M = line[1];
// int[,] RL = new int[N, N];
// for (int i = 0; i < M; i++)
//{
// var tmp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// RL[tmp[0]-1, tmp[1]-1] = 1;
// RL[tmp[1]-1, tmp[0]-1] = 1;
//}
// bool[] visit = new bool[N];
// DFSgraph(RL,visit,0);
// Console.WriteLine(cnt);
// var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var N = line[0];
// var M = line[1];
// if (N * 2 < M)
//{
// Console.WriteLine(N + (M - 2 * N) /4);
//}
// else
//{
// Console.WriteLine(M/2);
//}
// var N = int.Parse(Console.ReadLine());
// var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int[,] dp = new int[N + 1, 10001];
////for (int i = 0; i < N; i++)
////{
//// dp[0, line[0]] = line[i];
////}
// for (int i = 0; i < N; i++)
//{
// for (int j = 0; j < 10001; j++)
// {
// dp[i + 1, line[i]] = line[i];
// if (dp[i,j] != 0)
// {
// dp[i + 1, j] = dp[i, j];
// dp[i + 1, dp[i, j] + line[i]] = line[i] + dp[i, j];
// }
// }
//}
// long ans = 0;
// for (int i = 0; i < 10001; i++)
//{
// if (dp[N,i] != 0)
// {
// ans++;
// }
//}
// Console.WriteLine(ans + 1);
// var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// var A = line[0];
// var B = line[1];
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var line3 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int[] a = new int[A];
// int[] b = new int[B];
// for (int i = 0; i < A; i++)
//{
// a[i] = line2[i];
//}
// for (int i = 0; i < B; i++)
//{
// b[i] = line3[i];
//}
// int AB = A + B;
// int[,] dp = new int[A + 1, B + 1];
// for (int i = 1; i <= A; i++)
//{
// if ((AB - i) % 2 == 0)
// {
// dp[i, 0] = dp[i - 1, 0] + a[A - i];
// }
// else
// {
// dp[i, 0] = dp[i - 1, 0];
// }
//}
// for (int i = 1; i <= B; i++)
//{
// if ((AB - i) % 2 == 0)
// {
// dp[0, i] = dp[0, i -1] + b[B - i];
// }
// else
// {
// dp[0, i] = dp[0, i -1];
// }
//}
// for (int i = 1; i <= A; i++)
//{
// for (int j = 1; j <= B; j++)
// {
// if ((AB - i - j) % 2 == 0)
// {
// dp[i, j] = Math.Max(dp[i -1,j] + a[A - i],dp[i,j-1] + b[B -
// j]);
// }
// else
// {
// dp[i, j] = Math.Min(dp[i - 1, j] , dp[i, j - 1]);
// }
// }
//}
// Console.WriteLine(dp[A,B]);
var N = int.Parse(Console.ReadLine());
int[] dp = new int[N + 1];
for (int i = 1; i <= N; i++) {
dp[i] = i;
}
List<int> hai = new List<int>();
int loop = 6;
while (N >= loop) {
hai.Add(loop);
loop *= 6;
}
loop = 9;
while (N >= loop) {
hai.Add(loop);
loop *= 9;
}
var hai2 = hai.OrderBy(n => n).ToArray();
foreach (var item in hai) {
for (int i = 1; i < N; i++) {
if (i + item <= N) {
dp[i + item] = Math.Min(dp[i + item], dp[i] + 1);
}
}
}
Console.WriteLine(dp[N]);
}
public static void DFSgraph(int[,] RL, bool[] visit, int v) {
visit[v] = true;
if (visit.Where(n => n == true).Count() == visit.Length) {
cnt++;
return;
}
for (int i = 0; i < visit.Length; i++) {
if (RL[v, i] == 0)
continue;
if (visit[i])
continue;
bool[] tmpvisit = new bool[visit.Length];
visit.CopyTo(tmpvisit, 0);
DFSgraph(RL, tmpvisit, i);
}
}
public static void PrimeFactors(int n, int[] sosuu) {
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
sosuu[i]++;
} else {
i++;
}
}
if (tmp != 1)
sosuu[tmp]++;
}
public static void DFSzahyo(int x, int y, int[] s, int[] g) {
if (x == g[0] && y == g[1]) {
return;
}
miz[x, y] = true;
for (int i = 0; i < 4; i++) {
if (miz[x + xMove[i], y + yMove[i]] != true) {
DFSzahyo(x + xMove[i], y + yMove[i], s, g);
}
}
}
public static void saikiseven(int ope, int sum, int[] hairetui) {
if (ope == 1) {
sum = hairetui[ope - 1];
}
if (ope == 7 && sum == 7) {
int[] dummy = new int[ope];
hairetui.CopyTo(dummy, 0);
list.Add(dummy);
return;
} else if (ope == 7 && sum != 7) {
return;
}
for (int i = 0; i < 2; i++) {
if (i == 0) {
sum += hairetui[ope + 1];
hairetui[ope] = i;
saikiseven(ope + 2, sum, hairetui);
sum -= hairetui[ope + 1];
} else {
sum -= hairetui[ope + 1];
hairetui[ope] = i;
saikiseven(ope + 2, sum, hairetui);
}
}
return;
}
public static void saiki(int soezi, int[] hairetui) {
if (soezi == 10) {
int[] dummy = new int[soezi];
hairetui.CopyTo(dummy, 0);
list.Add(dummy);
return;
}
for (int j = 0; j < 2; j++) {
hairetui[soezi] = j;
saiki(soezi + 1, hairetui);
}
return;
}
public static void DFS(int v, bool[] visited, int[,] dag) {
visited[v] = true;
for (int i = 0; i < visited.Length; i++) {
if (dag[v, i] == 0)
continue;
if (visited[i])
continue;
DFS(i, visited, dag);
}
}
public static long LowerBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long 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 long LowerBound<T>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static long UpperBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long 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 long UpperBound<T>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
}
/// <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<ComparablePair<int,
// int>>(maxIndex); priorityQueue.Push(new ComparablePair<int, int>(0,
// s));
// while (priorityQueue.Count() > 0)
// {
// var costDestinationPair = priorityQueue.Pop();
// 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.Push(new ComparablePair<int,
// int>(newCostToi, i));
// }
// }
// }
// return cost[t];
// }
//}
// public class ComparablePair<T, U> : IComparable where T : IComparable<T>
//{
// public readonly T Item1;
// public readonly U Item2;
// public int CompareTo(object obj)
// {
// ComparablePair<T, U> castedObj = (ComparablePair<T, U>)obj;
// return this.Item1.CompareTo(castedObj.Item1);
// }
// public ComparablePair(T t, U u)
// {
// Item1 = t;
// Item2 = u;
// }
//}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static List<int[]> list = new List<int[]>();
static int[] yMove = new int[] { -1, 1, 0, 0 };
static int[] xMove = new int[] { 0, 0, -1, 1 };
static bool[,] miz;
static int cnt = 0;
static void Main(string[] args) {
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var N = line1[0];
// var M = line1[1];
// var a = new long[M];
// var b = new long[M];
// int bridge = 0;
// int[,] dag = new int[N,N];
// for (int i = 0; i < M; i++)
//{
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// a[i] = line2[0]-1;
// b[i] = line2[1]-1;
// dag[a[i], b[i]] = 1;
// dag[b[i], a[i]] = 1;
//}
// for (int i = 0; i < M; i++)
//{
// bool[] visited = new bool[N];
// dag[a[i], b[i]] = 0;
// dag[b[i], a[i]] = 0;
// DFS(0,visited,dag);
// if (visited.Where(n => n == true).Count() != N)
// {
// bridge++;
// }
// dag[a[i], b[i]] = 1;
// dag[b[i], a[i]] = 1;
//}
// Console.WriteLine(bridge);
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var A = line1[0];
// var B = line1[1];
// var C = line1[2];
// var D = line1[3];
// var E = line1[4];
// var F = line1[5];
// var N = int.Parse(Console.ReadLine());
// char[] mozi = new char[N];
// long[] MARCH = new long[5];
// long cnt = 0;
// for (int i = 0; i < N; i++)
//{
// mozi[i] = Console.ReadLine().ToCharArray()[0];
//}
// MARCH[0] = mozi.Where(n => n == 'M').Count();
// MARCH[1] = mozi.Where(n => n == 'A').Count();
// MARCH[2] = mozi.Where(n => n == 'R').Count();
// MARCH[3] = mozi.Where(n => n == 'C').Count();
// MARCH[4] = mozi.Where(n => n == 'H').Count();
// for (int i = 0; i < 3; i++)
//{
// for (int j = i + 1; j < 4; j++)
// {
// for (int k = j + 1; k < 5; k++)
// {
// cnt += MARCH[i] * MARCH[j] * MARCH[k];
// }
// }
//}
// Console.WriteLine(cnt);
// var N = int.Parse(Console.ReadLine());
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int candy = 0;
// int MAX = 0;
// for (int i = 0; i < N; i++)
//{
// for (int k = 0; k <= i; k++)
// {
// candy += line1[k];
// }
// for (int j = N - 1; j >= i; j--)
// {
// candy += line2[j];
// }
// MAX = Math.Max(candy,MAX);
// candy = 0;
//}
// Console.WriteLine(MAX);
// var N = int.Parse(Console.ReadLine());
// List<int[]> list = new List<int[]>();
// int t = 0;
// int x = 0;
// int y = 0;
// for (int i = 0; i < N; i++)
//{
// var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// list.Add(txy);
//}
// foreach (var item in list)
//{
// if (item[0] - t >= Math.Abs(item[1] + item[2] - x - y))
// {
// if (((item[0] - t) % 2 == 1 && Math.Abs(x + y - item[1] - item[2])
// % 2 == 1) ||
// ((item[0] - t) % 2 == 0 && Math.Abs(x + y - item[1] - item[2])
// % 2 == 0))
// {
// t = item[0];
// x = item[1];
// y = item[2];
// }
// else
// {
// Console.WriteLine("No");
// return;
// }
// }
// else
// {
// Console.WriteLine("No");
// return;
// }
//}
// Console.WriteLine("Yes");
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// if (line1[1] >= 10000)
//{
// for (int i = 0; i <= line1[1]/10000; i++)
// {
// for (int j = 0; j <= line1[1] / 5000; j++)
// {
// if (10000 * i + 5000 * j + (line1[0] - i - j) * 1000 ==
// line1[1] && line1[0] - i - j >= 0)
// {
// Console.WriteLine("{0} {1} {2}",i,j,line1[0] - i - j);
// return;
// }
// }
// }
//}
// else
//{
// for (int i = 0; i < 2; i++)
// {
// for (int j = 0; j <= 9; j++)
// {
// if (5000 * i + 1000 * j == line1[1] && i + j == line1[0])
// {
// Console.WriteLine("{0} {1} {2}", 0, i, j);
// return;
// }
// }
// }
//}
// Console.WriteLine("{0} {1} {2}", -1, -1, -1);
// var N = int.Parse(Console.ReadLine());
// int[,] station = new int[N,3];
// long sum = 0;
// for (int i = 0; i < N - 1; i++)
//{
// var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// station[i, 0] = line[0];
// station[i, 1] = line[1];
// station[i, 2] = line[2];
//}
// for (int j = 0; j < N -1; j++)
//{
// for (int i = j; i < N - 1; i++)
// {
// var F = station[i, 2];
// var S = station[i, 1];
// if (i == j)
// {
// sum += station[i, 0] + station[i, 1];
// }
// else
// {
// if (sum < S)
// {
// sum = S + station[i, 0];
// }
// else if (sum % F == 0)
// {
// sum += station[i, 0];
// }
// else
// {
// sum += F - (sum % F) + station[i, 0];
// }
// }
// }
// Console.WriteLine(sum);
// sum = 0;
//}
// Console.WriteLine(sum);
// var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// long A = line[0];
// int i = 0;
// while (A <= line[1])
//{
// A *=2;
// i++;
//}
// Console.WriteLine(i);
// var N = long.Parse(Console.ReadLine());
// var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// Dictionary<long, long> dic = new Dictionary<long, long>();
// long sum = 0;
// for (int i = 0; i < N; i++)
//{
// if (dic.ContainsKey(line[i]))
// {
// dic[line[i]]++;
// }
// else
// {
// dic.Add(line[i], 1);
// }
//}
// foreach (var item in dic)
//{
// if (item.Key == item.Value)
// {
// }
// else if (item.Key < item.Value)
// {
// sum += item.Value - item.Key;
// }
// else
// {
// sum += item.Value;
// }
//}
// Console.WriteLine(sum);
// var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// var N = line[0];
// var K = line[1];
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// long cnt = 0;
// long sum = 0;
// long[] lngarray = new long[N];
// for (int i = 0; i < N; i++)
//{
// lngarray[line2[i]-1]++;
//}
// if (lngarray.Where(n => n !=0).Count() <= K)
//{
// Console.WriteLine(0);
// return;
//}
// var orderlng = lngarray.Where(n => n != 0).OrderBy(n => n).ToArray();
// for (int i = 0; i < orderlng.Length; i++)
//{
// if (cnt == orderlng.Length - K)
// {
// Console.WriteLine(sum);
// return;
// }
// else
// {
// sum += orderlng[i];
// cnt++;
// }
//}
// int soe = 0;
// saiki(soe, new int[10]);
// var N = int.Parse(Console.ReadLine());
// var F = new List<int[]>();
// var P = new List<int[]>();
// for (int i = 0; i < N; i++)
//{
// var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// F.Add(line);
//}
// for (int i = 0; i < N; i++)
//{
// var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// P.Add(line);
//}
// int sum = int.MinValue;
// list.RemoveAt(0);
// foreach (var item in list)
//{
// int tmpsum = 0;
// for (int i = 0; i < N; i++)
// {
// int c = 0;
// for (int j = 0; j < 10; j++)
// {
// if (item[j] == 1 && F[i][j] == 1)
// {
// c++;
// }
// }
// tmpsum += P[i][c];
// }
// sum = Math.Max(sum, tmpsum);
//}
// Console.WriteLine(sum);
// var line = Console.ReadLine().ToCharArray();
// int[] hai = new int[7];
// hai[0] = int.Parse(line[0].ToString());
// hai[2] = int.Parse(line[1].ToString());
// hai[4] = int.Parse(line[2].ToString());
// hai[6] = int.Parse(line[3].ToString());
// saikiseven(1,0, hai);
// string ope1 = list[0][1] == 0 ? "+" : "-";
// string ope2 = list[0][3] == 0 ? "+" : "-";
// string ope3 = list[0][5] == 0 ? "+" : "-";
// Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}=7", list[0][0],ope1, list[0][2],
// ope2,list[0][4], ope3,list[0][6]);
// var N = long.Parse(Console.ReadLine());
// var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// long[] A = new long[N];
// for (int i = 0; i < N; i++)
//{
// A[i] = Math.Abs(i - (N - i -1));
//}
// var tmp1 = line.OrderBy(n => n).ToArray();
// var tmp2 = A.OrderBy(n => n).ToArray();
// for (int i = 0; i < N; i++)
//{
// if (tmp1[i] != tmp2[i])
// {
// Console.WriteLine(0);
// return;
// }
//}
// long X = 1;
// for (int i = 0; i < N/2; i++)
//{
// X *= 2;
// X %= 1000000007;
//}
// Console.WriteLine(X);
// var line =Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// var sx = line[0];
// var sy = line[1];
// var tx = line[2];
// var ty = line[3];
// var path1 = new string('U', ty - sy) + new string('R',tx - sx);
// var path2 = new string('D', ty - sy) + new string('L', tx - sx);
// var path3 = new string('L', 1) + new string('U', ty - sy + 1) + new
// string('R', tx - sx + 1) + new string('D', 1); var path4 = new string('R',
// 1) + new string('D', ty - sy + 1) + new string('L', tx - sx + 1) + new
// string('U', 1); Console.WriteLine(path1 + path2 + path3 + path4); int[]
// sosuu = new int[1000];
// var N = int.Parse(Console.ReadLine());
// int[] sosuu = new int[1001];
// long ans = 1;
// for (int i = 1; i < N + 1; i++)
//{
// PrimeFactors(i, sosuu);
//}
// for (int i = 2; i < N + 1; i++)
//{
// ans *= sosuu[i] + 1;
// ans %= 1000000007;
//}
// Console.WriteLine(ans);
// var N = long.Parse(Console.ReadLine());
// long X = 0;
// long Y = 0;
// X = N / 11;
// if ((N - (11 * X)) == 0)
//{
// Y = 0;
//}
// else if ((N - (11 * X)) <= 6)
//{
// Y = 1;
//}
// else
//{
// Y = 2;
//}
// Console.WriteLine(X * 2 + Y);
// var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var N = line[0];
// var M = line[1];
// int[,] RL = new int[N, N];
// for (int i = 0; i < M; i++)
//{
// var tmp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// RL[tmp[0]-1, tmp[1]-1] = 1;
// RL[tmp[1]-1, tmp[0]-1] = 1;
//}
// bool[] visit = new bool[N];
// DFSgraph(RL,visit,0);
// Console.WriteLine(cnt);
// var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// var N = line[0];
// var M = line[1];
// if (N * 2 < M)
//{
// Console.WriteLine(N + (M - 2 * N) /4);
//}
// else
//{
// Console.WriteLine(M/2);
//}
// var N = int.Parse(Console.ReadLine());
// var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int[,] dp = new int[N + 1, 10001];
////for (int i = 0; i < N; i++)
////{
//// dp[0, line[0]] = line[i];
////}
// for (int i = 0; i < N; i++)
//{
// for (int j = 0; j < 10001; j++)
// {
// dp[i + 1, line[i]] = line[i];
// if (dp[i,j] != 0)
// {
// dp[i + 1, j] = dp[i, j];
// dp[i + 1, dp[i, j] + line[i]] = line[i] + dp[i, j];
// }
// }
//}
// long ans = 0;
// for (int i = 0; i < 10001; i++)
//{
// if (dp[N,i] != 0)
// {
// ans++;
// }
//}
// Console.WriteLine(ans + 1);
// var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// var A = line[0];
// var B = line[1];
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var line3 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int[] a = new int[A];
// int[] b = new int[B];
// for (int i = 0; i < A; i++)
//{
// a[i] = line2[i];
//}
// for (int i = 0; i < B; i++)
//{
// b[i] = line3[i];
//}
// int AB = A + B;
// int[,] dp = new int[A + 1, B + 1];
// for (int i = 1; i <= A; i++)
//{
// if ((AB - i) % 2 == 0)
// {
// dp[i, 0] = dp[i - 1, 0] + a[A - i];
// }
// else
// {
// dp[i, 0] = dp[i - 1, 0];
// }
//}
// for (int i = 1; i <= B; i++)
//{
// if ((AB - i) % 2 == 0)
// {
// dp[0, i] = dp[0, i -1] + b[B - i];
// }
// else
// {
// dp[0, i] = dp[0, i -1];
// }
//}
// for (int i = 1; i <= A; i++)
//{
// for (int j = 1; j <= B; j++)
// {
// if ((AB - i - j) % 2 == 0)
// {
// dp[i, j] = Math.Max(dp[i -1,j] + a[A - i],dp[i,j-1] + b[B -
// j]);
// }
// else
// {
// dp[i, j] = Math.Min(dp[i - 1, j] , dp[i, j - 1]);
// }
// }
//}
// Console.WriteLine(dp[A,B]);
var N = int.Parse(Console.ReadLine());
int[] dp = new int[N + 1];
for (int i = 1; i <= N; i++) {
dp[i] = i;
}
List<int> hai = new List<int>();
int loop = 6;
while (N >= loop) {
hai.Add(loop);
loop *= 6;
}
loop = 9;
while (N >= loop) {
hai.Add(loop);
loop *= 9;
}
var hai2 = hai.OrderBy(n => n).ToArray();
foreach (var item in hai) {
for (int i = 0; i < N; i++) {
if (i + item <= N) {
dp[i + item] = Math.Min(dp[i + item], dp[i] + 1);
}
}
}
Console.WriteLine(dp[N]);
}
public static void DFSgraph(int[,] RL, bool[] visit, int v) {
visit[v] = true;
if (visit.Where(n => n == true).Count() == visit.Length) {
cnt++;
return;
}
for (int i = 0; i < visit.Length; i++) {
if (RL[v, i] == 0)
continue;
if (visit[i])
continue;
bool[] tmpvisit = new bool[visit.Length];
visit.CopyTo(tmpvisit, 0);
DFSgraph(RL, tmpvisit, i);
}
}
public static void PrimeFactors(int n, int[] sosuu) {
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
sosuu[i]++;
} else {
i++;
}
}
if (tmp != 1)
sosuu[tmp]++;
}
public static void DFSzahyo(int x, int y, int[] s, int[] g) {
if (x == g[0] && y == g[1]) {
return;
}
miz[x, y] = true;
for (int i = 0; i < 4; i++) {
if (miz[x + xMove[i], y + yMove[i]] != true) {
DFSzahyo(x + xMove[i], y + yMove[i], s, g);
}
}
}
public static void saikiseven(int ope, int sum, int[] hairetui) {
if (ope == 1) {
sum = hairetui[ope - 1];
}
if (ope == 7 && sum == 7) {
int[] dummy = new int[ope];
hairetui.CopyTo(dummy, 0);
list.Add(dummy);
return;
} else if (ope == 7 && sum != 7) {
return;
}
for (int i = 0; i < 2; i++) {
if (i == 0) {
sum += hairetui[ope + 1];
hairetui[ope] = i;
saikiseven(ope + 2, sum, hairetui);
sum -= hairetui[ope + 1];
} else {
sum -= hairetui[ope + 1];
hairetui[ope] = i;
saikiseven(ope + 2, sum, hairetui);
}
}
return;
}
public static void saiki(int soezi, int[] hairetui) {
if (soezi == 10) {
int[] dummy = new int[soezi];
hairetui.CopyTo(dummy, 0);
list.Add(dummy);
return;
}
for (int j = 0; j < 2; j++) {
hairetui[soezi] = j;
saiki(soezi + 1, hairetui);
}
return;
}
public static void DFS(int v, bool[] visited, int[,] dag) {
visited[v] = true;
for (int i = 0; i < visited.Length; i++) {
if (dag[v, i] == 0)
continue;
if (visited[i])
continue;
DFS(i, visited, dag);
}
}
public static long LowerBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long 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 long LowerBound<T>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static long UpperBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long 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 long UpperBound<T>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
}
/// <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<ComparablePair<int,
// int>>(maxIndex); priorityQueue.Push(new ComparablePair<int, int>(0,
// s));
// while (priorityQueue.Count() > 0)
// {
// var costDestinationPair = priorityQueue.Pop();
// 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.Push(new ComparablePair<int,
// int>(newCostToi, i));
// }
// }
// }
// return cost[t];
// }
//}
// public class ComparablePair<T, U> : IComparable where T : IComparable<T>
//{
// public readonly T Item1;
// public readonly U Item2;
// public int CompareTo(object obj)
// {
// ComparablePair<T, U> castedObj = (ComparablePair<T, U>)obj;
// return this.Item1.CompareTo(castedObj.Item1);
// }
// public ComparablePair(T t, U u)
// {
// Item1 = t;
// Item2 = u;
// }
//}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 1,804
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
/* string[] input = ReadLine().Split(' ');
int n = int.Parse(input[0]);
int m = int.Parse(input[1]);*/
// string temp = ReadLine();
int a = int.Parse(ReadLine());
int b = a;
for (int i = 0; i < a; i++) {
int cc = 0;
int t = i;
while (t > 0) {
cc += t % 6;
t /= 6;
}
t = a - i;
while (t > 0) {
cc += t % 9;
t /= 9;
}
if (b > cc)
b = cc;
}
WriteLine(b);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
/* string[] input = ReadLine().Split(' ');
int n = int.Parse(input[0]);
int m = int.Parse(input[1]);*/
// string temp = ReadLine();
int a = int.Parse(ReadLine());
int b = a;
for (int i = 0; i <= a; i++) {
int cc = 0;
int t = i;
while (t > 0) {
cc += t % 6;
t /= 6;
}
t = a - i;
while (t > 0) {
cc += t % 9;
t /= 9;
}
if (b > cc)
b = cc;
}
WriteLine(b);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 142
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main(string[] args) {
var N = long.Parse(ReadLine());
long res = N;
for (long i = 0; i <= N; i++) {
long tmp = 0;
long t = 1;
while (t > 0) {
tmp += t % 6;
t /= 6;
}
t = N - i;
while (t > 0) {
tmp += t % 9;
t /= 9;
}
if (res > tmp) {
res = tmp;
}
}
WriteLine(res);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main(string[] args) {
var N = long.Parse(ReadLine());
long res = N;
for (long i = 0; i <= N; i++) {
long tmp = 0;
long t = i;
while (t > 0) {
tmp += t % 6;
t /= 6;
}
t = N - i;
while (t > 0) {
tmp += t % 9;
t /= 9;
}
if (res > tmp) {
res = tmp;
}
}
WriteLine(res);
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
| 8
| 138
| 2
|
//
using System;
public class Hello {
public static void Main() {
var N = int.Parse(Console.ReadLine());
int res = N;
for (var i = 0; i < N; i++) {
int cc = 0;
int t = i;
while (t > 0) {
cc += t % 6;
t /= 6;
}
t = N - i;
while (t > 0) {
cc += t % 9;
t /= 9;
}
res = Math.Min(res, cc);
}
Console.WriteLine(res);
}
}
|
//
using System;
public class Hello {
public static void Main() {
var N = int.Parse(Console.ReadLine());
int res = N;
for (var i = 0; i <= N; i++) {
int cc = 0;
int t = i;
while (t > 0) {
cc += t % 6;
t /= 6;
}
t = N - i;
while (t > 0) {
cc += t % 9;
t /= 9;
}
res = Math.Min(res, cc);
}
Console.WriteLine(res);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 122
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC {
class Program {
static void Main() {
Console.WriteLine(Solve(int.Parse(Console.ReadLine())).Min());
}
static IEnumerable<int> Solve(int n) {
for (var i = 0; i < n; i++) {
var j = n - i;
var cnt6 = Enumerable.Range(0, i)
.Select(p => Math.Pow(6, p))
.TakeWhile(val => val <= i)
.Select(val => Math.Floor(i / val) % 6)
.Sum(val => (int)val);
var cnt9 = Enumerable.Range(0, j)
.Select(p => Math.Pow(9, p))
.TakeWhile(val => val <= j)
.Select(val => Math.Floor(j / val) % 9)
.Sum(val => (int)val);
yield return cnt6 + cnt9;
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC099.C {
class Program {
static void Main() {
Console.WriteLine(Solve(int.Parse(Console.ReadLine())).Min());
}
static IEnumerable<int> Solve(int n) {
for (var i = 0; i <= n; i++) {
var j = n - i;
var cnt6 = Enumerable.Range(0, i)
.Select(p => Math.Pow(6, p))
.TakeWhile(val => val <= i)
.Select(val => Math.Floor(i / val) % 6)
.Sum(val => (int)val);
var cnt9 = Enumerable.Range(0, j)
.Select(p => Math.Pow(9, p))
.TakeWhile(val => val <= j)
.Select(val => Math.Floor(j / val) % 9)
.Sum(val => (int)val);
yield return cnt6 + cnt9;
}
}
}
}
|
[["-", 36, 36, 0, 208, 0, 209, 141, 232, 141, 22], ["+", 0, 208, 0, 209, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 209, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 209, 141, 232, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 245
| 6
|
using System;
namespace atcorder {
class MainClass {
public static void Main(string[] args) { atcorder.Strange_Bank.Run(); }
}
public class Strange_Bank {
public Strange_Bank() {}
public static void Run() {
int N = int.Parse(Console.ReadLine());
//動的に考えよう
int[] list = new int[100000];
int[] pow9 = new int[6];
int[] pow6 = new int[6];
for (int i = 0; i < 6; i++) {
pow9[i] = (int)Math.Pow(9, i + 1);
pow6[i] = (int)Math.Pow(6, i + 1);
}
list[1] = 1;
for (int i = 2; i <= N; i++) {
int min = 100000;
for (int j = 0; j < 6; j++) {
if (i - pow9[j] >= 0) {
if (min > list[i - pow9[j]])
min = list[i - pow9[j]];
} else
break;
}
for (int j = 0; j < 6; j++) {
if (i - pow6[j] >= 0) {
if (min > list[i - pow6[j]])
min = list[i - pow6[j]];
} else
break;
}
if (min > list[i - 1])
min = list[i - 1];
list[i] = min + 1;
}
Console.WriteLine(list[N]);
}
}
}
|
using System;
namespace atcorder {
class MainClass {
public static void Main(string[] args) { atcorder.Strange_Bank.Run(); }
}
public class Strange_Bank {
public Strange_Bank() {}
public static void Run() {
int N = int.Parse(Console.ReadLine());
//動的に考えよう
int[] list = new int[100001];
int[] pow9 = new int[6];
int[] pow6 = new int[6];
for (int i = 0; i < 6; i++) {
pow9[i] = (int)Math.Pow(9, i + 1);
pow6[i] = (int)Math.Pow(6, i + 1);
}
list[1] = 1;
for (int i = 2; i <= N; i++) {
int min = 100000;
for (int j = 0; j < 6; j++) {
if (i - pow9[j] >= 0) {
if (min > list[i - pow9[j]])
min = list[i - pow9[j]];
} else
break;
}
for (int j = 0; j < 6; j++) {
if (i - pow6[j] >= 0) {
if (min > list[i - pow6[j]])
min = list[i - pow6[j]];
} else
break;
}
if (min > list[i - 1])
min = list[i - 1];
list[i] = min + 1;
}
Console.WriteLine(list[N]);
}
}
}
|
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
| 8
| 335
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
static void Main(string[] args) {
int N = int.Parse(ReadLine());
int ans = int.MaxValue;
for (int A = 1; A < N - 1; A++) {
ans = Min(sumFunc(A) + sumFunc(N - A), ans);
}
WriteLine(ans);
}
static int sumFunc(int i) {
if (i < 10)
return i;
return sumFunc(i / 10) + i % 10;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
static void Main(string[] args) {
int N = int.Parse(ReadLine());
int ans = int.MaxValue;
for (int A = 1; A < N; A++) {
ans = Min(sumFunc(A) + sumFunc(N - A), ans);
}
WriteLine(ans);
}
static int sumFunc(int i) {
if (i < 10)
return i;
return sumFunc(i / 10) + i % 10;
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 142
| 2
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
int kazu = int.Parse(ReadLine());
int a = 1;
int b = 0;
while (a < kazu) {
a *= 10;
}
a /= 10;
b = kazu - a;
int count = 0;
while (a > 0 && b > 0) {
count += a % 10 + b % 10;
a /= 10;
b /= 10;
}
WriteLine(count);
}
}
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
int kazu = int.Parse(ReadLine());
int a = 1;
int b = 0;
while (a < kazu) {
a *= 10;
}
a /= 10;
b = kazu - a;
int count = 0;
while (a > 0 || b > 0) {
count += a % 10 + b % 10;
a /= 10;
b /= 10;
// WriteLine("{0} {1} {2}",count,a,b);
}
WriteLine(count);
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 106]]
| 8
| 112
| 2
|
using System;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var min = 99999;
for (int i = 1; i < N - 1; i++) {
var A = i;
var B = N - i;
A = CalcDigitSum(A);
B = CalcDigitSum(B);
if (A + B < min) {
min = A + B;
}
}
Console.WriteLine(min);
}
static int CalcDigitSum(int num) {
var txt = num.ToString();
var res = 0;
foreach (char c in txt) {
res += int.Parse(c.ToString());
}
return res;
}
}
|
using System;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var min = 99999;
for (int i = 1; i < N; i++) {
var A = i;
var B = N - i;
A = CalcDigitSum(A);
B = CalcDigitSum(B);
if (A + B < min) {
min = A + B;
}
}
Console.WriteLine(min);
}
static int CalcDigitSum(int num) {
var txt = num.ToString();
var res = 0;
foreach (char c in txt) {
res += int.Parse(c.ToString());
}
return res;
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 152
| 2
|
using System;
namespace agc025_a {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
long ret = long.MaxValue;
for (int i = 0; i < n; i++) {
int a = i;
int b = n - i;
if (Math.Min(a, b) < 0)
continue;
string c = a.ToString();
string d = b.ToString();
int now = 0;
for (int j = 0; j < c.Length; j++)
now += int.Parse(c[j].ToString());
for (int j = 0; j < d.Length; j++)
now += int.Parse(d[j].ToString());
ret = Math.Min(ret, now);
}
Console.WriteLine(ret);
}
}
}
|
using System;
namespace agc025_a {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
long ret = long.MaxValue;
for (int i = 0; i < n; i++) {
int a = i;
int b = n - i;
if (Math.Min(a, b) <= 0)
continue;
string c = a.ToString();
string d = b.ToString();
int now = 0;
for (int j = 0; j < c.Length; j++)
now += int.Parse(c[j].ToString());
for (int j = 0; j < d.Length; j++)
now += int.Parse(d[j].ToString());
ret = Math.Min(ret, now);
}
Console.WriteLine(ret);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 191
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program {
const int mod = 998244353;
static long[] s, r;
static long ans = 0;
static void Main() {
Sc sc = new Sc();
s = sc.La;
r = new long[s[0] + 1];
r[0] = 1;
for (int i = 1; i <= s[0]; i++) {
r[i] = (r[i - 1] * i) % mod;
}
for (int i = 0; i <= s[0]; i++) {
if (s[1] * i <= s[3] && (s[3] - s[1] * i) % s[2] == 0 &&
(s[3] - s[1] * i) / s[2] <= s[3]) {
int q = (int)((s[3] - s[1] * i) / s[2]);
ans = (ans + ((r[s[0]] * Mi(r[i] * r[s[0] - i])) % mod) *
((r[s[0]] * Mi(r[q] * r[s[0] - q])) % mod)) %
mod;
}
}
Console.WriteLine(ans);
}
static long Mi(long a) {
long b = mod, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
a ^= b;
b ^= a;
a ^= b;
u -= t * v;
u ^= v;
v ^= u;
u ^= v;
}
u %= mod;
if (u < 0) {
u += mod;
}
return u % mod;
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public int[] Ia2 {
get {
return Array.ConvertAll((Console.ReadLine() + " 0").Split(), int.Parse);
}
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse);
}
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program {
const int mod = 998244353;
static long[] s, r;
static long ans = 0;
static void Main() {
Sc sc = new Sc();
s = sc.La;
r = new long[s[0] + 1];
r[0] = 1;
for (int i = 1; i <= s[0]; i++) {
r[i] = (r[i - 1] * i) % mod;
}
for (int i = 0; i <= s[0]; i++) {
if (s[1] * i <= s[3] && (s[3] - s[1] * i) % s[2] == 0 &&
(s[3] - s[1] * i) / s[2] <= s[0]) {
int q = (int)((s[3] - s[1] * i) / s[2]);
ans = (ans + ((r[s[0]] * Mi(r[i] * r[s[0] - i])) % mod) *
((r[s[0]] * Mi(r[q] * r[s[0] - q])) % mod)) %
mod;
}
}
Console.WriteLine(ans);
}
static long Mi(long a) {
long b = mod, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
a ^= b;
b ^= a;
a ^= b;
u -= t * v;
u ^= v;
v ^= u;
u ^= v;
}
u %= mod;
if (u < 0) {
u += mod;
}
return u % mod;
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public int[] Ia2 {
get {
return Array.ConvertAll((Console.ReadLine() + " 0").Split(), int.Parse);
}
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse);
}
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
}
|
[["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 671
| 2
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
class Program {
static string[] input = Console.ReadLine().Split(' ');
static long n = long.Parse(input[0]);
static long a = long.Parse(input[1]);
static long b = long.Parse(input[2]);
static long k = long.Parse(input[3]);
static long p = 998244353;
static long answer = 0;
static long memoB = 0;
static long[] factorials = new long[n + 1];
static long[] factorialRs = new long[n + 1]; // i!^-1(mod p), pは素数
static void Main() {
factorials[0] = 1;
factorialRs[n] = DivideModFactorial(n, p);
for (long i = 1; i <= n; i++) {
factorials[i] = (factorials[i - 1] * i) % p;
factorialRs[n - i] =
(factorialRs[n + 1 - i] * (n + 1 - i)) % p; //逆元を先にメモ
}
for (long i = 0; i <= n; i++) {
if ((k - a * i) % b != 0 || (k - a * i) / b <= n || (k - a * i) / b >= 0)
continue; // aに対するbが存在しないとき
else {
memoB = (k - a * i) / b;
long memo = Comb(n, i, p);
memo %= p;
memo *= Comb(n, memoB, p);
memo %= p;
answer += memo;
answer %= p;
}
}
Console.WriteLine(answer);
}
static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x % p;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
answer %= p;
}
memo *= memo;
memo %= p;
num *= 2;
}
return answer;
}
static long DivideModReverse(long x, long p) //戻り値はx^-1(mod p), pは素数
{
long answer = DivideMod(x, p - 2, p);
return answer;
}
static long DivideModFactorial(long x, long p) //戻り値はx!^-1(mod p), pは素数
{
long answer = 1;
for (long i = x; i >= 2; i--) {
answer *= DivideModReverse(i, p);
answer %= p;
}
return answer;
}
static long Comb(long a, long b, long p) //戻り値は組み合わせC(a,b)のmod p
{
long answer = 1;
answer *= factorials[a];
answer %= p;
answer *= factorialRs[a - b];
answer %= p;
answer *= factorialRs[b];
answer %= p;
return answer;
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
class Program {
static string[] input = Console.ReadLine().Split(' ');
static long n = long.Parse(input[0]);
static long a = long.Parse(input[1]);
static long b = long.Parse(input[2]);
static long k = long.Parse(input[3]);
static long p = 998244353;
static long answer = 0;
static long memoB = 0;
static long[] factorials = new long[n + 1];
static long[] factorialRs = new long[n + 1]; // i!^-1(mod p), pは素数
static void Main() {
factorials[0] = 1;
factorialRs[n] = DivideModFactorial(n, p);
for (long i = 1; i <= n; i++) {
factorials[i] = (factorials[i - 1] * i) % p;
factorialRs[n - i] =
(factorialRs[n + 1 - i] * (n + 1 - i)) % p; //逆元を先にメモ
}
for (long i = 0; i <= n; i++) {
if ((k - a * i) % b != 0 || (k - a * i) / b > n || (k - a * i) / b < 0)
continue; // aに対するbが存在しないとき
else {
memoB = (k - a * i) / b;
long memo = Comb(n, i, p);
memo %= p;
memo *= Comb(n, memoB, p);
memo %= p;
answer += memo;
answer %= p;
}
}
Console.WriteLine(answer);
}
static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x % p;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
answer %= p;
}
memo *= memo;
memo %= p;
num *= 2;
}
return answer;
}
static long DivideModReverse(long x, long p) //戻り値はx^-1(mod p), pは素数
{
long answer = DivideMod(x, p - 2, p);
return answer;
}
static long DivideModFactorial(long x, long p) //戻り値はx!^-1(mod p), pは素数
{
long answer = 1;
for (long i = x; i >= 2; i--) {
answer *= DivideModReverse(i, p);
answer %= p;
}
return answer;
}
static long Comb(long a, long b, long p) //戻り値は組み合わせC(a,b)のmod p
{
long answer = 1;
answer *= factorials[a];
answer %= p;
answer *= factorialRs[a - b];
answer %= p;
answer *= factorialRs[b];
answer %= p;
return answer;
}
}
|
[["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18]]
| 8
| 575
| 4
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
int N = re.i();
int A = re.i();
int B = re.i();
long K = re.l();
Fact F = new Fact(N * 2);
long count = 0;
for (int i = 0; i <= N; i++) {
if ((K - A * i) % B != 0) {
continue;
}
long b = (K - A * i) / B;
if (b < 0 || b > N) {
continue;
}
int j = (int)b;
long c = F.GetConv(N, i) * F.GetConv(N, j) % Define.mod;
count = (count + c) % Define.mod;
}
sb.Append(count + "\n");
}
}
class Fact {
public long[] f;
public long[] rf;
public Fact(int N) {
f = new long[N + 1];
rf = new long[N + 1];
for (int i = 0; i < N + 1; i++) {
if (i == 0) {
f[i] = 1;
} else {
f[i] = (f[i - 1] * i) % Define.mod;
}
}
for (int i = N; i >= 0; i--) {
if (i == N) {
rf[i] = pow(f[N], Define.mod - 2);
} else {
rf[i] = rf[i + 1] * (i + 1) % Define.mod;
}
}
}
public long pow(long N, long K) {
if (K == 0) {
return 1;
} else if (K % 2 == 0) {
long t = pow(N, K / 2);
return t * t % Define.mod;
} else {
return N * pow(N, K - 1) % Define.mod;
}
}
public long GetFact(int N) { return f[N]; }
public long GetPerm(int N, int R) { return f[N] * rf[N - R] % Define.mod; }
public long GetConv(int N, int R) {
return ((f[N] * rf[R]) % Define.mod * rf[N - R]) % Define.mod;
}
public long GetRev(int N) {
if (N == 0) {
return 1;
} else {
return rf[N] * f[N - 1] % Define.mod;
}
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 998244353; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
int N = re.i();
long A = re.i();
long B = re.i();
long K = re.l();
Fact F = new Fact(N * 2);
long count = 0;
for (int i = 0; i <= N; i++) {
if ((K - A * i) % B != 0) {
continue;
}
long b = (K - A * i) / B;
if (b < 0 || b > N) {
continue;
}
int j = (int)b;
long c = F.GetConv(N, i) * F.GetConv(N, j) % Define.mod;
count = (count + c) % Define.mod;
}
sb.Append(count + "\n");
}
}
class Fact {
public long[] f;
public long[] rf;
public Fact(int N) {
f = new long[N + 1];
rf = new long[N + 1];
for (int i = 0; i < N + 1; i++) {
if (i == 0) {
f[i] = 1;
} else {
f[i] = (f[i - 1] * i) % Define.mod;
}
}
for (int i = N; i >= 0; i--) {
if (i == N) {
rf[i] = pow(f[N], Define.mod - 2);
} else {
rf[i] = rf[i + 1] * (i + 1) % Define.mod;
}
}
}
public long pow(long N, long K) {
if (K == 0) {
return 1;
} else if (K % 2 == 0) {
long t = pow(N, K / 2);
return t * t % Define.mod;
} else {
return N * pow(N, K - 1) % Define.mod;
}
}
public long GetFact(int N) { return f[N]; }
public long GetPerm(int N, int R) { return f[N] * rf[N - R] % Define.mod; }
public long GetConv(int N, int R) {
return ((f[N] * rf[R]) % Define.mod * rf[N - R]) % Define.mod;
}
public long GetRev(int N) {
if (N == 0) {
return 1;
} else {
return rf[N] * f[N - 1] % Define.mod;
}
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 998244353; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 2,202
| 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.Int64;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var a = new long[n];
var b = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ri;
b[i] = ri;
}
a = a.OrderByDescending(x => x).ToArray();
b = b.OrderBy(x => x).ToArray();
Debug.WriteLine(a.AsJoinedString());
Debug.WriteLine(b.AsJoinedString());
var ans = 0L;
var u = 0L;
var cnt = 0;
for (int i = 0; i < n; i++) {
u += 2 * a[i];
u -= 2 * b[i];
cnt += 2;
Debug.WriteLine(u);
if (cnt <= n)
ans = Max(ans, u);
else if (cnt - 1 <= n) {
ans = Max(ans, u - 2 * a[i]);
ans = Max(ans, u + 2 * b[i]);
}
}
Console.WriteLine(ans);
}
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 < n; ++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 = false });
var solver = new Program.Solver();
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.Int64;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var a = new long[n];
var b = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ri;
b[i] = ri;
}
a = a.OrderByDescending(x => x).ToArray();
b = b.OrderBy(x => x).ToArray();
Debug.WriteLine(a.AsJoinedString());
Debug.WriteLine(b.AsJoinedString());
var ans = 0L;
var u = 0L;
var cnt = 0;
for (int i = 0; i < n; i++) {
u += 2 * a[i];
u -= 2 * b[i];
cnt += 2;
Debug.WriteLine(u);
if (cnt <= n)
ans = Max(ans, u);
if (cnt - 1 <= n) {
ans = Max(ans, u - 2 * a[i]);
ans = Max(ans, u + 2 * b[i]);
}
}
Console.WriteLine(ans);
}
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 < n; ++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 = false });
var solver = new Program.Solver();
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
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
| 8
| 1,039
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Solution {
// Not Solved ======================================--
public int N;
public List<Data> D;
public int[] OrderLRight, OrderRLeft;
public void Run() {
N = Input.ReadInt();
D = new List<Data>();
for (int i = 0; i < N; i++) {
var line = Input.ReadIntArray();
D.Add(new Data { ID = i, L = line[0], R = line[1] });
}
D.Sort((d1, d2) => (-1) * d1.L.CompareTo(d2.R));
OrderLRight = D.Select(d => d.ID).ToArray();
D.Sort((d1, d2) => d1.R.CompareTo(d2.R));
OrderRLeft = D.Select(d => d.ID).ToArray();
D.Sort((d1, d2) => d1.ID.CompareTo(d2.ID));
long ret1 = Solve(1);
long ret2 = Solve(-1);
Console.WriteLine(Math.Max(ret1, ret2));
}
public long Solve(int firstDirection) {
long ret = 0;
bool[] flags = new bool[N];
for (int i = 0; i < N; i++)
flags[i] = false;
int pos = 0;
int li = 0;
int ri = 0;
int direction = firstDirection;
while (true) {
if (direction == 1) {
if (ri == N)
break;
int i = OrderLRight[ri];
if (!flags[i]) {
int newpos = D[i].L;
if (newpos <= pos)
break;
ret += Math.Abs(pos - newpos);
Console.Error.WriteLine("=> {0}: {1}->{2}", i, pos, newpos);
pos = newpos;
direction *= -1;
flags[i] = true;
}
ri++;
} else {
if (li == N)
break;
int i = OrderRLeft[li];
if (!flags[i]) {
int newpos = D[i].R;
if (newpos >= pos)
break;
ret += Math.Abs(pos - newpos);
Console.Error.WriteLine("<= {0}: {1}->{2}", i, pos, newpos);
pos = newpos;
direction *= -1;
flags[i] = true;
}
li++;
}
}
ret += Math.Abs(pos);
Console.Error.WriteLine("-----");
return ret;
}
}
// libs ----------
class Data {
public int ID;
public int L;
public int R;
}
// common ----------
internal static class Input {
public static string ReadString() {
string line = Console.ReadLine();
return line;
}
public static int ReadInt() {
string line = Console.ReadLine();
return int.Parse(line);
}
public static int[] ReadIntArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(int.Parse).ToArray();
}
public static long ReadLong() {
string line = Console.ReadLine();
return long.Parse(line);
}
public static long[] ReadLongArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(long.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(double.Parse).ToArray();
}
}
internal class Program {
public static void Main(string[] args) {
var s = new Solution();
s.Run();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Solution {
// Not Solved ======================================--
public int N;
public List<Data> D;
public int[] OrderLRight, OrderRLeft;
public void Run() {
N = Input.ReadInt();
D = new List<Data>();
for (int i = 0; i < N; i++) {
var line = Input.ReadIntArray();
D.Add(new Data { ID = i, L = line[0], R = line[1] });
}
D.Sort((d1, d2) => (-1) * d1.L.CompareTo(d2.L));
OrderLRight = D.Select(d => d.ID).ToArray();
D.Sort((d1, d2) => d1.R.CompareTo(d2.R));
OrderRLeft = D.Select(d => d.ID).ToArray();
D.Sort((d1, d2) => d1.ID.CompareTo(d2.ID));
long ret1 = Solve(1);
long ret2 = Solve(-1);
Console.WriteLine(Math.Max(ret1, ret2));
}
public long Solve(int firstDirection) {
long ret = 0;
bool[] flags = new bool[N];
for (int i = 0; i < N; i++)
flags[i] = false;
int pos = 0;
int li = 0;
int ri = 0;
int direction = firstDirection;
while (true) {
if (direction == 1) {
if (ri == N)
break;
int i = OrderLRight[ri];
if (!flags[i]) {
int newpos = D[i].L;
if (newpos <= pos)
break;
ret += Math.Abs(pos - newpos);
Console.Error.WriteLine("=> {0}: {1}->{2}", i, pos, newpos);
pos = newpos;
direction *= -1;
flags[i] = true;
}
ri++;
} else {
if (li == N)
break;
int i = OrderRLeft[li];
if (!flags[i]) {
int newpos = D[i].R;
if (newpos >= pos)
break;
ret += Math.Abs(pos - newpos);
Console.Error.WriteLine("<= {0}: {1}->{2}", i, pos, newpos);
pos = newpos;
direction *= -1;
flags[i] = true;
}
li++;
}
}
ret += Math.Abs(pos);
Console.Error.WriteLine("-----");
return ret;
}
}
// libs ----------
class Data {
public int ID;
public int L;
public int R;
}
// common ----------
internal static class Input {
public static string ReadString() {
string line = Console.ReadLine();
return line;
}
public static int ReadInt() {
string line = Console.ReadLine();
return int.Parse(line);
}
public static int[] ReadIntArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(int.Parse).ToArray();
}
public static long ReadLong() {
string line = Console.ReadLine();
return long.Parse(line);
}
public static long[] ReadLongArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(long.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(double.Parse).ToArray();
}
}
internal class Program {
public static void Main(string[] args) {
var s = new Solution();
s.Run();
}
}
}
|
[["-", 12, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
| 8
| 795
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC____098 {
class Program {
static void Main(string[] args) {
int A, B, max;
var word = Console.ReadLine().Split(' ');
A = int.Parse(word[0]);
B = int.Parse(word[1]);
max = A + B;
if (A - B > max)
max = A - B;
else if (A * B > max)
max = A * B;
Console.WriteLine(max);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC____098 {
class Program {
static void Main(string[] args) {
int A, B, max;
var word = Console.ReadLine().Split(' ');
A = int.Parse(word[0]);
B = int.Parse(word[1]);
max = A + B;
if (A - B > max)
max = A - B;
if (A * B > max)
max = A * B;
Console.WriteLine(max);
Console.ReadKey();
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 141
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC098A {
class Program {
static void Main(string[] args) {
int a, b, c;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = a + b;
if (a - b > c)
c = a;
if (c < a * b)
c = a * b;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC098A {
class Program {
static void Main(string[] args) {
int a, b, c;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = a + b;
if (c < a - b)
c = a - b;
if (c < a * b)
c = a * b;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 138
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC098A {
class Program {
static void Main(string[] args) {
int a, b, max;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
max = a + b;
if (max < a - b)
max = a - b;
else if (max < a * b)
max = a * b;
Console.WriteLine(max);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC098A {
class Program {
static void Main(string[] args) {
int a, b, max;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
max = a + b;
if (max < a - b)
max = a - b;
if (max < a * b)
max = a * b;
Console.WriteLine(max);
Console.ReadKey();
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 141
| 1
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder {
class Program {
static void Main(string[] args) { MainStream(); }
static void MainStream() {
Scan sc = new Scan();
write wr = new write();
int[] arr = sc.intarr;
int a = arr[0];
int b = arr[1];
int ans = Method.max(a * b, a + b, a - b);
wr.wri(ans);
}
}
class Scan {
public string str => Console.ReadLine();
public string[] strarr => str.Split(' ');
public long[] longarr => strarr.Select(long.Parse).ToArray();
public int[] intarr => strarr.Select(int.Parse).ToArray();
public char[] chararr => str.ToArray();
}
class write {
public void wri<Type>(Type x) { Console.WriteLine(x); }
}
class Method {
static public int max(params int[] nums) {
int maxx = nums[0];
for (int i = 1; i < nums.Length; i++) {
Math.Max(maxx, nums[i]);
}
return maxx;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder {
class Program {
static void Main(string[] args) { MainStream(); }
static void MainStream() {
Scan sc = new Scan();
write wr = new write();
int[] arr = sc.intarr;
int a = arr[0];
int b = arr[1];
int ans = Method.max(a * b, a + b, a - b);
wr.wri(ans);
}
}
class Scan {
public string str => Console.ReadLine();
public string[] strarr => str.Split(' ');
public long[] longarr => strarr.Select(long.Parse).ToArray();
public int[] intarr => strarr.Select(int.Parse).ToArray();
public char[] chararr => str.ToArray();
}
class write {
public void wri<Type>(Type x) { Console.WriteLine(x); }
}
class Method {
static public int max(params int[] nums) {
int maxx = nums[0];
for (int i = 1; i < nums.Length; i++) {
maxx = Math.Max(maxx, nums[i]);
}
return maxx;
}
}
}
|
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32]]
| 8
| 273
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC098A {
class Program {
static void Main(string[] args) {
int A, B, max;
var word = Console.ReadLine().Split(' ');
A = int.Parse(word[1]);
B = int.Parse(word[2]);
if (A + B > A * B && A + B > A - B) {
max = A + B;
} else if (A * B > A + B && A * B > A - B) {
max = A * B;
} else
max = A - B;
Console.WriteLine(max);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC098A {
class Program {
static void Main(string[] args) {
int A, B, max;
var word = Console.ReadLine().Split(' ');
A = int.Parse(word[0]);
B = int.Parse(word[1]);
if (A + B > A * B && A + B > A - B)
max = A + B;
else if (A * B > A + B && A * B > A - B)
max = A * B;
else
max = A - B;
Console.WriteLine(max);
Console.ReadKey();
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46]]
| 8
| 166
| 8
|
using System;
namespace AtCoder.ABC098 {
public class A {
public static void Solve() {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
var max = 0;
max = Math.Max(max, (a + b));
max = Math.Max(max, (a - b));
max = Math.Max(max, (a * b));
Console.WriteLine(max);
}
}
}
namespace AtCoder {
class Program {
static void Main(string[] args) { ABC098.A.Solve(); }
}
}
|
using System;
namespace AtCoder.ABC098 {
public class A {
public static void Solve() {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
var max = -100000000;
max = Math.Max(max, (a + b));
max = Math.Max(max, (a - b));
max = Math.Max(max, (a * b));
Console.WriteLine(max);
}
}
}
namespace AtCoder {
class Program {
static void Main(string[] args) { ABC098.A.Solve(); }
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203]]
| 8
| 150
| 3
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using static System.Math;
using static Reader;
class P {
static void Main() {
int a = NextInt;
int b = NextInt;
Min(Min(a + b, a - b), a * b).WriteLine();
}
}
#region io
static class Reader {
static TextReader stdinReader = Console.In;
public static char NextChar => (char)stdinReader.Read();
public static int NextInt => ReadInt();
public static long NextLong => ReadLong();
public static string NextString => ReadString();
public static IEnumerable<int> NextIntCollection => ReadIntCollection();
public static IEnumerable<long> NextLongCollection => ReadLongCollection();
public static IEnumerable<string> NextStringCollection =>
ReadStringCollection();
public static string NextLine => stdinReader.ReadLine();
public static int ReadInt() {
int i;
bool isNegative;
checked {
i = 0;
isNegative = false;
char next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (!char.IsDigit(next)) {
if (next == '-') {
isNegative = true;
} else if (next != '+')
break;
} else {
i *= 10;
i += next - '0';
}
next = NextChar;
}
}
return isNegative ? -i : i;
}
public static long ReadLong() {
long i;
bool isNegative;
checked {
i = 0;
isNegative = false;
char next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (!char.IsDigit(next)) {
if (next == '-') {
isNegative = true;
} else if (next != '+')
break;
} else {
i *= 10;
i += next - '0';
}
next = NextChar;
}
}
return isNegative ? -i : i;
}
public static string ReadString() {
StringBuilder builder = new StringBuilder();
char next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (char.IsWhiteSpace(next))
break;
builder.Append(next);
next = NextChar;
}
return builder.ToString();
}
public static IEnumerable<int> ReadIntCollection() {
int i;
bool isNegative;
char next;
while (true) {
i = 0;
isNegative = false;
next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (!char.IsDigit(next)) {
if (next == '-') {
isNegative = true;
} else if (next != '+')
break;
} else {
i *= 10;
i += next - '0';
}
next = NextChar;
}
yield return isNegative ? -i : i;
if (!char.IsSeparator(next))
break;
}
}
public static IEnumerable<long> ReadLongCollection() {
long i;
bool isNegative;
char next;
while (true) {
i = 0;
isNegative = false;
next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (!char.IsDigit(next)) {
if (next == '-') {
isNegative = true;
} else if (next != '+')
break;
} else {
i *= 10;
i += next - '0';
}
next = NextChar;
}
yield return isNegative ? -i : i;
if (!char.IsSeparator(next))
break;
}
}
public static IEnumerable<string> ReadStringCollection() {
StringBuilder builder = new StringBuilder();
char next;
while (true) {
builder.Clear();
next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (char.IsWhiteSpace(next))
break;
builder.Append(next);
next = NextChar;
}
yield return builder.ToString();
if (!char.IsSeparator(next))
break;
}
}
}
static class Writer {
public static void WriteLine<T>(this T item) => Console.WriteLine(item);
public static void WriteLog<T>(this T item) => Debug.WriteLine(item);
}
#endregion
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using static System.Math;
using static Reader;
class P {
static void Main() {
int a = NextInt;
int b = NextInt;
Max(Max(a + b, a - b), a * b).WriteLine();
}
}
#region io
static class Reader {
static TextReader stdinReader = Console.In;
public static char NextChar => (char)stdinReader.Read();
public static int NextInt => ReadInt();
public static long NextLong => ReadLong();
public static string NextString => ReadString();
public static IEnumerable<int> NextIntCollection => ReadIntCollection();
public static IEnumerable<long> NextLongCollection => ReadLongCollection();
public static IEnumerable<string> NextStringCollection =>
ReadStringCollection();
public static string NextLine => stdinReader.ReadLine();
public static int ReadInt() {
int i;
bool isNegative;
checked {
i = 0;
isNegative = false;
char next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (!char.IsDigit(next)) {
if (next == '-') {
isNegative = true;
} else if (next != '+')
break;
} else {
i *= 10;
i += next - '0';
}
next = NextChar;
}
}
return isNegative ? -i : i;
}
public static long ReadLong() {
long i;
bool isNegative;
checked {
i = 0;
isNegative = false;
char next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (!char.IsDigit(next)) {
if (next == '-') {
isNegative = true;
} else if (next != '+')
break;
} else {
i *= 10;
i += next - '0';
}
next = NextChar;
}
}
return isNegative ? -i : i;
}
public static string ReadString() {
StringBuilder builder = new StringBuilder();
char next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (char.IsWhiteSpace(next))
break;
builder.Append(next);
next = NextChar;
}
return builder.ToString();
}
public static IEnumerable<int> ReadIntCollection() {
int i;
bool isNegative;
char next;
while (true) {
i = 0;
isNegative = false;
next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (!char.IsDigit(next)) {
if (next == '-') {
isNegative = true;
} else if (next != '+')
break;
} else {
i *= 10;
i += next - '0';
}
next = NextChar;
}
yield return isNegative ? -i : i;
if (!char.IsSeparator(next))
break;
}
}
public static IEnumerable<long> ReadLongCollection() {
long i;
bool isNegative;
char next;
while (true) {
i = 0;
isNegative = false;
next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (!char.IsDigit(next)) {
if (next == '-') {
isNegative = true;
} else if (next != '+')
break;
} else {
i *= 10;
i += next - '0';
}
next = NextChar;
}
yield return isNegative ? -i : i;
if (!char.IsSeparator(next))
break;
}
}
public static IEnumerable<string> ReadStringCollection() {
StringBuilder builder = new StringBuilder();
char next;
while (true) {
builder.Clear();
next = NextChar;
while (char.IsWhiteSpace(next))
next = NextChar;
while (true) {
if (char.IsWhiteSpace(next))
break;
builder.Append(next);
next = NextChar;
}
yield return builder.ToString();
if (!char.IsSeparator(next))
break;
}
}
}
static class Writer {
public static void WriteLine<T>(this T item) => Console.WriteLine(item);
public static void WriteLog<T>(this T item) => Debug.WriteLine(item);
}
#endregion
|
[["-", 0, 1, 0, 213, 63, 214, 205, 213, 63, 22], ["+", 0, 1, 0, 213, 63, 214, 205, 213, 63, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 213, 63, 22]]
| 8
| 922
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace add {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
int c = (a + b);
int d = (a - b);
int e = (a * b);
if (c > d && c > e && a >= -1000 && b <= 1000) {
Console.WriteLine("{0}", c);
} else if (d > c && d > e && a >= -1000 && b <= 1000) {
Console.WriteLine("{0}", d);
} else if (e > c && e > d && a >= -1000 && b <= 1000) {
Console.WriteLine("{0}", e);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace add {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
int c = (a + b);
int d = (a - b);
int e = (a * b);
if (c >= d && c >= e && a >= -1000 && b <= 1000) {
Console.WriteLine("{0}", c);
} else if (d >= c && d >= e && a >= -1000 && b <= 1000) {
Console.WriteLine("{0}", d);
} else if (e >= c && e >= d && a >= -1000 && b <= 1000) {
Console.WriteLine("{0}", e);
}
}
}
}
|
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 47], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 20], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 17, 47], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 20]]
| 8
| 212
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp21 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
int ans = 0;
List<char> list = new List<char>();
for (int i = 0; i < N; i++) {
int sum = 0;
string a = "", b = "";
for (int j = 0; j < i; j++) {
a += S[j];
}
for (int j = i; j < N; j++) {
b += S[j];
}
for (int j = 0; j < a.Length; j++) {
if (!list.Contains(a[j])) {
if (b.Contains(a[j])) {
sum++;
list.Add(a[j]);
}
}
}
if (ans < sum) {
ans = sum;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp21 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
int ans = 0;
List<char> list = new List<char>();
for (int i = 0; i < N; i++) {
int sum = 0;
list.Clear();
string a = "", b = "";
for (int j = 0; j < i; j++) {
a += S[j];
}
for (int j = i; j < N; j++) {
b += S[j];
}
for (int j = 0; j < a.Length; j++) {
if (!list.Contains(a[j])) {
if (b.Contains(a[j])) {
sum++;
list.Add(a[j]);
}
}
}
if (ans < sum) {
ans = sum;
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 245
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace C {
class Program {
static void Main(string[] args) {
var N = Console.ReadLine().ToInt();
var S = Console.ReadLine();
var w = new int[N];
var e = new int[N];
for (var i = 1; i < N; i++) {
w[i] = (S[i - 1] == 'W' ? 1 : 0) + w[i - 1];
}
for (var i = N - 2; i >= 0; i--) {
e[i] = (S[i + 1] == 'E' ? 1 : 0) + e[i + 1];
}
var ret = int.MaxValue;
for (var i = 0; i < N - 1; i++) {
var cost = w[i] + e[i];
ret = Math.Min(ret, cost);
}
Console.WriteLine(ret);
}
}
static class StringExtention {
static public int ToInt(this string input) { return int.Parse(input); }
static public int[] ToIntArray(this string input) {
return input.Split(' ').Select(int.Parse).ToArray();
}
static public long ToLong(this string input) { return long.Parse(input); }
static public long[] ToLongArray(this string input) {
return input.Split(' ').Select(long.Parse).ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace C {
class Program {
static void Main(string[] args) {
var N = Console.ReadLine().ToInt();
var S = Console.ReadLine();
var w = new int[N];
var e = new int[N];
for (var i = 1; i < N; i++) {
w[i] = (S[i - 1] == 'W' ? 1 : 0) + w[i - 1];
}
for (var i = N - 2; i >= 0; i--) {
e[i] = (S[i + 1] == 'E' ? 1 : 0) + e[i + 1];
}
var ret = int.MaxValue;
for (var i = 0; i < N; i++) {
var cost = w[i] + e[i];
ret = Math.Min(ret, cost);
}
Console.WriteLine(ret);
}
}
static class StringExtention {
static public int ToInt(this string input) { return int.Parse(input); }
static public int[] ToIntArray(this string input) {
return input.Split(' ').Select(int.Parse).ToArray();
}
static public long ToLong(this string input) { return long.Parse(input); }
static public long[] ToLongArray(this string input) {
return input.Split(' ').Select(long.Parse).ToArray();
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 333
| 2
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int[] wt = new int[N + 2];
int[] et = new int[N + 2];
int w = 0;
int e = 0;
for (int i = 0; i < N; i++) {
if (s[i] == 'W') {
w++;
} else {
e++;
}
wt[i + 1] = w;
et[i + 1] = e;
}
wt[N + 1] = wt[N];
et[N + 1] = et[N];
int ans = int.MaxValue;
for (int i = 1; i < N + 1; i++) {
ans = Math.Min(ans, wt[i - 1] + e - et[i + 1]);
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int[] wt = new int[N + 2];
int[] et = new int[N + 2];
int w = 0;
int e = 0;
for (int i = 0; i < N; i++) {
if (s[i] == 'W') {
w++;
} else {
e++;
}
wt[i + 1] = w;
et[i + 1] = e;
}
wt[N + 1] = wt[N];
et[N + 1] = et[N];
int ans = int.MaxValue;
for (int i = 1; i < N + 1; i++) {
ans = Math.Min(ans, wt[i - 1] + e - et[i]);
}
Console.WriteLine(ans);
}
}
}
|
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 240
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class C {
public static void Main() {
int N = Int32.Parse(Console.ReadLine());
string S = Console.ReadLine();
int[] csumEast = new int[N + 2];
int[] csumWest = new int[N + 2];
for (int i = 1; i <= N; i++) {
csumEast[i] = csumEast[i - 1];
csumWest[i] = csumWest[i - 1];
if (S[i - 1] == 'E')
csumEast[i]++;
else
csumWest[i]++;
}
csumEast[N + 1] = csumEast[N];
csumWest[N + 1] = csumWest[N];
int ans = Int32.MaxValue;
for (int i = 1; i <= N; i++) {
int tmp = 0;
tmp += csumWest[i - 1];
tmp += (csumEast[N + 1] - csumEast[i + 1]);
ans = Math.Min(ans, tmp);
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class C {
public static void Main() {
int N = Int32.Parse(Console.ReadLine());
string S = Console.ReadLine();
int[] csumEast = new int[N + 2];
int[] csumWest = new int[N + 2];
for (int i = 1; i <= N; i++) {
csumEast[i] = csumEast[i - 1];
csumWest[i] = csumWest[i - 1];
if (S[i - 1] == 'E')
csumEast[i]++;
else
csumWest[i]++;
}
csumEast[N + 1] = csumEast[N];
csumWest[N + 1] = csumWest[N];
int ans = Int32.MaxValue;
for (int i = 1; i <= N; i++) {
int tmp = 0;
tmp += csumWest[i - 1];
tmp += (csumEast[N + 1] - csumEast[i]);
ans = Math.Min(ans, tmp);
}
Console.WriteLine(ans);
}
}
|
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 245
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static AtCoderTemplate.MyExtensions;
using static AtCoderTemplate.MyInputOutputs;
using static AtCoderTemplate.MyNumericFunctions;
namespace AtCoderTemplate {
public class Program {
public static void Main(string[] args) {
var N = ReadInt();
var S = Console.ReadLine();
var ToW = S.Scanl(0, (i, c) => c == 'W' ? i + 1 : i);
var ToE = S.Reverse().Scanl(0, (i, c) => c == 'E' ? i + 1 : i).Reverse();
var ToWPlus = ToW.Append(ToW.Last()).ToList();
var ToEPlus = ToE.Prepend(ToE.First()).ToList();
var min = Enumerable.Range(1, N - 2)
.Select(i => ToWPlus[i - 1] + ToEPlus[i + 1])
.Min();
// PrintRow (ToWPlus);
// PrintRow (ToEPlus);
Print(min);
}
}
static class MyInputOutputs {
/* Input & Output*/
public static int ReadInt() { return int.Parse(Console.ReadLine()); }
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<int> ReadInts() {
return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList();
}
public static List<List<int>> ReadIntColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static List<List<long>> ReadLongColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static void Print<T>(T item) { Console.WriteLine(item); }
public static void PrintIf<T1, T2>(bool condition, T1 trueResult,
T2 falseResult) {
if (condition) {
Console.WriteLine(trueResult);
} else {
Console.WriteLine(falseResult);
}
}
public static void PrintRow<T>(IEnumerable<T> list) {
/* 横ベクトルで表示
A B C D ...
*/
if (!list.IsEmpty()) {
Console.Write(list.First());
foreach (var item in list.Skip(1)) {
Console.Write($" {item}");
}
}
Console.Write("\n");
}
public static void PrintColomn<T>(IEnumerable<T> list) {
/* 縦ベクトルで表示
A
B
C
D
...
*/
foreach (var item in list) {
Console.WriteLine(item);
}
}
public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) {
foreach (var row in sources) {
PrintRow(row);
}
}
}
static class MyNumericFunctions {
public static bool isEven(int a) { return a % 2 == 0; }
public static bool isEven(long a) { return a % 2 == 0; }
public static bool isOdd(int a) { return !isEven(a); }
public static bool isOdd(long a) { return !isEven(a); }
public static long nPk(int n, int k) {
if (k > n) {
return 0;
} else {
return Enumerable.Range(n - k + 1, k)
.Aggregate((long)1, ((i, m) => i * m));
}
}
public static long Fact(int n) { return nPk(n, n); }
public static long nCk(int n, int k) {
if (k > n) {
return 0;
} else {
return nPk(n, k) / Fact(k);
}
}
// 最大公約数
public static long GCD(long m, long n) {
if (m < n) {
return GCD(n, m);
} else if (n == 0) {
return m;
} else {
return GCD(n, m % n);
}
}
// 最小公倍数
public static long LCM(long m, long n) {
if (m < n) {
return LCM(n, m);
} else {
return (m * n) / GCD(m, n);
}
}
}
static class MyExtensions {
// AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2
// はそれに対応して仕様はあるが、実装がない
public static IEnumerable<T> Append<T>(this IEnumerable<T> source,
T element) {
return source.Concat(Enumerable.Repeat(element, 1));
}
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source,
T element) {
return Enumerable.Repeat(element, 1).Concat(source);
}
// TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2
// はそれに対応していない
public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source,
int count) {
return source.Skip(source.Count() - count);
}
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source,
int count) {
return source.Take(source.Count() - count);
}
public static bool IsEmpty<T>(this IEnumerable<T> source) {
return !source.Any();
}
/// <summary>
/// インデックスiの位置の要素からk個取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source,
int i, int count) {
return source.Take(i).Concat(source.Skip(i + count));
}
/// <summary>
/// インデックスiの位置の要素を取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source,
int i) {
return source.TakeAwayRange(i, 1);
}
/// <summary>
/// インデックスiの位置にシーケンスを挿入する
/// O(N + K)
/// </summary>
public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source,
int i, IEnumerable<T> inserted) {
return source.Take(i).Concat(inserted).Concat(source.Skip(i));
}
/// <summary>
/// 順列を得る
/// O(N!)
/// </summary>
public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source,
int n) {
if (n == 0 || source.IsEmpty() || source.Count() < n) {
return Enumerable.Empty<IEnumerable<T>>();
} else if (n == 1) {
return source.Select(i => new List<T> { i });
} else {
var nexts = source.Select(
(x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)),
selected = source.Take(i + 1).Last() });
return nexts.SelectMany(
next => Perm(next.next, n - 1)
.Select(item => item.Prepend(next.selected)));
}
}
/// <summary>
/// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る
/// </summary>
/// <para>O(N)</para>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数</param>
/// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example>
public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source,
Func<T1, T1, TR> func) {
var list = source.ToList();
return Enumerable.Range(1, list.Count - 1)
.Select(i => func(list[i], list[i - 1]));
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、first)
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <param name="first">func(first, source[0])のための初項</param>
/// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2),
/// f(f(f(0,1),2),3)]</example>
public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source,
TR first, Func<TR, T, TR> func) {
var list = source.ToList();
var result = new List<TR> { first };
foreach (var i in Enumerable.Range(0, source.Count())) {
result.Add(func(result[i], list[i]));
}
return result;
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、source.First())
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example>
public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source,
Func<T, T, T> func) {
var list = source.ToList();
var result = new List<T> { list[0] };
foreach (var i in Enumerable.Range(1, source.Count() - 1)) {
result.Add(func(result[i - 1], list[i]));
}
return result;
}
/// <summary>
/// 昇順にソートしたインデックスを得る
/// </summary>
/// <para>O(N * log N)</para>
public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) {
return source.Select((item, i) => new { Item = item, Index = i })
.OrderBy(x => x.Item)
.Select(x => x.Index);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static AtCoderTemplate.MyExtensions;
using static AtCoderTemplate.MyInputOutputs;
using static AtCoderTemplate.MyNumericFunctions;
namespace AtCoderTemplate {
public class Program {
public static void Main(string[] args) {
var N = ReadInt();
var S = Console.ReadLine();
var ToW = S.Scanl(0, (i, c) => c == 'W' ? i + 1 : i);
var ToE = S.Reverse().Scanl(0, (i, c) => c == 'E' ? i + 1 : i).Reverse();
var ToWPlus = ToW.Append(ToW.Last()).ToList();
var ToEPlus = ToE.Prepend(ToE.First()).ToList();
var min = Enumerable.Range(1, N)
.Select(i => ToWPlus[i - 1] + ToEPlus[i + 1])
.Min();
// PrintRow (ToWPlus);
// PrintRow (ToEPlus);
Print(min);
}
}
static class MyInputOutputs {
/* Input & Output*/
public static int ReadInt() { return int.Parse(Console.ReadLine()); }
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<int> ReadInts() {
return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList();
}
public static List<List<int>> ReadIntColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static List<List<long>> ReadLongColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static void Print<T>(T item) { Console.WriteLine(item); }
public static void PrintIf<T1, T2>(bool condition, T1 trueResult,
T2 falseResult) {
if (condition) {
Console.WriteLine(trueResult);
} else {
Console.WriteLine(falseResult);
}
}
public static void PrintRow<T>(IEnumerable<T> list) {
/* 横ベクトルで表示
A B C D ...
*/
if (!list.IsEmpty()) {
Console.Write(list.First());
foreach (var item in list.Skip(1)) {
Console.Write($" {item}");
}
}
Console.Write("\n");
}
public static void PrintColomn<T>(IEnumerable<T> list) {
/* 縦ベクトルで表示
A
B
C
D
...
*/
foreach (var item in list) {
Console.WriteLine(item);
}
}
public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) {
foreach (var row in sources) {
PrintRow(row);
}
}
}
static class MyNumericFunctions {
public static bool isEven(int a) { return a % 2 == 0; }
public static bool isEven(long a) { return a % 2 == 0; }
public static bool isOdd(int a) { return !isEven(a); }
public static bool isOdd(long a) { return !isEven(a); }
public static long nPk(int n, int k) {
if (k > n) {
return 0;
} else {
return Enumerable.Range(n - k + 1, k)
.Aggregate((long)1, ((i, m) => i * m));
}
}
public static long Fact(int n) { return nPk(n, n); }
public static long nCk(int n, int k) {
if (k > n) {
return 0;
} else {
return nPk(n, k) / Fact(k);
}
}
// 最大公約数
public static long GCD(long m, long n) {
if (m < n) {
return GCD(n, m);
} else if (n == 0) {
return m;
} else {
return GCD(n, m % n);
}
}
// 最小公倍数
public static long LCM(long m, long n) {
if (m < n) {
return LCM(n, m);
} else {
return (m * n) / GCD(m, n);
}
}
}
static class MyExtensions {
// AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2
// はそれに対応して仕様はあるが、実装がない
public static IEnumerable<T> Append<T>(this IEnumerable<T> source,
T element) {
return source.Concat(Enumerable.Repeat(element, 1));
}
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source,
T element) {
return Enumerable.Repeat(element, 1).Concat(source);
}
// TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2
// はそれに対応していない
public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source,
int count) {
return source.Skip(source.Count() - count);
}
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source,
int count) {
return source.Take(source.Count() - count);
}
public static bool IsEmpty<T>(this IEnumerable<T> source) {
return !source.Any();
}
/// <summary>
/// インデックスiの位置の要素からk個取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source,
int i, int count) {
return source.Take(i).Concat(source.Skip(i + count));
}
/// <summary>
/// インデックスiの位置の要素を取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source,
int i) {
return source.TakeAwayRange(i, 1);
}
/// <summary>
/// インデックスiの位置にシーケンスを挿入する
/// O(N + K)
/// </summary>
public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source,
int i, IEnumerable<T> inserted) {
return source.Take(i).Concat(inserted).Concat(source.Skip(i));
}
/// <summary>
/// 順列を得る
/// O(N!)
/// </summary>
public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source,
int n) {
if (n == 0 || source.IsEmpty() || source.Count() < n) {
return Enumerable.Empty<IEnumerable<T>>();
} else if (n == 1) {
return source.Select(i => new List<T> { i });
} else {
var nexts = source.Select(
(x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)),
selected = source.Take(i + 1).Last() });
return nexts.SelectMany(
next => Perm(next.next, n - 1)
.Select(item => item.Prepend(next.selected)));
}
}
/// <summary>
/// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る
/// </summary>
/// <para>O(N)</para>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数</param>
/// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example>
public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source,
Func<T1, T1, TR> func) {
var list = source.ToList();
return Enumerable.Range(1, list.Count - 1)
.Select(i => func(list[i], list[i - 1]));
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、first)
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <param name="first">func(first, source[0])のための初項</param>
/// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2),
/// f(f(f(0,1),2),3)]</example>
public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source,
TR first, Func<TR, T, TR> func) {
var list = source.ToList();
var result = new List<TR> { first };
foreach (var i in Enumerable.Range(0, source.Count())) {
result.Add(func(result[i], list[i]));
}
return result;
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、source.First())
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example>
public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source,
Func<T, T, T> func) {
var list = source.ToList();
var result = new List<T> { list[0] };
foreach (var i in Enumerable.Range(1, source.Count() - 1)) {
result.Add(func(result[i - 1], list[i]));
}
return result;
}
/// <summary>
/// 昇順にソートしたインデックスを得る
/// </summary>
/// <para>O(N * log N)</para>
public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) {
return source.Select((item, i) => new { Item = item, Index = i })
.OrderBy(x => x.Item)
.Select(x => x.Index);
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 205, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 1,898
| 2
|
using System;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。
string input =
Console.ReadLine(); // Splitで区切り文字を指定して複数個受け取る。
int minCount = 0;
int count = 0;
for (int i = 1; i < input.Length; i++) {
if (input[i] == 'E')
count++;
}
minCount = count; //1つ目の場合
for (int i = 1; i < input.Length; i++) {
if (input[i - 1] == 'W' && input[i] == 'W')
count--;
if (input[i - 1] == 'E' && input[i] == 'E')
count++;
if (count < minCount)
minCount = count;
}
Console.WriteLine(minCount); // WriteLineをWriteとすると、改行なしで出力。
}
}
|
using System;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。
string input =
Console.ReadLine(); // Splitで区切り文字を指定して複数個受け取る。
int minCount = 0;
int count = 0;
for (int i = 1; i < input.Length; i++) {
if (input[i] == 'E')
count++;
}
minCount = count; //1つ目の場合
for (int i = 1; i < input.Length; i++) {
if (input[i - 1] == 'W' && input[i] == 'W')
count++;
if (input[i - 1] == 'E' && input[i] == 'E')
count--;
if (count < minCount)
minCount = count;
}
Console.WriteLine(minCount); // WriteLineをWriteとすると、改行なしで出力。
}
}
|
[["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 68]]
| 8
| 172
| 4
|
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
var W = new int[n + 1];
var E = new int[n + 1];
var ans = n;
W[0] = 0;
E[0] = 0;
for (var i = 1; i < n + 1; i++) {
if (s[i - 1] == 'W') {
W[i] = W[i - 1] + 1;
E[i] = E[i - 1];
} else {
W[i] = W[i - 1];
E[i] = E[i - 1] + 1;
}
}
for (int j = 1; j < n + 1; j++) {
ans = Math.Min(ans, W[j] + E[n] - E[j] - 1);
}
Console.WriteLine(ans);
}
}
|
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
var W = new int[n + 1];
var E = new int[n + 1];
var ans = n;
W[0] = 0;
E[0] = 0;
for (var i = 1; i < n + 1; i++) {
if (s[i - 1] == 'W') {
W[i] = W[i - 1] + 1;
E[i] = E[i - 1];
} else {
W[i] = W[i - 1];
E[i] = E[i - 1] + 1;
}
}
for (int j = 1; j < n + 1; j++) {
ans = Math.Min(ans, W[j - 1] + E[n] - E[j]);
}
Console.WriteLine(ans);
}
}
|
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 219
| 4
|
using System;
class Program {
static void Main(string[] args) {
string t = Console.ReadLine();
int N = int.Parse(t);
string S = Console.ReadLine();
string A = "EW";
int[] B = new int[2];
int[] C = new int[2];
for (var i = 0; i < S.Length; i++) {
B[A.IndexOf(S.Substring(i, 1))] += 1;
}
int countmin = N;
for (var i = 0; i < S.Length - 1; i++) {
B[A.IndexOf(S.Substring(i, 1))] -= 1;
if (i > 0) {
C[A.IndexOf(S.Substring(i - 1, 1))] += 1;
}
int count = B[0] + C[1];
countmin = Math.Min(countmin, count);
}
Console.WriteLine(countmin);
}
}
|
using System;
class Program {
static void Main(string[] args) {
string t = Console.ReadLine();
int N = int.Parse(t);
string S = Console.ReadLine();
string A = "EW";
int[] B = new int[2];
int[] C = new int[2];
for (var i = 0; i < S.Length; i++) {
B[A.IndexOf(S.Substring(i, 1))] += 1;
}
int countmin = N;
for (var i = 0; i < S.Length; i++) {
B[A.IndexOf(S.Substring(i, 1))] -= 1;
if (i > 0) {
C[A.IndexOf(S.Substring(i - 1, 1))] += 1;
}
int count = B[0] + C[1];
countmin = Math.Min(countmin, count);
}
Console.WriteLine(countmin);
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 216
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main() {
var N = int.Parse(ReadLine());
var S = ReadLine();
var w = new int[N + 1];
for (int i = 0; i < N; i++) {
w[i + 1] = w[i] + (S[i] == 'W' ? 0 : 1);
}
var ans = 100000000;
for (int i = 0; i < N; i++) {
var l = i - w[i + 1];
var r = w[N] - w[i + 1];
ans = Math.Min(ans, l + r);
}
WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main() {
var N = int.Parse(ReadLine());
var S = ReadLine();
var w = new int[N + 1];
for (int i = 0; i < N; i++) {
w[i + 1] = w[i] + (S[i] == 'W' ? 0 : 1);
}
var ans = 100000000;
for (int i = 0; i < N; i++) {
var l = i - w[i];
var r = w[N] - w[i + 1];
ans = Math.Min(ans, l + r);
}
WriteLine(ans);
}
}
|
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 171
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Text;
using Console = System.Console;
namespace Atcoder {
class Program {
private const long COMDIV = 1000000007;
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
var array = new List<int>();
int count = S.Count(x => x == 'E');
array.Add(count);
for (int i = 1; i < N; i++) {
if (S[i] == 'E')
--count;
if (S[i - 1] == 'W')
++count;
array.Add(count);
}
Console.WriteLine(array.Min());
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Text;
using Console = System.Console;
namespace Atcoder {
class Program {
private const long COMDIV = 1000000007;
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
var array = new List<int>();
int count = S.Skip(1).Count(x => x == 'E');
array.Add(count);
for (int i = 1; i < N; i++) {
if (S[i] == 'E')
--count;
if (S[i - 1] == 'W')
++count;
array.Add(count);
}
Console.WriteLine(array.Min());
}
}
}
|
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131]]
| 8
| 203
| 5
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P {
public static void Main() {
int n = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
int[] eSum = new int[n + 1];
for (int i = 0; i < n; i++)
eSum[i + 1] = eSum[i] + (s[i] == 'E' ? 1 : 0);
int[] wSum = new int[n + 1];
for (int i = n - 1; i >= 0; i--)
wSum[i] = wSum[i + 1] + (s[i] == 'W' ? 1 : 0);
Console.WriteLine(wSum.Skip(1).Zip(eSum, (x, y) => x + y).Min());
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P {
public static void Main() {
int n = int.Parse(Console.ReadLine());
var s = Console.ReadLine();
int[] eSum = new int[n + 1];
for (int i = 0; i < n; i++)
eSum[i + 1] = eSum[i] + (s[i] == 'W' ? 1 : 0);
int[] wSum = new int[n + 1];
for (int i = n - 1; i >= 0; i--)
wSum[i] = wSum[i + 1] + (s[i] == 'E' ? 1 : 0);
Console.WriteLine(wSum.Skip(1).Zip(eSum, (x, y) => x + y).Min());
}
}
|
[["-", 12, 23, 0, 41, 15, 16, 12, 252, 0, 253], ["+", 12, 23, 0, 41, 15, 16, 12, 252, 0, 253]]
| 8
| 238
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
//入力
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
//計算
//[0, i)のWの個数を計算する
int[] vw = new int[N + 1];
for (int i = 0; i <= N; i++) {
vw[i + 1] += vw[i];
if (S[i] == 'W') {
vw[i + 1]++;
}
}
//[0, i)のEの個数を計算する
int[] ve = new int[N + 1];
for (int i = 0; i <= N; i++) {
ve[i + 1] += ve[i];
if (S[i] == 'E') {
ve[i + 1]++;
}
}
//答えとなる数値
int ans = 999999999;
//検証
for (int i = 0; i < N; i++) {
int now = vw[i] + (ve[N] - ve[i + 1]);
ans = Math.Min(ans, now);
}
//出力
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
//入力
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
//計算
//[0, i)のWの個数を計算する
int[] vw = new int[N + 1];
for (int i = 0; i < N; i++) {
vw[i + 1] += vw[i];
if (S[i] == 'W') {
vw[i + 1]++;
}
}
//[0, i)のEの個数を計算する
int[] ve = new int[N + 1];
for (int i = 0; i < N; i++) {
ve[i + 1] += ve[i];
if (S[i] == 'E') {
ve[i + 1]++;
}
}
//答えとなる数値
int ans = 999999999;
//検証
for (int i = 0; i < N; i++) {
int now = vw[i] + (ve[N] - ve[i + 1]);
ans = Math.Min(ans, now);
}
//出力
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
| 8
| 257
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P {
public static void Main() {
var nkq = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = nkq[0];
var k = nkq[1];
var q = nkq[2];
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var allSection = new Section() { Start = 0, End = n - 1 };
Section[] sections = Enumerable.Repeat(allSection, n).ToArray();
var minInd = a.Select((Elem, Ind) => new { Elem, Ind })
.OrderBy(x => x.Elem)
.Select(x => x.Ind)
.ToArray();
int ind = 0;
var min = a[minInd[q - 1]] - a[minInd[0]];
while (q + ind < n) {
// indを取り除かないとしたら
var splitAt = minInd[ind];
var section = sections[splitAt];
var lSection = new Section() { Start = section.Start, End = splitAt - 1 };
var rSection = new Section() { Start = splitAt + 1, End = section.End };
sections[splitAt] = null;
for (int i = lSection.Start; i <= lSection.End; i++)
sections[i] = lSection;
for (int i = rSection.Start; i <= rSection.End; i++)
sections[i] = rSection;
int[] maxOpeartionCount = new int[n];
for (int i = 0; i < n; i++) {
var elem = sections[i];
if (elem == null)
continue;
maxOpeartionCount[elem.Start] = elem.GetOperatableCount(k);
i = elem.End + 1;
}
for (int i = ind + 1, count = 0; i < n; i++) {
var sec = sections[minInd[i]];
if (maxOpeartionCount[sec.Start] <= 0)
continue;
maxOpeartionCount[sec.Start]--;
count++;
if (count == q) {
min = Min(min, a[minInd[i]] - a[minInd[ind]]);
break;
}
}
ind++;
}
Console.WriteLine(min);
}
}
class Section {
public int Start;
public int End;
public int Length => End - Start + 1;
public int GetOperatableCount(int k) => Max(0, Length - k + 1);
}
class SegmentTree<T> {
public readonly int Size;
T Identity;
Func<T, T, T> Merge;
int LeafCount;
int Height;
T[] Operators;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public SegmentTree(int size, T identity, Func<T, T, T> merge) {
Size = size;
Identity = identity;
Merge = merge;
Height = 1;
LeafCount = 1;
while (LeafCount < size) {
Height++;
LeafCount <<= 1;
}
Operators = new T[LeafCount << 1];
for (int i = 0; i < Operators.Length; i++)
Operators[i] = identity;
}
public T this[int index] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return Query(index); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set {
Propagate(index += LeafCount);
Operators[index] = value;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Operate(int i, T x) {
Propagate(i += LeafCount);
Operators[i] = Merge(Operators[i], x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Operate(int l, int r, T x) {
l += LeafCount;
r += LeafCount;
Propagate(l);
Propagate(r);
while (l <= r) {
if ((l & 1) == 1)
Operators[l] = Merge(Operators[l], x);
if ((r & 1) == 0)
Operators[r] = Merge(Operators[r], x);
l = (l + 1) / 2;
r = (r - 1) / 2;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Query(int index) {
index += LeafCount;
Propagate(index);
return Operators[index];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Propagate(int sectionIndex) {
for (int i = Height - 1; i >= 1; i--) {
var section = sectionIndex >> i;
var leftChild = sectionIndex >> (i - 1);
var rightChild = leftChild ^ 1;
Operators[leftChild] = Merge(Operators[leftChild], Operators[section]);
Operators[rightChild] = Merge(Operators[rightChild], Operators[section]);
Operators[section] = Identity;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P {
public static void Main() {
var nkq = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = nkq[0];
var k = nkq[1];
var q = nkq[2];
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var allSection = new Section() { Start = 0, End = n - 1 };
Section[] sections = Enumerable.Repeat(allSection, n).ToArray();
var minInd = a.Select((Elem, Ind) => new { Elem, Ind })
.OrderBy(x => x.Elem)
.Select(x => x.Ind)
.ToArray();
int ind = 0;
var min = a[minInd[q - 1]] - a[minInd[0]];
while (ind < n) {
// indを取り除かないとしたら
var splitAt = minInd[ind];
var section = sections[splitAt];
var lSection = new Section() { Start = section.Start, End = splitAt - 1 };
var rSection = new Section() { Start = splitAt + 1, End = section.End };
sections[splitAt] = null;
for (int i = lSection.Start; i <= lSection.End; i++)
sections[i] = lSection;
for (int i = rSection.Start; i <= rSection.End; i++)
sections[i] = rSection;
int[] maxOpeartionCount = new int[n];
for (int i = 0; i < n; i++) {
var elem = sections[i];
if (elem == null)
continue;
maxOpeartionCount[elem.Start] = elem.GetOperatableCount(k);
i = elem.End;
}
for (int i = ind + 1, count = 0; i < n; i++) {
var sec = sections[minInd[i]];
if (maxOpeartionCount[sec.Start] <= 0)
continue;
maxOpeartionCount[sec.Start]--;
count++;
if (count == q) {
min = Min(min, a[minInd[i]] - a[minInd[ind + 1]]);
break;
}
}
ind++;
}
Console.WriteLine(min);
}
}
class Section {
public int Start;
public int End;
public int Length => End - Start + 1;
public int GetOperatableCount(int k) => Max(0, Length - k + 1);
}
class SegmentTree<T> {
public readonly int Size;
T Identity;
Func<T, T, T> Merge;
int LeafCount;
int Height;
T[] Operators;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public SegmentTree(int size, T identity, Func<T, T, T> merge) {
Size = size;
Identity = identity;
Merge = merge;
Height = 1;
LeafCount = 1;
while (LeafCount < size) {
Height++;
LeafCount <<= 1;
}
Operators = new T[LeafCount << 1];
for (int i = 0; i < Operators.Length; i++)
Operators[i] = identity;
}
public T this[int index] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return Query(index); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set {
Propagate(index += LeafCount);
Operators[index] = value;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Operate(int i, T x) {
Propagate(i += LeafCount);
Operators[i] = Merge(Operators[i], x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Operate(int l, int r, T x) {
l += LeafCount;
r += LeafCount;
Propagate(l);
Propagate(r);
while (l <= r) {
if ((l & 1) == 1)
Operators[l] = Merge(Operators[l], x);
if ((r & 1) == 0)
Operators[r] = Merge(Operators[r], x);
l = (l + 1) / 2;
r = (r - 1) / 2;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Query(int index) {
index += LeafCount;
Propagate(index);
return Operators[index];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Propagate(int sectionIndex) {
for (int i = Height - 1; i >= 1; i--) {
var section = sectionIndex >> i;
var leftChild = sectionIndex >> (i - 1);
var rightChild = leftChild ^ 1;
Operators[leftChild] = Merge(Operators[leftChild], Operators[section]);
Operators[rightChild] = Merge(Operators[rightChild], Operators[section]);
Operators[section] = Identity;
}
}
}
|
[["-", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 52, 15, 16, 31, 16, 17, 72], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 1,086
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main() {
var s = ReadLine();
var K = int.Parse(ReadLine());
var h = new List<string>();
for (int i = 0; i < s.Length; i++) {
for (int j = 1; j <= K; j++) {
if (i + j - 1 < s.Length)
h.Add(s.Substring(i, j));
}
}
var a = new List<string>(h);
a.Sort();
WriteLine(a[K - 1]);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main() {
var s = ReadLine();
var K = int.Parse(ReadLine());
var h = new HashSet<string>();
for (int i = 0; i < s.Length; i++) {
for (int j = 1; j <= K; j++) {
if (i + j - 1 < s.Length)
h.Add(s.Substring(i, j));
}
}
var a = new List<string>(h);
a.Sort();
WriteLine(a[K - 1]);
}
}
|
[["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22]]
| 8
| 150
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var S = sc.ReadStr();
var K = sc.ReadInt();
var set = new HashSet<string>();
for (int i = 1; i <= K; i++) {
for (int j = 0; j < S.Length - i; j++) {
var s = S.Substring(j, i);
set.Add(s);
}
}
var a = set.ToArray();
Array.Sort(a);
var ans = a[K - 1];
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var S = sc.ReadStr();
var K = sc.ReadInt();
var set = new HashSet<string>();
for (int i = 1; i <= K; i++) {
for (int j = 0; j <= S.Length - i; j++) {
var s = S.Substring(j, i);
set.Add(s);
}
}
var a = set.ToArray();
Array.Sort(a);
var ans = a[K - 1];
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 1,167
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int a = sc.NextInt();
int b = sc.NextInt();
int answer = a < b ? a - 1 : a;
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int a = sc.NextInt();
int b = sc.NextInt();
int answer = a > b ? a - 1 : a;
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 200, 0, 212, 0, 41, 15, 16, 17, 18], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 47]]
| 8
| 372
| 2
|
using System;
using static System.Console;
using System.Linq;
namespace Main {
class Program {
static void Main(string[] args) {
int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
WriteLine(tmp[0] <= tmp[1] ? tmp[1] : tmp[1] - 1);
}
}
}
|
using System;
using static System.Console;
using System.Linq;
namespace Main {
class Program {
static void Main(string[] args) {
int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
WriteLine(tmp[0] <= tmp[1] ? tmp[0] : tmp[0] - 1);
}
}
}
|
[["-", 0, 41, 64, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 41, 64, 204, 206, 207, 0, 28, 0, 203], ["-", 75, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 85
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using Console = System.Console;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var r = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
if (r[0] < r[1]) {
Console.WriteLine(r[0]);
} else {
Console.WriteLine(r[0] - 1);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using Console = System.Console;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var r = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
if (r[0] <= r[1]) {
Console.WriteLine(r[0]);
} else {
Console.WriteLine(r[0] - 1);
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 119
| 2
|
using System;
class p {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
Console.WriteLine(a <= b ? a - 1 : a);
}
}
|
using System;
class p {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
Console.WriteLine(a <= b ? a : a - 1);
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 64, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 41, 64, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 12, 203]]
| 8
| 73
| 4
|
using System;
using System.Linq;
namespace A {
class Program {
static void Main(string[] args) {
// Console.WriteLine("Hello World!");
var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
Console.WriteLine(ab[1] >= ab[0] ? ab[0] - 1 : ab[0] - 2);
}
}
}
|
using System;
using System.Linq;
namespace A {
class Program {
static void Main(string[] args) {
// Console.WriteLine("Hello World!");
var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
Console.WriteLine(ab[1] >= ab[0] ? ab[0] : ab[0] - 1);
}
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 64, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 41, 64, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 41, 75, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 12, 203]]
| 8
| 81
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder {
class Program {
static void Main(string[] args) { MainStream(); }
static void MainStream() {
Scan sc = new Scan();
write wr = new write();
int[] array = sc.intarr;
int a = array[0];
int b = array[1];
if (a <= b) {
wr.wri(a + 1);
} else {
wr.wri(a);
}
}
}
class Scan {
public string str => Console.ReadLine();
public string[] strarr => str.Split(' ');
public long[] longarr => strarr.Select(long.Parse).ToArray();
public int[] intarr => strarr.Select(int.Parse).ToArray();
public char[] chararr => str.ToArray();
}
class write {
public void wri<Type>(Type x) { Console.WriteLine(x); }
}
class Method {
static public int max(params int[] nums) {
int maxx = nums[0];
for (int i = 1; i < nums.Length; i++) {
maxx = Math.Max(maxx, nums[i]);
}
return maxx;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace AtCoder {
class Program {
static void Main(string[] args) { MainStream(); }
static void MainStream() {
Scan sc = new Scan();
write wr = new write();
int[] array = sc.intarr;
int a = array[0];
int b = array[1];
if (a <= b) {
wr.wri(a);
} else {
wr.wri(a - 1);
}
}
}
class Scan {
public string str => Console.ReadLine();
public string[] strarr => str.Split(' ');
public long[] longarr => strarr.Select(long.Parse).ToArray();
public int[] intarr => strarr.Select(int.Parse).ToArray();
public char[] chararr => str.ToArray();
}
class write {
public void wri<Type>(Type x) { Console.WriteLine(x); }
}
class Method {
static public int max(params int[] nums) {
int maxx = nums[0];
for (int i = 1; i < nums.Length; i++) {
maxx = Math.Max(maxx, nums[i]);
}
return maxx;
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 275
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions {
public static int ToInt(this string s) => int.Parse(s);
public static long ToLong(this string s) => long.Parse(s);
public static char ToChar(this string s) => char.Parse(s);
public static double ToDouble(this string s) => double.Parse(s);
public static int[] ToIntArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
public static long[] ToLongArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
public static double[] ToDoubleArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}
class Program {
static string[] ReadLines(int n) =>
Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();
static void Main() {
int[] ab = Console.ReadLine().ToIntArray();
int a = ab[0];
int b = ab[1];
var ans = a;
if (a <= b) {
ans += 1;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Collections;
static class Extensions {
public static int ToInt(this string s) => int.Parse(s);
public static long ToLong(this string s) => long.Parse(s);
public static char ToChar(this string s) => char.Parse(s);
public static double ToDouble(this string s) => double.Parse(s);
public static int[] ToIntArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
public static long[] ToLongArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
public static double[] ToDoubleArray(this string s) =>
s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}
class Program {
static string[] ReadLines(int n) =>
Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray();
static void Main() {
int[] ab = Console.ReadLine().ToIntArray();
int a = ab[0];
int b = ab[1];
var ans = a - 1;
if (a <= b) {
ans += 1;
}
Console.WriteLine(ans);
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 353
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
Console.WriteLine(a + (a > b ? -b : 0));
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
Console.WriteLine(a + (a > b ? -1 : 0));
}
}
|
[["-", 0, 16, 12, 23, 0, 41, 64, 241, 0, 22], ["+", 0, 16, 12, 23, 0, 41, 64, 241, 0, 203]]
| 8
| 92
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class A {
public static void Main() {
string[] args = Console.ReadLine().Split(' ');
int a = Int32.Parse(args[0]);
int b = Int32.Parse(args[1]);
Console.WriteLine((b >= a) ? a : b);
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class A {
public static void Main() {
string[] args = Console.ReadLine().Split(' ');
int a = Int32.Parse(args[0]);
int b = Int32.Parse(args[1]);
Console.WriteLine((b >= a) ? a : a - 1);
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 12, 203]]
| 8
| 92
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) { ABC096_A(); }
static void ABC096_A() {
var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
Console.WriteLine(ab[0] < ab[1] ? ab[0] : ab[0] - 1);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) { ABC096_A(); }
static void ABC096_A() {
var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
Console.WriteLine(ab[0] <= ab[1] ? ab[0] : ab[0] - 1);
}
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19]]
| 8
| 99
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int n = 100;
/*
long n = long.Parse(Console.ReadLine());
long[] input = new long[5];
for(int a = 0; a < 5; a++)
{
input[a]=long.Parse(Console.ReadLine());
}
long[] list = new long[5];
list[0] = n;
long count = 0;
*/
int[] input =
Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
Console.WriteLine(input[1] <= input[0] ? input[0] : input[0] - 1);
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int n = 100;
/*
long n = long.Parse(Console.ReadLine());
long[] input = new long[5];
for(int a = 0; a < 5; a++)
{
input[a]=long.Parse(Console.ReadLine());
}
*/
int[] input =
Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
Console.WriteLine(input[1] >= input[0] ? input[0] : input[0] - 1);
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
| 8
| 105
| 2
|
using System;
using System.Linq;
class ABC96A {
public static void Main() {
string[] input = Console.ReadLine().Split(' ');
int m = int.Parse(input[0]);
int d = int.Parse(input[0]);
if (m > d)
m--;
Console.WriteLine(m);
}
}
|
using System;
using System.Linq;
class ABC96A {
public static void Main() {
string[] input = Console.ReadLine().Split(' ');
int m = int.Parse(input[0]);
int d = int.Parse(input[1]);
if (m > d)
m--;
Console.WriteLine(m);
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 80
| 2
|
using System;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var month = Convert.ToInt32(input[0]);
var day = Convert.ToInt32(input[1]);
if (month < day)
Console.WriteLine(month);
else
Console.WriteLine(month - 1);
}
}
|
using System;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var month = Convert.ToInt32(input[0]);
var day = Convert.ToInt32(input[1]);
if (month <= day)
Console.WriteLine(month);
else
Console.WriteLine(month - 1);
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 83
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC96 {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine().Split();
var a = int.Parse(s[0]);
var b = int.Parse(s[1]);
if (a > b) {
Console.WriteLine(a - b);
} else
Console.WriteLine(a);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC96 {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine().Split();
var a = int.Parse(s[0]);
var b = int.Parse(s[1]);
if (a > b) {
Console.WriteLine(a - 1);
} else
Console.WriteLine(a);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 110
| 2
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program {
const string Yes = "Yes";
const string No = "No";
const long Mod = 1000000007;
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var a = int.Parse(spl[0]);
var b = int.Parse(spl[1]);
var c = int.Parse(spl[0]);
var n = int.Parse(input.ReadLine());
if (a >= b && a >= c)
return a * Pow(2, n) + b + c;
if (b >= a && b >= c)
return b * Pow(2, n) + a + c;
if (c >= a && c >= b)
return c * Pow(2, n) + a + b;
return 0;
}
static long Pow(long x, long n) {
long ans = 1;
while (n > 0) {
if (n % 2 == 1) {
ans = ans * x;
}
x = x * x;
n /= 2;
}
return ans;
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program {
const string Yes = "Yes";
const string No = "No";
const long Mod = 1000000007;
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var a = int.Parse(spl[0]);
var b = int.Parse(spl[1]);
var c = int.Parse(spl[2]);
var n = int.Parse(input.ReadLine());
if (a >= b && a >= c)
return a * Pow(2, n) + b + c;
if (b >= a && b >= c)
return b * Pow(2, n) + a + c;
if (c >= a && c >= b)
return c * Pow(2, n) + a + b;
return 0;
}
static long Pow(long x, long n) {
long ans = 1;
while (n > 0) {
if (n % 2 == 1) {
ans = ans * x;
}
x = x * x;
n /= 2;
}
return ans;
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 322
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace At {
class Program {
static void Main(string[] args) {
var abc = ReadInts();
var k = ReadInt();
var max = abc.Max();
var ans = abc.Sum() - max;
for (int i = 0; i < k; i++) {
ans += max * 2;
}
WriteLine(ans);
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
//最大公約数
public static int Gcd(int a, int b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
var reminder = a % b;
a = b;
b = reminder;
}
return a;
}
//最小公倍数
public static int Lcm(int a, int b) { return a * b / Gcd(a, b); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace At {
class Program {
static void Main(string[] args) {
var abc = ReadInts();
var k = ReadInt();
var max = abc.Max();
var ans = abc.Sum() - max;
for (int i = 0; i < k; i++) {
max = max * 2;
}
ans += max;
WriteLine(ans);
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
//最大公約数
public static int Gcd(int a, int b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
var reminder = a % b;
a = b;
b = reminder;
}
return a;
}
//最小公倍数
public static int Lcm(int a, int b) { return a * b / Gcd(a, b); }
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 366
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Template {
class Program {
static void Main(string[] args) {
// スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
// 文字列の入力
int k = int.Parse(Console.ReadLine());
if (b <= a && c <= a) {
a = a * (1 << (k - 1));
} else if (a <= b && c <= b) {
b = b * (1 << (k - 1));
} else if (a <= c && b <= c) {
c = c * (1 << (k - 1));
}
//出力
Console.WriteLine(a + b + c);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Template {
class Program {
static void Main(string[] args) {
// スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
// 文字列の入力
int k = int.Parse(Console.ReadLine());
if (b <= a && c <= a) {
a = a * (1 << (k));
} else if (a <= b && c <= b) {
b = b * (1 << (k));
} else if (a <= c && b <= c) {
c = c * (1 << (k));
}
//出力
Console.WriteLine(a + b + c);
}
}
}
|
[["-", 12, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 12, 23, 0, 16, 12, 23, 0, 16, 12, 203]]
| 8
| 211
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProgrammingContest {
class Writer : IDisposable {
private System.IO.TextWriter writer;
private StringBuilder sb;
private bool isReactive;
public Writer(string path) : this(new System.IO.StreamWriter(path)) {}
public Writer(bool isReactive) : this(null, isReactive) {}
public Writer(System.IO.TextWriter writer = null, bool isReactive = false) {
this.writer = (writer ?? Console.Out);
this.isReactive = isReactive;
if (!this.isReactive) {
this.sb = new StringBuilder();
}
}
public void Dispose() {
if (!this.isReactive) {
this.writer.Write(sb.ToString());
}
if (!this.writer.Equals(Console.Out)) {
this.writer.Dispose();
}
}
public void Write(object val) {
if (this.isReactive) {
this.writer.Write(val.ToString());
this.writer.Flush();
} else {
this.sb.Append(val.ToString());
}
}
public void Write(string format, params object[] vals) {
if (this.isReactive) {
this.writer.Write(format, vals);
this.writer.Flush();
} else {
this.sb.AppendFormat(format, vals);
}
}
public void WriteLine(object val = null) {
this.Write((val ?? string.Empty).ToString() + System.Environment.NewLine);
}
public void WriteLine(int val) { this.WriteLine(val.ToString()); }
public void WriteLine(long val) { this.WriteLine(val.ToString()); }
public void WriteLine(string val) { this.WriteLine((object)val); }
public void WriteLine(string format, params object[] vals) {
this.Write(format + System.Environment.NewLine, vals);
}
}
class Scanner : IDisposable {
private Queue<string> buffer;
private char[] sep;
private System.IO.TextReader reader;
public Scanner(string path, char[] sep = null)
: this(new System.IO.StreamReader(path), sep) {}
public Scanner(System.IO.TextReader reader = null, char[] sep = null) {
this.buffer = new Queue<string>();
this.sep = (sep ?? new char[] { ' ' });
this.reader = (reader ?? Console.In);
}
private void CheckBuffer() {
if (this.buffer.Count == 0 && this.reader.Peek() != -1) {
string str = string.Empty;
for (; string.IsNullOrEmpty(str); str = this.reader.ReadLine())
;
str.Split(this.sep).ToList().ForEach(el => this.buffer.Enqueue(el));
}
}
public void Dispose() {
if (!this.reader.Equals(Console.In)) {
this.reader.Dispose();
}
}
public string Next {
get {
this.CheckBuffer();
return this.buffer.Dequeue();
}
}
public string[] GetStringArray(int N) {
return Enumerable.Range(0, N).Select(e => this.Next).ToArray();
}
public int NextInt {
get { return int.Parse(this.Next); }
}
public int[] GetIntArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextInt).ToArray();
}
public double NextDouble {
get { return double.Parse(this.Next); }
}
public double[] GetdoubleArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextDouble).ToArray();
}
public long NextLong {
get { return long.Parse(this.Next); }
}
public long[] GetLongArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextLong).ToArray();
}
public bool IsEnd {
get {
this.CheckBuffer();
return this.buffer.Count == 0;
}
}
}
class MainClass : IDisposable {
Scanner sc;
Writer wr;
const string backPath = "..";
char dirSep = System.IO.Path.DirectorySeparatorChar;
string inFilePath = string.Empty;
string outFilePath = string.Empty;
public MainClass() {
this.inFilePath = MainClass.backPath + this.dirSep + MainClass.backPath +
this.dirSep + "in.txt";
this.outFilePath = MainClass.backPath + this.dirSep + MainClass.backPath +
this.dirSep + "out.txt";
this.wr = new Writer(this.IsReactive);
// this.wr = new Writer(this.outFilePath);
#if DEBUG
if (!this.IsReactive) {
this.sc = new Scanner(this.inFilePath);
} else {
this.sc = new Scanner();
}
#else
this.sc = new Scanner();
#endif
}
static void Main(string[] args) {
using (var mainClass = new MainClass()) { mainClass.Solve(); }
}
public void Dispose() {
if (this.sc != null) {
this.sc.Dispose();
this.sc = null;
}
if (this.wr != null) {
this.wr.Dispose();
this.wr = null;
}
#if DEBUG
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
void MakeTestCase() {
var rand = new Random();
if (this.wr != null) {
this.wr.Dispose();
}
this.wr = new Writer(inFilePath);
}
void Solve() {
long[] a = sc.GetLongArray(3);
long k = sc.NextInt;
Array.Sort(a);
for (int i = 0; i < k; i++) {
a[a.Length - 1] = a[a.Length] << 1;
}
wr.WriteLine(a.Sum());
}
private bool IsReactive { get; } = false; // TODO: reactive check !!
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProgrammingContest {
class Writer : IDisposable {
private System.IO.TextWriter writer;
private StringBuilder sb;
private bool isReactive;
public Writer(string path) : this(new System.IO.StreamWriter(path)) {}
public Writer(bool isReactive) : this(null, isReactive) {}
public Writer(System.IO.TextWriter writer = null, bool isReactive = false) {
this.writer = (writer ?? Console.Out);
this.isReactive = isReactive;
if (!this.isReactive) {
this.sb = new StringBuilder();
}
}
public void Dispose() {
if (!this.isReactive) {
this.writer.Write(sb.ToString());
}
if (!this.writer.Equals(Console.Out)) {
this.writer.Dispose();
}
}
public void Write(object val) {
if (this.isReactive) {
this.writer.Write(val.ToString());
this.writer.Flush();
} else {
this.sb.Append(val.ToString());
}
}
public void Write(string format, params object[] vals) {
if (this.isReactive) {
this.writer.Write(format, vals);
this.writer.Flush();
} else {
this.sb.AppendFormat(format, vals);
}
}
public void WriteLine(object val = null) {
this.Write((val ?? string.Empty).ToString() + System.Environment.NewLine);
}
public void WriteLine(int val) { this.WriteLine(val.ToString()); }
public void WriteLine(long val) { this.WriteLine(val.ToString()); }
public void WriteLine(string val) { this.WriteLine((object)val); }
public void WriteLine(string format, params object[] vals) {
this.Write(format + System.Environment.NewLine, vals);
}
}
class Scanner : IDisposable {
private Queue<string> buffer;
private char[] sep;
private System.IO.TextReader reader;
public Scanner(string path, char[] sep = null)
: this(new System.IO.StreamReader(path), sep) {}
public Scanner(System.IO.TextReader reader = null, char[] sep = null) {
this.buffer = new Queue<string>();
this.sep = (sep ?? new char[] { ' ' });
this.reader = (reader ?? Console.In);
}
private void CheckBuffer() {
if (this.buffer.Count == 0 && this.reader.Peek() != -1) {
string str = string.Empty;
for (; string.IsNullOrEmpty(str); str = this.reader.ReadLine())
;
str.Split(this.sep).ToList().ForEach(el => this.buffer.Enqueue(el));
}
}
public void Dispose() {
if (!this.reader.Equals(Console.In)) {
this.reader.Dispose();
}
}
public string Next {
get {
this.CheckBuffer();
return this.buffer.Dequeue();
}
}
public string[] GetStringArray(int N) {
return Enumerable.Range(0, N).Select(e => this.Next).ToArray();
}
public int NextInt {
get { return int.Parse(this.Next); }
}
public int[] GetIntArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextInt).ToArray();
}
public double NextDouble {
get { return double.Parse(this.Next); }
}
public double[] GetdoubleArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextDouble).ToArray();
}
public long NextLong {
get { return long.Parse(this.Next); }
}
public long[] GetLongArray(int N) {
return Enumerable.Range(0, N).Select(e => this.NextLong).ToArray();
}
public bool IsEnd {
get {
this.CheckBuffer();
return this.buffer.Count == 0;
}
}
}
class MainClass : IDisposable {
Scanner sc;
Writer wr;
const string backPath = "..";
char dirSep = System.IO.Path.DirectorySeparatorChar;
string inFilePath = string.Empty;
string outFilePath = string.Empty;
public MainClass() {
this.inFilePath = MainClass.backPath + this.dirSep + MainClass.backPath +
this.dirSep + "in.txt";
this.outFilePath = MainClass.backPath + this.dirSep + MainClass.backPath +
this.dirSep + "out.txt";
this.wr = new Writer(this.IsReactive);
// this.wr = new Writer(this.outFilePath);
#if DEBUG
if (!this.IsReactive) {
this.sc = new Scanner(this.inFilePath);
} else {
this.sc = new Scanner();
}
#else
this.sc = new Scanner();
#endif
}
static void Main(string[] args) {
using (var mainClass = new MainClass()) { mainClass.Solve(); }
}
public void Dispose() {
if (this.sc != null) {
this.sc.Dispose();
this.sc = null;
}
if (this.wr != null) {
this.wr.Dispose();
this.wr = null;
}
#if DEBUG
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
void MakeTestCase() {
var rand = new Random();
if (this.wr != null) {
this.wr.Dispose();
}
this.wr = new Writer(inFilePath);
}
void Solve() {
long[] a = sc.GetLongArray(3);
long k = sc.NextInt;
Array.Sort(a);
for (int i = 0; i < k; i++) {
a[a.Length - 1] = a[a.Length - 1] << 1;
}
wr.WriteLine(a.Sum());
}
private bool IsReactive { get; } = false; // TODO: reactive check !!
}
}
|
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 1,290
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp20 {
class Program {
static void Main(string[] args) {
int[] ABC = Console.ReadLine().Split().Select(int.Parse).ToArray();
int K = int.Parse(Console.ReadLine());
Array.Sort(ABC);
for (int i = 0; i < K; i++) {
ABC[2] = ABC[2] ^ 2;
}
int ans = ABC[0] + ABC[1] + ABC[2];
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp20 {
class Program {
static void Main(string[] args) {
int[] ABC = Console.ReadLine().Split().Select(int.Parse).ToArray();
int K = int.Parse(Console.ReadLine());
Array.Sort(ABC);
for (int i = 0; i < K; i++) {
ABC[2] = ABC[2] * 2;
}
int ans = ABC[0] + ABC[1] + ABC[2];
Console.WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 140], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48]]
| 8
| 146
| 2
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace FertiLib.Contest.C {
static class Program {
public static void Solve(Scanner cin) {
var (h, w) = cin.ReadValue<int, int>();
var s = new char [h + 2][];
for (int i = 0; i < h + 2; i++) {
s[i] = Enumerable.Repeat('.', w + 2).ToArray();
}
for (int i = 1; i < h + 1; i++) {
var s_ = cin.ReadString().ToCharArray();
for (int j = 0; j < w; j++) {
s[i][j + 1] = s_[j];
}
}
bool ok = true;
for (int i = 1; i < h + 1; i++) {
for (int j = 1; j < w + 1; j++) {
if (s[i][j] == '.') {
bool sssss = false;
if (s[i - 1][j] == '#')
sssss = true;
if (s[i][j - 1] == '#')
sssss = true;
if (s[i][j + 1] == '#')
sssss = true;
if (s[i + 1][j] == '#')
sssss = true;
if (!sssss)
ok = false;
}
}
}
YesNo(ok);
}
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) => Console.WriteLine(condition ? "YES" : "NO");
public static void
YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No");
public static void
yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no");
public static bool Chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) >= 0)
return false;
a = b;
return true;
}
public static bool Chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) <= 0)
return false;
a = b;
return true;
}
}
static class Util {
public static string
Join<T>(this IEnumerable<T> x,
string separator = "") => string.Join(separator, x);
}
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 FertiLib.Contest.C {
static class Program {
public static void Solve(Scanner cin) {
var (h, w) = cin.ReadValue<int, int>();
var s = new char [h + 2][];
for (int i = 0; i < h + 2; i++) {
s[i] = Enumerable.Repeat('.', w + 2).ToArray();
}
for (int i = 1; i < h + 1; i++) {
var s_ = cin.ReadString().ToCharArray();
for (int j = 0; j < w; j++) {
s[i][j + 1] = s_[j];
}
}
bool ok = true;
for (int i = 1; i < h + 1; i++) {
for (int j = 1; j < w + 1; j++) {
if (s[i][j] == '#') {
bool sssss = false;
if (s[i - 1][j] == '#')
sssss = true;
if (s[i][j - 1] == '#')
sssss = true;
if (s[i][j + 1] == '#')
sssss = true;
if (s[i + 1][j] == '#')
sssss = true;
if (!sssss)
ok = false;
}
}
}
YesNo(ok);
}
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) => Console.WriteLine(condition ? "YES" : "NO");
public static void
YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No");
public static void
yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no");
public static bool Chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) >= 0)
return false;
a = b;
return true;
}
public static bool Chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) <= 0)
return false;
a = b;
return true;
}
}
static class Util {
public static string
Join<T>(this IEnumerable<T> x,
string separator = "") => string.Join(separator, x);
}
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);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253]]
| 8
| 2,907
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
var h = input[0];
var w = input[1];
var s = new char [h][];
for (int i = 0; i < h; i++) {
s[i] = Console.ReadLine().ToCharArray();
}
bool f = true;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') {
bool f1 = i + 1 < h && s[i + 1][j] == '#';
bool f2 = j + 1 < w && s[i][j + 1] == '#';
bool f3 = i - 1 > 0 && s[i - 1][j] == '#';
bool f4 = j - 1 > 0 && s[i][j - 1] == '#';
if (!f1 && !f2 && !f3 && !f4)
f = false;
}
}
}
Console.WriteLine(f ? "Yes" : "No");
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
var h = input[0];
var w = input[1];
var s = new char [h][];
for (int i = 0; i < h; i++) {
s[i] = Console.ReadLine().ToCharArray();
}
bool f = true;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') {
bool f1 = i + 1 < h && s[i + 1][j] == '#';
bool f2 = j + 1 < w && s[i][j + 1] == '#';
bool f3 = i - 1 >= 0 && s[i - 1][j] == '#';
bool f4 = j - 1 >= 0 && s[i][j - 1] == '#';
if (!f1 && !f2 && !f3 && !f4)
f = false;
}
}
}
Console.WriteLine(f ? "Yes" : "No");
Console.Out.Flush();
}
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 47], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 20]]
| 8
| 367
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC096_C {
class Program {
static void Main(string[] args) {
string[] hw = Console.ReadLine().Split(' ');
int H = int.Parse(hw[0]);
int W = int.Parse(hw[1]);
string[] s = new string[H];
for (int i = 0; i < H; i++) {
s[i] = Console.ReadLine();
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
// Black
if (s[i][j].Equals('#')) {
bool is_ok = false;
// Upper
if (IsBlack(s, i - 1, j)) {
is_ok = true;
}
// Lower
if (IsBlack(s, i + 1, j)) {
is_ok = true;
}
// Right
if (IsBlack(s, i, j + 1)) {
is_ok = true;
}
// Left
if (IsBlack(s, i, j - 1)) {
is_ok = true;
}
if (!is_ok) {
Console.WriteLine("No");
break;
}
}
}
}
Console.WriteLine("Yes");
}
static bool IsBlack(string[] a, int h, int w) {
if (h < 0 || a.GetLength(0) <= h) {
return false;
}
if (w < 0 || a[h].Length <= w) {
return false;
}
if (a[h][w].Equals('#')) {
return true;
}
return false;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC096_C {
class Program {
static void Main(string[] args) {
string[] hw = Console.ReadLine().Split(' ');
int H = int.Parse(hw[0]);
int W = int.Parse(hw[1]);
string[] s = new string[H];
for (int i = 0; i < H; i++) {
s[i] = Console.ReadLine();
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
// Black
if (s[i][j].Equals('#')) {
bool is_ok = false;
// Upper
if (IsBlack(s, i - 1, j)) {
is_ok = true;
}
// Lower
if (IsBlack(s, i + 1, j)) {
is_ok = true;
}
// Right
if (IsBlack(s, i, j + 1)) {
is_ok = true;
}
// Left
if (IsBlack(s, i, j - 1)) {
is_ok = true;
}
if (!is_ok) {
Console.WriteLine("No");
return;
}
}
}
}
Console.WriteLine("Yes");
}
static bool IsBlack(string[] a, int h, int w) {
if (h < 0 || a.GetLength(0) <= h) {
return false;
}
if (w < 0 || a[h].Length <= w) {
return false;
}
if (a[h][w].Equals('#')) {
return true;
}
return false;
}
}
}
|
[["-", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 374
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int h = sc.NextInt();
int w = sc.NextInt();
bool[,] black = new bool[h, w];
for (int i = 0; i < h; i++) {
string str = sc.Next();
for (int j = 0; j < w; j++) {
black[i, j] = str[j] == '#';
}
}
int[] x = new int[] { 0, 0, -1, +1 };
int[] y = new int[] { 1, -1, 0, 0 };
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (!black[i, j]) {
continue;
}
int count = 0;
for (int k = 0; k <= 4; k++) {
if (i + x[k] < 0 || i + x[k] >= h || j + y[k] < 0 || j + y[k] >= w) {
continue;
}
if (black[i + x[k], j + y[k]]) {
count++;
}
}
if (count == 0) {
Console.WriteLine("No");
return;
}
}
}
Console.WriteLine("Yes");
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int h = sc.NextInt();
int w = sc.NextInt();
bool[,] black = new bool[h, w];
for (int i = 0; i < h; i++) {
string str = sc.Next();
for (int j = 0; j < w; j++) {
black[i, j] = str[j] == '#';
}
}
int[] x = new int[] { 0, 0, -1, 1 };
int[] y = new int[] { 1, -1, 0, 0 };
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (!black[i, j]) {
continue;
}
int count = 0;
for (int k = 0; k < 4; k++) {
if (i + x[k] < 0 || i + x[k] >= h || j + y[k] < 0 || j + y[k] >= w) {
continue;
}
if (black[i + x[k], j + y[k]]) {
count++;
}
}
if (count == 0) {
Console.WriteLine("No");
return;
}
}
}
Console.WriteLine("Yes");
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 212, 0, 227, 0, 229, 0, 241, 0, 72], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18]]
| 8
| 625
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class48 {
static string[] s;
static int h;
static int w;
static void Main() {
var hw = Console.ReadLine().Split();
h = int.Parse(hw[0]);
w = int.Parse(hw[1]);
s = new string[h];
for (int i = 0; i < h; i++) {
s[i] = Console.ReadLine();
}
bool ans = true;
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
if (s[j][i] == '#')
ans = check(i, j);
if (!ans)
break;
}
if (!ans)
break;
}
Console.WriteLine(ans ? "Yes" : "No");
}
static bool check(int x, int y) {
bool a = false;
for (int i = -1; i <= 1; i++) {
if (i == 0)
continue;
if (0 <= y + i && y + i < w)
a |= s[y + i][x] == '#';
if (0 <= x + i && x + i < h)
a |= s[y][x + i] == '#';
}
return a;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class48 {
static string[] s;
static int h;
static int w;
static void Main() {
var hw = Console.ReadLine().Split();
h = int.Parse(hw[0]);
w = int.Parse(hw[1]);
s = new string[h];
for (int i = 0; i < h; i++) {
s[i] = Console.ReadLine();
}
bool ans = true;
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
if (s[j][i] == '#')
ans = check(i, j);
if (!ans)
break;
}
if (!ans)
break;
}
Console.WriteLine(ans ? "Yes" : "No");
}
static bool check(int x, int y) {
bool a = false;
for (int i = -1; i <= 1; i++) {
if (i == 0)
continue;
if (0 <= y + i && y + i < h)
a |= s[y + i][x] == '#';
if (0 <= x + i && x + i < w)
a |= s[y][x + i] == '#';
}
return a;
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 322
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC096C {
class Program {
static void Main(string[] args) {
int[] input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int h = input[0];
int w = input[1];
char[][] s = new char [h][];
for (int i = 0; i < h; i++) {
s[i] = Console.ReadLine().ToCharArray();
}
int[] dx = { 0, 1, 0, -1 };
int[] dy = { 1, 0, -1, 0 };
bool isYes = true;
bool isFinished = false;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (s[y][x] == '#') {
bool isSharp = false;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
continue;
}
if (s[nx][ny] == '#') {
isSharp = true;
break;
}
}
if (!isSharp) {
isYes = false;
isFinished = true;
break;
}
}
}
if (isFinished) {
break;
}
}
if (isYes) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC096C {
class Program {
static void Main(string[] args) {
int[] input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int h = input[0];
int w = input[1];
char[][] s = new char [h][];
for (int i = 0; i < h; i++) {
s[i] = Console.ReadLine().ToCharArray();
}
int[] dx = { 0, 1, 0, -1 };
int[] dy = { -1, 0, 1, 0 };
bool isYes = true;
bool isFinished = false;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (s[y][x] == '#') {
bool isSharp = false;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
continue;
}
if (s[ny][nx] == '#') {
isSharp = true;
break;
}
}
if (!isSharp) {
isYes = false;
isFinished = true;
break;
}
}
}
if (isFinished) {
break;
}
}
if (isYes) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 0, 200, 0, 212, 0, 229, 0, 241, 0, 33], ["-", 0, 200, 0, 212, 0, 229, 0, 241, 0, 33], ["-", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 369
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC096C {
class Program {
static void Main(string[] args) {
int[] input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int h = input[0];
int w = input[1];
char[][] s = new char [h][];
for (int i = 0; i < w; i++) {
s[i] = Console.ReadLine().ToCharArray();
}
bool isYes = true;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') {
if ((0 < i && s[i - 1][j] == '.') &&
(i < h - 1 && s[i + 1][j] == '.') &&
(0 < j && s[i][j - 1] == '.') &&
(j < w - 1 && s[i][j + 1] == '.')) {
isYes = false;
// break;
}
}
}
}
if (isYes) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC096C {
class Program {
static void Main(string[] args) {
int[] input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int h = input[0];
int w = input[1];
char[][] s = new char [h][];
for (int i = 0; i < h; i++) {
s[i] = Console.ReadLine().ToCharArray();
}
bool isYes = true;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '#') {
if ((0 < i && s[i - 1][j] == '.') &&
(i < h - 1 && s[i + 1][j] == '.') &&
(0 < j && s[i][j - 1] == '.') &&
(j < w - 1 && s[i][j + 1] == '.')) {
isYes = false;
break;
}
}
}
}
if (isYes) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
| 8
| 315
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static int[] N;
static char[][] C;
static void INPUT() {
N = LineInt();
C = new char[N[0]][];
for (var i = 0; i < N[1]; i++) {
C[i] = NextString().ToArray();
}
}
static void OUT() {
var dx = new int[] { -1, 0, 1, 0 };
var dy = new int[] { 0, -1, 0, 1 };
for (var h = 0; h < N[0]; h++)
for (var w = 0; w < N[1]; w++) {
if (C[h][w] == '#') {
var b = false;
for (var i = 0; i < 4; i++) {
var nx = w + dx[i];
var ny = h + dy[i];
if (nx < 0 || N[1] <= nx)
continue;
if (ny < 0 || N[0] <= ny)
continue;
if (C[ny][nx] == '#')
b = true;
}
if (!b) {
Console.WriteLine("No");
return;
}
}
}
Console.WriteLine("Yes");
}
static void Main(string[] args) {
#if DEBUG
TESTINPUT();
// INPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() {}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static int[] N;
static char[][] C;
static void INPUT() {
N = LineInt();
C = new char[N[0]][];
for (var i = 0; i < N[0]; i++) {
C[i] = NextString().ToArray();
}
}
static void OUT() {
var dx = new int[] { -1, 0, 1, 0 };
var dy = new int[] { 0, -1, 0, 1 };
for (var h = 0; h < N[0]; h++)
for (var w = 0; w < N[1]; w++) {
if (C[h][w] == '#') {
var b = false;
for (var i = 0; i < 4; i++) {
var nx = w + dx[i];
var ny = h + dy[i];
if (nx < 0 || N[1] <= nx)
continue;
if (ny < 0 || N[0] <= ny)
continue;
if (C[ny][nx] == '#')
b = true;
}
if (!b) {
Console.WriteLine("No");
return;
}
}
}
Console.WriteLine("Yes");
}
static void Main(string[] args) {
#if DEBUG
TESTINPUT();
INPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() {}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {}
|
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22]]
| 8
| 669
| 6
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
int q = int.Parse(input[2]);
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long minNum = 0;
long answer = long.MaxValue;
int countMemo = 0;
List<long> answerList = new List<long>();
List<long> answerSubList = new List<long>();
for (int i = 0; i < n; i++) //最小値の選択
{
minNum = nums[i];
answerList.Clear();
answerSubList.Clear();
for (int j = 0; j < n; j++) {
if (nums[j] >= minNum) {
countMemo++;
if (countMemo == k) {
for (int l = 0; l < k; l++) {
answerSubList.Add(nums[j - l]);
}
} else if (countMemo > k)
answerSubList.Add(nums[j]);
} else {
if (countMemo >= k) {
answerSubList.Sort((a, b) => a.CompareTo(b));
for (int l = 0; l < answerSubList.Count() - k + 1; l++) {
answerList.Add(answerSubList[l]);
}
}
answerSubList.Clear();
countMemo = 0;
}
}
if (countMemo >= k) {
answerSubList.Sort((a, b) => a.CompareTo(b));
for (int l = 0; l < answerSubList.Count() - k + 1; l++) {
answerList.Add(answerSubList[l]);
}
}
if (answerList.Count() < q)
continue;
else {
answerList.Sort((a, b) => a.CompareTo(b));
answer = Math.Min(answer, answerList[q - 1] - minNum);
}
}
Console.WriteLine(answer);
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
int q = int.Parse(input[2]);
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long minNum = 0;
long answer = long.MaxValue;
int countMemo = 0;
List<long> answerList = new List<long>();
List<long> answerSubList = new List<long>();
for (int i = 0; i < n; i++) //最小値の選択
{
minNum = nums[i];
answerList.Clear();
answerSubList.Clear();
countMemo = 0;
for (int j = 0; j < n; j++) {
if (nums[j] >= minNum) {
countMemo++;
if (countMemo == k) {
for (int l = 0; l < k; l++) {
answerSubList.Add(nums[j - l]);
}
} else if (countMemo > k)
answerSubList.Add(nums[j]);
} else {
if (countMemo >= k) {
answerSubList.Sort((a, b) => a.CompareTo(b));
for (int l = 0; l < answerSubList.Count() - k + 1; l++) {
answerList.Add(answerSubList[l]);
}
}
answerSubList.Clear();
countMemo = 0;
}
}
if (countMemo >= k) {
answerSubList.Sort((a, b) => a.CompareTo(b));
for (int l = 0; l < answerSubList.Count() - k + 1; l++) {
answerList.Add(answerSubList[l]);
}
}
if (answerList.Count() < q)
continue;
else {
answerList.Sort((a, b) => a.CompareTo(b));
answer = Math.Min(answer, answerList[q - 1] - minNum);
}
}
Console.WriteLine(answer);
}
}
|
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 472
| 4
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var a = long.Parse(spl[0]);
var b = long.Parse(spl[1]);
var c = long.Parse(spl[2]);
var k = long.Parse(spl[2]);
// a-b b-a a-b b-a
//(a) (b+c) (2a+b+c) (2a+3b+3c)
//(b) (a+c) (a+2b+c) (3a+2b+3c)
//(c) (a+b) (a+b+2c) (3a+3b+2c)
long y = (k % 2 == 0) ? a - b : b - a;
if (Math.Abs(y) > 1000000000000000000)
return "Unfair";
return y;
}
static int[] ToIntArray(string strs, int n) {
var ret = new int[n];
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var a = long.Parse(spl[0]);
var b = long.Parse(spl[1]);
var c = long.Parse(spl[2]);
var k = long.Parse(spl[3]);
// a-b b-a a-b b-a
//(a) (b+c) (2a+b+c) (2a+3b+3c)
//(b) (a+c) (a+2b+c) (3a+2b+3c)
//(c) (a+b) (a+b+2c) (3a+3b+2c)
long y = (k % 2 == 0) ? a - b : b - a;
if (Math.Abs(y) > 1000000000000000000)
return "Unfair";
return y;
}
static int[] ToIntArray(string strs, int n) {
var ret = new int[n];
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 317
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
long A = cin.Long();
long B = cin.Long();
long C = cin.Long();
long K = cin.Long();
if (K % 2 == 0)
Console.WriteLine(B - A);
else
Console.WriteLine(A - B);
Console.ReadLine();
}
static int GCD(int a, int b) // a,bの最大公約数を返す
{
if (a < b)
// 引数を入替えて自分を呼び出す
return GCD(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
static int LCM(int a, int b) // a,bの最小公倍数を返す
{
return a / GCD(a, b) * b;
}
static int BinarySearch<T>(T[] array, T target)
where T : IComparable<T> // 2分探索
{
int min = 0;
int max = array.Length - 1;
while (true) {
// 範囲内に見つからなかった
if (max < min)
return -1;
// 範囲内の中央値と比較する
int mid = min + (max - min) / 2;
switch (target.CompareTo(array[mid])) {
case -1: // 中央値より小さい
max = mid - 1;
break;
case 1: // 中央値より大きい
min = mid + 1;
break;
case 0: // 見つかった
return mid;
}
}
}
static void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
}
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 Int() { 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] = Int() + add;
}
return Array;
}
public long Long() { 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] = Long() + add;
}
return Array;
}
public double Double() { 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] = Double() + add;
}
return Array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
long A = cin.Long();
long B = cin.Long();
long C = cin.Long();
long K = cin.Long();
if (K % 2 != 0)
Console.WriteLine(B - A);
else
Console.WriteLine(A - B);
Console.ReadLine();
}
static int GCD(int a, int b) // a,bの最大公約数を返す
{
if (a < b)
// 引数を入替えて自分を呼び出す
return GCD(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
static int LCM(int a, int b) // a,bの最小公倍数を返す
{
return a / GCD(a, b) * b;
}
static int BinarySearch<T>(T[] array, T target)
where T : IComparable<T> // 2分探索
{
int min = 0;
int max = array.Length - 1;
while (true) {
// 範囲内に見つからなかった
if (max < min)
return -1;
// 範囲内の中央値と比較する
int mid = min + (max - min) / 2;
switch (target.CompareTo(array[mid])) {
case -1: // 中央値より小さい
max = mid - 1;
break;
case 1: // 中央値より大きい
min = mid + 1;
break;
case 0: // 見つかった
return mid;
}
}
}
static void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
}
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 Int() { 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] = Int() + add;
}
return Array;
}
public long Long() { 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] = Long() + add;
}
return Array;
}
public double Double() { 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] = Double() + add;
}
return Array;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79]]
| 8
| 699
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression,
System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;
class Program
{
static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
const int M = 1000000007;
// const int M = 998244353;
const long LM = (long)1e18;
const double eps = 1e-11;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
const string dstring = "RDLU";
static void Main()
{
int a, b, c, k;
sc.Multi(out a, out b, out c, out k);
Prt(k % 2 == 0 ? a - b : b - a);
sw.Flush();
}
static void DBG(string a) => Console.WriteLine(a);
static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
static void DBG(params object[] a) => DBG(string.Join(" ", a));
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
public T v1;
public U v2;
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
public override string ToString() => v1 + " " + v2;
}
static class util
{
public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]);
public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2);
public static T sqr<T>(T a) => Operator<T>.Multiply(a, a);
public static T Max<T>(params T[] a) => a.Max();
public static T Min<T>(params T[] a) => a.Min();
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w;
public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++) ret[i] = a[i];
return ret;
}
}
static class Operator<T>
{
static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
class Scan
{
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U>
{ T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); }
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b)
{ var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); }
public void Multi<T, U, V>(out T a, out U b, out V c)
{ var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); }
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
{ var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); }
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
{ var ar = StrArr; 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]); }
public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f)
{ var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); }
}
static class mymath
{
public static long Mod = 1000000007;
public static bool isprime(long a) {
if (a < 2) return false;
for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
return true;
}
public static bool[] sieve(int n) {
var p = new bool[n + 1];
for (int i = 2; i <= n; i++) p[i] = true;
for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
return p;
}
public static List<int> getprimes(int n) {
var prs = new List<int>();
var p = sieve(n);
for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
return prs;
}
public static long[][] E(int n) {
var ret = new long[n][];
for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
return ret;
}
public static double[][] dE(int n) {
var ret = new double[n][];
for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; }
return ret;
}
public static long[][] pow(long[][] A, long n) {
if (n == 0) return E(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double[][] pow(double[][] A, long n) {
if (n == 0) return dE(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0;
for (int i = 0; i < n; i++) ret += x[i] * y[i];
return ret;
}
public static double _dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0, r = 0;
for (int i = 0; i < n; i++) {
double s = ret + (x[i] * y[i] + r);
r = (x[i] * y[i] + r) - (s - ret);
ret = s;
}
return ret;
}
public static long dot(long[] x, long[] y) {
int n = x.Length;
long ret = 0;
for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
return ret;
}
public static T[][] trans<T>(T[][] A) {
int n = A[0].Length, m = A.Length;
var ret = new T[n][];
for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
return ret;
}
public static double[] mul(double a, double[] x) {
int n = x.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i];
return ret;
}
public static long[] mul(long a, long[] x) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod;
return ret;
}
public static double[] mul(double[][] A, double[] x) {
int n = A.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static long[] mul(long[][] A, long[] x) {
int n = A.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static double[][] mul(double a, double[][] A) {
int n = A.Length;
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static long[][] mul(long a, long[][] A) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static double[][] mul(double[][] A, double[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[][] mul(long[][] A, long[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[] add(long[] x, long[] y) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
return ret;
}
public static long[][] add(long[][] A, long[][] B) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
return ret;
}
public static long pow(long a, long b) {
if (a >= Mod) return pow(a % Mod, b);
if (a == 0) return 0;
if (b == 0) return 1;
var t = pow(a, b / 2);
if ((b & 1) == 0) return t * t % Mod;
return t * t % Mod * a % Mod;
}
public static long inv(long a) => pow(a, Mod - 2);
public static long gcd(long a, long b) {
while (b > 0) { var t = a % b; a = b; b = t; } return a;
}
// a x + b y = gcd(a, b)
public static long extgcd(long a, long b, out long x, out long y) {
long g = a; x = 1; y = 0;
if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
return g;
}
public static long lcm(long a, long b) => a / gcd(a, b) * b;
static long[] facts;
public static long[] setfacts(int n) {
facts = new long[n + 1];
facts[0] = 1;
for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod;
return facts;
}
public static long comb(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
if (n - r < r) r = n - r;
if (r == 0) return 1;
if (r == 1) return n;
if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod;
int[] numer = new int[r], denom = new int[r];
for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
for (int p = 2; p <= r; p++) {
int piv = denom[p - 1];
if (piv > 1) {
int ofst = (n - r) % p;
for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
}
}
long ret = 1;
for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
return ret;
}
public static long[][] getcombs(int n) {
var ret = new long[n + 1][];
for (int i = 0; i <= n; i++) {
ret[i] = new long[i + 1];
ret[i][0] = ret[i][i] = 1;
for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod;
}
return ret;
}
// nC0, nC2, ..., nCn
public static long[] getcomb(int n) {
var ret = new long[n + 1];
ret[0] = 1;
for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod;
return ret;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression,
System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;
class Program
{
static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
const int M = 1000000007;
// const int M = 998244353;
const long LM = (long)1e18;
const double eps = 1e-11;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
const string dstring = "RDLU";
static void Main()
{
int a, b, c;
long k;
sc.Multi(out a, out b, out c, out k);
Prt(k % 2 == 0 ? a - b : b - a);
sw.Flush();
}
static void DBG(string a) => Console.WriteLine(a);
static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
static void DBG(params object[] a) => DBG(string.Join(" ", a));
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
public T v1;
public U v2;
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
public override string ToString() => v1 + " " + v2;
}
static class util
{
public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]);
public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2);
public static T sqr<T>(T a) => Operator<T>.Multiply(a, a);
public static T Max<T>(params T[] a) => a.Max();
public static T Min<T>(params T[] a) => a.Min();
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w;
public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++) ret[i] = a[i];
return ret;
}
}
static class Operator<T>
{
static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
class Scan
{
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U>
{ T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); }
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b)
{ var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); }
public void Multi<T, U, V>(out T a, out U b, out V c)
{ var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); }
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
{ var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); }
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
{ var ar = StrArr; 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]); }
public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f)
{ var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); }
}
static class mymath
{
public static long Mod = 1000000007;
public static bool isprime(long a) {
if (a < 2) return false;
for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
return true;
}
public static bool[] sieve(int n) {
var p = new bool[n + 1];
for (int i = 2; i <= n; i++) p[i] = true;
for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
return p;
}
public static List<int> getprimes(int n) {
var prs = new List<int>();
var p = sieve(n);
for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
return prs;
}
public static long[][] E(int n) {
var ret = new long[n][];
for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
return ret;
}
public static double[][] dE(int n) {
var ret = new double[n][];
for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; }
return ret;
}
public static long[][] pow(long[][] A, long n) {
if (n == 0) return E(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double[][] pow(double[][] A, long n) {
if (n == 0) return dE(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0;
for (int i = 0; i < n; i++) ret += x[i] * y[i];
return ret;
}
public static double _dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0, r = 0;
for (int i = 0; i < n; i++) {
double s = ret + (x[i] * y[i] + r);
r = (x[i] * y[i] + r) - (s - ret);
ret = s;
}
return ret;
}
public static long dot(long[] x, long[] y) {
int n = x.Length;
long ret = 0;
for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
return ret;
}
public static T[][] trans<T>(T[][] A) {
int n = A[0].Length, m = A.Length;
var ret = new T[n][];
for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
return ret;
}
public static double[] mul(double a, double[] x) {
int n = x.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i];
return ret;
}
public static long[] mul(long a, long[] x) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod;
return ret;
}
public static double[] mul(double[][] A, double[] x) {
int n = A.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static long[] mul(long[][] A, long[] x) {
int n = A.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static double[][] mul(double a, double[][] A) {
int n = A.Length;
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static long[][] mul(long a, long[][] A) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static double[][] mul(double[][] A, double[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[][] mul(long[][] A, long[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[] add(long[] x, long[] y) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
return ret;
}
public static long[][] add(long[][] A, long[][] B) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
return ret;
}
public static long pow(long a, long b) {
if (a >= Mod) return pow(a % Mod, b);
if (a == 0) return 0;
if (b == 0) return 1;
var t = pow(a, b / 2);
if ((b & 1) == 0) return t * t % Mod;
return t * t % Mod * a % Mod;
}
public static long inv(long a) => pow(a, Mod - 2);
public static long gcd(long a, long b) {
while (b > 0) { var t = a % b; a = b; b = t; } return a;
}
// a x + b y = gcd(a, b)
public static long extgcd(long a, long b, out long x, out long y) {
long g = a; x = 1; y = 0;
if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
return g;
}
public static long lcm(long a, long b) => a / gcd(a, b) * b;
static long[] facts;
public static long[] setfacts(int n) {
facts = new long[n + 1];
facts[0] = 1;
for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod;
return facts;
}
public static long comb(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
if (n - r < r) r = n - r;
if (r == 0) return 1;
if (r == 1) return n;
if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod;
int[] numer = new int[r], denom = new int[r];
for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
for (int p = 2; p <= r; p++) {
int piv = denom[p - 1];
if (piv > 1) {
int ofst = (n - r) % p;
for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
}
}
long ret = 1;
for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
return ret;
}
public static long[][] getcombs(int n) {
var ret = new long[n + 1][];
for (int i = 0; i <= n; i++) {
ret[i] = new long[i + 1];
ret[i][0] = ret[i][i] = 1;
for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod;
}
return ret;
}
// nC0, nC2, ..., nCn
public static long[] getcomb(int n) {
var ret = new long[n + 1];
ret[0] = 1;
for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod;
return ret;
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 4,246
| 3
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace AGC024B {
class Program {
static void Main(string[] args) {
var N = RInt;
var P = RIntsC(N);
var Q = new int[N];
for (int i = 0; i < N; i++) {
Q[P[i] - 1] = i;
}
//変えなくて良いのはいくつある?
int ans = 1;
int cand = 1;
for (int i = 0; i < N - 1; i++) {
if (Q[i] < Q[i + 1]) {
cand++;
ans = Math.Max(cand, ans);
} else
cand = 1;
}
if (N == 1)
ans = 0;
Console.WriteLine(N - ans);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace AGC024B {
class Program {
static void Main(string[] args) {
var N = RInt;
var P = RIntsC(N);
var Q = new int[N];
for (int i = 0; i < N; i++) {
Q[P[i] - 1] = i;
}
//変えなくて良いのはいくつある?
int ans = 1;
int cand = 1;
for (int i = 0; i < N - 1; i++) {
if (Q[i] < Q[i + 1]) {
cand++;
ans = Math.Max(cand, ans);
} else
cand = 1;
}
if (N == 1)
ans = N;
Console.WriteLine(N - ans);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
[["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22]]
| 8
| 1,240
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
public class B {
public static void Main() {
int N = GetInt();
int[] P = new int[N];
for (int i = 0; i < N; i++)
P[i] = GetInt() - 1;
int[] Q = new int[N];
for (int i = 0; i < N; i++)
Q[P[i]] = i;
int len = 0;
int num = 1;
for (int j = 1; j < N; j++) {
if (Q[j] > Q[j - 1])
num++;
else
num = 1;
len = Math.Max(len, num);
}
Console.WriteLine(N - len);
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
public class B {
public static void Main() {
int N = GetInt();
int[] P = new int[N];
for (int i = 0; i < N; i++)
P[i] = GetInt() - 1;
int[] Q = new int[N];
for (int i = 0; i < N; i++)
Q[P[i]] = i;
int len = 1;
int num = 1;
for (int j = 1; j < N; j++) {
if (Q[j] > Q[j - 1])
num++;
else
num = 1;
len = Math.Max(len, num);
}
Console.WriteLine(N - len);
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 334
| 2
|
using System.Collections.Generic;
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine().Trim());
var d = new Dictionary<int, int>();
for (int i = 0; i < n; i++)
d[int.Parse(Console.ReadLine().Trim())] = i;
var ret = 1;
var pre = d[1];
var te = 1;
for (int i = 2; i <= n; i++) {
if (d[i] > pre) {
te++;
ret = Math.Max(ret, te);
} else
te = 1;
pre = d[i];
}
Console.WriteLine(ret);
}
}
|
using System.Collections.Generic;
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine().Trim());
var d = new Dictionary<int, int>();
for (int i = 0; i < n; i++)
d[int.Parse(Console.ReadLine().Trim())] = i;
var ret = 1;
var pre = d[1];
var te = 1;
for (int i = 2; i <= n; i++) {
if (d[i] > pre) {
te++;
ret = Math.Max(ret, te);
} else
te = 1;
pre = d[i];
}
Console.WriteLine(n - ret);
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
| 8
| 166
| 2
|
using System;
using System.Collections.Generic;
namespace Backfront {
class ConsoleInput {
private string[] currentLine = null;
private int currentCursor = 0;
public string Get() {
if (currentLine == null || currentCursor >= currentLine.Length) {
currentLine = Console.ReadLine().Split(' ');
currentCursor = 0;
}
var res = currentLine[currentCursor];
currentCursor++;
return res;
}
public int GetInt() { return int.Parse(Get()); }
}
struct Pair : IComparable<Pair> {
public int index;
public int value;
public int CompareTo(Pair other) { return this.value - other.value; }
}
class Program {
static ConsoleInput input = new ConsoleInput();
static void Main(string[] args) {
int N = input.GetInt();
var P = new List<Pair>();
for (int i = 0; i < N; ++i) {
P.Add(new Pair { index = i, value = input.GetInt() });
}
P.Sort();
int counter = 1;
int maxCount = 0;
for (int i = 0; i < N - 1; ++i) {
if (P[i].index < P[i + 1].index) {
counter++;
if (counter > maxCount)
maxCount = counter;
} else {
counter = 1;
}
}
Console.WriteLine(N - maxCount);
}
}
}
|
using System;
using System.Collections.Generic;
namespace Backfront {
class ConsoleInput {
private string[] currentLine = null;
private int currentCursor = 0;
public string Get() {
if (currentLine == null || currentCursor >= currentLine.Length) {
currentLine = Console.ReadLine().Split(' ');
currentCursor = 0;
}
var res = currentLine[currentCursor];
currentCursor++;
return res;
}
public int GetInt() { return int.Parse(Get()); }
}
struct Pair : IComparable<Pair> {
public int index;
public int value;
public int CompareTo(Pair other) { return this.value - other.value; }
}
class Program {
static ConsoleInput input = new ConsoleInput();
static void Main(string[] args) {
int N = input.GetInt();
var P = new List<Pair>();
for (int i = 0; i < N; ++i) {
P.Add(new Pair { index = i, value = input.GetInt() });
}
P.Sort();
int counter = 1;
int maxCount = 1;
for (int i = 0; i < N - 1; ++i) {
if (P[i].index < P[i + 1].index) {
counter++;
if (counter > maxCount)
maxCount = counter;
} else {
counter = 1;
}
}
Console.WriteLine(N - maxCount);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 302
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
using static AtCoder.CalcL;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
// const int MOD = 998244353;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dI = { 0, 1, 0, -1 };
static readonly int[] dJ = { 1, 0, -1, 0 };
// static List<List<int>> G = new List<List<int>>();
// static List<List<Edge>>G = new List<List<Edge>>();
// static List<Edge> E = new List<Edge>();
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
int N = int.Parse(Console.ReadLine());
var a = new long[N];
for (var i = 0; i < N; i++)
a[i] = long.Parse(Console.ReadLine());
long ans = 0;
for (var i = 0; i < N; i++) {
if (i == 0) {
if (a[0] != 0) {
Console.WriteLine(-1);
return;
}
} else {
if (a[i] - a[i - 1] > 2) {
Console.WriteLine(-1);
return;
} else if (a[i] - a[i - 1] == 1) {
ans++;
} else {
ans += a[i];
}
}
}
Console.WriteLine(ans);
// Console.Out.Flush();
}
struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
}
public class Scanner {
public int[] ReadSplitInt() {
return ConvertAll(Console.ReadLine().Split(), int.Parse);
}
public long[] ReadSplitLong() {
return ConvertAll(Console.ReadLine().Split(), long.Parse);
}
public double[] ReadSplit_Double() {
return ConvertAll(Console.ReadLine().Split(), double.Parse);
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Display<T>(T[,] array2d, int n, int m) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
Console.Write($"{array2d[i, j]} ");
}
Console.WriteLine();
}
}
static public long LPow(int a, int b) { return (long)Pow(a, b); }
}
static public class CalcI {
public static int Gcd(int a, int b) {
if (a * b == 0) {
return Max(a, b);
}
return a % b == 0 ? b : Gcd(b, a % b);
}
public static int Lcm(int a, int b) {
int g = Gcd(a, b);
return a / g * b;
}
public static int Ceil(int n, int div) { return (n + div - 1) / div; }
}
static public class CalcL {
public static long Gcd(long a, long b) {
if (a * b == 0) {
return Max(a, b);
}
return a % b == 0 ? b : Gcd(b, a % b);
}
public static long Lcm(long a, long b) {
long g = Gcd(a, b);
return a / g * b;
}
public static long Ceil(long n, long div) { return (n + div - 1) / div; }
}
class Modulo {
private const long M = 1000000007;
// private const int M = 998244353;
private readonly long[] m_facs;
public long Mul(long a, long b) { return ((a * b) % M); }
public Modulo(long n) {
m_facs = new long[n + 1];
m_facs[0] = 1;
for (long i = 1; i <= n; ++i) {
m_facs[i] = Mul(m_facs[i - 1], i);
}
}
public long Fac(long n) { return m_facs[n]; }
public long Pow(long a, long m) {
switch (m) {
case 0:
return 1L;
case 1:
return a;
default:
long p1 = Pow(a, m / 2);
long p2 = Mul(p1, p1);
return ((m % 2) == 0) ? p2 : Mul(p2, a);
}
}
public long Div(long a, long b) { return Mul(a, Pow(b, M - 2)); }
public long Ncr(long n, long r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
long res = Fac(n);
res = Div(res, Fac(r));
res = Div(res, Fac(n - r));
return res;
}
public Modulo() {}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
using static AtCoder.CalcL;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
// const int MOD = 998244353;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dI = { 0, 1, 0, -1 };
static readonly int[] dJ = { 1, 0, -1, 0 };
// static List<List<int>> G = new List<List<int>>();
// static List<List<Edge>>G = new List<List<Edge>>();
// static List<Edge> E = new List<Edge>();
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
int N = int.Parse(Console.ReadLine());
var a = new long[N];
for (var i = 0; i < N; i++)
a[i] = long.Parse(Console.ReadLine());
long ans = 0;
for (var i = 0; i < N; i++) {
if (i == 0) {
if (a[0] != 0) {
Console.WriteLine(-1);
return;
}
} else {
if (a[i] - a[i - 1] >= 2) {
Console.WriteLine(-1);
return;
} else if (a[i] - a[i - 1] == 1) {
ans++;
} else {
ans += a[i];
}
}
}
Console.WriteLine(ans);
// Console.Out.Flush();
}
struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
}
public class Scanner {
public int[] ReadSplitInt() {
return ConvertAll(Console.ReadLine().Split(), int.Parse);
}
public long[] ReadSplitLong() {
return ConvertAll(Console.ReadLine().Split(), long.Parse);
}
public double[] ReadSplit_Double() {
return ConvertAll(Console.ReadLine().Split(), double.Parse);
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Display<T>(T[,] array2d, int n, int m) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
Console.Write($"{array2d[i, j]} ");
}
Console.WriteLine();
}
}
static public long LPow(int a, int b) { return (long)Pow(a, b); }
}
static public class CalcI {
public static int Gcd(int a, int b) {
if (a * b == 0) {
return Max(a, b);
}
return a % b == 0 ? b : Gcd(b, a % b);
}
public static int Lcm(int a, int b) {
int g = Gcd(a, b);
return a / g * b;
}
public static int Ceil(int n, int div) { return (n + div - 1) / div; }
}
static public class CalcL {
public static long Gcd(long a, long b) {
if (a * b == 0) {
return Max(a, b);
}
return a % b == 0 ? b : Gcd(b, a % b);
}
public static long Lcm(long a, long b) {
long g = Gcd(a, b);
return a / g * b;
}
public static long Ceil(long n, long div) { return (n + div - 1) / div; }
}
class Modulo {
private const long M = 1000000007;
// private const int M = 998244353;
private readonly long[] m_facs;
public long Mul(long a, long b) { return ((a * b) % M); }
public Modulo(long n) {
m_facs = new long[n + 1];
m_facs[0] = 1;
for (long i = 1; i <= n; ++i) {
m_facs[i] = Mul(m_facs[i - 1], i);
}
}
public long Fac(long n) { return m_facs[n]; }
public long Pow(long a, long m) {
switch (m) {
case 0:
return 1L;
case 1:
return a;
default:
long p1 = Pow(a, m / 2);
long p2 = Mul(p1, p1);
return ((m % 2) == 0) ? p2 : Mul(p2, a);
}
}
public long Div(long a, long b) { return Mul(a, Pow(b, M - 2)); }
public long Ncr(long n, long r) {
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
long res = Fac(n);
res = Div(res, Fac(r));
res = Div(res, Fac(n - r));
return res;
}
public Modulo() {}
}
}
|
[["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 1,169
| 2
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
class Program {
static void Main() {
long n = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。
long[] nums = new long[n];
for (long i = 0; i < n; i++) {
nums[i] = long.Parse(Console.ReadLine());
}
long answer = 0;
long numMemo = 0;
bool isPossible = true;
if (nums[0] != 0)
isPossible = false;
else {
for (long i = 1; i < n; i++) {
if (nums[i] > numMemo + 1) {
isPossible = false;
break;
}
if (nums[i] == numMemo + 1) {
answer++;
numMemo = nums[i];
}
if (nums[i] < numMemo + 1) {
answer += nums[i];
numMemo = nums[i];
}
}
}
Console.WriteLine((isPossible) ? answer : -1);
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
class Program {
static void Main() {
long n = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。
long[] nums = new long[n];
for (long i = 0; i < n; i++) {
nums[i] = long.Parse(Console.ReadLine());
}
long answer = 0;
long numMemo = 0;
bool isPossible = true;
if (nums[0] != 0)
isPossible = false;
else {
for (long i = 1; i < n; i++) {
// Console.WriteLine(answer);
if (nums[i] > numMemo + 1) {
isPossible = false;
break;
} else if (nums[i] == numMemo + 1) {
answer++;
numMemo = nums[i];
} else if (nums[i] < numMemo + 1) {
answer += nums[i];
numMemo = nums[i];
}
}
}
Console.WriteLine((isPossible) ? answer : -1);
}
}
|
[["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95]]
| 8
| 215
| 2
|
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine().Trim());
var a0 = int.Parse(Console.ReadLine().Trim());
if (a0 != 0) {
Console.WriteLine(-1);
goto end;
}
var p = 0;
var ret = 0L;
var pre = 0;
for (int i = 1; i < n; i++) {
var aw = int.Parse(Console.ReadLine().Trim());
var w = aw - pre;
if (w >= 2) {
Console.WriteLine(-1);
goto end;
}
if (w <= 0) {
ret += i - 1 - p;
p = i - 1;
}
pre = aw;
}
ret += n - 1 - p;
Console.WriteLine(ret);
end:;
}
}
|
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine().Trim());
var a0 = int.Parse(Console.ReadLine().Trim());
if (a0 != 0) {
Console.WriteLine(-1);
goto end;
}
var p = 0;
var ret = 0L;
var pre = 0;
for (int i = 1; i < n; i++) {
var aw = int.Parse(Console.ReadLine().Trim());
var w = aw - pre;
if (w >= 2) {
Console.WriteLine(-1);
goto end;
}
if (w <= 0) {
ret += i - 1 - p;
p = i - aw;
}
pre = aw;
}
ret += n - 1 - p;
Console.WriteLine(ret);
end:;
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 190
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
int[] A = cin.ArrayInt(N);
if (A[0] != 0) {
Console.WriteLine(-1);
return;
}
for (int i = 1; i < N; i++) {
if (A[i] > A[i] + 1) {
Console.WriteLine(-1);
return;
}
}
long ans = 0;
for (int i = 0; i < N; i++) {
if (i != N - 1 && A[i + 1] == A[i] + 1)
continue;
ans += A[i];
}
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
int[] A = cin.ArrayInt(N);
if (A[0] != 0) {
Console.WriteLine(-1);
return;
}
for (int i = 1; i < N; i++) {
if (A[i] > A[i - 1] + 1) {
Console.WriteLine(-1);
return;
}
}
long ans = 0;
for (int i = 0; i < N; i++) {
if (i != N - 1 && A[i + 1] == A[i] + 1)
continue;
ans += A[i];
}
Console.WriteLine(ans);
}
}
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;
}
}
|
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 579
| 2
|
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;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var g = Enumerate(n, x => new int[n]);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
g[i][j] = g[j][i] = 100000;
var G = Enumerate(n, x => new List<int>());
var pair = new List<int[]>();
for (int i = 0; i < n; i++)
pair.Add(new int[] { i, i });
for (int i = 0; i < n - 1; i++) {
var u = ri - 1;
var v = ri - 1;
g[u][v] = g[v][u] = 1;
G[u].Add(v);
G[v].Add(u);
pair.Add(new int[] { u, v });
}
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
g[i][j] = Min(g[i][j], g[i][k] + g[k][j]);
var val = Enumerate(n + 5, x => INF);
foreach (var p in pair) {
var c = p[0];
var d = p[1];
var pos = Enumerate(n + 5, x => new List<int>());
for (int i = 0; i < n; i++) {
var max = Max(g[c][i], g[d][i]);
pos[max].Add(i);
}
var used = new bool[n + 5];
var sz = new int[n + 5];
int dep = 0;
for (int i = n + 3; i >= 0; i--) {
if (pos[i].Count == 0)
continue;
sz[i] = 1;
dep = Max(dep, i);
foreach (var v in pos[i]) {
var cnt = 0;
foreach (var t in G[v])
if (used[t])
cnt++;
sz[i] = Max(sz[i], cnt * sz[i + 1]);
}
foreach (var v in pos[i])
used[v] = true;
}
if (c == d)
val[dep + 1] = Min(val[dep + 1], sz[0]);
else
val[dep] = Min(val[dep], 2 * sz[1]);
}
for (int i = 0; i <= n; i++)
if (val[i] != INF) {
Console.WriteLine($"{i} {val[i]}");
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;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var g = Enumerate(n, x => new int[n]);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
g[i][j] = g[j][i] = 100000;
var G = Enumerate(n, x => new List<int>());
var pair = new List<int[]>();
for (int i = 0; i < n; i++)
pair.Add(new int[] { i, i });
for (int i = 0; i < n - 1; i++) {
var u = ri - 1;
var v = ri - 1;
g[u][v] = g[v][u] = 1;
G[u].Add(v);
G[v].Add(u);
pair.Add(new int[] { u, v });
}
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
g[i][j] = Min(g[i][j], g[i][k] + g[k][j]);
var val = Enumerate(n + 5, x => INF);
foreach (var p in pair) {
var c = p[0];
var d = p[1];
var pos = Enumerate(n + 5, x => new List<int>());
for (int i = 0; i < n; i++) {
var max = Max(g[c][i], g[d][i]);
pos[max].Add(i);
}
var used = new bool[n + 5];
var sz = new long[n + 5];
int dep = 0;
for (int i = n + 3; i >= 0; i--) {
if (pos[i].Count == 0)
continue;
sz[i] = 1;
dep = Max(dep, i);
foreach (var v in pos[i]) {
var cnt = 0;
foreach (var t in G[v])
if (used[t])
cnt++;
sz[i] = Max(sz[i], cnt * sz[i + 1]);
}
foreach (var v in pos[i])
used[v] = true;
}
if (c == d)
val[dep + 1] = Min(val[dep + 1], sz[0]);
else
val[dep] = Min(val[dep], 2 * sz[1]);
}
for (int i = 0; i <= n; i++)
if (val[i] != INF) {
Console.WriteLine($"{i} {val[i]}");
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, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
| 8
| 1,469
| 2
|
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 (N == 2) {
Console.WriteLine("{0} {1}", 1, 0);
return;
}
E = new HashSet<int>[N];
for (int i = 0; i < N; i++)
E[i] = new HashSet<int>();
for (int i = 0; i < N - 1; i++) {
E[A[i]].Add(B[i]);
E[B[i]].Add(A[i]);
}
int[] farthest = new int[2];
int[] depth = null;
int[] parent = null;
for (int t = 0; t < 2; t++) {
var rt = farthest[0];
depth = new int[N];
parent = new int[N];
depth[rt] = 0;
parent[rt] = -1;
int maxdep = 0;
int deepest = rt;
var q = new Queue<int>();
q.Enqueue(rt);
while (q.Count > 0) {
var now = q.Dequeue();
foreach (var nxt in E[now]) {
if (nxt != parent[now]) {
depth[nxt] = depth[now] + 1;
parent[nxt] = now;
if (depth[nxt] > maxdep) {
maxdep = depth[nxt];
deepest = nxt;
}
q.Enqueue(nxt);
}
}
}
farthest[t] = deepest;
}
int diam = depth[farthest[1]];
List<int> tops = new List<int>();
for (int now = farthest[1]; now != farthest[0]; now = parent[now]) {
if (diam % 2 == 0) {
if (depth[now] == diam / 2)
tops.Add(now);
} else {
if (depth[now] == diam / 2 || depth[now] == diam / 2 + 1)
tops.Add(now);
}
}
List<List<int>> candis = new List<List<int>>();
candis.Add(tops);
if (tops.Count == 1) {
foreach (var nxt in E[tops[0]]) {
candis.Add(new List<int>() { tops[0], nxt });
}
}
long min = long.MaxValue;
foreach (var ctops in candis) {
long[] dp = new long[diam / 2 + 1];
depth = new int[N];
parent = new int[N];
var qq = new Queue<int>();
foreach (var n in ctops) {
depth[n] = 0;
parent[n] = -1;
qq.Enqueue(n);
}
if (ctops.Count == 2) {
E[ctops[0]].Remove(ctops[1]);
E[ctops[1]].Remove(ctops[0]);
}
while (qq.Count > 0) {
var now = qq.Dequeue();
int nchild = E[now].Count;
if (parent[now] != -1)
nchild--;
dp[depth[now]] = Math.Max(dp[depth[now]], nchild);
foreach (var nxt in E[now]) {
if (nxt != parent[now]) {
depth[nxt] = depth[now] + 1;
parent[nxt] = now;
qq.Enqueue(nxt);
}
}
}
long ans = (long)ctops.Count;
for (int i = 0; i < dp.Length - 1; i++)
ans *= dp[i];
min = Math.Min(min, ans);
if (ctops.Count == 2) {
E[ctops[0]].Add(ctops[1]);
E[ctops[1]].Add(ctops[0]);
}
}
Console.WriteLine("{0} {1}", diam / 2 + 1, min);
}
HashSet<int>[] E;
int N;
int[] A, B;
public Sol() {
N = ri();
A = new int[N - 1];
B = new int[N - 1];
for (int i = 0; i < N - 1; i++) {
var d = ria();
A[i] = d[0] - 1;
B[i] = d[1] - 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 (N == 2) {
Console.WriteLine("{0} {1}", 1, 2);
return;
}
E = new HashSet<int>[N];
for (int i = 0; i < N; i++)
E[i] = new HashSet<int>();
for (int i = 0; i < N - 1; i++) {
E[A[i]].Add(B[i]);
E[B[i]].Add(A[i]);
}
int[] farthest = new int[2];
int[] depth = null;
int[] parent = null;
for (int t = 0; t < 2; t++) {
var rt = farthest[0];
depth = new int[N];
parent = new int[N];
depth[rt] = 0;
parent[rt] = -1;
int maxdep = 0;
int deepest = rt;
var q = new Queue<int>();
q.Enqueue(rt);
while (q.Count > 0) {
var now = q.Dequeue();
foreach (var nxt in E[now]) {
if (nxt != parent[now]) {
depth[nxt] = depth[now] + 1;
parent[nxt] = now;
if (depth[nxt] > maxdep) {
maxdep = depth[nxt];
deepest = nxt;
}
q.Enqueue(nxt);
}
}
}
farthest[t] = deepest;
}
int diam = depth[farthest[1]];
List<int> tops = new List<int>();
for (int now = farthest[1]; now != farthest[0]; now = parent[now]) {
if (diam % 2 == 0) {
if (depth[now] == diam / 2)
tops.Add(now);
} else {
if (depth[now] == diam / 2 || depth[now] == diam / 2 + 1)
tops.Add(now);
}
}
List<List<int>> candis = new List<List<int>>();
candis.Add(tops);
if (tops.Count == 1) {
foreach (var nxt in E[tops[0]]) {
candis.Add(new List<int>() { tops[0], nxt });
}
}
long min = long.MaxValue;
foreach (var ctops in candis) {
long[] dp = new long[diam / 2 + 1];
depth = new int[N];
parent = new int[N];
var qq = new Queue<int>();
foreach (var n in ctops) {
depth[n] = 0;
parent[n] = -1;
qq.Enqueue(n);
}
if (ctops.Count == 2) {
E[ctops[0]].Remove(ctops[1]);
E[ctops[1]].Remove(ctops[0]);
}
while (qq.Count > 0) {
var now = qq.Dequeue();
int nchild = E[now].Count;
if (parent[now] != -1)
nchild--;
dp[depth[now]] = Math.Max(dp[depth[now]], nchild);
foreach (var nxt in E[now]) {
if (nxt != parent[now]) {
depth[nxt] = depth[now] + 1;
parent[nxt] = now;
qq.Enqueue(nxt);
}
}
}
long ans = (long)ctops.Count;
for (int i = 0; i < dp.Length - 1; i++)
ans *= dp[i];
min = Math.Min(min, ans);
if (ctops.Count == 2) {
E[ctops[0]].Add(ctops[1]);
E[ctops[1]].Add(ctops[0]);
}
}
Console.WriteLine("{0} {1}", diam / 2 + 1, min);
}
HashSet<int>[] E;
int N;
int[] A, B;
public Sol() {
N = ri();
A = new int[N - 1];
B = new int[N - 1];
for (int i = 0; i < N - 1; i++) {
var d = ria();
A[i] = d[0] - 1;
B[i] = d[1] - 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));
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 1,231
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0040 {
class Program {
static void Main(string[] args) {
var St = Console.ReadLine();
long a = long.Parse(St.Split(' ')[0]);
long b = long.Parse(St.Split(' ')[1]);
long c = long.Parse(St.Split(' ')[2]);
long d = long.Parse(St.Split(' ')[3]);
if (Math.Abs(a - c) <= d && Math.Abs(a - b) <= d && Math.Abs(b - c) <= d) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0040 {
class Program {
static void Main(string[] args) {
var St = Console.ReadLine();
long a = long.Parse(St.Split(' ')[0]);
long b = long.Parse(St.Split(' ')[1]);
long c = long.Parse(St.Split(' ')[2]);
long d = long.Parse(St.Split(' ')[3]);
if (Math.Abs(a - c) <= d ||
(Math.Abs(a - b) <= d && Math.Abs(b - c) <= d)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 193
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public const long DpInf = 99999999999;
public static void Main(string[] args) {
var n = Input().ToInt();
var a = n[0];
var b = n[1];
var c = n[2];
var d = n[3];
if (Math.Abs(a - b) <= 3 && Math.Abs(b - c) <= 3 || Math.Abs(a - c) <= 3) {
Console.WriteLine("Yes");
return;
}
Console.WriteLine("No");
}
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 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 const long DpInf = 99999999999;
public static void Main(string[] args) {
var n = Input().ToInt();
var a = n[0];
var b = n[1];
var c = n[2];
var d = n[3];
if (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d || Math.Abs(a - c) <= d) {
Console.WriteLine("Yes");
return;
}
Console.WriteLine("No");
}
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 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, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 338
| 6
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.