buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
string S = cin.next();
int black = 0;
int white = 0;
int min = N;
for (int i = 0; i < N; i++) {
if (S[i] == '.')
white++;
}
for (int i = 0; i < N; i++) {
if (S[i] == '#')
black++;
else
white--;
if (black + white < min)
min = black + white;
}
Console.WriteLine(min);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
string S = cin.next();
int black = 0;
int white = 0;
for (int i = 0; i < N; i++) {
if (S[i] == '.')
white++;
}
int min = white;
for (int i = 0; i < N; i++) {
if (S[i] == '#')
black++;
else
white--;
if (black + white < min)
min = black + white;
}
if (black == N)
min = 0;
Console.WriteLine(min);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 551
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace C {
class Program {
static void Main(string[] args) {
int n = RInt();
string s = RSt();
int resA = s.Count(x => x == '#');
int resB = s.Count(x => x == '.');
int allChange = Math.Min(resA, resB);
int[] sharpCnts = new int[s.Length];
for (int i = 1; i < s.Length; i++) {
if (s[i] == '#') {
sharpCnts[i] = sharpCnts[i - 1] + 1;
} else {
sharpCnts[i] = sharpCnts[i - 1];
}
}
int res = int.MaxValue;
for (int i = 0; i < s.Length - 1; i++) {
if (s[i] == '.' && s[i + 1] == '#') {
res = Math.Min(res, sharpCnts[i] + ((s.Length - (i + 1)) -
(sharpCnts[s.Length - 1] -
sharpCnts[i + 1] + 1)));
}
}
Console.WriteLine(Math.Min(res, allChange));
}
static string RSt() { return Console.ReadLine(); }
static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
static double RDouble() { return double.Parse(Console.ReadLine()); }
static string[] RArSt(char sep = ' ') {
return Console.ReadLine().Trim().Split(sep);
}
static int[] RArInt(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => int.Parse(e));
}
static long[] RArLong(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => long.Parse(e));
}
static double[] RArDouble(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => double.Parse(e));
}
static string WAr<T>(IEnumerable<T> array, string sep = " ") {
return string.Join(sep, array.Select(x => x.ToString()).ToArray());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace C {
class Program {
static void Main(string[] args) {
int n = RInt();
string s = RSt();
int resA = s.Count(x => x == '#');
int resB = s.Count(x => x == '.');
int allChange = Math.Min(resA, resB);
int[] sharpCnts = new int[s.Length];
sharpCnts[0] = s[0] == '#' ? 1 : 0;
for (int i = 1; i < s.Length; i++) {
if (s[i] == '#') {
sharpCnts[i] = sharpCnts[i - 1] + 1;
} else {
sharpCnts[i] = sharpCnts[i - 1];
}
}
int res = int.MaxValue;
for (int i = 0; i < s.Length - 1; i++) {
if (s[i] == '.' && s[i + 1] == '#') {
res = Math.Min(res, sharpCnts[i] + ((s.Length - (i + 1)) -
(sharpCnts[s.Length - 1] -
sharpCnts[i + 1] + 1)));
}
}
Console.WriteLine(Math.Min(res, allChange));
}
static string RSt() { return Console.ReadLine(); }
static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
static double RDouble() { return double.Parse(Console.ReadLine()); }
static string[] RArSt(char sep = ' ') {
return Console.ReadLine().Trim().Split(sep);
}
static int[] RArInt(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => int.Parse(e));
}
static long[] RArLong(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => long.Parse(e));
}
static double[] RArDouble(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => double.Parse(e));
}
static string WAr<T>(IEnumerable<T> array, string sep = " ") {
return string.Join(sep, array.Select(x => x.ToString()).ToArray());
}
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 11, 12, 41, 15, 16, 31, 204, 205, 22], ["+", 12, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["+", 0, 11, 12, 41, 15, 16, 12, 252, 0, 104], ["+", 0, 11, 12, 41, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 75, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 575
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtC {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
char before = '.';
int count = 0;
var list = new List<int>();
for (int i = 0; i < S.Length; i++) {
if (S[i] != before) {
before = S[i];
list.Add(count);
count = 1;
} else
count++;
}
if (count != 0)
list.Add(count);
if (list.Count == 1) {
Console.WriteLine(0);
return;
}
int left = 0, right = 0;
for (int i = 0; i < list.Count; i += 2) {
right += list[i];
}
var counts = new List<int>();
for (int i = 1; i < list.Count; i += 2) {
counts.Add(left + right);
left += list[i];
right -= list[i - 1];
}
counts.Add(left + right);
Console.WriteLine(counts.Min());
}
}
static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtC {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
char before = '.';
int count = 0;
var list = new List<int>();
for (int i = 0; i < S.Length; i++) {
if (S[i] != before) {
before = S[i];
list.Add(count);
count = 1;
} else
count++;
}
if (count != 0)
list.Add(count);
if ((list.Count & 1) == 0)
list.Add(0);
if (list.Count == 1) {
Console.WriteLine(0);
return;
}
int left = 0, right = 0;
for (int i = 0; i < list.Count; i += 2) {
right += list[i];
}
var counts = new List<int>();
for (int i = 1; i < list.Count; i += 2) {
right -= list[i - 1];
counts.Add(left + right);
left += list[i];
}
counts.Add(left);
Console.WriteLine(counts.Min());
}
}
static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 67], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 328
| 39
|
using System;
namespace D {
class Dmondai {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(Console.ReadLine());
}
int s = 0;
for (int i = 0; i < n; i++) {
s += a[i];
}
long[,] dp = new long[n + 1, s + 1];
long[,] dp2 = new long[n + 1, s + 1];
dp[0, 0] = 1;
dp2[0, 0] = 1;
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j < s + 1; j++) {
if (j + a[i - 1] <= s) {
dp[i, j + a[i - 1]] += dp[i - 1, j];
dp2[i, j + a[i - 1]] += dp2[i - 1, j];
dp[i, j + a[i - 1]] %= 998244353;
dp2[i, j + a[i - 1]] %= 998244353;
}
dp[i, j] += dp[i - 1, j] * 2;
dp2[i, j] += dp2[i - 1, j];
dp[i, j] %= 998244353;
dp2[i, j] %= 998244353;
}
}
long ans = 1;
for (int i = 0; i < n; i++) {
ans *= 3;
ans %= 998244353;
}
for (int i = (s + 1) / 2; i < s + 1; i++) {
ans -= dp[n, i] * 3;
ans %= 998244353;
}
if (s % 2 == 0) {
ans += dp2[n, s / 2] * 3;
}
Console.WriteLine((ans % 998244353).ToString());
}
}
}
|
using System;
namespace D {
class Dmondai {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(Console.ReadLine());
}
int s = 0;
for (int i = 0; i < n; i++) {
s += a[i];
}
long[,] dp = new long[n + 1, s + 1];
long[,] dp2 = new long[n + 1, s + 1];
dp[0, 0] = 1;
dp2[0, 0] = 1;
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j < s + 1; j++) {
if (j + a[i - 1] <= s) {
dp[i, j + a[i - 1]] += dp[i - 1, j];
dp2[i, j + a[i - 1]] += dp2[i - 1, j];
dp[i, j + a[i - 1]] %= 998244353;
dp2[i, j + a[i - 1]] %= 998244353;
}
dp[i, j] += dp[i - 1, j] * 2;
dp2[i, j] += dp2[i - 1, j];
dp[i, j] %= 998244353;
dp2[i, j] %= 998244353;
}
}
long ans = 1;
for (int i = 0; i < n; i++) {
ans *= 3;
ans %= 998244353;
}
for (int i = (s + 1) / 2; i < s + 1; i++) {
ans -= dp[n, i] * 3;
ans %= 998244353;
if (ans < 0) {
ans += 998244353;
}
}
if (s % 2 == 0) {
ans += dp2[n, s / 2] * 3;
}
Console.WriteLine((ans % 998244353).ToString());
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 444
| 12
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC124A {
class Program {
static void Main(string[] args) {
int A = ReadInt;
int B = ReadInt;
if (A > B) {
Console.WriteLine(2 * A - 1);
} else {
Console.WriteLine(2 * B - 1);
}
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String ReadNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int ReadInt => int.Parse(ReadNext());
public static long ReadLong => long.Parse(ReadNext());
public static int[] ReadInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] NextLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
}
static class Debug {
static public void Draw2D(int[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
int[,] map2 = new int[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;
else if (i == 0)
map2[i, j] = j - 1;
else if (j == 0)
map2[i, j] = i - 1;
else
map2[i, j] = map[i - 1, j - 1];
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j] % 10);
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
static void Draw1D(int[] 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 ABC124A {
class Program {
static void Main(string[] args) {
int A = ReadInt;
int B = ReadInt;
if (A > B) {
Console.WriteLine(2 * A - 1);
} else if (A == B)
Console.WriteLine(2 * A);
else {
Console.WriteLine(2 * B - 1);
}
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String ReadNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int ReadInt => int.Parse(ReadNext());
public static long ReadLong => long.Parse(ReadNext());
public static int[] ReadInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] NextLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
}
static class Debug {
static public void Draw2D(int[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
int[,] map2 = new int[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;
else if (i == 0)
map2[i, j] = j - 1;
else if (j == 0)
map2[i, j] = i - 1;
else
map2[i, j] = map[i - 1, j - 1];
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j] % 10);
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
static void Draw1D(int[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
| 8
| 546
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var ab = CinTAr();
int m = ab.Max();
Cout(m + m - 1);
Cin();
}
static int GCD(int a, int b) {
if (a < b) {
swap(ref a, ref b);
}
if (a % b == 0) {
return b;
} else {
return GCD(b, a % b);
}
}
static void swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static readonly int MOD1E9 = 10000007;
static bool isInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static int[] yakusuu(int n) {
if (n == 1) {
return new int[] { 1 };
}
HashSet<int> res = new HashSet<int>();
for (int i = 1; i < Math.Ceiling(n / 2.0); i++) {
if (n % i == 0) {
res.Add(i);
res.Add(n / i);
}
}
return res.ToArray();
}
/// <summary>
/// Debug時のみの使用を推奨
/// </summary>
/// <typeparam name="Type"></typeparam>
/// <param name="types"></param>
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = "";
foreach (var i in types) {
text += " " + i;
}
WriteLine(text.Substring(1));
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var ab = CinTAr();
int m = ab.Max();
if (ab[0] != ab[1]) {
Cout(m + m - 1);
} else {
Cout(m + m);
}
Cin();
}
static int GCD(int a, int b) {
if (a < b) {
swap(ref a, ref b);
}
if (a % b == 0) {
return b;
} else {
return GCD(b, a % b);
}
}
static void swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static readonly int MOD1E9 = 10000007;
static bool isInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static int[] yakusuu(int n) {
if (n == 1) {
return new int[] { 1 };
}
HashSet<int> res = new HashSet<int>();
for (int i = 1; i < Math.Ceiling(n / 2.0); i++) {
if (n % i == 0) {
res.Add(i);
res.Add(n / i);
}
}
return res.ToArray();
}
/// <summary>
/// Debug時のみの使用を推奨
/// </summary>
/// <typeparam name="Type"></typeparam>
/// <param name="types"></param>
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = "";
foreach (var i in types) {
text += " " + i;
}
WriteLine(text.Substring(1));
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 718
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
// using System.Text;
// using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
int[] AB =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int A = AB[0];
int B = AB[1];
int n = Math.Max(A, B);
Console.WriteLine(2 * n - 1);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
// using System.Text;
// using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
int[] AB =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int A = AB[0];
int B = AB[1];
int n = Math.Max(A, B);
if (A == B) {
Console.WriteLine(2 * n);
} else {
Console.WriteLine(2 * n - 1);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 105
| 20
|
using System;
class Program {
static void Main(string[] args) {
var inputValues = Console.ReadLine().Split(' ');
var A = int.Parse(inputValues[0]);
var B = int.Parse(inputValues[1]);
var coins = 0;
for (int i = 0; i <= 1; i++) {
if (A >= B) {
coins += A;
} else {
coins += B;
}
}
Console.WriteLine(coins);
}
}
|
using System;
class Program {
static void Main(string[] args) {
var inputValues = Console.ReadLine().Split(' ');
var A = int.Parse(inputValues[0]);
var B = int.Parse(inputValues[1]);
var coins = 0;
for (int i = 0; i <= 1; i++) {
if (A >= B) {
coins += A;
A += -1;
} else {
coins += B;
B += -1;
}
}
Console.WriteLine(coins);
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 75, 196, 0, 1, 0, 11, 12, 241, 0, 203]]
| 8
| 107
| 10
|
using System;
namespace Sample {
class test {
static void Main() {
int ans = 0;
string[] a = Console.ReadLine().Split(' ');
int A = int.Parse(a[0]);
int B = int.Parse(a[1]);
if (A > B) {
ans += A;
A--;
if (A > B) {
ans += A;
}
if (A == B) {
ans += A;
}
}
if (B > A) {
ans += B;
B--;
if (A < B) {
ans += B;
}
if (A == B) {
ans += A;
}
}
if (A == B) {
ans = A + B;
}
Console.WriteLine(ans);
}
}
}
|
using System;
namespace Sample {
class test {
static void Main() {
int ans = 0;
string[] a = Console.ReadLine().Split(' ');
int A = int.Parse(a[0]);
int B = int.Parse(a[1]);
while (true) {
if (A > B) {
ans += A;
A--;
if (A > B) {
ans += A;
break;
}
if (A == B) {
ans += A;
break;
}
}
if (B > A) {
ans += B;
B--;
if (A < B) {
ans += B;
break;
}
if (A == B) {
ans += B;
break;
}
}
if (A == B) {
ans = A + B;
break;
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 166
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Buttons {
class Program {
static void Main(string[] args) {
int button1 = 0;
int button2 = 0;
string temp = Console.ReadLine();
string[] inp = temp.Split(' ');
button1 = Convert.ToInt16(inp[0]);
button2 = Convert.ToInt16(inp[1]);
if (button1 > button2) {
Console.WriteLine(2 * button1 - 1);
} else {
Console.WriteLine(2 * button2 - 1);
}
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Buttons {
class Program {
static void Main(string[] args) {
int button1 = 0;
int button2 = 0;
string temp = Console.ReadLine();
string[] inp = temp.Split(' ');
button1 = Convert.ToInt16(inp[0]);
button2 = Convert.ToInt16(inp[1]);
if (button1 > button2) {
Console.WriteLine(2 * button1 - 1);
}
if (button1 == button2) {
Console.WriteLine(2 * button1);
}
if (button1 < button2) {
Console.WriteLine(2 * button2 - 1);
}
Console.ReadLine();
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 142
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
string[] sS = System.Console.ReadLine().Trim().Split(' ');
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// 解析
List<int> lstInp = new List<int>();
for (int i = 0; i < sS.Length; i++) {
lstInp.Add(int.Parse(sS[i]));
}
int iOut = 0;
lstInp.Sort();
iOut += lstInp[1];
lstInp[1] -= 1;
lstInp.Sort();
iOut += lstInp[1];
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
string[] sS = System.Console.ReadLine().Trim().Split(' ');
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// 解析
List<int> lstInp = new List<int>();
for (int i = 0; i < sS.Length; i++) {
lstInp.Add(int.Parse(sS[i]));
}
int iOut = 0;
lstInp.Sort();
iOut += lstInp[1];
lstInp[1] -= 1;
lstInp.Sort();
iOut += lstInp[1];
// 出力
System.Console.WriteLine("{0}", iOut.ToString());
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
|
[["+", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 217
| 17
|
using System;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var A = int.Parse(input[0]);
var B = int.Parse(input[1]);
var result = 0;
for (var i = 0; i < 2; i++) {
result += Math.Max(A, B);
}
result--;
Console.WriteLine(result);
}
}
|
using System;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var A = int.Parse(input[0]);
var B = int.Parse(input[1]);
var result = 0;
for (var i = 0; i < 2; i++) {
result += Math.Max(A, B);
}
if (A != B) {
result--;
}
Console.WriteLine(result);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 102
| 8
|
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) {
// 提出時にはコメントアウトする
var exStdIn = new System.IO.StreamReader("stdin.txt");
System.Console.SetIn(exStdIn);
// 解答
int ret = 0;
// 読み込み
string line = Console.ReadLine();
// 半角スペースでsplit
string[] lineSplit = line.Split(' ');
// intに変換
int a = int.Parse(lineSplit[0]);
int b = int.Parse(lineSplit[1]);
// 2回繰り返す
for (int i = 0; i < 2; i++) {
if (a > b) {
ret += a;
a--;
} else {
ret += b;
b--;
}
}
Console.WriteLine(ret);
}
}
}
|
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) {
//// 提出時にはコメントアウトする
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// System.Console.SetIn(exStdIn);
// 解答
int ret = 0;
// 読み込み
string line = Console.ReadLine();
// 半角スペースでsplit
string[] lineSplit = line.Split(' ');
// intに変換
int a = int.Parse(lineSplit[0]);
int b = int.Parse(lineSplit[1]);
// 2回繰り返す
for (int i = 0; i < 2; i++) {
if (a > b) {
ret += a;
a--;
} else {
ret += b;
b--;
}
}
Console.WriteLine(ret);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 234, 22], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 0, 131], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 0, 131], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 178
| 24
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
if (A < B) {
Console.WriteLine(B + (B - 1));
} else if (A > B) {
Console.WriteLine(A + (A - 1));
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
if (A < B) {
Console.WriteLine(B + (B - 1));
} else if (A > B) {
Console.WriteLine(A + (A - 1));
} else if (A == B) {
Console.WriteLine(A + B);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46]]
| 8
| 105
| 18
|
using System;
public class Program {
public static void Main() {
int a;
int b;
string[] str =
Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得
a = int.Parse(str[0]); //数値で受け取りたい場合は変換する
b = int.Parse(str[1]);
int res;
res = a < b ? b * 2 - 1 : a * 2 - 1;
Console.WriteLine(res);
}
}
|
using System;
public class Program {
public static void Main() {
int a;
int b;
string[] str =
Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得
a = int.Parse(str[0]); //数値で受け取りたい場合は変換する
b = int.Parse(str[1]);
int res;
if (a == b) {
res = a * 2;
} else {
res = a < b ? b * 2 - 1 : a * 2 - 1;
}
Console.WriteLine(res);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 94
| 17
|
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 AB = ReadInts();
var A = AB[0];
var B = AB[1];
Print(A + B);
}
}
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,
Func<TR, T, TR> func, TR first) {
var list = source.ToList();
var result = new List<TR> { first };
foreach (var i in Enumerable.Range(1, source.Count())) {
result.Add(func(result[i - 1], 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 AB = ReadInts();
var A = AB[0];
var B = AB[1];
Print(Max(Max(A + A - 1, A + B), B + B - 1));
}
}
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,
Func<TR, T, TR> func, TR first) {
var list = source.ToList();
var result = new List<TR> { first };
foreach (var i in Enumerable.Range(1, source.Count())) {
result.Add(func(result[i - 1], 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);
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 1,770
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] H =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
int cnt = 1;
for (int j = 1; j < N; j++) {
if (H[0] <= H[j] && H[j - 1] <= H[j]) {
cnt++;
}
}
Console.WriteLine(cnt);
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] H =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
int cnt = 0;
long max = 0;
for (int j = 0; j < N; j++) {
if (max <= H[j]) {
max = H[j];
cnt++;
}
}
Console.WriteLine(cnt);
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 167
| 29
|
using System;
using System.Reflection;
namespace study4 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int[] A = new int[20];
for (int count = 0; count < N;) {
A[count] = int.Parse(input[count]);
count++;
}
int ans = 1;
int flag = A[0];
for (int t = 1; t < N;) {
if (flag <= A[t]) {
ans++;
}
t++;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Reflection;
namespace study4 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int[] A = new int[20];
for (int count = 0; count < N;) {
A[count] = int.Parse(input[count]);
count++;
}
int ans = 1;
int flag = A[0];
for (int t = 1; t < N;) {
if (flag <= A[t]) {
ans++;
flag = A[t];
}
t++;
}
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 153
| 7
|
using System;
using System.Linq;
class B {
static void Main() {
Console.ReadLine();
var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
var t = h[0];
Console.WriteLine(h.Skip(1).Count(x => {
var b = x >= t;
t = Math.Max(t, x);
return b;
}));
}
}
|
using System;
using System.Linq;
class B {
static void Main() {
Console.ReadLine();
var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
var t = 0;
Console.WriteLine(h.Count(x => {
var b = x >= t;
t = Math.Max(t, x);
return b;
}));
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25]]
| 8
| 98
| 2
|
using System;
namespace ABC124_b {
class Program {
static void Main(string[] args) {
string[] array1 = Console.ReadLine().Split(' ');
int a = int.Parse(array1[0]);
string[] array2 = Console.ReadLine().Split(' ');
int[] intAry = Array.ConvertAll<string, int>(
array2, delegate(string value) { return int.Parse(value); });
int count = 1;
for (int i = 1; i < a; i++) {
if ((intAry[0] <= intAry[i]) && (intAry[i - 1] <= intAry[i])) {
count++;
}
}
Console.WriteLine(count);
}
}
}
|
using System;
namespace ABC124_b {
class Program {
static void Main(string[] args) {
string[] array1 = Console.ReadLine().Split(' ');
int a = int.Parse(array1[0]);
string[] array2 = Console.ReadLine().Split(' ');
int[] intAry = Array.ConvertAll<string, int>(
array2, delegate(string value) { return int.Parse(value); });
int count = 1;
int max = 0;
max = intAry[0];
for (int i = 1; i < a; i++) {
if ((max <= intAry[i]) && (intAry[i - 1] <= intAry[i])) {
max = intAry[i];
count++;
}
}
Console.WriteLine(count);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 15, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["-", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 165
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AIZUproject08 {
// 128B
/*class Data
{
public int ID { get; set; }
public string Name { get; set; }
public int Evaluation { get; set; }
}
class Program
{
static void Main()
{
List<Data> datalist = new List<Data>();
Data data;
int N = int.Parse(Console.ReadLine());
for (int i=0;i< N;i++)
{
var temp = Console.ReadLine().Split(' ');
data = new Data();
data.ID = i + 1;
data.Name = temp[0];
data.Evaluation = int.Parse(temp[1]);
datalist.Add(data);
}
datalist = datalist.OrderBy(n => n.Name).ThenByDescending(n =>
n.Evaluation).ToList(); foreach (var ans in datalist)
{
Console.WriteLine(ans.ID);
}
}
}*/
// 127B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int r = input[0];
int D = input[1];
int X = input[2];
for (int i=0;i<10;i++)
{
var ans = r * X - D;
Console.WriteLine(ans);
X = ans;
}
}
}*/
// 126B
/*class Program
{
static void Main()
{
List<int> mae = new List<int>();
List<int> ushiro = new List<int>();
string input = Console.ReadLine();
var rabel = "NA";
for (int i = 0; i < 2; i++)
{
char moji = input[i];
mae.Add(int.Parse(string.Join("",moji)));
}
for (int i = 2; i < 4; i++)
{
char moji = input[i];
ushiro.Add(int.Parse(string.Join("", moji)));
}
int A = 10 * mae[0] + 1 * mae[1];
int B = 10 * ushiro[0] + 1 * ushiro[1];
if (0 <= A && A <= 99 && 0 < B && B < 13)
{
rabel = "YYMM";
if (0 < A && A < 13 && 0 < B && B < 13)
{
rabel = "AMBIGUOUS";
}
}
else if (0 <= B && B <= 99 && 0 < A && A < 13)
{
rabel = "MMYY";
if (0 < A && A < 13 && 0 < B && B < 13)
{
rabel = "AMBIGUOUS";
}
}
Console.WriteLine(rabel);
}
}*/
// 125B
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] V = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] C = Console.ReadLine().Split().Select(int.Parse).ToArray();
int Answer = 0;
for (int i=0;i<N;i++)
{
var temp = V[i] - C[i];
if (temp > 0)
{
Answer += temp;
}
}
Console.WriteLine(Answer);
}
}*/
// 124B
class Program {
static void Main() {
int Ans = 0;
int count = 1;
int N = int.Parse(Console.ReadLine());
int[] Height = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0; i < Height.Length; i++) {
for (int j = 0; j < i; j++) {
if (Height[i] >= Height[j]) {
Ans++;
} else {
break;
}
if (Ans == i) {
count++;
}
}
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AIZUproject08 {
// 128B
/*class Data
{
public int ID { get; set; }
public string Name { get; set; }
public int Evaluation { get; set; }
}
class Program
{
static void Main()
{
List<Data> datalist = new List<Data>();
Data data;
int N = int.Parse(Console.ReadLine());
for (int i=0;i< N;i++)
{
var temp = Console.ReadLine().Split(' ');
data = new Data();
data.ID = i + 1;
data.Name = temp[0];
data.Evaluation = int.Parse(temp[1]);
datalist.Add(data);
}
datalist = datalist.OrderBy(n => n.Name).ThenByDescending(n =>
n.Evaluation).ToList(); foreach (var ans in datalist)
{
Console.WriteLine(ans.ID);
}
}
}*/
// 127B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int r = input[0];
int D = input[1];
int X = input[2];
for (int i=0;i<10;i++)
{
var ans = r * X - D;
Console.WriteLine(ans);
X = ans;
}
}
}*/
// 126B
/*class Program
{
static void Main()
{
List<int> mae = new List<int>();
List<int> ushiro = new List<int>();
string input = Console.ReadLine();
var rabel = "NA";
for (int i = 0; i < 2; i++)
{
char moji = input[i];
mae.Add(int.Parse(string.Join("",moji)));
}
for (int i = 2; i < 4; i++)
{
char moji = input[i];
ushiro.Add(int.Parse(string.Join("", moji)));
}
int A = 10 * mae[0] + 1 * mae[1];
int B = 10 * ushiro[0] + 1 * ushiro[1];
if (0 <= A && A <= 99 && 0 < B && B < 13)
{
rabel = "YYMM";
if (0 < A && A < 13 && 0 < B && B < 13)
{
rabel = "AMBIGUOUS";
}
}
else if (0 <= B && B <= 99 && 0 < A && A < 13)
{
rabel = "MMYY";
if (0 < A && A < 13 && 0 < B && B < 13)
{
rabel = "AMBIGUOUS";
}
}
Console.WriteLine(rabel);
}
}*/
// 125B
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] V = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] C = Console.ReadLine().Split().Select(int.Parse).ToArray();
int Answer = 0;
for (int i=0;i<N;i++)
{
var temp = V[i] - C[i];
if (temp > 0)
{
Answer += temp;
}
}
Console.WriteLine(Answer);
}
}*/
// 124B
class Program {
static void Main() {
int Ans = 0;
int count = 0;
int N = int.Parse(Console.ReadLine());
int[] Height = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0; i < Height.Length; i++) {
for (int j = 0; j < i; j++) {
if (Height[i] >= Height[j]) {
Ans++;
}
}
if (Ans == i) {
count++;
}
Ans = 0;
}
Console.WriteLine(count);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 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
| 175
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Great_Ocean_View {
class Program {
static void Main(string[] args) {
int otpt = 1;
int no = Convert.ToInt16(Console.ReadLine());
string[] inp = (Console.ReadLine()).Split(' ');
int[] mountain = new int[no];
int maxheight = mountain[0];
for (int i = 0; i <= no - 1; i++) {
mountain[i] = Convert.ToInt16(inp[i]);
}
for (int j = 1; j <= no - 1; j++) {
if (mountain[j] >= maxheight) {
maxheight = mountain[j];
otpt++;
}
}
Console.WriteLine(otpt);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Great_Ocean_View {
class Program {
static void Main(string[] args) {
int otpt = 1;
int no = Convert.ToInt16(Console.ReadLine());
string[] inp = (Console.ReadLine()).Split(' ');
int[] mountain = new int[no];
for (int i = 0; i <= no - 1; i++) {
mountain[i] = Convert.ToInt16(inp[i]);
}
int maxheight = mountain[0];
for (int j = 1; j <= no - 1; j++) {
if (mountain[j] >= maxheight) {
maxheight = mountain[j];
otpt++;
}
}
Console.WriteLine(otpt);
Console.ReadKey();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
| 8
| 189
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]B - Great Ocean View
int n = int.Parse(Console.ReadLine());
var h = ReadLine();
int views = 1;
for (int i = 1; i < n; i++) {
if (h[i] > h[i - 1] && h[i] >= h[0]) {
views++;
}
}
Console.WriteLine(views);
}
static List<int> ReadLine() {
var line = Console.ReadLine();
var array = line.Split(' ');
return array.Select(x => int.Parse(x)).ToList();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]B - Great Ocean View
int n = int.Parse(Console.ReadLine());
var h = ReadLine();
int views = 1;
for (int i = 1; i < n; i++) {
int max = h.Take(i).Max();
if (h[i] >= max) {
views++;
}
}
Console.WriteLine(views);
}
static List<int> ReadLine() {
var line = Console.ReadLine();
var array = line.Split(' ');
return array.Select(x => int.Parse(x)).ToList();
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 163
| 31
|
using System;
using System.Linq;
namespace ABC124 {
class Program {
static void Main(string[] args) {
string mountains = Console.ReadLine();
string[] height = Console.ReadLine().Split(' ');
int intMountains = int.Parse(mountains);
int[] intHeigt = height.Select(int.Parse).ToArray();
if (intHeigt[0] == intHeigt.Max()) {
Console.WriteLine(1);
return;
}
int minHeight = intHeigt[0];
int count = 0;
foreach (int h in intHeigt) {
if (h >= minHeight) {
minHeight = h;
count++;
}
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Linq;
namespace ABC124 {
class Program {
static void Main(string[] args) {
string mountains = Console.ReadLine();
string[] height = Console.ReadLine().Split(' ');
int intMountains = int.Parse(mountains);
int[] intHeigt = height.Select(int.Parse).ToArray();
/*
if (intHeigt[0] == intHeigt.Max()){
Console.WriteLine(1);
return;
}
*/
int minHeight = intHeigt[0];
int count = 0;
foreach (int h in intHeigt) {
if (h >= minHeight) {
minHeight = h;
count++;
}
}
Console.WriteLine(count);
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 150
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
var imp = Console.ReadLine().Split(' ');
int[] ary = new int[N];
int H = 0;
int count = 1;
for (int i = 0; i < N; i++) {
ary[i] = int.Parse(imp[i]);
}
for (int j = 1; j < N; j++) // j個の旅館
{
int[] newone = new int[j];
Array.Copy(ary, 0, newone, 0, j);
H = newone.Max();
Console.WriteLine(H);
if (H <= ary[j]) {
count += 1;
}
}
Console.WriteLine(count);
// System.Threading.Thread.Sleep(3000);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
var imp = Console.ReadLine().Split(' ');
int[] ary = new int[N];
int H = 0;
int count = 1;
for (int i = 0; i < N; i++) {
ary[i] = int.Parse(imp[i]);
}
for (int j = 1; j < N; j++) // j個の旅館
{
int[] newone = new int[j];
Array.Copy(ary, 0, newone, 0, j);
H = newone.Max();
// Console.WriteLine(H);
if (H <= ary[j]) {
count += 1;
}
}
Console.WriteLine(count);
// System.Threading.Thread.Sleep(3000);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 209
| 7
|
using System;
public class Program {
public static void Main() {
int a;
a = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
int[] i = new int[str.Length];
for (int x = 0; x < str.Length; x++) {
i[x] = int.Parse(str[x]);
}
int max = i[0];
int count = 1;
for (int y = 1; y < str.Length; y++) {
if (i[y] >= max)
count++;
}
Console.WriteLine(count);
}
}
|
using System;
public class Program {
public static void Main() {
int a;
a = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
int[] i = new int[str.Length];
for (int x = 0; x < str.Length; x++) {
i[x] = int.Parse(str[x]);
}
int max = i[0];
int count = 1;
for (int y = 1; y < str.Length; y++) {
if (i[y] >= max) {
count++;
max = i[y];
}
}
Console.WriteLine(count);
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 146
| 9
|
using System;
namespace CSsample {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string input = Console.ReadLine();
var H = input.Split();
int num = 1;
bool flag = false;
for (int i = 1; i < N; i++) {
for (int j = 0; j < i; j++) {
if (int.Parse(H[i]) < int.Parse(H[j])) {
flag = true;
}
}
if (flag == false) {
num++;
}
flag = false;
}
}
}
}
|
using System;
namespace CSsample {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string input = Console.ReadLine();
var H = input.Split();
int num = 1;
bool flag = false;
for (int i = 1; i < N; i++) {
for (int j = 0; j < i; j++) {
if (int.Parse(H[i]) < int.Parse(H[j])) {
flag = true;
}
}
if (flag == false) {
num++;
}
flag = false;
}
Console.WriteLine(num);
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 139
| 7
|
using System;
using System.Collections.Generic;
namespace cs {
public class Program {
public static void Main(string[] args) {
var input = Console.ReadLine().ToCharArray();
var count_BlackStart = 0;
var count_WhiteStart = 0;
var bs_nextColor = '1';
var ws_nextColor = '0';
char t;
for (int i = 1; i < input.Length; i++) {
if (input[i] != bs_nextColor) {
count_BlackStart++;
}
if (input[i] != ws_nextColor) {
count_WhiteStart++;
}
t = bs_nextColor;
bs_nextColor = ws_nextColor;
ws_nextColor = t;
}
Console.WriteLine((count_BlackStart > count_WhiteStart) ? count_WhiteStart
: count_BlackStart);
}
}
}
|
using System;
using System.Collections.Generic;
namespace cs {
public class Program {
public static void Main(string[] args) {
var input = Console.ReadLine().ToCharArray();
var count_BlackStart = (input[0] == '0' ? 0 : 1);
var count_WhiteStart = (input[0] == '1' ? 0 : 1);
var bs_nextColor = '1';
var ws_nextColor = '0';
char t;
for (int i = 1; i < input.Length; i++) {
if (input[i] != bs_nextColor) {
count_BlackStart++;
}
if (input[i] != ws_nextColor) {
count_WhiteStart++;
}
t = bs_nextColor;
bs_nextColor = ws_nextColor;
ws_nextColor = t;
}
Console.WriteLine((count_BlackStart > count_WhiteStart) ? count_WhiteStart
: count_BlackStart);
}
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["+", 0, 23, 0, 41, 15, 16, 31, 204, 205, 22], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 212, 0, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 23, 0, 41, 15, 16, 12, 252, 0, 104], ["+", 0, 23, 0, 41, 15, 16, 12, 252, 0, 253], ["+", 0, 200, 0, 212, 0, 23, 0, 41, 0, 101], ["+", 0, 200, 0, 212, 0, 23, 0, 41, 64, 203], ["+", 0, 200, 0, 212, 0, 23, 0, 41, 0, 102], ["+", 0, 200, 0, 212, 0, 23, 0, 41, 75, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 23, 0, 25], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 144
| 26
|
using System;
// using System.Collections.Generic;
using System.Linq;
// using System.Text;
// using System.Threading;
// using System.Threading.Tasks;
// using System.Timers;
namespace Test {
class Program {
static void Main(string[] args) {
var res = 0;
var nums = new[] { 0, 1 };
var S = Console.ReadLine().ToCharArray();
for (int i = 0; i < S.Length; i++) {
if (nums[((S[0] == '0' ? 0 : 1) + i % 2) % 2] == S[i]) {
res++;
}
}
Console.WriteLine(res);
}
}
}
|
using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;
// using System.Threading;
// using System.Threading.Tasks;
// using System.Timers;
namespace Test {
class Program {
static void Main(string[] args) {
var res = 0;
var nums = new[] { '0', '1' };
var S = Console.ReadLine().ToCharArray();
for (int i = 0; i < S.Length; i++) {
if (nums[((S[0] == '0' ? 0 : 1) + i % 2) % 2] != S[i]) {
res++;
}
}
Console.WriteLine(res);
}
}
}
|
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 0, 212, 0, 297, 0, 229, 0, 252, 0, 104], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79]]
| 8
| 125
| 11
|
using static System.Math;
using System;
public class Hello {
public static void Main() {
var s = Console.ReadLine().Trim();
var a = s.ToCharArray();
var ans2 = getAns1(a);
var ans1 = getAns0(a);
var ans = Min(ans1, ans2);
Console.WriteLine(ans);
}
static int getAns1(char[] a) {
var count = 0;
var aL = a.Length;
var p = 0;
while (true) {
if (a[p] == '0')
count++;
p++;
if (p == aL)
break;
if (a[p] == '1')
count++;
p++;
if (p == aL)
break;
}
return count;
}
static int getAns0(char[] a) {
var count = 0;
var aL = a.Length;
var p = 0;
while (true) {
if (a[p] == '1')
count++;
p++;
if (p == aL)
break;
if (a[p] == '0')
count++;
if (p == aL)
break;
}
return count;
}
}
|
using static System.Math;
using System;
public class Hello {
public static void Main() {
var s = Console.ReadLine().Trim();
var a = s.ToCharArray();
var ans1 = getAns0(a);
var ans2 = getAns1(a);
var ans = Min(ans1, ans2);
Console.WriteLine(ans);
}
static int getAns1(char[] a) {
var count = 0;
var aL = a.Length;
var p = 0;
while (true) {
if (a[p] == '0')
count++;
p++;
if (p == aL)
break;
if (a[p] == '1')
count++;
p++;
if (p == aL)
break;
}
return count;
}
static int getAns0(char[] a) {
var count = 0;
var aL = a.Length;
var p = 0;
while (true) {
if (a[p] == '1')
count++;
p++;
if (p == aL)
break;
if (a[p] == '0')
count++;
p++;
if (p == aL)
break;
}
return count;
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 52, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22]]
| 8
| 248
| 11
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadLine;
var counter = N.Count();
var charArray = N.ToCharArray();
var charArray2 = N.ToCharArray();
long result1 = 0;
long result2 = 0;
if (charArray2[0] == '0') {
charArray2[0] = '1';
} else {
charArray2[0] = '0';
}
for (int i = 0; i < counter - 1; i++) {
if (charArray[i] == charArray[i + 1]) {
if (charArray[i + 1] == '0') {
charArray[i + 1] = '1';
} else {
charArray[i + 1] = '0';
}
result1++;
}
if (charArray2[i] == charArray2[i + 1]) {
if (charArray2[i + 1] == '0') {
charArray2[i + 1] = '1';
} else {
charArray2[i + 1] = '0';
}
result2++;
}
}
if (result1 > result2) {
Console.Write(result2.ToString());
} else {
Console.Write(result1.ToString());
}
}
}
public class deci {
public bool IsFinish { get; set; } = false;
public int Len { get; set; }
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadLine;
var charArray = N.ToCharArray();
var charArray2 = N.ToCharArray();
long counter = charArray.Count();
long result1 = 0;
long result2 = 0;
if (charArray2[0] == '0') {
charArray2[0] = '1';
++result2;
} else {
charArray2[0] = '0';
++result2;
}
for (int i = 0; i < counter - 1; i++) {
if (charArray[i] == charArray[i + 1]) {
if (charArray[i + 1] == '0') {
charArray[i + 1] = '1';
} else {
charArray[i + 1] = '0';
}
++result1;
}
if (charArray2[i] == charArray2[i + 1]) {
if (charArray2[i + 1] == '0') {
charArray2[i + 1] = '1';
} else {
charArray2[i + 1] = '0';
}
++result2;
}
}
if (result1 > result2) {
Console.Write(result2.ToString());
} else {
Console.Write(result1.ToString());
}
}
}
public class deci {
public bool IsFinish { get; set; } = false;
public int Len { get; set; }
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 241, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 241, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 241, 0, 29], ["+", 0, 57, 75, 196, 0, 1, 0, 241, 0, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22]]
| 8
| 697
| 24
|
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();
string tmp = Console.ReadLine();
var s = new List<int>();
// var sampleA = new List<int>();//010101
// var sampleB = new List<int>();//101010
for (var i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i].ToString()));
}
int a = 0; // 101010
int b = 0; // 010101
for (int i = 0; i < s.Count; i++) {
int judge = i % 2;
if (s[i] == judge) {
a += 1;
} else {
b += 1;
}
Console.WriteLine(i);
}
if (a > b) {
wr.wri(b);
} 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); }
}
}
|
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();
string tmp = Console.ReadLine();
var s = new List<int>();
for (var i = 0; i < tmp.Length; i++) {
s.Add(int.Parse(tmp[i].ToString()));
}
int a = 0; // 101010
int b = 0; // 010101
for (int i = 0; i < s.Count; i++) {
int judge = i % 2;
if (s[i] == judge) {
a += 1;
} else {
b += 1;
}
}
if (a > b) {
wr.wri(b);
} 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); }
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 313
| 7
|
using System;
namespace AtCoder.ABC._124 {
class c {
static void Main(string[] args) {
var line = Console.ReadLine().Trim();
var len = line.Length;
var cntOdd = 0;
var cntEve = 0;
for (var i = 0; i < len; ++i) {
if (i % 2 == 0) {
if (line[i] == '1') {
++cntEve;
}
} else {
if (line[i] == '1') {
++cntOdd;
}
}
}
Console.WriteLine(Math.Min(Math.Round(len / 2.0d) - cntOdd + cntEve,
cntOdd + len / 2 - cntEve));
}
}
}
|
using System;
namespace AtCoder.ABC._124 {
class c {
static void Main(string[] args) {
var line = Console.ReadLine().Trim();
var len = line.Length;
var cntOdd = 0;
var cntEve = 0;
for (var i = 0; i < len; ++i) {
if (i % 2 == 0) {
if (line[i] == '1') {
++cntEve;
}
} else {
if (line[i] == '1') {
++cntOdd;
}
}
}
Console.WriteLine(Math.Min(Math.Ceiling(len / 2.0d) - cntEve + cntOdd,
cntEve + (len / 2 - cntOdd)));
}
}
}
|
[["-", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 148
| 12
|
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;
public class Program {
public static void Main() {
var s = Console.ReadLine().Trim();
var k = 0;
var l = -1;
for (int i = 1; i < s.Length; i++) {
if (s[i] != s[i - 1]) {
continue;
}
if (l < 0) {
l = i;
continue;
}
k += Math.Max(i - l, 1);
l = -1;
}
Console.WriteLine(k);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;
public class Program {
public static void Main() {
var s = Console.ReadLine().Trim();
var k = 0;
var l = -1;
for (int i = 1; i < s.Length; i++) {
if (s[i] != s[i - 1]) {
continue;
}
if (l < 0) {
l = i;
continue;
}
k += Math.Max(i - l, 1);
l = -1;
}
if (l > 0) {
k += s.Length - l;
}
Console.WriteLine(k);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 16, 31, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 16, 31, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 136
| 16
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
var r = ReadSplit();
var n = r[0].Int();
var k = r[1].Int();
var s = Read();
var l = new List<int>();
var pre = '2';
var start = s[0].Int();
var count = 0;
for (int i = 0; i < n; i++) {
if (pre == s[i]) {
count++;
} else {
if (count != 0)
l.Add(count);
count = 1;
pre = s[i];
}
if (i == n - 1) {
l.Add(count);
}
}
var ls = new int[l.Count + 1];
for (int i = 0; i < l.Count; i++) {
ls[i + 1] = ls[i] + l[i];
}
var ans = 0L;
var startR = false;
if (s[0] == '1')
startR = true;
for (int i = 0; i < ls.Length; i++) {
if (i - 1 < 0)
continue;
var sub = 0;
if (i % 2 == 0 && startR || i % 2 == 1 && !startR)
sub = k * 2 - 1;
else
sub = k * 2;
if (i + sub > ls.Length - 1)
break;
ans = Math.Max(ls[i + sub] - ls[i - 1], ans);
}
if (ans == 0) {
ans = ls.Max();
}
WriteRead(ans);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
var r = ReadSplit();
var n = r[0].Int();
var k = r[1].Int();
var s = Read();
var l = new List<int>();
var pre = '2';
var start = s[0].Int();
var count = 0;
for (int i = 0; i < n; i++) {
if (pre == s[i]) {
count++;
} else {
if (count != 0)
l.Add(count);
count = 1;
pre = s[i];
}
if (i == n - 1) {
l.Add(count);
}
}
var ls = new int[l.Count + 1];
for (int i = 0; i < l.Count; i++) {
ls[i + 1] = ls[i] + l[i];
}
var ans = 0L;
var startR = false;
if (s[0] == '1')
startR = true;
for (int i = 0; i < ls.Length; i++) {
if (i - 1 < 0)
continue;
var sub = 0;
if (i % 2 == 0 && startR || i % 2 == 1 && !startR)
sub = k * 2 - 1;
else
sub = k * 2;
if (i + sub > ls.Length - 1) {
ans = Math.Max(ls[ls.Length - 1] - ls[i - 1], ans);
} else {
ans = Math.Max(ls[i + sub] - ls[i - 1], ans);
}
}
if (ans == 0) {
ans = ls.Max();
}
WriteRead(ans);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 721
| 30
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var o = Ints;
var N = o[0];
var K = o[1];
var S = Str;
var lis = new List<int>();
int cnt = 0;
int curstate = 1;
for (int i = 0; i < N; ++i) {
if (S[i] - '0' == curstate)
++cnt;
else {
lis.Add(cnt);
curstate ^= 1;
cnt = 1;
}
}
lis.Add(cnt);
if (lis.Count % 2 == 0)
lis.Add(0);
int range = 2 * K + 1;
int ans = 0;
int left = 0;
int right = 0;
int cur = 0;
for (int i = 0; i < N; i += 2) {
int nextl = i;
int nextr = Min(lis.Count(), nextl + range);
while (nextl > left) {
cur -= lis[left];
++left;
}
while (nextr > right) {
curstate += lis[right];
++right;
}
ans = Max(ans, cur);
}
Write(ans);
}
}
public static class Graph {
public static long[] dijkstra(List<Tuple<long, int>>[] edge, int from,
long INF = Math2.INFL) {
long[] ret = Enumerable.Range(0, edge.Length).Select(_ => INF).ToArray();
var pq =
new PriorityQueue<Tuple<long, int>>((a, b) => (int)(a.Item1 - b.Item1));
ret[from] = 0;
pq.Enqueue(new Tuple<long, int>(0, from));
while (pq.Count > 0) {
var p = pq.Dequeue();
var v = p.Item2;
if (ret[v] < p.Item1)
continue;
foreach (var e in edge[v]) {
if (ret[e.Item2] > ret[v] + e.Item1) {
ret[e.Item2] = ret[v] + e.Item1;
pq.Enqueue(new Tuple<long, int>(ret[e.Item2], e.Item2));
}
}
}
return ret;
}
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = n; i >= n - r + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
// public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ",
// a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var o = Ints;
var N = o[0];
var K = o[1];
var S = Str;
var lis = new List<int>();
int cnt = 0;
int curstate = 1;
for (int i = 0; i < N; ++i) {
if (S[i] - '0' == curstate)
++cnt;
else {
lis.Add(cnt);
curstate ^= 1;
cnt = 1;
}
}
if (cnt != 0)
lis.Add(cnt);
if (lis.Count() % 2 == 0)
lis.Add(0);
int range = 2 * K + 1;
int ans = 0;
int left = 0;
int right = 0;
int cur = 0;
for (int i = 0; i < lis.Count(); i += 2) {
int nextl = i;
int nextr = Min(lis.Count(), i + range);
while (nextl > left) {
cur -= lis[left];
++left;
}
while (nextr > right) {
cur += lis[right];
++right;
}
ans = Max(ans, cur);
}
Write(ans);
}
}
public static class Graph {
public static long[] dijkstra(List<Tuple<long, int>>[] edge, int from,
long INF = Math2.INFL) {
long[] ret = Enumerable.Range(0, edge.Length).Select(_ => INF).ToArray();
var pq =
new PriorityQueue<Tuple<long, int>>((a, b) => (int)(a.Item1 - b.Item1));
ret[from] = 0;
pq.Enqueue(new Tuple<long, int>(0, from));
while (pq.Count > 0) {
var p = pq.Dequeue();
var v = p.Item2;
if (ret[v] < p.Item1)
continue;
foreach (var e in edge[v]) {
if (ret[e.Item2] > ret[v] + e.Item1) {
ret[e.Item2] = ret[v] + e.Item1;
pq.Enqueue(new Tuple<long, int>(ret[e.Item2], e.Item2));
}
}
}
return ret;
}
}
public class PriorityQueue<T> {
List<T> _item;
public int Count {
get { return _item.Count; }
}
bool _isascend { get; set; }
public T Peek {
get { return _item[0]; }
}
Comparison<T> Comp;
public PriorityQueue(bool IsAscend = true, IEnumerable<T> list = null)
: this(Comparer<T>.Default.Compare, IsAscend, list) {}
public PriorityQueue(Comparison<T> cmp, bool IsAscend = true,
IEnumerable<T> list = null) {
_item = new List<T>();
_isascend = IsAscend;
this.Comp = cmp;
if (list != null) {
_item.AddRange(list);
Build();
}
}
private int Compare(int i, int j) => (_isascend ? -1 : 1) *
Comp(_item[i], _item[j]);
private void Swap(int i, int j) {
var t = _item[i];
_item[i] = _item[j];
_item[j] = t;
}
private int Parent(int i) => (i - 1) >> 1;
private int Left(int i) => (i << 1) + 1;
public T Enqueue(T val) {
int i = _item.Count;
_item.Add(val);
while (i > 0) {
int p = Parent(i);
if (Compare(i, p) > 0)
Swap(i, p);
i = p;
}
return val;
}
private void Heapify(int index) {
for (int i = index, j; (j = Left(i)) < _item.Count; i = j) {
if (j != _item.Count - 1 && Compare(j, j + 1) < 0)
j++;
if (Compare(i, j) < 0)
Swap(i, j);
}
}
public T Dequeue() {
T val = _item[0];
_item[0] = _item[_item.Count - 1];
_item.RemoveAt(_item.Count - 1);
Heapify(0);
return val;
}
private void Build() {
for (var i = (_item.Count >> 1) - 1; i >= 0; i--)
Heapify(i);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = n; i >= n - r + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
// public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ",
// a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22]]
| 8
| 1,820
| 18
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Math;
using static Solve.Methods;
using static Solve.Input;
using static Solve.Output;
using pii = Solve.Pair<int, int>;
using pll = Solve.Pair<long, long>;
using pli = Solve.Pair<long, int>;
using pil = Solve.Pair<int, long>;
using pss = Solve.Pair<string, string>;
using psi = Solve.Pair<string, int>;
using lint = System.Collections.Generic.List<int>;
using llong = System.Collections.Generic.List<long>;
using lstr = System.Collections.Generic.List<string>;
using llint = System.Collections.Generic.List<System.Collections.Generic.List<int>>;
using llstr = System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using lllong = System.Collections.Generic.List<System.Collections.Generic.List<string>>;
using lii = System.Collections.Generic.List<Solve.Pair<int, int>>;
using lll = System.Collections.Generic.List<Solve.Pair<long, long>>;
using lli = System.Collections.Generic.List<Solve.Pair<long, int>>;
using lil = System.Collections.Generic.List<Solve.Pair<int, long>>;
using ll = System.Int64;
namespace Solve
{
public class Solver
{
public void Main()
{
int N, K;
string S;
In(out N, out K,out S);
// 1 である数
var list = new List<int>();
if(S[0] != '1') list.Add(0);
int cnt = 1;
for (int i = 1; i < N; i++)
{
if (S[i] != S[i - 1])
{
list.Add(cnt);
cnt = 1;
}
else ++cnt;
}
list.Add(cnt);
list.Add(0);
var cs = list.CumSum().ToArray();
// [i, i + 2K]
int max = 0;
for (int i = 0; i + 2 * K < list.Count; i += 2)
{
int now = cs[i + 2 * K];
if(i>0)now-=cs[i - 1];
chmax(ref max, now);
}
cout = max;
}
// ReSharper disable UnusedMember.Local
private const int MOD = (int) 1e9 + 7,
INF = 1000000010;
private const long LINF = 1000000000000000100;
}
// ライブラリ置き場ここから
/// <summary>
/// SegmentTree 一点更新区間取得
/// </summary>
/// <typeparam name="T">要素の型</typeparam>
public class SegmentTree<T>
{
private readonly int _size;
private readonly T[] _seg;
private readonly Func<T, T, T> _func;
private readonly T _identity;
public SegmentTree(int N, Func<T, T, T> func, T identity)
{
_func = func;
_identity = identity;
_size = 1 << (int) Ceiling(Log(N, 2));
_seg = Enumerable.Repeat(_identity, _size * 2).ToArray();
}
public void Set(int i, T value)
{
if (i < 0 || i >= _size) throw new ArgumentOutOfRangeException(nameof(i));
_seg[_size + i] = value;
}
public void Build()
{
for (int i = _size - 1; i > 0; i--)
_seg[i] = _func(_seg[2 * i], _seg[2 * i + 1]);
}
public void Update(int i, T value)
{
i += _size;
_seg[i] = value;
while ((i >>= 1) > 0)
_seg[i] = _func(_seg[2 * i], _seg[2 * i + 1]);
}
public T Query(int l, int r)
{
T L = _identity, R = _identity;
for (l += _size, r += _size; l < r; l >>= 1, r >>= 1)
{
if ((l & 1) > 0) L = _func(L, _seg[l++]);
if ((r & 1) > 0) R = _func(_seg[--r], R);
}
return _func(L, R);
}
public T this[int i] => _seg[i + _size];
}
// ライブラリ置き場ここまで
#region Templete
#if !LOCAL
namespace Library { }
#endif
public static class Methods
{
public static readonly int[] dx = {-1, 0, 0, 1};
public static readonly int[] dy = {0, 1, -1, 0};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Assert(bool b, string message = null)
{
if (!b) throw new Exception(message ?? "Assert failed.");
}
/*
public static Comparison<T> greater<T>()
where T : IComparable<T>
=> (a, b) => b.CompareTo(a);
*/
public static string JoinSpace<T>(this IEnumerable<T> source) => source.Join(" ");
public static string JoinEndline<T>(this IEnumerable<T> source) => source.Join("\n");
public static string Join<T>(this IEnumerable<T> source, string s) => string.Join(s, source);
public static string Join<T>(this IEnumerable<T> source, char c) => string.Join(c.ToString(), source);
/// <summary>
/// <see cref="Pair{T1, T2}"/> クラスのインスタンスを作成します。
/// </summary>
/// <typeparam name="T1">firstの型</typeparam>
/// <typeparam name="T2">secondの型</typeparam>
/// <param name="first">firstの値</param>
/// <param name="second">secondの値</param>
/// <returns>作成した<see cref="Pair{T1, T2}"/> クラスのインスタンス</returns>
public static Pair<T1, T2> make_pair<T1, T2>(T1 first, T2 second)
where T1 : IComparable<T1>
where T2 : IComparable<T2>
=> new Pair<T1, T2>(first, second);
/// <summary>aとbをスワップします。</summary>
public static void Swap<T>(ref T a, ref T b) where T : struct
{
var tmp = b;
b = a;
a = tmp;
}
/// <summary>aとbの最大公約数を求めます。</summary>
/// <returns>aとbの最大公約数</returns>
public static long Gcd(long a, long b)
{
while (true)
{
if (a < b) Swap(ref a, ref b);
if (a % b == 0) return b;
var x = a;
a = b;
b = x % b;
}
}
/// <summary>aとbの最小公倍数を求めます。</summary>
/// <returns>aとbの最小公倍数</returns>
public static long Lcm(long a, long b) => a / Gcd(a, b) * b;
/// <summary>
/// 指定した数値が素数であるかを判定します。
/// </summary>
/// <remarks>計算量 (sqrt(value)) </remarks>
/// <param name="value">判定する数値</param>
/// <returns>value が素数であるか</returns>
public static bool IsPrime(long value)
{
if (value <= 1) return false;
for (long i = 2; i * i <= value; i++)
if (value % i == 0)
return false;
return true;
}
/// <summary>
/// <see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) を求める
/// </summary>
/// <returns><see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) の値</returns>
public static long PowMod(long a, long b, long p)
{
long res = 1;
while (b > 0)
{
if (b % 2 != 0) res = res * a % p;
a = a * a % p;
b >>= 1;
}
return res;
}
/// <summary>
/// mod pにおけるaの逆元を求めます。
/// </summary>
/// <param name="a"></param>
/// <param name="p">法</param>
/// <returns></returns>
public static long ModInv(long a, long p)
=> PowMod(a, p - 2, p);
public static int DivCeil(int left, int right)
=> left / right + (left % right == 0 ? 0 : 1);
public static long DivCeil(long left, long right)
=> left / right + (left % right == 0L ? 0L : 1L);
/// <summary>
/// src の順列を求めます。
/// </summary>
/// <typeparam name="T">型</typeparam>
/// <param name="src">順列を求める配列</param>
/// <returns>src の順列</returns>
public static IEnumerable<T[]> Permutations<T>(IEnumerable<T> src)
{
var ret = new List<T[]>();
Search(ret, new Stack<T>(), src.ToArray());
return ret;
}
private static void Search<T>(ICollection<T[]> perms, Stack<T> stack, T[] a)
{
int N = a.Length;
if (N == 0) perms.Add(stack.Reverse().ToArray());
else
{
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i)
{
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) b[i] = a[i];
stack.Pop();
}
}
}
/// <summary>
/// 指定した条件を満たす最小の数値を返します。
/// </summary>
/// <param name="low">検索する数値の最小値</param>
/// <param name="high">検索する数値の最大値</param>
/// <param name="expression">条件</param>
/// <returns>条件を満たす最小の数値</returns>
public static long BinarySearch(long low, long high, Func<long, bool> expression)
{
while (low < high)
{
long middle = (high - low) / 2 + low;
if (!expression(middle))
high = middle;
else
low = middle + 1;
}
return high;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返します。
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
{
int low = start;
int high = end;
while (low < high)
{
var mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返します。
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="value">検索する値</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(T[] arr, T value) where T : IComparable
{
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返します。
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
{
int low = start;
int high = end;
while (low < high)
{
var mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返します。
/// </summary>Z
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="value">検索する値</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(T[] arr, T value)
{
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static IEnumerable<TResult> SelectNotNull<TSource, TResult>(this IEnumerable<TSource> source,
Func<TSource, TResult> func)
=> source.Where(val => val != null).Select(func);
public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource> source)
=> source.Where(val => val != null);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] ArrayOf<T>(params T[] arr) => arr;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<T> ListOf<T>(params T[] arr) => new List<T>(arr);
public static IEnumerable<TResult> Repeat<TResult>(TResult value)
{
while (true) yield return value;
// ReSharper disable once IteratorNeverReturns
}
public static IEnumerable<TResult> Repeat<TResult>(TResult value, int count)
=> Enumerable.Repeat(value, count);
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source, int count)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
for (int i = 0; i < count; i++)
foreach (var v in source)
yield return v;
}
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source)
{
if (source == null) throw new ArgumentNullException(nameof(source));
while (true)
foreach (var v in source)
yield return v;
}
/// <summary>
/// 文字の配列を文字列に変換します。
/// </summary>
/// <param name="source">文字の配列</param>
/// <returns>変換した文字列</returns>
public static string AsString(this IEnumerable<char> source) => new string(source.ToArray());
/// <summary>
/// <see cref="source"/> の累積和を返します。
/// </summary>
/// <returns><see cref="source"/> の累積和</returns>
public static IEnumerable<long> CumSum(this IEnumerable<long> source)
{
long sum = 0;
foreach (var item in source)
yield return sum += item;
}
/// <summary>
/// <see cref="source"/> の累積和を返します。
/// </summary>
/// <returns><see cref="source"/> の累積和</returns>
public static IEnumerable<int> CumSum(this IEnumerable<int> source)
{
int sum = 0;
foreach (var item in source)
yield return sum += item;
}
/// <summary>
/// <see cref="value"/>が l以上 r未満の範囲に含まれているかを返します。
/// </summary>
/// <typeparam name="T">要素の型</typeparam>
/// <param name="value">判定する値</param>
/// <param name="l">下限の値 (含まれる)</param>
/// <param name="r">上限の値 (含まれない)</param>
/// <returns><see cref="value"/> が指定した範囲に含まれているか</returns>
public static bool IsIn<T>(this T value, T l, T r)
where T : IComparable<T>
{
if (l.CompareTo(r) > 0) throw new ArgumentException();
return l.CompareTo(value) <= 0 && value.CompareTo(r) < 0;
}
/// <summary>
/// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を列挙します。
/// </summary>
/// <param name="start">値の下限 (含まれる)</param>
/// <param name="end">値の上限 (含まれない)</param>
/// <param name="step">1要素ごとに増やす値</param>
/// <returns>範囲の結果</returns>
public static IEnumerable<int> Range(int start, int end, int step = 1)
{
for (var i = start; i < end; i += step) yield return i;
}
/// <summary>
/// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を列挙します。
/// </summary>
/// <param name="end">値の上限 (含まれない)</param>
/// <returns>範囲の結果</returns>
public static IEnumerable<int> Range(int end) => Range(0, end);
/// <summary>
/// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を逆順に列挙します。
/// </summary>
/// <param name="start">値の下限 (含まれる)</param>
/// <param name="end">値の上限 (含まれない)</param>
/// <param name="step">1要素ごとに増やす値</param>
/// <returns>範囲の結果</returns>
public static IEnumerable<int> RangeReverse(int start, int end, int step = 1)
{
for (var i = end - 1; i >= start; i -= step) yield return i;
}
/// <summary>
/// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を逆順に列挙します。
/// </summary>
/// <param name="end">値の上限 (含まれない)</param>
/// <returns>範囲の結果</returns>
public static IEnumerable<int> RangeReverse(int end) => RangeReverse(0, end);
/// <summary>
/// 指定した配列をコピーして昇順ソートします。(非破壊的)
/// </summary>
/// <typeparam name="T">ソートする配列の型</typeparam>
/// <param name="arr">ソートする配列</param>
/// <returns>ソートされた配列</returns>
public static T[] Sort<T>(this T[] arr)
{
var array = new T[arr.Length];
arr.CopyTo(array, 0);
Array.Sort(array);
return array;
}
/// <summary>
/// 指定した配列をコピーして降順ソートします。(非破壊的)
/// </summary>
/// <typeparam name="T">ソートする配列の型</typeparam>
/// <param name="arr">ソートする配列</param>
/// <returns>ソートされた配列</returns>
public static T[] SortDescending<T>(this T[] arr)
{
var array = new T[arr.Length];
arr.CopyTo(array, 0);
Array.Sort(array);
Array.Reverse(array);
return array;
}
public static double Log2(double x) => Log(x, 2);
public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
{
if (a.CompareTo(b) > 0)
{
a = b;
return true;
}
return false;
}
public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
{
if (a.CompareTo(b) < 0)
{
a = b;
return true;
}
return false;
}
public static T Min<T>(params T[] col) => col.Min();
public static T Max<T>(params T[] col) => col.Max();
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされたジャグ配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[][] JaggedArray2D<T>(int a, int b, T defaultValue = default(T))
{
var ret = new T[a][];
for (int i = 0; i < a; i++)
{
ret[i] = Enumerable.Repeat(defaultValue, b).ToArray();
}
return ret;
}
/// <summary>
/// 要素数 (a, b) の,defaultValue で満たされた二次元配列を作成します。
/// </summary>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <typeparam name="T">配列の型</typeparam>
public static T[,] Array2D<T>(int a, int b, T defaultValue = default(T))
{
var ret = new T[a, b];
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
ret[i, j] = defaultValue;
return ret;
}
/// <summary>
/// ジャグ配列を2次元配列に変換します。配列の各要素の長さがすべて同じである必要があります。
/// </summary>
/// <param name="array">ジャグ配列</param>
/// <typeparam name="T">二次元配列</typeparam>
public static T[,] To2DArray<T>(this T[][] array)
{
if (!array.Any()) return new T[0, 0];
int len = array[0].Length;
if (array.Any(x => x.Length != len))
throw new ArgumentException("array の各要素の長さが異なります。", nameof(array));
var ret = new T[array.Length, len];
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < len; j++)
{
ret[i, j] = array[i][j];
}
}
return ret;
}
// public static vector<T> ToVector<T>(this IEnumerable<T> source) => new vector<T>(source);
}
public static class Input
{
private const char _separator = ' ';
private static readonly Queue<string> _input = new Queue<string>();
private static readonly StreamReader sr =
#if FILE
new StreamReader("in.txt");
#else
new StreamReader(Console.OpenStandardInput());
#endif
public static string ReadLine => sr.ReadLine();
public static string ReadStr => Read;
public static string Read
{
get
{
if (_input.Count != 0) return _input.Dequeue();
// ReSharper disable once PossibleNullReferenceException
var tmp = sr.ReadLine().Split(_separator);
foreach (var val in tmp)
{
_input.Enqueue(val);
}
return _input.Dequeue();
}
}
public static int ReadInt => int.Parse(Read);
public static long ReadLong => long.Parse(Read);
public static double ReadDouble => double.Parse(Read);
public static string[] StrArray() => ReadLine.Split(' ');
public static int[] IntArray() => ReadLine.Split(' ').Select(int.Parse).ToArray();
public static long[] LongArray() => ReadLine.Split(' ').Select(long.Parse).ToArray();
public static string[] StrArray(int n)
{
var ret = new string[n];
for (long i = 0; i < n; ++i) ret[i] = Read;
return ret;
}
public static int[] IntArray(int n, int offset = 0, bool sorted = false)
{
var ret = StrArray(n).Select(x => int.Parse(x) + offset).ToArray();
if (sorted) Array.Sort(ret);
return ret;
}
public static long[] LongArray(int n, long offset = 0, bool sorted = false)
{
var ret = StrArray(n).Select(x => long.Parse(x) + offset).ToArray();
if (sorted) Array.Sort(ret);
return ret;
}
public static string[,] Str2DArray(int n, int m)
{
var ret = new string[n, m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ret[i, j] = ReadStr;
return ret;
}
public static int[,] Int2DArray(int n, int m, int offset = 0)
{
var ret = new int[n, m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ret[i, j] = ReadInt + offset;
return ret;
}
public static long[,] Long2DArray(int n, int m, long offset = 0)
{
var ret = new long[n, m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ret[i, j] = ReadLong + offset;
return ret;
}
public static Tuple<string[], string[]> StrArrays2(int n)
{
var ret1 = new string[n];
var ret2 = new string[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadStr;
ret2[i] = ReadStr;
}
return Tuple.Create(ret1, ret2);
}
public static Tuple<int[], int[]> IntArrays2(int n, int offset1 = 0, int offset2 = 0)
{
var ret1 = new int[n];
var ret2 = new int[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadInt + offset1;
ret2[i] = ReadInt + offset2;
}
return Tuple.Create(ret1, ret2);
}
public static Tuple<long[], long[]> LongArrays2(int n, long offset1 = 0, long offset2 = 0)
{
var ret1 = new long[n];
var ret2 = new long[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadLong + offset1;
ret2[i] = ReadLong + offset2;
}
return Tuple.Create(ret1, ret2);
}
public static Tuple<string[], string[], string[]> StrArrays3(int n)
{
var ret1 = new string[n];
var ret2 = new string[n];
var ret3 = new string[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadStr;
ret2[i] = ReadStr;
}
return Tuple.Create(ret1, ret2, ret3);
}
public static Tuple<int[], int[], int[]> IntArrays3(int n, int offset1 = 0, int offset2 = 0, int offset3 = 0)
{
var ret1 = new int[n];
var ret2 = new int[n];
var ret3 = new int[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadInt + offset1;
ret2[i] = ReadInt + offset2;
ret3[i] = ReadInt + offset3;
}
return Tuple.Create(ret1, ret2, ret3);
}
public static Tuple<long[], long[], long[]> LongArrays3(int n, long offset1 = 0, long offset2 = 0,
long offset3 = 0)
{
var ret1 = new long[n];
var ret2 = new long[n];
var ret3 = new long[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadLong + offset1;
ret2[i] = ReadLong + offset2;
ret3[i] = ReadLong + offset3;
}
return Tuple.Create(ret1, ret2, ret3);
}
private static bool TypeEquals<T, U>() => typeof(T) == typeof(U);
private static T ChangeType<T, U>(U a) => (T) System.Convert.ChangeType(a, typeof(T));
private static T Convert<T>(string s) => TypeEquals<T, int>() ? ChangeType<T, int>(int.Parse(s))
: TypeEquals<T, long>() ? ChangeType<T, long>(long.Parse(s))
: TypeEquals<T, double>() ? ChangeType<T, double>(double.Parse(s))
: TypeEquals<T, char>() ? ChangeType<T, char>(s[0])
: ChangeType<T, string>(s);
public static bool In<T>(out T a)
{
try
{
a = Convert<T>(Read);
return true;
}
catch
{
a = default(T);
return false;
}
}
public static bool In<T, U>(out T a, out U b)
{
try
{
var ar = StrArray(2);
a = Convert<T>(ar[0]);
b = Convert<U>(ar[1]);
return true;
}
catch
{
a = default(T);
b = default(U);
return false;
}
}
public static bool In<T, U, V>(out T a, out U b, out V c)
{
try
{
var ar = StrArray(3);
a = Convert<T>(ar[0]);
b = Convert<U>(ar[1]);
c = Convert<V>(ar[2]);
return true;
}
catch
{
a = default(T);
b = default(U);
c = default(V);
return false;
}
}
public static bool In<T, U, V, W>(out T a, out U b, out V c, out W d)
{
try
{
var ar = StrArray(4);
a = Convert<T>(ar[0]);
b = Convert<U>(ar[1]);
c = Convert<V>(ar[2]);
d = Convert<W>(ar[3]);
return true;
}
catch
{
a = default(T);
b = default(U);
c = default(V);
d = default(W);
return false;
}
}
public static bool In<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
{
try
{
var ar = StrArray(5);
a = Convert<T>(ar[0]);
b = Convert<U>(ar[1]);
c = Convert<V>(ar[2]);
d = Convert<W>(ar[3]);
e = Convert<X>(ar[4]);
return true;
}
catch
{
a = default(T);
b = default(U);
c = default(V);
d = default(W);
e = default(X);
return false;
}
}
}
public static class Output
{
public static void print<T>(T t) => Console.WriteLine(t);
public static void print(params object[] o) => Console.WriteLine(o.Join(" "));
public static void PrintBool(bool val, string yes = "Yes", string no = "No")
=> Console.WriteLine(val ? yes : no);
public static void PrintYn(bool val) => PrintBool(val);
public static void PrintYN(bool val) => PrintBool(val, "YES", "NO");
public static void PrintPossible(bool val) => PrintBool(val, "Possible", "Impossible");
public static void PrintYay(bool val) => PrintBool(val, "Yay!", ":(");
public static void PrintDebug(params object[] args)
=> Console.Error.WriteLine(string.Join(" ", args));
/// <summary>
/// setter で設定された値を標準出力に出力します。
/// </summary>
public static object cout { set { Console.WriteLine(value); } }
/// <summary>
/// Local環境のみ,setter で設定された値を標準出力に出力します。
/// </summary>
public static object dout
{
set
{
#if LOCAL
Console.WriteLine(value);
#endif
}
}
/// <summary>
/// setter で設定された値を標準エラー出力に出力します。
/// </summary>
public static object cerr { set { Console.Error.WriteLine(value); } }
public const string endl = "\n";
}
public class Program
{
public static void Main(string[] args)
{
var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
Console.SetOut(sw);
new Solver().Main();
Console.Out.Flush();
}
}
[DebuggerDisplay("({first}, {second})")]
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>, IEquatable<Pair<T1, T2>>
where T1 : IComparable<T1>
where T2 : IComparable<T2>
{
public Pair(T1 first, T2 second)
{
this.first = first;
this.second = second;
}
public T1 first;
public T2 second;
public int CompareTo(Pair<T1, T2> other)
{
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;
var firstComparison = first.CompareTo(other.first);
return firstComparison != 0 ? firstComparison : second.CompareTo(other.second);
}
public override string ToString() => $"({first}, {second})";
public bool Equals(Pair<T1, T2> other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return EqualityComparer<T1>.Default.Equals(first, other.first) &&
EqualityComparer<T2>.Default.Equals(second, other.second);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((Pair<T1, T2>) obj);
}
public override int GetHashCode()
{
unchecked
{
return (EqualityComparer<T1>.Default.GetHashCode(first) * 397) ^
EqualityComparer<T2>.Default.GetHashCode(second);
}
}
}
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Math;
using static Solve.Methods;
using static Solve.Input;
using static Solve.Output;
using pii = Solve.Pair<int, int>;
using pll = Solve.Pair<long, long>;
using pli = Solve.Pair<long, int>;
using pil = Solve.Pair<int, long>;
using pss = Solve.Pair<string, string>;
using psi = Solve.Pair<string, int>;
using lint = System.Collections.Generic.List<int>;
using llong = System.Collections.Generic.List<long>;
using lstr = System.Collections.Generic.List<string>;
using llint = System.Collections.Generic.List<System.Collections.Generic.List<int>>;
using llstr = System.Collections.Generic.List<System.Collections.Generic.List<long>>;
using lllong = System.Collections.Generic.List<System.Collections.Generic.List<string>>;
using lii = System.Collections.Generic.List<Solve.Pair<int, int>>;
using lll = System.Collections.Generic.List<Solve.Pair<long, long>>;
using lli = System.Collections.Generic.List<Solve.Pair<long, int>>;
using lil = System.Collections.Generic.List<Solve.Pair<int, long>>;
using ll = System.Int64;
namespace Solve
{
public class Solver
{
public void Main()
{
int N, K;
string S;
In(out N, out K,out S);
// 1 である数
var list = new List<int>();
if(S[0] != '1') list.Add(0);
int cnt = 1;
for (int i = 1; i < N; i++)
{
if (S[i] != S[i - 1])
{
list.Add(cnt);
cnt = 1;
}
else ++cnt;
}
list.Add(cnt);
for (int i = 0; i < 1e6; i++)
{
list.Add(0);
}
var cs = list.CumSum().ToArray();
// [i, i + 2K]
int max = 0;
for (int i = 0; i + 2 * K < list.Count; i += 2)
{
int now = cs[i + 2 * K];
if(i>0)now-=cs[i - 1];
chmax(ref max, now);
}
cout = max;
}
// ReSharper disable UnusedMember.Local
private const int MOD = (int) 1e9 + 7,
INF = 1000000010;
private const long LINF = 1000000000000000100;
}
// ライブラリ置き場ここから
/// <summary>
/// SegmentTree 一点更新区間取得
/// </summary>
/// <typeparam name="T">要素の型</typeparam>
public class SegmentTree<T>
{
private readonly int _size;
private readonly T[] _seg;
private readonly Func<T, T, T> _func;
private readonly T _identity;
public SegmentTree(int N, Func<T, T, T> func, T identity)
{
_func = func;
_identity = identity;
_size = 1 << (int) Ceiling(Log(N, 2));
_seg = Enumerable.Repeat(_identity, _size * 2).ToArray();
}
public void Set(int i, T value)
{
if (i < 0 || i >= _size) throw new ArgumentOutOfRangeException(nameof(i));
_seg[_size + i] = value;
}
public void Build()
{
for (int i = _size - 1; i > 0; i--)
_seg[i] = _func(_seg[2 * i], _seg[2 * i + 1]);
}
public void Update(int i, T value)
{
i += _size;
_seg[i] = value;
while ((i >>= 1) > 0)
_seg[i] = _func(_seg[2 * i], _seg[2 * i + 1]);
}
public T Query(int l, int r)
{
T L = _identity, R = _identity;
for (l += _size, r += _size; l < r; l >>= 1, r >>= 1)
{
if ((l & 1) > 0) L = _func(L, _seg[l++]);
if ((r & 1) > 0) R = _func(_seg[--r], R);
}
return _func(L, R);
}
public T this[int i] => _seg[i + _size];
}
// ライブラリ置き場ここまで
#region Templete
#if !LOCAL
namespace Library { }
#endif
public static class Methods
{
public static readonly int[] dx = {-1, 0, 0, 1};
public static readonly int[] dy = {0, 1, -1, 0};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Assert(bool b, string message = null)
{
if (!b) throw new Exception(message ?? "Assert failed.");
}
/*
public static Comparison<T> greater<T>()
where T : IComparable<T>
=> (a, b) => b.CompareTo(a);
*/
public static string JoinSpace<T>(this IEnumerable<T> source) => source.Join(" ");
public static string JoinEndline<T>(this IEnumerable<T> source) => source.Join("\n");
public static string Join<T>(this IEnumerable<T> source, string s) => string.Join(s, source);
public static string Join<T>(this IEnumerable<T> source, char c) => string.Join(c.ToString(), source);
/// <summary>
/// <see cref="Pair{T1, T2}"/> クラスのインスタンスを作成します。
/// </summary>
/// <typeparam name="T1">firstの型</typeparam>
/// <typeparam name="T2">secondの型</typeparam>
/// <param name="first">firstの値</param>
/// <param name="second">secondの値</param>
/// <returns>作成した<see cref="Pair{T1, T2}"/> クラスのインスタンス</returns>
public static Pair<T1, T2> make_pair<T1, T2>(T1 first, T2 second)
where T1 : IComparable<T1>
where T2 : IComparable<T2>
=> new Pair<T1, T2>(first, second);
/// <summary>aとbをスワップします。</summary>
public static void Swap<T>(ref T a, ref T b) where T : struct
{
var tmp = b;
b = a;
a = tmp;
}
/// <summary>aとbの最大公約数を求めます。</summary>
/// <returns>aとbの最大公約数</returns>
public static long Gcd(long a, long b)
{
while (true)
{
if (a < b) Swap(ref a, ref b);
if (a % b == 0) return b;
var x = a;
a = b;
b = x % b;
}
}
/// <summary>aとbの最小公倍数を求めます。</summary>
/// <returns>aとbの最小公倍数</returns>
public static long Lcm(long a, long b) => a / Gcd(a, b) * b;
/// <summary>
/// 指定した数値が素数であるかを判定します。
/// </summary>
/// <remarks>計算量 (sqrt(value)) </remarks>
/// <param name="value">判定する数値</param>
/// <returns>value が素数であるか</returns>
public static bool IsPrime(long value)
{
if (value <= 1) return false;
for (long i = 2; i * i <= value; i++)
if (value % i == 0)
return false;
return true;
}
/// <summary>
/// <see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) を求める
/// </summary>
/// <returns><see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) の値</returns>
public static long PowMod(long a, long b, long p)
{
long res = 1;
while (b > 0)
{
if (b % 2 != 0) res = res * a % p;
a = a * a % p;
b >>= 1;
}
return res;
}
/// <summary>
/// mod pにおけるaの逆元を求めます。
/// </summary>
/// <param name="a"></param>
/// <param name="p">法</param>
/// <returns></returns>
public static long ModInv(long a, long p)
=> PowMod(a, p - 2, p);
public static int DivCeil(int left, int right)
=> left / right + (left % right == 0 ? 0 : 1);
public static long DivCeil(long left, long right)
=> left / right + (left % right == 0L ? 0L : 1L);
/// <summary>
/// src の順列を求めます。
/// </summary>
/// <typeparam name="T">型</typeparam>
/// <param name="src">順列を求める配列</param>
/// <returns>src の順列</returns>
public static IEnumerable<T[]> Permutations<T>(IEnumerable<T> src)
{
var ret = new List<T[]>();
Search(ret, new Stack<T>(), src.ToArray());
return ret;
}
private static void Search<T>(ICollection<T[]> perms, Stack<T> stack, T[] a)
{
int N = a.Length;
if (N == 0) perms.Add(stack.Reverse().ToArray());
else
{
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i)
{
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) b[i] = a[i];
stack.Pop();
}
}
}
/// <summary>
/// 指定した条件を満たす最小の数値を返します。
/// </summary>
/// <param name="low">検索する数値の最小値</param>
/// <param name="high">検索する数値の最大値</param>
/// <param name="expression">条件</param>
/// <returns>条件を満たす最小の数値</returns>
public static long BinarySearch(long low, long high, Func<long, bool> expression)
{
while (low < high)
{
long middle = (high - low) / 2 + low;
if (!expression(middle))
high = middle;
else
low = middle + 1;
}
return high;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返します。
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
{
int low = start;
int high = end;
while (low < high)
{
var mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返します。
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="value">検索する値</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(T[] arr, T value) where T : IComparable
{
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返します。
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
{
int low = start;
int high = end;
while (low < high)
{
var mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返します。
/// </summary>Z
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="value">検索する値</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(T[] arr, T value)
{
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static IEnumerable<TResult> SelectNotNull<TSource, TResult>(this IEnumerable<TSource> source,
Func<TSource, TResult> func)
=> source.Where(val => val != null).Select(func);
public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource> source)
=> source.Where(val => val != null);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] ArrayOf<T>(params T[] arr) => arr;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<T> ListOf<T>(params T[] arr) => new List<T>(arr);
public static IEnumerable<TResult> Repeat<TResult>(TResult value)
{
while (true) yield return value;
// ReSharper disable once IteratorNeverReturns
}
public static IEnumerable<TResult> Repeat<TResult>(TResult value, int count)
=> Enumerable.Repeat(value, count);
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source, int count)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));
for (int i = 0; i < count; i++)
foreach (var v in source)
yield return v;
}
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source)
{
if (source == null) throw new ArgumentNullException(nameof(source));
while (true)
foreach (var v in source)
yield return v;
}
/// <summary>
/// 文字の配列を文字列に変換します。
/// </summary>
/// <param name="source">文字の配列</param>
/// <returns>変換した文字列</returns>
public static string AsString(this IEnumerable<char> source) => new string(source.ToArray());
/// <summary>
/// <see cref="source"/> の累積和を返します。
/// </summary>
/// <returns><see cref="source"/> の累積和</returns>
public static IEnumerable<long> CumSum(this IEnumerable<long> source)
{
long sum = 0;
foreach (var item in source)
yield return sum += item;
}
/// <summary>
/// <see cref="source"/> の累積和を返します。
/// </summary>
/// <returns><see cref="source"/> の累積和</returns>
public static IEnumerable<int> CumSum(this IEnumerable<int> source)
{
int sum = 0;
foreach (var item in source)
yield return sum += item;
}
/// <summary>
/// <see cref="value"/>が l以上 r未満の範囲に含まれているかを返します。
/// </summary>
/// <typeparam name="T">要素の型</typeparam>
/// <param name="value">判定する値</param>
/// <param name="l">下限の値 (含まれる)</param>
/// <param name="r">上限の値 (含まれない)</param>
/// <returns><see cref="value"/> が指定した範囲に含まれているか</returns>
public static bool IsIn<T>(this T value, T l, T r)
where T : IComparable<T>
{
if (l.CompareTo(r) > 0) throw new ArgumentException();
return l.CompareTo(value) <= 0 && value.CompareTo(r) < 0;
}
/// <summary>
/// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を列挙します。
/// </summary>
/// <param name="start">値の下限 (含まれる)</param>
/// <param name="end">値の上限 (含まれない)</param>
/// <param name="step">1要素ごとに増やす値</param>
/// <returns>範囲の結果</returns>
public static IEnumerable<int> Range(int start, int end, int step = 1)
{
for (var i = start; i < end; i += step) yield return i;
}
/// <summary>
/// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を列挙します。
/// </summary>
/// <param name="end">値の上限 (含まれない)</param>
/// <returns>範囲の結果</returns>
public static IEnumerable<int> Range(int end) => Range(0, end);
/// <summary>
/// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を逆順に列挙します。
/// </summary>
/// <param name="start">値の下限 (含まれる)</param>
/// <param name="end">値の上限 (含まれない)</param>
/// <param name="step">1要素ごとに増やす値</param>
/// <returns>範囲の結果</returns>
public static IEnumerable<int> RangeReverse(int start, int end, int step = 1)
{
for (var i = end - 1; i >= start; i -= step) yield return i;
}
/// <summary>
/// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を逆順に列挙します。
/// </summary>
/// <param name="end">値の上限 (含まれない)</param>
/// <returns>範囲の結果</returns>
public static IEnumerable<int> RangeReverse(int end) => RangeReverse(0, end);
/// <summary>
/// 指定した配列をコピーして昇順ソートします。(非破壊的)
/// </summary>
/// <typeparam name="T">ソートする配列の型</typeparam>
/// <param name="arr">ソートする配列</param>
/// <returns>ソートされた配列</returns>
public static T[] Sort<T>(this T[] arr)
{
var array = new T[arr.Length];
arr.CopyTo(array, 0);
Array.Sort(array);
return array;
}
/// <summary>
/// 指定した配列をコピーして降順ソートします。(非破壊的)
/// </summary>
/// <typeparam name="T">ソートする配列の型</typeparam>
/// <param name="arr">ソートする配列</param>
/// <returns>ソートされた配列</returns>
public static T[] SortDescending<T>(this T[] arr)
{
var array = new T[arr.Length];
arr.CopyTo(array, 0);
Array.Sort(array);
Array.Reverse(array);
return array;
}
public static double Log2(double x) => Log(x, 2);
public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
{
if (a.CompareTo(b) > 0)
{
a = b;
return true;
}
return false;
}
public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
{
if (a.CompareTo(b) < 0)
{
a = b;
return true;
}
return false;
}
public static T Min<T>(params T[] col) => col.Min();
public static T Max<T>(params T[] col) => col.Max();
/// <summary>
/// 要素数 (a, b) の、defaultValue で満たされたジャグ配列を作成します。
/// </summary>
/// <typeparam name="T">配列の型</typeparam>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <returns>指定した条件で初期化された配列</returns>
public static T[][] JaggedArray2D<T>(int a, int b, T defaultValue = default(T))
{
var ret = new T[a][];
for (int i = 0; i < a; i++)
{
ret[i] = Enumerable.Repeat(defaultValue, b).ToArray();
}
return ret;
}
/// <summary>
/// 要素数 (a, b) の,defaultValue で満たされた二次元配列を作成します。
/// </summary>
/// <param name="a">1次元の要素数</param>
/// <param name="b">2次元の要素数</param>
/// <param name="defaultValue">デフォルト値</param>
/// <typeparam name="T">配列の型</typeparam>
public static T[,] Array2D<T>(int a, int b, T defaultValue = default(T))
{
var ret = new T[a, b];
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
ret[i, j] = defaultValue;
return ret;
}
/// <summary>
/// ジャグ配列を2次元配列に変換します。配列の各要素の長さがすべて同じである必要があります。
/// </summary>
/// <param name="array">ジャグ配列</param>
/// <typeparam name="T">二次元配列</typeparam>
public static T[,] To2DArray<T>(this T[][] array)
{
if (!array.Any()) return new T[0, 0];
int len = array[0].Length;
if (array.Any(x => x.Length != len))
throw new ArgumentException("array の各要素の長さが異なります。", nameof(array));
var ret = new T[array.Length, len];
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < len; j++)
{
ret[i, j] = array[i][j];
}
}
return ret;
}
// public static vector<T> ToVector<T>(this IEnumerable<T> source) => new vector<T>(source);
}
public static class Input
{
private const char _separator = ' ';
private static readonly Queue<string> _input = new Queue<string>();
private static readonly StreamReader sr =
#if FILE
new StreamReader("in.txt");
#else
new StreamReader(Console.OpenStandardInput());
#endif
public static string ReadLine => sr.ReadLine();
public static string ReadStr => Read;
public static string Read
{
get
{
if (_input.Count != 0) return _input.Dequeue();
// ReSharper disable once PossibleNullReferenceException
var tmp = sr.ReadLine().Split(_separator);
foreach (var val in tmp)
{
_input.Enqueue(val);
}
return _input.Dequeue();
}
}
public static int ReadInt => int.Parse(Read);
public static long ReadLong => long.Parse(Read);
public static double ReadDouble => double.Parse(Read);
public static string[] StrArray() => ReadLine.Split(' ');
public static int[] IntArray() => ReadLine.Split(' ').Select(int.Parse).ToArray();
public static long[] LongArray() => ReadLine.Split(' ').Select(long.Parse).ToArray();
public static string[] StrArray(int n)
{
var ret = new string[n];
for (long i = 0; i < n; ++i) ret[i] = Read;
return ret;
}
public static int[] IntArray(int n, int offset = 0, bool sorted = false)
{
var ret = StrArray(n).Select(x => int.Parse(x) + offset).ToArray();
if (sorted) Array.Sort(ret);
return ret;
}
public static long[] LongArray(int n, long offset = 0, bool sorted = false)
{
var ret = StrArray(n).Select(x => long.Parse(x) + offset).ToArray();
if (sorted) Array.Sort(ret);
return ret;
}
public static string[,] Str2DArray(int n, int m)
{
var ret = new string[n, m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ret[i, j] = ReadStr;
return ret;
}
public static int[,] Int2DArray(int n, int m, int offset = 0)
{
var ret = new int[n, m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ret[i, j] = ReadInt + offset;
return ret;
}
public static long[,] Long2DArray(int n, int m, long offset = 0)
{
var ret = new long[n, m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ret[i, j] = ReadLong + offset;
return ret;
}
public static Tuple<string[], string[]> StrArrays2(int n)
{
var ret1 = new string[n];
var ret2 = new string[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadStr;
ret2[i] = ReadStr;
}
return Tuple.Create(ret1, ret2);
}
public static Tuple<int[], int[]> IntArrays2(int n, int offset1 = 0, int offset2 = 0)
{
var ret1 = new int[n];
var ret2 = new int[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadInt + offset1;
ret2[i] = ReadInt + offset2;
}
return Tuple.Create(ret1, ret2);
}
public static Tuple<long[], long[]> LongArrays2(int n, long offset1 = 0, long offset2 = 0)
{
var ret1 = new long[n];
var ret2 = new long[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadLong + offset1;
ret2[i] = ReadLong + offset2;
}
return Tuple.Create(ret1, ret2);
}
public static Tuple<string[], string[], string[]> StrArrays3(int n)
{
var ret1 = new string[n];
var ret2 = new string[n];
var ret3 = new string[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadStr;
ret2[i] = ReadStr;
}
return Tuple.Create(ret1, ret2, ret3);
}
public static Tuple<int[], int[], int[]> IntArrays3(int n, int offset1 = 0, int offset2 = 0, int offset3 = 0)
{
var ret1 = new int[n];
var ret2 = new int[n];
var ret3 = new int[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadInt + offset1;
ret2[i] = ReadInt + offset2;
ret3[i] = ReadInt + offset3;
}
return Tuple.Create(ret1, ret2, ret3);
}
public static Tuple<long[], long[], long[]> LongArrays3(int n, long offset1 = 0, long offset2 = 0,
long offset3 = 0)
{
var ret1 = new long[n];
var ret2 = new long[n];
var ret3 = new long[n];
for (int i = 0; i < n; i++)
{
ret1[i] = ReadLong + offset1;
ret2[i] = ReadLong + offset2;
ret3[i] = ReadLong + offset3;
}
return Tuple.Create(ret1, ret2, ret3);
}
private static bool TypeEquals<T, U>() => typeof(T) == typeof(U);
private static T ChangeType<T, U>(U a) => (T) System.Convert.ChangeType(a, typeof(T));
private static T Convert<T>(string s) => TypeEquals<T, int>() ? ChangeType<T, int>(int.Parse(s))
: TypeEquals<T, long>() ? ChangeType<T, long>(long.Parse(s))
: TypeEquals<T, double>() ? ChangeType<T, double>(double.Parse(s))
: TypeEquals<T, char>() ? ChangeType<T, char>(s[0])
: ChangeType<T, string>(s);
public static bool In<T>(out T a)
{
try
{
a = Convert<T>(Read);
return true;
}
catch
{
a = default(T);
return false;
}
}
public static bool In<T, U>(out T a, out U b)
{
try
{
var ar = StrArray(2);
a = Convert<T>(ar[0]);
b = Convert<U>(ar[1]);
return true;
}
catch
{
a = default(T);
b = default(U);
return false;
}
}
public static bool In<T, U, V>(out T a, out U b, out V c)
{
try
{
var ar = StrArray(3);
a = Convert<T>(ar[0]);
b = Convert<U>(ar[1]);
c = Convert<V>(ar[2]);
return true;
}
catch
{
a = default(T);
b = default(U);
c = default(V);
return false;
}
}
public static bool In<T, U, V, W>(out T a, out U b, out V c, out W d)
{
try
{
var ar = StrArray(4);
a = Convert<T>(ar[0]);
b = Convert<U>(ar[1]);
c = Convert<V>(ar[2]);
d = Convert<W>(ar[3]);
return true;
}
catch
{
a = default(T);
b = default(U);
c = default(V);
d = default(W);
return false;
}
}
public static bool In<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
{
try
{
var ar = StrArray(5);
a = Convert<T>(ar[0]);
b = Convert<U>(ar[1]);
c = Convert<V>(ar[2]);
d = Convert<W>(ar[3]);
e = Convert<X>(ar[4]);
return true;
}
catch
{
a = default(T);
b = default(U);
c = default(V);
d = default(W);
e = default(X);
return false;
}
}
}
public static class Output
{
public static void print<T>(T t) => Console.WriteLine(t);
public static void print(params object[] o) => Console.WriteLine(o.Join(" "));
public static void PrintBool(bool val, string yes = "Yes", string no = "No")
=> Console.WriteLine(val ? yes : no);
public static void PrintYn(bool val) => PrintBool(val);
public static void PrintYN(bool val) => PrintBool(val, "YES", "NO");
public static void PrintPossible(bool val) => PrintBool(val, "Possible", "Impossible");
public static void PrintYay(bool val) => PrintBool(val, "Yay!", ":(");
public static void PrintDebug(params object[] args)
=> Console.Error.WriteLine(string.Join(" ", args));
/// <summary>
/// setter で設定された値を標準出力に出力します。
/// </summary>
public static object cout { set { Console.WriteLine(value); } }
/// <summary>
/// Local環境のみ,setter で設定された値を標準出力に出力します。
/// </summary>
public static object dout
{
set
{
#if LOCAL
Console.WriteLine(value);
#endif
}
}
/// <summary>
/// setter で設定された値を標準エラー出力に出力します。
/// </summary>
public static object cerr { set { Console.Error.WriteLine(value); } }
public const string endl = "\n";
}
public class Program
{
public static void Main(string[] args)
{
var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
Console.SetOut(sw);
new Solver().Main();
Console.Out.Flush();
}
}
[DebuggerDisplay("({first}, {second})")]
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>, IEquatable<Pair<T1, T2>>
where T1 : IComparable<T1>
where T2 : IComparable<T2>
{
public Pair(T1 first, T2 second)
{
this.first = first;
this.second = second;
}
public T1 first;
public T2 second;
public int CompareTo(Pair<T1, T2> other)
{
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;
var firstComparison = first.CompareTo(other.first);
return firstComparison != 0 ? firstComparison : second.CompareTo(other.second);
}
public override string ToString() => $"({first}, {second})";
public bool Equals(Pair<T1, T2> other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return EqualityComparer<T1>.Default.Equals(first, other.first) &&
EqualityComparer<T2>.Default.Equals(second, other.second);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((Pair<T1, T2>) obj);
}
public override int GetHashCode()
{
unchecked
{
return (EqualityComparer<T1>.Default.GetHashCode(first) * 397) ^
EqualityComparer<T2>.Default.GetHashCode(second);
}
}
}
#endregion
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 250], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 5,963
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC124
{
class D {
static void Main(string[] args) {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int K = input[1];
string S = Console.ReadLine();
List<int> list = new List<int>();
int count;
for (int i = 0; i < S.Length; i++) {
if (i == 0 && S[0] != '1') {
list.Add(0);
}
count = 1;
while (1 < S.Length && i < S.Length - 1 && S[i] == S[i + 1]) {
count++;
i++;
}
list.Add(count);
}
if (S.Length == 1) {
if (S[0] == '1') {
list.Add(1);
list.Add(0);
} else {
list.Add(0);
list.Add(1);
}
}
var Count = list.ToArray();
int[] CS = new int[Count.Length + 1];
CS[0] = 0;
for (int i = 1; i < Count.Length; i++) {
CS[i] = CS[i - 1] + Count[i - 1];
}
CS[Count.Length] = CS[Count.Length - 1] + Count[Count.Length - 1];
// if (CS.Length % 2 == 1) { CS[Count.Length + 1] = 0; }
int max = 0;
for (int i = 0; i + 2 * K + 1 < CS.Length; i += 2) {
max = Math.Max(max, CS[i + 2 * K + 1] - CS[i]);
}
if (S.Length == 1)
max = 1;
if (CS.Length / 2 <= K)
max = S.Length;
/*
foreach (var item in CS)
{
Console.WriteLine("cs " + item);
}
*/
Console.WriteLine(max);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC124
{
class D {
static void Main(string[] args) {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int K = input[1];
string S = Console.ReadLine();
List<int> list = new List<int>();
int count;
for (int i = 0; i < S.Length; i++) {
if (i == 0 && S[0] != '1') {
list.Add(0);
}
count = 1;
while (1 < S.Length && i < S.Length - 1 && S[i] == S[i + 1]) {
count++;
i++;
}
list.Add(count);
}
if (S.Length == 1) {
if (S[0] == '1') {
list.Add(1);
list.Add(0);
} else {
list.Add(0);
list.Add(1);
}
}
var Count = list.ToArray();
int[] CS = new int[Count.Length + 2];
CS[0] = 0;
for (int i = 1; i < Count.Length; i++) {
CS[i] = CS[i - 1] + Count[i - 1];
}
CS[Count.Length] = CS[Count.Length - 1] + Count[Count.Length - 1];
CS[Count.Length + 1] = CS[Count.Length - 1] + Count[Count.Length - 1];
int max = 0;
for (int i = 0; i + 2 * K + 1 < CS.Length; i += 2) {
max = Math.Max(max, CS[i + 2 * K + 1] - CS[i]);
}
if (S.Length == 1)
max = 1;
if (CS.Length / 2 <= K)
max = S.Length;
Console.WriteLine(max);
}
}
}
|
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 205, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 0, 131], ["+", 31, 204, 206, 207, 0, 28, 0, 214, 141, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72]]
| 8
| 430
| 29
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = l[0], K = l[1];
var array = Console.ReadLine().ToCharArray();
var acum = new List<int>();
if (array[0] == '0')
acum.Add(0);
for (var i = 0; i < N; i++) {
var count = i;
while (count < array.Count() && array[count] == array[i])
count++;
acum.Add(count - i);
i = count;
}
if (array[N - 1] == '0')
acum.Add(0);
var sum = new long[N + 1];
for (var i = 0; i < acum.Count(); i++)
sum[i + 1] = sum[i] + acum[i];
var res = 0L;
for (var left = 0; left < sum.Count(); left += 2) {
var right = left + K * 2 + 1;
if (right >= sum.Count())
right = sum.Count() - 1;
res = Math.Max(res, sum[right] - sum[left]);
}
Console.WriteLine(res);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = l[0], K = l[1];
var array = Console.ReadLine().ToCharArray();
var acum = new List<int>();
if (array[0] == '0')
acum.Add(0);
for (var i = 0; i < array.Count();) {
var count = i;
while (count < array.Count() && array[count] == array[i])
count++;
acum.Add(count - i);
i = count;
}
if (array[N - 1] == '0')
acum.Add(0);
var sum = new long[acum.Count() + 1];
for (var i = 0; i < acum.Count(); i++)
sum[i + 1] = sum[i] + acum[i];
var res = 0L;
for (var left = 0; left < sum.Count(); left += 2) {
var right = left + K * 2 + 1;
if (right >= sum.Count())
right = sum.Count() - 1;
res = Math.Max(res, sum[right] - sum[left]);
}
Console.WriteLine(res);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["+", 225, 226, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 225, 226, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 225, 226, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 225, 226, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 225, 226, 0, 16, 31, 213, 3, 4, 0, 25]]
| 8
| 321
| 14
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
new ABC124().SolveD(new ConsoleInput(Console.In, ' '));
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
public static class AtCoderLib {
// ユークリッドの互除法
public static int Gcd(int a, int b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
class ABC124 {
public void SolveD(ConsoleInput cin) {
var n = cin.ReadInt;
var k = cin.ReadInt;
var s = cin.Read;
var C = s.ToCharArray();
var A = new List<int>();
//ランレングス圧縮
int length = 1;
for (int i = 1; i < n; i++) {
if (C[i] == C[i - 1]) {
length++;
} else {
A.Add(length);
length = 1;
}
}
A.Add(length);
//しゃくとり法
int sum = 0;
int result = 1;
int left = 0;
int right = 2 * k;
if (C[0] == '1')
right++;
// Write($"A=");
// foreach (var a in A) { Write(a); }
// WriteLine();
sum = A.Skip(left).Take(right - left).Sum();
while (left < A.Count() - k) {
// WriteLine($"L={left} R={right}");
if (sum > result)
result = sum;
left++;
sum -= A[left];
if (right - left == 2 * k) {
right += 2;
if (right < A.Count())
sum += A[right];
}
}
if (sum > result)
result = sum;
WriteLine(result);
ReadLine();
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
new ABC124().SolveD(new ConsoleInput(Console.In, ' '));
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
public static class AtCoderLib {
// ユークリッドの互除法
public static int Gcd(int a, int b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
class ABC124 {
public void SolveD(ConsoleInput cin) {
var n = cin.ReadInt;
var k = cin.ReadInt;
var s = cin.Read;
var C = s.ToCharArray();
var A = new List<int>();
//ランレングス圧縮
int length = 1;
for (int i = 1; i < n; i++) {
if (C[i] == C[i - 1]) {
length++;
} else {
A.Add(length);
length = 1;
}
}
A.Add(length);
//しゃくとり法
int sum = 0;
int result = 1;
int left = 0;
int right = 2 * k;
if (C[0] == '1')
right++;
// Write($"A=");
// foreach (var a in A) { Write(a); }
// WriteLine();
sum = A.Skip(left).Take(right - left).Sum();
while (left < A.Count() - 2 * k) {
// WriteLine($"L={left} R={right} sum={sum}");
if (sum > result)
result = sum;
sum -= A[left];
left++;
if (right - left == 2 * k - 1) {
right++;
if (right <= A.Count())
sum += A[right - 1];
right++;
if (right <= A.Count())
sum += A[right - 1];
}
}
if (sum > result)
result = sum;
WriteLine(result);
ReadLine();
}
}
}
|
[["+", 0, 52, 15, 16, 12, 16, 12, 16, 31, 203], ["+", 0, 52, 15, 16, 12, 16, 12, 16, 17, 48], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 737
| 37
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var nk = Console.ReadLine().Split();
var n = int.Parse(nk[0]);
var k = int.Parse(nk[1]) * 2 + 1;
var s = Console.ReadLine();
var d = new List<int> { 1 };
for (int i = 1; i < s.Length; i++) {
if (s[i - 1] == s[i])
d[d.Count - 1]++;
else
d.Add(d[d.Count - 1] + 1);
}
if (d.Count <= k) {
Console.WriteLine(n);
return;
}
var ans = 0;
var j = s[0] == '0' ? 1 : 0;
for (; j < d.Count; j += 2) {
if (k <= j) {
ans = Math.Max(ans, d[j] - d[j - k]);
} else {
ans = Math.Max(ans, d[j]);
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var nk = Console.ReadLine().Split();
var n = int.Parse(nk[0]);
var k = int.Parse(nk[1]) * 2 + 1;
var s = Console.ReadLine();
var d = new List<int> { 1 };
for (int i = 1; i < s.Length; i++) {
if (s[i - 1] == s[i])
d[d.Count - 1]++;
else
d.Add(d[d.Count - 1] + 1);
}
d.Add(d[d.Count - 1]);
var ans = 0;
var j = s[0] == '0' ? 1 : 0;
for (; j < d.Count; j += 2) {
if (k <= j) {
ans = Math.Max(ans, d[j] - d[j - k]);
} else {
ans = Math.Max(ans, d[j]);
}
}
Console.WriteLine(ans);
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 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], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 256
| 21
|
using System;
using System.Linq;
using System.Collections.Generic;
class Dmondai {
static void Main() {
var nk =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
var N = nk[0];
var K = nk[1];
var S = Console.ReadLine();
var list = new List<int[]>();
var currentNum = -1;
var currentNumCount = 0;
var zeroCount = 0;
var isFirstZero = false;
var allCount = 0;
for (int i = 0; i < N; ++i) {
if (currentNum != S[i]) {
allCount++;
if (currentNum == -1)
isFirstZero = S[i] == '0';
if (S[i] == '0')
zeroCount++;
if (currentNum != -1)
list.Add(new int[2] { i == 0 ? S[i] : currentNum, currentNumCount });
currentNum = S[i];
currentNumCount = 1;
} else
currentNumCount++;
if (i == N - 1)
list.Add(new int[2] { currentNum, currentNumCount });
}
var ans = 0;
var count = zeroCount - K + 1;
// isFirstZero 0246 else 1357
//一番初め
var c = 0;
if (isFirstZero) {
var iC = 2 * K;
for (int i = 0; i < iC; ++i)
if (i < allCount)
c += list[i][1];
} else {
var iC = 2 * K + 1;
for (int i = 0; i < iC; ++i)
if (i < allCount)
c += list[i][1];
}
if (ans < c)
ans = c;
//累積和
for (int i = 1; i < count; ++i) {
//引く
if (i == 1 && isFirstZero) {
c -= list[0][1];
} // 0246
else if (isFirstZero) {
c -= (list[(i - 1) * 2][1] + list[(i - 1) * 2 - 1][1]);
} // 1357
else {
c -= (list[(i - 1) * 2][1] + list[(i - 1) * 2 + 1][1]);
}
//足す
// 0246
if (isFirstZero) {
var addIndex = (i + K - 1) * 2 - 1;
c += list[addIndex][1];
if (addIndex + 1 < allCount)
c += list[addIndex + 1][1];
} // 1357
else {
var addIndex = (i + K - 1) * 2 + 1;
c += list[addIndex][1];
if (addIndex + 1 < allCount)
c += list[addIndex + 1][1];
}
if (ans < c)
ans = c;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Dmondai {
static void Main() {
var nk =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
var N = nk[0];
var K = nk[1];
var S = Console.ReadLine();
var list = new List<int[]>();
var currentNum = -1;
var currentNumCount = 0;
var zeroCount = 0;
var isFirstZero = false;
var allCount = 0;
for (int i = 0; i < N; ++i) {
if (currentNum != S[i]) {
allCount++;
if (currentNum == -1)
isFirstZero = S[i] == '0';
if (S[i] == '0')
zeroCount++;
if (currentNum != -1)
list.Add(new int[2] { currentNum, currentNumCount });
currentNum = S[i];
currentNumCount = 1;
} else
currentNumCount++;
if (i == N - 1)
list.Add(new int[2] { currentNum, currentNumCount });
}
var ans = 0;
var count = zeroCount - K + 1;
// isFirstZero 0246 else 1357
//一番初め
var c = 0;
if (isFirstZero) {
var iC = 2 * K - 1;
for (int i = 0; i <= iC; ++i)
if (i < allCount)
c += list[i][1];
} else {
var iC = 2 * K;
for (int i = 0; i <= iC; ++i)
if (i < allCount)
c += list[i][1];
}
if (ans < c)
ans = c;
//累積和
for (int i = 1; i < count; ++i) {
//引く
if (i == 1 && isFirstZero) {
c -= list[0][1];
} // 0246
else if (isFirstZero) {
c -= (list[(i - 1) * 2][1] + list[(i - 1) * 2 - 1][1]);
} // 1357
else {
c -= (list[(i - 1) * 2][1] + list[(i - 1) * 2 + 1][1]);
}
//足す
// 0246
if (isFirstZero) {
var addIndex = (i + K - 1) * 2;
c += list[addIndex][1];
if (addIndex + 1 < allCount)
c += list[addIndex + 1][1];
} // 1357
else {
var addIndex = (i + K - 1) * 2 + 1;
c += list[addIndex][1];
if (addIndex + 1 < allCount)
c += list[addIndex + 1][1];
}
if (ans < c)
ans = c;
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 227, 0, 229, 0, 41, 15, 16, 31, 22], ["-", 0, 227, 0, 229, 0, 41, 15, 16, 17, 60], ["-", 0, 227, 0, 229, 0, 41, 15, 16, 12, 203], ["-", 0, 28, 0, 227, 0, 229, 0, 41, 0, 101], ["-", 0, 227, 0, 229, 0, 41, 64, 204, 205, 22], ["-", 0, 229, 0, 41, 64, 204, 206, 207, 0, 70], ["-", 0, 41, 64, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 229, 0, 41, 64, 204, 206, 207, 0, 73], ["-", 0, 28, 0, 227, 0, 229, 0, 41, 0, 102], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 57, 75, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33]]
| 8
| 608
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const int INF = 1 << 30;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
//ここから
var N = cin.Long1;
var A = cin.LongM;
var gcd = new long[N + 1];
var gcdinv = new long[N + 1];
gcd[0] = 0;
gcd[N] = 0;
for (long i = 0; i < N; ++i) {
gcd[i + 1] = mmath.GCD(gcd[i], A[i]);
}
for (long i = N - 1; i >= 0; --i) {
gcd[i] = mmath.GCD(gcd[i + 1], A[i]);
}
long ans = -1;
for (int i = 0; i < N; ++i) {
ans = Math.Max(mmath.GCD(gcd[i], gcdinv[i + 1]), ans);
}
cout.wri(ans);
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y > 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const int INF = 1 << 30;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner cin = new Scaner();
write cout = new write();
Math2 mmath = new Math2();
//ここから
var N = cin.Long1;
var A = cin.LongM;
var gcd = new long[N + 1];
var gcdinv = new long[N + 1];
for (long i = 0; i < N; ++i) {
gcd[i + 1] = mmath.GCD(gcd[i], A[i]);
}
for (long i = N - 1; i >= 0; --i) {
gcdinv[i] = mmath.GCD(gcdinv[i + 1], A[i]);
}
long ans = -1;
for (int i = 0; i < N; ++i) {
ans = Math.Max(mmath.GCD(gcd[i], gcdinv[i + 1]), ans);
}
cout.wri(ans);
}
}
// b-aで降順
// priority queue
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
public class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
// Nまでの階乗をセットしておく
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = pow(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
// nCr 引数:n r (mod)
public long nCr(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
//階乗(O(logN)) 引数:底x n乗 (MOD)
public long pow(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
//最大公約数 引数:整数x,y
public long GCD(long x, long y) {
while (y != 0) {
var r = x % y;
x = y;
y = r;
}
return x;
}
//最小公倍数 引数:整数x,y
public long LCM(long x, long y) { return x * y / GCD(x, y); }
//素因数分解 引数:整数N
public Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
}
namespace CompLib.Algorithms {
#region BinarySearch
public static partial class Algorithm {
static int binarySearch<T>(IList<T> a, T v, IComparer<T> cmp, bool islb) {
var l = 0;
var r = a.Count - 1;
while (l <= r) {
var m = (l + r) / 2;
var res = cmp.Compare(a[m], v);
if (res < 0 || (res == 0 && !islb))
l = m + 1;
else
r = m - 1;
}
return l;
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v, Comparison<T> f) {
return binarySearch(a, v, Comparer<T>.Create(f), true);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int LowerBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, true);
}
/// <summary>
/// 与えられた比較関数に従って,<paramref name="a"/> の要素のうち,<paramref
/// name="v"/> 以上の要素であるような最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v, Comparison<T> cmp) {
return binarySearch(a, v, Comparer<T>.Create(cmp), false);
}
/// <summary>
/// デフォルトの比較関数に従って,<paramref name="a"/>
///の要素のうち,<paramref name="v"/>
///より真に大きい要素が現れる最小のインデックスを取得します.
/// </summary>
/// <typeparam name="T"><see cref="IList{T}"/>
/// の要素の型を指定します.</typeparam> <param
/// name="a">対象となるコレクション</param> <param
/// name="v">対象となる要素</param> <param name="f"></param>
/// <returns><paramref name="v"/> 以上の要素であるような最小の o-indexed
/// でのインデックス.</returns> <remarks> <paramref name="a"/>
/// は比較関数に対して昇順であることを仮定しています.この関数は O(log N)
/// で実行されます.</remarks>
public static int UpperBound<T>(this IList<T> a, T v) {
return binarySearch(a, v, Comparer<T>.Default, false);
}
}
#endregion
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrM => Str.Split(' ');
public long[] LongM => StrM.Select(long.Parse).ToArray();
public int[] IntM => StrM.Select(int.Parse).ToArray();
public char[] CharM => Str.ToArray();
public long Long1 => LongM[0];
public int Int1 => IntM[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
[["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 79]]
| 8
| 1,523
| 20
|
using System;
using System.Linq;
class C {
static void Main() {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine()
.Split()
.Select(int.Parse)
.GroupBy(x => x)
.SelectMany(g => g.Take(2))
.ToArray();
var l = new int[n];
var r = new int[n];
l[0] = a[0];
r[n - 1] = a[n - 1];
for (int i = 1; i < n; i++) {
l[i] = Gcd(l[i - 1], a[i]);
r[n - 1 - i] = Gcd(r[n - i], a[n - 1 - i]);
}
var M1 = Math.Max(r[1], l[n - 2]);
var M2 = Enumerable.Range(1, n - 2).Max(i => Gcd(l[i - 1], r[i + 1]));
Console.WriteLine(Math.Max(M1, M2));
}
static int Gcd(int x, int y) {
for (int r; (r = x % y) > 0; x = y, y = r)
;
return y;
}
}
|
using System;
using System.Linq;
class C {
static void Main() {
Console.ReadLine();
var a = Console.ReadLine()
.Split()
.Select(int.Parse)
.GroupBy(x => x)
.SelectMany(g => g.Take(2))
.ToArray();
var n = a.Length;
var l = new int[n];
var r = new int[n];
l[0] = a[0];
r[n - 1] = a[n - 1];
for (int i = 1; i < n; i++) {
l[i] = Gcd(l[i - 1], a[i]);
r[n - 1 - i] = Gcd(r[n - i], a[n - 1 - i]);
}
var M1 = Math.Max(r[1], l[n - 2]);
var M2 = n <= 2
? 1
: Enumerable.Range(1, n - 2).Max(i => Gcd(l[i - 1], r[i + 1]));
Console.WriteLine(Math.Max(M1, M2));
}
static int Gcd(int x, int y) {
for (int r; (r = x % y) > 0; x = y, y = r)
;
return y;
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 19], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102]]
| 8
| 291
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var L = Enumerable.Repeat(0, n).ToList();
for (var i = 0; i < n; i++) {
if (i == 0) {
L[0] = a[0];
} else {
L[i] = gcd(a[i - 1], L[i - 1]);
}
}
var R = Enumerable.Repeat(0, n).ToList();
for (var i = n - 1; i >= 0; i--) {
if (i == n - 1) {
R[n - 1] = a[n - 1];
} else {
R[i] = gcd(a[i + 1], R[i + 1]);
}
}
var max = 0;
for (var i = 0; i < n; i++) {
max = Math.Max(max, gcd(L[i], R[i]));
}
Console.WriteLine(max);
}
static int gcd(int a, int b) {
if (b > a) {
return gcd(b, a);
} else {
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var L = Enumerable.Repeat(0, n).ToList();
for (var i = 0; i < n; i++) {
if (i == 0) {
L[0] = 0;
} else {
L[i] = gcd(a[i - 1], L[i - 1]);
}
}
var R = Enumerable.Repeat(0, n).ToList();
for (var i = n - 1; i >= 0; i--) {
if (i == n - 1) {
R[n - 1] = 0;
} else {
R[i] = gcd(a[i + 1], R[i + 1]);
}
}
var max = 0;
for (var i = 0; i < n; i++) {
max = Math.Max(max, gcd(L[i], R[i]));
}
Console.WriteLine(max);
}
static int gcd(int a, int b) {
if (b > a) {
return gcd(b, a);
} else {
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 348
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC125_C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var str1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int max = 0;
List<int> Number = new List<int>();
for (var x = 0; x < N; x++) {
Number.Add(str1[x]);
}
var L = Enumerable.Repeat(0, N).ToList();
for (var i = 0; i < N; ++i) {
L[i] = i == 0 ? 0 : Gcd(L[i - 1], Number[i - 1]);
}
var R = Enumerable.Repeat(0, N).ToList();
R[N - 1] = 0;
R[N - 2] = Number[N - 1];
for (var i = N - 3; i >= 0; ++i) {
R[i] = Gcd(R[i + 1], Number[i + 1]);
}
for (var i = 0; i < N; ++i) {
max = Math.Max(Gcd(L[i], R[i]), max);
}
Console.WriteLine(max);
}
public static int Gcd(int a, int b) {
if (a < b)
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC125_C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var str1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int max = 0;
List<int> Number = new List<int>();
for (var x = 0; x < N; x++) {
Number.Add(str1[x]);
}
var L = Enumerable.Repeat(0, N).ToList();
for (var i = 0; i < N; ++i) {
L[i] = i == 0 ? 0 : Gcd(L[i - 1], Number[i - 1]);
}
var R = Enumerable.Repeat(0, N).ToList();
for (var i = N - 1; i >= 0; --i) {
R[i] = i == N - 1 ? 0 : Gcd(R[i + 1], Number[i + 1]);
}
for (var i = 0; i < N; ++i) {
max = Math.Max(Gcd(L[i], R[i]), max);
}
Console.WriteLine(max);
}
public static int Gcd(int a, int b) {
if (a < b)
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 241, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 68], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 31, 22], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 17, 33], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102]]
| 8
| 355
| 35
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var inputs = Console.ReadLine().Split(' ');
var A = new List<long>();
for (int i = 0; i < inputs.Length; i++) {
A.Add(long.Parse(inputs[i]));
}
A.Add(0);
var lefts = new long[N + 1];
lefts[0] = A[0];
for (int i = 0; i < A.Count - 1; i++) {
lefts[i + 1] = Gcd(lefts[i], A[i + 1]);
}
var rights = new long[N + 1];
rights[N] = A[N - 1];
for (int i = A.Count - 1; i >= 1; i--) {
rights[i - 1] = Gcd(rights[i], A[i - 1]);
}
long max = 0;
for (int i = 0; i < A.Count - 1; i++) {
long target;
if (i == 0) {
target = rights[1];
} else {
target = Gcd(lefts[i - 1], rights[i + 1]);
}
max = Math.Max(target, max);
}
Console.WriteLine(max);
}
/**
* ユークリッド互除法
* <see cref="https://qiita.com/gushwell/items/e9614b4ac2bea3fc6486"/>
*/
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var inputs = Console.ReadLine().Split(' ');
var A = new List<long>();
for (int i = 0; i < inputs.Length; i++) {
A.Add(long.Parse(inputs[i]));
}
A.Add(0);
var lefts = new long[N + 1];
lefts[0] = A[0];
for (int i = 0; i < A.Count - 1; i++) {
lefts[i + 1] = Gcd(lefts[i], A[i + 1]);
}
var rights = new long[N + 1];
rights[N] = A[N - 1];
for (int i = A.Count - 1; i >= 1; i--) {
rights[i - 1] = Gcd(rights[i], A[i - 1]);
}
long max = 0;
for (int i = 0; i < A.Count - 1; i++) {
long target;
if (i == 0) {
target = rights[1];
} else if (i == A.Count - 2) {
target = lefts[i - 1];
} else {
target = Gcd(lefts[i - 1], rights[i + 1]);
}
max = Math.Max(target, max);
}
Console.WriteLine(max);
}
/**
* ユークリッド互除法
* <see cref="https://qiita.com/gushwell/items/e9614b4ac2bea3fc6486"/>
*/
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 75, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 75, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 75, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 33], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95]]
| 8
| 377
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GCD_on_Blackboard {
class Program {
static int GCD(int a, int b) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
var large = a > b ? a : b;
var small = a > b ? b : a;
int remain = large % small;
if (remain == 0) {
return small;
}
return GCD(remain, small);
}
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int[] L = new int[n + 1];
int[] R = new int[n + 1];
int[] C = new int[n];
L[0] = 0;
R[n] = 0;
for (int i = 0; i < n; i++) {
L[i + 1] = GCD(L[i], A[i]);
R[n - i - 1] = GCD(R[n - i], A[n - i - 1]);
C[i] = GCD(L[i], R[i + 1]);
}
Console.WriteLine(C.Max());
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GCD_on_Blackboard {
class Program {
static int GCD(int a, int b) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
var large = a > b ? a : b;
var small = a > b ? b : a;
int remain = large % small;
if (remain == 0) {
return small;
}
return GCD(remain, small);
}
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int[] L = new int[n + 1];
int[] R = new int[n + 1];
int[] C = new int[n];
L[0] = 0;
R[n] = 0;
for (int i = 0; i < n; i++) {
L[i + 1] = GCD(L[i], A[i]);
R[n - i - 1] = GCD(R[n - i], A[n - i - 1]);
}
for (int i = 0; i < n; i++) {
C[i] = GCD(L[i], R[i + 1]);
}
Console.WriteLine(C.Max());
Console.ReadKey();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45]]
| 8
| 323
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace CSharp {
class Program {
static IEnumerable<long> EnumerateDivisors(long n) {
for (long i = 1; i * i <= n; i++) {
if (n % i == 0) {
yield return i;
if (n / i != i) {
yield return n / i;
}
}
}
}
static void Main(string[] args) {
ReadString();
long[] A = ReadLongArray();
long[] divisors =
Enumerable.Concat(EnumerateDivisors(A[0]), EnumerateDivisors(A[1]))
.Distinct()
.ToArray();
long ans =
divisors
.Select(x => new { Value = x, Count = A.Count(v => v % x == 0) })
.Where(x => x.Value != 1 && x.Count >= A.Length - 1)
.OrderByDescending(x => x.Value)
.First()
.Value;
Console.WriteLine(ans);
}
#region Helpers
static int[] ReadIntArray() =>
Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
static long[] ReadLongArray() =>
Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
static int[] ReadLineIntArray(int count) =>
Enumerable.Repeat(0, count)
.Select(_ => int.Parse(Console.ReadLine()))
.ToArray();
static long[] ReadLineLongArray(int count) =>
Enumerable.Repeat(0, count)
.Select(_ => long.Parse(Console.ReadLine()))
.ToArray();
static string ReadString() => Console.ReadLine();
static int ReadInt() => int.Parse(Console.ReadLine());
static long ReadLong() => long.Parse(Console.ReadLine());
static void ReadInt(out int first) {
var array = ReadIntArray();
first = array[0];
}
static void ReadInt(out int first, out int second) {
var array = ReadIntArray();
first = array[0];
second = array[1];
}
static void ReadInt(out int first, out int second, out int third) {
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadInt(out int first, out int second, out int third,
out int fourth) {
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
static void ReadLong(out long first) {
var array = ReadLongArray();
first = array[0];
}
static void ReadLong(out long first, out long second) {
var array = ReadLongArray();
first = array[0];
second = array[1];
}
static void ReadLong(out long first, out long second, out long third) {
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadLong(out long first, out long second, out long third,
out long fourth) {
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace CSharp {
class Program {
static IEnumerable<long> EnumerateDivisors(long n) {
for (long i = 1; i * i <= n; i++) {
if (n % i == 0) {
yield return i;
if (n / i != i) {
yield return n / i;
}
}
}
}
static void Main(string[] args) {
ReadString();
long[] A = ReadLongArray();
long[] divisors =
Enumerable.Concat(EnumerateDivisors(A[0]), EnumerateDivisors(A[1]))
.Distinct()
.ToArray();
long ans =
divisors
.Select(x => new { Value = x, Count = A.Count(v => v % x == 0) })
.Where(x => x.Count >= A.Length - 1)
.Max(x => x.Value);
Console.WriteLine(ans);
}
#region Helpers
static int[] ReadIntArray() =>
Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
static long[] ReadLongArray() =>
Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
static int[] ReadLineIntArray(int count) =>
Enumerable.Repeat(0, count)
.Select(_ => int.Parse(Console.ReadLine()))
.ToArray();
static long[] ReadLineLongArray(int count) =>
Enumerable.Repeat(0, count)
.Select(_ => long.Parse(Console.ReadLine()))
.ToArray();
static string ReadString() => Console.ReadLine();
static int ReadInt() => int.Parse(Console.ReadLine());
static long ReadLong() => long.Parse(Console.ReadLine());
static void ReadInt(out int first) {
var array = ReadIntArray();
first = array[0];
}
static void ReadInt(out int first, out int second) {
var array = ReadIntArray();
first = array[0];
second = array[1];
}
static void ReadInt(out int first, out int second, out int third) {
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadInt(out int first, out int second, out int third,
out int fourth) {
var array = ReadIntArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
static void ReadLong(out long first) {
var array = ReadLongArray();
first = array[0];
}
static void ReadLong(out long first, out long second) {
var array = ReadLongArray();
first = array[0];
second = array[1];
}
static void ReadLong(out long first, out long second, out long third) {
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
}
static void ReadLong(out long first, out long second, out long third,
out long fourth) {
var array = ReadLongArray();
first = array[0];
second = array[1];
third = array[2];
fourth = array[3];
}
#endregion
}
}
|
[["-", 0, 218, 8, 16, 31, 16, 31, 214, 141, 22], ["-", 0, 28, 0, 218, 8, 16, 31, 16, 17, 79], ["-", 0, 28, 0, 218, 8, 16, 31, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 98], ["-", 0, 218, 8, 16, 12, 16, 31, 214, 205, 22], ["-", 0, 218, 8, 16, 12, 16, 31, 214, 0, 131], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 212, 0, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 212, 0, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
| 8
| 743
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class abc125c {
public static int GCD(int a, int b) {
if (b > a)
Swap(ref a, ref b);
if (b == 0)
return a;
return GCD(b, a % b);
}
private static void Swap<T>(ref T a, ref T b) {
var temp = a;
a = b;
b = temp;
}
static void Main() {
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
var L = Enumerable.Repeat(0, N).ToList();
L[1] = A[0];
for (var i = 2; i != N; ++i) {
L[i] = GCD(L[i - 1], A[i]);
}
var R = Enumerable.Repeat(0, N).ToList();
R[N - 1] = 0;
R[N - 2] = A[N - 1];
for (var i = N - 3; i >= 0; --i) {
R[i] = GCD(R[i + 1], A[i + 1]);
}
var answer = 0;
for (var i = 0; i != N; ++i) {
answer = Math.Max(GCD(L[i], R[i]), answer);
}
Console.WriteLine(answer);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class abc125c {
public static int GCD(int a, int b) {
if (b > a)
Swap(ref a, ref b);
if (b == 0)
return a;
return GCD(b, a % b);
}
private static void Swap<T>(ref T a, ref T b) {
var temp = a;
a = b;
b = temp;
}
static void Main() {
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
var L = Enumerable.Repeat(0, N).ToList();
for (var i = 0; i != N; ++i) {
L[i] = i == 0 ? 0 : GCD(L[i - 1], A[i - 1]);
}
var R = Enumerable.Repeat(0, N).ToList();
R[N - 1] = 0;
R[N - 2] = A[N - 1];
for (var i = N - 3; i >= 0; --i) {
R[i] = GCD(R[i + 1], A[i + 1]);
}
var answer = 0;
for (var i = 0; i != N; ++i) {
answer = Math.Max(GCD(L[i], R[i]), answer);
}
Console.WriteLine(answer);
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 345
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC {
public static void Main() {
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int divided = -1;
int[] fromleft_GCD = new int[N];
int[] fromright_GCD = new int[N];
fromleft_GCD[0] = A[0];
fromright_GCD[N - 1] = A[N - 1];
for (int i = 1; i < N; i++) {
fromleft_GCD[i] = gcd2(fromleft_GCD[i - 1], A[i]);
fromright_GCD[N - i - 1] = gcd2(fromright_GCD[N - i], A[N - i - 1]);
}
int max_gcd = fromright_GCD[1];
for (int i = 2; i < fromright_GCD.Length; i++) {
var temp = gcd2(fromleft_GCD[i - 2], fromright_GCD[i]);
if (max_gcd < temp)
max_gcd = temp;
}
Console.WriteLine(max_gcd);
}
public static int[] prime_109() {
List<int> numbers = new List<int>();
for (int i = 2; i < 100000; i++) {
numbers.Add(i);
}
List<int> output = new List<int>();
while (numbers.Count != 0) {
int temp = numbers[0];
numbers.RemoveAt(0);
output.Add(temp);
var d = numbers.Where(x => x % temp != 0);
numbers = new List<int>(d);
}
return output.ToArray();
}
public static int gcd2(int a, int b) {
if (a % b == 0)
return b;
else
return gcd2(b, a % b);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC {
public static void Main() {
int N = int.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int divided = -1;
int[] fromleft_GCD = new int[N];
int[] fromright_GCD = new int[N];
fromleft_GCD[0] = A[0];
fromright_GCD[N - 1] = A[N - 1];
for (int i = 1; i < N; i++) {
fromleft_GCD[i] = gcd2(fromleft_GCD[i - 1], A[i]);
fromright_GCD[N - i - 1] = gcd2(fromright_GCD[N - i], A[N - i - 1]);
}
int max_gcd = Math.Max(fromleft_GCD[N - 2], fromright_GCD[1]);
for (int i = 0; i < N - 2; i++) {
var temp = gcd2(fromleft_GCD[i], fromright_GCD[i + 2]);
if (max_gcd < temp)
max_gcd = temp;
}
Console.WriteLine(max_gcd);
}
public static int[] prime_109() {
List<int> numbers = new List<int>();
for (int i = 2; i < 100000; i++) {
numbers.Add(i);
}
List<int> output = new List<int>();
while (numbers.Count != 0) {
int temp = numbers[0];
numbers.RemoveAt(0);
output.Add(temp);
var d = numbers.Where(x => x % temp != 0);
numbers = new List<int>(d);
}
return output.ToArray();
}
public static int gcd2(int a, int b) {
if (a % b == 0)
return b;
else
return gcd2(b, a % b);
}
}
|
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72]]
| 8
| 419
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
class ABC125C {
public static void Main() {
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
var S = new int[N - 1];
var R = new int[N - 1];
S[0] = A[0];
R[0] = A.Last();
for (int i = 1; i < N - 1; i++) {
S[i] = GCD(S[i - 1], A[i]);
R[i] = GCD(R[i - 1], A[N - (i + 1)]);
}
var list = new List<int>();
for (int i = 0; i < N - 2; i++) {
list.Add(GCD(S[i], R[N - (i + 3)]));
}
list.Add(GCD(S.Last(), A[N - 2]));
list.Add(GCD(R.Last(), A[1]));
Console.WriteLine(list.Max());
}
public static int GCD(int a, int b) {
if (b == 0) {
Console.WriteLine(a);
return a;
}
return GCD(b, a % b);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class ABC125C {
public static void Main() {
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
var S = new int[N - 1];
var R = new int[N - 1];
S[0] = A[0];
R[0] = A.Last();
for (int i = 1; i < N - 1; i++) {
S[i] = GCD(S[i - 1], A[i]);
R[i] = GCD(R[i - 1], A[N - (i + 1)]);
}
var list = new List<int>();
for (int i = 0; i < N - 2; i++) {
list.Add(GCD(S[i], R[N - (i + 3)]));
}
list.Add(GCD(S.Last(), A[N - 2]));
list.Add(GCD(R.Last(), A[1]));
Console.WriteLine(list.Max());
}
public static int GCD(int a, int b) {
if (b == 0) {
return a;
}
return GCD(b, a % b);
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 317
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProconTemplate {
class Doing {
public static void Main(string[] args) {
// Drop
Console.ReadLine();
var inputList =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
if (inputList.Length == 2) {
Console.WriteLine(inputList.Max());
return;
}
var duplicationList =
inputList.GroupBy(i => i)
.Select(g => new { number = g.Key, dupCount = g.Count() })
.ToList();
var alwaysGcd = -1;
if (duplicationList.Any(x => x.dupCount >= 2)) {
// 2回以上登場している数字は必ず使うので計算
alwaysGcd = Gcd(duplicationList.Where(x => x.dupCount >= 2)
.Select(x => x.number)
.ToArray());
}
if (alwaysGcd == 1) {
Console.WriteLine(alwaysGcd);
return;
} else if (!duplicationList.Any(x => x.dupCount == 1)) {
Console.WriteLine(alwaysGcd);
return;
}
// 1回のみの数字はスキップして計算する
var singleList = duplicationList.Where(x => x.dupCount == 1)
.Select(x => x.number)
.ToArray();
if (singleList.Length <= 1) {
Console.WriteLine(alwaysGcd);
return;
}
var maxInt = int.MinValue;
for (int skipIndex = 0; skipIndex < singleList.Length; skipIndex++) {
var gcdCache = 0;
if (alwaysGcd == -1) {
if (skipIndex == 0) {
gcdCache = singleList[1];
} else {
gcdCache = singleList[0];
}
} else {
gcdCache = alwaysGcd;
}
for (int useIndex = 0; useIndex < singleList.Length; useIndex++) {
if (gcdCache == 1) {
break;
} else if (useIndex == skipIndex) {
continue;
}
if (gcdCache > singleList[useIndex]) {
gcdCache = Gcd(gcdCache, singleList[useIndex]);
} else if (gcdCache < singleList[useIndex]) {
gcdCache = Gcd(singleList[useIndex], gcdCache);
}
}
maxInt = Math.Max(maxInt, gcdCache);
}
Console.WriteLine(maxInt);
}
public static int Gcd(int[] intArray) {
var gcdCache = 0;
if (intArray[0] > intArray[1]) {
gcdCache = Gcd(intArray[0], intArray[1]);
} else {
gcdCache = Gcd(intArray[1], intArray[0]);
}
for (int index = 2; index < intArray.Length; index++) {
if (gcdCache == 1) {
return 1;
}
if (gcdCache > intArray[index]) {
gcdCache = Gcd(gcdCache, intArray[index]);
} else if (gcdCache < intArray[index]) {
gcdCache = Gcd(intArray[index], gcdCache);
}
}
return gcdCache;
}
public static int Gcd(int a, int b) {
if (b <= 0) {
return a;
} else if (b == 1) {
return 1;
} else if (a == b) {
return a;
}
return Gcd(b, a % b);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProconTemplate {
class Doing {
public static void Main(string[] args) {
// Drop
Console.ReadLine();
var inputList =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
if (inputList.Length == 2) {
Console.WriteLine(inputList.Max());
return;
}
var duplicationList =
inputList.GroupBy(i => i)
.Select(g => new { number = g.Key, dupCount = g.Count() })
.ToList();
var alwaysGcd = -1;
if (duplicationList.Any(x => x.dupCount >= 2)) {
// 2回以上登場している数字は必ず使うので計算
alwaysGcd = Gcd(duplicationList.Where(x => x.dupCount >= 2)
.Select(x => x.number)
.ToArray());
}
if (alwaysGcd == 1) {
Console.WriteLine(alwaysGcd);
return;
} else if (!duplicationList.Any(x => x.dupCount == 1)) {
Console.WriteLine(alwaysGcd);
return;
}
// 1回のみの数字はスキップして計算する
var singleList = duplicationList.Where(x => x.dupCount == 1)
.Select(x => x.number)
.ToArray();
if (singleList.Length <= 1) {
Console.WriteLine(alwaysGcd);
return;
}
var maxInt = int.MinValue;
for (int skipIndex = 0; skipIndex < singleList.Length; skipIndex++) {
var gcdCache = 0;
if (alwaysGcd == -1) {
if (skipIndex == 0) {
gcdCache = singleList[1];
} else {
gcdCache = singleList[0];
}
} else {
gcdCache = alwaysGcd;
}
for (int useIndex = 0; useIndex < singleList.Length; useIndex++) {
if (gcdCache == 1) {
break;
} else if (useIndex == skipIndex) {
continue;
}
if (gcdCache > singleList[useIndex]) {
gcdCache = Gcd(gcdCache, singleList[useIndex]);
} else if (gcdCache < singleList[useIndex]) {
gcdCache = Gcd(singleList[useIndex], gcdCache);
}
}
maxInt = Math.Max(maxInt, gcdCache);
}
Console.WriteLine(maxInt);
}
public static int Gcd(int[] intArray) {
if (intArray.Length == 1) {
return intArray[0];
}
var gcdCache = 0;
if (intArray[0] > intArray[1]) {
gcdCache = Gcd(intArray[0], intArray[1]);
} else {
gcdCache = Gcd(intArray[1], intArray[0]);
}
for (int index = 2; index < intArray.Length; index++) {
if (gcdCache == 1) {
return 1;
}
if (gcdCache > intArray[index]) {
gcdCache = Gcd(gcdCache, intArray[index]);
} else if (gcdCache < intArray[index]) {
gcdCache = Gcd(intArray[index], gcdCache);
}
}
return gcdCache;
}
public static int Gcd(int a, int b) {
if (b <= 0) {
return a;
} else if (b == 1) {
return 1;
} else if (a == b) {
return a;
}
return Gcd(b, a % b);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 37, 0, 204, 205, 22], ["+", 64, 196, 0, 37, 0, 204, 206, 207, 0, 70], ["+", 0, 37, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 64, 196, 0, 37, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 665
| 16
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace D {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var n = int.Parse(Console.ReadLine());
var ai = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
var sum = 0L;
var min = (long)Math.Pow(10, 9);
var minIndex = 0;
var minusCount = 0;
for (var i = 0; i < ai.Length; i++) {
if (ai[i] < 0)
minusCount++;
ai[i] = Math.Abs(ai[i]);
if (ai[i] < min) {
minIndex = i;
}
sum += ai[i];
}
if (minusCount % 2 == 1)
sum -= 2 * ai[minIndex];
Console.WriteLine(sum);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace D {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var n = int.Parse(Console.ReadLine());
var ai = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
var sum = 0L;
var min = (long)Math.Pow(10, 9);
var minIndex = 0;
var minusCount = 0;
for (var i = 0; i < ai.Length; i++) {
if (ai[i] < 0)
minusCount++;
ai[i] = Math.Abs(ai[i]);
if (ai[i] < min) {
min = ai[i];
minIndex = i;
}
sum += ai[i];
}
if (minusCount % 2 == 1)
sum -= 2 * ai[minIndex];
Console.WriteLine(sum);
}
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 256
| 7
|
using System;
namespace Kyopuro {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int i;
int count;
string[] st = Console.ReadLine().Split(' ');
long ans = 0;
long[] num = new long[N];
for (i = 0; i < N; i++) {
num[i] = long.Parse(st[i]);
}
count = CountMinus(num, N);
Array.Sort(num);
for (i = 0; i < N; i++) {
num[i] = Math.Abs(long.Parse(st[i]));
}
if (ExistZero(num, N)) {
for (i = 0; i < N; i++) {
ans += Math.Abs(num[i]);
}
} else if (count == 1) {
ans = num[0] * -1;
for (i = 1; i < N; i++) {
ans += Math.Abs(num[i]);
}
} else {
for (i = 0; i < N; i++) {
ans += Math.Abs(num[i]);
}
}
Console.WriteLine(ans);
}
static int CountMinus(long[] numlist, int N) {
int count = 0;
int i;
for (i = 0; i < N; i++) {
if (numlist[i] < 0) {
count++;
}
}
return count % 2;
}
static bool ExistZero(long[] numlist, int N) {
bool isExist = false;
int i;
for (i = 0; i < N; i++) {
if (numlist[i] == 0) {
isExist = true;
}
}
return isExist;
}
}
}
|
using System;
namespace Kyopuro {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int i;
int count;
string[] st = Console.ReadLine().Split(' ');
long ans = 0;
long[] num = new long[N];
for (i = 0; i < N; i++) {
num[i] = long.Parse(st[i]);
}
count = CountMinus(num, N);
for (i = 0; i < N; i++) {
num[i] = Math.Abs(long.Parse(st[i]));
}
Array.Sort(num);
if (ExistZero(num, N)) {
for (i = 0; i < N; i++) {
ans += Math.Abs(num[i]);
}
} else if (count == 1) {
ans = num[0] * -1;
for (i = 1; i < N; i++) {
ans += Math.Abs(num[i]);
}
} else {
for (i = 0; i < N; i++) {
ans += Math.Abs(num[i]);
}
}
Console.WriteLine(ans);
}
static int CountMinus(long[] numlist, int N) {
int count = 0;
int i;
for (i = 0; i < N; i++) {
if (numlist[i] < 0) {
count++;
}
}
return count % 2;
}
static bool ExistZero(long[] numlist, int N) {
bool isExist = false;
int i;
for (i = 0; i < N; i++) {
if (numlist[i] == 0) {
isExist = true;
}
}
return isExist;
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 389
| 14
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Threading;
using System.Threading.Tasks;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
var A = cin.ReadLongArray(N);
var Ap = new List<long>();
var An = new List<long>();
foreach (var a in A) {
if (a > 0) {
Ap.Add(a);
} else {
An.Add(a);
}
}
var ans = 0L;
if (Ap.Count == 0) {
if (An.Count % 2 == 0) {
ans = -An.Sum();
} else {
ans = -An.Sum() + An.Max() * 2;
}
} else if (An.Count == 0) {
ans = Ap.Sum();
} else if (An.Count % 2 == 0) {
ans = Ap.Sum() - An.Sum();
} else {
if (Ap.Count > 0 && Ap.Min() + An.Max() < 0) {
Console.WriteLine("!");
ans = Ap.Sum() - An.Sum() - Ap.Min() * 2;
} else {
ans = Ap.Sum() - An.Sum() + An.Max() * 2;
}
}
Console.WriteLine(ans);
}
static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Threading;
using System.Threading.Tasks;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
var A = cin.ReadLongArray(N);
var Ap = new List<long>();
var An = new List<long>();
foreach (var a in A) {
if (a > 0) {
Ap.Add(a);
} else {
An.Add(a);
}
}
var ans = 0L;
if (Ap.Count == 0) {
if (An.Count % 2 == 0) {
ans = -An.Sum();
} else {
ans = -An.Sum() + An.Max() * 2;
}
} else if (An.Count == 0) {
ans = Ap.Sum();
} else if (An.Count % 2 == 0) {
ans = Ap.Sum() - An.Sum();
} else {
if (Ap.Count > 0 && Ap.Min() + An.Max() < 0) {
ans = Ap.Sum() - An.Sum() - Ap.Min() * 2;
} else {
ans = Ap.Sum() - An.Sum() + An.Max() * 2;
}
}
Console.WriteLine(ans);
}
static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 729
| 9
|
namespace AtCoder.ABC.D125 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.IO;
using AtCoder.ABC.IO;
public class Quest {
public object Solve(Parser parser) {
int n = parser.Integer();
long[] a = parser.Long(n);
long[][] v = new long [2][];
v[0] = new long[n + 1];
v[1] = new long[n + 1];
v[0][0] = 0;
v[1][0] = -10 ^ 15;
for (int i = 0; i < n; i++) {
v[0][i + 1] = Math.Max(v[0][i] + a[i], v[1][i] - a[i]);
v[1][i + 1] = Math.Max(v[0][i] - a[i], v[1][i] + a[i]);
}
return v[0][n];
}
}
static class Program {
static void Main(string[] args) {
var i = new Parser(Console.OpenStandardInput());
var o = new Printer(Console.OpenStandardOutput());
var got = new Quest().Solve(i);
o.WriteLine(got);
o.Flush();
}
}
}
namespace AtCoder.ABC.IO {
#region IO
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
public class Parser {
public Parser(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof;
public bool IsEndOfStream {
get { return isEof; }
}
public IEnumerable<Parser> Take(int n) {
return Enumerable.Range(1, n).Select(_ => this);
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture)
: double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
#endregion
}
|
namespace AtCoder.ABC.D125 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.IO;
using AtCoder.ABC.IO;
public class Quest {
public object Solve(Parser parser) {
int n = parser.Integer();
long[] a = parser.Long(n);
long[][] v = new long [2][];
v[0] = new long[n + 1];
v[1] = new long[n + 1];
v[0][0] = 0;
v[1][0] = (long)-Math.Pow(10, 15);
for (int i = 0; i < n; i++) {
v[0][i + 1] = Math.Max(v[0][i] + a[i], v[1][i] - a[i]);
v[1][i + 1] = Math.Max(v[0][i] - a[i], v[1][i] + a[i]);
}
return v[0][n];
}
}
static class Program {
static void Main(string[] args) {
var i = new Parser(Console.OpenStandardInput());
var o = new Printer(Console.OpenStandardOutput());
var got = new Quest().Solve(i);
o.WriteLine(got);
o.Flush();
}
}
}
namespace AtCoder.ABC.IO {
#region IO
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
public class Parser {
public Parser(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof;
public bool IsEndOfStream {
get { return isEof; }
}
public IEnumerable<Parser> Take(int n) {
return Enumerable.Range(1, n).Select(_ => this);
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture)
: double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
#endregion
}
|
[["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 12, 74, 51, 241, 0, 213, 63, 214, 205, 22], ["+", 12, 74, 51, 241, 0, 213, 63, 214, 0, 131], ["+", 12, 74, 51, 241, 0, 213, 63, 214, 141, 22], ["+", 12, 74, 51, 241, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 140], ["+", 12, 74, 51, 241, 0, 213, 3, 4, 0, 21], ["+", 12, 74, 51, 241, 0, 213, 3, 4, 0, 25]]
| 8
| 1,152
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
//入力
long N = long.Parse(Console.ReadLine());
List<long> A =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
long cnt = A.Count(value => value < 0);
List<long> B = A.ConvertAll(x => Math.Abs(x))
.FindAll(x => x > 0)
.OrderBy(x => x)
.ToList();
//回答となる数値
long ans = B.Sum();
//奇数の時
if (cnt % 2 == 1 && cnt == 0) {
ans -= 2 * B[0];
}
//出力
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) {
//入力
long N = long.Parse(Console.ReadLine());
List<long> A =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
long cnt = A.Count(value => value < 0);
int zeroCount = A.Count(value => value == 0);
List<long> B = A.ConvertAll(x => Math.Abs(x))
.FindAll(x => x > 0)
.OrderBy(x => x)
.ToList();
//回答となる数値
long ans = B.Sum();
//奇数の時
if (cnt % 2 == 1 && zeroCount == 0) {
ans -= 2 * B[0];
}
//出力
Console.WriteLine(ans);
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
| 8
| 188
| 16
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp2 {
public class Program {
public static void Main(string[] args) {
int N;
int[] listA;
N = Read(Console.ReadLine())[0];
int[] ansCollection = new int[N];
listA = Read(Console.ReadLine());
// find negative number
int[] data = Negative_Min(listA);
int negNum = data[0];
int min = data[1];
int ans = 0;
if (negNum % 2 == 0) {
foreach (var item in listA)
ans += Math.Abs(item);
} else {
foreach (var item in listA)
ans += Math.Abs(item);
ans -= 2 * min;
}
Console.WriteLine(ans);
}
public static int[] Negative_Min(int[] array) {
int neg = 0;
int min = Math.Abs(array[0]);
foreach (var num in array) {
if (num < 0)
neg++;
int ab = Math.Abs(num);
if (min > ab)
min = ab;
}
int[] ans = new int[2] { neg, min };
return ans;
}
private static int[] Read(string input) {
string[] inputs = input.Split(' ');
int num = inputs.Length;
int[] ints = new int[num];
for (int i = 0; i < num; i++) {
ints[i] = int.Parse(inputs[i]);
}
return ints;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleApp2 {
public class Program {
public static void Main(string[] args) {
long N;
long[] listA;
N = Read(Console.ReadLine())[0];
int[] ansCollection = new int[N];
listA = Read(Console.ReadLine());
// find negative number
long[] data = Negative_Min(listA);
long negNum = data[0];
long min = data[1];
long ans = 0;
if (negNum % 2 == 0) {
foreach (long item in listA)
ans += Math.Abs(item);
} else {
foreach (var item in listA)
ans += Math.Abs(item);
ans -= 2 * min;
}
Console.WriteLine(ans);
}
public static long[] Negative_Min(long[] array) {
int neg = 0;
long min = Math.Abs(array[0]);
foreach (var num in array) {
if (num < 0)
neg++;
long ab = Math.Abs(num);
if (min > ab)
min = ab;
}
long[] ans = new long[2] { neg, min };
return ans;
}
private static long[] Read(string input) {
string[] inputs = input.Split(' ');
long num = inputs.Length;
long[] ints = new long[num];
for (int i = 0; i < num; i++) {
ints[i] = long.Parse(inputs[i]);
}
return ints;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 57, 64, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 196, 0, 57, 64, 196, 0, 210, 39, 199], ["-", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["-", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["-", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
| 8
| 337
| 36
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] A = new long[N];
string[] input = Console.ReadLine().Split(' ');
long min = long.MaxValue;
long ans = 0;
for (long i = 0; i < N; i++) {
A[i] = long.Parse(input[i]);
if (min > Math.Abs(A[i])) {
min = Math.Abs(A[i]);
}
ans += Math.Abs(A[i]);
}
if (N % 2 == 1)
ans -= 2 * min;
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] A = new long[N];
string[] input = Console.ReadLine().Split(' ');
long min = long.MaxValue;
long ans = 0;
long minus = 0;
for (long i = 0; i < N; i++) {
A[i] = long.Parse(input[i]);
if (min > Math.Abs(A[i])) {
min = Math.Abs(A[i]);
}
if (A[i] < 0) {
minus++;
}
ans += Math.Abs(A[i]);
}
if (minus % 2 == 1)
ans -= 2 * min;
Console.WriteLine(ans);
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22]]
| 8
| 177
| 21
|
using System;
using static System.Console;
using System.Text;
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program {
public static int count = 0;
static void Main(string[] args) {
var alg = new cp();
var n = alg.inputLong();
// var s=inputString();
var arr = alg.inputSplitLong();
// var jug=inputJaggedArrayInt(n);
long minuscount = 0;
for (long a = 0; a < n; a++) {
arr[a] = Math.Abs(arr[a]);
}
Array.Sort(arr);
WriteLine(minuscount % 2 == 0 ? arr.Sum() : arr.Sum() - arr[0] * 2);
}
}
class cp {
public cp() {}
public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); }
public int LCM(int a, int b) { return a * b / GCD(a, b); }
public int countChar(string s, string key) {
return s.Length - s.Replace(key, "").Length;
}
public string YesNo(bool f, string type = null) {
string str;
if (f)
str = "Yes";
else
str = "No";
if (type == "lower")
return str.ToLower();
else if (type == "upper")
return str.ToUpper();
else
return str;
}
public void inputSkip() {
ReadLine();
return;
}
public string inputString() { return ReadLine(); }
public string[] inputSplitString() { return ReadLine().Split(); }
public string[] inputLinesString(int len) {
var arr = new string[len];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine();
}
return arr;
}
public string[][] inputJaggedArrayString(int len) {
var arr = new string[len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split();
}
return arr;
}
public int inputInt() { return int.Parse(ReadLine()); }
public int[] inputSplitInt() {
return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
public int[] inputLinesInt(int len) {
var arr = new int[len];
for (int a = 0; a < len; a++) {
arr[a] = int.Parse(ReadLine());
}
return arr;
}
public int[][] inputJaggedArrayInt(int len) {
var arr = new int [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
return arr;
}
public long inputLong() { return long.Parse(ReadLine()); }
public long[] inputSplitLong() {
return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
public long[] inputLinesLong(int len) {
var arr = new long[len];
for (int a = 0; a < len; a++) {
arr[a] = long.Parse(ReadLine());
}
return arr;
}
public long[][] inputJaggedArrayLong(int len) {
var arr = new long [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
return arr;
}
public double inputDouble() { return double.Parse(ReadLine()); }
public double[] inputSplitDouble() {
return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
public double[] inputLinesDouble(int len) {
var arr = new double[len];
for (int a = 0; a < len; a++) {
arr[a] = double.Parse(ReadLine());
}
return arr;
}
public double[][] inputJaggedArrayDouble(int len) {
var arr = new double [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
return arr;
}
}
|
using System;
using static System.Console;
using System.Text;
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program {
public static int count = 0;
static void Main(string[] args) {
var alg = new cp();
var n = alg.inputLong();
// var s=inputString();
var arr = alg.inputSplitLong();
// var jug=inputJaggedArrayInt(n);
long minuscount = 0;
for (long a = 0; a < n; a++) {
if (arr[a] < 0)
minuscount++;
arr[a] = Math.Abs(arr[a]);
}
Array.Sort(arr);
WriteLine(minuscount % 2 == 0 ? arr.Sum() : arr.Sum() - arr[0] * 2);
}
}
class cp {
public cp() {}
public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); }
public int LCM(int a, int b) { return a * b / GCD(a, b); }
public int countChar(string s, string key) {
return s.Length - s.Replace(key, "").Length;
}
public string YesNo(bool f, string type = null) {
string str;
if (f)
str = "Yes";
else
str = "No";
if (type == "lower")
return str.ToLower();
else if (type == "upper")
return str.ToUpper();
else
return str;
}
public void inputSkip() {
ReadLine();
return;
}
public string inputString() { return ReadLine(); }
public string[] inputSplitString() { return ReadLine().Split(); }
public string[] inputLinesString(int len) {
var arr = new string[len];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine();
}
return arr;
}
public string[][] inputJaggedArrayString(int len) {
var arr = new string[len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split();
}
return arr;
}
public int inputInt() { return int.Parse(ReadLine()); }
public int[] inputSplitInt() {
return ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
public int[] inputLinesInt(int len) {
var arr = new int[len];
for (int a = 0; a < len; a++) {
arr[a] = int.Parse(ReadLine());
}
return arr;
}
public int[][] inputJaggedArrayInt(int len) {
var arr = new int [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray();
}
return arr;
}
public long inputLong() { return long.Parse(ReadLine()); }
public long[] inputSplitLong() {
return ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
public long[] inputLinesLong(int len) {
var arr = new long[len];
for (int a = 0; a < len; a++) {
arr[a] = long.Parse(ReadLine());
}
return arr;
}
public long[][] inputJaggedArrayLong(int len) {
var arr = new long [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray();
}
return arr;
}
public double inputDouble() { return double.Parse(ReadLine()); }
public double[] inputSplitDouble() {
return ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
public double[] inputLinesDouble(int len) {
var arr = new double[len];
for (int a = 0; a < len; a++) {
arr[a] = double.Parse(ReadLine());
}
return arr;
}
public double[][] inputJaggedArrayDouble(int len) {
var arr = new double [len][];
for (int a = 0; a < len; a++) {
arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray();
}
return arr;
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 1,007
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
long[] A = cin.ArrayLong(N, 0);
long[] newA0 = new long[N];
long[] newA1 = new long[N];
long ans = 0;
int i = 0;
long min = 999999999;
for (i = 0; i < N; i++) {
if (A[i] < 0)
A[i] = (-1) * A[i];
ans += A[i];
if (A[i] < min && A[i] != 0)
min = A[i];
}
Console.WriteLine(ans - min * 2);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
long[] A = cin.ArrayLong(N, 0);
long[] newA0 = new long[N];
long[] newA1 = new long[N];
long ans = 0;
int i = 0;
long min = 10000000000;
int count = 0;
for (i = 0; i < N; i++) {
if (A[i] < 0) {
A[i] = (-1) * A[i];
count++;
}
ans += A[i];
if (A[i] < min)
min = A[i];
}
if (count % 2 != 0)
ans -= min * 2;
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;
}
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 611
| 37
|
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 A = ReadLongs();
var minusCount = A.Where(a => a < 0).Count();
if (isEven(minusCount) || A.Any(a => a == 0)) {
Print(A.Select(a => Abs(a)).Sum());
} else {
Print(A.Select(a => Abs(a)).OrderBy(x => x).Skip(1).Sum());
}
}
}
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 A = ReadLongs();
var minusCount = A.Where(a => a < 0).Count();
if (isEven(minusCount) || A.Any(a => a == 0)) {
Print(A.Select(a => Abs(a)).Sum());
} else {
var B = A.Select(a => Abs(a)).OrderBy(x => x);
Print(B.Skip(1).Sum() - B.First());
}
}
}
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);
}
}
}
|
[["-", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22]]
| 8
| 1,843
| 15
|
using System;
using System.Linq;
namespace abc125 {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var anums =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
var plusNum = 0;
var zeroNum = 0;
var minusNum = 0;
long absTotal = 0;
long absMin = long.MaxValue;
foreach (var a in anums) {
var abs = Math.Abs(a);
absTotal += abs;
absMin = Math.Min(abs, absMin);
if (a > 0) {
plusNum++;
} else if (a < 0) {
minusNum++;
} else {
zeroNum++;
}
}
var output = absTotal;
if (zeroNum == 0 && Math.Abs(plusNum - minusNum) % 2 == 1) {
output -= 2 * absMin;
}
Console.WriteLine(output);
}
}
}
|
using System;
using System.Linq;
namespace abc125 {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var anums =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
var plusNum = 0;
var zeroNum = 0;
var minusNum = 0;
long absTotal = 0;
long absMin = long.MaxValue;
foreach (var a in anums) {
var abs = Math.Abs(a);
absTotal += abs;
absMin = Math.Min(abs, absMin);
if (a > 0) {
plusNum++;
} else if (a < 0) {
minusNum++;
} else {
zeroNum++;
}
}
var output = absTotal;
if (zeroNum == 0 && minusNum % 2 == 1) {
output -= 2 * absMin;
}
Console.WriteLine(output);
}
}
}
|
[["-", 12, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["-", 12, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["-", 12, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["-", 12, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 12, 16, 31, 16, 31, 213, 3, 4, 0, 25]]
| 8
| 202
| 7
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Hello {
static public int mod = 1000000007;
public static void Main() {
// 方針
// なし
int[] num = inta();
if (num[0] < num[2] && num[2] < num[1]) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
// static int square2(long a,long b,long m){var list = new List<int>();int
// temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp <
// b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b >
// 0){if(temp <= b){b -= temp;ret =
// ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Hello {
static public int mod = 1000000007;
public static void Main() {
// 方針
// なし
int[] num = inta();
if (num[0] < num[2] && num[2] < num[1] ||
num[1] < num[2] && num[2] < num[0]) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
// static int square2(long a,long b,long m){var list = new List<int>();int
// temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp <
// b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b >
// 0){if(temp <= b){b -= temp;ret =
// ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 18], ["+", 15, 16, 12, 16, 31, 16, 12, 204, 205, 22], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 98], ["+", 15, 16, 12, 16, 12, 16, 31, 204, 205, 22], ["+", 12, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 18], ["+", 15, 16, 12, 16, 12, 16, 12, 204, 205, 22], ["+", 12, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 828
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tenka1_PBC_2019 {
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 = int.Parse(word[2]);
if (a <= c && b >= c)
Console.WriteLine("Yes");
else {
Console.WriteLine("No");
}
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tenka1_PBC_2019 {
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 = int.Parse(word[2]);
if (a <= c && b >= c)
Console.WriteLine("Yes");
else if (a >= c && b <= c)
Console.WriteLine("Yes");
else {
Console.WriteLine("No");
}
Console.ReadKey();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 20], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
| 8
| 142
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var nk = CinTAr();
if (nk[0] <= nk[2] && nk[1] >= nk[2]) {
Cout("Yes");
} else {
Cout("No");
}
Cin();
}
static int loop(int num, int max) {
if (num > max) {
return 0;
} else if (num < 0) {
return max;
} else {
return num;
}
}
static int GCD(int a, int b) {
if (a < b) {
swap(ref a, ref b);
}
if (a % b == 0) {
return b;
} else {
return GCD(b, a % b);
}
}
static void swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static readonly int MOD10E9 = (1000000000 + 7);
static bool isInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static int[] yakusuu(int n) {
if (n == 1) {
return new int[] { 1 };
}
HashSet<int> res = new HashSet<int>();
for (int i = 1; i < Math.Ceiling(n / 2.0); i++) {
if (n % i == 0) {
res.Add(i);
res.Add(n / i);
}
}
return res.ToArray();
}
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = string.Join(" ", types);
WriteLine(text);
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;
namespace AtCoder_1 {
class Program {
static void Main(string[] args) {
var nk = CinTAr();
if (nk[0] > nk[1]) {
swap(ref nk[1], ref nk[0]);
}
if (nk[0] <= nk[2] && nk[1] >= nk[2]) {
Cout("Yes");
} else {
Cout("No");
}
Cin();
}
static int loop(int num, int max) {
if (num > max) {
return 0;
} else if (num < 0) {
return max;
} else {
return num;
}
}
static int GCD(int a, int b) {
if (a < b) {
swap(ref a, ref b);
}
if (a % b == 0) {
return b;
} else {
return GCD(b, a % b);
}
}
static void swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static readonly int MOD10E9 = (1000000000 + 7);
static bool isInt(double d) { return (int)d == d; }
static string Cin() { return ReadLine(); }
static string[] CinAr() { return ReadLine().Split(' '); }
static int CinT() { return S2i(Cin()); }
static int[] CinTAr() {
return CinAr().Select((x, i) => { return S2i(x); }).ToArray();
}
static long CinL() { return S2L(Cin()); }
static long[] CinLAr() {
return CinAr().Select((x, i) => { return S2L(x); }).ToArray();
}
static double CinD() { return S2D(Cin()); }
static double[] CinDAr() {
return CinAr().Select((x, i) => { return S2D(x); }).ToArray();
}
static int S2i(string s) { return int.Parse(s); }
static long S2L(string s) { return long.Parse(s); }
static double S2D(string s) { return double.Parse(s); }
static void Cout(object s) { WriteLine(s); }
static int[] yakusuu(int n) {
if (n == 1) {
return new int[] { 1 };
}
HashSet<int> res = new HashSet<int>();
for (int i = 1; i < Math.Ceiling(n / 2.0); i++) {
if (n % i == 0) {
res.Add(i);
res.Add(n / i);
}
}
return res.ToArray();
}
static void CoutAr<Type>(IEnumerable<Type> types) {
string text = string.Join(" ", types);
WriteLine(text);
}
public static long nCr(int n, int r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(int n, int r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(int topFactorial,
int divisorFactorial) {
long result = 1;
for (int i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 275], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73]]
| 8
| 767
| 29
|
using System;
namespace Project {
class Mains {
public static void Main(string[] args) {
int a = int.Parse(args[0]);
int b = int.Parse(args[1]);
int c = int.Parse(args[2]);
Console.WriteLine((a < c && c < b) || (b < c && c < a) ? "Yes" : "No");
}
}
}
|
using System;
namespace Project {
class Mains {
public static void Main() {
string[] args = Console.ReadLine().Split(' ');
int a = int.Parse(args[0]);
int b = int.Parse(args[1]);
int c = int.Parse(args[2]);
Console.WriteLine((a < c && c < b) || (b < c && c < a) ? "Yes" : "No");
}
}
}
|
[["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
| 8
| 95
| 16
|
using System;
using System.Linq;
namespace OTW {
class P {
private string Read() { return Console.ReadLine(); }
private int[] ReadArray() {
return Read().Split().Select(int.Parse).ToArray();
}
private void S() {
var abc = Read();
var array = abc.Split().Select(int.Parse).ToArray();
var a = array[0];
var b = array[1];
var c = array[2];
if (a < b || b < c) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
static void Main(string[] args) { new P().S(); }
}
}
|
using System;
using System.Linq;
namespace OTW {
class P {
private string Read() { return Console.ReadLine(); }
private int[] ReadArray() {
return Read().Split().Select(int.Parse).ToArray();
}
private void S() {
var abc = Read();
var array = abc.Split().Select(int.Parse).ToArray();
var a = array[0];
var b = array[1];
var c = array[2];
if ((c < b && c < a) || (c > b && c > a)) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
}
}
static void Main(string[] args) { new P().S(); }
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 98], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 17, 18], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 47], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 170
| 20
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Main {
public static class Program {
public static List<int> list = new List<int>();
static void Main(string[] arg) {
var input = GetIntList(Console.ReadLine());
var answer = "";
int a = input[1] - input[0];
int cmod = a % input[2];
answer = 0 == cmod ? "Yes" : "No";
if (Math.Min(input[0], input[1]) > input[2]) {
answer = "No";
} else if (Math.Max(input[0], input[1]) < input[2]) {
answer = "No";
}
Console.WriteLine(answer);
Console.ReadLine();
}
#region libraries
private static int[] GetIntList(string line) {
return line.Split(' ').Select(x => int.Parse(x)).ToArray();
}
private static double[] GetDoubleList(string line) {
return line.Split(' ').Select(x => double.Parse(x)).ToArray();
}
private static ulong[] GetUlongList(string line) {
return line.Split(' ').Select(x => ulong.Parse(x)).ToArray();
}
private static long[] GetLongList(string line) {
return line.Split(' ').Select(x => long.Parse(x)).ToArray();
}
private static int SearchNearest(this IEnumerable<int> list, int target) {
var min = list.Min(c => Math.Abs(c - target));
return list.First(c => Math.Abs(c - target) == min);
}
public static bool IsOdd(int i) { return i % 2 == 1 ? true : false; }
public static int Gcd(int a, int b) {
if (a < b) {
Gcd(b, a);
}
while (b != 0) {
var rm = a % b;
a = b;
b = rm;
}
return a;
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Main {
public static class Program {
public static List<int> list = new List<int>();
static void Main(string[] arg) {
var input = GetIntList(Console.ReadLine());
var answer = "Yes";
int a = Math.Abs(input[1] - input[0]);
if (Math.Min(input[0], input[1]) > input[2]) {
answer = "No";
} else if (Math.Max(input[0], input[1]) < input[2]) {
answer = "No";
}
// else{
// int cmod = Math.Max(a,input[2]) % Math.Min(a,input[2]);
// answer = 0==cmod?"Yes":"No";
// }
Console.WriteLine(answer);
Console.ReadLine();
}
#region libraries
private static int[] GetIntList(string line) {
return line.Split(' ').Select(x => int.Parse(x)).ToArray();
}
private static double[] GetDoubleList(string line) {
return line.Split(' ').Select(x => double.Parse(x)).ToArray();
}
private static ulong[] GetUlongList(string line) {
return line.Split(' ').Select(x => ulong.Parse(x)).ToArray();
}
private static long[] GetLongList(string line) {
return line.Split(' ').Select(x => long.Parse(x)).ToArray();
}
private static int SearchNearest(this IEnumerable<int> list, int target) {
var min = list.Min(c => Math.Abs(c - target));
return list.First(c => Math.Abs(c - target) == min);
}
public static bool IsOdd(int i) { return i % 2 == 1 ? true : false; }
public static int Gcd(int a, int b) {
if (a < b) {
Gcd(b, a);
}
while (b != 0) {
var rm = a % b;
a = b;
b = rm;
}
return a;
}
#endregion
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 41, 15, 16, 31, 203], ["-", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["-", 0, 1, 0, 11, 12, 41, 15, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["-", 0, 1, 0, 11, 12, 41, 64, 5, 0, 62], ["-", 0, 1, 0, 11, 12, 41, 64, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["-", 0, 1, 0, 11, 12, 41, 75, 5, 0, 62], ["-", 0, 1, 0, 11, 12, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 485
| 30
|
using System;
using System.Linq;
namespace TBCA {
class Program {
static void Main(string[] args) {
var line = Console.ReadLine().Split(' ').ToArray();
var A = int.Parse(line[0]);
var B = int.Parse(line[1]);
var C = int.Parse(line[2]);
if (C > A && C < B) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Linq;
namespace TBCA {
class Program {
static void Main(string[] args) {
var line = Console.ReadLine().Split(' ').ToArray();
var A = int.Parse(line[0]);
var B = int.Parse(line[1]);
var C = int.Parse(line[2]);
if (C > A && C < B) {
Console.WriteLine("Yes");
} else if (A > C && B < C) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 47], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
| 8
| 119
| 22
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
char[] cs = new char[] { ' ' };
// char[] cs = new char[] { ' ', ',' };
// int val = int.Parse(Console.ReadLine());
// int[] vals = parseAry(Console.ReadLine().Split(cs));
// string str = Console.ReadLine();
// string[] strs = Console.ReadLine().Split(cs);
// string res="";
// int res = 0; ;
// int t = int.Parse(Console.ReadLine());
// string str = Console.ReadLine();
// int[] vals = parseAry(Console.ReadLine().Split(cs));
// int n = int.Parse(Console.ReadLine());
// string res="";
string res = "No";
int[] vals = parseAry(Console.ReadLine().Split(cs));
if (vals[0] < vals[2] && vals[2] < vals[1]) {
res = "Yes";
}
Console.WriteLine(res);
return;
}
// String[] -----> int[]
static int[] parseAry(string[] str) {
int[] nums = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = int.Parse(str[i]);
}
return nums;
}
// String[] -----> long[]
static long[] parseAryL(string[] str) {
long[] nums = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = long.Parse(str[i]);
}
return nums;
}
//文字列を1文字ずつString[]に入れる
static string[] strAry(String str) {
string[] re = new string[str.Length];
for (int i = 0; i < str.Length; i++) {
re[i] = str[i].ToString();
}
return re;
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
char[] cs = new char[] { ' ' };
// char[] cs = new char[] { ' ', ',' };
// int val = int.Parse(Console.ReadLine());
// int[] vals = parseAry(Console.ReadLine().Split(cs));
// string str = Console.ReadLine();
// string[] strs = Console.ReadLine().Split(cs);
// string res="";
// int res = 0; ;
// int t = int.Parse(Console.ReadLine());
// string str = Console.ReadLine();
// int[] vals = parseAry(Console.ReadLine().Split(cs));
// int n = int.Parse(Console.ReadLine());
// string res="";
string res = "No";
int[] vals = parseAry(Console.ReadLine().Split(cs));
if (vals[0] < vals[2] && vals[2] < vals[1]) {
res = "Yes";
}
if (vals[0] > vals[2] && vals[2] > vals[1]) {
res = "Yes";
}
Console.WriteLine(res);
return;
}
// String[] -----> int[]
static int[] parseAry(string[] str) {
int[] nums = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = int.Parse(str[i]);
}
return nums;
}
// String[] -----> long[]
static long[] parseAryL(string[] str) {
long[] nums = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
nums[i] = long.Parse(str[i]);
}
return nums;
}
//文字列を1文字ずつString[]に入れる
static string[] strAry(String str) {
string[] re = new string[str.Length];
for (int i = 0; i < str.Length; i++) {
re[i] = str[i].ToString();
}
return re;
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 318
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
if (args.Length > 0 && args[0] == "debug") {
var inputs = new[] { @"
3 8 5
",
@"
7 3 1
",
@"
10 2 4
",
@"
31 41 59
" };
foreach (var str in inputs) {
var text = str.Trim();
if (text.Length == 0)
continue;
var reader = new System.IO.StringReader(text);
Console.SetIn(reader);
Main2(args);
Console.WriteLine();
Console.WriteLine("----------------------------------");
Console.WriteLine();
}
} else
Main2(args);
}
public static void Main2(string[] args) {
checked {
var list = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
var a = (list[0]);
var b = (list[1]);
var c = (list[2]);
if (a < b) {
Console.WriteLine(b > c ? "Yes" : "No");
} else {
Console.WriteLine(b < c ? "Yes" : "No");
}
}
}
}
public static class EnumerablePlus {
///< summary>出力文字列に変換。</summary>
public static string MkString<T>(this IEnumerable<T> list) {
return list
.Aggregate(new System.Text.StringBuilder(),
(a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b))
.ToString();
}
///< summary>添字付きfor。</summary>
public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a) {
int i = 0;
foreach (var item in list) {
a(item, i);
}
}
///< summary>指定回数デリゲートを呼び出す。</summary>
public static IEnumerable<T> Repeat<T>(int n, Func<T> f) {
for (int i = 0; i < n; i++) {
yield return f();
}
}
}
public static class MathPlus {
///< summary>約数。順番は不定。</summary>
public static List<long> Divisor(long n) {
var list =
Prime(n)
.GroupBy(id => id)
.Select(pair => new { prime = pair.Key, power = pair.Count() })
.ToList();
var result = list.Aggregate(new List<long>(), (left, pair) => {
var list2 = Enumerable.Range(0, pair.power + 1)
.Aggregate(new List<long>(), (res, l) => {
var next = res.Count > 0 ? res.Last() * pair.prime : 1L;
res.Add(next);
return res;
});
if (left.Count == 0)
return list2.ToList();
return list2.SelectMany(l => left.Select(m => l * m)).ToList();
});
return result;
}
///< summary>順列の数。</summary>
public static long Permutation(long n, long r) => Factorial(n, r);
///< summary>組合せの数。</summary>
public static long Combination(long n, long r) {
if (r == 0)
return 1;
return Factorial(n, r) / Factorial(r);
}
///< summary>階乗。カウントも指定可能。</summary>
public static long Factorial(long a, long count = long.MaxValue) {
long res = 1;
for (long i = 0; a > 0 && i < count; i++) {
checked { res *= a; }
--a;
}
return res;
}
///< summary>素因数分解。昇順。</summary>
public static List<long> Prime(long a) {
var res = new List<long>();
for (long b = 2, c = (long)Math.Ceiling(Math.Sqrt(a)); b <= c; ++b) {
while (a % b == 0) {
res.Add(b);
a = a / b;
}
}
return res;
}
///< summary>最小公倍数。</summary>
public static long Lcm(IEnumerable<long> list) {
return list.Aggregate((a, b) => Lcm(a, b));
}
///< summary>最小公倍数。</summary>
public static long Lcm(long a, long b) { return checked(a * b) / Gcd(a, b); }
///< summary>最大公約数。</summary>
public static long Gcd(IEnumerable<long> list) {
return list.Aggregate((a, b) => Gcd(a, b));
}
///< summary>最大公約数。</summary>
public static long Gcd(long a, long b) {
if (a < b)
Gcd(b, a);
while (b != 0) {
var rem = a % b;
a = b;
b = rem;
}
return a;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
if (args.Length > 0 && args[0] == "debug") {
var inputs = new[] { @"
3 8 5
",
@"
7 3 1
",
@"
10 2 4
",
@"
31 41 59
" };
foreach (var str in inputs) {
var text = str.Trim();
if (text.Length == 0)
continue;
var reader = new System.IO.StringReader(text);
Console.SetIn(reader);
Main2(args);
Console.WriteLine();
Console.WriteLine("----------------------------------");
Console.WriteLine();
}
} else
Main2(args);
}
public static void Main2(string[] args) {
checked {
var list = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
var a = (list[0]);
var b = (list[1]);
var c = (list[2]);
if (a < b) {
Console.WriteLine((a < c && b > c) ? "Yes" : "No");
} else {
Console.WriteLine((a > c && b < c) ? "Yes" : "No");
}
}
}
}
public static class EnumerablePlus {
///< summary>出力文字列に変換。</summary>
public static string MkString<T>(this IEnumerable<T> list) {
return list
.Aggregate(new System.Text.StringBuilder(),
(a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b))
.ToString();
}
///< summary>添字付きfor。</summary>
public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a) {
int i = 0;
foreach (var item in list) {
a(item, i);
}
}
///< summary>指定回数デリゲートを呼び出す。</summary>
public static IEnumerable<T> Repeat<T>(int n, Func<T> f) {
for (int i = 0; i < n; i++) {
yield return f();
}
}
}
public static class MathPlus {
///< summary>約数。順番は不定。</summary>
public static List<long> Divisor(long n) {
var list =
Prime(n)
.GroupBy(id => id)
.Select(pair => new { prime = pair.Key, power = pair.Count() })
.ToList();
var result = list.Aggregate(new List<long>(), (left, pair) => {
var list2 = Enumerable.Range(0, pair.power + 1)
.Aggregate(new List<long>(), (res, l) => {
var next = res.Count > 0 ? res.Last() * pair.prime : 1L;
res.Add(next);
return res;
});
if (left.Count == 0)
return list2.ToList();
return list2.SelectMany(l => left.Select(m => l * m)).ToList();
});
return result;
}
///< summary>順列の数。</summary>
public static long Permutation(long n, long r) => Factorial(n, r);
///< summary>組合せの数。</summary>
public static long Combination(long n, long r) {
if (r == 0)
return 1;
return Factorial(n, r) / Factorial(r);
}
///< summary>階乗。カウントも指定可能。</summary>
public static long Factorial(long a, long count = long.MaxValue) {
long res = 1;
for (long i = 0; a > 0 && i < count; i++) {
checked { res *= a; }
--a;
}
return res;
}
///< summary>素因数分解。昇順。</summary>
public static List<long> Prime(long a) {
var res = new List<long>();
for (long b = 2, c = (long)Math.Ceiling(Math.Sqrt(a)); b <= c; ++b) {
while (a % b == 0) {
res.Add(b);
a = a / b;
}
}
return res;
}
///< summary>最小公倍数。</summary>
public static long Lcm(IEnumerable<long> list) {
return list.Aggregate((a, b) => Lcm(a, b));
}
///< summary>最小公倍数。</summary>
public static long Lcm(long a, long b) { return checked(a * b) / Gcd(a, b); }
///< summary>最大公約数。</summary>
public static long Gcd(IEnumerable<long> list) {
return list.Aggregate((a, b) => Gcd(a, b));
}
///< summary>最大公約数。</summary>
public static long Gcd(long a, long b) {
if (a < b)
Gcd(b, a);
while (b != 0) {
var rem = a % b;
a = b;
b = rem;
}
return a;
}
}
}
|
[["+", 3, 4, 0, 28, 0, 41, 15, 23, 0, 24], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 18], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 28, 0, 41, 15, 23, 0, 16, 17, 98], ["+", 3, 4, 0, 28, 0, 41, 15, 23, 0, 25], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 47]]
| 8
| 971
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long r = sc.NextLong();
long g = sc.NextLong();
long b = sc.NextLong();
long n = sc.NextLong();
long answer = 0;
for (int i = 0; i <= r; i++) {
for (int j = 0; j <= g; j++) {
if (i + j > n) {
break;
}
if (n - i - j <= b) {
answer++;
}
}
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long r = sc.NextLong();
long g = sc.NextLong();
long b = sc.NextLong();
long n = sc.NextLong();
long answer = 0;
for (int i = 0; i * r <= n; i++) {
for (int j = 0; j * g <= n; j++) {
if (i * r + j * g > n) {
break;
}
long mod = n - i * r - j * g;
if (mod % b == 0) {
answer++;
}
}
}
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, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 212, 0, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 212, 0, 16, 31, 16, 12, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 441
| 29
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
string[] cin = Console.ReadLine().Split();
int a = int.Parse(cin[0]);
int b = int.Parse(cin[1]);
int c = int.Parse(cin[2]);
if (a < c && c < b)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
string[] cin = Console.ReadLine().Split();
int a = int.Parse(cin[0]);
int b = int.Parse(cin[1]);
int c = int.Parse(cin[2]);
if (a < c && c < b)
Console.WriteLine("Yes");
else if (b < c && c < a)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
| 8
| 118
| 20
|
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) {
string[] str = Console.ReadLine().Split(' ');
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
int c = int.Parse(str[2]);
Console.WriteLine(a < c && c < b ? "Yes" : "No");
}
}
}
|
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) {
string[] str = Console.ReadLine().Split(' ');
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
int c = int.Parse(str[2]);
if (a > b) {
int t = a;
a = b;
b = t;
}
Console.WriteLine(a < c && c < b ? "Yes" : "No");
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 124
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
//入力
string s = Console.ReadLine();
int A = int.Parse(s.Split(' ')[0]);
int B = int.Parse(s.Split(' ')[1]);
int C = int.Parse(s.Split(' ')[2]);
//計算
if (A < C && C < B) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
//出力
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
//入力
string s = Console.ReadLine();
int A = int.Parse(s.Split(' ')[0]);
int B = int.Parse(s.Split(' ')[1]);
int C = int.Parse(s.Split(' ')[2]);
//計算
if (A < C && C < B) {
Console.WriteLine("Yes");
} else if (B < C && C < A) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
//出力
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
| 8
| 147
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { new Program().Solve(); }
void Solve() {
Scanner cin = new Scanner();
int R = cin.NextInt();
int G = cin.NextInt();
int B = cin.NextInt();
int N = cin.NextInt();
int MAX = 3000;
int count = 0;
for (int r = 0; r < MAX; r++) {
for (int g = 0; g < MAX; g++) {
int residual = N - R * r - G * g;
if (residual % B == 0) {
count++;
}
}
}
Console.WriteLine(count);
}
}
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 char[] ArrayChar() { return Next().ToCharArray(); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = NextInt() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { new Program().Solve(); }
void Solve() {
Scanner cin = new Scanner();
int R = cin.NextInt();
int G = cin.NextInt();
int B = cin.NextInt();
int N = cin.NextInt();
int MAX = 3000;
int count = 0;
for (int r = 0; r <= MAX; r++) {
for (int g = 0; g <= MAX; g++) {
int residual = N - R * r - G * g;
if (residual < 0) {
break;
}
if (residual % B == 0) {
count++;
}
}
}
Console.WriteLine(count);
}
}
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 char[] ArrayChar() { return Next().ToCharArray(); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = NextInt() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 544
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B {
class Program {
static void Main(string[] args) {
string[] V = Console.ReadLine().Split(' ');
int R = int.Parse(V[0]);
int G = int.Parse(V[1]);
int B = int.Parse(V[2]);
int N = int.Parse(V[3]);
int count = 0;
int g = 0;
int r = 0;
int b = 0;
for (r = 0; r * R <= N; r++) {
for (g = 0; g * G + r * R <= N; g++) {
for (b = 0; b * B + g * G + r * R == N; b++) {
count++;
}
}
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B {
class Program {
static void Main(string[] args) {
string[] V = Console.ReadLine().Split(' ');
int R = int.Parse(V[0]);
int G = int.Parse(V[1]);
int B = int.Parse(V[2]);
int N = int.Parse(V[3]);
int count = 0;
int g = 0;
int r = 0;
for (r = 0; r * R <= N; r++) {
for (g = 0; g * G + r * R <= N; g++) {
if ((N - g * G - r * R) % B == 0 || N == g * G + r * R)
count++;
}
}
Console.WriteLine(count);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 0, 7, 8, 196, 0, 7, 10, 11, 31, 22], ["-", 8, 196, 0, 7, 10, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 196, 0, 7, 10, 11, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 17, 48], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 12, 22], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["-", 0, 7, 15, 16, 31, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 209
| 36
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var RGBN = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
var R = RGBN[0];
var G = RGBN[1];
var B = RGBN[2];
var N = RGBN[3];
int cnt = 0;
for (int i = 0; i <= N / R; i++) {
if (R * i == N) {
cnt += 1;
break;
}
for (int j = 0; j <= N / G; j++) {
if (R * i + G * j == N) {
cnt += 1;
break;
}
if ((N - (R * i + G * j)) % B == 0) {
cnt += 1;
}
}
}
Console.WriteLine(cnt);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var RGBN = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
var R = RGBN[0];
var G = RGBN[1];
var B = RGBN[2];
var N = RGBN[3];
int cnt = 0;
for (int i = 0; i <= N / R; i++) {
if (R * i == N) {
cnt += 1;
break;
}
for (int j = 0; j <= N / G; j++) {
// if(R*i+G*j==N){cnt+=1;break;}
if (((N - (R * i + G * j)) % B == 0) &&
((N - (R * i + G * j)) / B >= 0)) {
// Console.WriteLine("{0} {1} {2}",i,j,(N-(R*i+G*j))/B);
cnt += 1;
}
}
}
Console.WriteLine(cnt);
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 85], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 201
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
//入力
string s = Console.ReadLine();
int R = int.Parse(s.Split(' ')[0]);
int G = int.Parse(s.Split(' ')[1]);
int B = int.Parse(s.Split(' ')[2]);
int N = int.Parse(s.Split(' ')[3]);
//解答となる数値
int ans = 0;
//検証
int rMax = N / R;
int gMax = N / G;
int bMax = N / B;
for (int r = rMax; r >= 0; r--) {
for (int g = gMax; g >= 0; g--) {
if ((N - (R * r + G * g)) % B == 0) {
ans++;
}
}
}
//出力
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
//入力
string s = Console.ReadLine();
int R = int.Parse(s.Split(' ')[0]);
int G = int.Parse(s.Split(' ')[1]);
int B = int.Parse(s.Split(' ')[2]);
int N = int.Parse(s.Split(' ')[3]);
//解答となる数値
int ans = 0;
//検証
int rMax = N / R;
int gMax = N / G;
int bMax = N / B;
for (int r = rMax; r >= 0; r--) {
for (int g = gMax; g >= 0; g--) {
if ((N - (R * r + G * g)) % B == 0 && (N - (R * r + G * g)) >= 0) {
ans++;
}
}
}
//出力
Console.WriteLine(ans);
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 17, 48], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
| 8
| 225
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
class Pair : IComparable {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
public static List<Pair>[
,
] pairs;
public static int[,] ans;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
int n = scan.Integer();
long sum = 0;
int maeb = 0;
int atoa = 0;
int ba = 0;
for (int i = 0; i < n; i++) {
string s = scan.Scan();
char buf = ',';
if (s[0] == 'B' && s[s.Length - 1] != 'A') {
maeb++;
}
if (s[s.Length - 1] == 'A' && s[0] != 'B') {
atoa++;
}
if (s[0] == 'B' && s[s.Length - 1] == 'A') {
ba++;
}
for (int j = 1; j < s.Length; j++) {
if (s[j] == 'B' && s[j - 1] == 'A') {
sum++;
}
}
}
if (atoa > 0 || maeb > 0) {
Console.WriteLine(sum + Math.Min(maeb, atoa) + ba);
} else {
Console.WriteLine(sum + ba - 1);
}
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static long[] SoinsuBunkai(long num) {
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1) {
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps) {
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。
n = DivideWith(n, i + p, primes);
if (n == 1)
break;
}
i += 30;
}
return primes.ToArray();
}
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
class Pair : IComparable {
public int x;
public int y;
public Pair(int X, int Y) {
x = X;
y = Y;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
public static List<Pair>[
,
] pairs;
public static int[,] ans;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
int n = scan.Integer();
long sum = 0;
int maeb = 0;
int atoa = 0;
int ba = 0;
for (int i = 0; i < n; i++) {
string s = scan.Scan();
char buf = ',';
if (s[0] == 'B' && s[s.Length - 1] != 'A') {
maeb++;
}
if (s[s.Length - 1] == 'A' && s[0] != 'B') {
atoa++;
}
if (s[0] == 'B' && s[s.Length - 1] == 'A') {
ba++;
}
for (int j = 1; j < s.Length; j++) {
if (s[j] == 'B' && s[j - 1] == 'A') {
sum++;
}
}
}
if (ba == 0) {
Console.WriteLine(sum + Math.Min(maeb, atoa));
} else if (atoa > 0 || maeb > 0) {
Console.WriteLine(sum + Math.Min(maeb, atoa) + ba);
} else {
Console.WriteLine(sum + ba - 1);
}
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static long[] SoinsuBunkai(long num) {
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1) {
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps) {
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。
n = DivideWith(n, i + p, primes);
if (n == 1)
break;
}
i += 30;
}
return primes.ToArray();
}
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
| 8
| 8,350
| 25
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var N = Int1;
int ans = 0;
int sufA = 0;
int preB = 0;
int AB = 0;
for (int i = 0; i < N; ++i) {
var s = Str;
for (int j = 0; j < s.Length - 1; ++j) {
if (s[j] == 'A' && s[j + 1] == 'B') {
ans++;
j++;
}
}
if (s[0] == 'B' && s.Last() == 'A')
++AB;
else if (s[0] == 'B')
preB++;
else if (s[s.Length - 1] == 'A')
sufA++;
}
if (preB + sufA > 0)
ans += Min(preB, sufA) + AB;
else
ans += AB - 1;
Write(ans);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
public static Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public static List<long> DivisorEnumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var N = Int1;
int ans = 0;
int sufA = 0;
int preB = 0;
int AB = 0;
for (int i = 0; i < N; ++i) {
var s = Str;
for (int j = 0; j < s.Length - 1; ++j) {
if (s[j] == 'A' && s[j + 1] == 'B') {
ans++;
}
}
if (s[0] == 'B' && s.Last() == 'A')
++AB;
else if (s[0] == 'B')
preB++;
else if (s[s.Length - 1] == 'A')
sufA++;
}
if (preB + sufA > 0)
ans += Min(preB, sufA) + AB;
else
ans += Max(0, AB - 1);
Write(ans);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
public static Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public static List<long> DivisorEnumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 1, 0, 11, 12, 213, 63, 22], ["+", 75, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 75, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 1,213
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var S = sc.ReadStrArray(N);
var ab = 0;
var a = 0;
var b = 0;
for (int i = 0; i < N; i++) {
var c1 = S[i].First();
var cx = S[i].Last();
if (c1 == 'B' && cx == 'A') {
ab++;
} else if (c1 == 'B') {
b++;
} else if (cx == 'A') {
a++;
}
}
var ans = 0;
for (int i = 0; i < N; i++) {
var prev = S[i][0];
for (int j = 1; j < S[i].Length; j++) {
if (prev == 'A' && S[i][j] == 'B')
ans++;
prev = S[i][j];
}
}
if (ab > 0) {
ans += ab - 1;
ans += Math.Min(a, b) + 1;
} else if (a > 0 && b > 0) {
ans += Math.Min(a, b);
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var S = sc.ReadStrArray(N);
var ab = 0;
var a = 0;
var b = 0;
for (int i = 0; i < N; i++) {
var c1 = S[i].First();
var cx = S[i].Last();
if (c1 == 'B' && cx == 'A') {
ab++;
} else if (c1 == 'B') {
b++;
} else if (cx == 'A') {
a++;
}
}
var ans = 0;
for (int i = 0; i < N; i++) {
var prev = S[i][0];
for (int j = 1; j < S[i].Length; j++) {
if (prev == 'A' && S[i][j] == 'B')
ans++;
prev = S[i][j];
}
}
if (ab > 0) {
ans += ab - 1;
if (a > 0 && b > 0) {
ans += Math.Min(a, b) + 1;
} else {
if (a > 0 || b > 0)
ans++;
}
} else if (a > 0 && b > 0) {
ans += Math.Min(a, b);
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 106], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 75, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 75, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 1,266
| 28
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
long ba = 0; // B**A
long onlya = 0; // (B以外)**A
long onlyb = 0; // B**(A以外)
long ans = 0;
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (s[0] == 'B' && s[s.Length - 1] == 'A')
ba++;
else if (s[0] == 'B')
onlyb++;
else if (s[s.Length - 1] == 'A')
onlya++;
for (int j = 0; j < s.Length - 1; j++) {
if (s[j] == 'A' && s[j + 1] == 'B')
ans++;
}
}
// only同士くっつける
ans += Math.Min(onlya, onlyb);
//// 余ったのをbaとくっつける
// long useba = Math.Min(ba, Math.Abs(onlya - onlyb));
// ans += useba;
//// 余ったba同士をくっつける
// ans += ba - useba;
ans += ba;
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
long ba = 0; // B**A
long onlya = 0; // (B以外)**A
long onlyb = 0; // B**(A以外)
long ans = 0;
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (s[0] == 'B' && s[s.Length - 1] == 'A')
ba++;
else if (s[0] == 'B')
onlyb++;
else if (s[s.Length - 1] == 'A')
onlya++;
for (int j = 0; j < s.Length - 1; j++) {
if (s[j] == 'A' && s[j + 1] == 'B')
ans++;
}
}
// 3通りの場合分け
// ba==0のときonly同士くっつける
// ba!=0のとき&&onlyがあるとき
// ba!=0のとき&&onlyがないとき
if (ba == 0)
ans += Math.Min(onlya, onlyb);
else if (onlya + onlyb > 0)
ans += ba + Math.Min(onlya, onlyb);
else
ans += ba - 1;
Console.WriteLine(ans);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 72], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 24], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 0, 57, 75, 57, 75, 1, 0, 11, 31, 22], ["+", 75, 57, 75, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 57, 75, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 57, 75, 1, 0, 11, 12, 16, 17, 33], ["+", 75, 57, 75, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 231
| 31
|
using System;
namespace AtCoderDiverta2019C {
class Program {
static void Main(string[] args) {
int ans = 0;
int N = int.Parse(Console.ReadLine());
int EndA = 0;
int StartB = 0;
int Both = 0;
for (int i = 0; i < N; i++) {
string s = Console.ReadLine();
ans += (s.Length - s.Replace("AB", "").Length) / 2;
if (s.StartsWith("B"))
StartB++;
if (s.EndsWith("A"))
EndA++;
if (s.StartsWith("B") && s.EndsWith("A"))
Both++;
}
if (EndA == StartB) {
if (EndA == Both)
ans += EndA - 1;
else
ans += EndA;
} else if (EndA > StartB)
ans += StartB;
else
ans += EndA;
Console.WriteLine(ans.ToString());
}
}
}
|
using System;
namespace AtCoderDiverta2019C {
class Program {
static void Main(string[] args) {
int ans = 0;
int N = int.Parse(Console.ReadLine());
int EndA = 0;
int StartB = 0;
int Both = 0;
for (int i = 0; i < N; i++) {
string s = Console.ReadLine();
ans += (s.Length - s.Replace("AB", "").Length) / 2;
if (s.StartsWith("B"))
StartB++;
if (s.EndsWith("A"))
EndA++;
if (s.StartsWith("B") && s.EndsWith("A"))
Both++;
}
if (EndA == 0 || StartB == 0) {
Console.WriteLine(ans.ToString());
return;
}
if (EndA == StartB) {
if (EndA == Both)
ans += EndA - 1;
else
ans += EndA;
} else if (EndA > StartB)
ans += StartB;
else
ans += EndA;
Console.WriteLine(ans.ToString());
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 208
| 25
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProblemC {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var ss = new string[N];
var isStartB = new bool[N];
var isEndA = new bool[N];
var onlyBothTrue = true;
var insideABCount = 0;
for (int i = 0; i < N; i++) {
ss[i] = Console.ReadLine();
for (int j = 0; j < ss[i].Count() - 1; j++) {
if (ss[i].Substring(j, 2) == "AB")
insideABCount++;
}
isStartB[i] = ss[i].First() == 'B';
isEndA[i] = ss[i].Last() == 'A';
onlyBothTrue = isStartB[i] == isEndA[i];
}
var startBCount = isStartB.Count(x => x);
var endACount = isEndA.Count(x => x);
var minStartBEndA = Math.Min(startBCount, endACount);
if (minStartBEndA == 0)
Console.WriteLine(insideABCount);
else if (onlyBothTrue)
Console.WriteLine(insideABCount + minStartBEndA - 1);
else
Console.WriteLine(insideABCount + minStartBEndA);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProblemC {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var ss = new string[N];
var isStartB = new bool[N];
var isEndA = new bool[N];
var onlyBothTrue = true;
var insideABCount = 0;
for (int i = 0; i < N; i++) {
ss[i] = Console.ReadLine();
for (int j = 0; j < ss[i].Count() - 1; j++) {
if (ss[i].Substring(j, 2) == "AB")
insideABCount++;
}
isStartB[i] = ss[i].First() == 'B';
isEndA[i] = ss[i].Last() == 'A';
if (isStartB[i] != isEndA[i])
onlyBothTrue = false;
}
var startBCount = isStartB.Count(x => x);
var endACount = isEndA.Count(x => x);
var minStartBEndA = Math.Min(startBCount, endACount);
if (minStartBEndA == 0)
Console.WriteLine(insideABCount);
else if (onlyBothTrue)
Console.WriteLine(insideABCount + minStartBEndA - 1);
else
Console.WriteLine(insideABCount + minStartBEndA);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 211, 0, 147]]
| 8
| 293
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using E = System.Linq.Enumerable;
public class Program {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var s = Console.In.ReadToEnd();
var k = 0;
for (int i = 1; i < s.Length; i++) {
if (s[i - 1] != 'A' || s[i] != 'B') {
continue;
}
k++;
}
var ss = s.Split('\n')
.Select(x => x.Trim())
.Where(x => !string.IsNullOrEmpty(x))
.ToArray();
var prefixB = ss.Count(x => x.First() == 'B');
var suffixA = ss.Count(x => x.Last() == 'A');
var coexistence = ss.Count(x => x.First() == 'B' && x.Last() == 'A');
var atBound = Math.Min(prefixB, suffixA);
if (atBound == coexistence && prefixB == suffixA) {
atBound--;
}
k += atBound;
Console.WriteLine(k);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using E = System.Linq.Enumerable;
public class Program {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var s = Console.In.ReadToEnd();
var k = 0;
for (int i = 1; i < s.Length; i++) {
if (s[i - 1] != 'A' || s[i] != 'B') {
continue;
}
k++;
i++;
}
var ss = s.Split('\n')
.Select(x => x.Trim())
.Where(x => !string.IsNullOrEmpty(x))
.ToArray();
var prefixB = ss.Count(x => x.First() == 'B');
var suffixA = ss.Count(x => x.Last() == 'A');
var coexistence = ss.Count(x => x.First() == 'B' && x.Last() == 'A');
var atBound = Math.Min(prefixB, suffixA);
if (atBound > 0 && atBound == coexistence && prefixB == suffixA) {
atBound--;
}
k += atBound;
Console.WriteLine(k);
}
}
|
[["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98]]
| 8
| 269
| 7
|
using System;
using System.Collections.Generic;
public class diverta2019C {
public static void Main() {
int N, lastA = 0, firstB = 0, ans = 0;
string str;
bool preA = false, same = true, fB = false, lA = false;
N = int.Parse(System.Console.ReadLine());
for (int i = 0; i < N; i++) {
fB = false;
lA = false;
preA = false;
str = System.Console.ReadLine();
for (int j = 0; j < str.Length; j++) {
if (str[j] == 'B' && preA)
ans++;
if (str[j] == 'A')
preA = true;
else
preA = false;
if (j == 0 && str[j] == 'B') {
firstB++;
fB = true;
}
if (j == str.Length - 1 && str[j] == 'A') {
lastA++;
lA = true;
}
}
if ((fB && !lA) || (!fB && lA))
same = false;
}
ans += Math.Min(firstB, lastA);
if (same && ans > 0)
ans -= 1;
System.Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
public class diverta2019C {
public static void Main() {
int N, lastA = 0, firstB = 0, ans = 0;
string str;
bool preA = false, same = true, fB = false, lA = false;
N = int.Parse(System.Console.ReadLine());
for (int i = 0; i < N; i++) {
fB = false;
lA = false;
preA = false;
str = System.Console.ReadLine();
for (int j = 0; j < str.Length; j++) {
if (str[j] == 'B' && preA)
ans++;
if (str[j] == 'A')
preA = true;
else
preA = false;
if (j == 0 && str[j] == 'B') {
firstB++;
fB = true;
}
if (j == str.Length - 1 && str[j] == 'A') {
lastA++;
lA = true;
}
}
if ((fB && !lA) || (!fB && lA))
same = false;
}
if (firstB == 0 && lastA == 0)
same = false;
ans += Math.Min(firstB, lastA);
if (same && ans > 0)
ans -= 1;
System.Console.WriteLine(ans);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 269
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtC {
class Program {
static void Main(string[] args) {
var N = ReadInt();
var s = new string[N];
for (int i = 0; i < N; i++)
s[i] = ReadString();
Out(Calc(s));
}
private static int Calc(string[] s) {
int firstBCount = 0, lastACount = 0, firstBAndLastACount = 0,
innerABCount = 0, nonEdgeCount = 0;
for (int i = 0; i < s.Length; i++) {
var str = s[i];
if (str[0] == 'B' && str[str.Length - 1] == 'A') {
firstBAndLastACount++;
firstBCount++;
lastACount++;
} else if (str[0] != 'B' && str[str.Length - 1] != 'A') {
nonEdgeCount++;
} else {
if (str[0] == 'B')
firstBCount++;
if (str[str.Length - 1] == 'A')
lastACount++;
}
for (int r = 0; r < str.Length - 1; r++)
if (str[r] == 'A' && str[r + 1] == 'B')
innerABCount++;
}
var edgeABCount = Math.Min(s.Length - nonEdgeCount - 1,
Math.Min(firstBCount, lastACount));
return edgeABCount + innerABCount;
}
//最小公倍数
static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static string ReadString() { return Console.ReadLine(); }
static void Out(object o) { Console.WriteLine(o); }
}
static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
class PriorityQueue<T> {}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtC {
class Program {
static void Main(string[] args) {
// Test();
var N = ReadInt();
var s = new string[N];
for (int i = 0; i < N; i++)
s[i] = ReadString();
Out(Calc(s));
}
private static int Calc(string[] s) {
int firstBCount = 0, lastACount = 0, firstBAndLastACount = 0,
innerABCount = 0, nonEdgeCount = 0;
for (int i = 0; i < s.Length; i++) {
var str = s[i];
if (str[0] == 'B' && str[str.Length - 1] == 'A') {
firstBAndLastACount++;
firstBCount++;
lastACount++;
} else if (str[0] != 'B' && str[str.Length - 1] != 'A') {
nonEdgeCount++;
} else {
if (str[0] == 'B')
firstBCount++;
if (str[str.Length - 1] == 'A')
lastACount++;
}
for (int r = 0; r < str.Length - 1; r++)
if (str[r] == 'A' && str[r + 1] == 'B')
innerABCount++;
}
var edgeABCount = Math.Max(Math.Min(s.Length - nonEdgeCount - 1,
Math.Min(firstBCount, lastACount)),
0);
return edgeABCount + innerABCount;
}
//最小公倍数
static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static string ReadString() { return Console.ReadLine(); }
static void Out(object o) { Console.WriteLine(o); }
}
static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
class PriorityQueue<T> {}
}
|
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 708
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Math;
class Program {
static int a = 0;
static int b = 0;
static int c = 0;
static void Main() {
int n = int.Parse(Console.ReadLine());
string[] s = new string[n];
for (int i = 0; i < n; i++)
s[i] = Console.ReadLine();
int ans = 0;
foreach (var si in s)
ans += Count(si);
ans += Min(a + c, b + c);
// int l = Abs(a - b);
// if (l == 0){
// ans += Max(0,c - 1);
// goto END;
//}
// ans += Min(l,c) + Max(0,c-l);
END:
Console.WriteLine(ans);
}
static int Count(string s) {
int n = s.Length;
if (s[0] != 'B' && s[n - 1] == 'A')
a++;
if (s[0] == 'B' && s[n - 1] != 'A')
b++;
if (s[0] == 'B' && s[n - 1] == 'A')
c++;
int v = 0;
for (int i = 0; i < n - 1; i++)
if (s[i] == 'A' && s[i + 1] == 'B')
v++;
return v;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Math;
class Program {
static int a = 0;
static int b = 0;
static int c = 0;
static void Main() {
int n = int.Parse(Console.ReadLine());
string[] s = new string[n];
for (int i = 0; i < n; i++)
s[i] = Console.ReadLine();
int ans = 0;
foreach (var si in s)
ans += Count(si);
if (a == 0 && b == 0) {
ans += Max(0, c - 1);
goto END;
}
ans += Min(a + c, b + c);
END:
Console.WriteLine(ans);
}
static int Count(string s) {
int n = s.Length;
if (s[0] != 'B' && s[n - 1] == 'A')
a++;
if (s[0] == 'B' && s[n - 1] != 'A')
b++;
if (s[0] == 'B' && s[n - 1] == 'A')
c++;
int v = 0;
for (int i = 0; i < n - 1; i++)
if (s[i] == 'A' && s[i + 1] == 'B')
v++;
return v;
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 127], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 292
| 26
|
using System;
class Diverta_2019_C {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int count = 0;
int A = 0;
int B = 0;
int AB = 0;
string[] s = new string[N];
for (int i = 0; i < N; i++) {
s[i] = Console.ReadLine();
for (int j = 0; j < s[i].Length; j++) {
int pos = s[i].IndexOf("AB", j);
if (pos < 0)
break;
count++;
j += pos;
}
if (s[i][0] == 'B' && s[i][s[i].Length - 1] == 'A')
AB++;
else if (s[i][0] == 'B')
B++;
else if (s[i][s[i].Length - 1] == 'A')
A++;
}
if (A == 0 && B == 0)
count += AB - 1;
else if (A == B)
count += A + AB - 1;
else
count += Math.Min(A, B) + AB;
Console.WriteLine(count);
}
}
|
using System;
class Diverta_2019_C {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int count = 0;
int A = 0;
int B = 0;
int BA = 0;
string[] s = new string[N];
for (int i = 0; i < N; i++) {
s[i] = Console.ReadLine();
for (int j = 0; j < s[i].Length; j++) {
int pos = s[i].IndexOf("AB", j);
if (pos < 0)
break;
count++;
j += pos;
}
if (s[i][0] == 'B' && s[i][s[i].Length - 1] == 'A')
BA++;
else if (s[i][0] == 'B')
B++;
else if (s[i][s[i].Length - 1] == 'A')
A++;
}
if (A == 0 && B == 0 && BA > 1)
count += BA - 1;
else
count += Math.Min(A, B) + BA;
Console.WriteLine(count);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["-", 64, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["-", 64, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["-", 64, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["-", 75, 57, 75, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 274
| 25
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
var N = Int32.Parse(Console.ReadLine());
var count = 0L;
var firstB = 0;
var lastA = 0;
var ba = 0;
for (int i = 0; i < N; ++i) {
var str = Console.ReadLine();
if (str[0] == 'B')
firstB++;
if (str[str.Length - 1] == 'A')
lastA++;
if (str[0] == 'B' && str[str.Length - 1] == 'A')
ba++;
var beforeLetter = str[0];
for (int j = 1; j < str.Length; ++j) {
if (beforeLetter == 'A' && str[j] == 'B')
count++;
beforeLetter = str[j];
}
}
if (ba == firstB && ba == lastA)
firstB--;
count += Math.Min(firstB, lastA);
Console.WriteLine(count);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
var N = Int32.Parse(Console.ReadLine());
var count = 0L;
var firstB = 0;
var lastA = 0;
var ba = 0;
for (int i = 0; i < N; ++i) {
var str = Console.ReadLine();
if (str[0] == 'B')
firstB++;
if (str[str.Length - 1] == 'A')
lastA++;
if (str[0] == 'B' && str[str.Length - 1] == 'A')
ba++;
var beforeLetter = str[0];
for (int j = 1; j < str.Length; ++j) {
if (beforeLetter == 'A' && str[j] == 'B')
count++;
beforeLetter = str[j];
}
}
if (ba == firstB && ba == lastA)
firstB--;
count += Math.Max(0, Math.Min(firstB, lastA));
Console.WriteLine(count);
}
}
|
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 228
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Diverta {
class C {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int countA = 0, countB = 0, countAB = 0, countBA = 0;
for (int i = 0; i < N; i++) {
string s = Console.ReadLine();
if (s.StartsWith("B")) {
if (s.EndsWith("A")) {
countBA++;
} else {
countB++;
}
} else if (s.EndsWith("A")) {
countA++;
}
while (s.Length > 0) {
int id = s.IndexOf("AB");
if (id >= 0) {
countAB++;
s = s.Substring(id + 2);
} else {
break;
}
}
}
int sum = countBA - 1;
if (countB > 0) {
sum++;
countB--;
}
if (countA > 0) {
sum++;
countA--;
}
int max = countAB + sum + Math.Min(countA, countB);
Console.WriteLine(max);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Diverta {
class C {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int countA = 0, countB = 0, countAB = 0, countBA = 0;
for (int i = 0; i < N; i++) {
string s = Console.ReadLine();
if (s.StartsWith("B")) {
if (s.EndsWith("A")) {
countBA++;
} else {
countB++;
}
} else if (s.EndsWith("A")) {
countA++;
}
while (s.Length > 0) {
int id = s.IndexOf("AB");
if (id >= 0) {
countAB++;
s = s.Substring(id + 2);
} else {
break;
}
}
}
int sum = 0;
if (countBA >= 1) {
sum = countBA - 1;
if (countB > 0) {
sum++;
countB--;
}
if (countA > 0) {
sum++;
countA--;
}
}
int max = countAB + sum + Math.Min(countA, countB);
Console.WriteLine(max);
}
}
}
|
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 261
| 12
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int a = 0, b = 0, ab = 0;
bool allBXA = true;
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (s[0] == 'B') {
b++;
if (s[s.Length - 1] != 'A')
allBXA = false;
}
if (s[s.Length - 1] == 'A') {
a++;
if (s[0] != 'B')
allBXA = false;
}
for (int j = 0; j < s.Length - 1; j++) {
if (s[j] == 'A' && s[j + 1] == 'B')
ab++;
}
}
ab += Math.Min(a, b);
if (allBXA)
ab--;
Console.WriteLine(ab);
}
}
// mcs Main.cs
// mono Main.exe
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int a = 0, b = 0, ab = 0;
bool allBXA = true;
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (s[0] == 'B') {
b++;
if (s[s.Length - 1] != 'A')
allBXA = false;
}
if (s[s.Length - 1] == 'A') {
a++;
if (s[0] != 'B')
allBXA = false;
}
for (int j = 0; j < s.Length - 1; j++) {
if (s[j] == 'A' && s[j + 1] == 'B')
ab++;
}
}
if (a == 0 && b == 0)
allBXA = false;
ab += Math.Min(a, b);
if (allBXA)
ab--;
Console.WriteLine(ab);
}
}
// mcs Main.cs
// mono Main.exe
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 224
| 14
|
using System;
namespace diverta2019_C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var s = new string[N];
var a = 0;
var b = 0;
var ab = 0;
var same = 0;
var none = 0;
for (int i = 0; i < N; i++) {
s[i] = Console.ReadLine();
var flag1 = s[i][0] == 'B';
var flag2 = s[i][s[i].Length - 1] == 'A';
if (flag1)
b++;
if (flag2)
a++;
if (flag1 && flag2)
same++;
if (!flag1 && !flag2)
none++;
s[i] = s[i].Replace("AB", "0");
foreach (var c in s[i]) {
if (c == '0')
ab++;
}
}
var n = Math.Min(a, b);
var max = Math.Max(a, b);
if (n == same && max == same)
n--;
Console.WriteLine(n + ab);
}
}
}
|
using System;
namespace diverta2019_C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var s = new string[N];
var a = 0;
var b = 0;
var ab = 0;
var same = 0;
var none = 0;
for (int i = 0; i < N; i++) {
s[i] = Console.ReadLine();
var flag1 = s[i][0] == 'B';
var flag2 = s[i][s[i].Length - 1] == 'A';
if (flag1)
b++;
if (flag2)
a++;
if (flag1 && flag2)
same++;
s[i] = s[i].Replace("AB", "0");
foreach (var c in s[i]) {
if (c == '0')
ab++;
}
}
var n = Math.Min(a, b);
var max = Math.Max(a, b);
if (same > 0 && n == same && max == same)
n--;
Console.WriteLine(n + ab);
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 241, 0, 111], ["-", 8, 196, 0, 57, 15, 16, 31, 241, 0, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 241, 0, 111], ["-", 8, 196, 0, 57, 15, 16, 12, 241, 0, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["-", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98]]
| 8
| 258
| 15
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z {
static void Main() => new K();
}
class K {
int F => int.Parse(Str);
long FL => long.Parse(Str);
int[] G => Strs.Select(int.Parse).ToArray();
uint[] GU => Strs.Select(uint.Parse).ToArray();
decimal[] GD => Strs.Select(decimal.Parse).ToArray();
long[] GL => Strs.Select(long.Parse).ToArray();
string Str => ReadLine();
string[] Strs => Str.Split(new char[] { ' ', '\t' },
StringSplitOptions.RemoveEmptyEntries);
static T[] ConstantArray<T>(int n, T val) {
var a = new T[n];
for (var i = 0; i < n; i++)
a[i] = val;
return a;
}
static T[] MakeArray<T>(int n, Func<int, T> f) {
var a = new T[n];
for (var i = 0; i < n; i++)
a[i] = f(i);
return a;
}
static int ArgMax<T>(IList<T> a)
where T : IComparable<T> {
var m = a[0];
var mi = 0;
for (var i = 1; i < a.Count; i++)
if (m.CompareTo(a[i]) < 0) {
m = a[i];
mi = i;
}
return mi;
}
static int ArgMin<T>(IList<T> a)
where T : IComparable<T> {
var m = a[0];
var mi = 0;
for (var i = 1; i < a.Count; i++)
if (m.CompareTo(a[i]) > 0) {
m = a[i];
mi = i;
}
return mi;
}
static ulong One(int k) => 1ul << k;
static ulong All(int k) => One(k) - 1;
static bool Has(ulong s, int k) => (s & One(k)) != 0;
const int MOD = 1000000007;
public K() {
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
Solve();
Out.Flush();
}
void Solve() {
var N = F;
var S = MakeArray(N, _ => Str);
// ...A, B..., B...A, other
int cA = 0, cB = 0, cBA = 0;
var ans = 0;
foreach (var s in S) {
if (s[0] == 'B' && s[s.Length - 1] == 'A')
cBA++;
else if (s[0] == 'B')
cB++;
else if (s[s.Length - 1] == 'A')
cA++;
for (var i = 1; i < s.Length; i++)
if (s[i - 1] == 'A' && s[i] == 'B')
ans++;
}
// WriteLine($"ans={ans}, cA={cA}, cB={cB}, cBA={cBA}");
if (cA == 0 && cB == 0) {
if (cBA >= 2)
ans += cBA - 1;
} else if (cA == 0 || cB == 0)
ans += cBA;
else {
if (cA < cB)
cB--;
else
cA--;
ans += cBA;
var x = Min(cA, cB);
ans += x;
cA -= x;
cB -= x;
}
WriteLine(ans);
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z {
static void Main() => new K();
}
class K {
int F => int.Parse(Str);
long FL => long.Parse(Str);
int[] G => Strs.Select(int.Parse).ToArray();
uint[] GU => Strs.Select(uint.Parse).ToArray();
decimal[] GD => Strs.Select(decimal.Parse).ToArray();
long[] GL => Strs.Select(long.Parse).ToArray();
string Str => ReadLine();
string[] Strs => Str.Split(new char[] { ' ', '\t' },
StringSplitOptions.RemoveEmptyEntries);
static T[] ConstantArray<T>(int n, T val) {
var a = new T[n];
for (var i = 0; i < n; i++)
a[i] = val;
return a;
}
static T[] MakeArray<T>(int n, Func<int, T> f) {
var a = new T[n];
for (var i = 0; i < n; i++)
a[i] = f(i);
return a;
}
static int ArgMax<T>(IList<T> a)
where T : IComparable<T> {
var m = a[0];
var mi = 0;
for (var i = 1; i < a.Count; i++)
if (m.CompareTo(a[i]) < 0) {
m = a[i];
mi = i;
}
return mi;
}
static int ArgMin<T>(IList<T> a)
where T : IComparable<T> {
var m = a[0];
var mi = 0;
for (var i = 1; i < a.Count; i++)
if (m.CompareTo(a[i]) > 0) {
m = a[i];
mi = i;
}
return mi;
}
static ulong One(int k) => 1ul << k;
static ulong All(int k) => One(k) - 1;
static bool Has(ulong s, int k) => (s & One(k)) != 0;
const int MOD = 1000000007;
public K() {
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
Solve();
Out.Flush();
}
void Solve() {
var N = F;
var S = MakeArray(N, _ => Str);
// ...A, B..., B...A, other
int cA = 0, cB = 0, cBA = 0;
var ans = 0;
foreach (var s in S) {
if (s[0] == 'B' && s[s.Length - 1] == 'A')
cBA++;
else if (s[0] == 'B')
cB++;
else if (s[s.Length - 1] == 'A')
cA++;
for (var i = 1; i < s.Length; i++)
if (s[i - 1] == 'A' && s[i] == 'B')
ans++;
}
// WriteLine($"ans={ans}, cA={cA}, cB={cB}, cBA={cBA}");
if (cA == 0 && cB == 0) {
if (cBA >= 2)
ans += cBA - 1;
} else if (cA == 0 || cB == 0)
ans += cBA;
else
ans += Min(cB + cBA, cA + cBA);
WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["-", 0, 57, 75, 57, 75, 196, 0, 57, 0, 121], ["-", 0, 57, 75, 57, 75, 196, 0, 57, 0, 24], ["-", 75, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 75, 57, 75, 196, 0, 57, 15, 16, 17, 18], ["-", 75, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 57, 75, 57, 75, 196, 0, 57, 0, 25], ["-", 75, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 75, 196, 0, 57, 64, 1, 0, 223, 0, 68], ["-", 75, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 57, 75, 57, 75, 196, 0, 57, 0, 95], ["-", 75, 196, 0, 57, 75, 1, 0, 223, 0, 22], ["-", 75, 196, 0, 57, 75, 1, 0, 223, 0, 68], ["-", 75, 57, 75, 196, 0, 57, 75, 1, 0, 35], ["-", 75, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 57, 75, 57, 75, 196, 0, 197, 0, 35], ["-", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 75, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 75, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 75, 196, 0, 46]]
| 8
| 797
| 40
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Debug = System.Diagnostics.Debug;
using System.Runtime.CompilerServices;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
var n = int.Parse(Console.ReadLine());
string[] s =
Enumerable.Repeat(0, n).Select(_ => Console.ReadLine()).ToArray();
var tailA = s.Count(x => x.Last() == 'A');
var headB = s.Count(x => x.First() == 'B');
var res = 0;
foreach (var item in s) {
for (int i = 0; i < item.Length - 1; i++) {
if (item[i] == 'A' && item[i + 1] == 'B')
res++;
}
}
res +=
Min(tailA, headB) - (s.All(x => (x.First() == 'B' && x.Last() == 'A') ||
(x.First() != 'B' && x.Last() != 'A'))
? 1
: 0);
Console.WriteLine(Max(0, res));
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Debug = System.Diagnostics.Debug;
using System.Runtime.CompilerServices;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
var n = int.Parse(Console.ReadLine());
string[] s =
Enumerable.Repeat(0, n).Select(_ => Console.ReadLine()).ToArray();
var tailA = s.Count(x => x.Last() == 'A');
var headB = s.Count(x => x.First() == 'B');
var res = 0;
foreach (var item in s) {
for (int i = 0; i < item.Length - 1; i++) {
if (item[i] == 'A' && item[i + 1] == 'B')
res++;
}
}
res += Max(0, Min(tailA, headB) -
(s.All(x => (x.First() == 'B' && x.Last() == 'A') ||
(x.First() != 'B' && x.Last() != 'A'))
? 1
: 0));
Console.WriteLine(res);
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 325
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
// using System.Threading.Tasks;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
readonly Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
readonly int dom = 998244353;
bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (b.CompareTo(a) < 0) {
a = b;
return true;
}
return false;
}
void solve() {
int N = cin.nextint;
int lasta = 0;
int firstb = 0;
int multi = 0;
long ans = 0;
for (int i = 0; i < N; i++) {
var S = ReadLine();
int L = S.Length;
if (S[0] == 'B' && S[L - 1] == 'A')
multi++;
else if (S[0] == 'B')
firstb++;
else if (S[L - 1] == 'A')
lasta++;
for (int j = 1; j < L; j++) {
if (S[j - 1] == 'A' && S[j] == 'B') {
ans++;
}
}
}
// WriteLine(ans + " " + multi + " " + firstb + " " + lasta);
int Z = Min(lasta, firstb);
ans += Z;
ans += multi;
// int W = lasta - Z + firstb - Z;
// if (W == 0)
//{
// ans += multi - 1;
//}
// else if (W <= multi)
//{
// ans += W - 1;
// multi -= W - 1;
// ans += multi;
//}
// else
//{
// ans += multi;
//}
WriteLine(ans);
}
}
static class Ex {
public static void join<T>(this IEnumerable<T> values, string sep = " ") =>
WriteLine(string.Join(sep, values));
public static string
concat<T>(this IEnumerable<T> values) => string.Concat(values);
public static string reverse(this string s) {
var t = s.ToCharArray();
Array.Reverse(t);
return t.concat();
}
public static int lower_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int upper_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
}
class Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T f;
public U s;
public Pair(T f, U s) {
this.f = f;
this.s = s;
}
public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0
? f.CompareTo(a.f)
: s.CompareTo(a.s);
public override string ToString() => $"{f} {s}";
}
class Scanner {
string[] s;
int i;
readonly char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan => ReadLine().Split();
public int[] scanint => Array.ConvertAll(scan, int.Parse);
public long[] scanlong => Array.ConvertAll(scan, long.Parse);
public double[] scandouble => Array.ConvertAll(scan, double.Parse);
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint => int.Parse(next);
public long nextlong => long.Parse(next);
public double nextdouble => double.Parse(next);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
// using System.Threading.Tasks;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
readonly Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
readonly int dom = 998244353;
bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (b.CompareTo(a) < 0) {
a = b;
return true;
}
return false;
}
void solve() {
int N = cin.nextint;
int lasta = 0;
int firstb = 0;
int multi = 0;
long ans = 0;
for (int i = 0; i < N; i++) {
var S = ReadLine();
int L = S.Length;
if (S[0] == 'B' && S[L - 1] == 'A')
multi++;
else if (S[0] == 'B')
firstb++;
else if (S[L - 1] == 'A')
lasta++;
for (int j = 1; j < L; j++) {
if (S[j - 1] == 'A' && S[j] == 'B') {
ans++;
}
}
}
// WriteLine(ans + " " + multi + " " + firstb + " " + lasta);
int Z = Min(lasta, firstb);
ans += Z;
if (lasta == 0 && firstb == 0 && multi > 0)
ans += multi - 1;
else
ans += multi;
// int W = lasta - Z + firstb - Z;
// if (W == 0)
//{
// ans += multi - 1;
//}
// else if (W <= multi)
//{
// ans += W - 1;
// multi -= W - 1;
// ans += multi;
//}
// else
//{
// ans += multi;
//}
WriteLine(ans);
}
}
static class Ex {
public static void join<T>(this IEnumerable<T> values, string sep = " ") =>
WriteLine(string.Join(sep, values));
public static string
concat<T>(this IEnumerable<T> values) => string.Concat(values);
public static string reverse(this string s) {
var t = s.ToCharArray();
Array.Reverse(t);
return t.concat();
}
public static int lower_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int upper_bound<T>(this IList<T> arr, T val)
where T : IComparable<T> {
int low = 0, high = arr.Count;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (arr[mid].CompareTo(val) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
}
class Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T f;
public U s;
public Pair(T f, U s) {
this.f = f;
this.s = s;
}
public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0
? f.CompareTo(a.f)
: s.CompareTo(a.s);
public override string ToString() => $"{f} {s}";
}
class Scanner {
string[] s;
int i;
readonly char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan => ReadLine().Split();
public int[] scanint => Array.ConvertAll(scan, int.Parse);
public long[] scanlong => Array.ConvertAll(scan, long.Parse);
public double[] scandouble => Array.ConvertAll(scan, double.Parse);
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint => int.Parse(next);
public long nextlong => long.Parse(next);
public double nextdouble => double.Parse(next);
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 1,029
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass : Scanner {
static void Main() {
var N = RLong();
long ans = 0;
long max = N;
for (long i = 1; i < Sqrt(N); i++) {
if (N % i == 0)
ans += N / i - 1;
}
WriteLine(ans);
}
}
class Scanner {
public static int RInt() => int.Parse(Console.ReadLine());
public static long RLong() => long.Parse(Console.ReadLine());
public static string RString() => Console.ReadLine();
public static double RDouble() => double.Parse(Console.ReadLine());
public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(),
int.Parse);
public static int[] RInts(Func<string, int> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(),
long.Parse);
public static long[] RLongs(Func<string, long> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static double[] RDoubles() =>
Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
public static double[] RDoubles(Func<string, double> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static string[] RStrings() => Console.ReadLine().Split();
// public static string[] RStrings(Func<string, string> func) =>
// Console.ReadLine().Split().Select(func).ToArray();
public static T1 ReadStream<T1>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
return r1;
}
public static (T1, T2) ReadStream<T1, T2>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
return (r1, r2);
}
public static (T1, T2, T3) ReadStream<T1, T2, T3>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
return (r1, r2, r3);
}
public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
return (r1, r2, r3, r4);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass : Scanner {
static void Main() {
var N = RLong();
long ans = 0;
long max = N;
for (long i = 1; i <= Sqrt(N) + 1; i++) {
if (N % i == 0 && N / i - 1 > i)
ans += N / i - 1;
}
WriteLine(ans);
}
}
class Scanner {
public static int RInt() => int.Parse(Console.ReadLine());
public static long RLong() => long.Parse(Console.ReadLine());
public static string RString() => Console.ReadLine();
public static double RDouble() => double.Parse(Console.ReadLine());
public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(),
int.Parse);
public static int[] RInts(Func<string, int> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(),
long.Parse);
public static long[] RLongs(Func<string, long> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static double[] RDoubles() =>
Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
public static double[] RDoubles(Func<string, double> func) =>
Console.ReadLine().Split().Select(func).ToArray();
public static string[] RStrings() => Console.ReadLine().Split();
// public static string[] RStrings(Func<string, string> func) =>
// Console.ReadLine().Split().Select(func).ToArray();
public static T1 ReadStream<T1>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
return r1;
}
public static (T1, T2) ReadStream<T1, T2>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
return (r1, r2);
}
public static (T1, T2, T3) ReadStream<T1, T2, T3>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
return (r1, r2, r3);
}
public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() {
var r = RStrings();
var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
return (r1, r2, r3, r4);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 17, 85], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 720
| 12
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.