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;
namespace Atc_0026 {
class Program {
static void Main(string[] args) {
var A = int.Parse(Console.ReadLine());
var B = int.Parse(Console.ReadLine());
if (A != 1 && B != 1) {
Console.WriteLine(1);
}
if (A != 2 && B != 2) {
Console.WriteLine(2);
}
if (A != 2 && B != 3) {
Console.WriteLine(3);
}
}
}
}
|
using System;
namespace Atc_0026 {
class Program {
static void Main(string[] args) {
var A = int.Parse(Console.ReadLine());
var B = int.Parse(Console.ReadLine());
if (A != 1 && B != 1) {
Console.WriteLine(1);
}
if (A != 2 && B != 2) {
Console.WriteLine(2);
}
if (A != 3 && B != 3) {
Console.WriteLine(3);
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 107
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
for (int i = 1; i <= 3; i++) {
if (A == i && B == i) {
Console.WriteLine(i);
}
}
}
int A, B;
public Sol() {
A = ri();
B = ri();
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
for (int i = 1; i <= 3; i++) {
if (A != i && B != i) {
Console.WriteLine(i);
}
}
}
int A, B;
public Sol() {
A = ri();
B = ri();
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79]]
| 8
| 340
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var tmp = Console.ReadLine().Split(' ');
var s = tmp[0];
var t = tmp[1];
var result = string.Empty;
for (int i = 0; i < n; i++) {
result = s[i].ToString() + t[i].ToString();
}
Console.WriteLine(result);
}
static List<long> ReadLine() {
var line = Console.ReadLine();
var array = line.Split(' ');
return array.Select(x => long.Parse(x)).ToList();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var tmp = Console.ReadLine().Split(' ');
var s = tmp[0];
var t = tmp[1];
var result = string.Empty;
for (int i = 0; i < n; i++) {
result += s[i].ToString() + t[i].ToString();
}
Console.WriteLine(result);
}
static List<long> ReadLine() {
var line = Console.ReadLine();
var array = line.Split(' ');
return array.Select(x => long.Parse(x)).ToList();
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
| 8
| 176
| 2
|
using System;
namespace ABC148B {
class Program {
static void Main(string[] args) {
string str1 = Console.ReadLine();
int n = int.Parse(str1);
string[] str2 = Console.ReadLine().Split(' ');
char[] c1 = str2[0].ToCharArray();
char[] c2 = str2[1].ToCharArray();
for (int i = 0; i < n; i++) {
Console.Write(c1[i] + c2[i]);
}
Console.Write("\n");
}
}
}
|
using System;
namespace ABC148B {
class Program {
static void Main(string[] args) {
string str1 = Console.ReadLine();
int n = int.Parse(str1);
string[] str2 = Console.ReadLine().Split(' ');
char[] c1 = str2[0].ToCharArray();
char[] c2 = str2[1].ToCharArray();
for (int i = 0; i < n; i++) {
Console.Write("{0}{1}", c1[i], c2[i]);
}
Console.Write("\n");
}
}
}
|
[["+", 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], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
| 8
| 127
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CountABC {
class Program {
static void Main(string[] args) {
int lettersAmount = int.Parse(Console.ReadLine());
List<char> lettersInput = Console.ReadLine().ToList();
List<string> abcSentences = new List<string>();
int abcAmount = 0;
for (int i = 0; i < lettersAmount; i++) {
string abcString = "";
if (lettersInput[i].ToString() == "A" && i + 1 <= lettersAmount &&
i + 2 <= lettersAmount) {
abcString += lettersInput[i].ToString() +
lettersInput[i + 1].ToString() +
lettersInput[i + 2].ToString();
}
if (abcString == "ABC") {
abcAmount++;
}
}
Console.WriteLine(abcAmount);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace CountABC {
class Program {
static void Main(string[] args) {
int lettersAmount = int.Parse(Console.ReadLine());
List<char> lettersInput = Console.ReadLine().ToList();
List<string> abcSentences = new List<string>();
int abcAmount = 0;
for (int i = 0; i < lettersAmount; i++) {
string abcString = "";
if (lettersInput[i].ToString() == "A" && i < lettersAmount &&
i + 1 < lettersAmount && i + 2 < lettersAmount) {
abcString += lettersInput[i].ToString() +
lettersInput[i + 1].ToString() +
lettersInput[i + 2].ToString();
}
if (abcString == "ABC") {
abcAmount++;
}
}
Console.WriteLine(abcAmount);
}
}
}
|
[["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18]]
| 8
| 187
| 8
|
using System;
using System.Linq;
namespace b {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine().Trim();
var c = 0;
var i = 0;
while (true) {
if (i + 3 < s.Length) {
var sb = s.Substring(i, 3);
if (sb.Equals("ABC")) {
c += 1;
}
i += 1;
} else {
break;
}
}
Console.WriteLine(c);
}
}
}
|
using System;
using System.Linq;
namespace b {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine().Trim();
var c = 0;
var i = 0;
while (true) {
if (i + 3 <= s.Length) {
var sb = s.Substring(i, 3);
if (sb.Equals("ABC")) {
c += 1;
}
i += 1;
} else {
break;
}
}
Console.WriteLine(c);
}
}
}
|
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 127
| 2
|
using System;
namespace abc150B {
class MainClass {
public static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
string temp;
int Ans = 0;
for (int i = 0; i < N - 3; i++) {
temp = S.Substring(i, 3);
if (temp == "ABC")
Ans = Ans + 1;
}
Console.WriteLine(Ans);
}
}
}
|
using System;
namespace abc150B {
class MainClass {
public static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string S = Console.ReadLine();
string temp;
int Ans = 0;
for (int i = 0; i <= N - 3; i++) {
temp = S.Substring(i, 3);
if (temp == "ABC")
Ans = Ans + 1;
}
Console.WriteLine(Ans);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 104
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace CSharp {
static class Program {
static void Main(string[] args) {
ReadString();
string s = ReadString();
int ans = 0;
for (int i = 0; i < s.Length - 3; i++) {
if (s.Substring(i, 3) == "ABC") {
ans++;
}
}
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 {
static class Program {
static void Main(string[] args) {
ReadString();
string s = ReadString();
int ans = 0;
for (int i = 0; i < s.Length - 2; i++) {
if (s.Substring(i, 3) == "ABC") {
ans++;
}
}
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
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 625
| 2
|
using System;
public class AtCoderB {
static void Main() {
int n = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int answer = 0;
for (int i = 0; i < n - 3; i++) {
string str = s.Substring(i, 3);
if ("ABC".Equals(str)) {
answer++;
}
}
Console.WriteLine(answer);
}
}
|
using System;
public class AtCoderB {
static void Main() {
int n = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int answer = 0;
for (int i = 0; i < n - 2; i++) {
string str = s.Substring(i, 3);
if ("ABC".Equals(str)) {
answer++;
}
}
Console.WriteLine(answer);
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 96
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp12 {
class Program {
static void Main(string[] args) {
Console.ReadLine();
var str = Console.ReadLine();
int cnt = 0;
int s = 0;
while (true) {
s = str.IndexOf("ABC", s + 1);
if (s == -1)
break;
cnt++;
}
Console.WriteLine(cnt);
}
static void MainA(string[] args) {
var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
Console.WriteLine(arr[0] * 500 >= arr[1] ? "Yes" : "No");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp12 {
class Program {
static void Main(string[] args) {
Console.ReadLine();
var str = Console.ReadLine();
int cnt = 0;
int s = 0;
while (true) {
s = str.IndexOf("ABC", s);
if (s == -1)
break;
s++;
cnt++;
}
Console.WriteLine(cnt);
}
static void MainA(string[] args) {
var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
Console.WriteLine(arr[0] * 500 >= arr[1] ? "Yes" : "No");
}
}
}
|
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29]]
| 8
| 179
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;
namespace CP {
class Atria {
static void Main(string[] args) {
int n = int.Parse(ReadLine());
string s = ReadLine();
int ans = 0;
for (int i = 0; i < n - 3; i++) {
if (s.Substring(i, 3) == "ABC") {
ans++;
}
}
WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;
namespace CP {
class Atria {
static void Main(string[] args) {
int n = int.Parse(ReadLine());
string s = ReadLine();
int ans = 0;
for (int i = 0; i < n - 2; i++) {
if (s.Substring(i, 3) == "ABC") {
ans++;
}
}
WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 123
| 2
|
using System;
namespace B {
internal class Program {
public static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine().ToCharArray();
int count = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'A' && i < N - 3) {
if (S[i + 1] == 'B') {
if (S[i + 2] == 'C') {
count++;
}
}
}
}
Console.WriteLine(count);
}
}
}
|
using System;
namespace B {
internal class Program {
public static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine().ToCharArray();
int count = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'A' && i <= N - 3) {
if (S[i + 1] == 'B') {
if (S[i + 2] == 'C') {
count++;
}
}
}
}
Console.WriteLine(count);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
| 8
| 131
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
struct mint : IEquatable<mint> {
// static uint mod = 998244353;
static uint mod = 1000000007;
uint _v;
public mint(long v) : this((uint)(v % mod + mod)) {}
private mint(uint v) { _v = v < mod ? v : (v - mod); }
public static void SetMod(uint p) { mod = p; }
public static mint operator +(mint lhs, mint rhs) {
return new mint(lhs._v + rhs._v);
}
public static mint operator -(mint lhs, mint rhs) {
return new mint(lhs._v + mod - rhs._v);
}
public static mint operator *(mint lhs, mint rhs) {
return new mint((uint)((ulong)lhs._v * rhs._v % mod));
}
public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); }
public static mint operator ^(mint x, int n) { return Pow(x, n); }
public static bool operator ==(mint l, mint r) { return l._v == r._v; }
public static bool operator !=(mint l, mint r) { return !(l == r); }
public static bool operator<(mint l, mint r) { return l._v < r._v; }
public static bool operator>(mint l, mint r) { return l._v > r._v; }
public static mint Pow(mint x, int n) {
var r = new mint(1);
while (n > 0) {
if ((n & 1) > 0)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
public mint Pow(int n) { return Pow(this, n); }
public mint Inv() { return Pow((int)mod - 2); }
public bool Equals(mint o) { return this == o; }
public override bool Equals(object obj) {
if (obj is mint)
return this == (mint)obj;
else
return false;
}
public override int GetHashCode() { return _v.GetHashCode(); }
public override string ToString() { return _v.ToString(); }
public static implicit operator mint(int i) { return new mint(i); }
public static implicit operator mint(long i) { return new mint(i); }
private static mint[] _fact;
public static void SetFact(int n) {
_fact = new mint[n + 1];
_fact[0] = 1;
for (int i = 1; i < n + 1; i++) {
_fact[i] = _fact[i - 1] * i;
}
}
public static mint Fact(int n) {
if (_fact == null || _fact.Length < n) {
SetFact(n * 2);
}
return _fact[n];
}
public static mint Combination(int n, int r) {
return Fact(n) / (Fact(n - r) * Fact(r));
}
}
static class Extensions {
public static int LowerBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c > 0)
l = m + 1;
else
r = m;
}
return l;
}
public static int UpperBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c >= 0)
l = m + 1;
else
r = m;
}
return r;
}
}
class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
public static int[] ZAlgotithm(string s) {
var len = s.Length;
var a = new int[len];
a[0] = len;
var i = 1;
var j = 0;
while (i < len) {
while (i + j < len && s[j] == s[i + j])
j++;
a[i] = j;
if (j == 0) {
i++;
continue;
}
var k = 1;
while (i + k < len && k + a[k] < j) {
a[i + k] = a[k];
k++;
}
i += k;
j -= k;
}
return a;
}
public class MaxHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MaxHeap() : this(0) {}
public MaxHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c > 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) < 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MaxHeap<T> Copy(Comparison<T> comp = null) {
var c = new MaxHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MaxHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
public class MinHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MinHeap() : this(0) {}
public MinHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c < 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) > 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MinHeap<T> Copy(Comparison<T> comp = null) {
var c = new MinHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MinHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class InputLine {
private string[] _inputs;
private int _index = 0;
InputLine(string input) {
_inputs = input.Split();
_index = 0;
}
public static InputLine Read() { return new InputLine(Console.ReadLine()); }
public int NextInt() { return int.Parse(_inputs[_index++]); }
public long NextLong() { return long.Parse(_inputs[_index++]); }
public double NextDouble() { return double.Parse(_inputs[_index++]); }
}
public static int GCD(int x, int y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
public static long GCD(long x, long y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
static long ModPower(long x, long y, long mod) {
var bytes = BitConverter.GetBytes(y);
var bits = new System.Collections.BitArray(bytes);
var max2 = 0;
for (int i = bits.Length - 1; i >= 0; i--) {
if (bits[i]) {
max2 = i;
break;
}
}
long result = 1;
for (int i = max2; i >= 0; i--) {
result = (result * result) % mod;
if (bits[i]) {
result = (result * x) % mod;
}
}
return result;
}
static long ModFact(long n, long mod) {
long result = 1;
for (int i = 1; i <= n; i++) {
result = result * i % mod;
}
return result;
}
static long ModAdd(long x, long y, long mod) {
return ((x % mod) + (y % mod)) % mod;
}
static long ModMul(long x, long y, long mod) {
return ((x % mod) * (y % mod)) % mod;
}
static long ModDiv(long x, long y, long mod) {
//ใใงใซใใผใฎๅฐๅฎ็ใใใa^(-1) = a^(p-2)
return ModMul(x, ModPower(y, mod - 2, mod), mod);
}
static long ModComb(long n, long r, long mod) {
long numerator = 1;
for (int i = 0; i < r; i++) {
numerator = ModMul(numerator, n - i, mod);
}
long denominator = ModFact(r, mod);
return ModDiv(numerator, denominator, mod);
}
class Graph {
private int _size;
private List<int>[] _edges;
public Graph(int size) {
_size = size;
_edges = new List<int>[size];
}
public List<int> this[int i] {
get {
if (_edges[i] == null)
_edges[i] = new List<int>();
return _edges[i];
}
}
}
class Graph<T> {
private int _size;
private List<T>[] _edges;
public Graph(int size) {
_size = size;
_edges = new List<T>[size];
}
public List<T> this[int i] {
get {
if (_edges[i] == null)
_edges[i] = new List<T>();
return _edges[i];
}
}
}
static Graph<T> NewGraph<T>(int size, T template) {
return new Graph<T>(size);
}
static List<T> NewList<T>(T template) { return new List<T>(); }
static T[] NewArray<T>(int size, T template) { return new T[size]; }
static long p1097 = 1000000007;
static void Main(string[] args) {
//โ
var n = ReadInt();
var s = Console.ReadLine();
var next = 'A';
var count = 0;
for (int i = 0; i < n; i++) {
var c = s[i];
if (c == next) {
if (next == 'A') {
next = 'B';
} else if (next == 'B') {
next = 'C';
} else if (next == 'C') {
count++;
next = 'A';
}
} else {
if (c == 'A') {
continue;
}
next = 'A';
}
}
Console.WriteLine(count);
//โ
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
struct mint : IEquatable<mint> {
// static uint mod = 998244353;
static uint mod = 1000000007;
uint _v;
public mint(long v) : this((uint)(v % mod + mod)) {}
private mint(uint v) { _v = v < mod ? v : (v - mod); }
public static void SetMod(uint p) { mod = p; }
public static mint operator +(mint lhs, mint rhs) {
return new mint(lhs._v + rhs._v);
}
public static mint operator -(mint lhs, mint rhs) {
return new mint(lhs._v + mod - rhs._v);
}
public static mint operator *(mint lhs, mint rhs) {
return new mint((uint)((ulong)lhs._v * rhs._v % mod));
}
public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); }
public static mint operator ^(mint x, int n) { return Pow(x, n); }
public static bool operator ==(mint l, mint r) { return l._v == r._v; }
public static bool operator !=(mint l, mint r) { return !(l == r); }
public static bool operator<(mint l, mint r) { return l._v < r._v; }
public static bool operator>(mint l, mint r) { return l._v > r._v; }
public static mint Pow(mint x, int n) {
var r = new mint(1);
while (n > 0) {
if ((n & 1) > 0)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
public mint Pow(int n) { return Pow(this, n); }
public mint Inv() { return Pow((int)mod - 2); }
public bool Equals(mint o) { return this == o; }
public override bool Equals(object obj) {
if (obj is mint)
return this == (mint)obj;
else
return false;
}
public override int GetHashCode() { return _v.GetHashCode(); }
public override string ToString() { return _v.ToString(); }
public static implicit operator mint(int i) { return new mint(i); }
public static implicit operator mint(long i) { return new mint(i); }
private static mint[] _fact;
public static void SetFact(int n) {
_fact = new mint[n + 1];
_fact[0] = 1;
for (int i = 1; i < n + 1; i++) {
_fact[i] = _fact[i - 1] * i;
}
}
public static mint Fact(int n) {
if (_fact == null || _fact.Length < n) {
SetFact(n * 2);
}
return _fact[n];
}
public static mint Combination(int n, int r) {
return Fact(n) / (Fact(n - r) * Fact(r));
}
}
static class Extensions {
public static int LowerBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c > 0)
l = m + 1;
else
r = m;
}
return l;
}
public static int UpperBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c >= 0)
l = m + 1;
else
r = m;
}
return r;
}
}
class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
public static int[] ZAlgotithm(string s) {
var len = s.Length;
var a = new int[len];
a[0] = len;
var i = 1;
var j = 0;
while (i < len) {
while (i + j < len && s[j] == s[i + j])
j++;
a[i] = j;
if (j == 0) {
i++;
continue;
}
var k = 1;
while (i + k < len && k + a[k] < j) {
a[i + k] = a[k];
k++;
}
i += k;
j -= k;
}
return a;
}
public class MaxHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MaxHeap() : this(0) {}
public MaxHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c > 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) < 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MaxHeap<T> Copy(Comparison<T> comp = null) {
var c = new MaxHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MaxHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
public class MinHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MinHeap() : this(0) {}
public MinHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c < 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) > 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MinHeap<T> Copy(Comparison<T> comp = null) {
var c = new MinHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MinHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class InputLine {
private string[] _inputs;
private int _index = 0;
InputLine(string input) {
_inputs = input.Split();
_index = 0;
}
public static InputLine Read() { return new InputLine(Console.ReadLine()); }
public int NextInt() { return int.Parse(_inputs[_index++]); }
public long NextLong() { return long.Parse(_inputs[_index++]); }
public double NextDouble() { return double.Parse(_inputs[_index++]); }
}
public static int GCD(int x, int y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
public static long GCD(long x, long y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
static long ModPower(long x, long y, long mod) {
var bytes = BitConverter.GetBytes(y);
var bits = new System.Collections.BitArray(bytes);
var max2 = 0;
for (int i = bits.Length - 1; i >= 0; i--) {
if (bits[i]) {
max2 = i;
break;
}
}
long result = 1;
for (int i = max2; i >= 0; i--) {
result = (result * result) % mod;
if (bits[i]) {
result = (result * x) % mod;
}
}
return result;
}
static long ModFact(long n, long mod) {
long result = 1;
for (int i = 1; i <= n; i++) {
result = result * i % mod;
}
return result;
}
static long ModAdd(long x, long y, long mod) {
return ((x % mod) + (y % mod)) % mod;
}
static long ModMul(long x, long y, long mod) {
return ((x % mod) * (y % mod)) % mod;
}
static long ModDiv(long x, long y, long mod) {
//ใใงใซใใผใฎๅฐๅฎ็ใใใa^(-1) = a^(p-2)
return ModMul(x, ModPower(y, mod - 2, mod), mod);
}
static long ModComb(long n, long r, long mod) {
long numerator = 1;
for (int i = 0; i < r; i++) {
numerator = ModMul(numerator, n - i, mod);
}
long denominator = ModFact(r, mod);
return ModDiv(numerator, denominator, mod);
}
class Graph {
private int _size;
private List<int>[] _edges;
public Graph(int size) {
_size = size;
_edges = new List<int>[size];
}
public List<int> this[int i] {
get {
if (_edges[i] == null)
_edges[i] = new List<int>();
return _edges[i];
}
}
}
class Graph<T> {
private int _size;
private List<T>[] _edges;
public Graph(int size) {
_size = size;
_edges = new List<T>[size];
}
public List<T> this[int i] {
get {
if (_edges[i] == null)
_edges[i] = new List<T>();
return _edges[i];
}
}
}
static Graph<T> NewGraph<T>(int size, T template) {
return new Graph<T>(size);
}
static List<T> NewList<T>(T template) { return new List<T>(); }
static T[] NewArray<T>(int size, T template) { return new T[size]; }
static long p1097 = 1000000007;
static void Main(string[] args) {
//โ
var n = ReadInt();
var s = Console.ReadLine();
var next = 'A';
var count = 0;
for (int i = 0; i < n; i++) {
var c = s[i];
if (c == next) {
if (next == 'A') {
next = 'B';
} else if (next == 'B') {
next = 'C';
} else if (next == 'C') {
count++;
next = 'A';
}
} else {
if (c == 'A') {
next = 'B';
continue;
}
next = 'A';
}
}
Console.WriteLine(count);
//โ
}
}
}
|
[["+", 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, 252, 0, 104], ["+", 64, 196, 0, 1, 0, 11, 12, 252, 0, 253], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 3,519
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;
public class Prog {
public struct Pair {
public int x, y;
public Pair(int a, int b) {
y = a;
x = b;
}
}
public static void Solve() {
int N = NextInt();
string s = NextString();
int ans = 0;
for (int i = 3; i < N; i++)
if (s[i - 2].ToString() + s[i - 1].ToString() + s[i].ToString() == "ABC")
ans++;
Console.WriteLine(ans);
}
public static long GCD(long a, long b) {
if (a < b)
GCD(b, a);
long d = a % b;
while (b != 0) {
d = a % b;
a = b;
b = d;
}
return a;
}
public static long LCM(long a, long b) { return a / GCD(a, b) * b; }
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
return;
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
public long Abs(long a, long b) => Math.Abs(a - b);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;
public class Prog {
public struct Pair {
public int x, y;
public Pair(int a, int b) {
y = a;
x = b;
}
}
public static void Solve() {
int N = NextInt();
string s = NextString();
int ans = 0;
for (int i = 2; i < N; i++)
if (s[i - 2].ToString() + s[i - 1].ToString() + s[i].ToString() == "ABC")
ans++;
Console.WriteLine(ans);
}
public static long GCD(long a, long b) {
if (a < b)
GCD(b, a);
long d = a % b;
while (b != 0) {
d = a % b;
a = b;
b = d;
}
return a;
}
public static long LCM(long a, long b) { return a / GCD(a, b) * b; }
public static void Main() {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
return;
}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
public long Abs(long a, long b) => Math.Abs(a - b);
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 603
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
class Program {
static void Main(string[] args) { new Program().Calc(); }
Scanner cin;
public Program() {}
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 Calc() {
cin = new Scanner();
int n = cin.nextInt();
string s = cin.next();
char[] s_ = s.ToCharArray();
int ans = 0;
for (int i = 0; i < n; ++i) {
if (s_[i] == 'A' && s_[i + 1] == 'B' && s_[i + 2] == 'C')
ans++;
}
WriteLine(ans);
}
}
public static class StringExtension {
public static char GetChar1(this string str, int indexOneBase) {
return str[indexOneBase - 1];
}
}
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 static System.Console;
class Program {
static void Main(string[] args) { new Program().Calc(); }
Scanner cin;
public Program() {}
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 Calc() {
cin = new Scanner();
int n = cin.nextInt();
string s = cin.next();
char[] s_ = s.ToCharArray();
int ans = 0;
for (int i = 0; i < n - 2; ++i) {
if (s_[i] == 'A' && s_[i + 1] == 'B' && s_[i + 2] == 'C')
ans++;
}
WriteLine(ans);
}
}
public static class StringExtension {
public static char GetChar1(this string str, int indexOneBase) {
return str[indexOneBase - 1];
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 638
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
// functions
public void Solve() {
//ใใใใ
var n = IO.int1;
var s = IO.str;
int ans = 0;
for (int i = 0; i < n - 3; ++i) {
if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
ans++;
}
IO.wri(ans);
}
}
// b-aใง้้
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public double[] doublem => strm.Select(double.Parse).ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
public double double1 => doublem[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("No");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
// functions
public void Solve() {
//ใใใใ
var n = IO.int1;
var s = IO.str;
int ans = 0;
for (int i = 0; i < n - 2; ++i) {
if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
ans++;
}
IO.wri(ans);
}
}
// b-aใง้้
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public double[] doublem => strm.Select(double.Parse).ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
public double double1 => doublem[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("No");
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 914
| 2
|
using System;
namespace ABC150B {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
var count = 0;
for (var i = 0; i < N - 3; i++) {
if (S.Substring(i, 3) == "ABC") {
++count;
}
}
System.Console.WriteLine("{0}", count);
Console.ReadLine();
}
}
}
|
using System;
namespace ABC150B {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
var count = 0;
for (var i = 0; i < N - 2; i++) {
if (S.Substring(i, 3) == "ABC") {
++count;
}
}
System.Console.WriteLine("{0}", count);
Console.ReadLine();
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 107
| 2
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public void Solve() {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
var answer = 0;
for (int i = 0; i < S.Length - 3; i++) {
if (S[i + 0] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
answer++;
}
}
Console.WriteLine(answer);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public void Solve() {
var N = int.Parse(Console.ReadLine());
var S = Console.ReadLine();
var answer = 0;
for (int i = 0; i < S.Length - 2; i++) {
if (S[i + 0] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
answer++;
}
}
Console.WriteLine(answer);
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 215
| 2
|
using System;
class ProgramB {
static void Main(string[] args) {
//ๅ
ฅๅ
string input = Console.ReadLine();
long n = long.Parse(input);
string s = Console.ReadLine();
long count = 0;
for (int i = 0; i < n - 2; i++) {
if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
count++;
i += i + 2;
}
}
Console.WriteLine(count);
}
}
|
using System;
class ProgramB {
static void Main(string[] args) {
//ๅ
ฅๅ
string input = Console.ReadLine();
long n = long.Parse(input);
string s = Console.ReadLine();
long count = 0;
for (int i = 0; i < n - 2; i++) {
if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
count++;
i += 2;
}
}
Console.WriteLine(count);
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
| 8
| 121
| 2
|
using System;
public class Program {
public void Solve() {
var sc = new Scanner();
int n = sc.NextInt();
string s = sc.Next();
int cnt = 0;
for (int i = 0; i < s.Length - 3; i++) {
if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
cnt++;
}
}
Console.WriteLine(cnt);
}
public static void Main(string[] args) { new Program().Solve(); }
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region ในใใผในๅบๅใใงๅๅพ
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region ๅๅคๆ
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region ้
ๅๅๅพ
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
using System;
public class Program {
public void Solve() {
var sc = new Scanner();
int n = sc.NextInt();
string s = sc.Next();
int cnt = 0;
for (int i = 0; i + 2 < s.Length; i++) {
if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
cnt++;
}
}
Console.WriteLine(cnt);
}
public static void Main(string[] args) { new Program().Solve(); }
}
class Scanner {
public Scanner() {
_pos = 0;
_line = new string[0];
}
const char Separator = ' ';
private int _pos;
private string[] _line;
#region ในใใผในๅบๅใใงๅๅพ
public string Next() {
if (_pos >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_pos = 0;
}
return _line[_pos++];
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
#endregion
#region ๅๅคๆ
private int[] ToIntArray(string[] array) {
var result = new int[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = int.Parse(array[i]);
}
return result;
}
private long[] ToLongArray(string[] array) {
var result = new long[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = long.Parse(array[i]);
}
return result;
}
private double[] ToDoubleArray(string[] array) {
var result = new double[array.Length];
for (int i = 0; i < array.Length; i++) {
result[i] = double.Parse(array[i]);
}
return result;
}
#endregion
#region ้
ๅๅๅพ
public string[] Array() {
if (_pos >= _line.Length)
_line = Console.ReadLine().Split(Separator);
_pos = _line.Length;
return _line;
}
public int[] IntArray() { return ToIntArray(Array()); }
public long[] LongArray() { return ToLongArray(Array()); }
public double[] DoubleArray() { return ToDoubleArray(Array()); }
#endregion
}
|
[["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 549
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var n = ReadInt();
var s = Read();
var ans = 0;
for (int i = 0; i < n - 3; i++) {
if (s[i].ToString() + s[i + 1].ToString() + s[i + 2].ToString() ==
"ABC") {
ans++;
}
}
WriteLine(ans);
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var n = ReadInt();
var s = Read();
var ans = 0;
for (int i = 0; i < n - 2; i++) {
if (s[i].ToString() + s[i + 1].ToString() + s[i + 2].ToString() ==
"ABC") {
ans++;
}
}
WriteLine(ans);
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 312
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var S = sc.ReadStr();
var ans = 0;
for (int i = 0; i < N - 3; i++) {
var s = S.Substring(i, 3);
if (s == "ABC")
ans++;
}
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.ReadStr();
var ans = 0;
for (int i = 0; i < N - 2; i++) {
var s = S.Substring(i, 3);
if (s == "ABC")
ans++;
}
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, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 1,072
| 2
|
using System;
using System.Collections.Generic;
namespace cswork {
class Program {
public Program() {}
Scanner cin;
const int MAXIN = 1024;
bool[] used = new bool[MAXIN];
int[] perm = new int[MAXIN];
List<string> permList = new List<string>();
void Omame() {
cin = new Scanner();
int n = cin.nextInt();
string p = "";
for (int i = 0; i < n; i++) {
string pp = cin.next();
p += pp + " ";
}
p = p.Substring(0, p.Length - 1);
string q = "";
for (int i = 0; i < n; i++) {
string qq = cin.next();
q += qq + " ";
}
q = q.Substring(0, q.Length - 1);
Permutation(0, n, n);
int a = 0;
int b = 0;
for (int i = 0; i < permList.Count; i++) {
if (permList[i].Equals(p)) {
a = i;
} else if (permList[i].Equals(q)) {
b = i;
}
}
Console.WriteLine(Math.Abs(a - b));
}
static void Main(string[] args) { new Program().Omame(); }
public void Permutation(int pos, int n, int length) {
if (pos == n) {
string s = "";
for (int i = 0; i < n; i++) {
s += (perm[i] + 1) + " ";
}
s = s.Substring(0, s.Length - 1);
permList.Add(s);
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
perm[pos] = i;
used[i] = true;
Permutation(pos + 1, n, length);
used[i] = false;
}
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
}
|
using System;
using System.Collections.Generic;
namespace cswork {
class Program {
public Program() {}
Scanner cin;
const int MAXIN = 1024;
bool[] used = new bool[MAXIN];
int[] perm = new int[MAXIN];
List<string> permList = new List<string>();
void Omame() {
cin = new Scanner();
int n = cin.nextInt();
string p = "";
for (int i = 0; i < n; i++) {
string pp = cin.next();
p += pp + " ";
}
p = p.Substring(0, p.Length - 1);
string q = "";
for (int i = 0; i < n; i++) {
string qq = cin.next();
q += qq + " ";
}
q = q.Substring(0, q.Length - 1);
Permutation(0, n, n);
int a = 0;
int b = 0;
for (int i = 0; i < permList.Count; i++) {
if (permList[i].Equals(p)) {
a = i;
}
if (permList[i].Equals(q)) {
b = i;
}
}
Console.WriteLine(Math.Abs(a - b));
}
static void Main(string[] args) { new Program().Omame(); }
public void Permutation(int pos, int n, int length) {
if (pos == n) {
string s = "";
for (int i = 0; i < n; i++) {
s += (perm[i] + 1) + " ";
}
s = s.Substring(0, s.Length - 1);
permList.Add(s);
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
perm[pos] = i;
used[i] = true;
Permutation(pos + 1, n, length);
used[i] = false;
}
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
| 8
| 611
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;
namespace CP {
class Atria {
static void Main(string[] args) {
int n = int.Parse(ReadLine());
int[] p = ReadLine().Split(' ').Select(int.Parse).ToArray();
int[] q = ReadLine().Split(' ').Select(int.Parse).ToArray();
var s = new List<int>();
for (int i = 0; i < n; i++) {
s.Add(i + 1);
}
var parm = Permutation<int>.Make(s).ToList();
int pb = -1;
int qb = -1;
int j = 0;
while (pb == -1 || qb == -1) {
j++;
if (parm[j].SequenceEqual(p)) {
pb = j;
}
if (parm[j].SequenceEqual(q)) {
qb = j;
}
}
WriteLine(Abs(pb - qb));
}
}
static class Permutation<T> {
private static void Search(List<T[]> perms, Stack<T> stack, T[] a) {
int N = a.Length;
if (N == 0) {
perms.Add(stack.Reverse().ToArray());
} else {
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i) {
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) {
b[i] = a[i];
}
stack.Pop();
}
}
}
/// <summary>
/// ้
ๅใไธใใใจList<T>ใง้ ๅ็ตใฟๅใใใ่ฟใใ
/// </summary>
/// <param name="src"></param>
/// <returns></returns>
public static IEnumerable<T[]> Make(IEnumerable<T> src) {
var perms = new List<T[]>();
Search(perms, new Stack<T>(), src.ToArray());
return perms;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;
namespace CP {
class Atria {
static void Main(string[] args) {
int n = int.Parse(ReadLine());
int[] p = ReadLine().Split(' ').Select(int.Parse).ToArray();
int[] q = ReadLine().Split(' ').Select(int.Parse).ToArray();
var s = new List<int>();
for (int i = 0; i < n; i++) {
s.Add(i + 1);
}
var parm = Permutation<int>.Make(s).ToList();
int pb = -1;
int qb = -1;
int j = 0;
while (pb == -1 || qb == -1) {
if (parm[j].SequenceEqual(p)) {
pb = j;
}
if (parm[j].SequenceEqual(q)) {
qb = j;
}
j++;
}
WriteLine(Abs(pb - qb));
}
}
static class Permutation<T> {
private static void Search(List<T[]> perms, Stack<T> stack, T[] a) {
int N = a.Length;
if (N == 0) {
perms.Add(stack.Reverse().ToArray());
} else {
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i) {
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) {
b[i] = a[i];
}
stack.Pop();
}
}
}
/// <summary>
/// ้
ๅใไธใใใจList<T>ใง้ ๅ็ตใฟๅใใใ่ฟใใ
/// </summary>
/// <param name="src"></param>
/// <returns></returns>
public static IEnumerable<T[]> Make(IEnumerable<T> src) {
var perms = new List<T[]>();
Search(perms, new Stack<T>(), src.ToArray());
return perms;
}
}
}
|
[["-", 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
| 471
| 6
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ABC150C {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var PList = string.Join("", NNList(N));
var QList = string.Join("", NNList(N));
var list = LIB_Math.MakePermutation(N, false)
.Select(e => string.Join("", e))
.OrderBy(e => e)
.ToList();
var a = 0;
var b = 0;
for (var i = 0; i < list.Count; i++) {
if (PList == list[i])
a = i;
else if (QList == list[i])
b = i;
}
Console.WriteLine(Abs(a - b));
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
}
}
namespace Library {
class LIB_Math {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2) {
while (x % i == 0) {
x /= i;
yield return i;
}
}
if (x != 1)
yield return x;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long LCM(long a, long b) => a * b / GCD(a, b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void Build(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Comb(long n, long k) {
Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Perm(long n, long k) {
Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public IEnumerable<List<int>>
MakePermutation(long n, bool zeroIndexed = true) {
if (n <= 0)
throw new Exception();
var c = new int[n];
var a = new int[n];
if (!zeroIndexed)
a[0] = 1;
for (var i = 1; i < n; i++)
a[i] = a[i - 1] + 1;
yield return new List<int>(a);
for (var i = 0; i < n;) {
if (c[i] < i) {
if (i % 2 == 0) {
var t = a[0];
a[0] = a[i];
a[i] = t;
} else {
var t = a[c[i]];
a[c[i]] = a[i];
a[i] = t;
}
yield return new List<int>(a);
++c[i];
i = 0;
} else {
c[i] = 0;
++i;
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ABC150C {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var PList = string.Join("", NNList(N));
var QList = string.Join("", NNList(N));
var list = LIB_Math.MakePermutation(N, false)
.Select(e => string.Join("", e))
.OrderBy(e => e)
.ToList();
var a = 0;
var b = 0;
for (var i = 0; i < list.Count; i++) {
if (PList == list[i])
a = i;
if (QList == list[i])
b = i;
}
Console.WriteLine(Abs(a - b));
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
}
}
namespace Library {
class LIB_Math {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2) {
while (x % i == 0) {
x /= i;
yield return i;
}
}
if (x != 1)
yield return x;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long LCM(long a, long b) => a * b / GCD(a, b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void Build(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Comb(long n, long k) {
Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Perm(long n, long k) {
Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public IEnumerable<List<int>>
MakePermutation(long n, bool zeroIndexed = true) {
if (n <= 0)
throw new Exception();
var c = new int[n];
var a = new int[n];
if (!zeroIndexed)
a[0] = 1;
for (var i = 1; i < n; i++)
a[i] = a[i - 1] + 1;
yield return new List<int>(a);
for (var i = 0; i < n;) {
if (c[i] < i) {
if (i % 2 == 0) {
var t = a[0];
a[0] = a[i];
a[i] = t;
} else {
var t = a[c[i]];
a[c[i]] = a[i];
a[i] = t;
}
yield return new List<int>(a);
++c[i];
i = 0;
} else {
c[i] = 0;
++i;
}
}
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
| 8
| 1,802
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
var N = sc.Int;
var C = sc.ArrInt;
Array.Sort(C, (a, b) => b - a);
ModInt res = 0;
for (var i = 1; i <= N; i++)
res += C[i - 1] * (i + 1);
WriteLine(res * ModInt.Pow(4, N - 1));
}
}
public struct ModInt {
public const long MOD = (int)1e9 + 7;
// public const long MOD = 998244353;
public long Value { get; set; }
public ModInt(long n = 0) { Value = n; }
private static ModInt[] fac; //้ไน
private static ModInt[] inv; //้ๆฐ
private static ModInt[] facinv; // 1/(i!)
public override string ToString() => Value.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt l, ModInt r) {
l.Value += r.Value;
if (l.Value >= MOD)
l.Value -= MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt l, ModInt r) {
l.Value -= r.Value;
if (l.Value < 0)
l.Value += MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt
operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt l) => l.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long n) {
n %= MOD;
if (n < 0)
n += MOD;
return new ModInt(n);
}
public static ModInt Pow(ModInt m, long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return Pow(m * m, n >> 1);
else
return Pow(m * m, n >> 1) * m;
}
public static void Build(int n) {
fac = new ModInt[n + 1];
facinv = new ModInt[n + 1];
inv = new ModInt[n + 1];
inv[1] = 1;
fac[0] = fac[1] = 1;
facinv[0] = facinv[1] = 1;
for (var i = 2; i <= n; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = MOD - inv[MOD % i] * (MOD / i);
facinv[i] = facinv[i - 1] * inv[i];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Fac(ModInt n) => fac[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Inv(ModInt n) => inv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt FacInv(ModInt n) => facinv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Comb(ModInt n, ModInt r) {
if (n < r)
return 0;
if (n == r)
return 1;
var calc = fac[n];
calc = calc * facinv[r];
calc = calc * facinv[n - r];
return calc;
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static T[] Copy<T>(this T[] A) => Create(A.Length, idx => A[idx]);
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(),
Next<T2>());
public Pair<T1, T2, T3> PairMake<T1, T2, T3>() =>
new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Tie(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Tie(out T1 a, out T2 b, out T3 c) {
Tie(out a, out b);
c = v3;
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
var N = sc.Int;
var C = sc.ArrInt;
Array.Sort(C, (a, b) => b - a);
ModInt res = 0;
for (var i = 1; i <= N; i++)
res += C[i - 1] * (i + (ModInt)1);
WriteLine(res * ModInt.Pow(4, N - 1));
}
}
public struct ModInt {
public const long MOD = (int)1e9 + 7;
// public const long MOD = 998244353;
public long Value { get; set; }
public ModInt(long n = 0) { Value = n; }
private static ModInt[] fac; //้ไน
private static ModInt[] inv; //้ๆฐ
private static ModInt[] facinv; // 1/(i!)
public override string ToString() => Value.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt l, ModInt r) {
l.Value += r.Value;
if (l.Value >= MOD)
l.Value -= MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt l, ModInt r) {
l.Value -= r.Value;
if (l.Value < 0)
l.Value += MOD;
return l;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt
operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt l) => l.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long n) {
n %= MOD;
if (n < 0)
n += MOD;
return new ModInt(n);
}
public static ModInt Pow(ModInt m, long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return Pow(m * m, n >> 1);
else
return Pow(m * m, n >> 1) * m;
}
public static void Build(int n) {
fac = new ModInt[n + 1];
facinv = new ModInt[n + 1];
inv = new ModInt[n + 1];
inv[1] = 1;
fac[0] = fac[1] = 1;
facinv[0] = facinv[1] = 1;
for (var i = 2; i <= n; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = MOD - inv[MOD % i] * (MOD / i);
facinv[i] = facinv[i - 1] * inv[i];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Fac(ModInt n) => fac[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Inv(ModInt n) => inv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt FacInv(ModInt n) => facinv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Comb(ModInt n, ModInt r) {
if (n < r)
return 0;
if (n == r)
return 1;
var calc = fac[n];
calc = calc * facinv[r];
calc = calc * facinv[n - r];
return calc;
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static T[] Copy<T>(this T[] A) => Create(A.Length, idx => A[idx]);
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(),
Next<T2>());
public Pair<T1, T2, T3> PairMake<T1, T2, T3>() =>
new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Tie(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Tie(out T1 a, out T2 b, out T3 c) {
Tie(out a, out b);
c = v3;
}
}
#endregion
|
[["+", 12, 16, 12, 23, 0, 16, 12, 74, 0, 24], ["+", 12, 16, 12, 23, 0, 16, 12, 74, 39, 22], ["+", 12, 16, 12, 23, 0, 16, 12, 74, 0, 25]]
| 8
| 2,236
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0035 {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
var result = s.Split(' ')[0] + s.Split(' ')[1];
Console.WriteLine(result);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atc_0035 {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
var result = s.Split(' ')[1] + s.Split(' ')[0];
Console.WriteLine(result);
}
}
}
|
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 89
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
var inputArray = retreiveStringArray();
var inputCount = 2;
// ไธๆญฃใชๅ
ฅๅใฏๅฆ็ใใชใ
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
var N = inputArray[0];
var K = inputArray[1];
//็ญใใฎๅบๅ
var ans = N + K;
Console.WriteLine(ans);
}
/// <summary>
/// ๅใๆใๅบใใชใใใจใซใใฃใฆ็ใใๆๅคฑ็นๆฐ
/// </summary>
/// <param name="K"></param>
/// <param name="point"></param>
/// <param name="jankenList"></param>
/// <returns></returns>
private static long calLossPoint(long K, long point,
HashSet<long> jankenList) {
var changeList = new HashSet<
long>(); // K็ชๅ
ใซๅใๆใใใๅ ดๅใๆธใๆใใใๆธใๆใใ็ชๅทใ่ฆใใฆใใใชในใ
var count = 0;
foreach (var r in jankenList) {
if (changeList.Contains(r)) {
continue;
}
if (jankenList.Contains(r + K)) {
count++;
changeList.Add(r + K);
}
}
return point * count;
}
/// <summary>
/// ในใใผในใงๅบๅใใใๆๅญๅ้
ๅใฎๅ
ฅๅใๅใๅใ
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// ในใใผในใงๅบๅใใใๆดๆฐ้
ๅใฎๅ
ฅๅใๅใๅใ
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
var inputArray = retreiveStringArray();
var inputCount = 2;
// ไธๆญฃใชๅ
ฅๅใฏๅฆ็ใใชใ
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
var N = inputArray[0];
var K = inputArray[1];
//็ญใใฎๅบๅ
var ans = K + N;
Console.WriteLine(ans);
}
/// <summary>
/// ๅใๆใๅบใใชใใใจใซใใฃใฆ็ใใๆๅคฑ็นๆฐ
/// </summary>
/// <param name="K"></param>
/// <param name="point"></param>
/// <param name="jankenList"></param>
/// <returns></returns>
private static long calLossPoint(long K, long point,
HashSet<long> jankenList) {
var changeList = new HashSet<
long>(); // K็ชๅ
ใซๅใๆใใใๅ ดๅใๆธใๆใใใๆธใๆใใ็ชๅทใ่ฆใใฆใใใชในใ
var count = 0;
foreach (var r in jankenList) {
if (changeList.Contains(r)) {
continue;
}
if (jankenList.Contains(r + K)) {
count++;
changeList.Add(r + K);
}
}
return point * count;
}
/// <summary>
/// ในใใผในใงๅบๅใใใๆๅญๅ้
ๅใฎๅ
ฅๅใๅใๅใ
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// ในใใผในใงๅบๅใใใๆดๆฐ้
ๅใฎๅ
ฅๅใๅใๅใ
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
| 8
| 293
| 4
|
using System;
namespace ConsoleApp11 {
class MainClass {
public static void Main() {
string[] S = Console.ReadLine().Split();
string A = S[0];
string B = S[1];
string R;
R = A + B;
Console.WriteLine(R);
}
}
}
|
using System;
namespace ConsoleApp11 {
class MainClass {
public static void Main() {
string[] S = Console.ReadLine().Split();
string A = S[0];
string B = S[1];
string R;
R = B + A;
Console.WriteLine(R);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 66
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace cswork {
class Program {
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);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
public Program() {}
static void Main(string[] args) { new Program().Omame(); }
Scanner cin;
const int MAXIN = 1024;
bool[] used = new bool[MAXIN];
int[] perm = new int[MAXIN];
List<int[]> permList = new List<int[]>();
public void Permutation(int pos, int n, int length) {
if (pos == n) {
permList.Add((int[])perm.Clone());
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
perm[pos] = i;
used[i] = true;
Permutation(pos + 1, n, length);
used[i] = false;
}
}
}
public static List<long> GeneratePrime(long max) {
long prime;
double sqrtMax = Math.Sqrt(max);
var primeList = new List<long>();
List<long> searchList = new List<long>();
for (long i = 2; i <= max - 1; i++) {
searchList.Add(i);
}
do {
prime = searchList.First();
primeList.Add(prime);
searchList.RemoveAll(n => n % prime == 0);
} while (prime < sqrtMax);
primeList.AddRange(searchList);
return primeList;
}
void Omame() {
cin = new Scanner();
string S = cin.next();
string T = cin.next();
Console.WriteLine(S + T);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace cswork {
class Program {
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);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
public Program() {}
static void Main(string[] args) { new Program().Omame(); }
Scanner cin;
const int MAXIN = 1024;
bool[] used = new bool[MAXIN];
int[] perm = new int[MAXIN];
List<int[]> permList = new List<int[]>();
public void Permutation(int pos, int n, int length) {
if (pos == n) {
permList.Add((int[])perm.Clone());
}
for (int i = 0; i < n; i++) {
if (!used[i]) {
perm[pos] = i;
used[i] = true;
Permutation(pos + 1, n, length);
used[i] = false;
}
}
}
public static List<long> GeneratePrime(long max) {
long prime;
double sqrtMax = Math.Sqrt(max);
var primeList = new List<long>();
List<long> searchList = new List<long>();
for (long i = 2; i <= max - 1; i++) {
searchList.Add(i);
}
do {
prime = searchList.First();
primeList.Add(prime);
searchList.RemoveAll(n => n % prime == 0);
} while (prime < sqrtMax);
primeList.AddRange(searchList);
return primeList;
}
void Omame() {
cin = new Scanner();
string S = cin.next();
string T = cin.next();
Console.WriteLine(T + S);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 528
| 4
|
using System;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().ToArray();
Console.WriteLine(input[1] + " " + input[0]);
}
}
}
|
using System;
using System.Linq;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().ToArray();
Console.WriteLine(input[1] + input[0]);
}
}
}
|
[["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
| 8
| 63
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoderCs {
class Program {
static void Main() {
Console.WriteLine(string.Concat(Console.ReadLine().Split(' ')));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoderCs {
class Program {
static void Main() {
Console.WriteLine(string.Concat(Console.ReadLine().Split(' ').Reverse()));
}
}
}
|
[["+", 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
| 53
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A {
class Program {
public static void Main(string[] args) {
var s = ReadLineStringSplit();
Console.WriteLine(s[0] + s[1]);
ReadLine();
}
/// <summary>
/// ใณใณใใใผใทใงใณ
/// </summary>
/// <param name="n"></param>
/// <param name="m"></param>
/// <returns></returns>
static int nCm(int n, int m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * nCm(n - 1, m - 1) / m;
}
/// <summary>
/// stringใไธๆๅญใใคintใซใญใฃในใใใฆ้
ๅใซๅคๆใใพใใ
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static int[] StringCharArrayIntArray(string str) {
List<int> b = new List<int>();
for (int i = 0; i < str.Length; i++) {
b.Add(int.Parse(str[i].ToString()));
}
return b.ToArray();
}
public static string ReadLine() { return Console.ReadLine(); }
public static int ReadLineInt() { return int.Parse(Console.ReadLine()); }
public static string[] ReadLineStringSplit(char a = ' ') {
return ReadLine().Split(a).ToArray();
}
public static int[] ReadLineIntSpilit(char a = ' ') {
return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
}
static string[] GetAplhaLowerArray() => new string[] {
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
};
static string[] GetAplhaUpperArray() => new string[] {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
};
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A {
class Program {
public static void Main(string[] args) {
var s = ReadLineStringSplit();
Console.WriteLine(s[1] + s[0]);
ReadLine();
}
/// <summary>
/// ใณใณใใใผใทใงใณ
/// </summary>
/// <param name="n"></param>
/// <param name="m"></param>
/// <returns></returns>
static int nCm(int n, int m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * nCm(n - 1, m - 1) / m;
}
/// <summary>
/// stringใไธๆๅญใใคintใซใญใฃในใใใฆ้
ๅใซๅคๆใใพใใ
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static int[] StringCharArrayIntArray(string str) {
List<int> b = new List<int>();
for (int i = 0; i < str.Length; i++) {
b.Add(int.Parse(str[i].ToString()));
}
return b.ToArray();
}
public static string ReadLine() { return Console.ReadLine(); }
public static int ReadLineInt() { return int.Parse(Console.ReadLine()); }
public static string[] ReadLineStringSplit(char a = ' ') {
return ReadLine().Split(a).ToArray();
}
public static int[] ReadLineIntSpilit(char a = ' ') {
return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
}
static string[] GetAplhaLowerArray() => new string[] {
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
};
static string[] GetAplhaUpperArray() => new string[] {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
};
}
}
|
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 543
| 4
|
using System;
class ABC149_A {
static void Main(string[] args) {
string[] str1 = Console.ReadLine().Split(' ');
string str2 = str1[0] + str1[1];
Console.WriteLine(str2);
}
}
|
using System;
class ABC149_A {
static void Main(string[] args) {
string[] str1 = Console.ReadLine().Split(' ');
string str2 = str1[1] + str1[0];
Console.WriteLine(str2);
}
}
|
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 56
| 4
|
using System;
namespace ABC149 {
public class MainClass {
public static void Main(string[] args) {
string[] inp = Console.ReadLine().Split(' ');
Console.WriteLine(inp[0] + inp[1]);
}
}
}
|
using System;
namespace ABC149 {
public class MainClass {
public static void Main(string[] args) {
string[] inp = Console.ReadLine().Split(' ');
Console.WriteLine(inp[1] + inp[0]);
}
}
}
|
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 57
| 4
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class ABC {
static readonly int mod = 1000000007; // 10^9+7
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
string s = Console.ReadLine();
// int n = int.Parse(Console.ReadLine());
// long n = long.Parse(Console.ReadLine());
// int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
// long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
Console.WriteLine(string.Join("", s.Split()));
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder {
public class ABC {
static readonly int mod = 1000000007; // 10^9+7
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
string s = Console.ReadLine();
// int n = int.Parse(Console.ReadLine());
// long n = long.Parse(Console.ReadLine());
// int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
// long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
Console.WriteLine(string.Join("", s.Split().Reverse()));
Console.Out.Flush();
}
}
}
|
[["+", 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
| 120
| 4
|
using System;
namespace Strings {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine();
var inputs = input.Split();
Console.WriteLine(inputs[0] + inputs[1]);
}
}
}
|
using System;
namespace Strings {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine();
var inputs = input.Split();
Console.WriteLine(inputs[1] + inputs[0]);
}
}
}
|
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 55
| 4
|
using System;
namespace AtCoder {
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
Console.WriteLine(input[0] + input[1]);
}
}
}
|
using System;
namespace AtCoder {
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
Console.WriteLine(input[1] + input[0]);
}
}
}
|
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 51
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
string[] S = Console.ReadLine().Split(' ');
Console.WriteLine(S[0] + S[1]);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
string[] S = Console.ReadLine().Split(' ');
Console.WriteLine(S[1] + S[0]);
}
}
|
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 59
| 4
|
using System;
using System.Linq;
namespace AtCoder_Begginer_Contest1 {
class Program {
static void Main(string[] args) {
string[] ST = Console.ReadLine().Split();
string S = ST[0];
string T = ST[1];
string ans = S + T;
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
namespace AtCoder_Begginer_Contest1 {
class Program {
static void Main(string[] args) {
string[] ST = Console.ReadLine().Split();
string S = ST[0];
string T = ST[1];
string ans = T + S;
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
| 8
| 72
| 4
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var list = Console.ReadLine().Split(' ');
Console.WriteLine(list[0] + list[1]);
}
}
}
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var list = Console.ReadLine().Split(' ');
Console.WriteLine(list[1] + list[0]);
}
}
}
|
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 53
| 4
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
namespace atcoder_past_problem {
class Program {
static void Main(string[] args) {
new Program().Solve(new Input(Console.In));
}
public void Solve(Input input) {
var a = input.Read;
var b = input.Read;
Console.WriteLine($"{a}{b}");
}
}
public class Input {
private TextReader Stream { get; }
private char Separator { get; }
private Queue<string> InputStream { get; }
public Input(TextReader stream, char separator = ' ') {
Stream = stream;
Separator = separator;
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 => Stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => double.Parse(Read);
public int[] ReadIntArray =>
Stream.ReadLine().Split(Separator).Select(i => int.Parse(i)).ToArray();
public long[] ReadLongArray =>
Stream.ReadLine().Split(Separator).Select(l => long.Parse(l)).ToArray();
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
namespace atcoder_past_problem {
class Program {
static void Main(string[] args) {
new Program().Solve(new Input(Console.In));
}
public void Solve(Input input) {
var a = input.Read;
var b = input.Read;
Console.WriteLine($"{b}{a}");
}
}
public class Input {
private TextReader Stream { get; }
private char Separator { get; }
private Queue<string> InputStream { get; }
public Input(TextReader stream, char separator = ' ') {
Stream = stream;
Separator = separator;
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 => Stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => double.Parse(Read);
public int[] ReadIntArray =>
Stream.ReadLine().Split(Separator).Select(i => int.Parse(i)).ToArray();
public long[] ReadLongArray =>
Stream.ReadLine().Split(Separator).Select(l => long.Parse(l)).ToArray();
}
}
|
[["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22]]
| 8
| 342
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var res = new List<int>();
int i = 0;
int idx = 0;
while (i < n) {
for (int j = idx + 1; j < a.Length; j++) {
if (a[j] == i + 1) {
res.Add(a[j]);
idx = j;
break;
}
}
if (res.Count() != i + 1)
break;
else
i++;
}
Console.WriteLine(res.Count() == 0 ? -1 : n - res.Count());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var res = new List<int>();
int i = 0;
int idx = 0;
while (i < n) {
for (int j = idx; j < a.Length; j++) {
if (a[j] == i + 1) {
res.Add(a[j]);
idx = j;
break;
}
}
if (res.Count() != i + 1)
break;
else
i++;
}
Console.WriteLine(res.Count() == 0 ? -1 : n - res.Count());
}
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 195
| 2
|
using System;
namespace AtCoder {
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int search_index = 1;
int broken_count = 0;
int check_count = 0;
for (int i = 0; i < input.Length; i++) {
if (int.Parse(input[i]) == search_index) {
search_index++;
} else {
broken_count++;
}
check_count++;
}
if (broken_count == check_count) {
Console.WriteLine(-2);
} else if (search_index == check_count) {
Console.WriteLine(0);
} else {
Console.WriteLine(broken_count);
}
}
}
}
|
using System;
namespace AtCoder {
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split(' ');
int search_index = 1;
int broken_count = 0;
int check_count = 0;
for (int i = 0; i < input.Length; i++) {
if (int.Parse(input[i]) == search_index) {
search_index++;
} else {
broken_count++;
}
check_count++;
}
if (broken_count == check_count++) {
Console.WriteLine(-1);
} else if (search_index == check_count++) {
Console.WriteLine(0);
} else {
Console.WriteLine(broken_count);
}
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 12, 223, 0, 29], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 57, 75, 57, 15, 16, 12, 223, 0, 29]]
| 8
| 153
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Program {
static void Main() {
string line = Console.ReadLine().Trim();
string[] lineRecord = Console.ReadLine().Trim().Split(' ');
var list = new List<int>();
foreach (var item in lineRecord) {
list.Add(int.Parse(item));
}
var answer = CalcBreak(int.Parse(line), list);
Console.WriteLine(answer);
}
private static int CalcBreak(int N, List<int> rengaNO) {
int count = 0;
if (rengaNO.Contains(1))
return -1;
foreach (var item in rengaNO) {
if (item == count + 1)
count++;
}
return rengaNO.Count() - count;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Program {
static void Main() {
string line = Console.ReadLine().Trim();
string[] lineRecord = Console.ReadLine().Trim().Split(' ');
var list = new List<int>();
foreach (var item in lineRecord) {
list.Add(int.Parse(item));
}
var answer = CalcBreak(int.Parse(line), list);
Console.WriteLine(answer);
}
private static int CalcBreak(int N, List<int> rengaNO) {
int count = 0;
if (!rengaNO.Contains(1))
return -1;
foreach (var item in rengaNO) {
if (item == count + 1)
count++;
}
return rengaNO.Count() - count;
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 241, 0, 111]]
| 8
| 184
| 1
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var ans = 0;
var index = 0;
var max = a.Max();
var through = false;
for (var j = 1; j <= max || index < N; j++) {
var bef = index;
for (var i = index; i < N; i++) {
if (a[i] != j)
ans++;
else {
index = i + 1;
break;
}
if (i == N - 1)
through = true;
}
if (index < max && bef == index) {
Console.WriteLine(-1);
return;
}
if (through)
break;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var ans = 0;
var index = 0;
var max = a.Max();
var through = false;
for (var j = 1; j <= max || index < N; j++) {
var bef = index;
for (var i = index; i < N; i++) {
if (a[i] != j)
ans++;
else {
index = i + 1;
break;
}
if (i == N - 1)
through = true;
}
if (index == 0 && bef == index) {
Console.WriteLine(-1);
return;
}
if (through)
break;
}
Console.WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 207
| 4
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ใใใใ
static void Solve() {
long N = GetLong();
if ((N & 1) == 1 || N < 10) {
Console.WriteLine(0);
return;
}
long ans = 0;
for (int i = 1; i <= Math.Log(N, 5); i++) {
ans += N / (long)Math.Pow(5, i);
}
Console.WriteLine(ans);
}
}
//ๆกๅผตใกใฝใใ
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public void WriteObjects<T>(IList<T> values) {
var num = values.Count;
for (int i = 0; i < num; i++) {
Console.Write(values[i]);
if (i < num - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ใใใใ
static void Solve() {
long N = GetLong();
if ((N & 1) == 1 || N < 10) {
Console.WriteLine(0);
return;
}
long ans = 0;
for (int i = 1; i <= Math.Log(N, 5); i++) {
ans += N / 2 / (long)Math.Pow(5, i);
}
Console.WriteLine(ans);
}
}
//ๆกๅผตใกใฝใใ
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public void WriteObjects<T>(IList<T> values) {
var num = values.Count;
for (int i = 0; i < num; i++) {
Console.Write(values[i]);
if (i < num - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85]]
| 8
| 1,178
| 2
|
using System;
namespace GraphTheory {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
if (N % 2 != 0) {
Console.WriteLine(0);
return;
}
long m = 10;
long sum = 0;
while (m < N) {
sum += N / m;
m *= 5;
}
Console.WriteLine(sum);
}
}
}
|
using System;
namespace GraphTheory {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
if (N % 2 != 0) {
Console.WriteLine(0);
return;
}
long m = 10;
long sum = 0;
while (m <= N) {
sum += N / m;
m *= 5;
}
Console.WriteLine(sum);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 90
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using static System.Console;
public static class Program {
private static readonly long INF = long.MaxValue / 2;
private static readonly int MOD = 1000000007;
struct Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T first;
public U second;
private bool CompWithFirst;
public Pair(T f, U s, int comp) {
first = f;
second = s;
CompWithFirst = comp == 1;
}
public int CompareTo(Pair<T, U> other) {
return CompWithFirst ? first.CompareTo(other.first)
: second.CompareTo(other.second);
}
}
public class PriorityQueue<T>
where T : IComparable<T> {
private List<T> Q;
private readonly int r;
public PriorityQueue(bool ascending) {
if (ascending) {
r = 1;
} else {
r = -1;
}
Q = new List<T>();
}
private void PushHeap(List<T> list, T item) {
int n = list.Count();
list.Add(item);
while (n != 0) {
int pIndex = (n - 1) / 2;
if (list[n].CompareTo(list[pIndex]) * r > 0) {
Swap(Q, n, pIndex);
} else {
break;
}
n = pIndex;
}
}
private void PopHeap(List<T> list) {
int n = list.Count() - 1;
list[0] = list[n];
list.RemoveAt(n);
int cur = 0;
int comp;
while (2 * cur + 1 <= n - 1) {
int c1 = 2 * cur + 1;
int c2 = 2 * (cur + 1);
if (c1 == n - 1) {
comp = c1;
} else {
comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2;
}
if (list[cur].CompareTo(list[comp]) * r < 0) {
Swap(Q, cur, comp);
} else {
break;
}
cur = comp;
}
}
private void Swap(List<T> list, int a, int b) {
T keep = list[a];
list[a] = list[b];
list[b] = keep;
}
public void Enqueue(T value) { PushHeap(Q, value); }
public T Dequeue() {
T ret = Q[0];
PopHeap(Q);
return ret;
}
public T Peek() { return Q[0]; }
public int CountItem() { return Q.Count(); }
public bool IsEmpty() { return !Q.Any(); }
}
static long ModInv(long a, long m) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
long tmp = a;
a = b;
b = tmp;
u -= t * v;
tmp = u;
u = v;
v = tmp;
}
u %= m;
if (u < 0)
u += m;
return u;
}
public static long CalcComb(long n, long m) {
//ๆกไปถใใงใใฏ
if (n < m)
return 0;
if (n < 0 || m < 0)
return 0;
// n๏ผฃm ๏ผ n๏ผฃm-1 ร๏ผn-m+1๏ผ/ m
// return CalcFact(n) / (CalcFact(m) * CalcFact(n - m));
// MODใงๅฒใฃใฆbใฎ้ๅ
ใๆฑใใ
return CalcFact(n) * ModInv((CalcFact(m) * CalcFact(n - m)) % MOD, MOD) %
MOD;
}
/// <summary>
/// ้ไนใ่จ็ฎใใใ
/// </summary>
/// <param name="n">n</param>
/// <returns>nใฎ้ไน๏ผn!๏ผ</returns>
public static long CalcFact(long n) {
if (n <= 0) {
return 1;
}
return n * CalcFact(n - 1) % MOD;
}
struct Pos {
public int x;
public int y;
public Pos(int x, int y) {
this.x = x;
this.y = y;
}
public static Pos operator +(Pos p1, Pos p2) {
var result = new Pos();
result.x = p2.x + p1.x;
result.y = p2.y + p1.y;
return result;
}
public static Pos operator -(Pos p1, Pos p2) {
var result = new Pos();
result.x = p2.x - p1.x;
result.y = p2.y - p1.y;
return result;
}
}
class Modular {
private const int M = 1000000007;
private long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
private static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
}
static class Permutation<T> {
private static void Search(List<T[]> perms, Stack<T> stack, T[] a) {
int N = a.Length;
if (N == 0) {
perms.Add(stack.Reverse().ToArray());
} else {
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i) {
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) {
b[i] = a[i];
}
stack.Pop();
}
}
}
public static IEnumerable<T[]> All(IEnumerable<T> src) {
var perms = new List<T[]>();
Search(perms, new Stack<T>(), src.ToArray());
return perms;
}
}
public static int ReadLineToInt() { return int.Parse(ReadLine()); }
public static long ReadLineToLong() { return long.Parse(ReadLine()); }
public static int[] ReadLineToInts() {
return ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int nibunn(int[] array, int target) {
int L = 0;
int R = array.Length;
while (R - L > 1) {
int mid = (R + L) / 2;
if (array[mid] > target)
L = mid;
else
R = mid;
}
return L;
}
struct Testmony {
public int To;
public int IsHonest;
public Testmony(int to, int isHonest) {
To = to;
IsHonest = isHonest;
}
}
public static void Main(string[] args) {
long n = ReadLineToLong();
if (n % 2 == 0) {
WriteLine(0);
return;
}
n = n / 2;
long ans = 0;
while (n != 0) {
ans += n / 5;
n /= 5;
}
WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using static System.Console;
public static class Program {
private static readonly long INF = long.MaxValue / 2;
private static readonly int MOD = 1000000007;
struct Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T first;
public U second;
private bool CompWithFirst;
public Pair(T f, U s, int comp) {
first = f;
second = s;
CompWithFirst = comp == 1;
}
public int CompareTo(Pair<T, U> other) {
return CompWithFirst ? first.CompareTo(other.first)
: second.CompareTo(other.second);
}
}
public class PriorityQueue<T>
where T : IComparable<T> {
private List<T> Q;
private readonly int r;
public PriorityQueue(bool ascending) {
if (ascending) {
r = 1;
} else {
r = -1;
}
Q = new List<T>();
}
private void PushHeap(List<T> list, T item) {
int n = list.Count();
list.Add(item);
while (n != 0) {
int pIndex = (n - 1) / 2;
if (list[n].CompareTo(list[pIndex]) * r > 0) {
Swap(Q, n, pIndex);
} else {
break;
}
n = pIndex;
}
}
private void PopHeap(List<T> list) {
int n = list.Count() - 1;
list[0] = list[n];
list.RemoveAt(n);
int cur = 0;
int comp;
while (2 * cur + 1 <= n - 1) {
int c1 = 2 * cur + 1;
int c2 = 2 * (cur + 1);
if (c1 == n - 1) {
comp = c1;
} else {
comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2;
}
if (list[cur].CompareTo(list[comp]) * r < 0) {
Swap(Q, cur, comp);
} else {
break;
}
cur = comp;
}
}
private void Swap(List<T> list, int a, int b) {
T keep = list[a];
list[a] = list[b];
list[b] = keep;
}
public void Enqueue(T value) { PushHeap(Q, value); }
public T Dequeue() {
T ret = Q[0];
PopHeap(Q);
return ret;
}
public T Peek() { return Q[0]; }
public int CountItem() { return Q.Count(); }
public bool IsEmpty() { return !Q.Any(); }
}
static long ModInv(long a, long m) {
long b = m, u = 1, v = 0;
while (b != 0) {
long t = a / b;
a -= t * b;
long tmp = a;
a = b;
b = tmp;
u -= t * v;
tmp = u;
u = v;
v = tmp;
}
u %= m;
if (u < 0)
u += m;
return u;
}
public static long CalcComb(long n, long m) {
//ๆกไปถใใงใใฏ
if (n < m)
return 0;
if (n < 0 || m < 0)
return 0;
// n๏ผฃm ๏ผ n๏ผฃm-1 ร๏ผn-m+1๏ผ/ m
// return CalcFact(n) / (CalcFact(m) * CalcFact(n - m));
// MODใงๅฒใฃใฆbใฎ้ๅ
ใๆฑใใ
return CalcFact(n) * ModInv((CalcFact(m) * CalcFact(n - m)) % MOD, MOD) %
MOD;
}
/// <summary>
/// ้ไนใ่จ็ฎใใใ
/// </summary>
/// <param name="n">n</param>
/// <returns>nใฎ้ไน๏ผn!๏ผ</returns>
public static long CalcFact(long n) {
if (n <= 0) {
return 1;
}
return n * CalcFact(n - 1) % MOD;
}
struct Pos {
public int x;
public int y;
public Pos(int x, int y) {
this.x = x;
this.y = y;
}
public static Pos operator +(Pos p1, Pos p2) {
var result = new Pos();
result.x = p2.x + p1.x;
result.y = p2.y + p1.y;
return result;
}
public static Pos operator -(Pos p1, Pos p2) {
var result = new Pos();
result.x = p2.x - p1.x;
result.y = p2.y - p1.y;
return result;
}
}
class Modular {
private const int M = 1000000007;
private long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % M;
return new Modular((m < 0) ? m + M : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
private static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, M - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
}
static class Permutation<T> {
private static void Search(List<T[]> perms, Stack<T> stack, T[] a) {
int N = a.Length;
if (N == 0) {
perms.Add(stack.Reverse().ToArray());
} else {
var b = new T[N - 1];
Array.Copy(a, 1, b, 0, N - 1);
for (int i = 0; i < a.Length; ++i) {
stack.Push(a[i]);
Search(perms, stack, b);
if (i < b.Length) {
b[i] = a[i];
}
stack.Pop();
}
}
}
public static IEnumerable<T[]> All(IEnumerable<T> src) {
var perms = new List<T[]>();
Search(perms, new Stack<T>(), src.ToArray());
return perms;
}
}
public static int ReadLineToInt() { return int.Parse(ReadLine()); }
public static long ReadLineToLong() { return long.Parse(ReadLine()); }
public static int[] ReadLineToInts() {
return ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int nibunn(int[] array, int target) {
int L = 0;
int R = array.Length;
while (R - L > 1) {
int mid = (R + L) / 2;
if (array[mid] > target)
L = mid;
else
R = mid;
}
return L;
}
struct Testmony {
public int To;
public int IsHonest;
public Testmony(int to, int isHonest) {
To = to;
IsHonest = isHonest;
}
}
public static void Main(string[] args) {
long n = ReadLineToLong();
if (n % 2 != 0) {
WriteLine(0);
return;
}
n = n / 2;
long ans = 0;
while (n != 0) {
ans += n / 5;
n /= 5;
}
WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79]]
| 8
| 1,747
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using static Exter;
using System.Linq;
using System.Numerics;
#if DEBUG
#else
using console = System.Console;
#endif
public class App {
public static void Main(string[] args) {
long n = long.Parse(console.ReadLine());
if (n % 2 == 1) {
cout = 0;
return;
}
long sum = 0;
;
for (long i = 5; i < n / 2; i *= 5) {
sum += (n / 2) / i;
}
cout = sum;
}
public static long Lcm(long a, long b) => a * b / Gcd(a, b);
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long a, long b) {
if (b == 0)
return a;
return GcdRecursive(b, a % b);
}
}
public class RollingHash {
long[] h;
long m = 2147483647;
int b = 524287;
Power baser;
public RollingHash(string s) {
baser = new Power(b);
h = new long[s.Length];
h[0] = 0;
for (int i = 1; i < s.Length; i++) {
h[i] = (h[i - 1] * b + s[i]) % m;
}
}
public long Calc(int l, int r) {
cout = h[r];
cout = h[l] * baser.GetEntry(r - l - 1);
return 0;
}
}
public class PriorityQueue<T> : IEnumerable<T>
where T : IComparable {
List<T> buffer = new List<T>();
static void PushHeap(List<T> array, T elem) {
int n = array.Count;
array.Add(elem);
while (n != 0) {
int i = (n - 1) / 2;
if (array[n].CompareTo(array[i]) < 0) {
T tmp = array[n];
array[n] = array[i];
array[i] = tmp;
}
n = i;
}
}
static void PopHeap(List<T> array) {
int n = array.Count - 1;
array[0] = array[n];
array.RemoveAt(array.Count - 1);
for (int i = 0, j; (j = 2 * i + 1) < n;) {
if ((j != n - 1) && (array[j].CompareTo(array[j + 1]) > 0))
j++;
if (array[i].CompareTo(array[j]) > 0) {
T tmp = array[j];
array[j] = array[i];
array[i] = tmp;
}
i = j;
}
}
public int Count {
get { return buffer.Count; }
}
public void Push(T elem) { PushHeap(this.buffer, elem); }
public T Peek() { return buffer[0]; }
public T Pop() {
T a = buffer[0];
PopHeap(this.buffer);
return a;
}
public IEnumerator<T> GetEnumerator() {
var v = new List<T>(buffer);
while (v.Count != 0) {
yield return v[0];
PopHeap(v);
}
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
public class Power {
public int Base;
private List<long> Value = new List<long>();
public Power(int v) {
if (v == 1)
new ArgumentOutOfRangeException();
long prev = -1;
long g = v;
Base = v;
while (g > prev) {
Value.Add(g);
prev = g;
g *= g;
}
}
public long GetEntry(int exponent) {
long s = 1;
for (int i = 0; (1 << i) <= exponent; i++) {
if ((exponent & (1 << i)) != 0) {
s *= Value[i];
}
}
return s;
}
}
public static class Exter {
public static IEnumerable<long> PrimeFactors(long n) {
int i = 2;
long tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
public class LoopArray<T> {
public readonly int Length;
private T[] arr;
public LoopArray(int Capacity) { Length = Capacity; }
public LoopArray(T[] ar) {
arr = new T[ar.Length];
Array.Copy(ar, arr, ar.Length);
}
}
public class Point {
public Point(int cx, int cy) {
x = cx;
y = cy;
}
public int x;
public int y;
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f) {
foreach (var v in a) {
foreach (var w in b)
yield return f(v, w);
}
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f, Func<T1, T2, bool> s) {
foreach (var v in a) {
foreach (var w in b)
if (s(v, w))
yield return f(v, w);
}
}
public static int ToInt(this long v) => (int)v;
public static int ToInt(this string v) => int.Parse(v);
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int a,
int b) => b == 0 ? a : GcdRecursive(b, a % b);
public static object cout {
set {
console.Write(value.ToString());
console.WriteLine();
}
}
public static void ToCout<t>(this IEnumerable<t> v) {
cout = string.Join(",", v);
}
public static long[] readarr {
get {
preadarr =
console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
return preadarr;
}
}
public static long[] preadarr;
}
#if DEBUG
public static class console {
static int cursorLine = 0;
static readonly string[] cin = System.IO.File.ReadAllLines("Input.txt");
static public string ReadLine() {
if (cursorLine == cin.Length)
cout = "Out";
return cin[cursorLine++];
}
static public void WriteLine() { Console.WriteLine(); }
static public void WriteLine<T>(T input) { Console.WriteLine(input); }
static public void Write<T>(T input) { Console.Write(input); }
static public void WriteLine(string s, params object[] arr) {
Console.WriteLine(s, arr);
}
}
#endif
|
using System;
using System.Collections;
using System.Collections.Generic;
using static Exter;
using System.Linq;
using System.Numerics;
#if DEBUG
#else
using console = System.Console;
#endif
public class App {
public static void Main(string[] args) {
long n = long.Parse(console.ReadLine());
if (n % 2 == 1) {
cout = 0;
return;
}
long sum = 0;
;
for (long i = 5; i <= n / 2; i *= 5) {
sum += (n / 2) / i;
}
cout = sum;
}
public static long Lcm(long a, long b) => a * b / Gcd(a, b);
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long a, long b) {
if (b == 0)
return a;
return GcdRecursive(b, a % b);
}
}
public class RollingHash {
long[] h;
long m = 2147483647;
int b = 524287;
Power baser;
public RollingHash(string s) {
baser = new Power(b);
h = new long[s.Length];
h[0] = 0;
for (int i = 1; i < s.Length; i++) {
h[i] = (h[i - 1] * b + s[i]) % m;
}
}
public long Calc(int l, int r) {
cout = h[r];
cout = h[l] * baser.GetEntry(r - l - 1);
return 0;
}
}
public class PriorityQueue<T> : IEnumerable<T>
where T : IComparable {
List<T> buffer = new List<T>();
static void PushHeap(List<T> array, T elem) {
int n = array.Count;
array.Add(elem);
while (n != 0) {
int i = (n - 1) / 2;
if (array[n].CompareTo(array[i]) < 0) {
T tmp = array[n];
array[n] = array[i];
array[i] = tmp;
}
n = i;
}
}
static void PopHeap(List<T> array) {
int n = array.Count - 1;
array[0] = array[n];
array.RemoveAt(array.Count - 1);
for (int i = 0, j; (j = 2 * i + 1) < n;) {
if ((j != n - 1) && (array[j].CompareTo(array[j + 1]) > 0))
j++;
if (array[i].CompareTo(array[j]) > 0) {
T tmp = array[j];
array[j] = array[i];
array[i] = tmp;
}
i = j;
}
}
public int Count {
get { return buffer.Count; }
}
public void Push(T elem) { PushHeap(this.buffer, elem); }
public T Peek() { return buffer[0]; }
public T Pop() {
T a = buffer[0];
PopHeap(this.buffer);
return a;
}
public IEnumerator<T> GetEnumerator() {
var v = new List<T>(buffer);
while (v.Count != 0) {
yield return v[0];
PopHeap(v);
}
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
public class Power {
public int Base;
private List<long> Value = new List<long>();
public Power(int v) {
if (v == 1)
new ArgumentOutOfRangeException();
long prev = -1;
long g = v;
Base = v;
while (g > prev) {
Value.Add(g);
prev = g;
g *= g;
}
}
public long GetEntry(int exponent) {
long s = 1;
for (int i = 0; (1 << i) <= exponent; i++) {
if ((exponent & (1 << i)) != 0) {
s *= Value[i];
}
}
return s;
}
}
public static class Exter {
public static IEnumerable<long> PrimeFactors(long n) {
int i = 2;
long tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
public class LoopArray<T> {
public readonly int Length;
private T[] arr;
public LoopArray(int Capacity) { Length = Capacity; }
public LoopArray(T[] ar) {
arr = new T[ar.Length];
Array.Copy(ar, arr, ar.Length);
}
}
public class Point {
public Point(int cx, int cy) {
x = cx;
y = cy;
}
public int x;
public int y;
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f) {
foreach (var v in a) {
foreach (var w in b)
yield return f(v, w);
}
}
public static IEnumerable<Result>
ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b,
Func<T1, T2, Result> f, Func<T1, T2, bool> s) {
foreach (var v in a) {
foreach (var w in b)
if (s(v, w))
yield return f(v, w);
}
}
public static int ToInt(this long v) => (int)v;
public static int ToInt(this string v) => int.Parse(v);
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int a,
int b) => b == 0 ? a : GcdRecursive(b, a % b);
public static object cout {
set {
console.Write(value.ToString());
console.WriteLine();
}
}
public static void ToCout<t>(this IEnumerable<t> v) {
cout = string.Join(",", v);
}
public static long[] readarr {
get {
preadarr =
console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();
return preadarr;
}
}
public static long[] preadarr;
}
#if DEBUG
public static class console {
static int cursorLine = 0;
static readonly string[] cin = System.IO.File.ReadAllLines("Input.txt");
static public string ReadLine() {
if (cursorLine == cin.Length)
cout = "Out";
return cin[cursorLine++];
}
static public void WriteLine() { Console.WriteLine(); }
static public void WriteLine<T>(T input) { Console.WriteLine(input); }
static public void Write<T>(T input) { Console.Write(input); }
static public void WriteLine(string s, params object[] arr) {
Console.WriteLine(s, arr);
}
}
#endif
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 1,620
| 2
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
#if DEBUG
// MyDebugger.MakeTestCase("../TextFile2.txt"); return;
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var n = long.Parse(input.ReadLine());
if (n % 2 == 1)
return 0;
long i = 5 * 2;
long c = 0;
while (i < n) {
c += n / i;
// Debug.WriteLine(i + "/" + (n/i));
i *= 5;
}
return c;
// return func(n);
}
static long func(long n) {
Debug.WriteLine(n);
if (n < 2)
return 1;
return n * func(n - 2);
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
#if DEBUG
// MyDebugger.MakeTestCase("../TextFile2.txt"); return;
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var n = long.Parse(input.ReadLine());
if (n % 2 == 1)
return 0;
long i = 5 * 2;
long c = 0;
while (i <= n) {
c += n / i;
// Debug.WriteLine(i + "/" + (n/i));
i *= 5;
}
return c;
// return func(n);
}
static long func(long n) {
Debug.WriteLine(n);
if (n < 2)
return 1;
return n * func(n - 2);
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 191
| 2
|
using System;
using System.Linq;
namespace ABC148 {
class E {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
if (N % 2 != 0) {
Console.WriteLine(0);
return;
}
long res = 0;
N /= 2;
while (5 < N) {
res += N / 5;
N /= 5;
}
Console.WriteLine(res);
}
}
}
|
using System;
using System.Linq;
namespace ABC148 {
class E {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
if (N % 2 != 0) {
Console.WriteLine(0);
return;
}
long res = 0;
N /= 2;
while (5 <= N) {
res += N / 5;
N /= 5;
}
Console.WriteLine(res);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 94
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace AtCoder {
public class MainClass {
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput(), Console.Out.Encoding);
sw.AutoFlush = false;
Console.SetOut(sw);
if (args.Length > 0 && args[0] == "debug") {
var inputs = new[] { @"
12
",
@"
5
",
@"
1000000000000000000
",
@"
" };
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);
Console.Out.Flush();
}
public static void Main2(string[] args) {
checked {
var N = long.Parse(Console.ReadLine());
if (N % 2 == 0) {
var res = 0L;
for (long i = 10; i < N; i *= 5) {
res += N / i;
}
Console.WriteLine(res);
} else {
Console.WriteLine("0");
}
}
}
}
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, long> a) {
long i = 0;
foreach (var item in list) {
a(item, i);
}
}
///< summary>ๆทปๅญไปใforใ</summary>
public static void ForEach<T>(this IEnumerable<T> list, Action<T> a) {
foreach (var item in list) {
a(item);
}
}
///< summary>ๆๅฎๅๆฐใใชใฒใผใใๅผใณๅบใใ</summary>
public static IEnumerable<T> Repeat<T>(long n, Func<T> f) {
for (long 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>();
var a2 = Math.Ceiling(Math.Sqrt(a));
for (long b = 2; b <= a2; ++b) {
while (a % b == 0) {
res.Add(b);
a = a / b;
a2 = Math.Ceiling(Math.Sqrt(a));
}
}
if (a > 1)
res.Add(a);
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;
}
///< summary>ๅใไธใใ</summary>
public static long Ceiling(long a, long b) => (a + (b - 1)) / b;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace AtCoder {
public class MainClass {
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput(), Console.Out.Encoding);
sw.AutoFlush = false;
Console.SetOut(sw);
if (args.Length > 0 && args[0] == "debug") {
var inputs = new[] { @"
12
",
@"
5
",
@"
1000000000000000000
",
@"
" };
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);
Console.Out.Flush();
}
public static void Main2(string[] args) {
checked {
var N = long.Parse(Console.ReadLine());
if (N % 2 == 0) {
var res = 0L;
for (long i = 10; i <= N; i *= 5) {
res += N / i;
}
Console.WriteLine(res);
} else {
Console.WriteLine("0");
}
}
}
}
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, long> a) {
long i = 0;
foreach (var item in list) {
a(item, i);
}
}
///< summary>ๆทปๅญไปใforใ</summary>
public static void ForEach<T>(this IEnumerable<T> list, Action<T> a) {
foreach (var item in list) {
a(item);
}
}
///< summary>ๆๅฎๅๆฐใใชใฒใผใใๅผใณๅบใใ</summary>
public static IEnumerable<T> Repeat<T>(long n, Func<T> f) {
for (long 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>();
var a2 = Math.Ceiling(Math.Sqrt(a));
for (long b = 2; b <= a2; ++b) {
while (a % b == 0) {
res.Add(b);
a = a / b;
a2 = Math.Ceiling(Math.Sqrt(a));
}
}
if (a > 1)
res.Add(a);
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;
}
///< summary>ๅใไธใใ</summary>
public static long Ceiling(long a, long b) => (a + (b - 1)) / b;
}
}
|
[["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 1,080
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace template {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var n = cin.ReadLong;
var cnt = 0L;
if (n % 2 == 1) {
Console.WriteLine(0);
}
n /= 2;
while (n >= 5) {
cnt += n / 5;
n /= 5;
}
Console.WriteLine(cnt);
}
}
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.Collections.Generic;
using System.Linq;
namespace template {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var n = cin.ReadLong;
var cnt = 0L;
if (n % 2 == 1) {
Console.WriteLine(0);
return;
}
n /= 2;
while (n >= 5) {
cnt += n / 5;
n /= 5;
}
Console.WriteLine(cnt);
}
}
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, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 462
| 2
|
using System;
class E {
static void Main() {
var n = long.Parse(Console.ReadLine());
if (n % 2 == 1) {
Console.WriteLine(0);
return;
}
long r = 0, t = 1;
while (t < n)
r += n / (t *= 10);
Console.WriteLine(r);
}
}
|
using System;
class E {
static void Main() {
var n = long.Parse(Console.ReadLine());
if (n % 2 == 1) {
Console.WriteLine(0);
return;
}
long r = 0, t = 2;
while (t < n)
r += n / (t *= 5);
Console.WriteLine(r);
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 11, 12, 16, 12, 23, 0, 11, 12, 203], ["+", 0, 11, 12, 16, 12, 23, 0, 11, 12, 203]]
| 8
| 79
| 4
|
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 n = CinL();
if (n % 2 == 1) {
Cout(0);
} else {
long tot2 = 0;
for (int i = 1; i <= 27; i++) {
long now = ((long)Math.Pow(5, i));
tot2 += n / now;
}
Cout(tot2);
}
Cin();
}
static Random Rand = new Random();
static string[] AlphabetTable =
new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z" };
static int loop(int num, int max) {
if (num > max) {
return num % max;
} else if (num < 0) {
return max - (-num) % max;
} else {
return num;
}
}
static long GCD(long a, long 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 long[] yakusuu(long n) {
if (n == 1) {
return new long[] { 1 };
}
List<long> res = new List<long>();
res.Add(1);
for (long i = 2; i <= n / 2 + 1; i++) {
if (n % i == 0) {
res.Add(i);
}
}
res.Add(n);
return res.ToArray();
}
static bool isPrime(long num) {
if (num == 1) {
return false;
}
for (long i = 2; i <= Math.Sqrt(num) + 1; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
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);
}
}
public struct Pair<T> {
public T a;
public T b;
public T c;
public Pair(T _a, T _b) {
a = _a;
b = _b;
c = default(T);
}
public Pair(T _a, T _b, T _c) {
a = _a;
b = _b;
c = _c;
}
}
}
|
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 n = CinL();
if (n % 2 == 1) {
Cout(0);
} else {
long tot2 = 0;
for (int i = 1; i <= 27; i++) {
long now = ((long)Math.Pow(5, i));
tot2 += n / (now * 2);
}
Cout(tot2);
}
Cin();
}
static Random Rand = new Random();
static string[] AlphabetTable =
new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z" };
static int loop(int num, int max) {
if (num > max) {
return num % max;
} else if (num < 0) {
return max - (-num) % max;
} else {
return num;
}
}
static long GCD(long a, long 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 long[] yakusuu(long n) {
if (n == 1) {
return new long[] { 1 };
}
List<long> res = new List<long>();
res.Add(1);
for (long i = 2; i <= n / 2 + 1; i++) {
if (n % i == 0) {
res.Add(i);
}
}
res.Add(n);
return res.ToArray();
}
static bool isPrime(long num) {
if (num == 1) {
return false;
}
for (long i = 2; i <= Math.Sqrt(num) + 1; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
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);
}
}
public struct Pair<T> {
public T a;
public T b;
public T c;
public Pair(T _a, T _b) {
a = _a;
b = _b;
c = default(T);
}
public Pair(T _a, T _b, T _c) {
a = _a;
b = _b;
c = _c;
}
}
}
|
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 48], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
| 8
| 1,060
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
struct mint : IEquatable<mint> {
// static uint mod = 998244353;
static uint mod = 1000000007;
uint _v;
public mint(long v) : this((uint)(v % mod + mod)) {}
private mint(uint v) { _v = v < mod ? v : (v - mod); }
public static void SetMod(uint p) { mod = p; }
public static mint operator +(mint lhs, mint rhs) {
return new mint(lhs._v + rhs._v);
}
public static mint operator -(mint lhs, mint rhs) {
return new mint(lhs._v + mod - rhs._v);
}
public static mint operator *(mint lhs, mint rhs) {
return new mint((uint)((ulong)lhs._v * rhs._v % mod));
}
public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); }
public static mint operator ^(mint x, int n) { return Pow(x, n); }
public static bool operator ==(mint l, mint r) { return l._v == r._v; }
public static bool operator !=(mint l, mint r) { return !(l == r); }
public static bool operator<(mint l, mint r) { return l._v < r._v; }
public static bool operator>(mint l, mint r) { return l._v > r._v; }
public static mint Pow(mint x, int n) {
var r = new mint(1);
while (n > 0) {
if ((n & 1) > 0)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
public mint Pow(int n) { return Pow(this, n); }
public mint Inv() { return Pow((int)mod - 2); }
public bool Equals(mint o) { return this == o; }
public override bool Equals(object obj) {
if (obj is mint)
return this == (mint)obj;
else
return false;
}
public override int GetHashCode() { return _v.GetHashCode(); }
public override string ToString() { return _v.ToString(); }
public static implicit operator mint(int i) { return new mint(i); }
public static implicit operator mint(long i) { return new mint(i); }
private static mint[] _fact;
public static void SetFact(int n) {
_fact = new mint[n + 1];
_fact[0] = 1;
for (int i = 1; i < n + 1; i++) {
_fact[i] = _fact[i - 1] * i;
}
}
public static mint Fact(int n) {
if (_fact == null || _fact.Length < n) {
SetFact(n * 2);
}
return _fact[n];
}
public static mint Combination(int n, int r) {
return Fact(n) / (Fact(n - r) * Fact(r));
}
}
static class Extensions {
public static int LowerBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c > 0)
l = m + 1;
else
r = m;
}
return l;
}
public static int UpperBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c >= 0)
l = m + 1;
else
r = m;
}
return r;
}
}
class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
public static int[] ZAlgotithm(string s) {
var len = s.Length;
var a = new int[len];
a[0] = len;
var i = 1;
var j = 0;
while (i < len) {
while (i + j < len && s[j] == s[i + j])
j++;
a[i] = j;
if (j == 0) {
i++;
continue;
}
var k = 1;
while (i + k < len && k + a[k] < j) {
a[i + k] = a[k];
k++;
}
i += k;
j -= k;
}
return a;
}
public class MaxHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MaxHeap() : this(0) {}
public MaxHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c > 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) < 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MaxHeap<T> Copy(Comparison<T> comp = null) {
var c = new MaxHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MaxHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
public class MinHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MinHeap() : this(0) {}
public MinHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c < 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) > 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MinHeap<T> Copy(Comparison<T> comp = null) {
var c = new MinHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MinHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class InputLine {
private string[] _inputs;
private int _index = 0;
InputLine(string input) {
_inputs = input.Split();
_index = 0;
}
public static InputLine Read() { return new InputLine(Console.ReadLine()); }
public int NextInt() { return int.Parse(_inputs[_index++]); }
public long NextLong() { return long.Parse(_inputs[_index++]); }
public double NextDouble() { return double.Parse(_inputs[_index++]); }
}
public static int GCD(int x, int y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
public static long GCD(long x, long y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
static long ModPower(long x, long y, long mod) {
var bytes = BitConverter.GetBytes(y);
var bits = new System.Collections.BitArray(bytes);
var max2 = 0;
for (int i = bits.Length - 1; i >= 0; i--) {
if (bits[i]) {
max2 = i;
break;
}
}
long result = 1;
for (int i = max2; i >= 0; i--) {
result = (result * result) % mod;
if (bits[i]) {
result = (result * x) % mod;
}
}
return result;
}
static long ModFact(long n, long mod) {
long result = 1;
for (int i = 1; i <= n; i++) {
result = result * i % mod;
}
return result;
}
static long ModAdd(long x, long y, long mod) {
return ((x % mod) + (y % mod)) % mod;
}
static long ModMul(long x, long y, long mod) {
return ((x % mod) * (y % mod)) % mod;
}
static long ModDiv(long x, long y, long mod) {
//ใใงใซใใผใฎๅฐๅฎ็ใใใa^(-1) = a^(p-2)
return ModMul(x, ModPower(y, mod - 2, mod), mod);
}
static long ModComb(long n, long r, long mod) {
long numerator = 1;
for (int i = 0; i < r; i++) {
numerator = ModMul(numerator, n - i, mod);
}
long denominator = ModFact(r, mod);
return ModDiv(numerator, denominator, mod);
}
class Graph {
private int _size;
private List<int>[] _edges;
public Graph(int size) {
_size = size;
_edges = new List<int>[size];
}
public List<int> this[int i] {
get {
if (_edges[i] == null)
_edges[i] = new List<int>();
return _edges[i];
}
}
}
class Graph<T> {
private int _size;
private List<T>[] _edges;
public Graph(int size) {
_size = size;
_edges = new List<T>[size];
}
public List<T> this[int i] {
get {
if (_edges[i] == null)
_edges[i] = new List<T>();
return _edges[i];
}
}
}
static Graph<T> NewGraph<T>(int size, T template) {
return new Graph<T>(size);
}
static List<T> NewList<T>(T template) { return new List<T>(); }
static T[] NewArray<T>(int size, T template) { return new T[size]; }
static long p1097 = 1000000007;
static void Main(string[] args) {
//โ
var n = ReadLong();
if (n % 2 != 0) {
Console.WriteLine(0);
return;
}
long result = 0;
long five = 5;
n /= 2;
while (five < n) {
result += n / five;
if (five == 7450580596923828125)
break;
five *= 5;
}
Console.WriteLine(result);
//โ
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
struct mint : IEquatable<mint> {
// static uint mod = 998244353;
static uint mod = 1000000007;
uint _v;
public mint(long v) : this((uint)(v % mod + mod)) {}
private mint(uint v) { _v = v < mod ? v : (v - mod); }
public static void SetMod(uint p) { mod = p; }
public static mint operator +(mint lhs, mint rhs) {
return new mint(lhs._v + rhs._v);
}
public static mint operator -(mint lhs, mint rhs) {
return new mint(lhs._v + mod - rhs._v);
}
public static mint operator *(mint lhs, mint rhs) {
return new mint((uint)((ulong)lhs._v * rhs._v % mod));
}
public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); }
public static mint operator ^(mint x, int n) { return Pow(x, n); }
public static bool operator ==(mint l, mint r) { return l._v == r._v; }
public static bool operator !=(mint l, mint r) { return !(l == r); }
public static bool operator<(mint l, mint r) { return l._v < r._v; }
public static bool operator>(mint l, mint r) { return l._v > r._v; }
public static mint Pow(mint x, int n) {
var r = new mint(1);
while (n > 0) {
if ((n & 1) > 0)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
public mint Pow(int n) { return Pow(this, n); }
public mint Inv() { return Pow((int)mod - 2); }
public bool Equals(mint o) { return this == o; }
public override bool Equals(object obj) {
if (obj is mint)
return this == (mint)obj;
else
return false;
}
public override int GetHashCode() { return _v.GetHashCode(); }
public override string ToString() { return _v.ToString(); }
public static implicit operator mint(int i) { return new mint(i); }
public static implicit operator mint(long i) { return new mint(i); }
private static mint[] _fact;
public static void SetFact(int n) {
_fact = new mint[n + 1];
_fact[0] = 1;
for (int i = 1; i < n + 1; i++) {
_fact[i] = _fact[i - 1] * i;
}
}
public static mint Fact(int n) {
if (_fact == null || _fact.Length < n) {
SetFact(n * 2);
}
return _fact[n];
}
public static mint Combination(int n, int r) {
return Fact(n) / (Fact(n - r) * Fact(r));
}
}
static class Extensions {
public static int LowerBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c > 0)
l = m + 1;
else
r = m;
}
return l;
}
public static int UpperBound<T>(this IList<T> list, T value,
IComparer<T> comp = null) {
if (comp == null)
comp = Comparer<T>.Default;
var l = 0;
var r = list.Count;
while (l < r) {
var m = (l + r) / 2;
var c = comp.Compare(value, list[m]);
if (c >= 0)
l = m + 1;
else
r = m;
}
return r;
}
}
class Program {
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static int[] ReadIntArray(int n) {
var a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ReadInt();
}
return a;
}
static long[] ReadLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static long[] ReadLongArray(int n) {
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ReadLong();
}
return a;
}
static List<T> ReadObjects<T>(int n, Func<int[], T> creator) {
var l = new List<T>(n);
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
l.Add(creator(a));
}
return l;
}
static int[,] ReadMatrix(int n, int m) {
var r = new int[n, m];
for (int i = 0; i < n; i++) {
var a = ReadIntArray();
for (int j = 0; j < m; j++) {
r[i, j] = a[j];
}
}
return r;
}
public static int[] ZAlgotithm(string s) {
var len = s.Length;
var a = new int[len];
a[0] = len;
var i = 1;
var j = 0;
while (i < len) {
while (i + j < len && s[j] == s[i + j])
j++;
a[i] = j;
if (j == 0) {
i++;
continue;
}
var k = 1;
while (i + k < len && k + a[k] < j) {
a[i + k] = a[k];
k++;
}
i += k;
j -= k;
}
return a;
}
public class MaxHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MaxHeap() : this(0) {}
public MaxHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c > 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) < 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MaxHeap<T> Copy(Comparison<T> comp = null) {
var c = new MaxHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MaxHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
public class MinHeap<T> : IEnumerable<T> {
private List<T> _list;
private Comparer<T> _comp;
public int Count {
get { return _list.Count; }
}
public MinHeap() : this(0) {}
public MinHeap(int capacity, Comparison<T> comp = null) {
_list = new List<T>(capacity);
if (comp == null) {
_comp = Comparer<T>.Default;
} else {
_comp = Comparer<T>.Create(comp);
}
}
public void Push(T elem) { Upheap(elem); }
public T Pop() { return Downheap(); }
public T Peek() { return _list[0]; }
private void Swap(int i, int j) {
var a = _list[j];
_list[j] = _list[i];
_list[i] = a;
}
private void Upheap(T elem) {
_list.Add(elem);
var i = _list.Count - 1;
while (true) {
if (i == 0)
return;
var j = (i - 1) / 2;
var e = _list[i];
var p = _list[j];
var c = _comp.Compare(e, p);
if (c < 0) {
Swap(i, j);
i = j;
continue;
} else {
break;
}
}
}
private T Downheap() {
var result = _list[0];
var last = _list.Count - 1;
Swap(0, last);
_list.RemoveAt(last);
if (_list.Count == 0)
return result;
var i = 0;
while (true) {
if (i == _list.Count - 1)
return result;
var p = _list[i];
var j = i * 2 + 1;
if (j >= _list.Count)
return result;
if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) {
j++;
}
if (_comp.Compare(_list[i], _list[j]) > 0) {
Swap(i, j);
i = j;
} else {
return result;
}
}
}
public MinHeap<T> Copy(Comparison<T> comp = null) {
var c = new MinHeap<T>(0, comp);
c._list = _list.ToList();
return c;
}
public MinHeap(List<T> list) {
_list = list;
_comp = Comparer<T>.Default;
}
public List<T> GetList() { return _list; }
public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class InputLine {
private string[] _inputs;
private int _index = 0;
InputLine(string input) {
_inputs = input.Split();
_index = 0;
}
public static InputLine Read() { return new InputLine(Console.ReadLine()); }
public int NextInt() { return int.Parse(_inputs[_index++]); }
public long NextLong() { return long.Parse(_inputs[_index++]); }
public double NextDouble() { return double.Parse(_inputs[_index++]); }
}
public static int GCD(int x, int y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
public static long GCD(long x, long y) {
var a = Math.Max(x, y);
var b = x + y - a;
while (b != 0) {
var c = b;
b = a % b;
a = c;
}
return a;
}
static long ModPower(long x, long y, long mod) {
var bytes = BitConverter.GetBytes(y);
var bits = new System.Collections.BitArray(bytes);
var max2 = 0;
for (int i = bits.Length - 1; i >= 0; i--) {
if (bits[i]) {
max2 = i;
break;
}
}
long result = 1;
for (int i = max2; i >= 0; i--) {
result = (result * result) % mod;
if (bits[i]) {
result = (result * x) % mod;
}
}
return result;
}
static long ModFact(long n, long mod) {
long result = 1;
for (int i = 1; i <= n; i++) {
result = result * i % mod;
}
return result;
}
static long ModAdd(long x, long y, long mod) {
return ((x % mod) + (y % mod)) % mod;
}
static long ModMul(long x, long y, long mod) {
return ((x % mod) * (y % mod)) % mod;
}
static long ModDiv(long x, long y, long mod) {
//ใใงใซใใผใฎๅฐๅฎ็ใใใa^(-1) = a^(p-2)
return ModMul(x, ModPower(y, mod - 2, mod), mod);
}
static long ModComb(long n, long r, long mod) {
long numerator = 1;
for (int i = 0; i < r; i++) {
numerator = ModMul(numerator, n - i, mod);
}
long denominator = ModFact(r, mod);
return ModDiv(numerator, denominator, mod);
}
class Graph {
private int _size;
private List<int>[] _edges;
public Graph(int size) {
_size = size;
_edges = new List<int>[size];
}
public List<int> this[int i] {
get {
if (_edges[i] == null)
_edges[i] = new List<int>();
return _edges[i];
}
}
}
class Graph<T> {
private int _size;
private List<T>[] _edges;
public Graph(int size) {
_size = size;
_edges = new List<T>[size];
}
public List<T> this[int i] {
get {
if (_edges[i] == null)
_edges[i] = new List<T>();
return _edges[i];
}
}
}
static Graph<T> NewGraph<T>(int size, T template) {
return new Graph<T>(size);
}
static List<T> NewList<T>(T template) { return new List<T>(); }
static T[] NewArray<T>(int size, T template) { return new T[size]; }
static long p1097 = 1000000007;
static void Main(string[] args) {
//โ
var n = ReadLong();
if (n % 2 != 0) {
Console.WriteLine(0);
return;
}
long result = 0;
long five = 5;
n /= 2;
while (five <= n) {
result += n / five;
if (five == 7450580596923828125)
break;
five *= 5;
}
Console.WriteLine(result);
//โ
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 3,451
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
public void Solve() {
//ใใใใ
var o = IO.longm;
var n = o[0];
if (n == 10)
IO.wri(1);
else if ((n % 2) == 1)
IO.wri(0);
else {
var k = n / 2;
long aaa = 0;
for (long i = 5; i < k; i *= 5) {
aaa += (k / i);
}
var ans = Math.Min(k, aaa);
IO.wri(ans);
}
}
}
// b-aใง้้
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("No");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
public void Solve() {
//ใใใใ
var o = IO.longm;
var n = o[0];
if (n == 10)
IO.wri(1);
else if ((n % 2) == 1)
IO.wri(0);
else {
var k = n / 2;
long aaa = 0;
for (long i = 5; i <= k; i *= 5) {
aaa += (k / i);
}
var ans = Math.Min(k, aaa);
IO.wri(ans);
}
}
}
// b-aใง้้
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("No");
}
}
|
[["-", 75, 57, 75, 196, 0, 7, 15, 16, 17, 18], ["+", 75, 57, 75, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 905
| 2
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC148F {
class Program {
static void Main(string[] args) {
var N = RInt;
var u = RInt - 1;
var v = RInt - 1;
List<int>[] edges =
new List<int> [N].Select(x => new List<int>()).ToArray();
for (int i = 0; i < N - 1; i++) {
var a = RInt - 1;
var b = RInt - 1;
edges[a].Add(b);
edges[b].Add(a);
}
Queue<int> queA = new Queue<int>();
queA.Enqueue(v);
int[] distA = new int [N].Select(x => -1).ToArray();
distA[v] = 0;
while (queA.Count > 0) {
int now = queA.Dequeue();
foreach (var to in edges[now]) {
if (distA[to] == -1) {
distA[to] = distA[now] + 1;
queA.Enqueue(to);
}
}
}
Draw1D(distA);
Queue<int> queT = new Queue<int>();
queT.Enqueue(u);
int[] distT = new int [N].Select(x => -1).ToArray();
distT[u] = 0;
while (queT.Count > 0) {
int a = queT.Count;
for (int i = 0; i < a; i++) {
int now = queT.Dequeue();
foreach (var to in edges[now]) {
if (distT[to] != -1 || distA[to] <= distT[to])
continue;
distT[to] = distT[now] + 1;
queT.Enqueue(to);
}
}
}
Draw1D(distT);
int ans = 0;
for (int i = 0; i < N; i++) {
if (distT[i] == -1)
continue;
ans = Math.Max(distA[i] - 1, ans);
}
Console.WriteLine(ans);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//ไปฅไธๆชใในใ
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC148F {
class Program {
static void Main(string[] args) {
var N = RInt;
var u = RInt - 1;
var v = RInt - 1;
List<int>[] edges =
new List<int> [N].Select(x => new List<int>()).ToArray();
for (int i = 0; i < N - 1; i++) {
var a = RInt - 1;
var b = RInt - 1;
edges[a].Add(b);
edges[b].Add(a);
}
Queue<int> queA = new Queue<int>();
queA.Enqueue(v);
int[] distA = new int [N].Select(x => -1).ToArray();
distA[v] = 0;
while (queA.Count > 0) {
int now = queA.Dequeue();
foreach (var to in edges[now]) {
if (distA[to] == -1) {
distA[to] = distA[now] + 1;
queA.Enqueue(to);
}
}
}
Draw1D(distA);
Queue<int> queT = new Queue<int>();
queT.Enqueue(u);
int[] distT = new int [N].Select(x => -1).ToArray();
distT[u] = 0;
while (queT.Count > 0) {
int a = queT.Count;
for (int i = 0; i < a; i++) {
int now = queT.Dequeue();
foreach (var to in edges[now]) {
if (distT[to] != -1 || distA[to] <= distT[now] + 1)
continue;
distT[to] = distT[now] + 1;
queT.Enqueue(to);
}
}
}
Draw1D(distT);
int ans = 0;
for (int i = 0; i < N; i++) {
if (distT[i] == -1)
continue;
ans = Math.Max(distA[i] - 1, ans);
}
Console.WriteLine(ans);
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//ไปฅไธๆชใในใ
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
[["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
| 8
| 1,539
| 4
|
using System;
using System.Linq;
class A {
static void Main() {
int[] Ar = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
if (Ar.Sum() > 22)
Console.WriteLine("bust");
else
Console.WriteLine("win");
}
}
|
using System;
using System.Linq;
class A {
static void Main() {
int[] Ar = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
if (Ar.Sum() > 21)
Console.WriteLine("bust");
else
Console.WriteLine("win");
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 72
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC_147a {
class Program {
static void Main(string[] args) {
int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
if (input.Sum() <= 21) {
Console.WriteLine("win");
} else {
Console.WriteLine("burst");
}
Console.Read();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC_147a {
class Program {
static void Main(string[] args) {
int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
if (input.Sum() <= 21) {
Console.WriteLine("win");
} else {
Console.WriteLine("bust");
}
Console.Read();
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 112
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine().Split(' ');
int a1 = int.Parse(str[0]);
int a2 = int.Parse(str[1]);
int a3 = int.Parse(str[2]);
if (a1 + a2 + a3 <= 21) {
Console.WriteLine("Win");
} else {
Console.WriteLine("Burst");
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine().Split(' ');
int a1 = int.Parse(str[0]);
int a2 = int.Parse(str[1]);
int a3 = int.Parse(str[2]);
if (a1 + a2 + a3 <= 21) {
Console.WriteLine("win");
} else {
Console.WriteLine("bust");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 144
| 4
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
class DandA {
static void Main(string[] args) {
int[] aaa = ReadLineIntArray();
if (aaa[0] + aaa[0] + aaa[0] <= 21) {
Console.WriteLine("win");
} else {
Console.WriteLine("bust");
}
}
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
}
|
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
class DandA {
static void Main(string[] args) {
int[] aaa = ReadLineIntArray();
if (aaa[0] + aaa[1] + aaa[2] <= 21) {
Console.WriteLine("win");
} else {
Console.WriteLine("bust");
}
}
static private string ReadLineStr() { return Console.ReadLine(); }
static private int ReadLineInt() { return int.Parse(Console.ReadLine()); }
static private string[] ReadLineStrArray() {
return Console.ReadLine().Trim().Split();
}
static private int[] ReadLineIntArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => int.Parse(a))
.ToArray();
}
static private long[] ReadLineLongArray() {
return Console.ReadLine()
.Trim()
.Split()
.Select(a => long.Parse(a))
.ToArray();
}
static private string[][] ReadMLineStrArray(int arg) {
return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray();
}
static private int[][] ReadMLineIntArray(int arg) {
return new int [arg]
.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
.ToArray();
}
static private bool IsPrime(int num) {
if (num < 2)
return false;
if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0)
return false;
}
return true;
}
}
|
[["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 401
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC147A {
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 + c <= 21)
Console.WriteLine("Win");
else if (a + b + c >= 22)
Console.WriteLine("bust");
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC147A {
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 + c <= 21)
Console.WriteLine("win");
else if (a + b + c >= 22)
Console.WriteLine("bust");
Console.ReadKey();
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 148
| 2
|
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert
#if true && UTAKA_LOCAL
//#if false
#define UTAKA_DEBUG
#endif
//#define TOPCODER
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using static UtakaApp.Util;
namespace UtakaApp {
public partial class Program {
public const string SiteName = "AtCoder";
public const string ContestName = "abc149";
public const string ProblemName = "A";
public void Solve() {
string S = cin.Read;
string T = cin.Read;
cou.WriteLine(S + T);
}
}
//=========================================================================================
// Debug IO
//=========================================================================================
public partial class Program {
//=========================================================================================
// Main
//=========================================================================================
private readonly ConsoleInput cin;
private readonly IConsole cou;
public Program(ConsoleInput cin, IConsole cou) {
this.cin = cin;
this.cou = cou;
}
#if !TOPCODER
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems();
#else
var cin = new ConsoleInput(System.Console.In);
var console = new MyConsole();
new Program(cin, console).Solve();
console.Flush();
#endif
}
#endif
public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") {
if (!A.Any()) {
return;
}
var sb = new StringBuilder();
foreach (T v in A) {
sb.Append(v);
sb.Append(delimiter);
}
if (sb.Length > 0) {
sb.Length--;
}
cou.WriteLine(sb.ToString());
}
}
public static class Util {
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;
}
public static int LowerBound<T>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
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;
}
public static int UpperBound<T>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static int UpperBound<T>(List<T> list, 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(list[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int UpperBound<T>(List<T> list, T value) {
return UpperBound(list, 0, list.Count, value, Comparer<T>.Default);
}
public static T[] Array1D<T>(int a, T defaultValue)
where T : struct {
var ret = new T[a];
for (int i = 0; i < a; i++) {
ret[i] = defaultValue;
}
return ret;
}
public static T[] Array1D<T>(int a)
where T : struct {
var ret = new T[a];
return ret;
}
/// <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[,] Array2D<T>(int a, int b, T defaultValue)
where T : struct {
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;
}
public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue)
where T : struct {
T[,,] ret = new T[a, b, c];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
for (int k = 0; k < c; k++) {
ret[i, j, k] = defaultValue;
}
}
}
return ret;
}
/// <summary>
/// ่ฆ็ด ๆฐ (a, b) ใฎใdefaultValue ใงๆบใใใใJag้
ๅใไฝๆใใพใใ
/// </summary>
/// <typeparam name="T">้
ๅใฎๅ</typeparam>
/// <param name="a">1ๆฌกๅ
ใฎ่ฆ็ด ๆฐ</param>
/// <param name="b">2ๆฌกๅ
ใฎ่ฆ็ด ๆฐ</param>
/// <param name="defaultValue">ใใใฉใซใๅค</param>
/// <returns>ๆๅฎใใๆกไปถใงๅๆๅใใใ้
ๅ</returns>
public static T[][] JagArray2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
var row = new T[b];
ret[i] = row;
for (int j = 0; j < b; j++) {
row[j] = defaultValue;
}
}
return ret;
}
/// <summary>
/// ่ฆ็ด ๆฐ (a, b) ใฎdefaultๅคใงๆบใใใใJag้
ๅใไฝๆใใพใใ
/// </summary>
/// <typeparam name="T">้
ๅใฎๅ</typeparam>
/// <param name="a">1ๆฌกๅ
ใฎ่ฆ็ด ๆฐ</param>
/// <param name="b">2ๆฌกๅ
ใฎ่ฆ็ด ๆฐ</param>
/// <returns>ๅๆๅใใใ้
ๅ</returns>
public static T[][] JagArray2D<T>(int a, int b)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
ret[i] = new T[b];
}
return ret;
}
public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue)
where T : struct {
var ret = new T[a][][];
for (int i = 0; i < a; i++) {
T[][] aRow = new T[b][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[] bRow = new T[c];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
bRow[k] = defaultValue;
}
}
}
return ret;
}
public static T[][][] JagArray3D<T>(int a, int b, int c)
where T : struct {
var ret = new T[a][][];
for (int i = 0; i < a; i++) {
T[][] aRow = new T[b][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[] bRow = new T[c];
aRow[j] = bRow;
}
}
return ret;
}
public static T[][][][] JagArray4D<T>(int a, int b, int c, int d,
T defaultValue)
where T : struct {
var ret = new T[a][][][];
for (int i = 0; i < a; i++) {
T[][][] aRow = new T[b][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][] bRow = new T[c][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[] cRow = new T[d];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
cRow[l] = defaultValue;
}
}
}
}
return ret;
}
public static T[][][][] JagArray4D<T>(int a, int b, int c, int d)
where T : struct {
var ret = new T[a][][][];
for (int i = 0; i < a; i++) {
T[][][] aRow = new T[b][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][] bRow = new T[c][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[] cRow = new T[d];
bRow[k] = cRow;
}
}
}
return ret;
}
public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e,
T defaultValue)
where T : struct {
var ret = new T[a][][][][];
for (int i = 0; i < a; i++) {
T[][][][] aRow = new T[b][][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][][] bRow = new T[c][][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[][] cRow = new T[d][];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
T[] dRow = new T[e];
cRow[l] = dRow;
for (int m = 0; m < e; m++) {
dRow[m] = defaultValue;
}
}
}
}
}
return ret;
}
public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e)
where T : struct {
var ret = new T[a][][][][];
for (int i = 0; i < a; i++) {
T[][][][] aRow = new T[b][][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][][] bRow = new T[c][][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[][] cRow = new T[d][];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
T[] dRow = new T[e];
cRow[l] = dRow;
}
}
}
}
return ret;
}
/// <summary>
/// ใธใฃใฐ้
ๅใใณใใผใใฆ่ฟใใ
/// </summary>
public static T[][] CopyJagArray2D<T>(T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
}
public static class UtakaExtentions {
/// <summary>
/// IList<T>ใใณใใผใใพใ
/// </summary>
public static T[] Copy<T>(this IList<T> a) {
T[] ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
/// <summary>
/// 2ๆฌกๅ
ใธใฃใฐ้
ๅใใณใใผใใฆ่ฟใใ
/// </summary>
public static T[][] Copy<T>(this T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
}
public class IntLargeComparer : IComparer<int> {
public static IntLargeComparer Instance = new IntLargeComparer();
public int Compare(int x, int y) { return y - x; }
}
public class LongLargeComparer : IComparer<long> {
public static LongLargeComparer Instance = new LongLargeComparer();
public int Compare(long x, long y) {
if (x > y)
return -1;
if (x < y)
return 1;
return 0;
}
}
public class ConsoleInput {
private readonly char _separator = ' ';
private readonly TextReader _stream;
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => double.Parse(Read);
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i) {
ret[i] = Read;
}
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadInt;
}
return ret;
}
public int[] ReadIntArrayMinus1(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadInt - 1;
}
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadLong;
}
return ret;
}
}
public interface IConsole {
void Flush();
void Write(object obj);
void Write(string str);
void WriteLine(object obj);
void WriteLine(string str);
void WriteLine();
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { Console.WriteLine(str); }
public void WriteLine() { Console.WriteLine(); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// ไฝใใใชใ
}
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { mSb.Append(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public void WriteLine() { mSb.AppendLine(); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string GetDirectoryPath() {
var problemPart = string.IsNullOrEmpty(Program.ProblemName)
? ""
: $"/{Program.ProblemName}";
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
}
private string GetInputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
}
private string GetOutputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var cin = new ConsoleInput(inputStream);
var debugConsoleWriter = new DebugConsole();
new Program(cin, debugConsoleWriter).Solve();
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems(int targetTestCaseNumber = -1) {
if (targetTestCaseNumber >= 0) {
Console.WriteLine(
$"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
}
bool isSuccessAll = true;
int testCaseNumber = 0;
while (true) {
testCaseNumber++;
bool foundTargetTest = targetTestCaseNumber == testCaseNumber;
if (targetTestCaseNumber >= 0 && !foundTargetTest) {
continue;
}
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
if (foundTargetTest) {
break;
}
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
public static class Dbg {
[Conditional("UTAKA_DEBUG")]
public static void WriteLine(string str) { Console.WriteLine(str); }
[Conditional("UTAKA_DEBUG")]
public static void WriteLine() { Console.WriteLine(); }
[Conditional("UTAKA_DEBUG")]
public static void Write(string str) { Console.Write(str); }
}
}
|
// ReSharper disable ArrangeTypeMemberModifiers
// ReSharper disable ConvertIfStatementToSwitchStatement
// ReSharper disable FunctionRecursiveOnAllPaths
// ReSharper disable InconsistentNaming
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable InvertIf
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable MemberCanBeMadeStatic.Global
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable NonReadonlyMemberInGetHashCode
// ReSharper disable PossibleNullReferenceException
// ReSharper disable RedundantUsingDirective
// ReSharper disable SuggestVarOrType_BuiltInTypes
// ReSharper disable SuggestVarOrType_Elsewhere
// ReSharper disable TailRecursiveCall
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMember.Local
// ReSharper disable UseObjectOrCollectionInitializert
#if true && UTAKA_LOCAL
//#if false
#define UTAKA_DEBUG
#endif
//#define TOPCODER
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using static UtakaApp.Util;
namespace UtakaApp {
public partial class Program {
public const string SiteName = "AtCoder";
public const string ContestName = "abc149";
public const string ProblemName = "A";
public void Solve() {
string S = cin.Read;
string T = cin.Read;
cou.WriteLine(T + S);
}
}
//=========================================================================================
// Debug IO
//=========================================================================================
public partial class Program {
//=========================================================================================
// Main
//=========================================================================================
private readonly ConsoleInput cin;
private readonly IConsole cou;
public Program(ConsoleInput cin, IConsole cou) {
this.cin = cin;
this.cou = cou;
}
#if !TOPCODER
public static void Main(string[] args) {
#if UTAKA_LOCAL
//#if false
new TestCaseCheckerForAtCoder().TestProblems();
#else
var cin = new ConsoleInput(System.Console.In);
var console = new MyConsole();
new Program(cin, console).Solve();
console.Flush();
#endif
}
#endif
public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") {
if (!A.Any()) {
return;
}
var sb = new StringBuilder();
foreach (T v in A) {
sb.Append(v);
sb.Append(delimiter);
}
if (sb.Length > 0) {
sb.Length--;
}
cou.WriteLine(sb.ToString());
}
}
public static class Util {
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;
}
public static int LowerBound<T>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
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;
}
public static int UpperBound<T>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static int UpperBound<T>(List<T> list, 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(list[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
public static int UpperBound<T>(List<T> list, T value) {
return UpperBound(list, 0, list.Count, value, Comparer<T>.Default);
}
public static T[] Array1D<T>(int a, T defaultValue)
where T : struct {
var ret = new T[a];
for (int i = 0; i < a; i++) {
ret[i] = defaultValue;
}
return ret;
}
public static T[] Array1D<T>(int a)
where T : struct {
var ret = new T[a];
return ret;
}
/// <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[,] Array2D<T>(int a, int b, T defaultValue)
where T : struct {
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;
}
public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue)
where T : struct {
T[,,] ret = new T[a, b, c];
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
for (int k = 0; k < c; k++) {
ret[i, j, k] = defaultValue;
}
}
}
return ret;
}
/// <summary>
/// ่ฆ็ด ๆฐ (a, b) ใฎใdefaultValue ใงๆบใใใใJag้
ๅใไฝๆใใพใใ
/// </summary>
/// <typeparam name="T">้
ๅใฎๅ</typeparam>
/// <param name="a">1ๆฌกๅ
ใฎ่ฆ็ด ๆฐ</param>
/// <param name="b">2ๆฌกๅ
ใฎ่ฆ็ด ๆฐ</param>
/// <param name="defaultValue">ใใใฉใซใๅค</param>
/// <returns>ๆๅฎใใๆกไปถใงๅๆๅใใใ้
ๅ</returns>
public static T[][] JagArray2D<T>(int a, int b, T defaultValue)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
var row = new T[b];
ret[i] = row;
for (int j = 0; j < b; j++) {
row[j] = defaultValue;
}
}
return ret;
}
/// <summary>
/// ่ฆ็ด ๆฐ (a, b) ใฎdefaultๅคใงๆบใใใใJag้
ๅใไฝๆใใพใใ
/// </summary>
/// <typeparam name="T">้
ๅใฎๅ</typeparam>
/// <param name="a">1ๆฌกๅ
ใฎ่ฆ็ด ๆฐ</param>
/// <param name="b">2ๆฌกๅ
ใฎ่ฆ็ด ๆฐ</param>
/// <returns>ๅๆๅใใใ้
ๅ</returns>
public static T[][] JagArray2D<T>(int a, int b)
where T : struct {
var ret = new T[a][];
for (int i = 0; i < a; i++) {
ret[i] = new T[b];
}
return ret;
}
public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue)
where T : struct {
var ret = new T[a][][];
for (int i = 0; i < a; i++) {
T[][] aRow = new T[b][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[] bRow = new T[c];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
bRow[k] = defaultValue;
}
}
}
return ret;
}
public static T[][][] JagArray3D<T>(int a, int b, int c)
where T : struct {
var ret = new T[a][][];
for (int i = 0; i < a; i++) {
T[][] aRow = new T[b][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[] bRow = new T[c];
aRow[j] = bRow;
}
}
return ret;
}
public static T[][][][] JagArray4D<T>(int a, int b, int c, int d,
T defaultValue)
where T : struct {
var ret = new T[a][][][];
for (int i = 0; i < a; i++) {
T[][][] aRow = new T[b][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][] bRow = new T[c][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[] cRow = new T[d];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
cRow[l] = defaultValue;
}
}
}
}
return ret;
}
public static T[][][][] JagArray4D<T>(int a, int b, int c, int d)
where T : struct {
var ret = new T[a][][][];
for (int i = 0; i < a; i++) {
T[][][] aRow = new T[b][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][] bRow = new T[c][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[] cRow = new T[d];
bRow[k] = cRow;
}
}
}
return ret;
}
public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e,
T defaultValue)
where T : struct {
var ret = new T[a][][][][];
for (int i = 0; i < a; i++) {
T[][][][] aRow = new T[b][][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][][] bRow = new T[c][][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[][] cRow = new T[d][];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
T[] dRow = new T[e];
cRow[l] = dRow;
for (int m = 0; m < e; m++) {
dRow[m] = defaultValue;
}
}
}
}
}
return ret;
}
public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e)
where T : struct {
var ret = new T[a][][][][];
for (int i = 0; i < a; i++) {
T[][][][] aRow = new T[b][][][];
ret[i] = aRow;
for (int j = 0; j < b; j++) {
T[][][] bRow = new T[c][][];
aRow[j] = bRow;
for (int k = 0; k < c; k++) {
T[][] cRow = new T[d][];
bRow[k] = cRow;
for (int l = 0; l < d; l++) {
T[] dRow = new T[e];
cRow[l] = dRow;
}
}
}
}
return ret;
}
/// <summary>
/// ใธใฃใฐ้
ๅใใณใใผใใฆ่ฟใใ
/// </summary>
public static T[][] CopyJagArray2D<T>(T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
}
public static class UtakaExtentions {
/// <summary>
/// IList<T>ใใณใใผใใพใ
/// </summary>
public static T[] Copy<T>(this IList<T> a) {
T[] ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
/// <summary>
/// 2ๆฌกๅ
ใธใฃใฐ้
ๅใใณใใผใใฆ่ฟใใ
/// </summary>
public static T[][] Copy<T>(this T[][] source)
where T : struct {
int len = source.Length;
T[][] dest = new T[len][];
for (int i = 0; i < len; i++) {
T[] inner = source[i];
int innerLength = inner.Length;
T[] newer = new T[innerLength];
Array.Copy(inner, newer, innerLength);
dest[i] = newer;
}
return dest;
}
}
public class IntLargeComparer : IComparer<int> {
public static IntLargeComparer Instance = new IntLargeComparer();
public int Compare(int x, int y) { return y - x; }
}
public class LongLargeComparer : IComparer<long> {
public static LongLargeComparer Instance = new LongLargeComparer();
public int Compare(long x, long y) {
if (x > y)
return -1;
if (x < y)
return 1;
return 0;
}
}
public class ConsoleInput {
private readonly char _separator = ' ';
private readonly TextReader _stream;
private readonly Queue<string> inputStream;
public ConsoleInput(TextReader stream, char separator = ' ') {
_separator = separator;
_stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0) {
return inputStream.Dequeue();
}
var tmp = _stream.ReadLine().Split(_separator);
for (var i = 0; i < tmp.Length; ++i) {
inputStream.Enqueue(tmp[i]);
}
return inputStream.Dequeue();
}
}
public string ReadLine => _stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => double.Parse(Read);
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i) {
ret[i] = Read;
}
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadInt;
}
return ret;
}
public int[] ReadIntArrayMinus1(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadInt - 1;
}
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i) {
ret[i] = ReadLong;
}
return ret;
}
}
public interface IConsole {
void Flush();
void Write(object obj);
void Write(string str);
void WriteLine(object obj);
void WriteLine(string str);
void WriteLine();
}
public class MyConsole : IConsole {
public MyConsole() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
public void Flush() { Console.Out.Flush(); }
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { Console.Write(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { Console.WriteLine(str); }
public void WriteLine() { Console.WriteLine(); }
}
#if UTAKA_LOCAL
public class DebugConsole : IConsole {
private readonly StringBuilder mSb;
public DebugConsole() { mSb = new StringBuilder(); }
public void Flush() {
// ไฝใใใชใ
}
public void Write(object obj) { Write(obj.ToString()); }
public void Write(string str) { mSb.Append(str); }
public void WriteLine(object obj) { WriteLine(obj.ToString()); }
public void WriteLine(string str) { mSb.AppendLine(str); }
public void WriteLine() { mSb.AppendLine(); }
public string GetAllOutput() { return mSb.ToString(); }
}
#endif
#if UTAKA_LOCAL
public class TestCaseCheckerForAtCoder {
private string GetDirectoryPath() {
var problemPart = string.IsNullOrEmpty(Program.ProblemName)
? ""
: $"/{Program.ProblemName}";
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}";
}
private string GetInputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in";
}
private string GetOutputFilePath(int testCaseNumber) {
return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out";
}
public bool TestProblem(int testCaseNumber) {
var inputFilePath = GetInputFilePath(testCaseNumber);
var outputFilePath = GetOutputFilePath(testCaseNumber);
TextReader inputStream = new StreamReader(inputFilePath);
var cin = new ConsoleInput(inputStream);
var debugConsoleWriter = new DebugConsole();
new Program(cin, debugConsoleWriter).Solve();
var output = debugConsoleWriter.GetAllOutput();
TextReader outputStream = new StreamReader(outputFilePath);
var outputAnswer = outputStream.ReadToEnd();
Dbg.WriteLine(output);
Dbg.WriteLine(outputAnswer);
var isCorrect = output == outputAnswer;
return isCorrect;
}
public void TestProblems(int targetTestCaseNumber = -1) {
if (targetTestCaseNumber >= 0) {
Console.WriteLine(
$"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!");
}
bool isSuccessAll = true;
int testCaseNumber = 0;
while (true) {
testCaseNumber++;
bool foundTargetTest = targetTestCaseNumber == testCaseNumber;
if (targetTestCaseNumber >= 0 && !foundTargetTest) {
continue;
}
var inputFileName = GetInputFilePath(testCaseNumber);
if (!File.Exists(inputFileName)) {
break;
}
Console.WriteLine(
$"TestCase {testCaseNumber} =====================================================");
var result = TestProblem(testCaseNumber);
if (result) {
Console.WriteLine("Success");
} else {
isSuccessAll = false;
Console.WriteLine("Failure *****");
}
if (foundTargetTest) {
break;
}
}
if (isSuccessAll) {
Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!");
}
}
}
#endif
public static class Dbg {
[Conditional("UTAKA_DEBUG")]
public static void WriteLine(string str) { Console.WriteLine(str); }
[Conditional("UTAKA_DEBUG")]
public static void WriteLine() { Console.WriteLine(); }
[Conditional("UTAKA_DEBUG")]
public static void Write(string str) { Console.Write(str); }
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 3,878
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long[] iArray =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long A = iArray[0];
long B = iArray[1];
long K = iArray[2];
if (A == 0 && B == 0) {
Console.WriteLine(A + " " + B);
} else if (A > K) {
Console.WriteLine((A - K) + " " + B);
} else if (A - K < 0) {
if (B - (K - A) < 0) {
Console.WriteLine("0" + " " + "0");
} else {
Console.WriteLine("0" + " " + (B - (K - A)));
}
}
}
}
}
// ๆๅญๅใฎๅ
ฅๅ
// 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.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long[] iArray =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long A = iArray[0];
long B = iArray[1];
long K = iArray[2];
if (A == 0 && B == 0) {
Console.WriteLine(A + " " + B);
} else if (A > K) {
Console.WriteLine((A - K) + " " + B);
} else if (A - K <= 0) {
if (B - (K - A) <= 0) {
Console.WriteLine("0" + " " + "0");
} else {
Console.WriteLine("0" + " " + (B - (K - A)));
}
}
}
}
}
// ๆๅญๅใฎๅ
ฅๅ
// 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, 57, 75, 57, 75, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 19], ["-", 75, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 232
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace GreedyTakahashi {
class Program {
static void Main(string[] args) {
var abk = Console.ReadLine().Split();
int A = int.Parse(abk[0]);
int B = int.Parse(abk[1]);
int K = int.Parse(abk[2]);
if (K > A) {
K -= A;
A = 0;
} else {
A -= K;
K = 0;
}
if (K > B) {
K -= B;
B = 0;
} else {
B -= K;
K = 0;
}
Console.WriteLine(A.ToString() + " " + B.ToString());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace GreedyTakahashi {
class Program {
static void Main(string[] args) {
var abk = Console.ReadLine().Split();
long A = long.Parse(abk[0]);
long B = long.Parse(abk[1]);
long K = long.Parse(abk[2]);
if (K > A) {
K -= A;
A = 0;
} else {
A -= K;
K = 0;
}
if (K > B) {
K -= B;
B = 0;
} else {
B -= K;
K = 0;
}
Console.WriteLine(A.ToString() + " " + B.ToString());
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 161
| 12
|
using System;
namespace ABC149B {
class Program {
static void Main(string[] args) {
int a, b, k;
string[] ss = Console.ReadLine().Split(' ');
a = int.Parse(ss[0]);
b = int.Parse(ss[1]);
k = int.Parse(ss[2]);
if (a + b <= k)
Console.WriteLine("0" + " " + "0");
else if (a + b >= k && a <= k)
Console.WriteLine("0" + " " + (b - (k - a)));
else if (a + b >= k && a > k)
Console.WriteLine((a - k) + " " + b);
Console.ReadKey();
}
}
}
|
using System;
namespace ABC149B {
class Program {
static void Main(string[] args) {
double a, b, k;
string[] ss = Console.ReadLine().Split(' ');
a = double.Parse(ss[0]);
b = double.Parse(ss[1]);
k = double.Parse(ss[2]);
if (a + b <= k)
Console.WriteLine("0" + " " + "0");
else if (a + b >= k && a <= k)
Console.WriteLine("0" + " " + (b - (k - a)));
else if (a + b >= k && a > k)
Console.WriteLine((a - k) + " " + b);
Console.ReadKey();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
| 8
| 180
| 8
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static void Main() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
var a = input[0];
var b = input[1];
var k = input[2];
if (k <= a)
Console.WriteLine("{0} {1}", a - k, b);
else if (k <= a + b)
Console.WriteLine("0 {0}", a + b - k);
else
Console.WriteLine(0);
Console.Out.Flush();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static void Main() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var input = Reads();
var a = input[0];
var b = input[1];
var k = input[2];
if (k <= a)
Console.WriteLine("{0} {1}", a - k, b);
else if (k <= a + b)
Console.WriteLine("0 {0}", a + b - k);
else
Console.WriteLine("0 0");
Console.Out.Flush();
}
}
|
[["-", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 201
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var soliver = new Solver();
soliver.Exe();
}
}
public class Solver {
public void Exe() {
var p = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
if (p[0] > p[2]) {
Console.WriteLine($"{p[0 - p[2]]} {p[1]}");
} else if (p[1] > p[2] - p[0]) {
Console.WriteLine($"0 {p[1] - (p[2] - p[0])}");
} else {
Console.WriteLine($"0 0");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var soliver = new Solver();
soliver.Exe();
// Console.ReadLine();
}
}
public class Solver {
public void Exe() {
var p = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
if (p[0] > p[2]) {
Console.WriteLine($"{p[0] - p[2]} {p[1]}");
} else if (p[1] > p[2] - p[0]) {
Console.WriteLine($"0 {p[1] - (p[2] - p[0])}");
} else {
Console.WriteLine($"0 0");
}
}
}
}
|
[["+", 0, 284, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 200
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main() {
var tmp = ReadLine();
long a = tmp[0];
long b = tmp[1];
long k = tmp[2];
if (a <= k) {
k -= a;
a = 0;
} else {
a -= k;
}
if (b <= k) {
k -= b;
b = 0;
} else {
b -= k;
}
Console.WriteLine(a + " " + b);
}
static List<long> ReadLine() {
var line = Console.ReadLine();
var array = line.Split(' ');
return array.Select(x => long.Parse(x)).ToList();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main() {
var tmp = ReadLine();
long a = tmp[0];
long b = tmp[1];
long k = tmp[2];
if (a <= k) {
k -= a;
a = 0;
} else {
a -= k;
k = 0;
}
if (b <= k) {
k -= b;
b = 0;
} else {
b -= k;
}
Console.WriteLine(a + " " + b);
}
static List<long> ReadLine() {
var line = Console.ReadLine();
var array = line.Split(' ');
return array.Select(x => long.Parse(x)).ToList();
}
}
}
|
[["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 170
| 4
|
using System;
namespace example {
class plactis {
static void Main() {
string line = System.Console.ReadLine();
string[] l = line.Split(' ');
long[] data = new long[l.Length];
for (int i = 0; i < l.Length; i++) {
data[i] = long.Parse(l[i]);
}
if ((data[0] + data[1]) - data[2] <= 0) {
Console.WriteLine("0 0");
}
else if (data[0] - data[2] <= 0) {
Console.WriteLine("0 " + (data[0] - data[2]) + data[1]);
}
else if (data[0] - data[2] > 0) {
Console.WriteLine((data[0] - data[2]) + " " + data[1]);
}
}
}
}
|
using System;
namespace example {
class plactis {
static void Main() {
string line = System.Console.ReadLine();
string[] l = line.Split(' ');
long[] data = new long[l.Length];
for (int i = 0; i < l.Length; i++) {
data[i] = long.Parse(l[i]);
}
if ((data[0] + data[1]) - data[2] <= 0) {
Console.WriteLine("0 0");
}
else if (data[0] - data[2] <= 0) {
Console.WriteLine("0 " + ((data[0] - data[2]) + data[1]));
}
else if (data[0] - data[2] > 0) {
Console.WriteLine((data[0] - data[2]) + " " + data[1]);
}
}
}
}
|
[["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 207
| 2
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
long A = long.Parse(str[0]);
long B = long.Parse(str[1]);
long K = long.Parse(str[2]);
if (A >= K)
A = A - K;
else {
K = K - A;
B = B - K;
if (B < 0)
B = 0;
}
Console.WriteLine($"{A} {B}");
}
}
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //ๆจๆบๅ
ฅๅ
string[] str = Console.ReadLine().Split(' ');//2ใคไปฅไธใฎในใใผในๅบๅใๅ
ฅๅใฎๅๅพ
b = long.Parse(str[0]); //ๆฐๅคใงๅใๅใใใๅ ดๅใฏๅคๆใใ
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("ๆน่กใชใ a = {0} b = {1} c = {2}", a, b, c)//ๆน่กใชใๅบๅ
Console.WriteLine("ๆน่กใใ a = {0} b = {1} c = {2}", a, b, c);//ๆน่กไปใๅบๅ
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();
string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
*/
/*
static long func(long n)
{
long d = 0;
for (long i = 0; i < 10; i++)
{
if (n / longPow(10, i) == 0)
{
d = i;
break;
}
}
long ret = A * n + B * d;
return ret;
}
static long longPow(long a, long n)
{
long b = 1;
for (long i = 0; i < n; i++) b = b * a;
return b;
}
*/
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
long A = long.Parse(str[0]);
long B = long.Parse(str[1]);
long K = long.Parse(str[2]);
if (A >= K)
A = A - K;
else {
K = K - A;
B = B - K;
if (B < 0)
B = 0;
A = 0;
}
Console.WriteLine($"{A} {B}");
}
}
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //ๆจๆบๅ
ฅๅ
string[] str = Console.ReadLine().Split(' ');//2ใคไปฅไธใฎในใใผในๅบๅใๅ
ฅๅใฎๅๅพ
b = long.Parse(str[0]); //ๆฐๅคใงๅใๅใใใๅ ดๅใฏๅคๆใใ
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("ๆน่กใชใ a = {0} b = {1} c = {2}", a, b, c)//ๆน่กใชใๅบๅ
Console.WriteLine("ๆน่กใใ a = {0} b = {1} c = {2}", a, b, c);//ๆน่กไปใๅบๅ
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();
string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
*/
/*
static long func(long n)
{
long d = 0;
for (long i = 0; i < 10; i++)
{
if (n / longPow(10, i) == 0)
{
d = i;
break;
}
}
long ret = A * n + B * d;
return ret;
}
static long longPow(long a, long n)
{
long b = 1;
for (long i = 0; i < n; i++) b = b * a;
return b;
}
*/
|
[["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 133
| 4
|
using System;
namespace B {
class Program {
static void Main(string[] args) {
var s = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var A = s[0];
var B = s[1];
var K = s[2];
if (K < A) {
Console.WriteLine("{0} {1}", K - A, B);
} else if (A <= K && K < A + B) {
Console.WriteLine("{0} {1}", 0, B - (K - A));
} else if (A + B <= K) {
Console.WriteLine("0 0");
}
}
}
}
|
using System;
namespace B {
class Program {
static void Main(string[] args) {
var s = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var A = s[0];
var B = s[1];
var K = s[2];
if (K < A) {
Console.WriteLine("{0} {1}", A - K, B);
} else if (A <= K && K < A + B) {
Console.WriteLine("{0} {1}", 0, B - (K - A));
} else if (A + B <= K) {
Console.WriteLine("0 0");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 148
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public static void Main(string[] args) {
var p = Input();
var a = p[0].ToLong();
var b = p[1].ToLong();
var k = p[2].ToLong();
if (a - k >= 0) {
Console.WriteLine("{0} {1}", a - k, b - k);
return;
}
var c = b - (k - a);
if (c >= 0) {
Console.WriteLine("{0} {1}", 0, c);
return;
}
Console.WriteLine("0 0");
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public static void Main(string[] args) {
var p = Input();
var a = p[0].ToLong();
var b = p[1].ToLong();
var k = p[2].ToLong();
if (a - k >= 0) {
Console.WriteLine("{0} {1}", a - k, b);
return;
}
long c = b - (k - a);
if (c >= 0) {
Console.WriteLine("{0} {1}", 0, c);
return;
}
Console.WriteLine("0 0");
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 384
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;
public class Program {
public static void Main() {
var abk = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
var a = abk[0];
var b = abk[1];
var k = abk[2];
Console.WriteLine($"{Math.Max(0, a - k)} {b - (k - Math.Min(k, a))}");
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;
public class Program {
public static void Main() {
var abk = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
var a = abk[0];
var b = abk[1];
var k = abk[2];
Console.WriteLine(
$"{Math.Max(0, a - k)} {Math.Max(0, b - (k - Math.Min(k, a)))}");
}
}
|
[["+", 0, 283, 0, 284, 0, 213, 63, 214, 205, 22], ["+", 0, 283, 0, 284, 0, 213, 63, 214, 0, 131], ["+", 0, 283, 0, 284, 0, 213, 63, 214, 141, 22], ["+", 0, 283, 0, 284, 0, 213, 3, 4, 0, 24], ["+", 0, 284, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 283, 0, 284, 0, 213, 3, 4, 0, 21], ["+", 12, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 127
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var N = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var A = N[0];
var B = N[1];
var K = N[2];
var min = Math.Min(A, K);
if (min == A) {
var BL = A + B - K;
if (BL < 1) {
Console.WriteLine("0 0");
} else {
Console.WriteLine($"0 {A + B - K}");
}
} else {
Console.WriteLine($"{A-K} 0");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var N = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var A = N[0];
var B = N[1];
var K = N[2];
var min = Math.Min(A, K);
if (min == A) {
var BL = A + B - K;
if (BL < 1) {
Console.WriteLine("0 0");
} else {
Console.WriteLine($"0 {A + B - K}");
}
} else {
Console.WriteLine($"{A - K} {B}");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46]]
| 8
| 177
| 5
|
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) {
long[] nums =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
long A = nums[0];
long B = nums[1];
long K = nums[2];
if (A + B <= K) {
Console.WriteLine("0 0");
return;
}
if (A >= K) {
Console.WriteLine($"{A - K} 0");
return;
}
Console.WriteLine($"0 {B + A - K}");
}
}
}
|
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) {
long[] nums =
Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
long A = nums[0];
long B = nums[1];
long K = nums[2];
if (A + B <= K) {
Console.WriteLine("0 0");
return;
}
if (A >= K) {
Console.WriteLine($"{A - K} {B}");
return;
}
Console.WriteLine($"0 {B + A - K}");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46]]
| 8
| 165
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
static void Main(string[] args) {
string[] data = Console.ReadLine().Split(' ');
ulong a = ulong.Parse(data[0]);
ulong b = ulong.Parse(data[1]);
ulong k = ulong.Parse(data[2]);
/*for (ulong i = 0; i < k; i++)
{
if(a>0)
{
a--;
}else if (b > 0)
{
b--;
}
else
{
}
}*/
if (k < a) {
Console.WriteLine((a - k) + " " + b);
} else if (a <= k) {
if (a + b - k > 0) {
Console.WriteLine(0 + " " + (b + a - k));
} else if (a + b - k <= 0) {
Console.WriteLine(0 + " " + 0);
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_solve {
class Program {
static void Main(string[] args) {
string[] data = Console.ReadLine().Split(' ');
long a = long.Parse(data[0]);
long b = long.Parse(data[1]);
long k = long.Parse(data[2]);
/*for (ulong i = 0; i < k; i++)
{
if(a>0)
{
a--;
}else if (b > 0)
{
b--;
}
else
{
}
}*/
if (k < a) {
Console.WriteLine((a - k) + " " + b);
} else if (a <= k) {
if (a + b - k > 0) {
Console.WriteLine(0 + " " + (b + a - k));
} else if (a + b - k <= 0) {
Console.WriteLine(0 + " " + 0);
}
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 195
| 12
|
using System;
using System.Linq;
namespace AtCoderBeginnerContest149 {
class Program {
static void Main(string[] args) {
var inputs = Console.ReadLine()
.Split(' ')
.ToList()
.Select(x => long.Parse(x))
.ToList();
var a = inputs[0];
var b = inputs[1];
var k = inputs[2];
if (a >= k) {
a -= k;
Console.WriteLine(a + ' ' + b);
return;
} else {
k -= a;
if (b >= k) {
b -= k;
Console.WriteLine("0 " + b);
return;
} else {
Console.WriteLine("0 0");
return;
}
}
}
}
}
|
using System;
using System.Linq;
namespace AtCoderBeginnerContest149 {
class Program {
static void Main(string[] args) {
var inputs = Console.ReadLine()
.Split(' ')
.ToList()
.Select(x => long.Parse(x))
.ToList();
var a = inputs[0];
var b = inputs[1];
var k = inputs[2];
if (a >= k) {
a -= k;
Console.WriteLine(a + " " + b);
return;
} else {
k -= a;
if (b >= k) {
b -= k;
Console.WriteLine("0 " + b);
return;
} else {
Console.WriteLine("0 0");
return;
}
}
}
}
}
|
[["-", 0, 28, 0, 16, 31, 16, 12, 252, 0, 104], ["+", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62]]
| 8
| 160
| 4
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
namespace atcoder_past_problem {
class Program {
static void Main(string[] args) {
new Program().Solve(new Input(Console.In));
}
public void Solve(Input input) {
var a = input.ReadLong;
var b = input.ReadLong;
var k = input.ReadLong;
a = a - k;
if (a < 0) {
k = -1 * a;
a = 0;
} else
Console.WriteLine($"{a} {b}");
b = b - k;
if (b < 0) {
b = 0;
}
Console.WriteLine($"{a} {b}");
}
}
public class Input {
private TextReader Stream { get; }
private char Separator { get; }
private Queue<string> InputStream { get; }
public Input(TextReader stream, char separator = ' ') {
Stream = stream;
Separator = separator;
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 => Stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => double.Parse(Read);
public int[] ReadIntArray =>
Stream.ReadLine().Split(Separator).Select(i => int.Parse(i)).ToArray();
public long[] ReadLongArray =>
Stream.ReadLine().Split(Separator).Select(l => long.Parse(l)).ToArray();
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
namespace atcoder_past_problem {
class Program {
static void Main(string[] args) {
new Program().Solve(new Input(Console.In));
}
public void Solve(Input input) {
var a = input.ReadLong;
var b = input.ReadLong;
var k = input.ReadLong;
a = a - k;
if (a < 0) {
k = -1 * a;
a = 0;
} else {
Console.WriteLine($"{a} {b}");
return;
}
b = b - k;
if (b < 0) {
b = 0;
}
Console.WriteLine($"{a} {b}");
}
}
public class Input {
private TextReader Stream { get; }
private char Separator { get; }
private Queue<string> InputStream { get; }
public Input(TextReader stream, char separator = ' ') {
Stream = stream;
Separator = separator;
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 => Stream.ReadLine();
public int ReadInt => int.Parse(Read);
public long ReadLong => long.Parse(Read);
public double ReadDouble => double.Parse(Read);
public int[] ReadIntArray =>
Stream.ReadLine().Split(Separator).Select(i => int.Parse(i)).ToArray();
public long[] ReadLongArray =>
Stream.ReadLine().Split(Separator).Select(l => long.Parse(l)).ToArray();
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 409
| 4
|
using System;
using System.Linq;
namespace Sample {
class Sample {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
bool flg = false;
int tmp = N;
int i = 0;
while (!IsPrime(tmp)) {
tmp += i;
i++;
}
Console.WriteLine(tmp);
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // ๅถๆฐใฏใใใใใ้คใ
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// ็ด ๆฐใงใฏใชใ
return false;
}
}
// ็ด ๆฐใงใใ
return true;
}
}
}
|
using System;
using System.Linq;
namespace Sample {
class Sample {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
bool flg = false;
int tmp = N;
int i = 0;
while (!IsPrime(tmp)) {
tmp++;
}
Console.WriteLine(tmp);
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // ๅถๆฐใฏใใใใใ้คใ
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// ็ด ๆฐใงใฏใชใ
return false;
}
}
// ็ด ๆฐใงใใ
return true;
}
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22]]
| 8
| 167
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
class MainClass : Scanner {
static void Main() {
int X = RInt();
int num = X;
while (true) {
bool frag = true;
for (int i = 2; i < Sqrt(X) + 2; i++) {
if (num % i == 0)
frag = false;
}
if (frag) {
WriteLine(num);
return;
}
num++;
}
}
}
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() {
int X = RInt();
int num = X;
while (true) {
bool frag = true;
for (int i = 2; i <= Sqrt(X); i++) {
if (num % i == 0)
frag = false;
}
if (frag) {
WriteLine(num);
return;
}
num++;
}
}
}
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, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 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]]
| 8
| 735
| 4
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC149C {
class Program {
static void Main(string[] args) {
var S = RInt;
var pList = PrimeNumbers(100010);
for (int i = 0; i < pList.Length; i++) {
if (pList[i] > S) {
Console.WriteLine(pList[i]);
return;
}
}
}
/// <summary>
/// ่ช็ถๆฐnไปฅไธใฎ็ด ๆฐprimeๅๆ (NloglogN)
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int[] PrimeNumbers(int n) {
int max = n;
var searchList = Enumerable.Range(2, max).ToList();
var pList = new List<int>();
while (searchList.Count > 0) {
int cand = searchList.First();
pList.Add(cand);
searchList.RemoveAll(x => x % cand == 0);
}
return pList.ToArray();
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//ไปฅไธๆชใในใ
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
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
}
public 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 ABC149C {
class Program {
static void Main(string[] args) {
var S = RInt;
var pList = PrimeNumbers(100010);
for (int i = 0; i < pList.Length; i++) {
if (pList[i] >= S) {
Console.WriteLine(pList[i]);
return;
}
}
}
/// <summary>
/// ่ช็ถๆฐnไปฅไธใฎ็ด ๆฐprimeๅๆ (NloglogN)
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int[] PrimeNumbers(int n) {
int max = n;
var searchList = Enumerable.Range(2, max).ToList();
var pList = new List<int>();
while (searchList.Count > 0) {
int cand = searchList.First();
pList.Add(cand);
searchList.RemoveAll(x => x % cand == 0);
}
return pList.ToArray();
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//ไปฅไธๆชใในใ
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
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
}
public static void Draw1D(int[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 780
| 2
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
static void Main(string[] args) {
var n = Read().ToInt();
var ans = 0;
for (int i = n + 1; i <= 999999; i++) {
if (IsPrime(i)) {
ans = i;
break;
}
}
WriteRead(ans);
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // ๅถๆฐใฏใใใใใ้คใ
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// ็ด ๆฐใงใฏใชใ
return false;
}
}
// ็ด ๆฐใงใใ
return true;
}
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); }
public static List<List<T>> Permutations<T>(List<T> src, int n) {
// nใฏ1ไปฅไธใใคsrcใฎ้ทใใใใ็ญใๅฟ
่ฆใใใใ
int len = src.Count;
if (!(0 < n && n <= len)) {
throw new ArgumentOutOfRangeException();
}
var permutations = new List<List<T>>();
var queue = new Queue<List<int>>(
Enumerable.Range(0, len).Select(i => new List<int>() { i }));
while (queue.Any()) {
var indexes = queue.Dequeue();
if (indexes.Count == n) {
permutations.Add(indexes.Select(index => src[index]).ToList());
continue;
}
for (int index = 0; index < len; index++) {
if (indexes.Contains(index)) {
continue;
}
var newIndexes = new List<int>(indexes);
newIndexes.Add(index);
queue.Enqueue(newIndexes);
}
}
return permutations;
}
}
}
public static class Extentions {
public static int ToInt(this object obj) { return int.Parse(obj.ToString()); }
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(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 {
static void Main(string[] args) {
var n = Read().ToInt();
var ans = 0;
for (int i = n; i <= 999999; i++) {
if (IsPrime(i)) {
ans = i;
break;
}
}
WriteRead(ans);
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // ๅถๆฐใฏใใใใใ้คใ
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// ็ด ๆฐใงใฏใชใ
return false;
}
}
// ็ด ๆฐใงใใ
return true;
}
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); }
public static List<List<T>> Permutations<T>(List<T> src, int n) {
// nใฏ1ไปฅไธใใคsrcใฎ้ทใใใใ็ญใๅฟ
่ฆใใใใ
int len = src.Count;
if (!(0 < n && n <= len)) {
throw new ArgumentOutOfRangeException();
}
var permutations = new List<List<T>>();
var queue = new Queue<List<int>>(
Enumerable.Range(0, len).Select(i => new List<int>() { i }));
while (queue.Any()) {
var indexes = queue.Dequeue();
if (indexes.Count == n) {
permutations.Add(indexes.Select(index => src[index]).ToList());
continue;
}
for (int index = 0; index < len; index++) {
if (indexes.Contains(index)) {
continue;
}
var newIndexes = new List<int>(indexes);
newIndexes.Add(index);
queue.Enqueue(newIndexes);
}
}
return permutations;
}
}
}
public static class Extentions {
public static int ToInt(this object obj) { return int.Parse(obj.ToString()); }
public static decimal ToDecimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double ToDouble(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();
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 615
| 2
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// MyDebugger.Test(process, "../TextFile2.txt");
// MyDebugger.MakeTestCase("../TextFile2.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var n = int.Parse(input.ReadLine());
while (true) {
if (IsPrimeNumber(n))
return n;
n++;
}
}
static bool IsPrimeNumber(long n) {
if (n % 2 == 0)
return false;
var r = (long)Math.Sqrt((double)n);
for (int i = 3; i <= r; i += 2) {
if (n % i == 0)
return false;
}
return true;
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// MyDebugger.Test(process, "../TextFile2.txt");
// MyDebugger.MakeTestCase("../TextFile2.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
static object process(TextReader input) {
var n = int.Parse(input.ReadLine());
while (true) {
if (IsPrimeNumber(n))
return n;
n++;
}
}
static bool IsPrimeNumber(long n) {
if (n > 2 && n % 2 == 0)
return false;
var r = (long)Math.Sqrt((double)n);
for (int i = 3; i <= r; i += 2) {
if (n % i == 0)
return false;
}
return true;
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22]]
| 8
| 197
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
namespace ConsoleApp5 {
public class Program {
// static void SendAll()
//{
// Console.WriteLine("Start!!!");
// int count = 0;
// // Read in the specified file.
// // ... Use async StreamReader method.
// for (int i = 0; i < 10; i++)
// {
// SendFinal("hello", "hi", "duongtrungvinh2711@gmail.com");
// count++;
// Console.WriteLine("Done {0}", count);
// }
// Console.WriteLine("End!!!");
//}
// static void SendFinal(string title, string content, string receiver)
//{
// string myemail = "tomgiongvn.vn@gmail.com";
// string mypassword = "tomgiongvn@123";
// MailMessage message = new MailMessage();
// message.IsBodyHtml = true;
// message.From = new MailAddress(myemail, "PHรNG TรI Vแปค HUFLIT");
// message.To.Add(new MailAddress(receiver));
// //message.CC.Add(new MailAddress(myemail));
// message.Subject = title + " | HUFLIT";
// message.Body = content;
// SmtpClient smtp = new SmtpClient();
// smtp.Host = "smtp.gmail.com";
// smtp.Port = 587;
// smtp.UseDefaultCredentials = false;
// smtp.EnableSsl = true;
// NetworkCredential nc = new NetworkCredential(myemail, mypassword);
// smtp.Credentials = nc;
// smtp.Send(message);
//}
static bool lant(int n) {
for (int i = 2; i < Math.Sqrt(n) + 1; i++)
if (n % i == 0)
return false;
return true;
}
static void Main(string[] args) {
// Task task = new Task(SendAll);
// task.Start();
// for (int i = 0; i < 10000; i++)
// Console.Write(i);
// var watch = System.Diagnostics.Stopwatch.StartNew();
// the code that you want to measure comes here
int a = int.Parse(Console.ReadLine());
if (a < 3) {
Console.WriteLine(2);
} else {
a++;
while (!lant(a))
a++;
Console.WriteLine(a);
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
namespace ConsoleApp5 {
public class Program {
// static void SendAll()
//{
// Console.WriteLine("Start!!!");
// int count = 0;
// // Read in the specified file.
// // ... Use async StreamReader method.
// for (int i = 0; i < 10; i++)
// {
// SendFinal("hello", "hi", "duongtrungvinh2711@gmail.com");
// count++;
// Console.WriteLine("Done {0}", count);
// }
// Console.WriteLine("End!!!");
//}
// static void SendFinal(string title, string content, string receiver)
//{
// string myemail = "tomgiongvn.vn@gmail.com";
// string mypassword = "tomgiongvn@123";
// MailMessage message = new MailMessage();
// message.IsBodyHtml = true;
// message.From = new MailAddress(myemail, "PHรNG TรI Vแปค HUFLIT");
// message.To.Add(new MailAddress(receiver));
// //message.CC.Add(new MailAddress(myemail));
// message.Subject = title + " | HUFLIT";
// message.Body = content;
// SmtpClient smtp = new SmtpClient();
// smtp.Host = "smtp.gmail.com";
// smtp.Port = 587;
// smtp.UseDefaultCredentials = false;
// smtp.EnableSsl = true;
// NetworkCredential nc = new NetworkCredential(myemail, mypassword);
// smtp.Credentials = nc;
// smtp.Send(message);
//}
static bool lant(int n) {
for (int i = 2; i < Math.Sqrt(n) + 1; i++)
if (n % i == 0)
return false;
return true;
}
static void Main(string[] args) {
// Task task = new Task(SendAll);
// task.Start();
// for (int i = 0; i < 10000; i++)
// Console.Write(i);
// var watch = System.Diagnostics.Stopwatch.StartNew();
// the code that you want to measure comes here
int a = int.Parse(Console.ReadLine());
if (a < 3) {
Console.WriteLine(2);
} else {
while (!lant(a))
a++;
Console.WriteLine(a);
}
}
}
}
|
[["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 196
| 3
|
using System;
using System.Linq;
namespace Next_Prime {
class Program {
static void Main(string[] args) {
const int MAX_PRIME = 100004;
var input = long.Parse(Console.ReadLine());
var primeArray = Enumerable.Repeat<bool>(true, MAX_PRIME + 1).ToArray();
primeArray[0] = false;
primeArray[1] = false;
for (var i = 2; i <= input; i++) {
if (primeArray[i]) {
var maxJ = MAX_PRIME / i;
for (var j = 1; j <= maxJ; j++) {
primeArray[i * j] = false;
}
}
}
var minPrime = primeArray.ToList().IndexOf(true);
Console.WriteLine(minPrime);
}
}
}
|
using System;
using System.Linq;
namespace Next_Prime {
class Program {
static void Main(string[] args) {
const int MAX_PRIME = 100004;
var input = long.Parse(Console.ReadLine());
var primeArray = Enumerable.Repeat<bool>(true, MAX_PRIME + 1).ToArray();
primeArray[0] = false;
primeArray[1] = false;
for (var i = 2; i < input; i++) {
if (primeArray[i]) {
var maxJ = MAX_PRIME / i;
for (var j = 1; j <= maxJ; j++) {
primeArray[i * j] = false;
}
}
}
var minPrime = primeArray.ToList().IndexOf(true);
Console.WriteLine(minPrime);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
| 8
| 160
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace atcorder {
class Program {
static void Main(string[] args) {
string strArray = Console.ReadLine();
int start = Int32.Parse(strArray);
while (start <= 100000) {
if (IsPrime(start)) {
Console.WriteLine(start);
return;
}
start++;
}
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // ๅถๆฐใฏใใใใใ้คใ
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// ็ด ๆฐใงใฏใชใ
return false;
}
}
// ็ด ๆฐใงใใ
return true;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace atcorder {
class Program {
static void Main(string[] args) {
string strArray = Console.ReadLine();
int start = Int32.Parse(strArray);
while (start <= 100003) {
if (IsPrime(start)) {
Console.WriteLine(start);
return;
}
start++;
}
}
public static bool IsPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // ๅถๆฐใฏใใใใใ้คใ
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// ็ด ๆฐใงใฏใชใ
return false;
}
}
// ็ด ๆฐใงใใ
return true;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203]]
| 8
| 181
| 2
|
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) {
var primes = Primes(10000);
var X = int.Parse(Console.ReadLine());
var prime = primes.SkipWhile(x => x < X).First();
Console.WriteLine(prime);
}
static IEnumerable<int> Primes(int maxnum) {
int[] sieve = Enumerable.Range(0, maxnum + 1).ToArray();
sieve[1] = 0;
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] <= 0)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = 0;
}
return sieve.Where(n => n > 0);
}
}
}
|
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) {
var primes = Primes(100010);
var X = int.Parse(Console.ReadLine());
var prime = primes.SkipWhile(x => x < X).First();
Console.WriteLine(prime);
}
static IEnumerable<int> Primes(int maxnum) {
int[] sieve = Enumerable.Range(0, maxnum + 1).ToArray();
sieve[1] = 0; // 0 : ็ด ๆฐใงใฏใชใ
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] <= 0)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = 0;
}
return sieve.Where(n => n > 0);
}
}
}
|
[["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 208
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace PaizaTest {
class Program {
static void Main(string[] args) {
var x = int.Parse(Console.ReadLine());
// ็ด ๆฐใๆฑใใ
var max = 100000;
var list = new List<int>();
for (int i = 2; i < max; i++) {
if (list.Any(s => i % s == 0)) {
continue;
}
list.Add(i);
}
var value = list.First(i => i > x);
Console.WriteLine(value);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace PaizaTest {
class Program {
static void Main(string[] args) {
var x = int.Parse(Console.ReadLine());
// ็ด ๆฐใๆฑใใ
var max = 110000;
var list = new List<int>();
for (int i = 2; i < max; i++) {
if (list.Any(s => i % s == 0)) {
continue;
}
list.Add(i);
}
var value = list.First(i => i >= x);
Console.WriteLine(value);
}
// static void Main(string[] args)
//{
// var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
//// 2 <= n <= 10^5
//// 1 <= k <= n - 1
//// ใฐใผใฎๅๅฉ็น: r
//// ใใงใญใฎๅๅฉ็น: s
//// ใใผใฎๅๅฉ็น: p
// var rsp = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
// var t = Console.ReadLine();
// var score = 0;
// var rScore = rsp[0];
// var sScore = rsp[1];
// var pScore = rsp[2];
// var myHandHistory = new List<int>();
//// r = 1;
//// s = 2;
//// p = 3;
// for (int i = 0; i < nk[0]; i++)
//{
// var enemyHand = t[i];
// switch (enemyHand)
// {
// case 'r':
// myHandHistory.Add(3);
// if (myHandHistory.Count - 1 > nk[1] && myHandHistory[i - nk[1]]
// != 3)
// {
// score += pScore;
// }
// break;
// case 's':
// myHandHistory.Add(1);
// if (myHandHistory.Count - 1 > nk[1] && myHandHistory[i - nk[1]]
// != 1)
// {
// score += rScore;
// }
// break;
// case 'p':
// myHandHistory.Add(2);
// if (myHandHistory.Count - 1 > nk[1] && myHandHistory[i - nk[1]]
// != 2)
// {
// score += sScore;
// }
// break;
// default:
// break;
// }
//}
// Console.WriteLine(score);
//}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20]]
| 8
| 128
| 4
|
using System;
namespace AtCoder {
class Program {
static void Main() {
int x = int.Parse(Console.ReadLine());
int xx = x;
int result = 0;
bool found = false;
while (!found) {
int check = 0;
for (int i = 1; i < xx; i++) {
if (xx % i == 0) {
check++;
}
}
if (check == 1) {
found = true;
result = xx;
} else {
xx++;
}
}
Console.WriteLine(found);
}
}
}
|
using System;
namespace AtCoder {
class Program {
static void Main() {
int x = int.Parse(Console.ReadLine());
int xx = x;
int result = 0;
bool found = false;
while (!found) {
int check = 0;
for (int i = 1; i < xx; i++) {
if (xx % i == 0) {
check++;
}
}
if (check == 1) {
found = true;
result = xx;
} else {
xx++;
}
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 117
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
// functions
public void Solve() {
//ใใใใ
var x = IO.int1;
var r = Primes(x * 2).ToArray();
Array.Sort(r);
foreach (var xx in r) {
if (xx > x) {
IO.wri(xx);
return;
}
}
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
}
// b-aใง้้
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public double[] doublem => strm.Select(double.Parse).ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
public double double1 => doublem[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("No");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
class Program {
static void Main(string[] args) {
var wrong_answer = new wrong_answer();
wrong_answer.Solve();
}
}
public class wrong_answer {
const int INF = 1 << 30;
const long INFL = 1L << 60;
const int MOD = 1000000007;
const int MOD2 = 998244353;
myinout IO = new myinout();
Math2 mmath = new Math2();
// functions
public void Solve() {
//ใใใใ
var x = IO.int1;
var r = Primes(x * 2).ToArray();
Array.Sort(r);
foreach (var xx in r) {
if (xx >= x) {
IO.wri(xx);
return;
}
}
}
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
}
// b-aใง้้
public class Math2 {
public long[] fact;
public long[] invfact;
public void factoricalmodset(long N, long MOD = 1000000007) {
fact = new long[N + 1];
invfact = new long[N + 1];
fact[0] = 1;
for (long i = 1; i <= N; ++i) {
fact[i] = fact[i - 1] * i % MOD;
}
invfact[N] = pow(fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invfact[i - 1] = invfact[i] * i % MOD;
}
}
public long nCr(long n, long r, long MOD = 1000000007) {
return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD);
}
public long pow(long i, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
n >>= 1;
}
return res;
}
public long gcd(long i, long y) {
while (y != 0) {
var r = i % y;
i = y;
y = r;
}
return i;
}
public long lcm(long i, long y) { return i * y / gcd(i, y); }
public Dictionary<long, int> primefactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public List<long> divisorenumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
public void swap<T>(ref T a, ref T b) {
var i = a;
a = b;
b = i;
}
}
class myinout {
// in
public string str => Console.ReadLine();
public string[] strm => str.Split(' ');
public long[] longm => strm.Select(long.Parse).ToArray();
public int[] intm => strm.Select(int.Parse).ToArray();
public char[] charm => str.ToArray();
public double[] doublem => strm.Select(double.Parse).ToArray();
public long long1 => longm[0];
public int int1 => intm[0];
public char char1 => charm[0];
public double double1 => doublem[0];
// out
public void wri<T>(T i) { Console.WriteLine(i); }
public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); }
public void yn(bool i) {
if (i)
wri("Yes");
else
wri("No");
}
}
|
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 1,012
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
for (int i = N; i < 100001; i++) {
if (Sosu(i)) {
Console.WriteLine(i);
break;
}
}
}
public static bool Sosu(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
for (int i = N; i < 1000000; i++) {
if (Sosu(i)) {
Console.WriteLine(i);
break;
}
}
}
public static bool Sosu(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
// ็ด ๆฐใงใใ
return true;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 178
| 2
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
var X = long.Parse(Console.ReadLine());
var syugo = SieveOfEratosthenes(100000).Where(n => n >= X).Min();
Console.WriteLine(syugo);
}
static List<long> SieveOfEratosthenes(long N) {
var Primes = new List<long>();
if (N > 0) {
var IsPrime = new bool[N + 1];
for (long i = 0; i <= N; i++) {
IsPrime[i] = true;
}
// 0ใจ1ใฏๆถใใฆใใ
IsPrime[0] = false;
IsPrime[1] = false;
for (long i = 2; i <= (long)Math.Sqrt(N); i++) {
if (IsPrime[i]) {
long j = i * 2;
for (long k = j; k <= N; k += i) {
IsPrime[k] = false;
}
}
}
for (long i = 1; i <= N; i++) {
if (IsPrime[i]) {
Primes.Add(i);
}
}
}
return Primes;
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
var X = long.Parse(Console.ReadLine());
var syugo = SieveOfEratosthenes(100090).Where(n => n >= X).Min();
Console.WriteLine(syugo);
}
static List<long> SieveOfEratosthenes(long N) {
var Primes = new List<long>();
if (N > 0) {
var IsPrime = new bool[N + 1];
for (long i = 0; i <= N; i++) {
IsPrime[i] = true;
}
// 0ใจ1ใฏๆถใใฆใใ
IsPrime[0] = false;
IsPrime[1] = false;
for (long i = 2; i <= (long)Math.Sqrt(N); i++) {
if (IsPrime[i]) {
long j = i * 2;
for (long k = j; k <= N; k += i) {
IsPrime[k] = false;
}
}
}
for (long i = 1; i <= N; i++) {
if (IsPrime[i]) {
Primes.Add(i);
}
}
}
return Primes;
}
}
|
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 265
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
//ๅ
ฅๅ
var arr = arrInt();
var n = arr[0];
var k = arr[1];
arr = arrInt();
string t = crS();
//ๅฎ็พฉ
var win = new char[n];
int sum = 0;
for (int i = 0; i < n; i++) {
var a = t[i];
var hen = henkan(a);
if (i - k >= 0) {
if (win[i - k] == hen) {
if (i + k < n) {
if (henkan(t[i + k]) != a)
win[i] = a;
else
win[i] = Other(a, hen);
continue;
}
}
}
win[i] = hen;
sum += point(hen, arr);
}
Console.WriteLine(sum);
}
static char henkan(char a) {
if (a == 'r')
return 'p';
if (a == 's')
return 'r';
if (a == 'p')
return 's';
return 'e';
}
static char Other(char a, char b) {
char[] arr = { 'r', 's', 'p' };
foreach (var ele in arr)
if (a != ele && b != ele)
return ele;
return 'e';
}
static int point(char a, int[] arr) {
if (a == 'r')
return arr[0];
if (a == 's')
return arr[1];
if (a == 'p')
return arr[2];
return 0;
}
//ๅ
ฅๅๅใๅใ็จ
static string crS() { return Console.ReadLine(); }
static int crI() { return int.Parse(Console.ReadLine()); }
static int[] arrInt() {
return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
}
static long[] arrLong() {
return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
}
static string[] arrStr() { return Console.ReadLine().Split(' ').ToArray(); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
//ๅ
ฅๅ
var arr = arrInt();
var n = arr[0];
var k = arr[1];
arr = arrInt();
string t = crS();
//ๅฎ็พฉ
var win = new char[n];
int sum = 0;
for (int i = 0; i < n; i++) {
var a = t[i];
var hen = henkan(a);
if (i - k >= 0) {
if (win[i - k] == hen) {
if (i + k < n) {
if (henkan(t[i + k]) != a)
win[i] = a;
else
win[i] = Other(a, hen);
}
continue;
}
}
win[i] = hen;
sum += point(hen, arr);
}
Console.WriteLine(sum);
}
static char henkan(char a) {
if (a == 'r')
return 'p';
if (a == 's')
return 'r';
if (a == 'p')
return 's';
return 'e';
}
static char Other(char a, char b) {
char[] arr = { 'r', 's', 'p' };
foreach (var ele in arr)
if (a != ele && b != ele)
return ele;
return 'e';
}
static int point(char a, int[] arr) {
if (a == 'r')
return arr[0];
if (a == 's')
return arr[1];
if (a == 'p')
return arr[2];
return 0;
}
//ๅ
ฅๅๅใๅใ็จ
static string crS() { return Console.ReadLine(); }
static int crI() { return int.Parse(Console.ReadLine()); }
static int[] arrInt() {
return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
}
static long[] arrLong() {
return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
}
static string[] arrStr() { return Console.ReadLine().Split(' ').ToArray(); }
}
|
[["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 513
| 2
|
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(' ');
int iN = int.Parse(sS[0]);
int iK = int.Parse(sS[1]);
List<ClsJan> lstJan = new List<ClsJan>();
sS = System.Console.ReadLine().Trim().Split(' ');
lstJan.Add(new ClsJan() { cJ = 'r', cA = 's', iG = int.Parse(sS[0]) });
lstJan.Add(new ClsJan() { cJ = 's', cA = 'p', iG = int.Parse(sS[1]) });
lstJan.Add(new ClsJan() { cJ = 'p', cA = 'r', iG = int.Parse(sS[2]) });
string sT = System.Console.ReadLine().Trim();
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// ่งฃๆ
lstJan.Sort(delegate(ClsJan mca1, ClsJan mca2) {
return (int)(mca2.iG - mca1.iG);
}); // ็นใฎ้้
int iOut = 0;
List<char> lstMyj = new List<char>();
for (int i = 0; i < sT.Length; i++) {
lstMyj.Add(' ');
}
for (int j = 0; j < lstJan.Count; j++) {
for (int i = 0; i < sT.Length; i++) {
if (sT[i] == lstJan[j].cA) {
if (i - iK >= 0) {
if (lstMyj[i - iK] != lstJan[j].cJ) {
lstMyj[i] = lstJan[j].cJ;
iOut += lstJan[j].iG;
} else {
lstMyj[i] = sT[i];
}
} else {
lstMyj[i] = lstJan[j].cJ;
iOut += lstJan[j].iG;
}
}
}
}
// ๅบๅ
System.Console.WriteLine("{0}", iOut.ToString().Trim());
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("็ถ่กใใใซใฏไฝใใญใผใๆผใใฆใใ ใใ๏ผ๏ผ๏ผ");
Console.ReadKey();
#endif
}
// ็ตๆๆ
ๅ ฑ
private class ClsJan {
public char cJ { get; set; } = ' '; // ่ชๅๆๅญ
public char cA { get; set; } = ' '; // ็ธๆๆๅญ
public int iG { get; set; } = 0; // ็น
}
}
|
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(' ');
int iN = int.Parse(sS[0]);
int iK = int.Parse(sS[1]);
List<ClsJan> lstJan = new List<ClsJan>();
sS = System.Console.ReadLine().Trim().Split(' ');
lstJan.Add(new ClsJan() { cJ = 'r', cA = 's', iG = int.Parse(sS[0]) });
lstJan.Add(new ClsJan() { cJ = 's', cA = 'p', iG = int.Parse(sS[1]) });
lstJan.Add(new ClsJan() { cJ = 'p', cA = 'r', iG = int.Parse(sS[2]) });
string sT = System.Console.ReadLine().Trim();
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// ่งฃๆ
lstJan.Sort(delegate(ClsJan mca1, ClsJan mca2) {
return (int)(mca2.iG - mca1.iG);
}); // ็นใฎ้้
int iOut = 0;
List<char> lstMyj = new List<char>();
for (int i = 0; i < sT.Length; i++) {
lstMyj.Add(' ');
}
for (int j = 0; j < lstJan.Count; j++) {
for (int i = 0; i < sT.Length; i++) {
if (sT[i] == lstJan[j].cA) {
if (i - iK >= 0) {
if (lstMyj[i - iK] != lstJan[j].cJ) {
lstMyj[i] = lstJan[j].cJ;
iOut += lstJan[j].iG;
} else {
lstMyj[i] = ' ';
}
} else {
lstMyj[i] = lstJan[j].cJ;
iOut += lstJan[j].iG;
}
}
}
}
// ๅบๅ
System.Console.WriteLine("{0}", iOut.ToString().Trim());
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("็ถ่กใใใซใฏไฝใใญใผใๆผใใฆใใ ใใ๏ผ๏ผ๏ผ");
Console.ReadKey();
#endif
}
// ็ตๆๆ
ๅ ฑ
private class ClsJan {
public char cJ { get; set; } = ' '; // ่ชๅๆๅญ
public char cA { get; set; } = ' '; // ็ธๆๆๅญ
public int iG { get; set; } = 0; // ็น
}
}
|
[["-", 75, 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], ["+", 75, 196, 0, 1, 0, 11, 12, 252, 0, 104], ["+", 75, 196, 0, 1, 0, 11, 12, 252, 0, 253]]
| 8
| 599
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace CSharp {
static class Program {
static void Main(string[] args) {
int n, k;
ReadInt(out n, out k);
int r, s, p;
ReadInt(out r, out s, out p);
var T = ReadString();
int ans = 0;
List<char> list = new List<char>();
for (int i = 0; i < T.Length; i++) {
char hand = Win(T[i]);
if (i - k >= 0 && list[i - k] == hand) {
list.Add(T[i]);
continue;
}
switch (hand) {
case 'r':
ans += r;
break;
case 's':
ans += s;
break;
case 'p':
ans += p;
break;
default:
break;
}
list.Add(hand);
}
Console.WriteLine(ans);
}
static char Win(char hand) {
switch (hand) {
case 'r':
return 'p';
case 's':
return 'r';
case 'p':
return 's';
default:
return '\0';
}
}
#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];
}
static string YesNo(bool condition) => condition ? "Yes" : "No";
static string YESNO(bool condition) => condition ? "YES" : "NO";
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace CSharp {
static class Program {
static void Main(string[] args) {
int n, k;
ReadInt(out n, out k);
int r, s, p;
ReadInt(out r, out s, out p);
var T = ReadString();
int ans = 0;
List<char> list = new List<char>();
for (int i = 0; i < T.Length; i++) {
char hand = Win(T[i]);
if (i - k >= 0 && list[i - k] == hand) {
list.Add('\0');
continue;
}
switch (hand) {
case 'r':
ans += r;
break;
case 's':
ans += s;
break;
case 'p':
ans += p;
break;
default:
break;
}
list.Add(hand);
}
Console.WriteLine(ans);
}
static char Win(char hand) {
switch (hand) {
case 'r':
return 'p';
case 's':
return 'r';
case 'p':
return 's';
default:
return '\0';
}
}
#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];
}
static string YesNo(bool condition) => condition ? "Yes" : "No";
static string YESNO(bool condition) => condition ? "YES" : "NO";
#endregion
}
}
|
[["-", 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, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 44]]
| 8
| 826
| 7
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ABC149E {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var M = NN;
var AList = NNList(N).OrderByRand().OrderBy(e => e).ToArray();
var tree = new LIB_RedBlackTree<long>();
foreach (var item in AList) {
tree.Add(item);
}
var left = 2L;
var right = 200001L;
while (right - left > 1) {
var mid = (right + left) / 2;
var cnt = 0L;
foreach (var item in AList) {
var tgt = mid - item;
var idx = tree.LowerBound(tgt);
cnt += N - idx;
}
if (cnt >= M)
left = mid;
else
right = mid;
}
var pivot = left;
var seg = new LIB_DualSegTree<long>(N, 0, (x, y) => x + y);
for (var i = 0; i < N; i++) {
var idx = tree.LowerBound(pivot - AList[i]);
seg.Update(idx, N, 1);
seg[i] += N - idx;
}
var ans = 0L;
var count = 0L;
for (var i = 0; i < N; i++) {
ans += seg[i] * AList[i];
count += seg[i];
}
if (count / 2 > M)
ans -= pivot * (count / 2 - M);
Console.WriteLine(ans);
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
}
}
namespace Library {
class LIB_RedBlackTree {
public struct SumEntity {
public long s;
public long c;
}
static public LIB_RedBlackTree<long, long, long> CreateRUQRmQ() =>
new LIB_RedBlackTree<long, long, long>(long.MaxValue, long.MaxValue,
Math.Min, (x, y) => y,
(x, y) => y);
static public LIB_RedBlackTree<long, long, long> CreateRAQRmQ() =>
new LIB_RedBlackTree<long, long, long>(long.MaxValue, 0, Math.Min,
(x, y) => x + y, (x, y) => x + y);
static public LIB_RedBlackTree<long, long, long> CreateRUQRMQ() =>
new LIB_RedBlackTree<long, long, long>(long.MinValue, long.MinValue,
Math.Max, (x, y) => y,
(x, y) => y);
static public LIB_RedBlackTree<long, long, long> CreateRAQRMQ() =>
new LIB_RedBlackTree<long, long, long>(long.MinValue, 0, Math.Max,
(x, y) => x + y, (x, y) => x + y);
static public LIB_RedBlackTree<long, SumEntity, long>
CreateRUQRSQ() => new LIB_RedBlackTree<long, SumEntity, long>(
new SumEntity { c = 0, s = 0 }, long.MaxValue,
(x, y) => new SumEntity { c = x.c + y.c, s = x.s + y.s },
(x, y) => new SumEntity { c = x.c, s = x.c * y }, (x, y) => y);
static public LIB_RedBlackTree<long, SumEntity, long>
CreateRAQRSQ() => new LIB_RedBlackTree<long, SumEntity, long>(
new SumEntity { c = 0, s = 0 }, 0,
(x, y) => new SumEntity { c = x.c + y.c, s = x.s + y.s },
(x, y) => new SumEntity { c = x.c, s = x.s + x.c * y }, (x, y) => x + y);
}
class LIB_RedBlackTree<Key, ValueT, ValueE> {
bool ope;
class Node {
public Node left;
public Node right;
public Key key;
public ValueT val;
public ValueT dat;
public ValueE lazy;
public bool isBlack;
public int cnt;
public bool needRecalc;
}
Func<ValueT, ValueT, ValueT> f;
Func<ValueT, ValueE, ValueT> g;
Func<ValueE, ValueE, ValueE> h;
ValueT ti;
ValueE ei;
Comparison<Key> c;
Node root;
bool isNeedFix;
Node lmax;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree(ValueT ti, ValueE ei, Func<ValueT, ValueT, ValueT> f,
Func<ValueT, ValueE, ValueT> g,
Func<ValueE, ValueE, ValueE> h, Comparison<Key> c,
bool ope = true) {
this.ti = ti;
this.ei = ei;
this.f = f;
this.g = g;
this.h = h;
this.c = c;
this.ope = ope;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree(ValueT ti, ValueE ei, Func<ValueT, ValueT, ValueT> f,
Func<ValueT, ValueE, ValueT> g,
Func<ValueE, ValueE, ValueE> h)
: this(ti, ei, f, g, h, Comparer<Key>.Default.Compare) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IsRed(Node n) => n != null && !n.isBlack;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IsBlack(Node n) => n != null && n.isBlack;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
int Cnt(Node n) => n?.cnt ?? 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Eval(Node n) {
if (n == null || ei.Equals(n.lazy))
return;
n.val = g(n.val, n.lazy);
if (!n.needRecalc)
n.dat = g(n.dat, n.lazy);
if (n.left != null)
n.left.lazy = h(n.left.lazy, n.lazy);
if (n.right != null)
n.right.lazy = h(n.right.lazy, n.lazy);
n.lazy = ei;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Recalc(Node n) {
if (n == null)
return;
Eval(n);
if (!n.needRecalc)
return;
n.needRecalc = false;
n.dat = n.val;
if (n.left != null) {
Recalc(n.left);
n.dat = f(n.left.dat, n.dat);
}
if (n.right != null) {
Recalc(n.right);
n.dat = f(n.dat, n.right.dat);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RotateL(Node n) {
if (ope) {
Eval(n);
Eval(n.right);
}
Node m = n.right, t = m.left;
m.left = n;
n.right = t;
n.cnt -= m.cnt - Cnt(t);
m.cnt += n.cnt - Cnt(t);
if (ope) {
n.needRecalc = true;
m.needRecalc = true;
}
return m;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RotateR(Node n) {
if (ope) {
Eval(n);
Eval(n.left);
}
Node m = n.left, t = m.right;
m.right = n;
n.left = t;
n.cnt -= m.cnt - Cnt(t);
m.cnt += n.cnt - Cnt(t);
if (ope) {
n.needRecalc = true;
m.needRecalc = true;
}
return m;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RotateLR(Node n) {
n.left = RotateL(n.left);
return RotateR(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RotateRL(Node n) {
n.right = RotateR(n.right);
return RotateL(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(Key key, ValueT val) {
root = Add(root, key, val);
root.isBlack = true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node Add(Node n, Key key, ValueT val) {
if (n == null) {
isNeedFix = true;
return new Node() { key = key, val = val, dat = val, lazy = ei, cnt = 1 };
}
if (ope)
Eval(n);
if (c(key, n.key) < 0)
n.left = Add(n.left, key, val);
else
n.right = Add(n.right, key, val);
if (ope)
n.needRecalc = true;
n.cnt++;
return Balance(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node Balance(Node n) {
if (!isNeedFix)
return n;
if (!IsBlack(n))
return n;
if (IsRed(n.left) && IsRed(n.left.left)) {
n = RotateR(n);
n.left.isBlack = true;
} else if (IsRed(n.left) && IsRed(n.left.right)) {
n = RotateLR(n);
n.left.isBlack = true;
} else if (IsRed(n.right) && IsRed(n.right.left)) {
n = RotateRL(n);
n.right.isBlack = true;
} else if (IsRed(n.right) && IsRed(n.right.right)) {
n = RotateL(n);
n.right.isBlack = true;
} else
isNeedFix = false;
return n;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Remove(Key key) {
root = Remove(root, key);
if (root != null)
root.isBlack = true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node Remove(Node n, Key key) {
if (n == null) {
isNeedFix = false;
return n;
}
if (ope)
Eval(n);
n.cnt--;
var r = c(key, n.key);
if (r < 0) {
n.left = Remove(n.left, key);
if (ope)
n.needRecalc = true;
return BalanceL(n);
}
if (r > 0) {
n.right = Remove(n.right, key);
if (ope)
n.needRecalc = true;
return BalanceR(n);
}
if (n.left == null) {
isNeedFix = n.isBlack;
return n.right;
}
n.left = RemoveMax(n.left);
n.key = lmax.key;
n.val = lmax.val;
if (ope)
n.needRecalc = true;
return BalanceL(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RemoveMax(Node n) {
if (ope)
Eval(n);
n.cnt--;
if (n.right != null) {
n.right = RemoveMax(n.right);
if (ope)
n.needRecalc = true;
return BalanceR(n);
}
lmax = n;
isNeedFix = n.isBlack;
return n.left;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node BalanceL(Node n) {
if (!isNeedFix)
return n;
if (IsBlack(n.right) && IsRed(n.right.left)) {
var b = n.isBlack;
n = RotateRL(n);
n.isBlack = b;
n.left.isBlack = true;
isNeedFix = false;
} else if (IsBlack(n.right) && IsRed(n.right.right)) {
var b = n.isBlack;
n = RotateL(n);
n.isBlack = b;
n.right.isBlack = true;
n.left.isBlack = true;
isNeedFix = false;
} else if (IsBlack(n.right)) {
isNeedFix = n.isBlack;
n.isBlack = true;
n.right.isBlack = false;
} else {
n = RotateL(n);
n.isBlack = true;
n.left.isBlack = false;
n.left = BalanceL(n.left);
isNeedFix = false;
}
return n;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node BalanceR(Node n) {
if (!isNeedFix)
return n;
if (IsBlack(n.left) && IsRed(n.left.right)) {
var b = n.isBlack;
n = RotateLR(n);
n.isBlack = b;
n.right.isBlack = true;
isNeedFix = false;
} else if (IsBlack(n.left) && IsRed(n.left.left)) {
var b = n.isBlack;
n = RotateR(n);
n.isBlack = b;
n.left.isBlack = true;
n.right.isBlack = true;
isNeedFix = false;
} else if (IsBlack(n.left)) {
isNeedFix = n.isBlack;
n.isBlack = true;
n.left.isBlack = false;
} else {
n = RotateR(n);
n.isBlack = true;
n.right.isBlack = false;
n.right = BalanceR(n.right);
isNeedFix = false;
}
return n;
}
public KeyValuePair<Key, ValueT> this[long i] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return At(root, i); }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
KeyValuePair<Key, ValueT> At(Node n, long i) {
if (ope)
Eval(n);
if (n.left == null) {
if (i == 0)
return new KeyValuePair<Key, ValueT>(n.key, n.val);
else
return At(n.right, i - 1);
}
if (n.left.cnt == i)
return new KeyValuePair<Key, ValueT>(n.key, n.val);
if (n.left.cnt > i)
return At(n.left, i);
return At(n.right, i - n.left.cnt - 1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Have(Key key) {
var t = LowerBound(key);
return t < Cnt(root) && c(At(root, t).Key, key) == 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long UpperBound(Key key) => UpperBound(root, key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
long UpperBound(Node n, Key key) {
if (n == null)
return 0;
var r = c(key, n.key);
if (r < 0)
return UpperBound(n.left, key);
return Cnt(n.left) + 1 + UpperBound(n.right, key);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long LowerBound(Key key) => LowerBound(root, key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
long LowerBound(Node n, Key key) {
if (n == null)
return 0;
var r = c(key, n.key);
if (r <= 0)
return LowerBound(n.left, key);
return Cnt(n.left) + 1 + LowerBound(n.right, key);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public KeyValuePair<Key, ValueT> Min() {
Node n = root, p = null;
while (n != null) {
Eval(p = n);
n = n.left;
}
return new KeyValuePair<Key, ValueT>(n.key, n.val);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public KeyValuePair<Key, ValueT> Max() {
Node n = root, p = null;
while (n != null) {
Eval(p = n);
n = n.right;
}
return new KeyValuePair<Key, ValueT>(n.key, n.val);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Update(long l, long r, ValueE val) => Update(root, l, r, val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Update(Node n, long l, long r, ValueE val) {
if (n == null)
return;
Eval(n);
n.needRecalc = true;
var lc = Cnt(n.left);
if (lc < l)
Update(n.right, l - lc - 1, r - lc - 1, val);
else if (r <= lc)
Update(n.left, l, r, val);
else if (l <= 0 && Cnt(n) <= r)
n.lazy = val;
else {
n.val = g(n.val, val);
if (l < lc)
Update(n.left, l, lc, val);
if (lc + 1 < r)
Update(n.right, 0, r - lc - 1, val);
}
return;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ValueT Query(long l, long r) => Query(root, l, r);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
ValueT Query(Node n, long l, long r) {
var v1 = ti;
var v2 = ti;
var v3 = ti;
if (n == null)
return ti;
Eval(n);
var lc = Cnt(n.left);
if (lc < l)
v3 = Query(n.right, l - lc - 1, r - lc - 1);
else if (r <= lc)
v1 = Query(n.left, l, r);
else if (l <= 0 && Cnt(n) <= r) {
Recalc(n);
v2 = n.dat;
} else {
if (l < lc)
v1 = Query(n.left, l, lc);
if (lc + 1 < r)
v3 = Query(n.right, 0, r - lc - 1);
v2 = n.val;
}
return f(f(v1, v2), v3);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Any() => root != null;
public long Count => Cnt(root);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<KeyValuePair<Key, ValueT>> List() => L(root);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
IEnumerable<KeyValuePair<Key, ValueT>> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.left))
yield return i;
yield return new KeyValuePair<Key, ValueT>(n.key, n.val);
foreach (var i in L(n.right))
yield return i;
}
}
class LIB_RedBlackTree<Key, Value> {
LIB_RedBlackTree<Key, Value, Value> tree;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree(Comparison<Key> c) {
tree = new LIB_RedBlackTree<Key, Value, Value>(
default(Value), default(Value), (x, y) => x, (x, y) => x, (x, y) => x,
c, false);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree() : this(Comparer<Key>.Default.Compare) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(Key key, Value val) => tree.Add(key, val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Remove(Key key) => tree.Remove(key);
public KeyValuePair<Key, Value> this[long i] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return tree[i]; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Have(Key key) => tree.Have(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long UpperBound(Key key) => tree.UpperBound(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long LowerBound(Key key) => tree.LowerBound(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public KeyValuePair<Key, Value> Min() => tree.Min();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public KeyValuePair<Key, Value> Max() => tree.Max();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Any() => tree.Any();
public long Count => tree.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<KeyValuePair<Key, Value>> List() => tree.List();
}
class LIB_RedBlackTree<T> {
LIB_RedBlackTree<T, T, T> tree;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree(Comparison<T> c) {
tree = new LIB_RedBlackTree<T, T, T>(default(T), default(T), (x, y) => x,
(x, y) => x, (x, y) => x, c, false);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree() : this(Comparer<T>.Default.Compare) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(T val) => tree.Add(val, val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Remove(T val) => tree.Remove(val);
public T this[long i] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return tree[i].Key; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Have(T val) => tree.Have(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long UpperBound(T val) => tree.UpperBound(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long LowerBound(T val) => tree.LowerBound(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Min() => tree.Min().Key;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Max() => tree.Max().Key;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Any() => tree.Any();
public long Count => tree.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<T> List() => tree.List().Select(e => e.Key);
}
class LIB_DualSegTree<T> {
int n, height;
T ti;
Func<T, T, T> f;
T[] dat;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_DualSegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
f = _f;
dat = Enumerable.Repeat(ti, n << 1).ToArray();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_DualSegTree(IEnumerable<T> l, T _ti, Func<T, T, T> _f)
: this(l.Count(), _ti, _f) {
var idx = 0;
foreach (var item in l)
dat[n + idx++] = item;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Eval(long i) {
if (dat[i].Equals(ti))
return;
dat[(i << 1) | 0] = f(dat[(i << 1) | 0], dat[i]);
dat[(i << 1) | 1] = f(dat[(i << 1) | 1], dat[i]);
dat[i] = ti;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Thrust(long l, long r) {
if (l == r) {
Thrust(l);
return;
}
var xor = l ^ r;
var i = height;
for (; (xor >> i) != 0; --i)
Eval(l >> i);
for (; i != 0; --i) {
Eval(l >> i);
Eval(r >> i);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Update(long l, long r, T v) {
if (r < l)
throw new Exception();
Thrust(l += n, r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
dat[li] = f(dat[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
dat[ri] = f(dat[ri], v);
}
}
}
public T this[long idx] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
Thrust(idx += n);
return dat[idx];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set {
Thrust(idx += n);
dat[idx] = value;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ABC149E {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var M = NN;
var AList = NNList(N).OrderByRand().OrderBy(e => e).ToArray();
var tree = new LIB_RedBlackTree<long>();
foreach (var item in AList) {
tree.Add(item);
}
var left = 2L;
var right = 200001L;
while (right - left > 1) {
var mid = (right + left) / 2;
var cnt = 0L;
foreach (var item in AList) {
var tgt = mid - item;
var idx = tree.LowerBound(tgt);
cnt += N - idx;
}
if (cnt >= M)
left = mid;
else
right = mid;
}
var pivot = left;
var seg = new LIB_DualSegTree<long>(N, 0, (x, y) => x + y);
for (var i = 0; i < N; i++) {
var idx = tree.LowerBound(pivot - AList[i]);
if (idx != N)
seg.Update(idx, N, 1);
seg[i] += N - idx;
}
var ans = 0L;
var count = 0L;
for (var i = 0; i < N; i++) {
ans += seg[i] * AList[i];
count += seg[i];
}
if (count / 2 > M)
ans -= pivot * (count / 2 - M);
Console.WriteLine(ans);
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
}
}
namespace Library {
class LIB_RedBlackTree {
public struct SumEntity {
public long s;
public long c;
}
static public LIB_RedBlackTree<long, long, long> CreateRUQRmQ() =>
new LIB_RedBlackTree<long, long, long>(long.MaxValue, long.MaxValue,
Math.Min, (x, y) => y,
(x, y) => y);
static public LIB_RedBlackTree<long, long, long> CreateRAQRmQ() =>
new LIB_RedBlackTree<long, long, long>(long.MaxValue, 0, Math.Min,
(x, y) => x + y, (x, y) => x + y);
static public LIB_RedBlackTree<long, long, long> CreateRUQRMQ() =>
new LIB_RedBlackTree<long, long, long>(long.MinValue, long.MinValue,
Math.Max, (x, y) => y,
(x, y) => y);
static public LIB_RedBlackTree<long, long, long> CreateRAQRMQ() =>
new LIB_RedBlackTree<long, long, long>(long.MinValue, 0, Math.Max,
(x, y) => x + y, (x, y) => x + y);
static public LIB_RedBlackTree<long, SumEntity, long>
CreateRUQRSQ() => new LIB_RedBlackTree<long, SumEntity, long>(
new SumEntity { c = 0, s = 0 }, long.MaxValue,
(x, y) => new SumEntity { c = x.c + y.c, s = x.s + y.s },
(x, y) => new SumEntity { c = x.c, s = x.c * y }, (x, y) => y);
static public LIB_RedBlackTree<long, SumEntity, long>
CreateRAQRSQ() => new LIB_RedBlackTree<long, SumEntity, long>(
new SumEntity { c = 0, s = 0 }, 0,
(x, y) => new SumEntity { c = x.c + y.c, s = x.s + y.s },
(x, y) => new SumEntity { c = x.c, s = x.s + x.c * y }, (x, y) => x + y);
}
class LIB_RedBlackTree<Key, ValueT, ValueE> {
bool ope;
class Node {
public Node left;
public Node right;
public Key key;
public ValueT val;
public ValueT dat;
public ValueE lazy;
public bool isBlack;
public int cnt;
public bool needRecalc;
}
Func<ValueT, ValueT, ValueT> f;
Func<ValueT, ValueE, ValueT> g;
Func<ValueE, ValueE, ValueE> h;
ValueT ti;
ValueE ei;
Comparison<Key> c;
Node root;
bool isNeedFix;
Node lmax;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree(ValueT ti, ValueE ei, Func<ValueT, ValueT, ValueT> f,
Func<ValueT, ValueE, ValueT> g,
Func<ValueE, ValueE, ValueE> h, Comparison<Key> c,
bool ope = true) {
this.ti = ti;
this.ei = ei;
this.f = f;
this.g = g;
this.h = h;
this.c = c;
this.ope = ope;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree(ValueT ti, ValueE ei, Func<ValueT, ValueT, ValueT> f,
Func<ValueT, ValueE, ValueT> g,
Func<ValueE, ValueE, ValueE> h)
: this(ti, ei, f, g, h, Comparer<Key>.Default.Compare) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IsRed(Node n) => n != null && !n.isBlack;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IsBlack(Node n) => n != null && n.isBlack;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
int Cnt(Node n) => n?.cnt ?? 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Eval(Node n) {
if (n == null || ei.Equals(n.lazy))
return;
n.val = g(n.val, n.lazy);
if (!n.needRecalc)
n.dat = g(n.dat, n.lazy);
if (n.left != null)
n.left.lazy = h(n.left.lazy, n.lazy);
if (n.right != null)
n.right.lazy = h(n.right.lazy, n.lazy);
n.lazy = ei;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Recalc(Node n) {
if (n == null)
return;
Eval(n);
if (!n.needRecalc)
return;
n.needRecalc = false;
n.dat = n.val;
if (n.left != null) {
Recalc(n.left);
n.dat = f(n.left.dat, n.dat);
}
if (n.right != null) {
Recalc(n.right);
n.dat = f(n.dat, n.right.dat);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RotateL(Node n) {
if (ope) {
Eval(n);
Eval(n.right);
}
Node m = n.right, t = m.left;
m.left = n;
n.right = t;
n.cnt -= m.cnt - Cnt(t);
m.cnt += n.cnt - Cnt(t);
if (ope) {
n.needRecalc = true;
m.needRecalc = true;
}
return m;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RotateR(Node n) {
if (ope) {
Eval(n);
Eval(n.left);
}
Node m = n.left, t = m.right;
m.right = n;
n.left = t;
n.cnt -= m.cnt - Cnt(t);
m.cnt += n.cnt - Cnt(t);
if (ope) {
n.needRecalc = true;
m.needRecalc = true;
}
return m;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RotateLR(Node n) {
n.left = RotateL(n.left);
return RotateR(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RotateRL(Node n) {
n.right = RotateR(n.right);
return RotateL(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(Key key, ValueT val) {
root = Add(root, key, val);
root.isBlack = true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node Add(Node n, Key key, ValueT val) {
if (n == null) {
isNeedFix = true;
return new Node() { key = key, val = val, dat = val, lazy = ei, cnt = 1 };
}
if (ope)
Eval(n);
if (c(key, n.key) < 0)
n.left = Add(n.left, key, val);
else
n.right = Add(n.right, key, val);
if (ope)
n.needRecalc = true;
n.cnt++;
return Balance(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node Balance(Node n) {
if (!isNeedFix)
return n;
if (!IsBlack(n))
return n;
if (IsRed(n.left) && IsRed(n.left.left)) {
n = RotateR(n);
n.left.isBlack = true;
} else if (IsRed(n.left) && IsRed(n.left.right)) {
n = RotateLR(n);
n.left.isBlack = true;
} else if (IsRed(n.right) && IsRed(n.right.left)) {
n = RotateRL(n);
n.right.isBlack = true;
} else if (IsRed(n.right) && IsRed(n.right.right)) {
n = RotateL(n);
n.right.isBlack = true;
} else
isNeedFix = false;
return n;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Remove(Key key) {
root = Remove(root, key);
if (root != null)
root.isBlack = true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node Remove(Node n, Key key) {
if (n == null) {
isNeedFix = false;
return n;
}
if (ope)
Eval(n);
n.cnt--;
var r = c(key, n.key);
if (r < 0) {
n.left = Remove(n.left, key);
if (ope)
n.needRecalc = true;
return BalanceL(n);
}
if (r > 0) {
n.right = Remove(n.right, key);
if (ope)
n.needRecalc = true;
return BalanceR(n);
}
if (n.left == null) {
isNeedFix = n.isBlack;
return n.right;
}
n.left = RemoveMax(n.left);
n.key = lmax.key;
n.val = lmax.val;
if (ope)
n.needRecalc = true;
return BalanceL(n);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node RemoveMax(Node n) {
if (ope)
Eval(n);
n.cnt--;
if (n.right != null) {
n.right = RemoveMax(n.right);
if (ope)
n.needRecalc = true;
return BalanceR(n);
}
lmax = n;
isNeedFix = n.isBlack;
return n.left;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node BalanceL(Node n) {
if (!isNeedFix)
return n;
if (IsBlack(n.right) && IsRed(n.right.left)) {
var b = n.isBlack;
n = RotateRL(n);
n.isBlack = b;
n.left.isBlack = true;
isNeedFix = false;
} else if (IsBlack(n.right) && IsRed(n.right.right)) {
var b = n.isBlack;
n = RotateL(n);
n.isBlack = b;
n.right.isBlack = true;
n.left.isBlack = true;
isNeedFix = false;
} else if (IsBlack(n.right)) {
isNeedFix = n.isBlack;
n.isBlack = true;
n.right.isBlack = false;
} else {
n = RotateL(n);
n.isBlack = true;
n.left.isBlack = false;
n.left = BalanceL(n.left);
isNeedFix = false;
}
return n;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Node BalanceR(Node n) {
if (!isNeedFix)
return n;
if (IsBlack(n.left) && IsRed(n.left.right)) {
var b = n.isBlack;
n = RotateLR(n);
n.isBlack = b;
n.right.isBlack = true;
isNeedFix = false;
} else if (IsBlack(n.left) && IsRed(n.left.left)) {
var b = n.isBlack;
n = RotateR(n);
n.isBlack = b;
n.left.isBlack = true;
n.right.isBlack = true;
isNeedFix = false;
} else if (IsBlack(n.left)) {
isNeedFix = n.isBlack;
n.isBlack = true;
n.left.isBlack = false;
} else {
n = RotateR(n);
n.isBlack = true;
n.right.isBlack = false;
n.right = BalanceR(n.right);
isNeedFix = false;
}
return n;
}
public KeyValuePair<Key, ValueT> this[long i] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return At(root, i); }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
KeyValuePair<Key, ValueT> At(Node n, long i) {
if (ope)
Eval(n);
if (n.left == null) {
if (i == 0)
return new KeyValuePair<Key, ValueT>(n.key, n.val);
else
return At(n.right, i - 1);
}
if (n.left.cnt == i)
return new KeyValuePair<Key, ValueT>(n.key, n.val);
if (n.left.cnt > i)
return At(n.left, i);
return At(n.right, i - n.left.cnt - 1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Have(Key key) {
var t = LowerBound(key);
return t < Cnt(root) && c(At(root, t).Key, key) == 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long UpperBound(Key key) => UpperBound(root, key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
long UpperBound(Node n, Key key) {
if (n == null)
return 0;
var r = c(key, n.key);
if (r < 0)
return UpperBound(n.left, key);
return Cnt(n.left) + 1 + UpperBound(n.right, key);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long LowerBound(Key key) => LowerBound(root, key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
long LowerBound(Node n, Key key) {
if (n == null)
return 0;
var r = c(key, n.key);
if (r <= 0)
return LowerBound(n.left, key);
return Cnt(n.left) + 1 + LowerBound(n.right, key);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public KeyValuePair<Key, ValueT> Min() {
Node n = root, p = null;
while (n != null) {
Eval(p = n);
n = n.left;
}
return new KeyValuePair<Key, ValueT>(n.key, n.val);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public KeyValuePair<Key, ValueT> Max() {
Node n = root, p = null;
while (n != null) {
Eval(p = n);
n = n.right;
}
return new KeyValuePair<Key, ValueT>(n.key, n.val);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Update(long l, long r, ValueE val) => Update(root, l, r, val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Update(Node n, long l, long r, ValueE val) {
if (n == null)
return;
Eval(n);
n.needRecalc = true;
var lc = Cnt(n.left);
if (lc < l)
Update(n.right, l - lc - 1, r - lc - 1, val);
else if (r <= lc)
Update(n.left, l, r, val);
else if (l <= 0 && Cnt(n) <= r)
n.lazy = val;
else {
n.val = g(n.val, val);
if (l < lc)
Update(n.left, l, lc, val);
if (lc + 1 < r)
Update(n.right, 0, r - lc - 1, val);
}
return;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ValueT Query(long l, long r) => Query(root, l, r);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
ValueT Query(Node n, long l, long r) {
var v1 = ti;
var v2 = ti;
var v3 = ti;
if (n == null)
return ti;
Eval(n);
var lc = Cnt(n.left);
if (lc < l)
v3 = Query(n.right, l - lc - 1, r - lc - 1);
else if (r <= lc)
v1 = Query(n.left, l, r);
else if (l <= 0 && Cnt(n) <= r) {
Recalc(n);
v2 = n.dat;
} else {
if (l < lc)
v1 = Query(n.left, l, lc);
if (lc + 1 < r)
v3 = Query(n.right, 0, r - lc - 1);
v2 = n.val;
}
return f(f(v1, v2), v3);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Any() => root != null;
public long Count => Cnt(root);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<KeyValuePair<Key, ValueT>> List() => L(root);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
IEnumerable<KeyValuePair<Key, ValueT>> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.left))
yield return i;
yield return new KeyValuePair<Key, ValueT>(n.key, n.val);
foreach (var i in L(n.right))
yield return i;
}
}
class LIB_RedBlackTree<Key, Value> {
LIB_RedBlackTree<Key, Value, Value> tree;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree(Comparison<Key> c) {
tree = new LIB_RedBlackTree<Key, Value, Value>(
default(Value), default(Value), (x, y) => x, (x, y) => x, (x, y) => x,
c, false);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree() : this(Comparer<Key>.Default.Compare) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(Key key, Value val) => tree.Add(key, val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Remove(Key key) => tree.Remove(key);
public KeyValuePair<Key, Value> this[long i] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return tree[i]; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Have(Key key) => tree.Have(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long UpperBound(Key key) => tree.UpperBound(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long LowerBound(Key key) => tree.LowerBound(key);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public KeyValuePair<Key, Value> Min() => tree.Min();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public KeyValuePair<Key, Value> Max() => tree.Max();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Any() => tree.Any();
public long Count => tree.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<KeyValuePair<Key, Value>> List() => tree.List();
}
class LIB_RedBlackTree<T> {
LIB_RedBlackTree<T, T, T> tree;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree(Comparison<T> c) {
tree = new LIB_RedBlackTree<T, T, T>(default(T), default(T), (x, y) => x,
(x, y) => x, (x, y) => x, c, false);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_RedBlackTree() : this(Comparer<T>.Default.Compare) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(T val) => tree.Add(val, val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Remove(T val) => tree.Remove(val);
public T this[long i] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return tree[i].Key; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Have(T val) => tree.Have(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long UpperBound(T val) => tree.UpperBound(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long LowerBound(T val) => tree.LowerBound(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Min() => tree.Min().Key;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Max() => tree.Max().Key;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Any() => tree.Any();
public long Count => tree.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<T> List() => tree.List().Select(e => e.Key);
}
class LIB_DualSegTree<T> {
int n, height;
T ti;
Func<T, T, T> f;
T[] dat;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_DualSegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
f = _f;
dat = Enumerable.Repeat(ti, n << 1).ToArray();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_DualSegTree(IEnumerable<T> l, T _ti, Func<T, T, T> _f)
: this(l.Count(), _ti, _f) {
var idx = 0;
foreach (var item in l)
dat[n + idx++] = item;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Eval(long i) {
if (dat[i].Equals(ti))
return;
dat[(i << 1) | 0] = f(dat[(i << 1) | 0], dat[i]);
dat[(i << 1) | 1] = f(dat[(i << 1) | 1], dat[i]);
dat[i] = ti;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void Thrust(long l, long r) {
if (l == r) {
Thrust(l);
return;
}
var xor = l ^ r;
var i = height;
for (; (xor >> i) != 0; --i)
Eval(l >> i);
for (; i != 0; --i) {
Eval(l >> i);
Eval(r >> i);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Update(long l, long r, T v) {
if (r < l)
throw new Exception();
Thrust(l += n, r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
dat[li] = f(dat[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
dat[ri] = f(dat[ri], v);
}
}
}
public T this[long idx] {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
Thrust(idx += n);
return dat[idx];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set {
Thrust(idx += n);
dat[idx] = value;
}
}
}
}
|
[["+", 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, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
| 8
| 5,866
| 6
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
namespace V {
partial class Solver {
public void Solve() {
// var n = Read;
Write(SolveLong());
// YesNo(SolveBool());
}
public long SolveLong() {
var n = Read;
var m = Read;
var a = Arr(n).OrderBy(x => x).ToArray();
var l = a[0] + a[0];
var r = a[n - 1] + a[n - 1];
while (l + 1 < r) {
var mid = (l + r) / 2;
var count = 0L;
foreach (var i in C.Loop(n)) {
var idx = C.BinarySearch.GetLastIndexLess(mid - a[i], a);
var c = (n - idx) - 1;
count += c;
}
if (count >= m)
l = mid;
else
r = mid - 1;
}
var s = new List<long>() { 0L };
var current = 0L;
foreach (var i in C.Loop(n)) {
current += a[i];
s.Add(current);
}
var res = 0L;
var cnt = 0L;
foreach (var i in C.Loop(n)) {
var idx = C.BinarySearch.GetLastIndexLess(l - a[i], a);
var c = (n - idx) - 1;
cnt += c;
res += c * a[i];
res += s[(int)n] - s[(int)idx + 1];
}
res -= (cnt - m) * l;
return res;
}
public bool SolveBool() {
var n = Read;
return false;
}
}
}
namespace V {
class StartingPoint {
static void Main(string[] args) {
try {
var streamReader = args.Any()
? new StreamReader(args[0])
: new StreamReader(Console.OpenStandardInput());
var streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var scanner = new Scanner(streamReader);
var printer = new Printer(streamWriter);
var solver = new Solver(scanner, printer);
solver.Solve();
streamWriter.Flush();
} catch (Exception e) {
Console.WriteLine(e);
if (args.Any() == false)
throw e;
}
if (args.Any())
Console.ReadKey();
}
}
partial class Solver {
public Solver(Scanner sc, Printer pr) {
this.sc = sc;
this.pr = pr;
}
private readonly Scanner sc;
private readonly Printer pr;
private IEnumerable<int> Loop(int n) => C.Loop(n);
private IEnumerable<long> Loop(long n) => C.Loop(n);
private int RdInt => sc.Int;
private int ReadInt => sc.Int;
private long Rd => sc.Long;
private long Read => sc.Long;
private long ReadLong => sc.Long;
private double RdDouble => sc.Double;
private double ReadDouble => sc.Double;
private string Str => sc.Str;
private string RdStr => sc.Str;
private string ReadStr => sc.Str;
private int[] ArrInt(int n) => sc.Ints(n);
private int[] ArrInt(long n) => sc.Ints(n);
private long[] Arr(int n) => sc.Longs(n);
private long[] Arr(long n) => sc.Longs(n);
private long[] ArrLong(int n) => sc.Longs(n);
private long[] ArrLong(long n) => sc.Longs(n);
private double[] ArrDouble(int n) => sc.Doubles(n);
private double[] ArrDouble(long n) => sc.Doubles(n);
private string[] ArrStr(int n) => sc.Strs(n);
private string[] ArrStr(long n) => sc.Strs(n);
private void Wr(string s) => pr.Write(s);
private void Wr(object obj) => pr.Write(obj);
private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts);
private void Wr(params object[] objs) => pr.Write(objs);
private void Write(string s) => pr.Write(s);
private void Write(object obj) => pr.Write(obj);
private void Write<T>(IEnumerable<T> ts) => pr.Write(ts);
private void Write(params object[] objs) => pr.Write(objs);
private void YesNo(bool b) => Write(b ? "Yes" : "No");
private void YESNO(bool b) => Write(b ? "YES" : "NO");
}
class Scanner {
private readonly TextReader reader;
public Scanner(TextReader reader) { this.reader = reader; }
private Queue<string> strQueue = new Queue<string>();
public string Str {
get {
if (strQueue.Count > 0)
return strQueue.Dequeue();
string[] strs = null;
do {
strs = reader.ReadLine().Split(new[] { ' ' },
StringSplitOptions.RemoveEmptyEntries);
} while (strs.Any() == false);
foreach (var s in strs.Skip(1))
strQueue.Enqueue(s);
return strs[0];
}
}
public int Int => int.Parse(this.Str);
public long Long => long.Parse(this.Str);
public double Double => double.Parse(this.Str);
public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2));
public static T1
ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1));
public static T1 Convert<T1>(string s) =>
TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s))
: TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s))
: TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s))
: TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0])
: ChangeTypes<T1, string>(s);
public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str),
Convert<TY>(this.Str));
public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>(
Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str));
public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() =>
new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str),
Convert<TZ>(this.Str), Convert<TW>(this.Str));
}
static class ScannerExtension {
public static int[] Ints(this Scanner scanner,
int n) => scanner.Ints((long)n);
public static int[] Ints(this Scanner scanner,
long n) => scanner.ScanStrs<int>(n).ToArray();
public static long[] Longs(this Scanner scanner,
int n) => scanner.Longs((long)n);
public static long[] Longs(this Scanner scanner,
long n) => scanner.ScanStrs<long>(n).ToArray();
public static double[] Doubles(this Scanner scanner,
int n) => scanner.Doubles((long)n);
public static double[] Doubles(this Scanner scanner, long n) =>
scanner.ScanStrs<double>(n).ToArray();
public static string[] Strs(this Scanner scanner,
int n) => scanner.Strs((long)n);
public static string[] Strs(this Scanner scanner,
long n) => scanner.ScanStrs<string>(n).ToArray();
private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return Scanner.Convert<T>(scanner.Str);
}
public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) =>
scanner.Pairs<TX, TY>((long)n);
public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) =>
scanner.ScanPairs<TX, TY>(n).ToArray();
public static Pair<long, long>[] Pairs(this Scanner scanner,
int n) => scanner.Pairs((long)n);
public static Pair<long, long>[] Pairs(this Scanner scanner, long n) =>
scanner.ScanPairs<long, long>(n).ToArray();
public static Pair<int, int>[] PairsInt(this Scanner scanner,
int n) => scanner.PairsInt((long)n);
public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) =>
scanner.ScanPairs<int, int>(n).ToArray();
private static IEnumerable<Pair<TX, TY>>
ScanPairs<TX, TY>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P2<TX, TY>();
}
public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(
this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n);
public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner,
long n) =>
scanner.ScanPairs3<TX, TY, TZ>(n).ToArray();
public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) =>
scanner.Pairs3((long)n);
public static Pair3<long, long, long>[] Pairs3(this Scanner scanner,
long n) =>
scanner.ScanPairs3<long, long, long>(n).ToArray();
public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) =>
scanner.Pairs3Int((long)n);
public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner,
long n) =>
scanner.ScanPairs3<int, int, int>(n).ToArray();
private static IEnumerable<Pair3<TX, TY, TZ>>
ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P3<TX, TY, TZ>();
}
public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>(
this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n);
public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>(
this Scanner scanner,
long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray();
public static Pair4<long, long, long, long>[] Pairs4(
this Scanner scanner, int n) => scanner.Pairs4((long)n);
public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner,
long n) =>
scanner.ScanPairs4<long, long, long, long>(n).ToArray();
public static Pair4<int, int, int, int>[] Pairs4Int(
this Scanner scanner, int n) => scanner.Pairs4Int((long)n);
public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner,
long n) =>
scanner.ScanPairs4<int, int, int, int>(n).ToArray();
private static IEnumerable<Pair4<TX, TY, TZ, TW>>
ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P4<TX, TY, TZ, TW>();
}
}
class Pair<TX, TY> {
public TX X { get; }
public TY Y { get; }
public Pair(TX x, TY y) {
this.X = x;
this.Y = y;
}
}
class Pair : Pair<long, long> {
public Pair(long x, long y) : base(x, y) {}
}
class PairInt : Pair<int, int> {
public PairInt(int x, int y) : base(x, y) {}
}
class Pair3<TX, TY, TZ> {
public TX X { get; }
public TY Y { get; }
public TZ Z { get; }
public Pair3(TX x, TY y, TZ z) {
this.X = x;
this.Y = y;
this.Z = z;
}
}
class Pair3 : Pair3<long, long, long> {
public Pair3(long x, long y, long z) : base(x, y, z) {}
}
class Pair3Int : Pair3<int, int, int> {
public Pair3Int(int x, int y, int z) : base(x, y, z) {}
}
class Pair4<TX, TY, TZ, TW> {
public TX X { get; }
public TY Y { get; }
public TZ Z { get; }
public TW W { get; }
public Pair4(TX x, TY y, TZ z, TW w) {
this.X = x;
this.Y = y;
this.Z = z;
this.W = w;
}
}
class Pair4 : Pair4<long, long, long, long> {
public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {}
}
class Pair4Int : Pair4<int, int, int, int> {
public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {}
}
class Printer {
private readonly TextWriter writer;
public Printer(TextWriter writer) { this.writer = writer; }
public void Write(string obj) { writer.WriteLine(obj); }
public void Write(object obj) { writer.WriteLine(obj); }
public void Write<T>(IEnumerable<T> ts) {
writer.WriteLine(string.Join(" ", ts));
}
public void Write(params object[] objs) {
writer.WriteLine(string.Join(" ", objs));
}
}
static class Extension {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool SafeAdd<T>(this HashSet<T> ts, T t) {
if (ts.Contains(t)) {
return false;
} else {
ts.Add(t);
return false;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool SafeRemove<T>(this HashSet<T> ts, T t) {
if (ts.Contains(t)) {
ts.Remove(t);
return true;
} else {
return false;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] = value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafePlus<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] += value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] -= value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] *= value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] /= value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToDigit(this char c) => (long)(c - '0');
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToSmallAbcIndex(this char c) => (long)(c - 'a');
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToLargeAbcIndex(this char c) => (long)(c - 'A');
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string
ToStr(this IEnumerable<char> cs) => new string(cs.ToArray());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToLong(this IEnumerable<char> s) {
var basis = 1L;
var res = 0L;
foreach (var c in s) {
var d = c.ToSmallAbcIndex() + 1;
res += d * basis;
basis *= 27;
}
return res;
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static bool TryMin<T>(this ref T current, T newer) where T : struct,
// IComparable<T>
//{
// if (current.CompareTo(newer) <= 0)
// return false;
// current = newer;
// return true;
//}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static bool TryMax<T>(this ref T current, T newer) where T : struct,
// IComparable<T>
//{
// if (current.CompareTo(newer) >= 0)
// return false;
// current = newer;
// return true;
//}
}
class C {
public class SegmentTree<T> {
private readonly int valueCount;
private readonly int baseCount;
private readonly int baseIndex;
private readonly T[] nodes;
private readonly Func<T, T, T> func;
private readonly T defaultValue;
public SegmentTree(IReadOnlyList<T> ts, Func<T, T, T> func,
T filling = default(T)) {
this.func = func;
this.defaultValue = filling;
valueCount = ts.Count;
baseCount = 1;
while (valueCount > baseCount)
baseCount <<= 1;
nodes = new T[baseCount * 2 - 1];
baseIndex = baseCount - 1;
for (int i = 0; i < ts.Count; i++)
nodes[baseIndex + i] = ts[i];
for (int i = ts.Count; i < baseCount; i++)
nodes[baseIndex + i] = filling;
for (int i = baseIndex - 1; i >= 0; i--)
nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Update(int index, T t) {
var i = baseIndex + index;
nodes[i] = t;
while (i > 0) {
i -= 1;
i /= 2;
nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Query(int leftIndex, int rightNextIndex) {
T left = defaultValue;
T right = defaultValue;
int l = leftIndex + baseCount - 1;
int r = rightNextIndex + baseCount - 1;
for (; l < r; l >>= 1, r >>= 1) {
if ((l & 1) == 0) {
left = func.Invoke(left, nodes[l]);
}
if ((r & 1) == 0) {
r--;
right = func.Invoke(right, nodes[r]);
}
}
return func.Invoke(left, right);
}
}
public class SegmentTree {
public static SegmentTree<int> Sum(IReadOnlyList<int> values) =>
new SegmentTree<int>(values, (x, y) => x + y);
public static SegmentTree<long> Sum(IReadOnlyList<long> values) =>
new SegmentTree<long>(values, (x, y) => x + y);
public static SegmentTree<double> Sum(IReadOnlyList<double> values) =>
new SegmentTree<double>(values, (x, y) => x + y);
public static SegmentTree<int> Mult(IReadOnlyList<int> values) =>
new SegmentTree<int>(values, (x, y) => x * y, 1);
public static SegmentTree<long> Mult(IReadOnlyList<long> values) =>
new SegmentTree<long>(values, (x, y) => x * y, 1);
public static SegmentTree<double> Mult(IReadOnlyList<double> values) =>
new SegmentTree<double>(values, (x, y) => x * y, 1);
public static SegmentTree<int> Min(IReadOnlyList<int> values) =>
new SegmentTree<int>(values, Math.Min, int.MaxValue);
public static SegmentTree<long> Min(IReadOnlyList<long> values) =>
new SegmentTree<long>(values, Math.Min, long.MaxValue);
public static SegmentTree<double> Min(IReadOnlyList<double> values) =>
new SegmentTree<double>(values, Math.Min, double.MaxValue);
public static SegmentTree<int> Max(IReadOnlyList<int> values) =>
new SegmentTree<int>(values, Math.Max, int.MinValue);
public static SegmentTree<long> Max(IReadOnlyList<long> values) =>
new SegmentTree<long>(values, Math.Max, long.MinValue);
public static SegmentTree<double> Max(IReadOnlyList<double> values) =>
new SegmentTree<double>(values, Math.Max, double.MinValue);
}
public class UnionFind {
private int[] parents;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public UnionFind(int count) {
parents = Enumerable.Repeat(-1, count).ToArray();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryUnite(int x, int y) {
var rootX = GetRoot(x);
var rootY = GetRoot(y);
if (rootX == rootY)
return false;
if (parents[rootY] < parents[rootX]) {
var temp = rootX;
rootX = rootY;
rootY = temp;
}
parents[rootX] += parents[rootY];
parents[rootY] = rootX;
return true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Find(int x, int y) => GetRoot(x) == GetRoot(y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetRoot(int x) {
while (parents[x] >= 0)
x = parents[x];
return x;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long GetSize(int x) => -parents[GetRoot(x)];
}
public class IterTools {
/// <summary>
/// ็ตใฟๅใใ๏ผ้่คใชใ๏ผ
/// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<long>> Combinations(long n,
long k) {
if (k <= 0)
yield break;
long[] indices = new long[k];
long pointer = 0;
while (pointer >= 0) {
if (indices[pointer] < n) {
if (pointer >= k - 1) {
yield return indices;
indices[pointer]++;
} else {
indices[pointer + 1] = indices[pointer] + 1;
pointer++;
}
} else {
pointer--;
if (pointer >= 0)
indices[pointer]++;
}
}
}
/// <summary>
/// ็ตใฟๅใใ๏ผ้่คใชใ๏ผ
/// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts,
long k) {
if (k <= 0)
yield break;
long[] indices = new long[k];
T[] container = new T[k];
long pointer = 0;
long n = ts.LongLength;
while (pointer >= 0) {
if (indices[pointer] < n) {
container[pointer] = ts[indices[pointer]];
if (pointer >= k - 1) {
yield return container;
indices[pointer]++;
} else {
indices[pointer + 1] = indices[pointer] + 1;
pointer++;
}
} else {
pointer--;
if (pointer >= 0)
indices[pointer]++;
}
}
}
/// <summary>
/// ็ตใฟๅใใ๏ผ้่คใใ๏ผ
/// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<long>>
CombinationsWithReplacement(long n, long k) {
if (k <= 0)
yield break;
long[] container = new long[k];
long pointer = 0;
while (pointer >= 0) {
if (container[pointer] < n) {
if (pointer >= k - 1) {
yield return container;
container[pointer]++;
} else {
container[pointer + 1] = 0;
pointer++;
}
} else {
pointer--;
if (pointer >= 0)
container[pointer]++;
}
}
}
/// <summary>
/// ็ตใฟๅใใ๏ผ้่คใใ๏ผ
/// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<T>>
CombinationsWithReplacement<T>(T[] ts, long k) {
if (k <= 0)
yield break;
long[] indices = new long[k];
T[] container = new T[k];
long pointer = 0;
long n = ts.LongLength;
while (pointer >= 0) {
if (indices[pointer] < n) {
container[pointer] = ts[indices[pointer]];
if (pointer >= k - 1) {
yield return container;
indices[pointer]++;
} else {
indices[pointer + 1] = 0;
pointer++;
}
} else {
pointer--;
if (pointer >= 0)
indices[pointer]++;
}
}
}
/// <summary>
/// ้ ๅ
/// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<long>> Permutations(long n,
long k) {
if (k <= 0)
yield break;
HashSet<long> enumed = new HashSet<long>();
long[] container = new long[k];
long pointer = 0;
while (pointer >= 0) {
if (container[pointer] < n) {
if (enumed.Contains(container[pointer])) {
container[pointer]++;
} else if (pointer >= k - 1) {
yield return container;
container[pointer]++;
} else {
enumed.Add(container[pointer]);
container[pointer + 1] = 0;
pointer++;
}
} else {
pointer--;
if (pointer >= 0) {
enumed.Remove(container[pointer]);
container[pointer]++;
}
}
}
}
/// <summary>
/// ้ ๅ
/// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts,
long k) {
if (k <= 0)
yield break;
HashSet<long> enumed = new HashSet<long>();
long[] indices = new long[k];
T[] container = new T[k];
long pointer = 0;
long n = ts.LongLength;
while (pointer >= 0) {
if (indices[pointer] < n) {
if (enumed.Contains(indices[pointer])) {
indices[pointer]++;
} else if (pointer >= k - 1) {
container[pointer] = ts[indices[pointer]];
yield return container;
indices[pointer]++;
} else {
container[pointer] = ts[indices[pointer]];
enumed.Add(indices[pointer]);
indices[pointer + 1] = 0;
pointer++;
}
} else {
pointer--;
if (pointer >= 0) {
enumed.Remove(indices[pointer]);
indices[pointer]++;
}
}
}
}
}
public class Tree {
public Tree() { toNodes = new Dictionary<long, long[]>(); }
public Tree(Scanner sc, long n, bool base1 = true,
bool singleDirection = false) {
Adjust(sc.Pairs(n), base1, singleDirection);
}
public Tree(Pair<long, long>[] edges, bool base1 = true,
bool singleDirection = false) {
Adjust(edges, base1, singleDirection);
}
public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true,
bool singleDirection = false) {
Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1,
singleDirection);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Adjust(Pair<long, long>[] edges, bool base1,
bool singleDirection) {
var arrows = base1
? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 })
: edges.Select(x => new { from = x.X, to = x.Y });
if (singleDirection == false)
arrows =
arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from }));
toNodes =
arrows.GroupBy(x => x.from)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray());
}
private long[] empty = new long[0];
private Dictionary<long, long[]> toNodes;
public long[] To(long from) {
long[] res = null;
if (toNodes.TryGetValue(from, out res))
return res;
else
return empty;
}
public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) {
return GetRouteEdgesImpl(from, to).Skip(1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from,
long to) {
var routeNodes = GetRouteNodes(from, to);
var current = -1L;
foreach (var next in routeNodes) {
yield return new Pair<long, long>(current, next);
current = next;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<long> GetRouteNodes(long from, long to) {
Stack<long> routeNodes = new Stack<long>();
HashSet<long> checkedNodes = new HashSet<long>();
GetRouteNodes(from, to, routeNodes, checkedNodes);
return routeNodes.Reverse();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes,
HashSet<long> checkedNodes) {
routeNodes.Push(current);
checkedNodes.Add(current);
if (current == dest)
return true;
foreach (var next in toNodes[current]) {
if (checkedNodes.Contains(next))
continue;
if (GetRouteNodes(next, dest, routeNodes, checkedNodes))
return true;
}
routeNodes.Pop();
return false;
}
/// <summary>
/// ๆจใฎ็ดๅพ๏ผไธ็ช้ทใๆ๏ผใๆฑใใ
/// </summary>
/// <returns>ๆจใฎ็ดๅพ๏ผไธ็ช้ทใๆ๏ผ</returns>
public long GetDiameter() {
long firstFarthest = 0;
long _1 = 0;
GetDiameterImpl(-1, 0, 0, ref _1, ref firstFarthest);
long maxDistance = 0;
long _2 = 0;
GetDiameterImpl(-1, firstFarthest, 0, ref maxDistance, ref _2);
return maxDistance;
}
private void GetDiameterImpl(long from, long current, long distance,
ref long maxDistance, ref long farthest) {
if (distance > maxDistance) {
maxDistance = distance;
farthest = current;
}
foreach (var to in To(current)) {
if (from == to)
continue;
GetDiameterImpl(current, to, distance + 1, ref maxDistance,
ref farthest);
}
}
}
public class PriorityQueue<TKey, TState>
where TKey : IComparable<TKey> {
public int Count { get; private set; }
private readonly Func<TState, TKey> keySelector;
private readonly bool desc;
private TState[] states = new TState[65536];
private TKey[] keys = new TKey[65536];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) {
this.keySelector = keySelector;
this.desc = desc;
}
public TState Top {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
ValidateNonEmpty();
return states[1];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TState Dequeue() {
var top = Top;
var item = states[Count];
var key = keys[Count];
Count--;
int index = 1;
while (true) {
if ((index << 1) >= Count) {
if (index << 1 > Count)
break;
if (key.CompareTo(keys[index << 1]) <= 0 ^ desc)
break;
states[index] = states[index << 1];
keys[index] = keys[index << 1];
index <<= 1;
} else {
var nextIndex =
keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc
? (index << 1)
: (index << 1) + 1;
if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc)
break;
states[index] = states[nextIndex];
keys[index] = keys[nextIndex];
index = nextIndex;
}
}
states[index] = item;
keys[index] = key;
return top;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(TState state) {
var key = keySelector.Invoke(state);
Count++;
int index = Count;
if (states.Length == Count)
Extend(states.Length * 2);
while ((index >> 1) != 0) {
if (keys[index >> 1].CompareTo(key) <= 0 ^ desc)
break;
states[index] = states[index >> 1];
keys[index] = keys[index >> 1];
index >>= 1;
}
states[index] = state;
keys[index] = key;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Extend(int newSize) {
TState[] newStates = new TState[newSize];
TKey[] newKeys = new TKey[newSize];
states.CopyTo(newStates, 0);
keys.CopyTo(newKeys, 0);
states = newStates;
keys = newKeys;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ValidateNonEmpty() {
if (Count == 0)
throw new IndexOutOfRangeException();
}
}
public class BinaryIndexTree {
long length;
long[] binaryIndexedTree;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public BinaryIndexTree(long length) {
this.length = length;
binaryIndexedTree = new long[length + 1];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(long indexZeroBase, long additional) {
// i += i & -i
// 1ใ็ซใฃใฆใใๆไธไฝใใใใ่ถณใใใฎๆๅณ
for (long i = indexZeroBase + 1; i <= length; i += i & -i) {
binaryIndexedTree[i] += additional;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Sum(long indexZeroBase) {
long result = 0;
// i += i & -i
// 1ใ็ซใฃใฆใใๆไธไฝใใใใๅผใใใฎๆๅณ
for (long i = indexZeroBase + 1; i > 0; i -= i & -i) {
result += binaryIndexedTree[i];
}
return result;
}
}
public static class BinarySearch {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered)
where T : IComparable {
return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered,
int low, int high)
where T : IComparable {
var count = listOrdered.Count;
if (count == 0)
return low;
if (listOrdered[high].CompareTo(x) <= 0)
return high + 1;
while (low < high) {
var mid = (low + high) / 2;
if (listOrdered[mid].CompareTo(x) > 0)
high = mid;
else
low = mid + 1;
}
return low;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long GetLastIndexLess<T>(T x, IList<T> listOrdered)
where T : IComparable {
return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low,
int high)
where T : IComparable {
var count = listOrdered.Count;
if (count == 0)
return low - 1;
if (listOrdered[0].CompareTo(x) >= 0)
return low - 1;
while (low < high) {
var mid = (low + high + 1) / 2;
if (listOrdered[mid].CompareTo(x) < 0)
low = mid;
else
high = mid - 1;
}
return low;
}
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: ่ฒ ใฎ็ก้ๅคง
/// long.MaxValue: ใใฉใ็ใใชใ
/// ใใฎไป: ่ท้ข
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Gcd(int a, int b) => Gcd((long)a, (long)b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Gcd(long a, long b) {
if (a < b)
return GcdImpl(b, a);
else
return GcdImpl(a, b);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long GcdImpl(long a, long b) {
var remainder = a % b;
if (remainder == 0)
return b;
else
return GcdImpl(b, remainder);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Lcm(int a, int b) => Lcm((long)a, (long)b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Pow(int n, int p) => Pow((long)n, (long)p);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Pow(long n, long p) {
var res = 1L;
for (long i = 0; i < p; i++)
res *= n;
return res;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Dictionary<long, long> Factorize(int n) => Factorize((long)n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Dictionary<long, long> Factorize(long n) {
var res = new Dictionary<long, long>();
var r = n;
for (long i = 2; i * i <= r; i++) {
var c = 0L;
while (r % i == 0) {
c++;
r /= i;
}
if (c > 0)
res.Add(i, c);
}
if (r > 1)
res.Add(r, 1);
return res;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<long> Divisors(int n) => Divisors((long)n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<long> Divisors(long n) {
var cache = new Stack<long>();
for (long i = 1; i * i <= n; i++) {
if (n % i == 0) {
yield return i;
cache.Push(i);
}
}
var r = cache.Peek();
if (r * r == n)
cache.Pop();
while (cache.Count > 0) {
var i = cache.Pop();
yield return n / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<int> Loop(int n) {
for (int i = 0; i < n; i++)
yield return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<long> Loop(long n) {
for (long i = 0L; i < n; i++)
yield return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<T> Repeat<T>(T t, long n) {
for (long i = 0L; i < n; i++)
yield return t;
}
}
struct Mint {
public static long Divider {
set { divider = value; }
}
private static long divider = 1000000007L;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Set998244353() { divider = 998244353L; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Set1000000009() { divider = 1000000009L; }
public long Value { get; }
public override string ToString() => this.Value.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mint(long value) { this.Value = value; }
// public static implicit operator Mint(long a) => new Mint(a % divider);
// public static implicit operator Mint(int a) => new Mint(a % divider);
// public static explicit operator long(Mint a) => a.Value;
// public static explicit operator int(Mint a) => (int)a.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint
operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator +(Mint a, long b) => a + new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator +(Mint a, int b) => a + new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator -(Mint a, Mint b) {
var t = (a.Value - b.Value) % divider;
if (t < 0L)
t += divider;
return new Mint(t);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator -(Mint a, long b) => a - new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator -(Mint a, int b) => a - new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint
operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator *(Mint a, long b) => a * new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator *(Mint a, int b) => a * new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator /(Mint a, Mint b) =>
new Mint((a.Value * InvImpl(b.Value)) % divider);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator /(Mint a, long b) => a / new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator /(Mint a, int b) => a / new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mint Pow(long p) => new Mint(PowImpl(Value, p));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long PowImpl(long a, long p) {
if (p == 0L)
return 1L;
if (p == 1L)
return a;
var halfP = p / 2L;
var halfPowered = PowImpl(a, halfP);
var powered = halfPowered * halfPowered % divider;
return p % 2L == 0L ? powered : powered * a % divider;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Inv(long a) => new Mint(InvImpl(a));
private static readonly Dictionary<long, long> invCache =
new Dictionary<long, long>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long InvImpl(long a) {
long cache;
if (invCache.TryGetValue(a, out cache))
return cache;
var result = PowImpl(a, divider - 2L);
invCache.Add(a, result);
return result;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Fac(long a) => new Mint(FacImpl(a));
private static long[] facCache = new long[262144];
private static long cachedFac = 0L;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long FacImpl(long a) {
if (a >= divider)
return 0L;
facCache[0] = 1L;
if (facCache.LongLength <= a) {
long newSize = facCache.LongLength;
while (newSize <= a) {
newSize *= 2;
}
ExtendFacCache(newSize);
}
if (cachedFac < a) {
var val = facCache[cachedFac];
var start = cachedFac + 1L;
for (long i = start; i <= a; i++) {
val = (val * i) % divider;
facCache[i] = val;
}
cachedFac = a;
}
return facCache[a];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void ExtendFacCache(long newSize) {
long[] newFacCache = new long[newSize];
facCache.CopyTo(newFacCache, 0);
facCache = newFacCache;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long PermImpl(long n, long r) {
if (n < r)
return 0L;
if (r <= 0L)
return 1L;
var nn = FacImpl(n);
var nr = FacImpl(n - r);
return (nn * InvImpl(nr)) % divider;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long CombImpl(long n, long r) {
if (n < r)
return 0L;
if (n == r)
return 1L;
if (n - r < r)
return CombImpl(n, n - r);
var nn = FacImpl(n);
var nr = FacImpl(n - r);
var rr = FacImpl(r);
var nrrr = (nr * rr) % divider;
return (nn * InvImpl(nrrr)) % divider;
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
namespace V {
partial class Solver {
public void Solve() {
// var n = Read;
Write(SolveLong());
// YesNo(SolveBool());
}
public long SolveLong() {
var n = Read;
var m = Read;
var a = Arr(n).OrderBy(x => x).ToArray();
var l = a[0] + a[0];
var r = a[n - 1] + a[n - 1];
while (l + 1 < r) {
var mid = (l + r) / 2;
var count = 0L;
foreach (var i in C.Loop(n)) {
var idx = C.BinarySearch.GetLastIndexLess(mid - a[i], a);
var c = (n - idx) - 1;
count += c;
}
if (count >= m)
l = mid;
else
r = mid;
}
var s = new List<long>() { 0L };
var current = 0L;
foreach (var i in C.Loop(n)) {
current += a[i];
s.Add(current);
}
var res = 0L;
var cnt = 0L;
foreach (var i in C.Loop(n)) {
var idx = C.BinarySearch.GetLastIndexLess(l - a[i], a);
var c = (n - idx) - 1;
cnt += c;
res += c * a[i];
res += s[(int)n] - s[(int)idx + 1];
}
res -= (cnt - m) * l;
return res;
}
public bool SolveBool() {
var n = Read;
return false;
}
}
}
namespace V {
class StartingPoint {
static void Main(string[] args) {
try {
var streamReader = args.Any()
? new StreamReader(args[0])
: new StreamReader(Console.OpenStandardInput());
var streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var scanner = new Scanner(streamReader);
var printer = new Printer(streamWriter);
var solver = new Solver(scanner, printer);
solver.Solve();
streamWriter.Flush();
} catch (Exception e) {
Console.WriteLine(e);
if (args.Any() == false)
throw e;
}
if (args.Any())
Console.ReadKey();
}
}
partial class Solver {
public Solver(Scanner sc, Printer pr) {
this.sc = sc;
this.pr = pr;
}
private readonly Scanner sc;
private readonly Printer pr;
private IEnumerable<int> Loop(int n) => C.Loop(n);
private IEnumerable<long> Loop(long n) => C.Loop(n);
private int RdInt => sc.Int;
private int ReadInt => sc.Int;
private long Rd => sc.Long;
private long Read => sc.Long;
private long ReadLong => sc.Long;
private double RdDouble => sc.Double;
private double ReadDouble => sc.Double;
private string Str => sc.Str;
private string RdStr => sc.Str;
private string ReadStr => sc.Str;
private int[] ArrInt(int n) => sc.Ints(n);
private int[] ArrInt(long n) => sc.Ints(n);
private long[] Arr(int n) => sc.Longs(n);
private long[] Arr(long n) => sc.Longs(n);
private long[] ArrLong(int n) => sc.Longs(n);
private long[] ArrLong(long n) => sc.Longs(n);
private double[] ArrDouble(int n) => sc.Doubles(n);
private double[] ArrDouble(long n) => sc.Doubles(n);
private string[] ArrStr(int n) => sc.Strs(n);
private string[] ArrStr(long n) => sc.Strs(n);
private void Wr(string s) => pr.Write(s);
private void Wr(object obj) => pr.Write(obj);
private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts);
private void Wr(params object[] objs) => pr.Write(objs);
private void Write(string s) => pr.Write(s);
private void Write(object obj) => pr.Write(obj);
private void Write<T>(IEnumerable<T> ts) => pr.Write(ts);
private void Write(params object[] objs) => pr.Write(objs);
private void YesNo(bool b) => Write(b ? "Yes" : "No");
private void YESNO(bool b) => Write(b ? "YES" : "NO");
}
class Scanner {
private readonly TextReader reader;
public Scanner(TextReader reader) { this.reader = reader; }
private Queue<string> strQueue = new Queue<string>();
public string Str {
get {
if (strQueue.Count > 0)
return strQueue.Dequeue();
string[] strs = null;
do {
strs = reader.ReadLine().Split(new[] { ' ' },
StringSplitOptions.RemoveEmptyEntries);
} while (strs.Any() == false);
foreach (var s in strs.Skip(1))
strQueue.Enqueue(s);
return strs[0];
}
}
public int Int => int.Parse(this.Str);
public long Long => long.Parse(this.Str);
public double Double => double.Parse(this.Str);
public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2));
public static T1
ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1));
public static T1 Convert<T1>(string s) =>
TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s))
: TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s))
: TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s))
: TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0])
: ChangeTypes<T1, string>(s);
public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str),
Convert<TY>(this.Str));
public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>(
Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str));
public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() =>
new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str),
Convert<TZ>(this.Str), Convert<TW>(this.Str));
}
static class ScannerExtension {
public static int[] Ints(this Scanner scanner,
int n) => scanner.Ints((long)n);
public static int[] Ints(this Scanner scanner,
long n) => scanner.ScanStrs<int>(n).ToArray();
public static long[] Longs(this Scanner scanner,
int n) => scanner.Longs((long)n);
public static long[] Longs(this Scanner scanner,
long n) => scanner.ScanStrs<long>(n).ToArray();
public static double[] Doubles(this Scanner scanner,
int n) => scanner.Doubles((long)n);
public static double[] Doubles(this Scanner scanner, long n) =>
scanner.ScanStrs<double>(n).ToArray();
public static string[] Strs(this Scanner scanner,
int n) => scanner.Strs((long)n);
public static string[] Strs(this Scanner scanner,
long n) => scanner.ScanStrs<string>(n).ToArray();
private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return Scanner.Convert<T>(scanner.Str);
}
public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) =>
scanner.Pairs<TX, TY>((long)n);
public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) =>
scanner.ScanPairs<TX, TY>(n).ToArray();
public static Pair<long, long>[] Pairs(this Scanner scanner,
int n) => scanner.Pairs((long)n);
public static Pair<long, long>[] Pairs(this Scanner scanner, long n) =>
scanner.ScanPairs<long, long>(n).ToArray();
public static Pair<int, int>[] PairsInt(this Scanner scanner,
int n) => scanner.PairsInt((long)n);
public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) =>
scanner.ScanPairs<int, int>(n).ToArray();
private static IEnumerable<Pair<TX, TY>>
ScanPairs<TX, TY>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P2<TX, TY>();
}
public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(
this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n);
public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner,
long n) =>
scanner.ScanPairs3<TX, TY, TZ>(n).ToArray();
public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) =>
scanner.Pairs3((long)n);
public static Pair3<long, long, long>[] Pairs3(this Scanner scanner,
long n) =>
scanner.ScanPairs3<long, long, long>(n).ToArray();
public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) =>
scanner.Pairs3Int((long)n);
public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner,
long n) =>
scanner.ScanPairs3<int, int, int>(n).ToArray();
private static IEnumerable<Pair3<TX, TY, TZ>>
ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P3<TX, TY, TZ>();
}
public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>(
this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n);
public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>(
this Scanner scanner,
long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray();
public static Pair4<long, long, long, long>[] Pairs4(
this Scanner scanner, int n) => scanner.Pairs4((long)n);
public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner,
long n) =>
scanner.ScanPairs4<long, long, long, long>(n).ToArray();
public static Pair4<int, int, int, int>[] Pairs4Int(
this Scanner scanner, int n) => scanner.Pairs4Int((long)n);
public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner,
long n) =>
scanner.ScanPairs4<int, int, int, int>(n).ToArray();
private static IEnumerable<Pair4<TX, TY, TZ, TW>>
ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) {
for (long i = 0; i < n; i++)
yield return scanner.P4<TX, TY, TZ, TW>();
}
}
class Pair<TX, TY> {
public TX X { get; }
public TY Y { get; }
public Pair(TX x, TY y) {
this.X = x;
this.Y = y;
}
}
class Pair : Pair<long, long> {
public Pair(long x, long y) : base(x, y) {}
}
class PairInt : Pair<int, int> {
public PairInt(int x, int y) : base(x, y) {}
}
class Pair3<TX, TY, TZ> {
public TX X { get; }
public TY Y { get; }
public TZ Z { get; }
public Pair3(TX x, TY y, TZ z) {
this.X = x;
this.Y = y;
this.Z = z;
}
}
class Pair3 : Pair3<long, long, long> {
public Pair3(long x, long y, long z) : base(x, y, z) {}
}
class Pair3Int : Pair3<int, int, int> {
public Pair3Int(int x, int y, int z) : base(x, y, z) {}
}
class Pair4<TX, TY, TZ, TW> {
public TX X { get; }
public TY Y { get; }
public TZ Z { get; }
public TW W { get; }
public Pair4(TX x, TY y, TZ z, TW w) {
this.X = x;
this.Y = y;
this.Z = z;
this.W = w;
}
}
class Pair4 : Pair4<long, long, long, long> {
public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {}
}
class Pair4Int : Pair4<int, int, int, int> {
public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {}
}
class Printer {
private readonly TextWriter writer;
public Printer(TextWriter writer) { this.writer = writer; }
public void Write(string obj) { writer.WriteLine(obj); }
public void Write(object obj) { writer.WriteLine(obj); }
public void Write<T>(IEnumerable<T> ts) {
writer.WriteLine(string.Join(" ", ts));
}
public void Write(params object[] objs) {
writer.WriteLine(string.Join(" ", objs));
}
}
static class Extension {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool SafeAdd<T>(this HashSet<T> ts, T t) {
if (ts.Contains(t)) {
return false;
} else {
ts.Add(t);
return false;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool SafeRemove<T>(this HashSet<T> ts, T t) {
if (ts.Contains(t)) {
ts.Remove(t);
return true;
} else {
return false;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] = value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafePlus<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] += value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] -= value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] *= value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) {
if (ts.ContainsKey(t))
ts[t] /= value;
else
ts.Add(t, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToDigit(this char c) => (long)(c - '0');
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToSmallAbcIndex(this char c) => (long)(c - 'a');
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToLargeAbcIndex(this char c) => (long)(c - 'A');
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string
ToStr(this IEnumerable<char> cs) => new string(cs.ToArray());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ToLong(this IEnumerable<char> s) {
var basis = 1L;
var res = 0L;
foreach (var c in s) {
var d = c.ToSmallAbcIndex() + 1;
res += d * basis;
basis *= 27;
}
return res;
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static bool TryMin<T>(this ref T current, T newer) where T : struct,
// IComparable<T>
//{
// if (current.CompareTo(newer) <= 0)
// return false;
// current = newer;
// return true;
//}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static bool TryMax<T>(this ref T current, T newer) where T : struct,
// IComparable<T>
//{
// if (current.CompareTo(newer) >= 0)
// return false;
// current = newer;
// return true;
//}
}
class C {
public class SegmentTree<T> {
private readonly int valueCount;
private readonly int baseCount;
private readonly int baseIndex;
private readonly T[] nodes;
private readonly Func<T, T, T> func;
private readonly T defaultValue;
public SegmentTree(IReadOnlyList<T> ts, Func<T, T, T> func,
T filling = default(T)) {
this.func = func;
this.defaultValue = filling;
valueCount = ts.Count;
baseCount = 1;
while (valueCount > baseCount)
baseCount <<= 1;
nodes = new T[baseCount * 2 - 1];
baseIndex = baseCount - 1;
for (int i = 0; i < ts.Count; i++)
nodes[baseIndex + i] = ts[i];
for (int i = ts.Count; i < baseCount; i++)
nodes[baseIndex + i] = filling;
for (int i = baseIndex - 1; i >= 0; i--)
nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Update(int index, T t) {
var i = baseIndex + index;
nodes[i] = t;
while (i > 0) {
i -= 1;
i /= 2;
nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Query(int leftIndex, int rightNextIndex) {
T left = defaultValue;
T right = defaultValue;
int l = leftIndex + baseCount - 1;
int r = rightNextIndex + baseCount - 1;
for (; l < r; l >>= 1, r >>= 1) {
if ((l & 1) == 0) {
left = func.Invoke(left, nodes[l]);
}
if ((r & 1) == 0) {
r--;
right = func.Invoke(right, nodes[r]);
}
}
return func.Invoke(left, right);
}
}
public class SegmentTree {
public static SegmentTree<int> Sum(IReadOnlyList<int> values) =>
new SegmentTree<int>(values, (x, y) => x + y);
public static SegmentTree<long> Sum(IReadOnlyList<long> values) =>
new SegmentTree<long>(values, (x, y) => x + y);
public static SegmentTree<double> Sum(IReadOnlyList<double> values) =>
new SegmentTree<double>(values, (x, y) => x + y);
public static SegmentTree<int> Mult(IReadOnlyList<int> values) =>
new SegmentTree<int>(values, (x, y) => x * y, 1);
public static SegmentTree<long> Mult(IReadOnlyList<long> values) =>
new SegmentTree<long>(values, (x, y) => x * y, 1);
public static SegmentTree<double> Mult(IReadOnlyList<double> values) =>
new SegmentTree<double>(values, (x, y) => x * y, 1);
public static SegmentTree<int> Min(IReadOnlyList<int> values) =>
new SegmentTree<int>(values, Math.Min, int.MaxValue);
public static SegmentTree<long> Min(IReadOnlyList<long> values) =>
new SegmentTree<long>(values, Math.Min, long.MaxValue);
public static SegmentTree<double> Min(IReadOnlyList<double> values) =>
new SegmentTree<double>(values, Math.Min, double.MaxValue);
public static SegmentTree<int> Max(IReadOnlyList<int> values) =>
new SegmentTree<int>(values, Math.Max, int.MinValue);
public static SegmentTree<long> Max(IReadOnlyList<long> values) =>
new SegmentTree<long>(values, Math.Max, long.MinValue);
public static SegmentTree<double> Max(IReadOnlyList<double> values) =>
new SegmentTree<double>(values, Math.Max, double.MinValue);
}
public class UnionFind {
private int[] parents;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public UnionFind(int count) {
parents = Enumerable.Repeat(-1, count).ToArray();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryUnite(int x, int y) {
var rootX = GetRoot(x);
var rootY = GetRoot(y);
if (rootX == rootY)
return false;
if (parents[rootY] < parents[rootX]) {
var temp = rootX;
rootX = rootY;
rootY = temp;
}
parents[rootX] += parents[rootY];
parents[rootY] = rootX;
return true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Find(int x, int y) => GetRoot(x) == GetRoot(y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetRoot(int x) {
while (parents[x] >= 0)
x = parents[x];
return x;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long GetSize(int x) => -parents[GetRoot(x)];
}
public class IterTools {
/// <summary>
/// ็ตใฟๅใใ๏ผ้่คใชใ๏ผ
/// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<long>> Combinations(long n,
long k) {
if (k <= 0)
yield break;
long[] indices = new long[k];
long pointer = 0;
while (pointer >= 0) {
if (indices[pointer] < n) {
if (pointer >= k - 1) {
yield return indices;
indices[pointer]++;
} else {
indices[pointer + 1] = indices[pointer] + 1;
pointer++;
}
} else {
pointer--;
if (pointer >= 0)
indices[pointer]++;
}
}
}
/// <summary>
/// ็ตใฟๅใใ๏ผ้่คใชใ๏ผ
/// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts,
long k) {
if (k <= 0)
yield break;
long[] indices = new long[k];
T[] container = new T[k];
long pointer = 0;
long n = ts.LongLength;
while (pointer >= 0) {
if (indices[pointer] < n) {
container[pointer] = ts[indices[pointer]];
if (pointer >= k - 1) {
yield return container;
indices[pointer]++;
} else {
indices[pointer + 1] = indices[pointer] + 1;
pointer++;
}
} else {
pointer--;
if (pointer >= 0)
indices[pointer]++;
}
}
}
/// <summary>
/// ็ตใฟๅใใ๏ผ้่คใใ๏ผ
/// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<long>>
CombinationsWithReplacement(long n, long k) {
if (k <= 0)
yield break;
long[] container = new long[k];
long pointer = 0;
while (pointer >= 0) {
if (container[pointer] < n) {
if (pointer >= k - 1) {
yield return container;
container[pointer]++;
} else {
container[pointer + 1] = 0;
pointer++;
}
} else {
pointer--;
if (pointer >= 0)
container[pointer]++;
}
}
}
/// <summary>
/// ็ตใฟๅใใ๏ผ้่คใใ๏ผ
/// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<T>>
CombinationsWithReplacement<T>(T[] ts, long k) {
if (k <= 0)
yield break;
long[] indices = new long[k];
T[] container = new T[k];
long pointer = 0;
long n = ts.LongLength;
while (pointer >= 0) {
if (indices[pointer] < n) {
container[pointer] = ts[indices[pointer]];
if (pointer >= k - 1) {
yield return container;
indices[pointer]++;
} else {
indices[pointer + 1] = 0;
pointer++;
}
} else {
pointer--;
if (pointer >= 0)
indices[pointer]++;
}
}
}
/// <summary>
/// ้ ๅ
/// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<long>> Permutations(long n,
long k) {
if (k <= 0)
yield break;
HashSet<long> enumed = new HashSet<long>();
long[] container = new long[k];
long pointer = 0;
while (pointer >= 0) {
if (container[pointer] < n) {
if (enumed.Contains(container[pointer])) {
container[pointer]++;
} else if (pointer >= k - 1) {
yield return container;
container[pointer]++;
} else {
enumed.Add(container[pointer]);
container[pointer + 1] = 0;
pointer++;
}
} else {
pointer--;
if (pointer >= 0) {
enumed.Remove(container[pointer]);
container[pointer]++;
}
}
}
}
/// <summary>
/// ้ ๅ
/// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts,
long k) {
if (k <= 0)
yield break;
HashSet<long> enumed = new HashSet<long>();
long[] indices = new long[k];
T[] container = new T[k];
long pointer = 0;
long n = ts.LongLength;
while (pointer >= 0) {
if (indices[pointer] < n) {
if (enumed.Contains(indices[pointer])) {
indices[pointer]++;
} else if (pointer >= k - 1) {
container[pointer] = ts[indices[pointer]];
yield return container;
indices[pointer]++;
} else {
container[pointer] = ts[indices[pointer]];
enumed.Add(indices[pointer]);
indices[pointer + 1] = 0;
pointer++;
}
} else {
pointer--;
if (pointer >= 0) {
enumed.Remove(indices[pointer]);
indices[pointer]++;
}
}
}
}
}
public class Tree {
public Tree() { toNodes = new Dictionary<long, long[]>(); }
public Tree(Scanner sc, long n, bool base1 = true,
bool singleDirection = false) {
Adjust(sc.Pairs(n), base1, singleDirection);
}
public Tree(Pair<long, long>[] edges, bool base1 = true,
bool singleDirection = false) {
Adjust(edges, base1, singleDirection);
}
public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true,
bool singleDirection = false) {
Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1,
singleDirection);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Adjust(Pair<long, long>[] edges, bool base1,
bool singleDirection) {
var arrows = base1
? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 })
: edges.Select(x => new { from = x.X, to = x.Y });
if (singleDirection == false)
arrows =
arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from }));
toNodes =
arrows.GroupBy(x => x.from)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray());
}
private long[] empty = new long[0];
private Dictionary<long, long[]> toNodes;
public long[] To(long from) {
long[] res = null;
if (toNodes.TryGetValue(from, out res))
return res;
else
return empty;
}
public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) {
return GetRouteEdgesImpl(from, to).Skip(1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from,
long to) {
var routeNodes = GetRouteNodes(from, to);
var current = -1L;
foreach (var next in routeNodes) {
yield return new Pair<long, long>(current, next);
current = next;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<long> GetRouteNodes(long from, long to) {
Stack<long> routeNodes = new Stack<long>();
HashSet<long> checkedNodes = new HashSet<long>();
GetRouteNodes(from, to, routeNodes, checkedNodes);
return routeNodes.Reverse();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes,
HashSet<long> checkedNodes) {
routeNodes.Push(current);
checkedNodes.Add(current);
if (current == dest)
return true;
foreach (var next in toNodes[current]) {
if (checkedNodes.Contains(next))
continue;
if (GetRouteNodes(next, dest, routeNodes, checkedNodes))
return true;
}
routeNodes.Pop();
return false;
}
/// <summary>
/// ๆจใฎ็ดๅพ๏ผไธ็ช้ทใๆ๏ผใๆฑใใ
/// </summary>
/// <returns>ๆจใฎ็ดๅพ๏ผไธ็ช้ทใๆ๏ผ</returns>
public long GetDiameter() {
long firstFarthest = 0;
long _1 = 0;
GetDiameterImpl(-1, 0, 0, ref _1, ref firstFarthest);
long maxDistance = 0;
long _2 = 0;
GetDiameterImpl(-1, firstFarthest, 0, ref maxDistance, ref _2);
return maxDistance;
}
private void GetDiameterImpl(long from, long current, long distance,
ref long maxDistance, ref long farthest) {
if (distance > maxDistance) {
maxDistance = distance;
farthest = current;
}
foreach (var to in To(current)) {
if (from == to)
continue;
GetDiameterImpl(current, to, distance + 1, ref maxDistance,
ref farthest);
}
}
}
public class PriorityQueue<TKey, TState>
where TKey : IComparable<TKey> {
public int Count { get; private set; }
private readonly Func<TState, TKey> keySelector;
private readonly bool desc;
private TState[] states = new TState[65536];
private TKey[] keys = new TKey[65536];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) {
this.keySelector = keySelector;
this.desc = desc;
}
public TState Top {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
ValidateNonEmpty();
return states[1];
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TState Dequeue() {
var top = Top;
var item = states[Count];
var key = keys[Count];
Count--;
int index = 1;
while (true) {
if ((index << 1) >= Count) {
if (index << 1 > Count)
break;
if (key.CompareTo(keys[index << 1]) <= 0 ^ desc)
break;
states[index] = states[index << 1];
keys[index] = keys[index << 1];
index <<= 1;
} else {
var nextIndex =
keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc
? (index << 1)
: (index << 1) + 1;
if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc)
break;
states[index] = states[nextIndex];
keys[index] = keys[nextIndex];
index = nextIndex;
}
}
states[index] = item;
keys[index] = key;
return top;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(TState state) {
var key = keySelector.Invoke(state);
Count++;
int index = Count;
if (states.Length == Count)
Extend(states.Length * 2);
while ((index >> 1) != 0) {
if (keys[index >> 1].CompareTo(key) <= 0 ^ desc)
break;
states[index] = states[index >> 1];
keys[index] = keys[index >> 1];
index >>= 1;
}
states[index] = state;
keys[index] = key;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Extend(int newSize) {
TState[] newStates = new TState[newSize];
TKey[] newKeys = new TKey[newSize];
states.CopyTo(newStates, 0);
keys.CopyTo(newKeys, 0);
states = newStates;
keys = newKeys;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ValidateNonEmpty() {
if (Count == 0)
throw new IndexOutOfRangeException();
}
}
public class BinaryIndexTree {
long length;
long[] binaryIndexedTree;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public BinaryIndexTree(long length) {
this.length = length;
binaryIndexedTree = new long[length + 1];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Add(long indexZeroBase, long additional) {
// i += i & -i
// 1ใ็ซใฃใฆใใๆไธไฝใใใใ่ถณใใใฎๆๅณ
for (long i = indexZeroBase + 1; i <= length; i += i & -i) {
binaryIndexedTree[i] += additional;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Sum(long indexZeroBase) {
long result = 0;
// i += i & -i
// 1ใ็ซใฃใฆใใๆไธไฝใใใใๅผใใใฎๆๅณ
for (long i = indexZeroBase + 1; i > 0; i -= i & -i) {
result += binaryIndexedTree[i];
}
return result;
}
}
public static class BinarySearch {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered)
where T : IComparable {
return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered,
int low, int high)
where T : IComparable {
var count = listOrdered.Count;
if (count == 0)
return low;
if (listOrdered[high].CompareTo(x) <= 0)
return high + 1;
while (low < high) {
var mid = (low + high) / 2;
if (listOrdered[mid].CompareTo(x) > 0)
high = mid;
else
low = mid + 1;
}
return low;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long GetLastIndexLess<T>(T x, IList<T> listOrdered)
where T : IComparable {
return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low,
int high)
where T : IComparable {
var count = listOrdered.Count;
if (count == 0)
return low - 1;
if (listOrdered[0].CompareTo(x) >= 0)
return low - 1;
while (low < high) {
var mid = (low + high + 1) / 2;
if (listOrdered[mid].CompareTo(x) < 0)
low = mid;
else
high = mid - 1;
}
return low;
}
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: ่ฒ ใฎ็ก้ๅคง
/// long.MaxValue: ใใฉใ็ใใชใ
/// ใใฎไป: ่ท้ข
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Gcd(int a, int b) => Gcd((long)a, (long)b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Gcd(long a, long b) {
if (a < b)
return GcdImpl(b, a);
else
return GcdImpl(a, b);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long GcdImpl(long a, long b) {
var remainder = a % b;
if (remainder == 0)
return b;
else
return GcdImpl(b, remainder);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Lcm(int a, int b) => Lcm((long)a, (long)b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Pow(int n, int p) => Pow((long)n, (long)p);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long Pow(long n, long p) {
var res = 1L;
for (long i = 0; i < p; i++)
res *= n;
return res;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Dictionary<long, long> Factorize(int n) => Factorize((long)n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Dictionary<long, long> Factorize(long n) {
var res = new Dictionary<long, long>();
var r = n;
for (long i = 2; i * i <= r; i++) {
var c = 0L;
while (r % i == 0) {
c++;
r /= i;
}
if (c > 0)
res.Add(i, c);
}
if (r > 1)
res.Add(r, 1);
return res;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<long> Divisors(int n) => Divisors((long)n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<long> Divisors(long n) {
var cache = new Stack<long>();
for (long i = 1; i * i <= n; i++) {
if (n % i == 0) {
yield return i;
cache.Push(i);
}
}
var r = cache.Peek();
if (r * r == n)
cache.Pop();
while (cache.Count > 0) {
var i = cache.Pop();
yield return n / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<int> Loop(int n) {
for (int i = 0; i < n; i++)
yield return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<long> Loop(long n) {
for (long i = 0L; i < n; i++)
yield return i;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IEnumerable<T> Repeat<T>(T t, long n) {
for (long i = 0L; i < n; i++)
yield return t;
}
}
struct Mint {
public static long Divider {
set { divider = value; }
}
private static long divider = 1000000007L;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Set998244353() { divider = 998244353L; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Set1000000009() { divider = 1000000009L; }
public long Value { get; }
public override string ToString() => this.Value.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mint(long value) { this.Value = value; }
// public static implicit operator Mint(long a) => new Mint(a % divider);
// public static implicit operator Mint(int a) => new Mint(a % divider);
// public static explicit operator long(Mint a) => a.Value;
// public static explicit operator int(Mint a) => (int)a.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint
operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator +(Mint a, long b) => a + new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator +(Mint a, int b) => a + new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator -(Mint a, Mint b) {
var t = (a.Value - b.Value) % divider;
if (t < 0L)
t += divider;
return new Mint(t);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator -(Mint a, long b) => a - new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator -(Mint a, int b) => a - new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint
operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator *(Mint a, long b) => a * new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator *(Mint a, int b) => a * new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator /(Mint a, Mint b) =>
new Mint((a.Value * InvImpl(b.Value)) % divider);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator /(Mint a, long b) => a / new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint operator /(Mint a, int b) => a / new Mint(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mint Pow(long p) => new Mint(PowImpl(Value, p));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long PowImpl(long a, long p) {
if (p == 0L)
return 1L;
if (p == 1L)
return a;
var halfP = p / 2L;
var halfPowered = PowImpl(a, halfP);
var powered = halfPowered * halfPowered % divider;
return p % 2L == 0L ? powered : powered * a % divider;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Inv(long a) => new Mint(InvImpl(a));
private static readonly Dictionary<long, long> invCache =
new Dictionary<long, long>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long InvImpl(long a) {
long cache;
if (invCache.TryGetValue(a, out cache))
return cache;
var result = PowImpl(a, divider - 2L);
invCache.Add(a, result);
return result;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Fac(long a) => new Mint(FacImpl(a));
private static long[] facCache = new long[262144];
private static long cachedFac = 0L;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long FacImpl(long a) {
if (a >= divider)
return 0L;
facCache[0] = 1L;
if (facCache.LongLength <= a) {
long newSize = facCache.LongLength;
while (newSize <= a) {
newSize *= 2;
}
ExtendFacCache(newSize);
}
if (cachedFac < a) {
var val = facCache[cachedFac];
var start = cachedFac + 1L;
for (long i = start; i <= a; i++) {
val = (val * i) % divider;
facCache[i] = val;
}
cachedFac = a;
}
return facCache[a];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void ExtendFacCache(long newSize) {
long[] newFacCache = new long[newSize];
facCache.CopyTo(newFacCache, 0);
facCache = newFacCache;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long PermImpl(long n, long r) {
if (n < r)
return 0L;
if (r <= 0L)
return 1L;
var nn = FacImpl(n);
var nr = FacImpl(n - r);
return (nn * InvImpl(nr)) % divider;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static long CombImpl(long n, long r) {
if (n < r)
return 0L;
if (n == r)
return 1L;
if (n - r < r)
return CombImpl(n, n - r);
var nn = FacImpl(n);
var nr = FacImpl(n - r);
var rr = FacImpl(r);
var nrrr = (nr * rr) % divider;
return (nn * InvImpl(nrrr)) % divider;
}
}
}
|
[["-", 0, 57, 75, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 57, 75, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 10,354
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.