buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Linq;
namespace c {
class Program {
static void Main(string[] args) {
int MOD_NUMBER = 1000000007;
int item_cnt = getIntParam();
long[] items = getLongParams();
long sum = 0;
long answer = 0;
for (int i = 0; i < item_cnt; i++) {
sum += items[i];
}
for (int i = 0; i < item_cnt; i++) {
sum -= items[i];
answer += (sum * items[i]);
}
Console.WriteLine(answer % MOD_NUMBER);
}
//↓↓↓ shared function ↓↓↓
static int getIntParam() { return int.Parse(Console.ReadLine()); }
static int[] getIntParams() {
return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
}
static long getLongParam() { return long.Parse(Console.ReadLine()); }
static long[] getLongParams() {
return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
}
static string getStringParam() { return Console.ReadLine(); }
static string[] getStringParams() { return Console.ReadLine().Split(' '); }
}
}
|
using System;
using System.Linq;
namespace c {
class Program {
static void Main(string[] args) {
long MOD_NUMBER = 1000000007;
int item_cnt = getIntParam();
long[] items = getLongParams();
long sum = 0;
long answer = 0;
for (int i = 0; i < item_cnt; i++) {
sum += items[i];
sum %= MOD_NUMBER;
}
for (int i = 0; i < item_cnt; i++) {
sum -= items[i];
if (sum < 0) {
sum += MOD_NUMBER;
}
answer += (sum * items[i]);
answer %= MOD_NUMBER;
}
Console.WriteLine(answer);
}
//↓↓↓ shared function ↓↓↓
static int getIntParam() { return int.Parse(Console.ReadLine()); }
static int[] getIntParams() {
return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
}
static long getLongParam() { return long.Parse(Console.ReadLine()); }
static long[] getLongParams() {
return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
}
static string getStringParam() { return Console.ReadLine(); }
static string[] getStringParams() { return Console.ReadLine().Split(' '); }
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 278
| 24
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
var mod = 1000000007;
var N = int.Parse(Console.ReadLine());
var A = new List<decimal>();
var line = Console.ReadLine().Split(" ");
for (int i = 0; i < N; i++) {
A.Add(decimal.Parse(line[i]));
};
var sums = new List<decimal>();
decimal sum = 0;
for (int i = 1; i < N; i++) {
sum = sum % mod + A[i];
sums.Add(sum);
}
sum = sum * A[0];
for (int left = 0; left < N - 2; left++) {
sum += A[left + 1] * (sums[N - 2] - sums[left]);
sum = sum % mod;
}
Console.WriteLine(sum);
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
checked {
var mod = 1000000007;
var N = int.Parse(Console.ReadLine());
var A = new List<long>();
var line = Console.ReadLine().Split(" ");
for (int i = 0; i < N; i++) {
A.Add(long.Parse(line[i]));
};
var sums = new List<long>();
long sum = 0;
for (int i = 1; i < N; i++) {
sum = sum + A[i];
sums.Add(sum);
}
sum = sum % mod;
sum = sum * A[0];
sum = sum % mod;
for (int left = 0; left < N - 2; left++) {
sum += A[left + 1] * ((sums[N - 2] - sums[left]) % mod);
sum = sum % mod;
}
Console.WriteLine(sum);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 109], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 0, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 287, 0, 196, 0, 1, 0, 35], ["+", 0, 287, 0, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46]]
| 8
| 236
| 29
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QuestionC {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] aStrings = Console.ReadLine().Split(' ');
List<double> aList = new List<double>();
foreach (string aString in aStrings) {
aList.Add(double.Parse(aString));
}
double[] a = aList.ToArray();
double aTotal = 0;
foreach (int num in a) {
aTotal = aTotal + num;
}
double sum = 0;
for (int firstIndex = 0; firstIndex < n - 1; firstIndex++) {
aTotal = aTotal - a[firstIndex];
sum = (sum + a[firstIndex] * aTotal) % (Math.Pow(10, 9) + 7);
}
Console.WriteLine(sum);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QuestionC {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] aStrings = Console.ReadLine().Split(' ');
List<decimal> aList = new List<decimal>();
foreach (string aString in aStrings) {
aList.Add(decimal.Parse(aString));
}
decimal[] a = aList.ToArray();
decimal aTotal = 0;
foreach (int num in a) {
aTotal = aTotal + num;
}
decimal sum = 0;
for (int firstIndex = 0; firstIndex < n - 1; firstIndex++) {
aTotal = aTotal - a[firstIndex];
sum = (sum + a[firstIndex] * aTotal) % (decimal)(Math.Pow(10, 9) + 7);
}
Console.WriteLine(sum);
}
}
}
|
[["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 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, 16, 12, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 25]]
| 8
| 209
| 15
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder177 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] A =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
long wa = 0;
long[] was = new long[N];
long ans = 0;
foreach (long a in A) {
wa += a;
}
wa -= A[0];
long mod = 1000000007;
for (long i = 0; i < N - 1; i++) {
if (i == 0) {
was[i] = wa % mod;
continue;
}
was[i] = (was[i - 1] - A[i]) % mod;
}
for (long i = 0; i < N - 1; i++) {
ans += (A[i] * was[i]) % mod;
ans %= mod;
}
Console.WriteLine(ans % mod);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder177 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] A =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
long wa = 0;
long[] was = new long[N];
long ans = 0;
foreach (long a in A) {
wa += a;
}
long mod = 1000000007;
for (long i = 0; i < N - 1; i++) {
if (i == 0) {
wa -= A[0];
was[i] = wa % mod;
continue;
}
wa -= A[i];
was[i] = wa % mod;
}
for (long i = 0; i < N - 1; i++) {
ans += (A[i] * was[i]) % mod;
ans %= mod;
}
Console.WriteLine(ans % mod);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["-", 12, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["-", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22]]
| 8
| 245
| 31
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder177 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] A =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
long sum = 0;
foreach (long a in A) {
sum += a;
}
long mod = 1000000007;
long ans = 0;
for (long i = 0; i < N - 1; i++) {
sum -= A[i];
ans += (A[i] * sum) % mod;
}
Console.WriteLine(ans % mod);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder177 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] A =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
long sum = 0;
foreach (long a in A) {
sum += a;
}
long mod = 1000000007;
long ans = 0;
for (long i = 0; i < N - 1; i++) {
sum -= A[i];
ans += (A[i] * (sum % mod));
ans %= mod;
}
Console.WriteLine(ans % mod);
}
}
}
|
[["+", 0, 11, 12, 23, 0, 16, 12, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 23, 0, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132]]
| 8
| 169
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class ABC177C {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
int[] a = new int[n];
long mod = 1000000007;
for (int i = 0; i < n; i++) {
a[i] = int.Parse(str[i]);
}
long ans = 0;
long sum = 0;
for (int i = 1; i < n; i++) {
sum += a[i] % mod;
}
for (int i = 1; i < n; i++) {
ans += (a[i - 1] % mod) * (sum % mod);
sum -= a[i];
if (sum < 0) {
sum += mod;
}
}
ans = ans % mod;
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
class ABC177C {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
long[] a = new long[n];
long mod = 1000000007;
for (int i = 0; i < n; i++) {
a[i] = long.Parse(str[i]);
}
long ans = 0;
long sum = 0;
for (int i = 1; i < n; i++) {
sum += a[i];
sum = sum % mod;
}
for (int i = 1; i < n; i++) {
ans += (a[i - 1] % mod) * (sum % mod);
sum -= a[i];
if (sum < 0) {
sum += mod;
}
ans = ans % mod;
}
ans = ans % mod;
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 227
| 20
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public void Run() {
var n = ni();
var a = nl(n);
var mod = 1000000007;
long ans = 1L * a.Sum() % mod * a.Sum() % mod;
foreach (var x in a) {
ans -= 1L * x * x;
ans %= mod;
}
ans *= (mod + 1) / 2;
ans %= mod;
if (ans < 0)
ans += mod;
cout.WriteLine(ans);
}
}
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public void Run() {
var n = ni();
var a = nl(n);
var mod = 1000000007;
long ans = a.Sum() % mod;
ans *= ans;
ans %= mod;
foreach (var x in a) {
ans -= 1L * x * x;
ans %= mod;
}
ans *= (mod + 1) / 2;
ans %= mod;
if (ans < 0)
ans += mod;
cout.WriteLine(ans);
}
}
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 31, 203], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132]]
| 8
| 1,354
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder177 {
class Program {
static void Main(string[] args) { QC(); }
static void QA() {
string[] splited = Console.ReadLine().Split(' ');
int D = int.Parse(splited[0]);
int T = int.Parse(splited[1]);
int S = int.Parse(splited[2]);
Console.WriteLine((((double)D / S) <= T) ? "Yes" : "No");
}
static void QB() {
string S = Console.ReadLine();
string T = Console.ReadLine();
int cntNotMatchMin = 1001;
for (int i = 0; i < S.Length - T.Length + 1; i++) {
int cntNotMatch = 0;
for (int j = 0; j < T.Length; j++) {
if (!S[i + j].Equals(T[j]))
cntNotMatch++;
}
if (cntNotMatch < cntNotMatchMin)
cntNotMatchMin = cntNotMatch;
}
Console.WriteLine(cntNotMatchMin);
}
static void QC() {
Console.ReadLine(); // 読み捨て
string[] splited = Console.ReadLine().Split(' ');
long sum = 0;
long befSum = 0;
for (int i = 1; i < splited.Length; i++) {
befSum = (befSum + long.Parse(splited[i])) % 1000000007;
}
for (int i = 0; i < splited.Length - 1; i++) {
if (i != 0)
befSum -= long.Parse(splited[i]);
sum = (sum + (long.Parse(splited[i]) * befSum)) % 1000000007;
}
Console.WriteLine(sum);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder177 {
class Program {
static void Main(string[] args) { QC(); }
static void QA() {
string[] splited = Console.ReadLine().Split(' ');
int D = int.Parse(splited[0]);
int T = int.Parse(splited[1]);
int S = int.Parse(splited[2]);
Console.WriteLine((((double)D / S) <= T) ? "Yes" : "No");
}
static void QB() {
string S = Console.ReadLine();
string T = Console.ReadLine();
int cntNotMatchMin = 1001;
for (int i = 0; i < S.Length - T.Length + 1; i++) {
int cntNotMatch = 0;
for (int j = 0; j < T.Length; j++) {
if (!S[i + j].Equals(T[j]))
cntNotMatch++;
}
if (cntNotMatch < cntNotMatchMin)
cntNotMatchMin = cntNotMatch;
}
Console.WriteLine(cntNotMatchMin);
}
static void QC() {
Console.ReadLine(); // 読み捨て
string[] splited = Console.ReadLine().Split(' ');
long sum = 0;
long befSum = 0;
for (int i = 1; i < splited.Length; i++) {
befSum = (befSum + long.Parse(splited[i])) % 1000000007;
}
for (int i = 0; i < splited.Length - 1; i++) {
if (i != 0)
befSum -= long.Parse(splited[i]);
if (befSum < 0)
befSum += 1000000007;
sum = (sum + (long.Parse(splited[i]) * befSum)) % 1000000007;
}
Console.WriteLine(sum);
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 412
| 10
|
using System;
using System.Linq;
namespace AtCoderTutorial {
public class AtCoder176 {
public static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] AN =
Console.ReadLine().Split(' ').Select(_ => long.Parse(_)).ToArray();
long modNum = (long)Math.Pow(10, 9) + 7;
long result = 0;
long ANtotal = 0;
for (int i = 0; i < N; i++) {
ANtotal = (ANtotal + AN[i]) % modNum;
}
// Console.WriteLine($"init ANtotal = {ANtotal}");
for (int i = 0; i < N - 1; i++) {
// for (int j = i + 1; j < AN.Length; j++)
// {
ANtotal = ANtotal - (AN[i] % modNum);
// Console.WriteLine($"count={i} ANTotal={ANtotal}");
result += AN[i] * (ANtotal % modNum);
// Console.WriteLine($"result = {result}");
result = result % modNum;
// }
}
Console.WriteLine(result);
}
}
}
|
using System;
using System.Linq;
namespace AtCoderTutorial {
public class AtCoder176 {
public static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] AN =
Console.ReadLine().Split(' ').Select(_ => long.Parse(_)).ToArray();
long modNum = (long)Math.Pow(10, 9) + 7;
long result = 0;
long ANtotal = 0;
for (int i = 0; i < N; i++) {
ANtotal = (ANtotal + AN[i]) % modNum;
}
// Console.WriteLine($"init ANtotal = {ANtotal}");
for (int i = 0; i < N - 1; i++) {
// for (int j = i + 1; j < AN.Length; j++)
// {
ANtotal = ANtotal - (AN[i] % modNum);
if (ANtotal < 0) {
ANtotal += modNum;
}
// Console.WriteLine($"count={i} ANTotal={ANtotal}");
result += AN[i] * (ANtotal % modNum);
// Console.WriteLine($"result = {result}");
result = result % modNum;
// }
}
Console.WriteLine(result);
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 196
| 12
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Diagnostics.Tracing;
namespace Main {
class Program {
static void Main(string[] args) {
//ここから
// int n=ReadInt();
// string[] str = Console.ReadLine().Split(' ');
long n = ReadLong();
long[] a = ReadArray(n);
long waru = (long)Math.Pow(10, 9) + 7;
long sum = a.Sum();
long ans = 0;
for (long i = 0; i < n - 1; i++) {
sum -= a[i];
ans += a[i] * sum;
ans %= waru;
}
Cout(ans);
//ここまで
}
static void Cout(string s) {
Console.WriteLine(s);
return;
}
static void Cout(int n) {
Console.WriteLine(n);
return;
}
static void Cout(long n) {
Console.WriteLine(n);
return;
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static int[] ReadArray(int n) {
string[] str = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(str[i]);
}
return a;
}
static long[] ReadArray(long n) {
string[] str = Console.ReadLine().Split(' ');
long[] a = new long[n];
for (long i = 0; i < n; i++) {
a[i] = long.Parse(str[i]);
}
return a;
}
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int Min(int a, int b) {
if (a < b)
return a;
return b;
}
static int Max(int a, int b) {
if (a > b)
return a;
return b;
}
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Diagnostics.Tracing;
namespace Main {
class Program {
static void Main(string[] args) {
//ここから
// int n=ReadInt();
// string[] str = Console.ReadLine().Split(' ');
long n = ReadLong();
long[] a = ReadArray(n);
long waru = (long)Math.Pow(10, 9) + 7;
long sum = a.Sum();
long ans = 0;
for (long i = 0; i < n - 1; i++) {
sum -= a[i];
if (sum > waru)
sum %= waru;
if (sum < 0)
sum += waru;
ans += a[i] * sum;
ans %= waru;
}
Cout(ans);
//ここまで
}
static void Cout(string s) {
Console.WriteLine(s);
return;
}
static void Cout(int n) {
Console.WriteLine(n);
return;
}
static void Cout(long n) {
Console.WriteLine(n);
return;
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static int[] ReadArray(int n) {
string[] str = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(str[i]);
}
return a;
}
static long[] ReadArray(long n) {
string[] str = Console.ReadLine().Split(' ');
long[] a = new long[n];
for (long i = 0; i < n; i++) {
a[i] = long.Parse(str[i]);
}
return a;
}
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int Min(int a, int b) {
if (a < b)
return a;
return b;
}
static int Max(int a, int b) {
if (a > b)
return a;
return b;
}
}
}
|
[["+", 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, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 132], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107]]
| 8
| 436
| 20
|
namespace AtCoder {
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
class Program {
static void Main() {
var MOD = 1000000007;
var N = int.Parse(System.Console.ReadLine());
var A = System.Console.ReadLine()
.Split(' ')
.Select((x) => long.Parse(x) % MOD)
.ToArray();
decimal sum = A.Sum() % MOD;
decimal ans = 0m;
for (int i = 0; i < N - 1; i++) {
ans += A[i] % MOD * ((sum - A[i]) % MOD);
ans = ans % MOD;
sum = (sum - A[i]) % MOD;
}
ans = ans % MOD;
Output(ans.ToString());
}
private static void Output(string str) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Console.WriteLine(str);
Console.Out.Flush();
}
}
static class Extentions {
#region 拡張メソッド(string)
public static string LeftB(this string stTarget, int iByteSize) {
return MidB(stTarget, 1, iByteSize);
}
public static string MidB(this string stTarget, int iStart) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, iStart - 1, bBytes.Length - iStart + 1);
}
public static string MidB(this string stTarget, int iStart, int iByteSize) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, iStart - 1, iByteSize);
}
public static string RightB(this string stTarget, int iByteSize) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, bBytes.Length - iByteSize, iByteSize);
}
public static bool IsNullOrEmpty(this string str) {
return string.IsNullOrEmpty(str);
}
/// <summary>
/// カルチャに依存した比較、または大文字と小文字を区別しない比較などの序数による比較を指定できる
/// Contains。
/// </summary>
/// <param name="value">対象文字列</param>
/// <param name="partialValue">部分文字列</param>
/// <param
/// name="comparison">カルチャ、大文字と小文字の区別、および並べ替え規則を指定する
/// StringComparison</param> <returns>一致する場合に true
/// を返します。</returns>
public static bool Contains(this string value, string partialValue,
StringComparison comparison = 0) {
return value.IndexOf(partialValue, comparison) >= 0;
}
public static bool IsNumeric(this string value) {
return decimal.TryParse(value, out decimal d);
}
public static int ToInt32(this String number, int retValue = 0) {
if (!number.IsNumeric())
return retValue;
return int.Parse(number);
}
#endregion
}
}
/*
static void Main()
{
var input = System.Console.ReadLine().ToArray();
var a = input[0];
var b = input[1];
var c = input[2];
var rain = 0;
if (a == 'R') rain++;
if (b == 'R') rain++;
if (c == 'R') rain++;
if (rain > 0 && b != 'R') rain--;
Output(rain.ToString());
}
*/
/*
using System;
using System.Collections.Generic;
using System.Linq;
// 整数の入力========================================
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(Console.ReadLine());
//配列操作========================================
var a = System.Console.ReadLine().Split(' ').Select((x) =>
long.Parse(x)).ToArray();
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = int.Parse(input2[i]);
}
Array.Sort(a);
Array.Reverse(a);
// 最小公倍数========================================
public static decimal Lcm(decimal a, decimal b)
{
return a * b / Gcd(a, b);
}
// ユークリッドの互除法 ========================================
public static decimal Gcd(decimal a, decimal b)
{
if (a < b)
{
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
}
while (b != 0)
{
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
//出力========================================
Console.WriteLine("");
var sb = new StringBuilder();
for (int j = 0; j<n; j++)
{
sb.AppendLine(a[j].ToString());
}
var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false
}; Console.SetOut(sw); Console.WriteLine(sb.ToString()); Console.Out.Flush();
*/
|
namespace AtCoder {
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
class Program {
static void Main() {
var MOD = 1000000007;
var N = int.Parse(System.Console.ReadLine());
var A = System.Console.ReadLine()
.Split(' ')
.Select((x) => long.Parse(x))
.ToArray();
decimal sum = A.Sum();
decimal ans = 0m;
for (int i = 0; i < N - 1; i++) {
ans += (A[i] * (sum - A[i])) % MOD;
ans = ans % MOD;
sum = sum - A[i];
}
ans = ans % MOD;
Output(ans.ToString());
}
private static void Output(string str) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Console.WriteLine(str);
Console.Out.Flush();
}
}
static class Extentions {
#region 拡張メソッド(string)
public static string LeftB(this string stTarget, int iByteSize) {
return MidB(stTarget, 1, iByteSize);
}
public static string MidB(this string stTarget, int iStart) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, iStart - 1, bBytes.Length - iStart + 1);
}
public static string MidB(this string stTarget, int iStart, int iByteSize) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, iStart - 1, iByteSize);
}
public static string RightB(this string stTarget, int iByteSize) {
System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8");
byte[] bBytes = hEncoding.GetBytes(stTarget);
return hEncoding.GetString(bBytes, bBytes.Length - iByteSize, iByteSize);
}
public static bool IsNullOrEmpty(this string str) {
return string.IsNullOrEmpty(str);
}
/// <summary>
/// カルチャに依存した比較、または大文字と小文字を区別しない比較などの序数による比較を指定できる
/// Contains。
/// </summary>
/// <param name="value">対象文字列</param>
/// <param name="partialValue">部分文字列</param>
/// <param
/// name="comparison">カルチャ、大文字と小文字の区別、および並べ替え規則を指定する
/// StringComparison</param> <returns>一致する場合に true
/// を返します。</returns>
public static bool Contains(this string value, string partialValue,
StringComparison comparison = 0) {
return value.IndexOf(partialValue, comparison) >= 0;
}
public static bool IsNumeric(this string value) {
return decimal.TryParse(value, out decimal d);
}
public static int ToInt32(this String number, int retValue = 0) {
if (!number.IsNumeric())
return retValue;
return int.Parse(number);
}
#endregion
}
}
/*
static void Main()
{
var input = System.Console.ReadLine().ToArray();
var a = input[0];
var b = input[1];
var c = input[2];
var rain = 0;
if (a == 'R') rain++;
if (b == 'R') rain++;
if (c == 'R') rain++;
if (rain > 0 && b != 'R') rain--;
Output(rain.ToString());
}
*/
/*
using System;
using System.Collections.Generic;
using System.Linq;
// 整数の入力========================================
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(Console.ReadLine());
//配列操作========================================
var a = System.Console.ReadLine().Split(' ').Select((x) =>
long.Parse(x)).ToArray();
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = int.Parse(input2[i]);
}
Array.Sort(a);
Array.Reverse(a);
// 最小公倍数========================================
public static decimal Lcm(decimal a, decimal b)
{
return a * b / Gcd(a, b);
}
// ユークリッドの互除法 ========================================
public static decimal Gcd(decimal a, decimal b)
{
if (a < b)
{
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
}
while (b != 0)
{
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
//出力========================================
Console.WriteLine("");
var sb = new StringBuilder();
for (int j = 0; j<n; j++)
{
sb.AppendLine(a[j].ToString());
}
var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false
}; Console.SetOut(sw); Console.WriteLine(sb.ToString()); Console.Out.Flush();
*/
|
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 109], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 109], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 592
| 14
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace ABC177 {
using static Ex;
public class Solve {
public static void Main(string[] args) { new ABC_C(); }
}
public class ABC_A {
public ABC_A() {
var (d, t, s) = ReadLongArray().ToTpl3();
var b = (s * t >= d);
b.YesNo();
}
}
public class ABC_B {
public ABC_B() {
var s = Read;
var t = Read;
var sl = s.Length;
var tl = t.Length;
int min = int.MaxValue;
for (int i = 0; i < sl; i++) {
if (i + tl > sl)
continue;
int cnt = 0;
for (int j = 0; j < tl; j++) {
if (s[i + j] != t[j])
cnt++;
}
Mins(ref min, cnt);
}
min.Cw();
}
}
public class ABC_C {
long mod = (long)1e9 + 7;
public ABC_C() {
int n = ReadInt;
var a = ReadLongArray();
long ans = 0;
long all = 0;
for (int j = 0; j < n; j++) {
long t = a[j];
t %= mod;
all += t;
all %= mod;
}
all += mod;
for (int i = 0; i < n - 1; i++) {
all -= a[i];
long t = all;
t %= mod;
t *= a[i];
t %= mod;
ans += t;
ans %= mod;
}
ans.Cw();
}
}
public static class Ex {
public static void Cw(this object s) { Console.WriteLine(s); }
public static bool Mins<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
public static bool Maxs<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
public static void Swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
public static void Swap<T>(List<T> list, int i, int j) {
T tmp = list[j];
list[j] = list[i];
list[i] = tmp;
}
public static long Lcm(int x, int y) { return x / Gcd(x, y) * y; }
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }
public static string Read {
get { return Console.ReadLine().Trim(); }
}
public static int ReadInt {
get { return int.Parse(Read); }
}
public static long ReadLong {
get { return long.Parse(Read); }
}
public static double ReadDouble {
get { return double.Parse(Read); }
}
public static string[] ReadArray() { return Read.Split(' '); }
public static int[] ReadIntArray() {
return Read.Split(' ').Select(int.Parse).ToArray();
}
public static long[] ReadLongArray() {
return Read.Split(' ').Select(long.Parse).ToArray();
}
public static string[] ReadArray(long N) {
var v = new string[N];
for (long i = 0; i < N; ++i)
v[i] = Read;
return v;
}
public static int[] ReadIntArray(long N) {
var v = new int[N];
for (long i = 0; i < N; ++i)
v[i] = ReadInt;
return v;
}
public static long[] ReadLongArray(long N) {
var v = new long[N];
for (long i = 0; i < N; ++i)
v[i] = ReadLong;
return v;
}
public static (T, T) ToTpl2<T>(this T[] v) { return (v[0], v[1]); }
public static (T, T, T) ToTpl3<T>(this T[] v) { return (v[0], v[1], v[2]); }
public static (T, T, T, T) ToTpl4<T>(this T[] v) {
return (v[0], v[1], v[2], v[3]);
}
public static (T, T, T, T, T) ToTpl5<T>(this T[] v) {
return (v[0], v[1], v[2], v[3], v[4]);
}
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace ABC177 {
using static Ex;
public class Solve {
public static void Main(string[] args) { new ABC_C(); }
}
public class ABC_A {
public ABC_A() {
var (d, t, s) = ReadLongArray().ToTpl3();
var b = (s * t >= d);
b.YesNo();
}
}
public class ABC_B {
public ABC_B() {
var s = Read;
var t = Read;
var sl = s.Length;
var tl = t.Length;
int min = int.MaxValue;
for (int i = 0; i < sl; i++) {
if (i + tl > sl)
continue;
int cnt = 0;
for (int j = 0; j < tl; j++) {
if (s[i + j] != t[j])
cnt++;
}
Mins(ref min, cnt);
}
min.Cw();
}
}
public class ABC_C {
long mod = (long)1e9 + 7;
public ABC_C() {
int n = ReadInt;
var a = ReadLongArray();
long ans = 0;
long all = 0;
for (int j = 0; j < n; j++) {
long t = a[j];
t %= mod;
all += t;
all %= mod;
}
for (int i = 0; i < n - 1; i++) {
all -= a[i];
if (all < 0)
all += mod;
long t = all;
t %= mod;
t *= a[i];
t %= mod;
ans += t;
ans %= mod;
}
ans.Cw();
}
}
public static class Ex {
public static void Cw(this object s) { Console.WriteLine(s); }
public static bool Mins<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
public static bool Maxs<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
public static void Swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
public static void Swap<T>(List<T> list, int i, int j) {
T tmp = list[j];
list[j] = list[i];
list[i] = tmp;
}
public static long Lcm(int x, int y) { return x / Gcd(x, y) * y; }
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }
public static string Read {
get { return Console.ReadLine().Trim(); }
}
public static int ReadInt {
get { return int.Parse(Read); }
}
public static long ReadLong {
get { return long.Parse(Read); }
}
public static double ReadDouble {
get { return double.Parse(Read); }
}
public static string[] ReadArray() { return Read.Split(' '); }
public static int[] ReadIntArray() {
return Read.Split(' ').Select(int.Parse).ToArray();
}
public static long[] ReadLongArray() {
return Read.Split(' ').Select(long.Parse).ToArray();
}
public static string[] ReadArray(long N) {
var v = new string[N];
for (long i = 0; i < N; ++i)
v[i] = Read;
return v;
}
public static int[] ReadIntArray(long N) {
var v = new int[N];
for (long i = 0; i < N; ++i)
v[i] = ReadInt;
return v;
}
public static long[] ReadLongArray(long N) {
var v = new long[N];
for (long i = 0; i < N; ++i)
v[i] = ReadLong;
return v;
}
public static (T, T) ToTpl2<T>(this T[] v) { return (v[0], v[1]); }
public static (T, T, T) ToTpl3<T>(this T[] v) { return (v[0], v[1], v[2]); }
public static (T, T, T, T) ToTpl4<T>(this T[] v) {
return (v[0], v[1], v[2], v[3]);
}
public static (T, T, T, T, T) ToTpl5<T>(this T[] v) {
return (v[0], v[1], v[2], v[3], v[4]);
}
}
}
|
[["-", 0, 263, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 263, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22]]
| 8
| 1,186
| 14
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
public static (long m, long s)[,] dp;
public static long mod;
static void Main(string[] args) {
checked {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var N = vals[0];
// var T = vals[1];
// var S = vals[2];
var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
mod = (long)1e9 + 7;
long ans = 0;
var sumA = new long[N + 1];
for (int i = 0; i < N; i++) {
sumA[i + 1] = (A[i] + sumA[i]) % mod;
}
for (int i = 0; i < N; i++) {
ans = (ans + (A[i] * (sumA[N] - sumA[i + 1])) % mod) % mod;
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
public static (long m, long s)[,] dp;
public static long mod;
static void Main(string[] args) {
checked {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var N = vals[0];
// var T = vals[1];
// var S = vals[2];
var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
mod = (long)1e9 + 7;
long ans = 0;
var sumA = new long[N + 1];
for (int i = 0; i < N; i++) {
sumA[i + 1] = (A[i] + sumA[i]) % mod;
}
for (int i = 0; i < N; i++) {
ans = (ans + (A[i] * ((sumA[N] - sumA[i + 1]) % mod)) % mod) % mod;
}
Console.WriteLine((ans + mod) % mod);
Console.Out.Flush();
}
}
}
}
|
[["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 31, 23, 0, 16, 12, 16, 31, 23, 0, 25], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 293
| 10
|
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;
class Program {
// Main
static void Main(string[] args) {
//読み込む
int N = int.Parse(Console.ReadLine());
long[] An =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long mod = 1000000007;
//累積和を計算
long[] accum = new long[N];
accum[0] = An[0] % mod;
for (int i = 1; i < N; i++) {
accum[i] = accum[i - 1] + (An[i] % mod);
accum[i] %= mod;
}
long ans = 0;
//順に計算
for (int i = 0; i < N; i++) {
long right = (accum[N - 1] - accum[i]) % mod;
long prod = (An[i] % mod) * right;
ans += (prod % mod);
ans %= mod;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;
class Program {
// Main
static void Main(string[] args) {
//読み込む
int N = int.Parse(Console.ReadLine());
long[] An =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long mod = 1000000007;
//累積和を計算
long[] accum = new long[N];
accum[0] = An[0] % mod;
for (int i = 1; i < N; i++) {
accum[i] = accum[i - 1] + (An[i] % mod);
accum[i] %= mod;
}
long ans = 0;
//順に計算
for (int i = 0; i < N; i++) {
long right = (accum[N - 1] - accum[i]) % mod;
long prod = (An[i] % mod) * right;
ans += (prod % mod);
ans %= mod;
}
if (ans < 0) {
ans += mod;
}
Console.WriteLine(ans);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 256
| 12
|
using System;
using System.Linq;
namespace C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var MOD = 1000000007L;
var sum = A.Sum();
sum %= MOD;
var result = 0L;
for (int i = 0; i < N - 1; i++) {
sum -= A[i];
result += A[i] * sum;
result %= MOD;
}
Console.WriteLine(result);
}
}
}
|
using System;
using System.Linq;
namespace C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var MOD = 1000000007L;
var sum = A.Sum();
sum %= MOD;
var result = 0L;
for (int i = 0; i < N - 1; i++) {
sum -= A[i];
if (sum < 0)
sum += MOD;
result += A[i] * sum;
result %= MOD;
}
Console.WriteLine(result);
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 134
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC177C {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] Ainput = Console.ReadLine().Split(' ');
long[] A = new long[N];
long sum = 0;
long mod = 1000000007;
for (int i = 0; i < N; i++) {
A[i] = long.Parse(Ainput[i]);
sum += A[i];
sum %= mod;
}
long[] wa = new long[N];
for (int i = 0; i < N; i++) {
wa[i] = sum + mod - A[i];
wa[i] %= mod;
}
long ans = 0;
for (int i = 0; i < N; i++) {
ans += A[i] * wa[i];
ans %= mod;
}
Console.WriteLine(ans / 2);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC177C {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] Ainput = Console.ReadLine().Split(' ');
long[] A = new long[N];
long sum = 0;
long mod = 1000000007;
for (int i = 0; i < N; i++) {
A[i] = long.Parse(Ainput[i]);
sum += A[i];
sum %= mod;
}
long[] wa = new long[N];
for (int i = 0; i < N; i++) {
wa[i] = sum + mod - A[i];
wa[i] %= mod;
}
long ans = 0;
for (int i = 0; i < N; i++) {
ans += A[i] * wa[i];
ans %= mod;
}
if (ans % 2 == 0) {
Console.WriteLine(ans / 2);
} else {
Console.WriteLine((ans + mod) / 2);
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 235
| 26
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
//出力の都度更新をやめる
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Ans();
//更新する
Console.Out.Flush();
}
public static void Ans() {
var inputArray = retreiveLongArray();
var inputCount = 1;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
long N = inputArray[0];
var Aarray = retreiveLongArray();
var total = Aarray.Sum();
long sum = 0;
for (int i = 0; i < N; i++) {
var a = Aarray[i];
sum += a * (total - a);
sum %= _mod * 2;
}
//答えの出力
var ans = sum / 2;
Console.WriteLine(ans);
}
private static long _mod = 1000000000 + 7;
/// <summary>
/// スペースで区切られた文字列配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// スペースで区切られた整数配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
/// <summary>
/// 2組みずつの入力データ(数値)からTuppleListを作成する
/// </summary>
/// <param name="N"></param>
/// <returns></returns>
private static List<Tuple<long, long>> createLongTuppleList(long N) {
var inpList = new List<Tuple<long, long>>();
for (int i = 0; i < N; i++) {
var inp = retreiveLongArray();
var item1 = inp[0];
var item2 = inp[1];
inpList.Add(new Tuple<long, long>(item1, item2));
}
return inpList;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder2 {
class Program {
static void Main(string[] args) {
//出力の都度更新をやめる
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Ans();
//更新する
Console.Out.Flush();
}
public static void Ans() {
var inputArray = retreiveLongArray();
var inputCount = 1;
// 不正な入力は処理しない
if (inputArray.Length != inputCount) {
Console.WriteLine("invalid input");
return;
}
long N = inputArray[0];
var Aarray = retreiveLongArray();
checked {
var total = Aarray.Sum();
long sum = 0;
for (int i = 0; i < N; i++) {
var a = Aarray[i];
var kakeru = (total - a) % (_mod * 2);
sum += a * kakeru;
sum %= (_mod * 2);
}
//答えの出力
var ans = sum / 2;
Console.WriteLine(ans);
}
}
private static long _mod = 1000000000 + 7;
/// <summary>
/// スペースで区切られた文字列配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static string[] retreiveStringArray() {
var inputArray = Console.ReadLine().Split(' ');
return inputArray;
}
/// <summary>
/// スペースで区切られた整数配列の入力を受け取る
/// </summary>
/// <returns></returns>
private static long[] retreiveLongArray() {
var inputArray = Console.ReadLine().Split(' ');
var longArray = inputArray.Select(s => long.Parse(s));
return longArray.ToArray();
}
/// <summary>
/// 2組みずつの入力データ(数値)からTuppleListを作成する
/// </summary>
/// <param name="N"></param>
/// <returns></returns>
private static List<Tuple<long, long>> createLongTuppleList(long N) {
var inpList = new List<Tuple<long, long>>();
for (int i = 0; i < N; i++) {
var inp = retreiveLongArray();
var item1 = inp[0];
var item2 = inp[1];
inpList.Add(new Tuple<long, long>(item1, item2));
}
return inpList;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 48], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46]]
| 8
| 416
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
long[] aa = sc.LongArray();
ModInt answer = new ModInt(0);
long[] sums = new long[n];
sums[0] = aa[0];
for (int i = 1; i < n; i++) {
sums[i] = aa[i] + sums[i - 1];
}
for (int i = 1; i < n; i++) {
answer += new ModInt(sums[i - 1]) * new ModInt(aa[i]);
}
Console.WriteLine(answer);
}
// ModInt
class ModInt {
public const long Mod = (int)1e9 + 7;
public long num;
public ModInt(long n) { num = n; }
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
long[] aa = sc.LongArray();
ModInt answer = new ModInt(0);
ModInt[] sums = new ModInt[n];
sums[0] = aa[0];
for (int i = 1; i < n; i++) {
sums[i] = aa[i] + sums[i - 1];
}
for (int i = 1; i < n; i++) {
answer += sums[i - 1] * (new ModInt(aa[i]));
}
Console.WriteLine(answer);
}
// ModInt
class ModInt {
public const long Mod = (int)1e9 + 7;
public long num;
public ModInt(long n) { num = n; }
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 22], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 230, 0, 228], ["-", 0, 1, 0, 11, 12, 16, 31, 230, 39, 22], ["-", 0, 11, 12, 16, 31, 230, 3, 4, 0, 24], ["-", 0, 11, 12, 16, 31, 230, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 12, 16, 12, 23, 0, 230, 3, 4, 0, 25]]
| 8
| 759
| 10
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
class Program {
#region Reader
static string ReadStr => Console.ReadLine();
static string[] ReadStrs => Console.ReadLine().Split(' ');
static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
static int[] ReadInts => Console.ReadLine()
.Trim()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
static long[] ReadLongs => Console.ReadLine()
.Trim()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
#endregion
#region Method
const int mod = 1000000007;
public static int Mod(int a, int mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
public static long Mod(long a, long mod = mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
#endregion
static void Main() {
int N = ReadInt;
long[] As = ReadLongs;
long sum = As.Sum();
long ans = 0;
for (int i = 0; i < As.Length; i++) {
sum -= As[i];
ans += Mod(As[i] * sum);
ans = Mod(ans);
}
WriteLine(Mod(ans));
}
}
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
class Program {
#region Reader
static string ReadStr => Console.ReadLine();
static string[] ReadStrs => Console.ReadLine().Split(' ');
static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
static int[] ReadInts => Console.ReadLine()
.Trim()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
static long[] ReadLongs => Console.ReadLine()
.Trim()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
#endregion
#region Method
const int mod = 1000000007;
public static int Mod(int a, int mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
public static long Mod(long a, long mod = mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
#endregion
static void Main() {
int N = ReadInt;
long[] As = ReadLongs;
long sum = Mod(As.Sum());
long ans = 0;
for (int i = 0; i < As.Length; i++) {
sum -= As[i];
sum = Mod(sum);
ans += Mod(As[i] * sum);
ans = Mod(ans);
}
WriteLine(Mod(ans));
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
| 8
| 339
| 10
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace AtCoder {
class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
var n = int.Parse(ReadLine());
var line =
ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
var sums = new long[line.Length + 1];
for (var i = 0; i < line.Length; i++) {
sums[i + 1] = (sums[i] + line[i]) % mod;
}
long sum = 0;
for (var i = 0; i < line.Length - 1; i++) {
sum += line[i] * (sums.Last() - sums[i + 1]);
sum %= mod;
}
WriteLine(sum);
}
}
}
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace AtCoder {
class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
var n = int.Parse(ReadLine());
var line =
ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
var sums = new long[line.Length + 1];
for (var i = 0; i < line.Length; i++) {
sums[i + 1] = (sums[i] + line[i]) % mod;
}
long sum = 0;
for (var i = 0; i < line.Length - 1; i++) {
var sub = sums.Last() - sums[i + 1];
if (sub < 0) {
sub += mod;
}
sum += line[i] * sub % mod;
sum %= mod;
}
WriteLine(sum);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 11, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 208
| 33
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ProgramingStudying2 {
class Program {
static void Main(string[] args) {
var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = nm[0];
var m = nm[1];
var G = new List<List<int>>();
for (int i = 0; i < n; i++) {
G.Add(new List<int>());
}
for (int i = 0; i < m; i++) {
var ab = Console.ReadLine().Split();
var a = int.Parse(ab[0]) - 1;
var b = int.Parse(ab[1]) - 1;
G[a].Add(b);
G[b].Add(a);
}
var ans = 0;
var visited = new bool[n];
var que = new Queue<int>();
for (int i = 0; i < n; i++) {
if (visited[i]) {
continue;
}
var count = 0;
que.Enqueue(i);
while (que.Any()) {
var x = que.Dequeue();
foreach (var nx in G[x]) {
if (visited[nx]) {
continue;
}
visited[nx] = true;
que.Enqueue(nx);
count++;
}
}
if (count > ans) {
ans = count;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ProgramingStudying2 {
class Program {
static void Main(string[] args) {
var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = nm[0];
var m = nm[1];
if (m == 0) {
Console.WriteLine(1);
return;
}
var G = new List<List<int>>();
for (int i = 0; i < n; i++) {
G.Add(new List<int>());
}
for (int i = 0; i < m; i++) {
var ab = Console.ReadLine().Split();
var a = int.Parse(ab[0]) - 1;
var b = int.Parse(ab[1]) - 1;
G[a].Add(b);
G[b].Add(a);
}
var ans = 0;
var visited = new bool[n];
var que = new Queue<int>();
for (int i = 0; i < n; i++) {
if (visited[i]) {
continue;
}
var count = 0;
que.Enqueue(i);
while (que.Any()) {
var x = que.Dequeue();
foreach (var nx in G[x]) {
if (visited[nx]) {
continue;
}
visited[nx] = true;
que.Enqueue(nx);
count++;
}
}
if (count > ans) {
ans = count;
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 338
| 17
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
class Program {
static void Main(string[] args) {
var inp = arrInt();
int n = inp[0];
int m = inp[1];
var fMap = mapInt(m);
UnionFind uni = new UnionFind(n);
foreach (var p in fMap)
uni.unite(p[0] - 1, p[1] - 1);
int max = 0;
for (int i = 0; i < n; i++)
max = Math.Max(max, uni.size[i]);
Console.WriteLine(max);
}
//入力受け取り用
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(); }
static List<int[]> mapInt(int h) {
List<int[]> mapInt = new List<int[]>();
for (int i = 0; i < h; i++) {
mapInt.Add(arrInt());
}
return mapInt;
}
static List<string[]> mapStr(int h) {
List<string[]> mapStr = new List<string[]>();
for (int i = 0; i < h; i++) {
mapStr.Add(arrStr());
}
return mapStr;
}
static List<char[]> mapChar(int h) {
List<char[]> mapChar = new List<char[]>();
for (int i = 0; i < h; i++) {
string s = crS();
mapChar.Add(s.ToCharArray());
}
return mapChar;
}
static List<char[]> mapCharCopy(List<char[]> map) {
List<char[]> copyMap = new List<char[]>();
foreach (var arr in map) {
List<char> list = new List<char>();
foreach (var ele in arr) {
list.Add(ele);
}
copyMap.Add(list.ToArray());
}
return copyMap;
}
}
class UnionFind {
int n;
int[] par;
int[] rank;
public int[] size;
public UnionFind(int n) {
this.n = n;
par = new int[n];
rank = new int[n];
size = new int[n];
// n要素で初期化
for (int i = 0; i < n; i++) {
par[i] = i;
rank[i] = 0;
size[i] = 1;
}
}
//木の根を求める
public int find(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
// xとyの属する集合を併合
public void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[x] = y;
} else {
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
size[x]++;
size[y]++;
}
// xとyが同じ集合に属するか否か
public bool same(int x, int y) { return find(x) == find(y); }
}
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
class Program {
static void Main(string[] args) {
var inp = arrInt();
int n = inp[0];
int m = inp[1];
var fMap = mapInt(m);
UnionFind uni = new UnionFind(n);
foreach (var p in fMap)
uni.unite(p[0] - 1, p[1] - 1);
int max = 0;
for (int i = 0; i < n; i++)
max = Math.Max(max, uni.size(i));
Console.WriteLine(max);
}
//入力受け取り用
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(); }
static List<int[]> mapInt(int h) {
List<int[]> mapInt = new List<int[]>();
for (int i = 0; i < h; i++) {
mapInt.Add(arrInt());
}
return mapInt;
}
static List<string[]> mapStr(int h) {
List<string[]> mapStr = new List<string[]>();
for (int i = 0; i < h; i++) {
mapStr.Add(arrStr());
}
return mapStr;
}
static List<char[]> mapChar(int h) {
List<char[]> mapChar = new List<char[]>();
for (int i = 0; i < h; i++) {
string s = crS();
mapChar.Add(s.ToCharArray());
}
return mapChar;
}
static List<char[]> mapCharCopy(List<char[]> map) {
List<char[]> copyMap = new List<char[]>();
foreach (var arr in map) {
List<char> list = new List<char>();
foreach (var ele in arr) {
list.Add(ele);
}
copyMap.Add(list.ToArray());
}
return copyMap;
}
}
class UnionFind {
int n;
int[] par;
int[] rank;
int[] sizeArr;
public UnionFind(int n) {
this.n = n;
par = new int[n];
rank = new int[n];
sizeArr = new int[n];
// n要素で初期化
for (int i = 0; i < n; i++) {
par[i] = i;
rank[i] = 0;
sizeArr[i] = 1;
}
}
//木の根を求める
public int find(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
// xとyの属する集合を併合
public void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[x] = y;
} else {
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
int tmp = sizeArr[x];
sizeArr[x] += sizeArr[y];
sizeArr[y] += tmp;
}
// xとyが同じ集合に属するか否か
public bool same(int x, int y) { return find(x) == find(y); }
public int size(int x) { return sizeArr[x]; }
}
|
[["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 8, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 259], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 263, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 263, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 8, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 37, 0, 204, 205, 22], ["+", 8, 196, 0, 37, 0, 204, 206, 207, 0, 70], ["+", 0, 37, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 196, 0, 37, 0, 204, 206, 207, 0, 73]]
| 8
| 830
| 47
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp3 {
internal class Class2 {
private static void Main(string[] args) {
try {
var nm = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
var n = nm[0];
var m = nm[1];
var lookup = Hoge(m).Distinct().ToLookup(x => x.Item1, x => x.Item2);
var list = new HashSet<HashSet<long>>();
var list2 = new HashSet<long>();
foreach (var tomo in lookup.Select(x => x.Key)) {
if (list2.Contains(tomo)) {
continue;
}
var newSet = new HashSet<long>();
list.Add(newSet);
Ho(list2, list, lookup, newSet, tomo);
}
Console.WriteLine(list.Max(x => x.Count));
} catch {
Console.WriteLine("?");
}
}
private static void Ho(HashSet<long> list2, HashSet<HashSet<long>> list,
ILookup<long, long> lookup,
HashSet<long> currentHashSet, long tomo) {
if (list2.Contains(tomo)) {
return;
}
currentHashSet.Add(tomo);
list2.Add(tomo);
foreach (var nextTomo in lookup[tomo].Where(x => !list2.Contains(x))) {
Ho(list2, list, lookup, currentHashSet, nextTomo);
}
}
private static IReadOnlyList<(long, long)> Hoge(int m) {
return Enumerable.Range(0, m)
.SelectMany(_ => {
var ab = Console.ReadLine().Split(" ").Select(long.Parse).ToArray();
var a = ab[0];
var b = ab[1];
return new List<(long, long)> {
(a, b),
(b, a),
};
})
.ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp3 {
internal class Class2 {
private static void Main(string[] args) {
var nm = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
var n = nm[0];
var m = nm[1];
var lookup = Hoge(m).Distinct().ToLookup(x => x.Item1, x => x.Item2);
var list = new HashSet<HashSet<long>>();
var list2 = new HashSet<long>();
foreach (var tomo in lookup.Select(x => x.Key)) {
if (list2.Contains(tomo)) {
continue;
}
var newSet = new HashSet<long>();
list.Add(newSet);
Ho(list2, list, lookup, newSet, tomo);
}
try {
Console.WriteLine(
list.Select(x => x.LongCount()).DefaultIfEmpty(1).Max());
} catch {
Console.WriteLine("?");
}
}
private static void Ho(HashSet<long> list2, HashSet<HashSet<long>> list,
ILookup<long, long> lookup,
HashSet<long> currentHashSet, long tomo) {
if (list2.Contains(tomo)) {
return;
}
currentHashSet.Add(tomo);
list2.Add(tomo);
foreach (var nextTomo in lookup[tomo].Where(x => !list2.Contains(x))) {
Ho(list2, list, lookup, currentHashSet, nextTomo);
}
}
private static IReadOnlyList<(long, long)> Hoge(int m) {
return Enumerable.Range(0, m)
.SelectMany(_ => {
var ab = Console.ReadLine().Split(" ").Select(long.Parse).ToArray();
var a = ab[0];
var b = ab[1];
return new List<(long, long)> {
(a, b),
(b, a),
};
})
.ToArray();
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 246, 0, 247], ["-", 0, 195, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 201, 0, 195, 8, 196, 0, 246, 0, 247], ["+", 0, 195, 8, 196, 0, 246, 8, 196, 0, 45], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 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]]
| 8
| 435
| 19
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace AtCoder {
class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
// var n = int.Parse(ReadLine());
var line =
ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
var n = line[0];
var m = line[1];
var parents = new int[n];
for (var i = 0; i < n; i++) {
parents[i] = i;
}
for (var i = 0; i < m; i++) {
var edge =
ReadLine().Split(' ').Select(value => int.Parse(value) - 1).ToArray();
var parent = edge.Min();
var child = edge.Max();
Unite(parents, child, parent);
}
var dic = new Dictionary<int, int>();
foreach (var parent in parents) {
if (!dic.ContainsKey(parent)) {
dic.Add(parent, 0);
}
dic[parent]++;
}
WriteLine(dic.Values.Max());
}
private static int Root(int[] parents, int x) {
if (parents[x] == x) {
return x;
}
return parents[x] = Root(parents, parents[x]);
}
private static void Unite(int[] parents, int x, int y) {
var rootX = Root(parents, x);
var rootY = Root(parents, y);
if (rootX == rootY) {
return;
}
parents[rootX] = rootY;
}
}
}
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace AtCoder {
class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
// var n = int.Parse(ReadLine());
var line =
ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
var n = line[0];
var m = line[1];
var parents = new int[n];
for (var i = 0; i < n; i++) {
parents[i] = i;
}
for (var i = 0; i < m; i++) {
var edge =
ReadLine().Split(' ').Select(value => int.Parse(value) - 1).ToArray();
var parent = edge.Min();
var child = edge.Max();
Unite(parents, child, parent);
}
for (var i = 0; i < n; i++) {
Root(parents, i);
}
var dic = new Dictionary<int, int>();
foreach (var parent in parents) {
if (!dic.ContainsKey(parent)) {
dic.Add(parent, 0);
}
dic[parent]++;
}
WriteLine(dic.Values.Max());
}
private static int Root(int[] parents, int x) {
if (parents[x] == x) {
return x;
}
return parents[x] = Root(parents, parents[x]);
}
private static void Unite(int[] parents, int x, int y) {
var rootX = Root(parents, x);
var rootY = Root(parents, y);
if (rootX == rootY) {
return;
}
parents[rootX] = rootY;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217]]
| 8
| 372
| 23
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
using static Atcoder.IO;
namespace Atcoder {
class Program {
static StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
static void Main(string[] args) {
try {
SetOut(sw);
Solve.Answer();
Out.Flush();
} catch (Exception ex) {
WriteLine(ex.ToString());
Out.Flush();
}
}
}
public class Solve {
public static void Answer() {
int N = RInt;
var A = RSInt;
var C = new int[A.Max() + 10];
for (int i = 0; i < N; i++) {
C[A[i]]++;
}
bool pairwise = true;
int Const = 1000005;
for (int i = 2; i < Const; i++) {
int cnt = 0;
for (int j = i; j < Const; j += i) {
cnt += C[j];
}
if (cnt > 1)
pairwise = false;
}
if (pairwise) {
WriteLine("pairwise coprime");
return;
}
int gcd = A[0];
for (int i = 1; i < N; i++) {
gcd = GCD(gcd, A[i]);
}
if (gcd == 1) {
WriteLine("setwise coprime");
} else {
WriteLine("not coprime");
}
}
public static int GCD(int x, int y) {
if (x < y)
Swap(ref x, ref y);
if (y == 0)
return x;
else
return GCD(x % y, y);
}
public static void Swap(ref int x, ref int y) {
int tmp = x;
x = y;
y = tmp;
}
public static long GCD(long x, long y) {
if (x < y)
Swap(ref x, ref y);
if (y == 0)
return x;
else
return GCD(x % y, y);
}
public static void Swap(ref long x, ref long y) {
long tmp = x;
x = y;
y = tmp;
}
public static long Choice2(long n) {
#region
if (n <= 1)
return 0;
if (n == 2)
return 1;
else
return n * (n - 1) / 2;
#endregion
}
}
public class IO {
#region Input
public static int RInt => int.Parse(ReadLine());
public static long RLong => long.Parse(ReadLine());
public static double RDouble => double.Parse(ReadLine());
public static string[] RSString => ReadLine().Split();
public static int[] RSInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToArray();
public static long[] RSLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToArray();
public static double[] RSDouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToArray();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES"
: "NO");
#endregion
}
public class Mod {
#region
private readonly static long M = 1000000007;
public static long Add(long a, long b) => (a + b) % M;
public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M
: (a - b) % M + M;
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
using static Atcoder.IO;
namespace Atcoder {
class Program {
static StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
static void Main(string[] args) {
try {
SetOut(sw);
Solve.Answer();
Out.Flush();
} catch (Exception ex) {
WriteLine(ex.ToString());
Out.Flush();
}
}
}
public class Solve {
public static void Answer() {
int Const = 1000005;
int N = RInt;
var A = RSInt;
var C = new int[Const + 10];
for (int i = 0; i < N; i++) {
C[A[i]]++;
}
bool pairwise = true;
for (int i = 2; i < Const; i++) {
int cnt = 0;
for (int j = i; j < Const; j += i) {
cnt += C[j];
}
if (cnt > 1)
pairwise = false;
}
if (pairwise) {
WriteLine("pairwise coprime");
return;
}
int gcd = A[0];
for (int i = 1; i < N; i++) {
gcd = GCD(gcd, A[i]);
}
if (gcd == 1) {
WriteLine("setwise coprime");
} else {
WriteLine("not coprime");
}
}
public static int GCD(int x, int y) {
if (x < y)
Swap(ref x, ref y);
if (y == 0)
return x;
else
return GCD(x % y, y);
}
public static void Swap(ref int x, ref int y) {
int tmp = x;
x = y;
y = tmp;
}
public static long GCD(long x, long y) {
if (x < y)
Swap(ref x, ref y);
if (y == 0)
return x;
else
return GCD(x % y, y);
}
public static void Swap(ref long x, ref long y) {
long tmp = x;
x = y;
y = tmp;
}
public static long Choice2(long n) {
#region
if (n <= 1)
return 0;
if (n == 2)
return 1;
else
return n * (n - 1) / 2;
#endregion
}
}
public class IO {
#region Input
public static int RInt => int.Parse(ReadLine());
public static long RLong => long.Parse(ReadLine());
public static double RDouble => double.Parse(ReadLine());
public static string[] RSString => ReadLine().Split();
public static int[] RSInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToArray();
public static long[] RSLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToArray();
public static double[] RSDouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToArray();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES"
: "NO");
#endregion
}
public class Mod {
#region
private readonly static long M = 1000000007;
public static long Add(long a, long b) => (a + b) % M;
public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M
: (a - b) % M + M;
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 225, 226, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 225, 226, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 225, 226, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 225, 226, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 225, 226, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 863
| 16
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace AtCoder
{
public class Program
{
static void Main()
{
var cin = new Scanner();
int n = cin.Int();
var a = cin.ArrayLong(n);
long max = a.Max();
var primes = Eratosthenes(max);
var distinct = new HashSet<long>();
bool isDistinct = true;
for (int i = 0; i < n; i++) {
var p = new HashSet<long>();
long aa = a[i];
while (primes[aa] != 0) {
p.Add(primes[aa]);
aa /= primes[aa];
}
p.Add(aa);
if (i == 0) {
foreach (var pp in p) {
distinct.Add(pp);
}
} else {
if (isDistinct) {
foreach (long pp in p) {
if (distinct.Contains(pp) == false) {
distinct.Add(pp);
} else {
isDistinct = false;
}
}
}
}
}
long gcd = GCD(a);
if (isDistinct) {
Console.WriteLine("pairwise coprime");
} else if (gcd == 1) {
Console.WriteLine("setwise coprime");
} else {
Console.WriteLine("not coprime");
}
}
public static long[] Eratosthenes(long n)
{
var primes = new long[n + 1];
for (long i = 2; i <= n; i++) {
if (primes[i] == 0) {
for (long j = i + i; j <= n; j += i) {
if (primes[j] == 0) {
primes[j] = i;
}
}
}
}
return primes;
}
public static long GCD(long a, long b)
{
if (b == 0) {
return a;
}
return GCD(b, a % b);
}
public static long GCD(long[] values)
{
if (values.Length == 1) {
return values[0];
}
long gcd = values[0];
for (int i = 1; i < values.Length; ++i) {
if (gcd == 1) {
return gcd;
}
gcd = GCD(values[i], gcd);
}
return gcd;
}
}
public class UnionFindTree
{
private readonly int[] sizes_;
private readonly int[] parents_;
public int Count { get; private set; }
public int GroupCount { get; private set; }
public UnionFindTree(int count)
{
parents_ = new int[count];
sizes_ = new int[count];
Count = 0;
GroupCount = count;
while (Count < count) {
parents_[Count] = Count;
sizes_[Count] = 1;
++Count;
}
}
public int GetSizeOf(int x) => sizes_[Find(x)];
public bool IsUnited(int x, int y) => Find(x) == Find(y);
public bool Unite(int x, int y)
{
x = Find(x);
y = Find(y);
if (y == x) {
return false;
}
int parent = sizes_[x] < sizes_[y] ? y : x;
int child = sizes_[x] < sizes_[y] ? x : y;
--GroupCount;
parents_[child] = parent;
sizes_[parent] += sizes_[child];
return true;
}
public int Find(int x)
{
while (x != parents_[x]) {
parents_[x] = parents_[parents_[x]];
x = parents_[x];
}
return x;
}
public IEnumerable<int> GetAllRoots => parents_.Where(x => x == parents_[x]);
}
public class HashMap<TKey, TValue> : Dictionary<TKey, TValue>
{
private readonly Func<TKey, TValue> initialzier_;
public HashMap(Func<TKey, TValue> initialzier)
: base()
{
initialzier_ = initialzier;
}
public HashMap(Func<TKey, TValue> initialzier, int capacity)
: base(capacity)
{
initialzier_ = initialzier;
}
new public TValue this[TKey key]
{
get
{
if (ContainsKey(key) == false) {
base[key] = initialzier_(key);
}
return base[key];
}
set { base[key] = value; }
}
}
public struct ModInt
{
public const long P = 1000000007;
//public const long P = 998244353;
public static ModInt Inverse(ModInt value) => Pow(value, P - 2);
public static ModInt Pow(ModInt value, long k) => Pow(value.value_, k);
public static ModInt Pow(long value, long k)
{
long ret = 1;
for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) {
if ((k & 1) == 1) {
ret = ret * value % P;
}
}
return new ModInt(ret);
}
private long value_;
public ModInt(long value)
=> value_ = value;
public ModInt(long value, bool mods)
{
if (mods) {
value %= P;
if (value < 0) {
value += P;
}
}
value_ = value;
}
public static ModInt operator +(ModInt lhs, ModInt rhs)
{
lhs.value_ = (lhs.value_ + rhs.value_) % P;
return lhs;
}
public static ModInt operator +(long lhs, ModInt rhs)
{
rhs.value_ = (lhs + rhs.value_) % P;
return rhs;
}
public static ModInt operator +(ModInt lhs, long rhs)
{
lhs.value_ = (lhs.value_ + rhs) % P;
return lhs;
}
public static ModInt operator -(ModInt lhs, ModInt rhs)
{
lhs.value_ = (P + lhs.value_ - rhs.value_) % P;
return lhs;
}
public static ModInt operator -(long lhs, ModInt rhs)
{
rhs.value_ = (P + lhs - rhs.value_) % P;
return rhs;
}
public static ModInt operator -(ModInt lhs, long rhs)
{
lhs.value_ = (P + lhs.value_ - rhs) % P;
return lhs;
}
public static ModInt operator *(ModInt lhs, ModInt rhs)
{
lhs.value_ = lhs.value_ * rhs.value_ % P;
return lhs;
}
public static ModInt operator *(long lhs, ModInt rhs)
{
rhs.value_ = lhs * rhs.value_ % P;
return rhs;
}
public static ModInt operator *(ModInt lhs, long rhs)
{
lhs.value_ = lhs.value_ * rhs % P;
return lhs;
}
public static ModInt operator /(ModInt lhs, ModInt rhs)
{
long exp = P - 2;
while (exp > 0) {
if (exp % 2 > 0) {
lhs *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return lhs;
}
public static implicit operator ModInt(long n) => new ModInt(n, true);
public long ToLong() => value_;
public override string ToString() => value_.ToString();
}
public static class Helper
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T>
=> target = target.CompareTo(value) > 0 ? value : target;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T>
{
if (target.CompareTo(value) > 0) {
target = value;
onUpdated(value);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T>
=> target = target.CompareTo(value) < 0 ? value : target;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T>
{
if (target.CompareTo(value) < 0) {
target = value;
onUpdated(value);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Array<T>(int n, Func<int, T> init)
=> Enumerable.Range(0, n).Select(x => init(x)).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<T> List<T>(int n, Func<int, T> init)
=> Enumerable.Range(0, n).Select(x => init(x)).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[,] Array2<T>(int n, int m, T init)
where T : struct
{
var array = new T[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
array[i, j] = init;
}
}
return array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer)
{
var array = new T[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
array[i, j] = initializer(i, j);
}
}
return array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[,,] Array3<T>(int n1, int n2, int n3, T init)
where T : struct
{
var array = new T[n1, n2, n3];
for (int i1 = 0; i1 < n1; i1++) {
for (int i2 = 0; i2 < n2; i2++) {
for (int i3 = 0; i3 < n3; i3++) {
array[i1, i2, i3] = init;
}
}
}
return array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[,,,] Array4<T>(int n1, int n2, int n3, int n4, T init)
where T : struct
{
var array = new T[n1, n2, n3, n4];
for (int i1 = 0; i1 < n1; i1++) {
for (int i2 = 0; i2 < n2; i2++) {
for (int i3 = 0; i3 < n3; i3++) {
for (int i4 = 0; i4 < n4; i4++) {
array[i1, i2, i3, i4] = init;
}
}
}
}
return array;
}
private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action)
{
for (int dn = 0; dn < 4; dn++) {
int d4i = i + delta4_[dn];
int d4j = j + delta4_[dn + 1];
if ((uint)d4i < (uint)imax && (uint)d4j < (uint)jmax) {
action(d4i, d4j);
}
}
}
private static readonly int[] delta8_ = { 1, 0, -1, 0, 1, 1, -1, -1, 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DoAt8(int i, int j, int imax, int jmax, Action<int, int> action)
{
for (int dn = 0; dn < 8; dn++) {
int d8i = i + delta8_[dn];
int d8j = j + delta8_[dn + 1];
if ((uint)d8i < (uint)imax && (uint)d8j < (uint)jmax) {
action(d8i, d8j);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ForEachSubBit(int bit, Action<int> action)
{
for (int sub = bit; sub >= 0; sub--) {
sub &= bit;
action(sub);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Reverse(string src)
{
var chars = src.ToCharArray();
for (int i = 0, j = chars.Length - 1; i < j; i++, j--) {
var tmp = chars[i];
chars[i] = chars[j];
chars[j] = tmp;
}
return new string(chars);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Join<T>(this IEnumerable<T> values, string separator = "")
=> string.Join(separator, values);
}
public class Scanner
{
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private readonly Func<string> reader_;
private string[] buf_;
private int index_;
public Scanner(string file = "")
{
if (string.IsNullOrWhiteSpace(file)) {
reader_ = Console.ReadLine;
} else {
filePath_ = file;
var fs = new StreamReader(file);
reader_ = fs.ReadLine;
}
buf_ = new string[0];
index_ = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public string NextLine() => reader_();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public string Next()
{
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = reader_();
while (st == "") {
st = reader_();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Int() => int.Parse(Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Int(int offset) => int.Parse(Next()) + offset;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (int, int) Int2(int offset = 0)
=> (Int(offset), Int(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (int, int, int) Int3(int offset = 0)
=> (Int(offset), Int(offset), Int(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (int, int, int, int) Int4(int offset = 0)
=> (Int(offset), Int(offset), Int(offset), Int(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int[] ArrayInt(int length, int offset = 0)
{
int[] Array = new int[length];
for (int i = 0; i < length; i++) {
Array[i] = Int(offset);
}
return Array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Long() => long.Parse(Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Long(long offset) => long.Parse(Next()) + offset;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (long, long) Long2(long offset = 0)
=> (Long(offset), Long(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (long, long, long) Long3(long offset = 0)
=> (Long(offset), Long(offset), Long(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (long, long, long, long) Long4(long offset = 0)
=> (Long(offset), Long(offset), Long(offset), Long(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long[] ArrayLong(int length, long offset = 0)
{
long[] Array = new long[length];
for (int i = 0; i < length; i++) {
Array[i] = Long(offset);
}
return Array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double Double() => double.Parse(Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double Double(double offset) => double.Parse(Next()) + offset;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (double, double) Double2(double offset = 0)
=> (Double(offset), Double(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (double, double, double) Double3(double offset = 0)
=> (Double(offset), Double(offset), Double(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (double, double, double, double) Double4(double offset = 0)
=> (Double(offset), Double(offset), Double(offset), Double(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double[] ArrayDouble(int length, double offset = 0)
{
double[] Array = new double[length];
for (int i = 0; i < length; i++) {
Array[i] = Double(offset);
}
return Array;
}
public void Save(string text)
{
if (string.IsNullOrWhiteSpace(filePath_)) {
return;
}
File.WriteAllText(filePath_ + "_output.txt", text);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace AtCoder
{
public class Program
{
static void Main()
{
var cin = new Scanner();
int n = cin.Int();
var a = cin.ArrayLong(n);
long max = a.Max();
var primes = Eratosthenes(max);
var distinct = new HashSet<long>();
bool isDistinct = true;
for (int i = 0; i < n; i++) {
var p = new HashSet<long>();
long aa = a[i];
while (primes[aa] != 0) {
p.Add(primes[aa]);
aa /= primes[aa];
}
p.Add(aa);
if (i == 0) {
foreach (var pp in p) {
distinct.Add(pp);
}
} else {
if (isDistinct) {
foreach (long pp in p) {
if (pp == 1) {
continue;
}
if (distinct.Contains(pp) == false) {
distinct.Add(pp);
} else {
isDistinct = false;
}
}
}
}
}
long gcd = GCD(a);
if (isDistinct) {
Console.WriteLine("pairwise coprime");
} else if (gcd == 1) {
Console.WriteLine("setwise coprime");
} else {
Console.WriteLine("not coprime");
}
}
public static long[] Eratosthenes(long n)
{
var primes = new long[n + 1];
for (long i = 2; i <= n; i++) {
if (primes[i] == 0) {
for (long j = i + i; j <= n; j += i) {
if (primes[j] == 0) {
primes[j] = i;
}
}
}
}
return primes;
}
public static long GCD(long a, long b)
{
if (b == 0) {
return a;
}
return GCD(b, a % b);
}
public static long GCD(long[] values)
{
if (values.Length == 1) {
return values[0];
}
long gcd = values[0];
for (int i = 1; i < values.Length; ++i) {
if (gcd == 1) {
return gcd;
}
gcd = GCD(values[i], gcd);
}
return gcd;
}
}
public class UnionFindTree
{
private readonly int[] sizes_;
private readonly int[] parents_;
public int Count { get; private set; }
public int GroupCount { get; private set; }
public UnionFindTree(int count)
{
parents_ = new int[count];
sizes_ = new int[count];
Count = 0;
GroupCount = count;
while (Count < count) {
parents_[Count] = Count;
sizes_[Count] = 1;
++Count;
}
}
public int GetSizeOf(int x) => sizes_[Find(x)];
public bool IsUnited(int x, int y) => Find(x) == Find(y);
public bool Unite(int x, int y)
{
x = Find(x);
y = Find(y);
if (y == x) {
return false;
}
int parent = sizes_[x] < sizes_[y] ? y : x;
int child = sizes_[x] < sizes_[y] ? x : y;
--GroupCount;
parents_[child] = parent;
sizes_[parent] += sizes_[child];
return true;
}
public int Find(int x)
{
while (x != parents_[x]) {
parents_[x] = parents_[parents_[x]];
x = parents_[x];
}
return x;
}
public IEnumerable<int> GetAllRoots => parents_.Where(x => x == parents_[x]);
}
public class HashMap<TKey, TValue> : Dictionary<TKey, TValue>
{
private readonly Func<TKey, TValue> initialzier_;
public HashMap(Func<TKey, TValue> initialzier)
: base()
{
initialzier_ = initialzier;
}
public HashMap(Func<TKey, TValue> initialzier, int capacity)
: base(capacity)
{
initialzier_ = initialzier;
}
new public TValue this[TKey key]
{
get
{
if (ContainsKey(key) == false) {
base[key] = initialzier_(key);
}
return base[key];
}
set { base[key] = value; }
}
}
public struct ModInt
{
public const long P = 1000000007;
//public const long P = 998244353;
public static ModInt Inverse(ModInt value) => Pow(value, P - 2);
public static ModInt Pow(ModInt value, long k) => Pow(value.value_, k);
public static ModInt Pow(long value, long k)
{
long ret = 1;
for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) {
if ((k & 1) == 1) {
ret = ret * value % P;
}
}
return new ModInt(ret);
}
private long value_;
public ModInt(long value)
=> value_ = value;
public ModInt(long value, bool mods)
{
if (mods) {
value %= P;
if (value < 0) {
value += P;
}
}
value_ = value;
}
public static ModInt operator +(ModInt lhs, ModInt rhs)
{
lhs.value_ = (lhs.value_ + rhs.value_) % P;
return lhs;
}
public static ModInt operator +(long lhs, ModInt rhs)
{
rhs.value_ = (lhs + rhs.value_) % P;
return rhs;
}
public static ModInt operator +(ModInt lhs, long rhs)
{
lhs.value_ = (lhs.value_ + rhs) % P;
return lhs;
}
public static ModInt operator -(ModInt lhs, ModInt rhs)
{
lhs.value_ = (P + lhs.value_ - rhs.value_) % P;
return lhs;
}
public static ModInt operator -(long lhs, ModInt rhs)
{
rhs.value_ = (P + lhs - rhs.value_) % P;
return rhs;
}
public static ModInt operator -(ModInt lhs, long rhs)
{
lhs.value_ = (P + lhs.value_ - rhs) % P;
return lhs;
}
public static ModInt operator *(ModInt lhs, ModInt rhs)
{
lhs.value_ = lhs.value_ * rhs.value_ % P;
return lhs;
}
public static ModInt operator *(long lhs, ModInt rhs)
{
rhs.value_ = lhs * rhs.value_ % P;
return rhs;
}
public static ModInt operator *(ModInt lhs, long rhs)
{
lhs.value_ = lhs.value_ * rhs % P;
return lhs;
}
public static ModInt operator /(ModInt lhs, ModInt rhs)
{
long exp = P - 2;
while (exp > 0) {
if (exp % 2 > 0) {
lhs *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return lhs;
}
public static implicit operator ModInt(long n) => new ModInt(n, true);
public long ToLong() => value_;
public override string ToString() => value_.ToString();
}
public static class Helper
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T>
=> target = target.CompareTo(value) > 0 ? value : target;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T>
{
if (target.CompareTo(value) > 0) {
target = value;
onUpdated(value);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T>
=> target = target.CompareTo(value) < 0 ? value : target;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T>
{
if (target.CompareTo(value) < 0) {
target = value;
onUpdated(value);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Array<T>(int n, Func<int, T> init)
=> Enumerable.Range(0, n).Select(x => init(x)).ToArray();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<T> List<T>(int n, Func<int, T> init)
=> Enumerable.Range(0, n).Select(x => init(x)).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[,] Array2<T>(int n, int m, T init)
where T : struct
{
var array = new T[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
array[i, j] = init;
}
}
return array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer)
{
var array = new T[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
array[i, j] = initializer(i, j);
}
}
return array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[,,] Array3<T>(int n1, int n2, int n3, T init)
where T : struct
{
var array = new T[n1, n2, n3];
for (int i1 = 0; i1 < n1; i1++) {
for (int i2 = 0; i2 < n2; i2++) {
for (int i3 = 0; i3 < n3; i3++) {
array[i1, i2, i3] = init;
}
}
}
return array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[,,,] Array4<T>(int n1, int n2, int n3, int n4, T init)
where T : struct
{
var array = new T[n1, n2, n3, n4];
for (int i1 = 0; i1 < n1; i1++) {
for (int i2 = 0; i2 < n2; i2++) {
for (int i3 = 0; i3 < n3; i3++) {
for (int i4 = 0; i4 < n4; i4++) {
array[i1, i2, i3, i4] = init;
}
}
}
}
return array;
}
private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action)
{
for (int dn = 0; dn < 4; dn++) {
int d4i = i + delta4_[dn];
int d4j = j + delta4_[dn + 1];
if ((uint)d4i < (uint)imax && (uint)d4j < (uint)jmax) {
action(d4i, d4j);
}
}
}
private static readonly int[] delta8_ = { 1, 0, -1, 0, 1, 1, -1, -1, 1 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DoAt8(int i, int j, int imax, int jmax, Action<int, int> action)
{
for (int dn = 0; dn < 8; dn++) {
int d8i = i + delta8_[dn];
int d8j = j + delta8_[dn + 1];
if ((uint)d8i < (uint)imax && (uint)d8j < (uint)jmax) {
action(d8i, d8j);
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ForEachSubBit(int bit, Action<int> action)
{
for (int sub = bit; sub >= 0; sub--) {
sub &= bit;
action(sub);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Reverse(string src)
{
var chars = src.ToCharArray();
for (int i = 0, j = chars.Length - 1; i < j; i++, j--) {
var tmp = chars[i];
chars[i] = chars[j];
chars[j] = tmp;
}
return new string(chars);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Join<T>(this IEnumerable<T> values, string separator = "")
=> string.Join(separator, values);
}
public class Scanner
{
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private readonly Func<string> reader_;
private string[] buf_;
private int index_;
public Scanner(string file = "")
{
if (string.IsNullOrWhiteSpace(file)) {
reader_ = Console.ReadLine;
} else {
filePath_ = file;
var fs = new StreamReader(file);
reader_ = fs.ReadLine;
}
buf_ = new string[0];
index_ = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public string NextLine() => reader_();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public string Next()
{
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = reader_();
while (st == "") {
st = reader_();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Int() => int.Parse(Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Int(int offset) => int.Parse(Next()) + offset;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (int, int) Int2(int offset = 0)
=> (Int(offset), Int(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (int, int, int) Int3(int offset = 0)
=> (Int(offset), Int(offset), Int(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (int, int, int, int) Int4(int offset = 0)
=> (Int(offset), Int(offset), Int(offset), Int(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int[] ArrayInt(int length, int offset = 0)
{
int[] Array = new int[length];
for (int i = 0; i < length; i++) {
Array[i] = Int(offset);
}
return Array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Long() => long.Parse(Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long Long(long offset) => long.Parse(Next()) + offset;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (long, long) Long2(long offset = 0)
=> (Long(offset), Long(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (long, long, long) Long3(long offset = 0)
=> (Long(offset), Long(offset), Long(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (long, long, long, long) Long4(long offset = 0)
=> (Long(offset), Long(offset), Long(offset), Long(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public long[] ArrayLong(int length, long offset = 0)
{
long[] Array = new long[length];
for (int i = 0; i < length; i++) {
Array[i] = Long(offset);
}
return Array;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double Double() => double.Parse(Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double Double(double offset) => double.Parse(Next()) + offset;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (double, double) Double2(double offset = 0)
=> (Double(offset), Double(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (double, double, double) Double3(double offset = 0)
=> (Double(offset), Double(offset), Double(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (double, double, double, double) Double4(double offset = 0)
=> (Double(offset), Double(offset), Double(offset), Double(offset));
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public double[] ArrayDouble(int length, double offset = 0)
{
double[] Array = new double[length];
for (int i = 0; i < length; i++) {
Array[i] = Double(offset);
}
return Array;
}
public void Save(string text)
{
if (string.IsNullOrWhiteSpace(filePath_)) {
return;
}
File.WriteAllText(filePath_ + "_output.txt", text);
}
}
}
|
[["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 64, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 210, 8, 196, 0, 57, 0, 24]]
| 8
| 3,671
| 10
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Tasks {
public class E {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var N = Scanner.Scan<int>();
var A = Scanner.ScanEnumerable<long>().ToArray();
var tmp = A[0];
for (var i = 1; i < N; i++) {
tmp = GCD(tmp, A[i]);
}
if (tmp != 1) {
Console.WriteLine("not coprime");
return;
}
var isPairwise = true;
var primes = new HashSet<long>();
for (var i = 0; i < N && isPairwise; i++) {
tmp = A[i];
if (primes.Contains(tmp)) {
isPairwise = false;
break;
}
var max = (long)Math.Sqrt(A[i]);
var p = 2;
while (p <= max) {
if (tmp % p == 0) {
if (primes.Contains(p))
isPairwise = false;
primes.Add(p);
while (tmp % p == 0) {
tmp /= p;
}
}
p++;
}
if (tmp > 1) {
primes.Add(tmp);
}
}
Console.WriteLine(isPairwise ? "pairwise coprime" : "setwise coprime");
}
static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
public static class Scanner {
private static Queue<string> queue = new Queue<string>();
public static T Next<T>() {
if (!queue.Any())
foreach (var item in Console.ReadLine().Trim().Split(" "))
queue.Enqueue(item);
return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
}
public static T Scan<T>() => Next<T>();
public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(),
Next<T3>());
public static (T1, T2, T3,
T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(),
Next<T3>(), Next<T4>());
public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() =>
(Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
public static IEnumerable<T>
ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(
x => (T)Convert.ChangeType(x, typeof(T)));
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Tasks {
public class E {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var N = Scanner.Scan<int>();
var A = Scanner.ScanEnumerable<long>().ToArray();
var tmp = A[0];
for (var i = 1; i < N; i++) {
tmp = GCD(tmp, A[i]);
}
if (tmp != 1) {
Console.WriteLine("not coprime");
return;
}
var isPairwise = true;
var primes = new HashSet<long>();
for (var i = 0; i < N && isPairwise; i++) {
tmp = A[i];
if (primes.Contains(tmp)) {
isPairwise = false;
break;
}
var max = (long)Math.Sqrt(A[i]);
var p = 2;
while (p <= max) {
if (tmp % p == 0) {
if (primes.Contains(p)) {
isPairwise = false;
break;
}
primes.Add(p);
while (tmp % p == 0) {
tmp /= p;
}
}
p++;
}
if (tmp > 1) {
if (primes.Contains(tmp)) {
isPairwise = false;
break;
}
primes.Add(tmp);
}
}
Console.WriteLine(isPairwise ? "pairwise coprime" : "setwise coprime");
}
static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);
public static class Scanner {
private static Queue<string> queue = new Queue<string>();
public static T Next<T>() {
if (!queue.Any())
foreach (var item in Console.ReadLine().Trim().Split(" "))
queue.Enqueue(item);
return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
}
public static T Scan<T>() => Next<T>();
public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(),
Next<T3>());
public static (T1, T2, T3,
T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(),
Next<T3>(), Next<T4>());
public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() =>
(Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
public static IEnumerable<T>
ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(
x => (T)Convert.ChangeType(x, typeof(T)));
}
}
}
|
[["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 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, 211, 0, 147], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 715
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace E {
class Program {
static List<int> min_factor = new List<int>();
static void Main(string[] args) {
var n = Int32.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(" ").Select(s => Int32.Parse(s)).ToList();
min_factor = new List<int>(1000001);
for (var i = 0; i <= 1000000; i++) {
min_factor.Add(i);
}
for (int i = 2; i * i <= 1000000; i++) {
if (min_factor[i] < i)
continue;
for (int j = i * i; j <= 1000000; j += i) {
if (min_factor[j] == j)
min_factor[j] = i;
}
}
var p = new List<List<int>>();
var values = new Dictionary<int, int>();
foreach (var val in a) {
p.Add(new List<int>());
var facts = PrimeFactors(val);
foreach (var hoge in facts.Distinct()) {
if (!values.ContainsKey(hoge))
values[hoge] = 0;
values[hoge]++;
p.Last().Add(hoge);
}
}
bool flag1 = true;
var f2 = true;
foreach (var v in values) {
if (v.Key == 1)
continue;
if (v.Value > 1) {
flag1 = false;
}
if (v.Value >= n) {
f2 = false;
}
}
if (flag1) {
Console.WriteLine("pairwise coprime");
return;
} else if (f2) {
Console.WriteLine("setwise coprime");
return;
}
Console.WriteLine("not coprime");
}
public static IEnumerable<int> PrimeFactors(int n) {
int tmp = n;
while (tmp > 1) {
yield return tmp;
tmp = tmp / min_factor[tmp];
}
yield return 1;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace E {
class Program {
static List<int> min_factor = new List<int>();
static void Main(string[] args) {
var n = Int32.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(" ").Select(s => Int32.Parse(s)).ToList();
min_factor = new List<int>();
for (var i = 0; i <= 1000000; i++) {
min_factor.Add(i);
}
for (int i = 2; i * i <= 1000000; i++) {
if (min_factor[i] < i)
continue;
for (int j = i * i; j <= 1000000; j += i) {
if (min_factor[j] == j)
min_factor[j] = i;
}
}
var p = new List<List<int>>();
var values = new Dictionary<int, int>();
foreach (var val in a) {
p.Add(new List<int>());
var facts = PrimeFactors(val);
foreach (var hoge in facts.Distinct()) {
if (!values.ContainsKey(hoge))
values[hoge] = 0;
values[hoge]++;
// p.Last().Add(hoge);
}
}
bool flag1 = true;
var f2 = true;
foreach (var v in values) {
if (v.Key == 1)
continue;
if (v.Value > 1) {
flag1 = false;
}
if (v.Value >= n) {
f2 = false;
}
}
if (flag1) {
Console.WriteLine("pairwise coprime");
return;
} else if (f2) {
Console.WriteLine("setwise coprime");
return;
}
Console.WriteLine("not coprime");
}
public static IEnumerable<int> PrimeFactors(int n) {
int tmp = n;
while (tmp > 1) {
yield return min_factor[tmp];
tmp = tmp / min_factor[tmp];
}
yield return 1;
}
}
}
|
[["-", 0, 11, 12, 230, 3, 4, 0, 28, 0, 203], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 285, 0, 204, 205, 22], ["+", 8, 196, 0, 285, 0, 204, 206, 207, 0, 70], ["+", 8, 196, 0, 285, 0, 204, 206, 207, 0, 73]]
| 8
| 441
| 15
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using N = System.Int64;
static class Program {
static public void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
}
public class Solver {
public void Solve() {
N n = rn;
var a = new List<N>();
for (int i = 0; i < n; i++) {
a.Add(rn);
}
N r = 0; // 0:pairwize 1:setwise 2:not
N m = a.Max();
if (Gcd(a.ToArray()) > 1) {
r = 2;
} else {
var prime = new List<N>();
var div = new N[m + 1];
if (n >= 2) {
prime.Add(2);
for (int i = 2; i <= m; i += 2) {
div[i] = 2;
}
}
for (N p = 3; p <= m; p += 2) {
if (div[p] == 0) {
prime.Add(p);
div[p] = p;
for (N q = p * p; q <= m; q += 2 * p) {
if (div[q] == 0) {
div[q] = p;
}
}
}
}
var flag = new N[m + 1];
for (int i = 0; i <= m; i++) {
flag[i] = -1;
}
for (int i = 0; i < n; i++) {
while (a[i] > 1) {
if (flag[div[a[i]]] > -1) {
r = 1;
break;
}
flag[div[a[i]]] = i;
a[i] /= div[a[i]];
}
if (r == 1)
break;
}
}
switch (r) {
case 0:
Write("pairwise coprime");
break;
case 1:
Write("setwise coprime");
break;
case 2:
Write("not coprime");
break;
}
}
N Gcd(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }
N rn {
get { return sc.Integer(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
void Write<T>(T t) { Console.WriteLine(t.ToString()); }
void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public N Integer() {
N ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public double Double() { return double.Parse(Scan()); }
}
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using N = System.Int64;
static class Program {
static public void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
}
public class Solver {
public void Solve() {
N n = rn;
var a = new List<N>();
for (int i = 0; i < n; i++) {
a.Add(rn);
}
N r = 0; // 0:pairwise 1:setwise 2:not
N m = a.Max();
if (Gcd(a.ToArray()) > 1) {
r = 2;
} else {
var prime = new List<N>();
var div = new N[m + 1];
if (n >= 2) {
prime.Add(2);
for (int i = 2; i <= m; i += 2) {
div[i] = 2;
}
}
for (N p = 3; p <= m; p += 2) {
if (div[p] == 0) {
prime.Add(p);
div[p] = p;
for (N q = p * p; q <= m; q += 2 * p) {
if (div[q] == 0) {
div[q] = p;
}
}
}
}
var flag = new N[m + 1];
for (int i = 0; i <= m; i++) {
flag[i] = -1;
}
for (int i = 0; i < n; i++) {
while (a[i] > 1) {
if (flag[div[a[i]]] > -1 && flag[div[a[i]]] < i) {
r = 1;
break;
}
flag[div[a[i]]] = i;
a[i] /= div[a[i]];
}
if (r == 1)
break;
}
}
switch (r) {
case 0:
Write("pairwise coprime");
break;
case 1:
Write("setwise coprime");
break;
case 2:
Write("not coprime");
break;
}
}
N Gcd(params N[] n) {
N p = n[0];
for (N i = 1; i < n.Length; i++) {
p = Gcd(p, n[i]);
}
return p;
}
N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }
N rn {
get { return sc.Integer(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
void Write<T>(T t) { Console.WriteLine(t.ToString()); }
void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public N Integer() {
N ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public double Double() { return double.Parse(Scan()); }
}
|
[["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 1,066
| 13
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC177.E(); }
class ABC177 {
public static void A() {
var D = Read.Long();
var T = Read.Long();
var S = Read.Long();
Console.WriteLine(S * T >= D ? "Yes" : "No");
}
public static void B() {
var S = Read.Str();
var T = Read.Str();
int min = S.Length;
for (int i = 0; i <= S.Length - T.Length; ++i) {
int count = 0;
for (int j = 0; j < T.Length; ++j) {
if (S[i + j] != T[j]) {
count++;
}
}
min = Math.Min(min, count);
}
Console.WriteLine(min);
}
public static void C() {
var N = Read.Int();
var A = Read.LongN();
var sum = new MOD(0);
var sum2 = new MOD(0);
foreach (var a in A) {
sum += a;
sum2 += new MOD(a * a);
}
Console.WriteLine((sum * sum - sum2) / 2);
}
public static void D() {
var N = Read.Int();
var M = Read.Int();
var AB = Read.TupleInt(M);
var uft = new Util.UnionFindTree(N);
foreach (var ab in AB) {
var A = ab.Item1 - 1;
var B = ab.Item2 - 1;
uft.Unite(A, B);
}
int max = 0;
for (int i = 0; i < N; ++i) {
max = Math.Max(max, uft.Count(i));
}
Console.WriteLine(max);
}
public static void E() {
var N = Read.Int();
var A = Read.LongN().Where(x => x > 1).ToArray();
N = A.Length;
var A2 = A.Distinct().ToArray();
var M = A2.Length;
if (N <= 1) {
Console.WriteLine("pairwise coprime");
return;
}
var gcd = A[0];
for (int i = 1; i < N; ++i) {
gcd = Util.GCD(gcd, A[i]);
}
throw new Exception();
if (gcd > 1) {
Console.WriteLine("not coprime");
return;
}
if (M > 300000 || N != M) {
Console.WriteLine("setwise coprime");
return;
}
var primes = Enumerable.Range(0, 1000001).Select(i => true).ToArray();
primes[0] = primes[1] = false;
for (int i = 2; i <= 1000; ++i) {
if (!primes[i]) {
continue;
}
for (int j = i * 2; j <= 1000000; j += i) {
primes[j] = false;
}
}
HashSet<long> primesX = new HashSet<long>();
for (int i = 2; i <= 1000; ++i) {
if (primes[i]) {
primesX.Add(i);
}
}
var dict = new Dictionary<long, int>();
foreach (var a in A2) {
foreach (var p in E_Primes(primesX, a)) {
if (!dict.ContainsKey(p)) {
dict.Add(p, 0);
}
dict[p]++;
}
}
bool isPair = true;
foreach (var kvp in dict) {
if (kvp.Value > 1) {
isPair = false;
}
}
Console.WriteLine(isPair ? "pairwise coprime" : "setwise coprime");
}
public static HashSet<long> E_Primes(HashSet<long> primes, long x) {
var hash = new HashSet<long>();
long y = x;
foreach (var p in primes) {
if (y % p == 0) {
hash.Add(p);
while (y % p == 0) {
y /= p;
}
}
if (y == 1) {
return hash;
}
}
if (y > 1 && !hash.Contains(y)) {
hash.Add(y);
}
return hash;
}
public static void F() {}
}
class Bound {
public static int Lowerbound<T1, T2>(SortedList<T1, T2> list, T1 x)
where T1 : IComparable<T1> { return Lowerbound(list.Keys, x); }
public static int Upperbound<T1, T2>(SortedList<T1, T2> list, T1 x)
where T1 : IComparable<T1> { return Upperbound(list.Keys, x); }
public static int Lowerbound<T>(IList<T> list, T x)
where T : IComparable<T> {
int min = 0;
int max = list.Count;
while (min < max) {
var mid = (min + max) / 2;
if (list[mid].CompareTo(x) >= 0) {
max = mid;
} else {
min = mid + 1;
}
}
return max;
}
public static int Upperbound<T>(IList<T> list, T x)
where T : IComparable<T> {
int min = 0;
int max = list.Count;
while (min < max) {
var mid = (min + max) / 2;
if (list[mid].CompareTo(x) > 0) {
max = mid;
} else {
min = mid + 1;
}
}
return max;
}
}
class Util {
public static T[,] Gen<T>(int r, int c, T v) {
var matrix = new T[r, c];
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
matrix[i, j] = v;
}
}
return matrix;
}
public static long[] ASum(long[] array) {
var res = new long[array.Length + 1];
for (int i = 0; i < array.Length; ++i) {
res[i + 1] = res[i] + array[i];
}
return res;
}
public static long[,] ASum(long[,] matrix) {
var N = matrix.GetLength(0);
var M = matrix.GetLength(1);
var res = new long[N + 1, M + 1];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
res[i + 1, j + 1] =
res[i, j + 1] + res[i + 1, j] - res[i, j] + matrix[i, j];
}
}
return res;
}
public static MyDict<T, long> Frequency2<T>(T[] array) {
var dict = new MyDict<T, long>();
foreach (var a in array) {
dict[a]++;
}
return dict;
}
public class MyDict<T1, T2> : Dictionary<T1, T2> {
public new T2 this[T1 key] {
get { if (!base.ContainsKey(key)) { base.Add(key, default(T2));
}
return base[key];
}
set { base[key] = value; }
}
}
public static bool IsPrime(long x) {
var fact = Factorize(x);
return fact.Count == 1 && fact.Values.ElementAt(0) == 1;
}
public static Dictionary<long, int> Factorize(long x) {
var dict = new Dictionary<long, int>();
long minp = 2;
while (x > 1) {
bool ok = false;
for (long p = minp; p * p <= x; ++p) {
if (x % p == 0) {
if (!dict.ContainsKey(p)) {
dict.Add(p, 0);
}
dict[p]++;
minp = p;
x /= p;
ok = true;
break;
}
}
if (!ok) {
if (!dict.ContainsKey(x)) {
dict.Add(x, 0);
}
dict[x]++;
break;
}
}
return dict;
}
public static long GCD(long a, long b) {
while (b > 0) {
var c = a % b;
a = b;
b = c;
}
return a;
}
public class BIT {
int N;
long[] array;
public BIT(int m) {
for (int n = 1;; n *= 2) {
if (n >= m) {
N = n;
array = new long[N + 1];
break;
}
}
}
public void Add(int idx, int v) {
for (int x = idx; x <= N; x += x & -x) {
array[x] += v;
}
}
public long Sum(int idx) {
long ret = 0;
for (int x = idx; x > 0; x -= x & -x) {
ret += array[x];
}
return ret;
}
}
public class UnionFindTree {
int[] parent;
int[] count;
public UnionFindTree(int n) {
parent = new int[n];
count = new int[n];
for (int i = 0; i < n; ++i) {
parent[i] = i;
count[i] = 1;
}
}
public int Root(int i) {
if (parent[i] == i) {
return i;
} else {
return parent[i] = Root(parent[i]);
}
}
public int Count(int i) { return count[Root(i)]; }
public bool Same(int i, int j) { return Root(i) == Root(j); }
public void Unite(int i, int j) {
var ri = Root(i);
var rj = Root(j);
if (ri != rj) {
parent[ri] = rj;
count[rj] += count[ri];
}
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private bool _isAsc = true;
private T[] _heap;
private int _sz = 0;
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
public PriorityQueue(int maxSize, bool isAsc = true) {
_heap = new T[maxSize];
_isAsc = isAsc;
}
private int Compare(T x, T y) {
if (_comparer != null) {
return _comparer.Compare(x, y);
}
return _isAsc ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
var i = _sz++;
while (i > 0) {
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0) {
break;
}
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0) {
a = b;
}
if (Compare(_heap[a], x) >= 0) {
break;
}
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _sz; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
}
public class MyTuple<T1, T2> : IComparable
where T1 : IComparable<T1> {
public readonly T1 Item1;
public readonly T2 Item2;
public MyTuple(T1 item1, T2 item2) {
Item1 = item1;
Item2 = item2;
}
public int CompareTo(object obj) {
return Item1.CompareTo(((MyTuple<T1, T2>)obj).Item1);
}
}
public static long[] Dijkstra(Dictionary<int, Dictionary<int, long>> adj, int N,
int M, int start) {
long INF = (long)1e18;
var dist = Enumerable.Range(0, N + 1).Select(i => INF).ToArray();
var queue = new PriorityQueue<MyTuple<long, int>>(N + M + 100);
dist[start] = 0;
queue.Push(new MyTuple<long, int>(0, start));
while (queue.Count() > 0) {
var kvp = queue.Pop();
var d = kvp.Item1;
var v = kvp.Item2;
if (dist[v] < d) {
continue;
}
foreach (var kvp2 in adj[v]) {
var newV = kvp2.Key;
var newD = dist[v] + kvp2.Value;
if (newD < dist[newV]) {
dist[newV] = newD;
queue.Push(new MyTuple<long, int>(newD, newV));
}
}
}
return dist;
}
}
struct MOD {
public static long P = 1000000007;
public readonly long V;
public MOD(long a) { this.V = a % P; }
public static implicit operator MOD(long a) { return new MOD(a); }
public static MOD operator +(MOD a, MOD b) {
return new MOD((a.V + b.V) % P);
}
public static MOD operator -(MOD a, MOD b) {
return new MOD((a.V - b.V + P) % P);
}
public static MOD operator *(MOD a, MOD b) {
return new MOD((a.V * b.V) % P);
}
public static MOD operator /(MOD a, MOD b) {
return new MOD((a.V * b.Inverse().V) % P);
}
public MOD Inverse() {
long a = V, p = P;
long b = p, c = 1, d = 0, e = 0, f = 0;
while (b != 0) {
e = a / b;
f = b;
b = a - e * b;
a = f;
f = d;
d = c - e * d;
c = f;
}
c %= p;
return c + (c < 0 ? p : 0);
}
public MOD Power(long n) {
long a = V, p = P;
long res = 1;
long mult = a;
for (int i = 0; i < 63; ++i) {
if ((n & ((long)1 << i)) > 0) {
res = (res * mult) % p;
}
mult = (mult * mult) % p;
}
return res;
}
public override string ToString() { return V.ToString(); }
}
static class Read {
static Queue<string> queue = new Queue<string>();
static void Enqueue() {
var ss = Console.ReadLine().Split(' ');
foreach (var s in ss) {
queue.Enqueue(s);
}
}
public static int Int() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt32(queue.Dequeue());
}
public static long Long() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt64(queue.Dequeue());
}
public static string Str() {
if (queue.Count == 0) {
Enqueue();
}
return queue.Dequeue();
}
public static int[] IntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
public static long[] LongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
public static ulong[] ULongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToUInt64(s))
.ToArray();
}
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = Read.IntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<long, long>[] TupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<string, string>[] TupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = Read.StrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<double, double>[] TupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
public static long[,] LongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = Read.LongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
public static Dictionary<int, HashSet<int>>
AdjacencyList(int N, int M, bool isDirectional = false) {
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new HashSet<int>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
if (!dict[ab[0]].Contains(ab[1])) {
dict[ab[0]].Add(ab[1]);
}
if (!isDirectional && !dict[ab[1]].Contains(ab[0])) {
dict[ab[1]].Add(ab[0]);
}
}
return dict;
}
public static Dictionary<int, Dictionary<int, long>>
AdjacencyListWithWeight(int N, int M, bool isDirectional = false) {
Dictionary<int, Dictionary<int, long>> dict =
new Dictionary<int, Dictionary<int, long>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new Dictionary<int, long>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1], ab[2]);
if (!isDirectional) {
dict[ab[1]].Add(ab[0], ab[2]);
}
}
return dict;
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC177.E(); }
class ABC177 {
public static void A() {
var D = Read.Long();
var T = Read.Long();
var S = Read.Long();
Console.WriteLine(S * T >= D ? "Yes" : "No");
}
public static void B() {
var S = Read.Str();
var T = Read.Str();
int min = S.Length;
for (int i = 0; i <= S.Length - T.Length; ++i) {
int count = 0;
for (int j = 0; j < T.Length; ++j) {
if (S[i + j] != T[j]) {
count++;
}
}
min = Math.Min(min, count);
}
Console.WriteLine(min);
}
public static void C() {
var N = Read.Int();
var A = Read.LongN();
var sum = new MOD(0);
var sum2 = new MOD(0);
foreach (var a in A) {
sum += a;
sum2 += new MOD(a * a);
}
Console.WriteLine((sum * sum - sum2) / 2);
}
public static void D() {
var N = Read.Int();
var M = Read.Int();
var AB = Read.TupleInt(M);
var uft = new Util.UnionFindTree(N);
foreach (var ab in AB) {
var A = ab.Item1 - 1;
var B = ab.Item2 - 1;
uft.Unite(A, B);
}
int max = 0;
for (int i = 0; i < N; ++i) {
max = Math.Max(max, uft.Count(i));
}
Console.WriteLine(max);
}
public static void E() {
var N = Read.Int();
var A = Read.LongN().Where(x => x > 1).ToArray();
var M = A.Length;
var A2 = A.Distinct().ToArray();
var K = A2.Length;
if (M <= 1) {
Console.WriteLine("pairwise coprime");
return;
}
var gcd = A[0];
for (int i = 1; i < M; ++i) {
gcd = Util.GCD(gcd, A[i]);
}
if (gcd > 1 && N == M) {
Console.WriteLine("not coprime");
return;
}
if (K > 300000 || M != K) {
Console.WriteLine("setwise coprime");
return;
}
var primes = Enumerable.Range(0, 1000001).Select(i => true).ToArray();
primes[0] = primes[1] = false;
for (int i = 2; i <= 1000; ++i) {
if (!primes[i]) {
continue;
}
for (int j = i * 2; j <= 1000000; j += i) {
primes[j] = false;
}
}
HashSet<long> primesX = new HashSet<long>();
for (int i = 2; i <= 1000; ++i) {
if (primes[i]) {
primesX.Add(i);
}
}
var dict = new Dictionary<long, int>();
foreach (var a in A2) {
foreach (var p in E_Primes(primesX, a)) {
if (!dict.ContainsKey(p)) {
dict.Add(p, 0);
}
dict[p]++;
}
}
bool isPair = true;
foreach (var kvp in dict) {
if (kvp.Value > 1) {
isPair = false;
}
}
Console.WriteLine(isPair ? "pairwise coprime" : "setwise coprime");
}
public static HashSet<long> E_Primes(HashSet<long> primes, long x) {
var hash = new HashSet<long>();
long y = x;
foreach (var p in primes) {
if (y % p == 0) {
hash.Add(p);
while (y % p == 0) {
y /= p;
}
}
if (y == 1) {
return hash;
}
}
if (y > 1 && !hash.Contains(y)) {
hash.Add(y);
}
return hash;
}
public static void F() {}
}
class Bound {
public static int Lowerbound<T1, T2>(SortedList<T1, T2> list, T1 x)
where T1 : IComparable<T1> { return Lowerbound(list.Keys, x); }
public static int Upperbound<T1, T2>(SortedList<T1, T2> list, T1 x)
where T1 : IComparable<T1> { return Upperbound(list.Keys, x); }
public static int Lowerbound<T>(IList<T> list, T x)
where T : IComparable<T> {
int min = 0;
int max = list.Count;
while (min < max) {
var mid = (min + max) / 2;
if (list[mid].CompareTo(x) >= 0) {
max = mid;
} else {
min = mid + 1;
}
}
return max;
}
public static int Upperbound<T>(IList<T> list, T x)
where T : IComparable<T> {
int min = 0;
int max = list.Count;
while (min < max) {
var mid = (min + max) / 2;
if (list[mid].CompareTo(x) > 0) {
max = mid;
} else {
min = mid + 1;
}
}
return max;
}
}
class Util {
public static T[,] Gen<T>(int r, int c, T v) {
var matrix = new T[r, c];
for (int i = 0; i < r; ++i) {
for (int j = 0; j < c; ++j) {
matrix[i, j] = v;
}
}
return matrix;
}
public static long[] ASum(long[] array) {
var res = new long[array.Length + 1];
for (int i = 0; i < array.Length; ++i) {
res[i + 1] = res[i] + array[i];
}
return res;
}
public static long[,] ASum(long[,] matrix) {
var N = matrix.GetLength(0);
var M = matrix.GetLength(1);
var res = new long[N + 1, M + 1];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
res[i + 1, j + 1] =
res[i, j + 1] + res[i + 1, j] - res[i, j] + matrix[i, j];
}
}
return res;
}
public static MyDict<T, long> Frequency2<T>(T[] array) {
var dict = new MyDict<T, long>();
foreach (var a in array) {
dict[a]++;
}
return dict;
}
public class MyDict<T1, T2> : Dictionary<T1, T2> {
public new T2 this[T1 key] {
get { if (!base.ContainsKey(key)) { base.Add(key, default(T2));
}
return base[key];
}
set { base[key] = value; }
}
}
public static bool IsPrime(long x) {
var fact = Factorize(x);
return fact.Count == 1 && fact.Values.ElementAt(0) == 1;
}
public static Dictionary<long, int> Factorize(long x) {
var dict = new Dictionary<long, int>();
long minp = 2;
while (x > 1) {
bool ok = false;
for (long p = minp; p * p <= x; ++p) {
if (x % p == 0) {
if (!dict.ContainsKey(p)) {
dict.Add(p, 0);
}
dict[p]++;
minp = p;
x /= p;
ok = true;
break;
}
}
if (!ok) {
if (!dict.ContainsKey(x)) {
dict.Add(x, 0);
}
dict[x]++;
break;
}
}
return dict;
}
public static long GCD(long a, long b) {
while (b > 0) {
var c = a % b;
a = b;
b = c;
}
return a;
}
public class BIT {
int N;
long[] array;
public BIT(int m) {
for (int n = 1;; n *= 2) {
if (n >= m) {
N = n;
array = new long[N + 1];
break;
}
}
}
public void Add(int idx, int v) {
for (int x = idx; x <= N; x += x & -x) {
array[x] += v;
}
}
public long Sum(int idx) {
long ret = 0;
for (int x = idx; x > 0; x -= x & -x) {
ret += array[x];
}
return ret;
}
}
public class UnionFindTree {
int[] parent;
int[] count;
public UnionFindTree(int n) {
parent = new int[n];
count = new int[n];
for (int i = 0; i < n; ++i) {
parent[i] = i;
count[i] = 1;
}
}
public int Root(int i) {
if (parent[i] == i) {
return i;
} else {
return parent[i] = Root(parent[i]);
}
}
public int Count(int i) { return count[Root(i)]; }
public bool Same(int i, int j) { return Root(i) == Root(j); }
public void Unite(int i, int j) {
var ri = Root(i);
var rj = Root(j);
if (ri != rj) {
parent[ri] = rj;
count[rj] += count[ri];
}
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private bool _isAsc = true;
private T[] _heap;
private int _sz = 0;
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
public PriorityQueue(int maxSize, bool isAsc = true) {
_heap = new T[maxSize];
_isAsc = isAsc;
}
private int Compare(T x, T y) {
if (_comparer != null) {
return _comparer.Compare(x, y);
}
return _isAsc ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
var i = _sz++;
while (i > 0) {
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0) {
break;
}
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0) {
a = b;
}
if (Compare(_heap[a], x) >= 0) {
break;
}
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _sz; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
}
public class MyTuple<T1, T2> : IComparable
where T1 : IComparable<T1> {
public readonly T1 Item1;
public readonly T2 Item2;
public MyTuple(T1 item1, T2 item2) {
Item1 = item1;
Item2 = item2;
}
public int CompareTo(object obj) {
return Item1.CompareTo(((MyTuple<T1, T2>)obj).Item1);
}
}
public static long[] Dijkstra(Dictionary<int, Dictionary<int, long>> adj, int N,
int M, int start) {
long INF = (long)1e18;
var dist = Enumerable.Range(0, N + 1).Select(i => INF).ToArray();
var queue = new PriorityQueue<MyTuple<long, int>>(N + M + 100);
dist[start] = 0;
queue.Push(new MyTuple<long, int>(0, start));
while (queue.Count() > 0) {
var kvp = queue.Pop();
var d = kvp.Item1;
var v = kvp.Item2;
if (dist[v] < d) {
continue;
}
foreach (var kvp2 in adj[v]) {
var newV = kvp2.Key;
var newD = dist[v] + kvp2.Value;
if (newD < dist[newV]) {
dist[newV] = newD;
queue.Push(new MyTuple<long, int>(newD, newV));
}
}
}
return dist;
}
}
struct MOD {
public static long P = 1000000007;
public readonly long V;
public MOD(long a) { this.V = a % P; }
public static implicit operator MOD(long a) { return new MOD(a); }
public static MOD operator +(MOD a, MOD b) {
return new MOD((a.V + b.V) % P);
}
public static MOD operator -(MOD a, MOD b) {
return new MOD((a.V - b.V + P) % P);
}
public static MOD operator *(MOD a, MOD b) {
return new MOD((a.V * b.V) % P);
}
public static MOD operator /(MOD a, MOD b) {
return new MOD((a.V * b.Inverse().V) % P);
}
public MOD Inverse() {
long a = V, p = P;
long b = p, c = 1, d = 0, e = 0, f = 0;
while (b != 0) {
e = a / b;
f = b;
b = a - e * b;
a = f;
f = d;
d = c - e * d;
c = f;
}
c %= p;
return c + (c < 0 ? p : 0);
}
public MOD Power(long n) {
long a = V, p = P;
long res = 1;
long mult = a;
for (int i = 0; i < 63; ++i) {
if ((n & ((long)1 << i)) > 0) {
res = (res * mult) % p;
}
mult = (mult * mult) % p;
}
return res;
}
public override string ToString() { return V.ToString(); }
}
static class Read {
static Queue<string> queue = new Queue<string>();
static void Enqueue() {
var ss = Console.ReadLine().Split(' ');
foreach (var s in ss) {
queue.Enqueue(s);
}
}
public static int Int() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt32(queue.Dequeue());
}
public static long Long() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt64(queue.Dequeue());
}
public static string Str() {
if (queue.Count == 0) {
Enqueue();
}
return queue.Dequeue();
}
public static int[] IntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
public static long[] LongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
public static ulong[] ULongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToUInt64(s))
.ToArray();
}
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = Read.IntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<long, long>[] TupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<string, string>[] TupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = Read.StrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<double, double>[] TupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
public static long[,] LongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = Read.LongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
public static Dictionary<int, HashSet<int>>
AdjacencyList(int N, int M, bool isDirectional = false) {
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new HashSet<int>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
if (!dict[ab[0]].Contains(ab[1])) {
dict[ab[0]].Add(ab[1]);
}
if (!isDirectional && !dict[ab[1]].Contains(ab[0])) {
dict[ab[1]].Add(ab[0]);
}
}
return dict;
}
public static Dictionary<int, Dictionary<int, long>>
AdjacencyListWithWeight(int N, int M, bool isDirectional = false) {
Dictionary<int, Dictionary<int, long>> dict =
new Dictionary<int, Dictionary<int, long>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new Dictionary<int, long>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1], ab[2]);
if (!isDirectional) {
dict[ab[1]].Add(ab[0], ab[2]);
}
}
return dict;
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 293, 0, 294], ["-", 0, 195, 8, 196, 0, 293, 0, 230, 0, 228], ["-", 0, 195, 8, 196, 0, 293, 0, 230, 39, 22], ["-", 8, 196, 0, 293, 0, 230, 3, 4, 0, 24], ["-", 8, 196, 0, 293, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 293, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79]]
| 8
| 4,396
| 25
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public static long Gcd(long s, long t) { return t != 0 ? Gcd(t, s % t) : s; }
public void Run() {
var n = ni();
var a = nl(n);
var lpf = GetLowestPrimeFactorTable(1000000 + 10);
if (PairwisePrime(a))
cout.WriteLine("pairwise coprime");
else if (a.Aggregate((x, y) => Gcd(x, y)) == 1)
cout.WriteLine("setwise coprime");
else
cout.WriteLine("not coprime");
}
private bool PairwisePrime(long[] a) {
var hist = new bool[1000000 + 10];
var lpf = GetLowestPrimeFactorTable(1000000 + 10);
foreach (var x in a) {
var current = x;
while (current > 1) {
var p = lpf[current];
if (hist[p])
return false;
while (current % p == 0)
current /= p;
hist[lpf[current]] = true;
}
}
return true;
}
public static int[] GetLowestPrimeFactorTable(int size) {
var lpf = new int[size + 1];
for (int i = 2; i <= size; i++) {
if (lpf[i] > 0)
continue;
lpf[i] = i;
for (int j = i + i; j <= size; j += i) {
if (lpf[j] == 0) {
lpf[j] = i;
}
}
}
return lpf;
}
}
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public static long Gcd(long s, long t) { return t != 0 ? Gcd(t, s % t) : s; }
public void Run() {
var n = ni();
var a = nl(n);
var lpf = GetLowestPrimeFactorTable(1000000 + 10);
if (PairwisePrime(a))
cout.WriteLine("pairwise coprime");
else if (a.Aggregate((x, y) => Gcd(x, y)) == 1)
cout.WriteLine("setwise coprime");
else
cout.WriteLine("not coprime");
}
private bool PairwisePrime(long[] a) {
var hist = new bool[1000000 + 10];
var lpf = GetLowestPrimeFactorTable(1000000 + 10);
foreach (var x in a) {
var current = x;
while (current > 1) {
var p = lpf[current];
if (hist[p])
return false;
hist[p] = true;
while (current % p == 0)
current /= p;
}
}
return true;
}
public static int[] GetLowestPrimeFactorTable(int size) {
var lpf = new int[size + 1];
for (int i = 2; i <= size; i++) {
if (lpf[i] > 0)
continue;
lpf[i] = i;
for (int j = i + i; j <= size; j += i) {
if (lpf[j] == 0) {
lpf[j] = i;
}
}
}
return lpf;
}
}
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 52, 8, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146]]
| 8
| 1,567
| 17
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
class Program {
#region Reader
static string ReadStr => Console.ReadLine();
static string[] ReadStrs => Console.ReadLine().Split(' ');
static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
static int[] ReadInts => Console.ReadLine()
.Trim()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
static long[] ReadLongs => Console.ReadLine()
.Trim()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
#endregion
#region Method
const int mod = 1000000007;
public static int Mod(int a, int mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
public static long Mod(long a, long mod = mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
#endregion
/// <summary>
/// 最大公約数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static Dictionary<int, int> PrimeFactors(int n) {
int i = 2;
int tmp = n;
Dictionary<int, int> d = new Dictionary<int, int>();
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
if (d.ContainsKey(i))
d[i]++;
else
d.Add(i, 1);
} else {
i++;
}
}
if (tmp != 1) {
if (d.ContainsKey(tmp))
d[tmp]++;
else
d.Add(tmp, 1);
}
return d;
}
static void Main() {
int N = ReadInt;
int[] As = ReadInts;
long g = As[0];
long max = As.Max();
for (int i = 1; i < N; i++) {
g = Gcd(g, As[i]);
}
if (g != 1) {
WriteLine("not coprime");
return;
}
bool[] num = new bool[max + 1];
for (int i = 0; i < N; i++) {
var d = PrimeFactors(As[i]);
foreach (var item in d) {
long m = item.Key;
long n = item.Key;
while (n <= max) {
if (!num[n]) {
num[n] = true;
n += m;
} else {
WriteLine("setwise coprime");
return;
}
}
}
}
WriteLine("pairwise coprime");
}
}
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
class Program {
#region Reader
static string ReadStr => Console.ReadLine();
static string[] ReadStrs => Console.ReadLine().Split(' ');
static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
static int[] ReadInts => Console.ReadLine()
.Trim()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
static long[] ReadLongs => Console.ReadLine()
.Trim()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
#endregion
#region Method
const int mod = 1000000007;
public static int Mod(int a, int mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
public static long Mod(long a, long mod = mod) {
return a % mod >= 0 ? a % mod : a % mod + mod;
}
#endregion
/// <summary>
/// 最大公約数
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long Gcd(long a, long b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public static Dictionary<int, int> PrimeFactors(int n) {
int i = 2;
int tmp = n;
Dictionary<int, int> d = new Dictionary<int, int>();
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
if (d.ContainsKey(i))
d[i]++;
else
d.Add(i, 1);
} else {
i++;
}
}
if (tmp != 1) {
if (d.ContainsKey(tmp))
d[tmp]++;
else
d.Add(tmp, 1);
}
return d;
}
static void Main() {
int N = ReadInt;
int[] As = ReadInts;
long g = As[0];
long max = As.Max();
for (int i = 1; i < N; i++) {
g = Gcd(g, As[i]);
}
if (g != 1) {
WriteLine("not coprime");
return;
}
bool[] ans = new bool[max + 1];
for (int i = 0; i < N; i++) {
if (As[i] == 1)
continue;
var d = PrimeFactors(As[i]);
foreach (var item in d) {
long m = item.Key;
long n = item.Key;
while (n <= max) {
if (!ans[n]) {
ans[n] = true;
} else {
WriteLine("setwise coprime ");
return;
}
n *= m;
}
}
}
WriteLine("pairwise coprime");
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 8, 196, 0, 57, 15, 241, 0, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 241, 0, 204, 205, 22], ["-", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 641
| 27
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class modMWorld {
public static long M = (int)Math.Pow(10, 9) + 7;
//必要な演算は、加減乗除、nCk,n!,a^n
public static long add(long a, long b) {
long sum = a + b;
sum += M;
return sum % M;
}
public static long sub(long a, long b) {
long dif = a - b;
dif += M * 2;
return dif % M;
}
public static long mul(long a, long b) {
long product = a;
product *= b;
return product % M;
}
public static long div(long a, long b) { return mul(a, Pow(b, M - 2)); }
public static long modify(long a) { return (a % M + M) % M; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static long Pow(long a, long m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
long p1 = Pow(a, m / 2);
long p2 = mul(p1, p1);
return ((m % 2) == 0) ? p2 : mul(p2, a);
}
}
public static long kaijou(long n) {
//!
long output = 1;
for (int i = 0; i < n; i++) {
output = mul(output, n - i);
}
return output;
}
public static long nCk(long n, long k) {
long output = 1;
for (int i = 1; i <= k; i++) {
output = mul(output, n - (i - 1));
output = div(output, i);
}
return output;
}
}
class Util {
public static string convertToBinary(int N, int length) {
string binary = Convert.ToString(N, 2);
while (length > binary.Length) {
binary = "0" + binary;
}
return binary;
}
public static int[] readintarr() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static long[] readlongarr() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
/// <summary>
/// nの約数を小さい順のリストで返します。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<int> make_divisor(int n) {
List<int> output = new List<int>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
output.Add(i);
if (i * i != n) {
output.Add(n / i);
}
}
}
output.Sort();
return output;
}
// iの素因数分解をします
public static List<int> soinsuuBunkai(int n) {
//素因数分解をします
List<int> output = new List<int>();
int target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
public static List<long> soinsuuBunkai(long n) {
List<long> output = new List<long>();
long target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
/// <summary>
/// 2引数の最大公約数を返します。longです。
/// </summary>
/// <param name="a">long 引数1</param>
/// <param name="b">long 引数2</param>
/// <returns></returns>
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2引数の最大公約数を返します。intです。
/// </summary>
/// <param name="a">int 引数1</param>
/// <param name="b">int 引数2</param>
/// <returns></returns>
public static int GCD(int a, int b) {
// if (a < b)
// swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2つの変数の中身を交換する。型はなんでもいい
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <param name="b"></param>
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)998244353; //(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
public static long nCr(long n, long r) {
long output = 1;
for (int i = 1; i <= r; i++) {
output *= (n + 1 - i);
output /= (i);
}
return output;
}
/// <summary>
/// 2引数の積 mod Mを求める。Mは10億7。
/// 変えられるよ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
/// <summary>
/// n! modMまたはnCmを求めるための準備を行う。引数は最大値。
/// </summary>
/// <param name="n"></param>
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
/// <summary>
/// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int Factorial(int n) { return factorial_modM[n]; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
/// <summary>
/// a / m Mod M を求める。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
/// <summary>
/// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <param name="r"></param>
/// <returns></returns>
public static int nCr_modM(int n, int r) {
if (r < 0)
return 0;
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
/// <summary>
/// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。
/// おすすめとしては、UnionFind<T>[] で宣言してしまう。
/// 配列で宣言したあと、コンストラクタ使ってnewするのを忘れないでね。
/// コンストラクタのitemは、そのノード固有のIDになるので、絶対必要です
/// </summary>
/// <typeparam name="T">int固定でいいよね。</typeparam>
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
this.item = item;
}
/// <summary>
/// 一番上の親を探す。
/// 探しながら繋がり方を最適化している。
/// UnionFindの頂点そのものを返すので、==での比較が可能。
/// </summary>
/// <returns></returns>
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
/// <summary>
/// unionfind2つを一つにつなぐ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
/// <summary>
/// 使い方:Permutation.next(配列) で次の配列を返す
/// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。
/// もし、次のがない場合、空の配列を返します。
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Permutation<T>
where T : IComparable {
public static T[] next(T[] letters) {
int pivot = -1;
for (int i = letters.Length - 2; i >= 0; i--) {
if (letters[i].CompareTo(letters[i + 1]) < 0) {
pivot = i;
break;
}
}
if (pivot == -1) {
return new T[0];
}
int big_min = letters.Length - 1;
T big_min_T = letters[letters.Length - 1];
for (int i = letters.Length - 1; i > pivot;
i--) { // big_min_Tより小さいかつ、pivotのより大きい
if (letters[pivot].CompareTo(letters[i]) > 0 &&
letters[pivot].CompareTo(big_min_T) < 0) {
big_min_T = letters[i];
big_min = i;
}
}
T temp = letters[pivot];
letters[pivot] = letters[big_min];
letters[big_min] = temp;
Array.Sort(letters, pivot + 1, letters.Length - pivot - 1);
return letters;
}
}
/// <summary>
/// 使い方 : Combination
/// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数)
/// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Combination<T>
where T : IComparable {
private static bool stop = false;
public static List<string> AllCombination(T[] letters, int n) {
// n桁ですよね。
List<string> outlist = new List<string>();
T[] state = new T[n];
for (int i = 0; i < n; i++) {
state[i] = letters[0];
}
outlist.Add(String.Join(" ", state));
while (true) {
next_keta(ref state, state.Length - 1, letters);
if (stop)
break;
outlist.Add(string.Join(" ", state));
}
return outlist;
}
public static T[] next_keta(ref T[] state, int keta, T[] letters) {
if (keta == -1) {
stop = true;
return new T[0];
}
if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) {
//見た桁を最初の要素にする処理を
state[keta] = letters[0];
return next_keta(ref state, keta - 1, letters);
} else {
int ketaindex = 0;
for (int i = 0; i < letters.Length; i++) {
if (state[keta].CompareTo(letters[i]) == 0) {
ketaindex = i;
break;
}
}
state[keta] = letters[ketaindex + 1];
return state;
}
}
}
/// <summary>
/// long
/// </summary>
class BinaryDictionary {
public Dictionary<long, long> dict = new Dictionary<long, long>();
public phantaSortedList<long> keys = new phantaSortedList<long>();
public bool ContainsKey(int x) { return (keys.indexSearch((long)x) != -1); }
public bool ContainsKey(long x) { return (keys.indexSearch((long)x) != -1); }
public void Add(int x) { this.Add((long)x); }
public void Add(long x) {
if (ContainsKey(x)) {
dict[x] += 1;
} else {
dict[x] = 1;
keys.Add(x);
}
}
public long Value(int key) { return dict[key]; }
public long Value(long key) { return dict[key]; }
}
/// <summary>
/// 常に昇順に並んでいるすごいやつだよ
///
/// </summary>
/// <typeparam name="T"></typeparam>
class phantaSortedList<T> {
public List<T> list;
readonly Comparison<T> cmp = Comparer<T>.Default.Compare;
public phantaSortedList() { list = new List<T>(); }
public void Add(T x) {
if (this.list.Count == 0) {
list.Add(x);
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
if (left == -1) {
if (cmp(list[0], x) >= 0) {
list.Insert(0, x);
} else {
list.Insert(1, x);
}
} else if (right == this.list.Count) {
if (cmp(list[this.list.Count - 1], x) >= 0) {
list.Insert(this.list.Count - 2, x);
} else {
list.Add(x);
}
} else {
list.Insert(right, x);
}
}
/// <summary>
/// xがあるならその最小indexを。ないなら-1を。
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public int indexSearch(T x) {
if (list.Count == 0) {
return -1;
}
int ok = list.Count;
int ng = -1;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
if (cmp(list[mid], x) >= 0) {
ok = mid;
} else {
ng = mid;
}
}
if (ok == list.Count) {
//リストの中にあるすべてのものより大きいものを検索した場合
return -1;
} else if (cmp(list[ok], x) == 0) {
return ok;
} else {
return -1;
}
}
/// <summary>
/// あるなら一つ削除。ないなら無視。
/// </summary>
/// <param name="x"></param>
public void Remove(T x) {
if (list.Count == 0) {
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
{
if (left == -1) {
if (cmp(list[0], x) == 0) {
list.RemoveAt(0);
}
} else if (right == this.list.Count) {
if (cmp(list.Last(), x) == 0) {
list.RemoveAt(list.Count - 1);
}
} else {
if (cmp(list[right], x) == 0) {
list.RemoveAt(right);
}
}
}
}
/// <summary>
/// 指定した値をlistから全滅させます。
/// </summary>
/// <param name="x"></param>
public void allRemove(T x) {
if (list.Count == 0) {
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
{
if (left == -1) {
while (cmp(list[0], x) == 0) {
list.RemoveAt(0);
}
} else if (right == this.list.Count) {
while (cmp(list.Last(), x) == 0) {
list.RemoveAt(list.Count - 1);
}
} else {
while (right < list.Count) {
if (cmp(list[right], x) == 0) {
list.RemoveAt(right);
} else {
break;
}
}
}
}
}
public T min() {
if (list.Count == 0)
return default(T);
return list[0];
}
public T max() {
if (list.Count == 0)
return default(T);
return list.Last();
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// あと絶対コンストラクタ使ってね
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
/// <summary>
/// !!!WARNING!!! 1-BASEです。
/// </summary>
/// <param name="m">要素の数の最大値。200001とか入れておくとよい</param>
/// <param name="f">2引数の関数</param>
/// <param
/// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param>
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
/// <summary>
/// j番目の値をxにする。計算し直さないので、
/// 入れ替えた後はall_update();を使おう
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
/// <summary>
/// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
/// <summary>
/// 木を全部計算し直す。多分NlogN。違うかも知れないから
/// よかったら教えて
/// </summary>
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
/// <summary>
/// j番目を消す。
/// </summary>
/// <param name="j"></param>
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
/// <summary>
/// s番目からt - 1 番目までの結果を返す。t番目は含まない。
/// これも当然のように1-BASE.
/// </summary>
/// <param name="s"></param>
/// <param name="t"></param>
/// <returns></returns>
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class pair<T> {
public T A;
public T B;
public pair() {}
public pair(T A, T B) {
this.A = A;
this.B = B;
}
}
public class chouten {
public int N;
public List<int> node;
public chouten(int n) {
this.N = n;
this.node = new List<int>();
}
}
public class ab {
public int a, b;
public ab(int a, int b) {
this.a = a;
this.b = b;
}
}
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
// System.Collections.Generic.SortedList<>
//文字列比較のcomparer
// StringComparer.OrdinalIgnoreCase
public static void Main() {
int N;
new readint(out N);
int[] A = Util.readintarr();
Array.Sort(A);
// 1 全GCD
int gcd = A[0];
for (int i = 1; i < N; i++) {
gcd = Util.GCD(gcd, A[i]);
}
if (gcd >= 2) {
Console.WriteLine("not coprime");
} else {
bool[] checker = new bool[A.Last() + 1];
for (int i = 0; i < N; i++) {
if (A[i] == 1)
continue;
if (checker[A[i]]) {
//おかぶり
Console.WriteLine("setwise coprime");
return;
} else {
checker[A[i]] = true;
// so因数分解…
List<int> insuu = Util.soinsuuBunkai(A[i]);
for (int count = 0; count < insuu.Count; count++) {
if (checker[insuu[count]])
continue;
for (int mul = 2; mul * insuu[count] < checker.Length; mul++) {
checker[mul * insuu[count]] = true;
}
}
}
}
Console.WriteLine("pairwise coprime");
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
class readint {
public readint(out int i) { i = int.Parse(Console.ReadLine()); }
public readint(out int a, out int b) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readint(out int a, out int b, out int c) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readint(out int a, out int b, out int c, out int d) {
int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class readlong {
public readlong(out long i) { i = long.Parse(Console.ReadLine()); }
public readlong(out long a, out long b) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
}
public readlong(out long a, out long b, out long c) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
}
public readlong(out long a, out long b, out long c, out long d) {
long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray();
a = sp[0];
b = sp[1];
c = sp[2];
d = sp[3];
}
}
class modMWorld {
public static long M = (int)Math.Pow(10, 9) + 7;
//必要な演算は、加減乗除、nCk,n!,a^n
public static long add(long a, long b) {
long sum = a + b;
sum += M;
return sum % M;
}
public static long sub(long a, long b) {
long dif = a - b;
dif += M * 2;
return dif % M;
}
public static long mul(long a, long b) {
long product = a;
product *= b;
return product % M;
}
public static long div(long a, long b) { return mul(a, Pow(b, M - 2)); }
public static long modify(long a) { return (a % M + M) % M; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static long Pow(long a, long m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
long p1 = Pow(a, m / 2);
long p2 = mul(p1, p1);
return ((m % 2) == 0) ? p2 : mul(p2, a);
}
}
public static long kaijou(long n) {
//!
long output = 1;
for (int i = 0; i < n; i++) {
output = mul(output, n - i);
}
return output;
}
public static long nCk(long n, long k) {
long output = 1;
for (int i = 1; i <= k; i++) {
output = mul(output, n - (i - 1));
output = div(output, i);
}
return output;
}
}
class Util {
public static string convertToBinary(int N, int length) {
string binary = Convert.ToString(N, 2);
while (length > binary.Length) {
binary = "0" + binary;
}
return binary;
}
public static int[] readintarr() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static long[] readlongarr() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
/// <summary>
/// nの約数を小さい順のリストで返します。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<int> make_divisor(int n) {
List<int> output = new List<int>();
for (int i = 1; i <= Math.Sqrt(n) + 1; i++) {
if (n % i == 0) {
output.Add(i);
if (i * i != n) {
output.Add(n / i);
}
}
}
output.Sort();
return output;
}
// iの素因数分解をします
public static List<int> soinsuuBunkai(int n) {
//素因数分解をします
List<int> output = new List<int>();
int target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
public static List<long> soinsuuBunkai(long n) {
List<long> output = new List<long>();
long target = n;
for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) {
while (target % i == 0) {
target /= i;
output.Add(i);
}
if (i == 2)
i--;
}
if (target > 1) {
output.Add(target);
}
return output;
}
/// <summary>
/// 2引数の最大公約数を返します。longです。
/// </summary>
/// <param name="a">long 引数1</param>
/// <param name="b">long 引数2</param>
/// <returns></returns>
public static long GCD(long a, long b) {
if (a < b)
swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2引数の最大公約数を返します。intです。
/// </summary>
/// <param name="a">int 引数1</param>
/// <param name="b">int 引数2</param>
/// <returns></returns>
public static int GCD(int a, int b) {
// if (a < b)
// swap(ref a, ref b);
if (a % b == 0)
return b;
return GCD(b, a % b);
}
/// <summary>
/// 2つの変数の中身を交換する。型はなんでもいい
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="a"></param>
/// <param name="b"></param>
public static void swap<T>(ref T a, ref T b) {
T temp = b;
b = a;
a = temp;
}
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(long a, long b) { return a * b / GCD(a, b); }
/// <summary>
/// 2引数の最大公約数を返します。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); }
public static int M = (int)998244353; //(Math.Pow(10, 9)) + 7;
private static int[] factorial_modM;
public static long nCr(long n, long r) {
long output = 1;
for (int i = 1; i <= r; i++) {
output *= (n + 1 - i);
output /= (i);
}
return output;
}
/// <summary>
/// 2引数の積 mod Mを求める。Mは10億7。
/// 変えられるよ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Multiple_modM(int a, int b) {
return (int)(Math.BigMul(a, b) % M);
}
/// <summary>
/// n! modMまたはnCmを求めるための準備を行う。引数は最大値。
/// </summary>
/// <param name="n"></param>
public static void factorial_modM_Prepare(int n) {
factorial_modM = new int[n + 1];
factorial_modM[0] = 1;
for (int i = 1; i <= n; ++i) {
factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i);
}
}
/// <summary>
/// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static int Factorial(int n) { return factorial_modM[n]; }
/// <summary>
/// a^m modMを求める
/// </summary>
/// <param name="a"></param>
/// <param name="m"></param>
/// <returns></returns>
public static int Pow(int a, int m) {
switch (m) {
case 0:
return 1;
case 1:
return a;
default:
int p1 = Pow(a, m / 2);
int p2 = Multiple_modM(p1, p1);
return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a);
}
}
/// <summary>
/// a / m Mod M を求める。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Div(int a, int b) {
return Multiple_modM(a, Pow(b, M - 2));
}
/// <summary>
/// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。
/// </summary>
/// <param name="n"></param>
/// <param name="r"></param>
/// <returns></returns>
public static int nCr_modM(int n, int r) {
if (r < 0)
return 0;
if (n < r) {
return 0;
}
if (n == r) {
return 1;
}
int res = Factorial(n);
res = Div(res, Factorial(r));
res = Div(res, Factorial(n - r));
return res;
}
}
/// <summary>
/// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。
/// おすすめとしては、UnionFind<T>[] で宣言してしまう。
/// 配列で宣言したあと、コンストラクタ使ってnewするのを忘れないでね。
/// コンストラクタのitemは、そのノード固有のIDになるので、絶対必要です
/// </summary>
/// <typeparam name="T">int固定でいいよね。</typeparam>
class UnionFind<T> {
public int tree_height;
public UnionFind<T> parent;
public T item { get; private set; }
public UnionFind(T item) {
tree_height = 0;
parent = this;
this.item = item;
}
/// <summary>
/// 一番上の親を探す。
/// 探しながら繋がり方を最適化している。
/// UnionFindの頂点そのものを返すので、==での比較が可能。
/// </summary>
/// <returns></returns>
public UnionFind<T> FindAdam() {
if (parent == this)
return this;
else {
UnionFind<T> ParentOfParent = parent.FindAdam();
parent = ParentOfParent; //縦長な構成をつなぎ直している
return ParentOfParent;
}
}
/// <summary>
/// unionfind2つを一つにつなぐ。
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public static void Unite(UnionFind<T> a, UnionFind<T> b) {
UnionFind<T> ParentOfA = a.FindAdam();
UnionFind<T> ParentOfB = b.FindAdam();
if (ParentOfA.tree_height < ParentOfB.tree_height) {
ParentOfA.parent = ParentOfB;
ParentOfB.tree_height =
Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height);
} else {
ParentOfB.parent = ParentOfA;
ParentOfA.tree_height =
Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height);
}
}
}
// Treap 平衡二分木
class Treap<T>
where T : IComparable {
private class Node {
private static Random g_rand = new Random();
private readonly int m_rank = g_rand.Next();
private readonly T m_value;
private Node m_lch;
private Node m_rch;
private int m_count;
public Node(T value) {
m_value = value;
m_count = 1;
}
private static int Count(Node node) {
return (node != null) ? node.m_count : 0;
}
private Node Update() {
m_count = Count(m_lch) + Count(m_rch) + 1;
return this;
}
public static Node Merge(Node a, Node b) {
if (a == null) {
return b;
}
if (b == null) {
return a;
}
if (a.m_rank < b.m_rank) {
a.m_rch = Merge(a.m_rch, b);
return a.Update();
} else {
b.m_lch = Merge(a, b.m_lch);
return b.Update();
}
}
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null) {
return new Tuple<Node, Node>(null, null);
}
if (k <= Count(t.m_lch)) {
var pair = Split(t.m_lch, k);
t.m_lch = pair.Item2;
return new Tuple<Node, Node>(pair.Item1, t.Update());
} else {
var pair = Split(t.m_rch, k - Count(t.m_lch) - 1);
t.m_rch = pair.Item1;
return new Tuple<Node, Node>(t.Update(), pair.Item2);
}
}
public int FindIndex(T value) {
int L = Count(m_lch);
if (value.CompareTo(m_value) < 0) {
return (m_lch != null) ? m_lch.FindIndex(value) : 0;
} else if (value.CompareTo(m_value) > 0) {
return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1;
} else {
return L;
}
}
public T this[int i] {
get {
int L = Count(m_lch);
if (i < L) {
return m_lch[i];
} else if (i > L) {
return m_rch[i - L - 1];
} else {
return m_value;
}
}
}
}
private Node node;
public void Insert(T value) {
if (node != null) {
int k = node.FindIndex(value);
var pair = Node.Split(node, k);
node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2);
} else {
node = new Node(value);
}
}
public int FindIndex(T value) { return node.FindIndex(value); }
public T this[int i] {
get { return node[i]; }
}
}
/// <summary>
/// 使い方:Permutation.next(配列) で次の配列を返す
/// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。
/// もし、次のがない場合、空の配列を返します。
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Permutation<T>
where T : IComparable {
public static T[] next(T[] letters) {
int pivot = -1;
for (int i = letters.Length - 2; i >= 0; i--) {
if (letters[i].CompareTo(letters[i + 1]) < 0) {
pivot = i;
break;
}
}
if (pivot == -1) {
return new T[0];
}
int big_min = letters.Length - 1;
T big_min_T = letters[letters.Length - 1];
for (int i = letters.Length - 1; i > pivot;
i--) { // big_min_Tより小さいかつ、pivotのより大きい
if (letters[pivot].CompareTo(letters[i]) > 0 &&
letters[pivot].CompareTo(big_min_T) < 0) {
big_min_T = letters[i];
big_min = i;
}
}
T temp = letters[pivot];
letters[pivot] = letters[big_min];
letters[big_min] = temp;
Array.Sort(letters, pivot + 1, letters.Length - pivot - 1);
return letters;
}
}
/// <summary>
/// 使い方 : Combination
/// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数)
/// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する
///
/// </summary>
/// <typeparam name="T"></typeparam>
class Combination<T>
where T : IComparable {
private static bool stop = false;
public static List<string> AllCombination(T[] letters, int n) {
// n桁ですよね。
List<string> outlist = new List<string>();
T[] state = new T[n];
for (int i = 0; i < n; i++) {
state[i] = letters[0];
}
outlist.Add(String.Join(" ", state));
while (true) {
next_keta(ref state, state.Length - 1, letters);
if (stop)
break;
outlist.Add(string.Join(" ", state));
}
return outlist;
}
public static T[] next_keta(ref T[] state, int keta, T[] letters) {
if (keta == -1) {
stop = true;
return new T[0];
}
if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) {
//見た桁を最初の要素にする処理を
state[keta] = letters[0];
return next_keta(ref state, keta - 1, letters);
} else {
int ketaindex = 0;
for (int i = 0; i < letters.Length; i++) {
if (state[keta].CompareTo(letters[i]) == 0) {
ketaindex = i;
break;
}
}
state[keta] = letters[ketaindex + 1];
return state;
}
}
}
/// <summary>
/// long
/// </summary>
class BinaryDictionary {
public Dictionary<long, long> dict = new Dictionary<long, long>();
public phantaSortedList<long> keys = new phantaSortedList<long>();
public bool ContainsKey(int x) { return (keys.indexSearch((long)x) != -1); }
public bool ContainsKey(long x) { return (keys.indexSearch((long)x) != -1); }
public void Add(int x) { this.Add((long)x); }
public void Add(long x) {
if (ContainsKey(x)) {
dict[x] += 1;
} else {
dict[x] = 1;
keys.Add(x);
}
}
public long Value(int key) { return dict[key]; }
public long Value(long key) { return dict[key]; }
}
/// <summary>
/// 常に昇順に並んでいるすごいやつだよ
///
/// </summary>
/// <typeparam name="T"></typeparam>
class phantaSortedList<T> {
public List<T> list;
readonly Comparison<T> cmp = Comparer<T>.Default.Compare;
public phantaSortedList() { list = new List<T>(); }
public void Add(T x) {
if (this.list.Count == 0) {
list.Add(x);
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
if (left == -1) {
if (cmp(list[0], x) >= 0) {
list.Insert(0, x);
} else {
list.Insert(1, x);
}
} else if (right == this.list.Count) {
if (cmp(list[this.list.Count - 1], x) >= 0) {
list.Insert(this.list.Count - 2, x);
} else {
list.Add(x);
}
} else {
list.Insert(right, x);
}
}
/// <summary>
/// xがあるならその最小indexを。ないなら-1を。
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public int indexSearch(T x) {
if (list.Count == 0) {
return -1;
}
int ok = list.Count;
int ng = -1;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
if (cmp(list[mid], x) >= 0) {
ok = mid;
} else {
ng = mid;
}
}
if (ok == list.Count) {
//リストの中にあるすべてのものより大きいものを検索した場合
return -1;
} else if (cmp(list[ok], x) == 0) {
return ok;
} else {
return -1;
}
}
/// <summary>
/// あるなら一つ削除。ないなら無視。
/// </summary>
/// <param name="x"></param>
public void Remove(T x) {
if (list.Count == 0) {
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
{
if (left == -1) {
if (cmp(list[0], x) == 0) {
list.RemoveAt(0);
}
} else if (right == this.list.Count) {
if (cmp(list.Last(), x) == 0) {
list.RemoveAt(list.Count - 1);
}
} else {
if (cmp(list[right], x) == 0) {
list.RemoveAt(right);
}
}
}
}
/// <summary>
/// 指定した値をlistから全滅させます。
/// </summary>
/// <param name="x"></param>
public void allRemove(T x) {
if (list.Count == 0) {
return;
}
int left = -1;
int right = this.list.Count;
while (right - left > 1) {
int target = (right + left) / 2;
if (cmp(list[target], x) >= 0) {
right = target;
} else {
left = target;
}
}
//同じものを指しているか、1違うものを指しているはず。
{
if (left == -1) {
while (cmp(list[0], x) == 0) {
list.RemoveAt(0);
}
} else if (right == this.list.Count) {
while (cmp(list.Last(), x) == 0) {
list.RemoveAt(list.Count - 1);
}
} else {
while (right < list.Count) {
if (cmp(list[right], x) == 0) {
list.RemoveAt(right);
} else {
break;
}
}
}
}
}
public T min() {
if (list.Count == 0)
return default(T);
return list[0];
}
public T max() {
if (list.Count == 0)
return default(T);
return list.Last();
}
}
namespace CompLib.Collections {
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
}
/// <summary>
/// SEGTREEは1-BASE運用でございます
/// よろしくおねがいします
/// あと絶対コンストラクタ使ってね
/// </summary>
/// <typeparam name="T"></typeparam>
class Segtree<T> {
int n; //高さ
T[] tree; //本体
Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか
T exnum; //初期値
int count;
/// <summary>
/// !!!WARNING!!! 1-BASEです。
/// </summary>
/// <param name="m">要素の数の最大値。200001とか入れておくとよい</param>
/// <param name="f">2引数の関数</param>
/// <param
/// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param>
public Segtree(int m, Func<T, T, T> f, T ex) {
this.count = 0;
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
this.count = 0;
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
/// <summary>
/// j番目の値をxにする。計算し直さないので、
/// 入れ替えた後はall_update();を使おう
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
/// <summary>
/// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる
/// </summary>
/// <param name="j">番目</param>
/// <param name="x">更新後の値</param>
public void update(int j, T x) // j番目をxにする
{
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
this.count++;
}
/// <summary>
/// 木を全部計算し直す。多分NlogN。違うかも知れないから
/// よかったら教えて
/// </summary>
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
/// <summary>
/// j番目を消す。
/// </summary>
/// <param name="j"></param>
public void delete (int j) {
int i = j + n - 1;
tree[i] = exnum;
int moved = 0;
while (true) {
tree[i + 1] = tree[i];
T check = tree[i];
moved++;
if (moved + j + 2 > count) {
break;
}
}
all_update();
}
// [s, t)
/// <summary>
/// s番目からt - 1 番目までの結果を返す。t番目は含まない。
/// これも当然のように1-BASE.
/// </summary>
/// <param name="s"></param>
/// <param name="t"></param>
/// <returns></returns>
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class pair<T> {
public T A;
public T B;
public pair() {}
public pair(T A, T B) {
this.A = A;
this.B = B;
}
}
public class chouten {
public int N;
public List<int> node;
public chouten(int n) {
this.N = n;
this.node = new List<int>();
}
}
public class ab {
public int a, b;
public ab(int a, int b) {
this.a = a;
this.b = b;
}
}
public class ABC {
// long[] sp = Console.ReadLine().Split().Select(long
// .Parse).ToArray(); int[] sp =
// Console.ReadLine().Split().Select(int.Parse).ToArray(); int N =
// int.Parse(Console.ReadLine());
// CompLib.Collections.PriorityQueue<?>
// System.Collections.Generic.SortedList<>
//文字列比較のcomparer
// StringComparer.OrdinalIgnoreCase
public static void Main() {
int N;
new readint(out N);
int[] A = Util.readintarr();
Array.Sort(A);
// 1 全GCD
int gcd = A[0];
for (int i = 1; i < N; i++) {
gcd = Util.GCD(gcd, A[i]);
}
if (gcd >= 2) {
Console.WriteLine("not coprime");
} else {
bool[] checker = new bool[A.Last() + 1];
for (int i = 0; i < N; i++) {
if (A[i] == 1)
continue;
if (checker[A[i]]) {
//おかぶり
Console.WriteLine("setwise coprime");
return;
} else {
// so因数分解…
List<int> insuu = Util.soinsuuBunkai(A[i]);
for (int count = 0; count < insuu.Count; count++) {
if (checker[insuu[count]])
continue;
for (int mul = 1; mul * insuu[count] < checker.Length; mul++) {
checker[mul * insuu[count]] = true;
}
}
}
}
Console.WriteLine("pairwise coprime");
return;
}
}
}
|
[["-", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 5,700
| 12
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
bool[] has = new bool[1000001];
for (int i = 0; i < a.Length; i++) {
if (has[a[i]])
goto end;
has[a[i]] = true;
}
foreach (var prime in Primes(1000001)) {
bool used = false;
for (int i = prime; i < has.Length; i += prime) {
if (!has[i])
continue;
if (used)
goto end;
used = true;
}
}
Console.WriteLine("pairwise coprime");
return;
end:;
if (a.Aggregate(GCD) == 1) {
Console.WriteLine("setwise coprime");
return;
}
Console.WriteLine("not coprime");
}
public static IEnumerable<int> Primes(int n) {
if (n < 2)
yield break;
yield return 2;
ulong[] bitArray = new ulong[(n + 1) / 2 / 64 + 1];
int[] smallPrimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61 };
foreach (var prime in smallPrimes) {
if (n < prime)
yield break;
yield return prime;
ulong[] mask = new ulong[prime];
for (int j = (prime - 3) >> 1; j < (prime << 6); j += prime)
mask[j >> 6] |= 1UL << j;
int maskInd = 0;
for (int i = 0; i < bitArray.Length; i++) {
bitArray[i] |= mask[maskInd];
if (++maskInd >= prime)
maskInd = 0;
}
}
int[] deBruijnIndex = { 0, 1, 59, 2, 60, 40, 54, 3, 61, 32, 49, 41, 55,
19, 35, 4, 62, 52, 30, 33, 50, 12, 14, 42, 56, 16,
27, 20, 36, 23, 44, 5, 63, 58, 39, 53, 31, 48, 18,
34, 51, 29, 11, 13, 15, 26, 22, 43, 57, 38, 47, 17,
28, 10, 25, 21, 37, 46, 9, 24, 45, 8, 7, 6 };
int maxInd = n / 2;
for (int i = 0; i < bitArray.Length; i++) {
for (ulong bit = ~bitArray[i]; bit != 0; bit &= bit - 1) {
int index =
i << 6 |
deBruijnIndex[((bit & (~bit + 1)) * 0x03F566ED27179461UL) >> 58];
int prime = (index << 1) + 3;
if (n < prime)
yield break;
yield return prime;
for (int ind = index; ind <= maxInd; ind += prime)
bitArray[ind >> 6] |= 1UL << ind;
}
}
}
static long GCD(long a, long b) {
while (true) {
if (b == 0)
return a;
a %= b;
if (a == 0)
return b;
b %= a;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P {
public static void Main() {
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
bool[] has = new bool[1000001];
for (int i = 0; i < a.Length; i++) {
if (a[i] == 1)
continue;
if (has[a[i]])
goto end;
has[a[i]] = true;
}
foreach (var prime in Primes(1000001)) {
bool used = false;
for (int i = prime; i < has.Length; i += prime) {
if (!has[i])
continue;
if (used)
goto end;
used = true;
}
}
Console.WriteLine("pairwise coprime");
return;
end:;
if (a.Aggregate(GCD) == 1) {
Console.WriteLine("setwise coprime");
return;
}
Console.WriteLine("not coprime");
}
public static IEnumerable<int> Primes(int n) {
if (n < 2)
yield break;
yield return 2;
ulong[] bitArray = new ulong[(n + 1) / 2 / 64 + 1];
int[] smallPrimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61 };
foreach (var prime in smallPrimes) {
if (n < prime)
yield break;
yield return prime;
ulong[] mask = new ulong[prime];
for (int j = (prime - 3) >> 1; j < (prime << 6); j += prime)
mask[j >> 6] |= 1UL << j;
int maskInd = 0;
for (int i = 0; i < bitArray.Length; i++) {
bitArray[i] |= mask[maskInd];
if (++maskInd >= prime)
maskInd = 0;
}
}
int[] deBruijnIndex = { 0, 1, 59, 2, 60, 40, 54, 3, 61, 32, 49, 41, 55,
19, 35, 4, 62, 52, 30, 33, 50, 12, 14, 42, 56, 16,
27, 20, 36, 23, 44, 5, 63, 58, 39, 53, 31, 48, 18,
34, 51, 29, 11, 13, 15, 26, 22, 43, 57, 38, 47, 17,
28, 10, 25, 21, 37, 46, 9, 24, 45, 8, 7, 6 };
int maxInd = n / 2;
for (int i = 0; i < bitArray.Length; i++) {
for (ulong bit = ~bitArray[i]; bit != 0; bit &= bit - 1) {
int index =
i << 6 |
deBruijnIndex[((bit & (~bit + 1)) * 0x03F566ED27179461UL) >> 58];
int prime = (index << 1) + 3;
if (n < prime)
yield break;
yield return prime;
for (int ind = index; ind <= maxInd; ind += prime)
bitArray[ind >> 6] |= 1UL << ind;
}
}
}
static long GCD(long a, long b) {
while (true) {
if (b == 0)
return a;
a %= b;
if (a == 0)
return b;
b %= a;
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24]]
| 8
| 773
| 11
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public void Run() {
var h = ni();
var w = ni();
var a = new int[h];
var b = new int[h];
for (int i = 0; i < h; i++) {
a[i] = ni() - 1;
b[i] = ni() - 1;
}
var ranges = new MultiSet<(int begin, int end, int value)>();
ranges.Add((-1, 0, -1000000));
for (int i = 0; i < w; i++) {
ranges.Add((i, i + 1, i));
}
var seg = new SegmentTree<long>((x, y) => Math.Min(x, y), long.MaxValue);
seg.Build(w, i => 0);
for (int i = 0; i < h; i++) {
var begin = ranges.IndexOfLowerBound((a[i], -1, -1));
var changed = new List<(int begin, int end, int value)>();
var prev = ranges.At(begin - 1);
if (b[i] + 1 <= prev.end)
continue;
ranges.Remove(prev);
prev.end = b[i] + 1;
ranges.Add(prev);
if (prev.value >= 0)
seg[prev.value] = prev.begin - prev.value;
for (int j = begin; j < ranges.Count; j++) {
var val = ranges.At(j);
if (val.begin < prev.end) {
changed.Add(val);
} else {
break;
}
}
foreach (var c in changed) {
ranges.Remove(c);
if (c.value >= 0)
seg[c.value] = long.MaxValue;
var v = c;
v.begin = prev.end;
if (v.begin < v.end) {
ranges.Add(v);
if (v.value >= 0) {
seg[v.value] = v.begin - v.value;
}
}
}
// ranges.TextDump();
// E.Range(0, w).Select(j => seg[j]).TextDump();
var ans = seg.Query(0, seg.Count);
if (ans <= w)
cout.WriteLine(ans + i + 1);
else
cout.WriteLine(-1);
}
}
public static int MoveUntil(int ok, int ng, Predicate<int> predicate) {
if (ok == ng)
throw new Exception();
while (Math.Abs(ok - ng) > 1) {
var mid = (ok + ng) >> 1;
if (predicate(mid)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
}
public sealed class SegmentTree<TMonoid> {
public int Count { get; private set; }
private TMonoid[] _node;
private readonly TMonoid _identity;
private readonly Func<TMonoid, TMonoid, TMonoid> _merge;
public SegmentTree(Func<TMonoid, TMonoid, TMonoid> merge, TMonoid identity) {
_merge = merge;
_identity = identity;
}
public void Build(IList<TMonoid> array) { Build(array.Count, i => array[i]); }
public void Build(int n, Func<int, TMonoid> create) {
Count = n;
_node = new TMonoid[2 * Count];
for (int i = 0; i < n; i++) {
_node[i + Count] = create(i);
}
for (int i = Count - 1; i > 0; i--) {
_node[i] = _merge(_node[i << 1], _node[i << 1 | 1]);
}
}
public void Set(int index, TMonoid val) {
int p = index + Count;
_node[p] = val;
while (p > 0) {
p >>= 1;
_node[p] = _merge(_node[p << 1], _node[p << 1 | 1]);
}
}
public TMonoid Query(int begin, int end) {
TMonoid lv = _identity, rv = _identity;
int l = begin + Count;
int r = end + Count - 1;
for (; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1) {
lv = _merge(lv, _node[l++]);
}
if ((r & 1) == 0) {
rv = _merge(_node[r--], rv);
}
}
return _merge(lv, rv);
}
public TMonoid this[int index] {
get { return _node[index + Count]; }
set { Set(index, value); }
}
};
public partial class MultiSet<T> {
private readonly LLRBTreeNode<T> end = new LLRBTreeNode<T>(default(T));
private LLRBTreeNode<T> root = null;
private readonly Comparison<T> _comparer;
public MultiSet() : this(Comparer<T>.Default.Compare) {}
public MultiSet(Comparison<T> comparer) {
_comparer = comparer;
root = end;
}
protected virtual bool AllowMultiple {
get { return true; }
}
public int Count {
get {
return root == null
? 0
: root.Count + root.LeftTotalCount + root.RightTotalCount - 1;
}
}
private LLRBTreeNode<T> FindNode(T value) {
var node = root;
while (node != null) {
int cmp = Compare(value, node);
if (cmp == 0) {
return node;
}
node = (cmp < 0) ? node.Left : node.Right;
}
return null;
}
public void Clear() { root = end; }
public bool Contains(T value) {
var node = FindNode(value);
return node != null;
}
public int CountOf(T value) {
var node = FindNode(value);
return node != null ? node.Count : 0;
}
public int IndexOfLowerBound(T value) {
var node = root;
int index = 0;
while (node != null) {
int cmp = Compare(value, node);
if (cmp <= 0) {
node = node.Left;
} else {
index += node.LeftTotalCount + node.Count;
node = node.Right;
}
}
return index;
}
private int Compare(T value, LLRBTreeNode<T> node) {
if (node == end) {
return -1;
}
return _comparer(value, node.Value);
}
public int IndexOfUpperBound(T value) {
var node = root;
int index = 0;
while (node != null) {
int cmp = Compare(value, node);
if (cmp < 0) {
node = node.Left;
} else {
index += node.LeftTotalCount + node.Count;
node = node.Right;
}
}
return index;
}
public T At(int index) {
var node = root;
while (node != null) {
int leftCount = node.LeftTotalCount;
if (leftCount <= index && index < leftCount + node.Count) {
return node.Value;
}
if (index < leftCount) {
node = node.Left;
} else {
index -= leftCount + node.Count;
node = node.Right;
}
}
throw new ArgumentOutOfRangeException("index");
}
public T Min() { return At(0); }
public T Max() { return At(Count - 1); }
public LLRBTreeIterator<T> AtIterator(int index) {
var node = root;
while (node != null) {
int leftCount = node.LeftTotalCount;
if (leftCount <= index && index < leftCount + node.Count) {
return new LLRBTreeIterator<T>(node, index - leftCount);
}
if (index < leftCount) {
node = node.Left;
} else {
index -= leftCount + node.Count;
node = node.Right;
}
}
throw new ArgumentOutOfRangeException("index");
}
public void Add(T value) {
root = Add(root, value);
root.Color = LLRBTreeNode<T>.BLACK;
}
private LLRBTreeNode<T> Add(LLRBTreeNode<T> h, T value) {
if (h == null) {
return new LLRBTreeNode<T>(value);
}
int cmp = Compare(value, h);
if (cmp == 0) {
if (AllowMultiple) {
h.Count++;
FixCount(h);
}
} else if (cmp <= 0) {
h.Left = Add(h.Left, value);
FixCount(h);
} else {
h.Right = Add(h.Right, value);
FixCount(h);
}
if (IsRed(h.Right) && !IsRed(h.Left)) {
h = RotateLeft(h);
}
if (IsRed(h.Left) && IsRed(h.Left.Left)) {
h = RotateRight(h);
}
if (IsRed(h.Left) && IsRed(h.Right)) {
ColorFlip(h);
}
return h;
}
private LLRBTreeNode<T> RemoveLeftestNode(LLRBTreeNode<T> h,
out LLRBTreeNode<T> leftMost) {
if (h.Left == null) {
leftMost = h;
return null;
}
if (!IsRed(h.Left) && !IsRed(h.Left.Left)) {
h = MoveRedLeft(h);
}
h.Left = RemoveLeftestNode(h.Left, out leftMost);
return FixUp(h);
}
private bool TryReduceCount(LLRBTreeNode<T> h, T value, out int num) {
num = 0;
if (h == null) {
return false;
}
int cmp = Compare(value, h);
if (cmp == 0) {
num = h.Count;
if (h.Count > 1) {
h.Count--;
FixCount(h);
return true;
}
return false;
}
if (TryReduceCount((cmp < 0) ? h.Left : h.Right, value, out num)) {
FixCount(h);
return true;
}
return false;
}
public bool Remove(T value) {
if (AllowMultiple) {
int num;
if (TryReduceCount(root, value, out num)) {
return true;
}
if (num == 0) {
return false;
}
} else {
if (!Contains(value)) {
return false;
}
}
root = RemoveNode(root, value);
if (root != null) {
root.Color = LLRBTreeNode<T>.BLACK;
}
return true;
}
private LLRBTreeNode<T> RemoveNode(LLRBTreeNode<T> h, T value) {
if (Compare(value, h) < 0) {
if (h.Left == null) {
throw new KeyNotFoundException("value");
}
if (!IsRed(h.Left) && !IsRed(h.Left.Left)) {
h = MoveRedLeft(h);
}
h.Left = RemoveNode(h.Left, value);
FixCount(h);
} else {
if (IsRed(h.Left)) {
h = RotateRight(h);
}
if (h.Right == null) {
if (Compare(value, h) == 0) {
return null;
}
throw new KeyNotFoundException("value");
}
if (!IsRed(h.Right) && !IsRed(h.Right.Left)) {
h = MoveRedRight(h);
}
if (Compare(value, h) == 0) {
LLRBTreeNode<T> sub;
h.Right = RemoveLeftestNode(h.Right, out sub);
h = Substitute(h, sub);
FixCount(h);
} else {
h.Right = RemoveNode(h.Right, value);
FixCount(h);
}
}
return FixUp(h);
}
private static LLRBTreeNode<T> Substitute(LLRBTreeNode<T> node,
LLRBTreeNode<T> sub) {
sub.Parent = node.Parent;
sub.Left = node.Left;
sub.Right = node.Right;
sub.TotalCount = node.TotalCount;
sub.Color = node.Color;
if (sub.Parent != null) {
if (sub.Parent.Left == node) {
sub.Parent.Left = sub;
}
if (sub.Parent.Right == node) {
sub.Parent.Right = sub;
}
}
if (sub.Left != null) {
sub.Left.Parent = sub;
}
if (sub.Right != null) {
sub.Right.Parent = sub;
}
return sub;
}
private static LLRBTreeNode<T> MoveRedLeft(LLRBTreeNode<T> h) {
ColorFlip(h);
if (IsRed(h.Right.Left)) {
h.Right = RotateRight(h.Right);
FixCount(h);
h = RotateLeft(h);
ColorFlip(h);
}
return h;
}
private static LLRBTreeNode<T> MoveRedRight(LLRBTreeNode<T> h) {
ColorFlip(h);
if (IsRed(h.Left.Left)) {
h = RotateRight(h);
ColorFlip(h);
}
return h;
}
private static LLRBTreeNode<T> RotateLeft(LLRBTreeNode<T> h) {
var x = h.Right;
h.Right = x.Left;
x.Left = h;
x.Color = h.Color;
h.Color = LLRBTreeNode<T>.RED;
FixCount(h);
FixCount(x);
return x;
}
private static LLRBTreeNode<T> RotateRight(LLRBTreeNode<T> h) {
var x = h.Left;
h.Left = x.Right;
x.Right = h;
x.Color = h.Color;
h.Color = LLRBTreeNode<T>.RED;
FixCount(h);
FixCount(x);
return x;
}
private static bool IsRed(LLRBTreeNode<T> h) {
return h != null && h.Color == LLRBTreeNode<T>.RED;
}
private static void ColorFlip(LLRBTreeNode<T> h) {
h.Color = !h.Color;
h.Left.Color = !h.Left.Color;
h.Right.Color = !h.Right.Color;
}
private static LLRBTreeNode<T> FixUp(LLRBTreeNode<T> h) {
if (IsRed(h.Right)) {
h = RotateLeft(h);
}
if (h.Left != null && IsRed(h.Left) && IsRed(h.Left.Left)) {
h = RotateRight(h);
}
if (IsRed(h.Left) && IsRed(h.Right)) {
ColorFlip(h);
}
FixCount(h);
return h;
}
private static void FixCount(LLRBTreeNode<T> node) {
node.TotalCount = node.Count + node.LeftTotalCount + node.RightTotalCount;
}
public void Debug() {
if (root != null) {
root.Debug();
}
}
}
public partial class Set<T> : MultiSet<T> {
protected override bool AllowMultiple {
get { return false; }
}
}
public class LLRBTreeNode<T> {
public const bool RED = true;
public const bool BLACK = false;
public T Value;
public bool Color = RED;
public LLRBTreeNode<T> Parent { get; set; }
private LLRBTreeNode<T> _left;
private LLRBTreeNode<T> _right;
public LLRBTreeNode<T> Left {
get { return _left; }
set {
if (_left != null && _left.Parent == this) {
_left.Parent = null;
}
_left = value;
if (_left != null) {
_left.Parent = this;
}
}
}
public LLRBTreeNode<T> Right {
get { return _right; }
set {
if (_right != null && _right.Parent == this) {
_right.Parent = null;
}
_right = value;
if (_right != null) {
_right.Parent = this;
}
}
}
public int Count = 1;
public LLRBTreeNode(T value) { Value = value; }
public int TotalCount = 1;
public int LeftTotalCount {
get { return Left == null ? 0 : Left.TotalCount; }
}
public int RightTotalCount {
get { return Right == null ? 0 : Right.TotalCount; }
}
public void Debug(string indent = "") {
Console.WriteLine(indent + ":" + Value + " - " + Count + " - " +
TotalCount);
if (Left != null) {
if (Left.Parent != this) {
Console.WriteLine("Missing Parent");
}
Left.Debug(indent + "L");
}
if (Right != null) {
if (Right.Parent != this) {
Console.WriteLine("Missing Parent");
}
Right.Debug(indent + "R");
}
}
}
public class LLRBTreeIterator<T> {
private readonly LLRBTreeNode<T> _node;
private readonly int _index;
public LLRBTreeIterator(LLRBTreeNode<T> node, int index = 0) {
_node = node;
_index = index;
}
public T Value {
get { return _node.Value; }
}
public static LLRBTreeIterator<T> operator ++(LLRBTreeIterator<T> x) {
return x.GetSuccessor();
}
public static LLRBTreeIterator<T> operator --(LLRBTreeIterator<T> x) {
return x.GetPredecessor();
}
private LLRBTreeIterator<T> GetSuccessor() {
if (_index + 1 < _node.Count) {
return new LLRBTreeIterator<T>(_node, _index + 1);
} else {
LLRBTreeNode<T> current, parent;
if (_node.Right == null) {
for (current = _node, parent = _node.Parent; parent.Right == current;
current = parent, parent = current.Parent) {
;
}
return new LLRBTreeIterator<T>(parent);
} else {
for (parent = _node.Right, current = parent.Left; current != null;
parent = current, current = parent.Left) {
;
}
return new LLRBTreeIterator<T>(parent);
}
}
}
private LLRBTreeIterator<T> GetPredecessor() {
if (0 <= _index - 1) {
return new LLRBTreeIterator<T>(_node, _index - 1);
} else {
LLRBTreeNode<T> current, parent;
if (_node.Left == null) {
for (current = _node, parent = _node.Parent; parent.Left == current;
current = parent, parent = current.Parent) {
;
}
return new LLRBTreeIterator<T>(parent, parent.Count - 1);
} else {
for (parent = _node.Left, current = parent.Right; current != null;
parent = current, current = parent.Right) {
;
}
return new LLRBTreeIterator<T>(parent, parent.Count - 1);
}
}
}
}
public partial class MultiSet<T> : IEnumerable<T> {
public IEnumerator<T> GetEnumerator() {
var node = root;
var stack = new Stack<LLRBTreeNode<T>>();
while (node != null || stack.Count > 0) {
while (node != null) {
stack.Push(node);
node = node.Left;
}
node = stack.Pop();
if (node == end) {
break;
}
int count = node.Count;
for (int i = 0; i < count; i++) {
yield return node.Value;
}
node = node.Right;
}
}
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
using E = System.Linq.Enumerable;
using System.Threading;
internal partial class Solver {
public void Run() {
var h = ni();
var w = ni();
var a = new int[h];
var b = new int[h];
for (int i = 0; i < h; i++) {
a[i] = ni() - 1;
b[i] = ni() - 1;
}
var ranges = new MultiSet<(int begin, int end, int value)>();
ranges.Add((-10, 0, -1000000));
for (int i = 0; i < w; i++) {
ranges.Add((i, i + 1, i));
}
var seg = new SegmentTree<long>((x, y) => Math.Min(x, y), long.MaxValue);
seg.Build(w, i => 0);
for (int i = 0; i < h; i++) {
var begin = ranges.IndexOfLowerBound((a[i], -1, -1)) - 1;
var changed = new List<(int begin, int end, int value)>();
var prev = ranges.At(begin);
if (b[i] + 1 > prev.end) {
ranges.Remove(prev);
prev.end = b[i] + 1;
ranges.Add(prev);
if (prev.value >= 0)
seg[prev.value] = prev.begin - prev.value;
for (int j = begin + 1; j < ranges.Count; j++) {
var val = ranges.At(j);
if (val.begin < prev.end) {
changed.Add(val);
} else {
break;
}
}
foreach (var c in changed) {
ranges.Remove(c);
if (c.value >= 0)
seg[c.value] = long.MaxValue;
var v = c;
v.begin = prev.end;
if (v.begin < v.end) {
ranges.Add(v);
if (v.value >= 0) {
seg[v.value] = v.begin - v.value;
}
}
}
}
// ranges.TextDump();
// E.Range(0, w).Select(j => seg[j]).TextDump();
var ans = seg.Query(0, seg.Count);
if (ans <= w)
cout.WriteLine(ans + i + 1);
else
cout.WriteLine(-1);
}
}
public static int MoveUntil(int ok, int ng, Predicate<int> predicate) {
if (ok == ng)
throw new Exception();
while (Math.Abs(ok - ng) > 1) {
var mid = (ok + ng) >> 1;
if (predicate(mid)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
}
public sealed class SegmentTree<TMonoid> {
public int Count { get; private set; }
private TMonoid[] _node;
private readonly TMonoid _identity;
private readonly Func<TMonoid, TMonoid, TMonoid> _merge;
public SegmentTree(Func<TMonoid, TMonoid, TMonoid> merge, TMonoid identity) {
_merge = merge;
_identity = identity;
}
public void Build(IList<TMonoid> array) { Build(array.Count, i => array[i]); }
public void Build(int n, Func<int, TMonoid> create) {
Count = n;
_node = new TMonoid[2 * Count];
for (int i = 0; i < n; i++) {
_node[i + Count] = create(i);
}
for (int i = Count - 1; i > 0; i--) {
_node[i] = _merge(_node[i << 1], _node[i << 1 | 1]);
}
}
public void Set(int index, TMonoid val) {
int p = index + Count;
_node[p] = val;
while (p > 0) {
p >>= 1;
_node[p] = _merge(_node[p << 1], _node[p << 1 | 1]);
}
}
public TMonoid Query(int begin, int end) {
TMonoid lv = _identity, rv = _identity;
int l = begin + Count;
int r = end + Count - 1;
for (; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1) {
lv = _merge(lv, _node[l++]);
}
if ((r & 1) == 0) {
rv = _merge(_node[r--], rv);
}
}
return _merge(lv, rv);
}
public TMonoid this[int index] {
get { return _node[index + Count]; }
set { Set(index, value); }
}
};
public partial class MultiSet<T> {
private readonly LLRBTreeNode<T> end = new LLRBTreeNode<T>(default(T));
private LLRBTreeNode<T> root = null;
private readonly Comparison<T> _comparer;
public MultiSet() : this(Comparer<T>.Default.Compare) {}
public MultiSet(Comparison<T> comparer) {
_comparer = comparer;
root = end;
}
protected virtual bool AllowMultiple {
get { return true; }
}
public int Count {
get {
return root == null
? 0
: root.Count + root.LeftTotalCount + root.RightTotalCount - 1;
}
}
private LLRBTreeNode<T> FindNode(T value) {
var node = root;
while (node != null) {
int cmp = Compare(value, node);
if (cmp == 0) {
return node;
}
node = (cmp < 0) ? node.Left : node.Right;
}
return null;
}
public void Clear() { root = end; }
public bool Contains(T value) {
var node = FindNode(value);
return node != null;
}
public int CountOf(T value) {
var node = FindNode(value);
return node != null ? node.Count : 0;
}
public int IndexOfLowerBound(T value) {
var node = root;
int index = 0;
while (node != null) {
int cmp = Compare(value, node);
if (cmp <= 0) {
node = node.Left;
} else {
index += node.LeftTotalCount + node.Count;
node = node.Right;
}
}
return index;
}
private int Compare(T value, LLRBTreeNode<T> node) {
if (node == end) {
return -1;
}
return _comparer(value, node.Value);
}
public int IndexOfUpperBound(T value) {
var node = root;
int index = 0;
while (node != null) {
int cmp = Compare(value, node);
if (cmp < 0) {
node = node.Left;
} else {
index += node.LeftTotalCount + node.Count;
node = node.Right;
}
}
return index;
}
public T At(int index) {
var node = root;
while (node != null) {
int leftCount = node.LeftTotalCount;
if (leftCount <= index && index < leftCount + node.Count) {
return node.Value;
}
if (index < leftCount) {
node = node.Left;
} else {
index -= leftCount + node.Count;
node = node.Right;
}
}
throw new ArgumentOutOfRangeException("index");
}
public T Min() { return At(0); }
public T Max() { return At(Count - 1); }
public LLRBTreeIterator<T> AtIterator(int index) {
var node = root;
while (node != null) {
int leftCount = node.LeftTotalCount;
if (leftCount <= index && index < leftCount + node.Count) {
return new LLRBTreeIterator<T>(node, index - leftCount);
}
if (index < leftCount) {
node = node.Left;
} else {
index -= leftCount + node.Count;
node = node.Right;
}
}
throw new ArgumentOutOfRangeException("index");
}
public void Add(T value) {
root = Add(root, value);
root.Color = LLRBTreeNode<T>.BLACK;
}
private LLRBTreeNode<T> Add(LLRBTreeNode<T> h, T value) {
if (h == null) {
return new LLRBTreeNode<T>(value);
}
int cmp = Compare(value, h);
if (cmp == 0) {
if (AllowMultiple) {
h.Count++;
FixCount(h);
}
} else if (cmp <= 0) {
h.Left = Add(h.Left, value);
FixCount(h);
} else {
h.Right = Add(h.Right, value);
FixCount(h);
}
if (IsRed(h.Right) && !IsRed(h.Left)) {
h = RotateLeft(h);
}
if (IsRed(h.Left) && IsRed(h.Left.Left)) {
h = RotateRight(h);
}
if (IsRed(h.Left) && IsRed(h.Right)) {
ColorFlip(h);
}
return h;
}
private LLRBTreeNode<T> RemoveLeftestNode(LLRBTreeNode<T> h,
out LLRBTreeNode<T> leftMost) {
if (h.Left == null) {
leftMost = h;
return null;
}
if (!IsRed(h.Left) && !IsRed(h.Left.Left)) {
h = MoveRedLeft(h);
}
h.Left = RemoveLeftestNode(h.Left, out leftMost);
return FixUp(h);
}
private bool TryReduceCount(LLRBTreeNode<T> h, T value, out int num) {
num = 0;
if (h == null) {
return false;
}
int cmp = Compare(value, h);
if (cmp == 0) {
num = h.Count;
if (h.Count > 1) {
h.Count--;
FixCount(h);
return true;
}
return false;
}
if (TryReduceCount((cmp < 0) ? h.Left : h.Right, value, out num)) {
FixCount(h);
return true;
}
return false;
}
public bool Remove(T value) {
if (AllowMultiple) {
int num;
if (TryReduceCount(root, value, out num)) {
return true;
}
if (num == 0) {
return false;
}
} else {
if (!Contains(value)) {
return false;
}
}
root = RemoveNode(root, value);
if (root != null) {
root.Color = LLRBTreeNode<T>.BLACK;
}
return true;
}
private LLRBTreeNode<T> RemoveNode(LLRBTreeNode<T> h, T value) {
if (Compare(value, h) < 0) {
if (h.Left == null) {
throw new KeyNotFoundException("value");
}
if (!IsRed(h.Left) && !IsRed(h.Left.Left)) {
h = MoveRedLeft(h);
}
h.Left = RemoveNode(h.Left, value);
FixCount(h);
} else {
if (IsRed(h.Left)) {
h = RotateRight(h);
}
if (h.Right == null) {
if (Compare(value, h) == 0) {
return null;
}
throw new KeyNotFoundException("value");
}
if (!IsRed(h.Right) && !IsRed(h.Right.Left)) {
h = MoveRedRight(h);
}
if (Compare(value, h) == 0) {
LLRBTreeNode<T> sub;
h.Right = RemoveLeftestNode(h.Right, out sub);
h = Substitute(h, sub);
FixCount(h);
} else {
h.Right = RemoveNode(h.Right, value);
FixCount(h);
}
}
return FixUp(h);
}
private static LLRBTreeNode<T> Substitute(LLRBTreeNode<T> node,
LLRBTreeNode<T> sub) {
sub.Parent = node.Parent;
sub.Left = node.Left;
sub.Right = node.Right;
sub.TotalCount = node.TotalCount;
sub.Color = node.Color;
if (sub.Parent != null) {
if (sub.Parent.Left == node) {
sub.Parent.Left = sub;
}
if (sub.Parent.Right == node) {
sub.Parent.Right = sub;
}
}
if (sub.Left != null) {
sub.Left.Parent = sub;
}
if (sub.Right != null) {
sub.Right.Parent = sub;
}
return sub;
}
private static LLRBTreeNode<T> MoveRedLeft(LLRBTreeNode<T> h) {
ColorFlip(h);
if (IsRed(h.Right.Left)) {
h.Right = RotateRight(h.Right);
FixCount(h);
h = RotateLeft(h);
ColorFlip(h);
}
return h;
}
private static LLRBTreeNode<T> MoveRedRight(LLRBTreeNode<T> h) {
ColorFlip(h);
if (IsRed(h.Left.Left)) {
h = RotateRight(h);
ColorFlip(h);
}
return h;
}
private static LLRBTreeNode<T> RotateLeft(LLRBTreeNode<T> h) {
var x = h.Right;
h.Right = x.Left;
x.Left = h;
x.Color = h.Color;
h.Color = LLRBTreeNode<T>.RED;
FixCount(h);
FixCount(x);
return x;
}
private static LLRBTreeNode<T> RotateRight(LLRBTreeNode<T> h) {
var x = h.Left;
h.Left = x.Right;
x.Right = h;
x.Color = h.Color;
h.Color = LLRBTreeNode<T>.RED;
FixCount(h);
FixCount(x);
return x;
}
private static bool IsRed(LLRBTreeNode<T> h) {
return h != null && h.Color == LLRBTreeNode<T>.RED;
}
private static void ColorFlip(LLRBTreeNode<T> h) {
h.Color = !h.Color;
h.Left.Color = !h.Left.Color;
h.Right.Color = !h.Right.Color;
}
private static LLRBTreeNode<T> FixUp(LLRBTreeNode<T> h) {
if (IsRed(h.Right)) {
h = RotateLeft(h);
}
if (h.Left != null && IsRed(h.Left) && IsRed(h.Left.Left)) {
h = RotateRight(h);
}
if (IsRed(h.Left) && IsRed(h.Right)) {
ColorFlip(h);
}
FixCount(h);
return h;
}
private static void FixCount(LLRBTreeNode<T> node) {
node.TotalCount = node.Count + node.LeftTotalCount + node.RightTotalCount;
}
public void Debug() {
if (root != null) {
root.Debug();
}
}
}
public partial class Set<T> : MultiSet<T> {
protected override bool AllowMultiple {
get { return false; }
}
}
public class LLRBTreeNode<T> {
public const bool RED = true;
public const bool BLACK = false;
public T Value;
public bool Color = RED;
public LLRBTreeNode<T> Parent { get; set; }
private LLRBTreeNode<T> _left;
private LLRBTreeNode<T> _right;
public LLRBTreeNode<T> Left {
get { return _left; }
set {
if (_left != null && _left.Parent == this) {
_left.Parent = null;
}
_left = value;
if (_left != null) {
_left.Parent = this;
}
}
}
public LLRBTreeNode<T> Right {
get { return _right; }
set {
if (_right != null && _right.Parent == this) {
_right.Parent = null;
}
_right = value;
if (_right != null) {
_right.Parent = this;
}
}
}
public int Count = 1;
public LLRBTreeNode(T value) { Value = value; }
public int TotalCount = 1;
public int LeftTotalCount {
get { return Left == null ? 0 : Left.TotalCount; }
}
public int RightTotalCount {
get { return Right == null ? 0 : Right.TotalCount; }
}
public void Debug(string indent = "") {
Console.WriteLine(indent + ":" + Value + " - " + Count + " - " +
TotalCount);
if (Left != null) {
if (Left.Parent != this) {
Console.WriteLine("Missing Parent");
}
Left.Debug(indent + "L");
}
if (Right != null) {
if (Right.Parent != this) {
Console.WriteLine("Missing Parent");
}
Right.Debug(indent + "R");
}
}
}
public class LLRBTreeIterator<T> {
private readonly LLRBTreeNode<T> _node;
private readonly int _index;
public LLRBTreeIterator(LLRBTreeNode<T> node, int index = 0) {
_node = node;
_index = index;
}
public T Value {
get { return _node.Value; }
}
public static LLRBTreeIterator<T> operator ++(LLRBTreeIterator<T> x) {
return x.GetSuccessor();
}
public static LLRBTreeIterator<T> operator --(LLRBTreeIterator<T> x) {
return x.GetPredecessor();
}
private LLRBTreeIterator<T> GetSuccessor() {
if (_index + 1 < _node.Count) {
return new LLRBTreeIterator<T>(_node, _index + 1);
} else {
LLRBTreeNode<T> current, parent;
if (_node.Right == null) {
for (current = _node, parent = _node.Parent; parent.Right == current;
current = parent, parent = current.Parent) {
;
}
return new LLRBTreeIterator<T>(parent);
} else {
for (parent = _node.Right, current = parent.Left; current != null;
parent = current, current = parent.Left) {
;
}
return new LLRBTreeIterator<T>(parent);
}
}
}
private LLRBTreeIterator<T> GetPredecessor() {
if (0 <= _index - 1) {
return new LLRBTreeIterator<T>(_node, _index - 1);
} else {
LLRBTreeNode<T> current, parent;
if (_node.Left == null) {
for (current = _node, parent = _node.Parent; parent.Left == current;
current = parent, parent = current.Parent) {
;
}
return new LLRBTreeIterator<T>(parent, parent.Count - 1);
} else {
for (parent = _node.Left, current = parent.Right; current != null;
parent = current, current = parent.Right) {
;
}
return new LLRBTreeIterator<T>(parent, parent.Count - 1);
}
}
}
}
public partial class MultiSet<T> : IEnumerable<T> {
public IEnumerator<T> GetEnumerator() {
var node = root;
var stack = new Stack<LLRBTreeNode<T>>();
while (node != null || stack.Count > 0) {
while (node != null) {
stack.Push(node);
node = node.Left;
}
node = stack.Pop();
if (node == end) {
break;
}
int count = node.Count;
for (int i = 0; i < count; i++) {
yield return node.Value;
}
node = node.Right;
}
}
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
// PREWRITEN CODE BEGINS FROM HERE
static public class StringExtensions {
static public string JoinToString<T>(this IEnumerable<T> source,
string separator = " ") {
return string.Join(separator, source);
}
}
internal partial class Solver : Scanner {
static readonly int? StackSizeInMebiByte = null; // 50;
public static void StartAndJoin(Action action, int maxStackSize) {
var thread = new Thread(new ThreadStart(action), maxStackSize);
thread.Start();
thread.Join();
}
public static void Main() {
#if LOCAL
byte[] inputBuffer = new byte[1000000];
var inputStream = Console.OpenStandardInput(inputBuffer.Length);
using (var reader = new StreamReader(inputStream, Console.InputEncoding,
false, inputBuffer.Length)) {
Console.SetIn(reader);
new Solver(Console.In, Console.Out).Run();
}
#else
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (StackSizeInMebiByte.HasValue) {
StartAndJoin(() => new Solver(Console.In, Console.Out).Run(),
StackSizeInMebiByte.Value * 1024 * 1024);
} else {
new Solver(Console.In, Console.Out).Run();
}
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
private readonly TextWriter cerr;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
cerr = Console.Error;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
#if DEBUG
internal static class LinqPadExtension {
public static string TextDump<T>(this T obj) {
if (obj is IEnumerable)
return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
else
return obj.ToString().Dump();
}
public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); }
}
#endif
public class Scanner {
private readonly TextReader Reader;
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
private readonly char[] buffer = new char[2 * 1024];
private int cursor = 0, length = 0;
private string Token;
private readonly StringBuilder sb = new StringBuilder(1024);
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return checked((int)NextLong()); }
public long NextLong() {
var s = Next();
long r = 0;
int i = 0;
bool negative = false;
if (s[i] == '-') {
negative = true;
i++;
}
for (; i < s.Length; i++) {
r = r * 10 + (s[i] - '0');
#if DEBUG
if (!char.IsDigit(s[i]))
throw new FormatException();
#endif
}
return negative ? -r : r;
}
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
string[] array = new string[size];
for (int i = 0; i < size; i++) {
array[i] = Next();
}
return array;
}
public int[] NextIntArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = NextInt();
}
return array;
}
public long[] NextLongArray(int size) {
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = NextLong();
}
return array;
}
public double[] NextDoubleArray(int size) {
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = NextDouble();
}
return array;
}
public string Next() {
if (Token == null) {
if (!StockToken()) {
throw new Exception();
}
}
var token = Token;
Token = null;
return token;
}
public bool HasNext() {
if (Token != null) {
return true;
}
return StockToken();
}
private bool StockToken() {
while (true) {
sb.Clear();
while (true) {
if (cursor >= length) {
cursor = 0;
if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
break;
}
}
var c = buffer[cursor++];
if (33 <= c && c <= 126) {
sb.Append(c);
} else {
if (sb.Length > 0)
break;
}
}
if (sb.Length > 0) {
Token = sb.ToString();
return true;
}
return false;
}
}
}
|
[["-", 0, 28, 0, 288, 0, 28, 0, 241, 0, 203], ["+", 0, 28, 0, 288, 0, 28, 0, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 5,213
| 14
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
Console.WriteLine(Scanner.Integer() % 1000);
}
// 以下ユーティリティー
static readonly StreamScanner Scanner =
new StreamScanner(Console.OpenStandardInput());
/// <summary> 数値読み込み </summary>
private static List<long> ScanLong(int count = 0) {
var scan = new List<long>();
for (int i = 0; i < count; i++) {
scan.Add(Scanner.Long());
}
return scan;
}
/// <summary> 一括出力 </summary>
private static void OutAllLine(IEnumerable<dynamic> items) {
var sb = new StringBuilder();
foreach (var result in items) {
sb.Append(result + "\n");
}
sb = sb.Remove(sb.Length - 1, 1);
Console.WriteLine(sb);
}
/// <summary> 素数判定 </summary>
public static bool IsPrime(int num) {
if (num < 2) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static IEnumerable<int> PrimeFactors(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var price = Scanner.Integer();
while (price > 0) {
price -= 1000;
}
Console.WriteLine(-price);
}
// 以下ユーティリティー
static readonly StreamScanner Scanner =
new StreamScanner(Console.OpenStandardInput());
/// <summary> 数値読み込み </summary>
private static List<long> ScanLong(int count = 0) {
var scan = new List<long>();
for (int i = 0; i < count; i++) {
scan.Add(Scanner.Long());
}
return scan;
}
/// <summary> 一括出力 </summary>
private static void OutAllLine(IEnumerable<dynamic> items) {
var sb = new StringBuilder();
foreach (var result in items) {
sb.Append(result + "\n");
}
sb = sb.Remove(sb.Length - 1, 1);
Console.WriteLine(sb);
}
/// <summary> 素数判定 </summary>
public static bool IsPrime(int num) {
if (num < 2) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static IEnumerable<int> PrimeFactors(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 22]]
| 8
| 725
| 26
|
//
// ABC173A
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace AtCoder.Template.ABC173A {
class Solver {
public static readonly long MOD_CONST =
1000000007; //(long)Math.Pow(10, 9) + 7;
public static void Main(string[] args) {
//出力高速化
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
public void Solve() {
int n = int.Parse(Console.ReadLine());
int o = n % 1000;
Console.WriteLine(o);
}
//---------------------------------------------------------------------------------
#region MyLib
/// <summary>
/// リストから、重複したものを除外したリストを新規に作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="src"></param>
/// <param name="dst"></param>
public static void getDistinctList<T>(List<T> src, out List<T> dst) {
var iter = src.Distinct();
dst = new List<T>();
foreach (var item in iter) {
dst.Add(item);
}
}
/// <summary>
/// グラフ系
/// </summary>
public class Node {
public Node(long val) {
this.Value = val;
this.Children = new List<Node>();
}
public Node(long val, List<Node> children) {
this.Value = val;
this.Children = children;
}
public long Value { get; set; }
public List<Node> Children { get; set; }
}
/// <summary>
/// Clamping
/// </summary>
/// <typeparam name="T">比較型</typeparam>
/// <param name="x">clampしたい値</param>
/// <param name="min">最小値</param>
/// <param name="max">最大値</param>
/// <returns>clamp済みの値</returns>
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T> {
if (x.CompareTo(min) < 0) {
return min;
} else if (x.CompareTo(max) > 0) {
return max;
} else
return x;
// return Math.Max(Math.Min(x, max), min);
}
/// <summary>
/// 指定された底log_baseでの, 対数を計算
/// </summary>
/// <param name="x"></param>
/// <param name="log_base">指定の底</param>
/// <returns></returns>
public static double LogBase(double x, double log_base) {
// log_b(N) = log_a(N) / log_a(B)より
return Math.Log(x) / Math.Log(log_base);
}
/// <summary>
/// 初項a, 公差d, 項数nの数列の和
/// </summary>
/// <param name="n">求めたいところ</param>
/// <returns>初項からxまで足した値</returns>
static long SumSeries(long a, long d, long n) {
return (2 * a + (n - 1) * d) * n / 2;
}
/// <summary>
/// 累積和の配列を計算する
/// Sum[ a[0], a[i] )がs[i+1]に入っている
/// s[0] : 0 //一切和を取らない場合
/// s[1] : ls[0] //a[0] + s[0] = a[0]
/// s[2] : ls[1] + s[1] //a[1] + a[0]
/// ...
/// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0]
/// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0]
///
/// 例: [1, 7)の和(a[1] + ... + a[6])
/// s[1] = a[0] //[0, 1)
/// s[7] = a[0] + a[1] + ... + a[6] //[0, 7)
/// よってs[7] - s[1]);
/// </summary>
/// <param name="ls">計算したい配列</param>
/// <returns>累積和配列</returns>
static List<long> AggregateSumList(List<long> a) {
var s = new List<long>(a.Count + 1);
if (a.Count == 0) {
return s;
}
s.Add(0); // s[0] = 0
for (int i = 0; i < a.Count; ++i) {
s.Add(a[i] + s[i]);
}
return s;
}
/// <summary>
/// 与えられた数が素数かどうかを計算する
/// </summary>
/// <param name="num">対象数</param>
/// <returns>true:素数, false:素数ではない(合成数)</returns>
public static bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
/// <summary>
/// 素因数分解
/// </summary>
/// <param name="n"></param>
/// <returns>keyが素数、valueがその素数の登場回数</returns>
public static Dictionary<long, long> PrimeFactorization(long n) {
var result = new Dictionary<long, long>();
//初めの素数2から割っていく
for (long p = 2; p * p <= n; p++) {
//割り切れないなら、素因数に含まれてない
if (n % p != 0)
continue;
long count = 0;
// 割り続ける
while (n % p == 0) {
count++;
n /= p;
}
result[p] = count;
}
// 素数が残っている場合
if (n != 1)
result[n] = 1;
return result;
}
/// <summary>
/// 順列mPnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Permutation(long m, long n) {
long ret = 1;
for (var i = 0; i < n; ++i) {
ret *= m - i;
}
return ret;
}
/// <summary>
/// 組み合わせmCnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Combination(long m, long n) {
if (m == n || n == 0) {
return 1;
}
long ans = 1;
for (var i = 1; i <= n; ++i) {
ans = ans * (m - i + 1) / i;
}
return ans;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
static long Lcm(long m, long n) {
var gcd = Gcd(m, n);
// return (m * n) / gcd;
return m / gcd * n; //桁あふれ対策
}
#endregion MyLib
}
}
|
//
// ABC173A
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace AtCoder.Template.ABC173A {
class Solver {
public static readonly long MOD_CONST =
1000000007; //(long)Math.Pow(10, 9) + 7;
public static void Main(string[] args) {
//出力高速化
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var solver = new Solver();
solver.Solve();
Console.Out.Flush();
}
public void Solve() {
int n = int.Parse(Console.ReadLine());
int hasu = n % 1000; //端数
if (hasu == 0) {
Console.WriteLine(0);
} else {
Console.WriteLine(1000 - hasu);
}
}
//---------------------------------------------------------------------------------
#region MyLib
/// <summary>
/// リストから、重複したものを除外したリストを新規に作成する
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="src"></param>
/// <param name="dst"></param>
public static void getDistinctList<T>(List<T> src, out List<T> dst) {
var iter = src.Distinct();
dst = new List<T>();
foreach (var item in iter) {
dst.Add(item);
}
}
/// <summary>
/// グラフ系
/// </summary>
public class Node {
public Node(long val) {
this.Value = val;
this.Children = new List<Node>();
}
public Node(long val, List<Node> children) {
this.Value = val;
this.Children = children;
}
public long Value { get; set; }
public List<Node> Children { get; set; }
}
/// <summary>
/// Clamping
/// </summary>
/// <typeparam name="T">比較型</typeparam>
/// <param name="x">clampしたい値</param>
/// <param name="min">最小値</param>
/// <param name="max">最大値</param>
/// <returns>clamp済みの値</returns>
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T> {
if (x.CompareTo(min) < 0) {
return min;
} else if (x.CompareTo(max) > 0) {
return max;
} else
return x;
// return Math.Max(Math.Min(x, max), min);
}
/// <summary>
/// 指定された底log_baseでの, 対数を計算
/// </summary>
/// <param name="x"></param>
/// <param name="log_base">指定の底</param>
/// <returns></returns>
public static double LogBase(double x, double log_base) {
// log_b(N) = log_a(N) / log_a(B)より
return Math.Log(x) / Math.Log(log_base);
}
/// <summary>
/// 初項a, 公差d, 項数nの数列の和
/// </summary>
/// <param name="n">求めたいところ</param>
/// <returns>初項からxまで足した値</returns>
static long SumSeries(long a, long d, long n) {
return (2 * a + (n - 1) * d) * n / 2;
}
/// <summary>
/// 累積和の配列を計算する
/// Sum[ a[0], a[i] )がs[i+1]に入っている
/// s[0] : 0 //一切和を取らない場合
/// s[1] : ls[0] //a[0] + s[0] = a[0]
/// s[2] : ls[1] + s[1] //a[1] + a[0]
/// ...
/// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0]
/// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0]
///
/// 例: [1, 7)の和(a[1] + ... + a[6])
/// s[1] = a[0] //[0, 1)
/// s[7] = a[0] + a[1] + ... + a[6] //[0, 7)
/// よってs[7] - s[1]);
/// </summary>
/// <param name="ls">計算したい配列</param>
/// <returns>累積和配列</returns>
static List<long> AggregateSumList(List<long> a) {
var s = new List<long>(a.Count + 1);
if (a.Count == 0) {
return s;
}
s.Add(0); // s[0] = 0
for (int i = 0; i < a.Count; ++i) {
s.Add(a[i] + s[i]);
}
return s;
}
/// <summary>
/// 与えられた数が素数かどうかを計算する
/// </summary>
/// <param name="num">対象数</param>
/// <returns>true:素数, false:素数ではない(合成数)</returns>
public static bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
/// <summary>
/// 素因数分解
/// </summary>
/// <param name="n"></param>
/// <returns>keyが素数、valueがその素数の登場回数</returns>
public static Dictionary<long, long> PrimeFactorization(long n) {
var result = new Dictionary<long, long>();
//初めの素数2から割っていく
for (long p = 2; p * p <= n; p++) {
//割り切れないなら、素因数に含まれてない
if (n % p != 0)
continue;
long count = 0;
// 割り続ける
while (n % p == 0) {
count++;
n /= p;
}
result[p] = count;
}
// 素数が残っている場合
if (n != 1)
result[n] = 1;
return result;
}
/// <summary>
/// 順列mPnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Permutation(long m, long n) {
long ret = 1;
for (var i = 0; i < n; ++i) {
ret *= m - i;
}
return ret;
}
/// <summary>
/// 組み合わせmCnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Combination(long m, long n) {
if (m == n || n == 0) {
return 1;
}
long ans = 1;
for (var i = 1; i <= n; ++i) {
ans = ans * (m - i + 1) / i;
}
return ans;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
static long Lcm(long m, long n) {
var gcd = Gcd(m, n);
// return (m * n) / gcd;
return m / gcd * n; //桁あふれ対策
}
#endregion MyLib
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 930
| 24
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Read();
int n = int.Parse(input[0]);
Write(n % 1000);
}
static string[] Read() { return Console.ReadLine().Split(' '); }
static void Write(object o) { Console.WriteLine(o.ToString()); }
}
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Read();
int n = int.Parse(input[0]);
Write(n % 1000 == 0 ? 0 : 1000 - n % 1000);
}
static string[] Read() { return Console.ReadLine().Split(' '); }
static void Write(object o) { Console.WriteLine(o.ToString()); }
}
|
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 17, 33], ["+", 0, 28, 0, 41, 75, 16, 12, 16, 31, 22], ["+", 0, 28, 0, 41, 75, 16, 12, 16, 17, 109], ["+", 0, 28, 0, 41, 75, 16, 12, 16, 12, 203]]
| 8
| 102
| 10
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Util {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
int N = ri();
Console.WriteLine(N % 10000 % 1000);
Console.ReadLine();
}
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 Util {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
int N = ri();
int i = 0;
while (i * 1000 < N) {
i++;
}
Console.WriteLine(i * 1000 - N);
Console.ReadLine();
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 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, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 109], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 306
| 26
|
using System;
using System.Collections.Generic;
// using System.Linq;
// using System.Numerics;
class Program {
static void Main(string[] args) {
var input = INP();
long N = TOL(input[0]);
long result = N;
for (int i = 0; i < 100; i++) {
if (result < 1000) {
CWL(result);
return;
} else {
result -= 1000;
}
}
}
public static List<int> PrimeFactors(int n) {
var tmpList = new List<int>();
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
tmpList.Add(i);
} else {
i++;
}
}
if (tmp != 1)
tmpList.Add(tmp);
return tmpList;
}
static string[] INP() { return Console.ReadLine().Split(' '); }
static void CWL(string value) { Console.WriteLine(value); }
static void CWL(int value) { Console.WriteLine(value); }
static void CWL(long value) { Console.WriteLine(value); }
static void CWL(float value) { Console.WriteLine(value); }
static void CWL(double value) { Console.WriteLine(value); }
static int TOI(string str) { return int.Parse(str); }
static long TOL(string str) { return long.Parse(str); }
static float TOF(string str) { return float.Parse(str); }
static double TOD(string str) { return double.Parse(str); }
/*static void Main (string[] args) {
var input = INP();
var input2 = INP();
var input3 = INP();
CWL("dummy");
}*/
}
|
using System;
using System.Collections.Generic;
// using System.Linq;
// using System.Numerics;
class Program {
static void Main(string[] args) {
var input = INP();
long N = TOL(input[0]);
long pay = 0;
for (int i = 0; i < 20; i++) {
if (pay >= N) {
CWL(pay - N);
return;
} else {
pay += 1000;
}
}
}
public static List<int> PrimeFactors(int n) {
var tmpList = new List<int>();
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
tmpList.Add(i);
} else {
i++;
}
}
if (tmp != 1)
tmpList.Add(tmp);
return tmpList;
}
static string[] INP() { return Console.ReadLine().Split(' '); }
static void CWL(string value) { Console.WriteLine(value); }
static void CWL(int value) { Console.WriteLine(value); }
static void CWL(long value) { Console.WriteLine(value); }
static void CWL(float value) { Console.WriteLine(value); }
static void CWL(double value) { Console.WriteLine(value); }
static int TOI(string str) { return int.Parse(str); }
static long TOL(string str) { return long.Parse(str); }
static float TOF(string str) { return float.Parse(str); }
static double TOD(string str) { return double.Parse(str); }
/*static void Main (string[] args) {
var input = INP();
var input2 = INP();
var input3 = INP();
CWL("dummy");
}*/
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 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, 12, 22], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
| 8
| 347
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;
class Program {
static void Main() => new Program().Solve();
public void Solve() {
int n = ReadInt();
Console.WriteLine(-n % 1000 + 1000);
}
}
static class Scanner {
static Queue<string> que = new Queue<string>();
public static string Read() {
if (!que.Any())
foreach (var s in Console.ReadLine().Split())
que.Enqueue(s);
return que.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static decimal ReadDecimal() => decimal.Parse(Read());
public static IEnumerable<string> Read(long n) {
for (long i = 0; i < n; i++)
yield return Read();
}
public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
public static IEnumerable<long>
ReadLong(long n) => Read(n).Select(long.Parse);
public static IEnumerable<double>
ReadDouble(long n) => Read(n).Select(double.Parse);
public static IEnumerable<decimal>
ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;
class Program {
static void Main() => new Program().Solve();
public void Solve() {
int n = ReadInt();
int x = -n % 1000;
if (x < 0)
x += 1000;
Console.WriteLine(x);
}
}
static class Scanner {
static Queue<string> que = new Queue<string>();
public static string Read() {
if (!que.Any())
foreach (var s in Console.ReadLine().Split())
que.Enqueue(s);
return que.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static decimal ReadDecimal() => decimal.Parse(Read());
public static IEnumerable<string> Read(long n) {
for (long i = 0; i < n; i++)
yield return Read();
}
public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
public static IEnumerable<long>
ReadLong(long n) => Read(n).Select(long.Parse);
public static IEnumerable<double>
ReadDouble(long n) => Read(n).Select(double.Parse);
public static IEnumerable<decimal>
ReadDecimal(long n) => Read(n).Select(decimal.Parse);
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 323
| 23
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<int> Slist() {
return new List<int>(ReadLine().Split().Select(int.Parse));
}
static void Main(string[] args) {
var N = Sarray()[0];
WriteLine(N % 1000);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<int> Slist() {
return new List<int>(ReadLine().Split().Select(int.Parse));
}
static void Main(string[] args) {
var N = Sarray()[0];
var ans = 1000 - (N % 1000);
WriteLine(ans % 1000);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
| 8
| 181
| 13
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
checked {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// TestCaseMaker.MakeTestCase1("../TextFile2.txt");
// MyDebugger.Test(process, "../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());
var x = 1000 - (n % 1000);
return x == 1000 ? 0 : x;
}
static int[] ToIntArray(string strs, int n) {
var ret = new int[n];
if (n == 0)
return ret;
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
checked {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// TestCaseMaker.MakeTestCase1("../TextFile2.txt");
// MyDebugger.Test(process, "../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());
var x = 1000 - (n % 1000);
return x == 1000 ? 0 : x;
}
static int[] ToIntArray(string strs, int n) {
var ret = new int[n];
if (n == 0)
return ret;
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
[["+", 0, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 287, 0, 196, 0, 1, 0, 35]]
| 8
| 249
| 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 ProblemA {
static bool SAIKI = false;
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;
Console.WriteLine(1000 - (N % 1000));
}
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 LIB_FastIO fastio = new LIB_FastIODebug();
static public void Main(string[] args) {
if (args.Length == 0) {
fastio = new LIB_FastIO();
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
if (SAIKI) {
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
} else
Solve();
Console.Out.Flush();
}
static long NN => fastio.Long();
static double ND => fastio.Double();
static string NS => fastio.Scan();
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 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 IOrderedEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) =>
Enumerable.OrderBy(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x,
Func<T1, T2> selector) =>
Enumerable.OrderBy(x.OrderByRand(), selector);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) =>
Enumerable.OrderByDescending(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1>
OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) =>
Enumerable.OrderByDescending(x.OrderByRand(), selector);
static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) =>
x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<string>
OrderByDescending(this IEnumerable<string> x) =>
x.OrderByRand().OrderByDescending(e => e,
StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderByDescending(selector,
StringComparer.OrdinalIgnoreCase);
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_FastIO {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_FastIO() { str = Console.OpenStandardInput(); }
readonly Stream str;
readonly byte[] buf = new byte[1024];
int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return isEof; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
virtual public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
virtual public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
virtual public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
class LIB_FastIODebug : LIB_FastIO {
Queue<string> param = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_FastIODebug() {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string Scan() => NextString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override long Long() => long.Parse(NextString());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override double Double() => double.Parse(NextString());
}
}
|
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 ProblemA {
static bool SAIKI = false;
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 v = 1000 - (N % 1000);
Console.WriteLine(v == 1000 ? 0 : v);
}
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 LIB_FastIO fastio = new LIB_FastIODebug();
static public void Main(string[] args) {
if (args.Length == 0) {
fastio = new LIB_FastIO();
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
if (SAIKI) {
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
} else
Solve();
Console.Out.Flush();
}
static long NN => fastio.Long();
static double ND => fastio.Double();
static string NS => fastio.Scan();
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 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 IOrderedEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) =>
Enumerable.OrderBy(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x,
Func<T1, T2> selector) =>
Enumerable.OrderBy(x.OrderByRand(), selector);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) =>
Enumerable.OrderByDescending(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1>
OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) =>
Enumerable.OrderByDescending(x.OrderByRand(), selector);
static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) =>
x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<string>
OrderByDescending(this IEnumerable<string> x) =>
x.OrderByRand().OrderByDescending(e => e,
StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderByDescending(selector,
StringComparer.OrdinalIgnoreCase);
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_FastIO {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_FastIO() { str = Console.OpenStandardInput(); }
readonly Stream str;
readonly byte[] buf = new byte[1024];
int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get { return isEof; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
virtual public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
virtual public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
virtual public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
class LIB_FastIODebug : LIB_FastIO {
Queue<string> param = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LIB_FastIODebug() {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string Scan() => NextString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override long Long() => long.Parse(NextString());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override double Double() => double.Parse(NextString());
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
| 8
| 1,517
| 19
|
using System;
class B {
static void Main() {
int c = 0, w = 0, t = 0, r = 0;
for (int i = 0; i < int.Parse(Console.ReadLine()); i++) {
var b = Console.ReadLine();
if (b == "AC")
c++;
if (b == "WA")
w++;
if (b == "TLE")
t++;
if (b == "RE")
r++;
}
Console.WriteLine("AC x " + c + "\n" + "WA x " + w + "\n" + "TLE x " + t +
"\n" + "RE x " + r);
}
}
|
using System;
class B {
static void Main() {
var a = int.Parse(Console.ReadLine());
int c = 0, w = 0, t = 0, r = 0;
for (int i = 0; i < a; i++) {
var b = Console.ReadLine();
if (b == "AC")
c++;
if (b == "WA")
w++;
if (b == "TLE")
t++;
if (b == "RE")
r++;
}
Console.WriteLine("AC x " + c + "\n" + "WA x " + w + "\n" + "TLE x " + t +
"\n" + "RE x " + r);
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 199], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 150
| 25
|
public class Hello {
public static void Main() {
// Your code here!
var line = int.Parse(System.Console.ReadLine());
string[] answer = { "AC", "WA", "TLE", "RE" };
int[] numbers = new int[4];
for (var i = 0; i < line; i++) {
var data = System.Console.ReadLine();
for (var j = 0; j < numbers.Length; j++) {
if (data == answer[j]) {
numbers[j] = numbers[j] + 1;
}
}
}
for (var k = 0; k < answer.Length; k++) {
System.Console.WriteLine(answer[k] + "x" + numbers[k]);
}
}
}
|
public class Hello {
public static void Main() {
// Your code here!
var line = int.Parse(System.Console.ReadLine());
string[] answer = { "AC", "WA", "TLE", "RE" };
int[] numbers = new int[4];
for (var i = 0; i < line; i++) {
var data = System.Console.ReadLine();
for (var j = 0; j < numbers.Length; j++) {
if (data == answer[j]) {
numbers[j] = numbers[j] + 1;
}
}
// System.Console.WriteLine(numbers[0]);
}
for (var k = 0; k < answer.Length; k++) {
System.Console.WriteLine(answer[k] + " " + "x" + " " + numbers[k]);
}
}
}
|
[["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 222], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222]]
| 8
| 171
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;
namespace AtCoderTemplate {
class Program {
static void Main(string[] args) {
string str;
str = Console.ReadLine();
int N = int.Parse(str);
Console.WriteLine(N);
int ac = 0;
int wa = 0;
int tle = 0;
int re = 0;
for (int i = 0; i < N; i++) {
string S = Console.ReadLine();
switch (S) {
case "AC":
ac += 1;
break;
case "WA":
wa += 1;
break;
case "TLE":
tle += 1;
break;
case "RE":
re += 1;
break;
}
}
Console.WriteLine("AC x " + ac);
Console.WriteLine("WA x " + wa);
Console.WriteLine("TLE x " + tle);
Console.WriteLine("RE x " + re);
}
}
class MyLibrary {
public static int GCD(int a, int b) {
if (a % b == 0)
return b;
return GCD(b, a % b);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;
namespace AtCoderTemplate {
class Program {
static void Main(string[] args) {
string str;
str = Console.ReadLine();
int N = int.Parse(str);
int ac = 0;
int wa = 0;
int tle = 0;
int re = 0;
for (int i = 0; i < N; i++) {
string S = Console.ReadLine();
switch (S) {
case "AC":
ac += 1;
break;
case "WA":
wa += 1;
break;
case "TLE":
tle += 1;
break;
case "RE":
re += 1;
break;
}
}
Console.WriteLine("AC x " + ac);
Console.WriteLine("WA x " + wa);
Console.WriteLine("TLE x " + tle);
Console.WriteLine("RE x " + re);
}
}
class MyLibrary {
public static int GCD(int a, int b) {
if (a % b == 0)
return b;
return GCD(b, a % b);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 267
| 7
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var num = cin.ReadInt;
int leftnum = 400;
int rightnum = 599;
int couter = 8;
while (rightnum < 1999) {
if (num < rightnum) {
break;
}
couter--;
rightnum += 200;
}
WriteLine(couter);
// var num = cin.ReadInt;
// int[] array = cin.ReadIntArray(num);
// List<int> list = array.ToList();
////for (int i =0; i < num; i++) {
//// list.Add(array[i]);
////}
// foreach (var x in list)
//{
// WriteLine(x);
//}
// WriteLine(list.First();
// var nk = Console.ReadLine().Split(' ');
// var n = int.Parse(nk[0]);
// var k = int.Parse(nk[1]);
// var t = new int[n][];
// for (int i =0; i < n;i++) {
// t[i] = cin.ReadIntArray(n);
//}
// int n = cin.ReadInt;
// int K = cin.ReadInt;
// int[] array = new int[n];
// for (int i =0; i < n; i++) {
// array[i] = cin.ReadInt;
//}
// for (int i =0; i < n; i++) {
// if (array[i] == 0) {
// WriteLine(n);
// }
//}
// int res = 0;
// int right = 0;
// long mult = 1;
// for (int left = 0; left < n; left++) {
// while (right < n && mult * array[right] <= K) {
// mult *= array[right];
// right++;
// }
// res = Math.Max(res, right - left);
// if (left == right) right++;
// else mult /= array[left];
//}
// WriteLine(res);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var num = cin.ReadInt;
int rightnum = 599;
int couter = 8;
while (rightnum <= 1999) {
if (num <= rightnum) {
break;
}
couter--;
rightnum += 200;
}
WriteLine(couter);
// var num = cin.ReadInt;
// int[] array = cin.ReadIntArray(num);
// List<int> list = array.ToList();
////for (int i =0; i < num; i++) {
//// list.Add(array[i]);
////}
// foreach (var x in list)
//{
// WriteLine(x);
//}
// WriteLine(list.First();
// var nk = Console.ReadLine().Split(' ');
// var n = int.Parse(nk[0]);
// var k = int.Parse(nk[1]);
// var t = new int[n][];
// for (int i =0; i < n;i++) {
// t[i] = cin.ReadIntArray(n);
//}
// int n = cin.ReadInt;
// int K = cin.ReadInt;
// int[] array = new int[n];
// for (int i =0; i < n; i++) {
// array[i] = cin.ReadInt;
//}
// for (int i =0; i < n; i++) {
// if (array[i] == 0) {
// WriteLine(n);
// }
//}
// int res = 0;
// int right = 0;
// long mult = 1;
// for (int left = 0; left < n; left++) {
// while (right < n && mult * array[right] <= K) {
// mult *= array[right];
// right++;
// }
// res = Math.Max(res, right - left);
// if (left == right) right++;
// else mult /= array[left];
//}
// WriteLine(res);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 518
| 9
|
using System;
namespace _20200725_M_SOLUTIONS_プロコンオープン_2020 {
class Program {
static void Main(string[] args) {
int a;
a = int.Parse(Console.ReadLine()); //標準入力
if (400 <= a && a < 599) {
Console.WriteLine(8);
} else if (600 <= a && a < 799) {
Console.WriteLine(7);
} else if (800 <= a && a < 999) {
Console.WriteLine(6);
} else if (1000 <= a && a < 1199) {
Console.WriteLine(5);
} else if (1200 <= a && a < 1399) {
Console.WriteLine(4);
} else if (1400 <= a && a < 1599) {
Console.WriteLine(3);
} else if (1600 <= a && a < 1799) {
Console.WriteLine(2);
} else if (1800 <= a && a < 1999) {
Console.WriteLine(1);
}
}
}
}
|
using System;
namespace _20200725_M_SOLUTIONS_プロコンオープン_2020 {
class Program {
static void Main(string[] args) {
int a;
a = int.Parse(Console.ReadLine()); //標準入力
if (400 <= a && a <= 599) {
Console.WriteLine(8);
} else if (600 <= a && a <= 799) {
Console.WriteLine(7);
} else if (800 <= a && a <= 999) {
Console.WriteLine(6);
} else if (1000 <= a && a <= 1199) {
Console.WriteLine(5);
} else if (1200 <= a && a <= 1399) {
Console.WriteLine(4);
} else if (1400 <= a && a <= 1599) {
Console.WriteLine(3);
} else if (1600 <= a && a <= 1799) {
Console.WriteLine(2);
} else if (1800 <= a && a <= 1999) {
Console.WriteLine(1);
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 19], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 17, 19]]
| 8
| 198
| 16
|
using System;
using System.IO.Pipes;
using System.Linq;
using System.Runtime.InteropServices;
class name {
static void Main() {
int[] magic = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] kaisu = Console.ReadLine().Split().Select(int.Parse).ToArray();
int and = 0;
int ans = 0;
for (int k = 1; k <= kaisu[0]; k++) {
if (magic[0] > magic[1]) {
magic[1] = magic[1] * 2;
and = k;
} else {
and = k - 1;
break;
}
}
for (int h = 1; h <= kaisu[0] - and; h++) {
if (h == kaisu[0] && ans == 0) {
break;
}
if (magic[1] > magic[2]) {
magic[2] = magic[2] * 2;
ans = 1;
}
}
if (magic[0] < magic[1] && magic[1] < magic[2]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
using System;
using System.IO.Pipes;
using System.Linq;
using System.Runtime.InteropServices;
class name {
static void Main() {
int[] magic = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] kaisu = Console.ReadLine().Split().Select(int.Parse).ToArray();
int and = 0;
int ans = 0;
for (int k = 1; k <= kaisu[0]; k++) {
if (magic[0] >= magic[1]) {
magic[1] = magic[1] * 2;
and = k;
} else {
and = k - 1;
break;
}
}
for (int h = 1; h <= kaisu[0] - and; h++) {
if (magic[1] >= magic[2]) {
magic[2] = magic[2] * 2;
} else {
break;
}
}
if (magic[0] < magic[1] && magic[1] < magic[2]) {
Console.WriteLine("Yes");
}
else {
Console.WriteLine("No");
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 64, 196], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 1], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 213], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 214], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 3, 4], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 64, 196], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 1], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 213], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 214], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 3, 4]]
| 8
| 269
| 30
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
int K = int.Parse(Console.ReadLine());
bool success = false;
for (int i = 0; i < K; i++) {
if (A < B && B < C) {
Console.WriteLine("Yes");
success = true;
break;
}
if (A > B) {
B *= 2;
} else if (B > C) {
C *= 2;
}
if (A < B && B < C) {
Console.WriteLine("Yes");
success = true;
break;
}
}
if (!success) {
Console.WriteLine("No");
}
}
}
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
int K = int.Parse(Console.ReadLine());
bool success = false;
for (int i = 0; i < K; i++) {
if (A >= B) {
B *= 2;
} else if (B >= C) {
C *= 2;
}
if (A < B && B < C) {
Console.WriteLine("Yes");
success = true;
break;
}
}
if (!success) {
Console.WriteLine("No");
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 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, 211, 0, 146], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 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, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 20]]
| 8
| 222
| 31
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
public class MainClass {
public static void Main(string[] args) {
#if DEBUG
var inputs = new[] { @"
7 2 5
3
",
@"
7 4 2
3
",
@"
",
@"
",
@"
" };
var stream = Console.OpenStandardOutput();
foreach (var str in inputs) {
var text = str.TrimStart();
if (text.Length == 0)
continue;
// File.ReadAllText(text);
Console.SetIn(new StringReader(text));
// using var stream = new FileStream(@$"tester\out_{text}",
// FileMode.Create);
Main2(args, stream);
Console.WriteLine("----------------------------------");
}
#else
Main2(args, Console.OpenStandardOutput());
#endif
}
///< summary>10^9 + 7</summary>
private const long BIGNUM = 1000000007L;
private static void Main2(string[] args, Stream stream) {
var sw = new StreamWriter(stream, Console.Out.Encoding);
sw.AutoFlush = false;
var beforeOut = Console.Out;
Console.SetOut(sw);
checked {
var /*ABC*/ (A, B, C) = (Int(), Int(), Int());
var K = int.Parse(Console.ReadLine());
if (B == 1 || C == 1) {
Console.WriteLine("NO");
return;
}
var t = 0;
while (B <= A) {
B *= 2;
t++;
}
while (C <= B) {
C *= 2;
t++;
}
Console.WriteLine(t <= K ? "Yes" : "No");
}
Console.Out.Flush();
Console.SetOut(beforeOut);
}
#region "入力"
private static string NextInput = "";
private static int Int() => int.Parse(Str());
private static long Long() => long.Parse(Str());
private static float Float() => float.Parse(Str());
private static double Double() => double.Parse(Str());
private static string Str() {
var s = NextInput;
if (s == "")
s = Console.ReadLine();
var idx = s.IndexOf(' ');
if (idx >= 0) {
NextInput = s.Substring(idx + 1);
return s.Substring(0, idx);
}
NextInput = "";
return s;
}
#endregion
}
public static class ComparerPlus {
///< summary>セレクタ関数から昇順のComparerを生成する。</summary>
public static Comparer<T> By<T, U>(Func<T, U> selector)
where U : IComparable {
return Comparer<T>.Create((a, b) => selector(a).CompareTo(selector(b)));
}
///< summary>セレクタ関数から降順のComparerを生成する。</summary>
public static Comparer<T> ByDecending<T, U>(Func<T, U> selector)
where U : IComparable {
return Comparer<T>.Create((a, b) => selector(b).CompareTo(selector(a)));
}
}
public static class EnumerablePlus {
///< summary>出力文字列に変換。</summary>
public static string MkString<T>(this IEnumerable<T> list,
string sep = null) {
if (sep == null)
sep = " ";
return list
.Aggregate(new System.Text.StringBuilder(),
(a, b) => ((a.Length > 0) ? a.Append(sep) : a).Append(b))
.ToString();
}
///< summary>添字付きfor。</summary>
public static void ForEachWithIdx<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();
}
}
///< summary>条件付きMin。</summary>
public static T MinBy<T, U>(this IEnumerable<T> xs, Func<T, U> key)
where U : IComparable<U> {
return xs.Aggregate((a, b) => key(a).CompareTo(key(b)) <= 0 ? a : b);
}
///< summary>条件付きMax。</summary>
public static T MaxBy<T, U>(this IEnumerable<T> xs, Func<T, U> key)
where U : IComparable<U> {
return xs.Aggregate((a, b) => key(a).CompareTo(key(b)) >= 0 ? a : b);
}
///< summary>条件付きMax。複数の値を返す。</summary>
public static List<T> MaxByList<T, U>(this IEnumerable<T> xs, Func<T, U> key)
where U : IComparable<U> {
return xs.Aggregate(new List<T>(), (list, b) => {
if (list.Count == 0) {
list.Add(b);
return list;
}
var aa = key(list[0]);
var bb = key(b);
if (aa.CompareTo(bb) < 0)
list.Clear();
if (aa.CompareTo(bb) <= 0) {
list.Add(b);
return list;
}
return list;
});
}
///< summary>複数の値を返す。</summary>
public static List<T> MaxList<T>(this IEnumerable<T> xs)
where T : IComparable<T> { return xs.MaxByList(o => o); }
}
public static class MathPlus {
///< summary>n(>=0)をradix進数に変換する。桁の小さい順に返す。</summary>
public static List<long> NRadix(long n, long radix) {
if (n < 0)
throw new ArgumentOutOfRangeException(nameof(n));
if (radix < 2)
throw new ArgumentOutOfRangeException(nameof(n));
var res = new List<long>();
if (n == 0L) {
res.Add(0);
return res;
}
while (n > 0L) {
res.Add(n % radix);
n /= radix;
}
return res;
}
///< summary>べき乗。高速な実装である。</summary>
public static long Power(long x, long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return Power(x * x, n / 2);
return x * Power(x, n - 1);
}
///< 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;
///< summary>区間内の合計。beginも1から?end含む。</summary>
public static ulong Sum(ulong begin, ulong end) {
var up = Sum(end);
var low = Sum(begin - 1);
return up - low;
}
///< summary>1からの合計。</summary>
public static ulong Sum(ulong end) => checked((end + 1) * end / 2);
}
public static class Util {
///< summary>リスト内の値を移動する。</summary>
public static void Move<T>(this IList<T> list, int from, int to) {
var item = list[from];
for (var idx = from; idx > to; --idx) {
list[idx] = list[idx - 1];
}
list[to] = item;
}
///< summary>最後の値か、デフォルト値を取得。</summary>
public static T LastOrValue<T>(this IList<T> list, T value) {
return list.Count > 0 ? list.Last() : value;
}
///< summary>辞書をMultiSetとして使うときのAdd。</summary>
public static void AddMulti<T>(this IDictionary<T, int> xs, T key) {
if (xs.ContainsKey(key))
xs[key]++;
else
xs.Add(key, 1);
}
///< summary>値を交換する。</summary>
public static void Swap(ref int x, ref int y) {
int temp = x;
x = y;
y = temp;
}
public static void Assert(bool cond) {
if (!cond)
throw new Exception();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
public class MainClass {
public static void Main(string[] args) {
#if DEBUG
var inputs = new[] { @"
7 2 5
3
",
@"
7 4 2
3
",
@"
",
@"
",
@"
" };
var stream = Console.OpenStandardOutput();
foreach (var str in inputs) {
var text = str.TrimStart();
if (text.Length == 0)
continue;
// File.ReadAllText(text);
Console.SetIn(new StringReader(text));
// using var stream = new FileStream(@$"tester\out_{text}",
// FileMode.Create);
Main2(args, stream);
Console.WriteLine("----------------------------------");
}
#else
Main2(args, Console.OpenStandardOutput());
#endif
}
///< summary>10^9 + 7</summary>
private const long BIGNUM = 1000000007L;
private static void Main2(string[] args, Stream stream) {
var sw = new StreamWriter(stream, Console.Out.Encoding);
sw.AutoFlush = false;
var beforeOut = Console.Out;
Console.SetOut(sw);
checked {
var /*ABC*/ (A, B, C) = (Int(), Int(), Int());
var K = int.Parse(Console.ReadLine());
var t = 0;
while (B <= A) {
B *= 2;
t++;
}
while (C <= B) {
C *= 2;
t++;
}
Console.WriteLine(t <= K ? "Yes" : "No");
}
Console.Out.Flush();
Console.SetOut(beforeOut);
}
#region "入力"
private static string NextInput = "";
private static int Int() => int.Parse(Str());
private static long Long() => long.Parse(Str());
private static float Float() => float.Parse(Str());
private static double Double() => double.Parse(Str());
private static string Str() {
var s = NextInput;
if (s == "")
s = Console.ReadLine();
var idx = s.IndexOf(' ');
if (idx >= 0) {
NextInput = s.Substring(idx + 1);
return s.Substring(0, idx);
}
NextInput = "";
return s;
}
#endregion
}
public static class ComparerPlus {
///< summary>セレクタ関数から昇順のComparerを生成する。</summary>
public static Comparer<T> By<T, U>(Func<T, U> selector)
where U : IComparable {
return Comparer<T>.Create((a, b) => selector(a).CompareTo(selector(b)));
}
///< summary>セレクタ関数から降順のComparerを生成する。</summary>
public static Comparer<T> ByDecending<T, U>(Func<T, U> selector)
where U : IComparable {
return Comparer<T>.Create((a, b) => selector(b).CompareTo(selector(a)));
}
}
public static class EnumerablePlus {
///< summary>出力文字列に変換。</summary>
public static string MkString<T>(this IEnumerable<T> list,
string sep = null) {
if (sep == null)
sep = " ";
return list
.Aggregate(new System.Text.StringBuilder(),
(a, b) => ((a.Length > 0) ? a.Append(sep) : a).Append(b))
.ToString();
}
///< summary>添字付きfor。</summary>
public static void ForEachWithIdx<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();
}
}
///< summary>条件付きMin。</summary>
public static T MinBy<T, U>(this IEnumerable<T> xs, Func<T, U> key)
where U : IComparable<U> {
return xs.Aggregate((a, b) => key(a).CompareTo(key(b)) <= 0 ? a : b);
}
///< summary>条件付きMax。</summary>
public static T MaxBy<T, U>(this IEnumerable<T> xs, Func<T, U> key)
where U : IComparable<U> {
return xs.Aggregate((a, b) => key(a).CompareTo(key(b)) >= 0 ? a : b);
}
///< summary>条件付きMax。複数の値を返す。</summary>
public static List<T> MaxByList<T, U>(this IEnumerable<T> xs, Func<T, U> key)
where U : IComparable<U> {
return xs.Aggregate(new List<T>(), (list, b) => {
if (list.Count == 0) {
list.Add(b);
return list;
}
var aa = key(list[0]);
var bb = key(b);
if (aa.CompareTo(bb) < 0)
list.Clear();
if (aa.CompareTo(bb) <= 0) {
list.Add(b);
return list;
}
return list;
});
}
///< summary>複数の値を返す。</summary>
public static List<T> MaxList<T>(this IEnumerable<T> xs)
where T : IComparable<T> { return xs.MaxByList(o => o); }
}
public static class MathPlus {
///< summary>n(>=0)をradix進数に変換する。桁の小さい順に返す。</summary>
public static List<long> NRadix(long n, long radix) {
if (n < 0)
throw new ArgumentOutOfRangeException(nameof(n));
if (radix < 2)
throw new ArgumentOutOfRangeException(nameof(n));
var res = new List<long>();
if (n == 0L) {
res.Add(0);
return res;
}
while (n > 0L) {
res.Add(n % radix);
n /= radix;
}
return res;
}
///< summary>べき乗。高速な実装である。</summary>
public static long Power(long x, long n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return Power(x * x, n / 2);
return x * Power(x, n - 1);
}
///< 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;
///< summary>区間内の合計。beginも1から?end含む。</summary>
public static ulong Sum(ulong begin, ulong end) {
var up = Sum(end);
var low = Sum(begin - 1);
return up - low;
}
///< summary>1からの合計。</summary>
public static ulong Sum(ulong end) => checked((end + 1) * end / 2);
}
public static class Util {
///< summary>リスト内の値を移動する。</summary>
public static void Move<T>(this IList<T> list, int from, int to) {
var item = list[from];
for (var idx = from; idx > to; --idx) {
list[idx] = list[idx - 1];
}
list[to] = item;
}
///< summary>最後の値か、デフォルト値を取得。</summary>
public static T LastOrValue<T>(this IList<T> list, T value) {
return list.Count > 0 ? list.Last() : value;
}
///< summary>辞書をMultiSetとして使うときのAdd。</summary>
public static void AddMulti<T>(this IDictionary<T, int> xs, T key) {
if (xs.ContainsKey(key))
xs[key]++;
else
xs.Add(key, 1);
}
///< summary>値を交換する。</summary>
public static void Swap(ref int x, ref int y) {
int temp = x;
x = y;
y = temp;
}
public static void Assert(bool cond) {
if (!cond)
throw new Exception();
}
}
|
[["-", 8, 196, 0, 287, 0, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 287, 0, 196, 0, 57, 0, 24], ["-", 0, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 287, 0, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 287, 0, 196, 0, 57, 0, 25], ["-", 0, 287, 0, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 0, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 287, 0, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,152
| 23
|
using System;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class {
static void Main(string[] args) {
var (N, K) = ReadValue<long, long>();
var A = ulongArray;
ulong sum = A[0] * A[K - 1];
for (var i = 0; i < N - K; i++) {
ulong tmp = A[i + 1] * A[K + i];
if (sum < tmp) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
sum = tmp;
// Console.WriteLine(tmp);
}
}
static T1 ReadValue<T1>() {
var t1 = TypeDescriptor.GetConverter(typeof(T1));
return (T1)t1.ConvertFromString(Console.ReadLine());
}
static (T1, T2) ReadValue<T1, T2>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]));
}
static (T1, T2, T3) ReadValue<T1, T2, T3>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]));
}
static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
var t4 = TypeDescriptor.GetConverter(typeof(T4));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]), (T4)t4.ConvertFromString(rl[3]));
}
static (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
var t4 = TypeDescriptor.GetConverter(typeof(T4));
var t5 = TypeDescriptor.GetConverter(typeof(T5));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]), (T4)t4.ConvertFromString(rl[3]),
(T5)t5.ConvertFromString(rl[4]));
}
static string[] stringArray => Console.ReadLine().Split().ToArray();
static int[] intArray =>
Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
static long[] longArray =>
Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
static ulong[] ulongArray =>
Console.ReadLine().Trim().Split().Select(ulong.Parse).ToArray();
static double[] doubleArray =>
Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
static decimal[] decimalArray =>
Console.ReadLine().Trim().Split().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class {
static void Main(string[] args) {
var (N, K) = ReadValue<long, long>();
var A = longArray;
for (var i = 0; i < N - K; i++) {
if (A[i] < A[K + i]) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
static T1 ReadValue<T1>() {
var t1 = TypeDescriptor.GetConverter(typeof(T1));
return (T1)t1.ConvertFromString(Console.ReadLine());
}
static (T1, T2) ReadValue<T1, T2>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]));
}
static (T1, T2, T3) ReadValue<T1, T2, T3>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]));
}
static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
var t4 = TypeDescriptor.GetConverter(typeof(T4));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]), (T4)t4.ConvertFromString(rl[3]));
}
static (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
var t4 = TypeDescriptor.GetConverter(typeof(T4));
var t5 = TypeDescriptor.GetConverter(typeof(T5));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]), (T4)t4.ConvertFromString(rl[3]),
(T5)t5.ConvertFromString(rl[4]));
}
static string[] stringArray => Console.ReadLine().Split().ToArray();
static int[] intArray =>
Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
static long[] longArray =>
Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
static ulong[] ulongArray =>
Console.ReadLine().Trim().Split().Select(ulong.Parse).ToArray();
static double[] doubleArray =>
Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
static decimal[] decimalArray =>
Console.ReadLine().Trim().Split().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 906
| 36
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
string line = Console.ReadLine();
string[] split = line.Split(' ');
int n = Int32.Parse(split[0]);
int k = Int32.Parse(split[1]);
int[] ai = new int[200000];
line = Console.ReadLine();
split = line.Split(' ');
for (int i = 0; i < n; ++i) {
ai[i] = Int32.Parse(split[i]);
}
int ak = 1;
for (int i = 0; i < k; ++i) {
ak *= ai[i];
}
for (int testnum = k; testnum < n; testnum++) {
int next_ak = ak / ai[testnum - k] * ai[testnum];
if (ak < next_ak)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
ak = next_ak;
}
int a = 0;
}
}
class list {
public int juni;
public int old;
public list(int juni, int old) {
this.juni = juni;
this.old = old;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
string line = Console.ReadLine();
string[] split = line.Split(' ');
int n = Int32.Parse(split[0]);
int k = Int32.Parse(split[1]);
int[] ai = new int[200000];
line = Console.ReadLine();
split = line.Split(' ');
for (int i = 0; i < n; ++i) {
ai[i] = Int32.Parse(split[i]);
}
int ak = 1;
for (int i = 0; i < k; ++i) {
ak *= ai[i];
}
for (int testnum = k; testnum < n; testnum++) {
if (ai[testnum - k] < ai[testnum])
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
int a = 0;
}
}
class list {
public int juni;
public int old;
public list(int juni, int old) {
this.juni = juni;
this.old = old;
}
}
}
|
[["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 85], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 75, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 286
| 19
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextInt();
var k = cin.nextInt();
var a = cin.ArrayLong(n);
var now = 1L;
for (int i = k - 1; 0 <= i; i--) {
now *= a[i];
}
var nowk = k;
var beforek = 0;
for (int i = 0; i < n - k; i++) {
var tmp = now / a[beforek];
tmp = tmp * a[nowk];
if (now < tmp) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
now = tmp;
beforek++;
nowk++;
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextInt();
var k = cin.nextInt();
var a = cin.ArrayLong(n);
var now = 1L;
for (int i = k - 1; 0 <= i; i--) {
now *= a[i];
}
var nowk = k;
var beforek = 0;
for (int i = 0; i < n - k; i++) {
var before = a[beforek];
var noww = a[nowk];
if (before < noww) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
beforek++;
nowk++;
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 683
| 17
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Reflection.Emit;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
checked {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// TestCaseMaker.MakeTestCase1("../TextFile2.txt");
// MyDebugger.Test(process, "../TextFile2.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var n = int.Parse(spl[0]);
var k = int.Parse(spl[1]);
var aa = ToIntArray(input.ReadLine(), n);
long x = 1;
int kk = 0;
var sb = new StringBuilder();
for (int i = 0; i < n; i++) {
long y = x;
if (kk >= k) {
y /= aa[i - k];
y *= aa[i];
sb.AppendLine((y > x) ? Yes : No);
} else {
y *= aa[i];
}
x = y;
kk++;
}
return sb;
}
static long[] ToIntArray(string strs, int n) {
var ret = new long[n];
if (n == 0)
return ret;
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = long.Parse(spl[i]);
return ret;
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Reflection.Emit;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
checked {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// TestCaseMaker.MakeTestCase1("../TextFile2.txt");
// MyDebugger.Test(process, "../TextFile2.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var n = int.Parse(spl[0]);
var k = int.Parse(spl[1]);
var aa = ToIntArray(input.ReadLine(), n);
int kk = 0;
var sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (kk >= k) {
if (aa[i - k] < aa[i]) {
sb.AppendLine(Yes);
} else {
sb.AppendLine(No);
}
}
kk++;
}
return sb;
}
static long[] ToIntArray(string strs, int n) {
var ret = new long[n];
if (n == 0)
return ret;
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = long.Parse(spl[i]);
return ret;
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 90], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 3, 4, 0, 28, 0, 41, 15, 23, 0, 24], ["-", 0, 28, 0, 41, 15, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 41, 15, 23, 0, 16, 17, 47], ["-", 0, 28, 0, 41, 15, 23, 0, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 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, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 382
| 46
|
using System;
using System.Linq;
class D {
static void Main() {
int N = int.Parse(Console.ReadLine());
var A =
(Console.ReadLine()).Split(' ').Select(s => long.Parse(s)).ToArray();
var Sum = 1000L;
var Stock = 0L;
for (int i = 0; i < N - 1; i++) {
if (A[i + 1] < A[i]) {
Sum += A[i] * Stock;
Stock = 0;
} else if (A[i + 1] > A[i]) {
Stock += Sum / A[i];
Sum -= Stock * A[i];
}
}
if (Stock != 0) {
Sum = Sum + A[A.Length - 1] * Stock;
Stock = 0;
}
Console.WriteLine(Sum.ToString());
}
}
|
using System;
using System.Linq;
class D {
static void Main() {
int N = int.Parse(Console.ReadLine());
var A =
(Console.ReadLine()).Split(' ').Select(s => long.Parse(s)).ToArray();
var Sum = 1000L;
var Stock = 0L;
for (int i = 0; i < N - 1; i++) {
if (A[i + 1] < A[i]) {
Sum += A[i] * Stock;
Stock = 0;
} else if (A[i + 1] > A[i]) {
var now = Sum / A[i];
Sum -= now * A[i];
Stock += now;
}
}
if (Stock != 0) {
Sum = Sum + A[A.Length - 1] * Stock;
Stock = 0;
}
Console.WriteLine(Sum.ToString());
}
}
|
[["-", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
| 8
| 197
| 11
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text; // for StringBuilder
class c {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
a.Add(0);
var listA = new List<int>();
var listB = new List<int>();
bool judge = false;
for (int i = 0; i < n; i++) {
if (a[i] < a[i + 1]) {
listA.Add(i - 1);
judge = true;
}
if (a[i] > a[i + 1] && judge) {
listB.Add(i);
judge = false;
}
}
long money = 1000;
while (listB.Count() >= 1) {
int min = a.Where((f, g) => g >= listA[0] + 1 && g <= listB[0]).Min();
int max = a.Where((f, g) => g >= listA[0] + 1 && g <= listB[0]).Max();
long kabu = money / min;
money = money - kabu * min + kabu * max;
listA.RemoveAt(0);
listB.RemoveAt(0);
}
Console.WriteLine(money);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text; // for StringBuilder
class c {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
a.Add(0);
var listA = new List<int>();
var listB = new List<int>();
bool judge = false;
int temp = 0;
for (int i = 0; i < n; i++) {
if (a[i] < a[i + 1]) {
if (!judge)
listA.Add(i - 1);
judge = true;
}
if (a[i] > a[i + 1] && judge) {
listB.Add(i);
judge = false;
temp = 0;
}
}
long money = 1000;
while (listB.Count() >= 1) {
int min = a.Where((f, g) => g >= listA[0] + 1 && g <= listB[0]).Min();
int max = a.Where((f, g) => g >= listA[0] + 1 && g <= listB[0]).Max();
long kabu = money / min;
money = money - kabu * min + kabu * max;
listA.RemoveAt(0);
listB.RemoveAt(0);
}
Console.WriteLine(money);
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 241, 0, 111], ["+", 0, 57, 64, 196, 0, 57, 15, 241, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 305
| 14
|
using System;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class {
static void Main(string[] args) {
var N = ReadValue<long>();
var A = longArray;
long tmp = 0;
long money = 1000;
for (var i = 0; i < N - 1; i++) {
if (A[i] < A[i + 1]) {
tmp = money / A[i];
money -= A[i] * tmp;
} else if (A[i] > A[i + 1]) {
money += A[i] * tmp;
tmp = 0;
}
}
if (tmp > 0)
money += A.Last() * tmp;
Console.Write(money);
}
static T1 ReadValue<T1>() {
var t1 = TypeDescriptor.GetConverter(typeof(T1));
return (T1)t1.ConvertFromString(Console.ReadLine());
}
static (T1, T2) ReadValue<T1, T2>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]));
}
static (T1, T2, T3) ReadValue<T1, T2, T3>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]));
}
static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
var t4 = TypeDescriptor.GetConverter(typeof(T4));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]), (T4)t4.ConvertFromString(rl[3]));
}
static (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
var t4 = TypeDescriptor.GetConverter(typeof(T4));
var t5 = TypeDescriptor.GetConverter(typeof(T5));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]), (T4)t4.ConvertFromString(rl[3]),
(T5)t5.ConvertFromString(rl[4]));
}
static string[] stringArray => Console.ReadLine().Split().ToArray();
static int[] intArray =>
Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
static long[] longArray =>
Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
static double[] doubleArray =>
Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
static decimal[] decimalArray =>
Console.ReadLine().Trim().Split().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
namespace ConsoleApp1 {
public class Class {
static void Main(string[] args) {
var N = ReadValue<long>();
var A = longArray;
long tmp = 0;
long money = 1000;
for (var i = 0; i < N - 1; i++) {
if (A[i] < A[i + 1]) {
if (money >= A[i]) {
tmp = money / A[i];
money -= A[i] * tmp;
}
} else if (A[i] > A[i + 1]) {
money += A[i] * tmp;
tmp = 0;
}
}
if (tmp > 0)
money += A.Last() * tmp;
Console.Write(money);
}
static T1 ReadValue<T1>() {
var t1 = TypeDescriptor.GetConverter(typeof(T1));
return (T1)t1.ConvertFromString(Console.ReadLine());
}
static (T1, T2) ReadValue<T1, T2>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]));
}
static (T1, T2, T3) ReadValue<T1, T2, T3>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]));
}
static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
var t4 = TypeDescriptor.GetConverter(typeof(T4));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]), (T4)t4.ConvertFromString(rl[3]));
}
static (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var rl = Console.ReadLine().Trim().Split().ToArray();
var t1 = TypeDescriptor.GetConverter(typeof(T1));
var t2 = TypeDescriptor.GetConverter(typeof(T2));
var t3 = TypeDescriptor.GetConverter(typeof(T3));
var t4 = TypeDescriptor.GetConverter(typeof(T4));
var t5 = TypeDescriptor.GetConverter(typeof(T5));
return ((T1)t1.ConvertFromString(rl[0]), (T2)t2.ConvertFromString(rl[1]),
(T3)t3.ConvertFromString(rl[2]), (T4)t4.ConvertFromString(rl[3]),
(T5)t5.ConvertFromString(rl[4]));
}
static string[] stringArray => Console.ReadLine().Split().ToArray();
static int[] intArray =>
Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
static long[] longArray =>
Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
static double[] doubleArray =>
Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
static decimal[] decimalArray =>
Console.ReadLine().Trim().Split().Select(decimal.Parse).ToArray();
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 64, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 900
| 11
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace AtCoder {
class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
var n = int.Parse(ReadLine());
var line =
ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
long possession = 1000;
var max = line[0];
var min = line[0];
bool? increased = null;
for (var i = 1; i < n; i++) {
if (line[i] > line[i - 1]) {
if (increased != true) {
increased = true;
min = line[i - 1];
}
max = Max(max, line[i]);
} else if (line[i] < line[i - 1]) {
if (increased != false) {
if (increased == true) {
possession += (possession / min) * (max - min);
max = line[i];
min = line[i];
}
increased = false;
max = line[i - 1];
}
min = Min(min, line[i]);
}
}
if (increased == true) {
possession += (possession / min) * (max - min);
}
WriteLine(possession);
}
}
}
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace AtCoder {
class Program {
private static long mod = 1000000007;
static void Main(string[] args) {
var n = int.Parse(ReadLine());
var line =
ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
long possession = 1000;
var max = line[0];
var min = line[0];
bool? increased = null;
for (var i = 1; i < n; i++) {
if (line[i] > line[i - 1]) {
if (increased != true) {
increased = true;
min = line[i - 1];
max = line[i];
}
max = Max(max, line[i]);
} else if (line[i] < line[i - 1]) {
if (increased != false) {
if (increased == true) {
possession += (possession / min) * (max - min);
max = line[i];
min = line[i];
}
increased = false;
max = line[i - 1];
}
min = Min(min, line[i]);
}
}
if (increased == true) {
possession += (possession / min) * (max - min);
}
WriteLine(possession);
}
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 305
| 7
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace MSOL2020F {
class Program {
static void Main(string[] args) {
var N = RInt;
List<Pos> U = new List<Pos>();
List<Pos> D = new List<Pos>();
List<Pos> L = new List<Pos>();
List<Pos> R = new List<Pos>();
List<Pos>[] U2 =
new List<Pos> [200010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] D2 =
new List<Pos> [200010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] L2 =
new List<Pos> [200010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] R2 =
new List<Pos> [200010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] Lm =
new List<Pos> [400010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] Lp =
new List<Pos> [400010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] Rm =
new List<Pos> [400010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] Rp =
new List<Pos> [400010].Select(x => new List<Pos>()).ToArray();
for (int i = 0; i < N; i++) {
var x = RInt;
var y = RInt;
var s = RString;
var p = new Pos(x, y);
if (s == "U") {
U.Add(p);
U2[p.x].Add(p);
} else if (s == "D") {
D.Add(p);
D2[p.x].Add(p);
} else if (s == "L") {
L.Add(p);
Lm[p.m].Add(p);
Lp[p.p].Add(p);
L2[p.y].Add(p);
} else if (s == "R") {
R.Add(p);
Rm[p.m].Add(p);
Rp[p.p].Add(p);
R2[p.y].Add(p);
}
}
int ans = int.MaxValue;
int[][] Lmarr = new int [400010][];
int[][] Rparr = new int [400010][];
int[][] Lparr = new int [400010][];
int[][] Rmarr = new int [400010][];
for (int i = 0; i < 400010; i++) {
Lmarr[i] = Lm[i].Select(a => a.y).OrderBy(a => a).ToArray();
Rparr[i] = Rp[i].Select(a => a.y).OrderBy(a => a).ToArray();
Lparr[i] = Lp[i].Select(a => -a.y).OrderBy(a => a).ToArray();
Rmarr[i] = Rm[i].Select(a => -a.y).OrderBy(a => a).ToArray();
}
// ①
foreach (var p in U) {
var candm = Lmarr[p.m];
if (candm.Length == 0)
continue;
int indm = LowerBound(candm, p.y);
if (indm < candm.Length)
ans = Math.Min(ans, (candm[indm] - p.y) * 10);
var candp = Rparr[p.p];
if (candp.Length == 0)
continue;
int indp = LowerBound(candp, p.y);
if (indp < candp.Length)
ans = Math.Min(ans, (candp[indp] - p.y) * 10);
}
// ②
foreach (var p in D) {
var candm = Lparr[p.p];
if (candm.Length == 0)
continue;
int indm = LowerBound(candm, -p.y);
if (indm < candm.Length)
ans = Math.Min(ans, (candm[indm] + p.y) * 10);
var candp = Rmarr[p.m];
if (candp.Length == 0)
continue;
int indp = LowerBound(candp, -p.y);
if (indp < candp.Length)
ans = Math.Min(ans, (candp[indp] + p.y) * 10);
}
// ③
int[][] Darr = new int [200010][];
int[][] Larr = new int [200010][];
for (int i = 0; i < 200010; i++) {
Darr[i] = D2[i].Select(a => a.y).OrderBy(a => a).ToArray();
Larr[i] = L2[i].Select(a => a.x).OrderBy(a => a).ToArray();
}
foreach (var u in U) {
if (Darr[u.x].Length == 0)
continue;
int ind = LowerBound(Darr[u.x], u.y);
if (ind < Darr[u.x].Length)
ans = Math.Min(ans, (Darr[u.x][ind] - u.y) * 10 / 2);
}
foreach (var r in R) {
if (Larr[r.y].Length == 0)
continue;
int ind = LowerBound(Larr[r.y], r.x);
if (ind < Larr[r.y].Length)
ans = Math.Min(ans, (Larr[r.y][ind] - r.x) * 10 / 2);
}
if (ans != int.MaxValue)
Console.WriteLine(ans);
else
Console.WriteLine("SAFE");
}
public static int LowerBound<T>(T[] a, T v) {
return LowerBound(a, v, Comparer<T>.Default);
}
public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(a[mid], v);
if (res == -1)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
struct Pos {
public int x;
public int y;
public int m => (x - y) + 200000;
public int p => (x + y);
public Pos(int x, int y) {
this.x = x;
this.y = y;
}
}
}
}
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 MSOL2020F {
class Program {
static void Main(string[] args) {
var N = RInt;
List<Pos> U = new List<Pos>();
List<Pos> D = new List<Pos>();
List<Pos> L = new List<Pos>();
List<Pos> R = new List<Pos>();
List<Pos>[] U2 =
new List<Pos> [200010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] D2 =
new List<Pos> [200010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] L2 =
new List<Pos> [200010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] R2 =
new List<Pos> [200010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] Lm =
new List<Pos> [400010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] Lp =
new List<Pos> [400010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] Rm =
new List<Pos> [400010].Select(x => new List<Pos>()).ToArray();
List<Pos>[] Rp =
new List<Pos> [400010].Select(x => new List<Pos>()).ToArray();
for (int i = 0; i < N; i++) {
var x = RInt;
var y = RInt;
var s = RString;
var p = new Pos(x, y);
if (s == "U") {
U.Add(p);
U2[p.x].Add(p);
} else if (s == "D") {
D.Add(p);
D2[p.x].Add(p);
} else if (s == "L") {
L.Add(p);
Lm[p.m].Add(p);
Lp[p.p].Add(p);
L2[p.y].Add(p);
} else if (s == "R") {
R.Add(p);
Rm[p.m].Add(p);
Rp[p.p].Add(p);
R2[p.y].Add(p);
}
}
int ans = int.MaxValue;
int[][] Lmarr = new int [400010][];
int[][] Rparr = new int [400010][];
int[][] Lparr = new int [400010][];
int[][] Rmarr = new int [400010][];
for (int i = 0; i < 400010; i++) {
Lmarr[i] = Lm[i].Select(a => a.y).OrderBy(a => a).ToArray();
Rparr[i] = Rp[i].Select(a => a.y).OrderBy(a => a).ToArray();
Lparr[i] = Lp[i].Select(a => -a.y).OrderBy(a => a).ToArray();
Rmarr[i] = Rm[i].Select(a => -a.y).OrderBy(a => a).ToArray();
}
// ①
foreach (var p in U) {
var candm = Lmarr[p.m];
if (candm.Length != 0) {
int indm = LowerBound(candm, p.y);
if (indm < candm.Length)
ans = Math.Min(ans, (candm[indm] - p.y) * 10);
}
var candp = Rparr[p.p];
if (candp.Length == 0)
continue;
int indp = LowerBound(candp, p.y);
if (indp < candp.Length)
ans = Math.Min(ans, (candp[indp] - p.y) * 10);
}
// ②
foreach (var p in D) {
var candm = Lparr[p.p];
if (candm.Length != 0) {
int indm = LowerBound(candm, -p.y);
if (indm < candm.Length)
ans = Math.Min(ans, (candm[indm] + p.y) * 10);
}
var candp = Rmarr[p.m];
if (candp.Length == 0)
continue;
int indp = LowerBound(candp, -p.y);
if (indp < candp.Length)
ans = Math.Min(ans, (candp[indp] + p.y) * 10);
}
// ③
int[][] Darr = new int [200010][];
int[][] Larr = new int [200010][];
for (int i = 0; i < 200010; i++) {
Darr[i] = D2[i].Select(a => a.y).OrderBy(a => a).ToArray();
Larr[i] = L2[i].Select(a => a.x).OrderBy(a => a).ToArray();
}
foreach (var u in U) {
if (Darr[u.x].Length == 0)
continue;
int ind = LowerBound(Darr[u.x], u.y);
if (ind < Darr[u.x].Length)
ans = Math.Min(ans, (Darr[u.x][ind] - u.y) * 10 / 2);
}
foreach (var r in R) {
if (Larr[r.y].Length == 0)
continue;
int ind = LowerBound(Larr[r.y], r.x);
if (ind < Larr[r.y].Length)
ans = Math.Min(ans, (Larr[r.y][ind] - r.x) * 10 / 2);
}
if (ans != int.MaxValue)
Console.WriteLine(ans);
else
Console.WriteLine("SAFE");
}
public static int LowerBound<T>(T[] a, T v) {
return LowerBound(a, v, Comparer<T>.Default);
}
public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(a[mid], v);
if (res == -1)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
struct Pos {
public int x;
public int y;
public int m => (x - y) + 200000;
public int p => (x + y);
public Pos(int x, int y) {
this.x = x;
this.y = y;
}
}
}
}
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
}
}
}
|
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 210, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 210, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 2,611
| 12
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Read();
int l = int.Parse(input[0]);
int r = int.Parse(input[1]);
int d = int.Parse(input[2]);
int ld = l / d;
int rd = (r - 1) / d;
Write(ld - rd);
}
static string[] Read() { return Console.ReadLine().Split(' '); }
static void Write(object o) { Console.WriteLine(o.ToString()); }
}
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Read();
int l = int.Parse(input[0]);
int r = int.Parse(input[1]);
int d = int.Parse(input[2]);
int ld = (l - 1) / d;
int rd = r / d;
Write(rd - ld);
}
static string[] Read() { return Console.ReadLine().Split(' '); }
static void Write(object o) { Console.WriteLine(o.ToString()); }
}
|
[["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["-", 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
| 146
| 12
|
using System;
namespace SoloLearn {
class Program {
static void Main(string[] args) {
string S = "cupofcoffee";
string T = "cupofhottea";
int count = 0;
for (int i = 0; i < S.Length; i++) {
if (S[i] != T[i])
count++;
}
Console.Write(count);
}
}
}
|
using System;
namespace SoloLearn {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
string T = Console.ReadLine();
int count = 0;
for (int i = 0; i < S.Length; i++) {
if (S[i] != T[i])
count++;
}
Console.Write(count);
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 81
| 16
|
using System;
using System.Collections.Generic;
namespace abc172_c {
class Program {
static void Main(string[] args) {
var N = CIn.ReadInt();
var M = CIn.ReadInt();
var K = CIn.ReadInt();
var A = CIn.ReadIntArray(N);
var B = CIn.ReadIntArray(M);
var sumA = new long[N + 1];
var sumB = new long[M + 1];
var books = 0;
for (var i = 1; i <= M; i++) {
sumB[i] = sumB[i - 1] + B[i - 1];
}
for (var j = 0; j <= N; j++) {
if (j >= 1)
sumA[j] = sumA[j - 1] + A[j - 1];
var min = K - sumA[j];
for (var k = 0; k <= M; k++) {
var binary = Array.BinarySearch(sumB, min);
if (binary >= 0) {
books = Math.Max(books, binary + j);
} else {
binary = ~binary - 1;
books = Math.Max(books, binary + j);
}
}
}
Console.WriteLine(books);
}
}
class CIn {
private static readonly Queue<string> fieldBuffer = new Queue<string>();
public static string Read() {
if (fieldBuffer.Count == 0) {
foreach (var field in Console.ReadLine().Split()) {
fieldBuffer.Enqueue(field);
}
}
return fieldBuffer.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static string[] ReadStringArray(long n) {
var array = new string[n];
for (var i = 0; i < n; i++) {
array[i] = Read();
}
return array;
}
public static int[] ReadIntArray(long n) {
var array = new int[n];
for (var i = 0; i < n; i++) {
array[i] = ReadInt();
}
return array;
}
public static long[] ReadLongArray(long n) {
var array = new long[n];
for (var i = 0; i < n; i++) {
array[i] = ReadLong();
}
return array;
}
public static double[] ReadDoubleArray(long n) {
var array = new double[n];
for (var i = 0; i < n; i++) {
array[i] = ReadDouble();
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
namespace abc172_c {
class Program {
static void Main(string[] args) {
var N = CIn.ReadInt();
var M = CIn.ReadInt();
var K = CIn.ReadInt();
var A = CIn.ReadIntArray(N);
var B = CIn.ReadIntArray(M);
var sumA = new long[N + 1];
var sumB = new long[M + 1];
var books = 0;
for (var i = 1; i <= M; i++) {
sumB[i] = sumB[i - 1] + B[i - 1];
}
for (var j = 0; j <= N; j++) {
if (j >= 1)
sumA[j] = sumA[j - 1] + A[j - 1];
var min = K - sumA[j];
if (min >= 0) {
var binary = Array.BinarySearch(sumB, min);
if (binary >= 0) {
books = Math.Max(books, binary + j);
} else {
binary = ~binary - 1;
books = Math.Max(books, binary + j);
}
}
}
Console.WriteLine(books);
}
}
class CIn {
private static readonly Queue<string> fieldBuffer = new Queue<string>();
public static string Read() {
if (fieldBuffer.Count == 0) {
foreach (var field in Console.ReadLine().Split()) {
fieldBuffer.Enqueue(field);
}
}
return fieldBuffer.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static string[] ReadStringArray(long n) {
var array = new string[n];
for (var i = 0; i < n; i++) {
array[i] = Read();
}
return array;
}
public static int[] ReadIntArray(long n) {
var array = new int[n];
for (var i = 0; i < n; i++) {
array[i] = ReadInt();
}
return array;
}
public static long[] ReadLongArray(long n) {
var array = new long[n];
for (var i = 0; i < n; i++) {
array[i] = ReadLong();
}
return array;
}
public static double[] ReadDoubleArray(long n) {
var array = new double[n];
for (var i = 0; i < n; i++) {
array[i] = ReadDouble();
}
return array;
}
}
}
|
[["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29]]
| 8
| 582
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var r = ReadSplit();
var n = r[0].Int();
var m = r[1].Int();
var k = r[2].Long();
var r2 = ReadSplit();
var r3 = ReadSplit();
var la = new long[n + 1];
var lb = new long[m];
var rb = new long[m + 1];
for (int i = 0; i < n; i++) {
la[i + 1] = r2[i].Long();
}
for (int i = 0; i < m; i++) {
lb[i] = r3[i].Long();
rb[i + 1] += rb[i] + lb[i];
}
var at = 0L;
var ans = 0L;
for (int i = 0; i <= n; i++) {
at += la[i];
var left = -1;
var right = rb.Length;
if (k - at < 0)
break;
if (rb[1] > k)
continue;
var mid = 0;
while (right - left > 1) {
mid = left + (right - left) / 2;
if (rb[mid] >= k - at) {
right = mid;
} else
left = mid;
}
ans = Math.Max(ans, mid + i);
}
WriteRead(ans);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var r = ReadSplit();
var n = r[0].Int();
var m = r[1].Int();
var k = r[2].Long();
var r2 = ReadSplit();
var r3 = ReadSplit();
var la = new long[n + 1];
var lb = new long[m];
var rb = new long[m + 1];
for (int i = 0; i < n; i++) {
la[i + 1] = r2[i].Long();
}
for (int i = 0; i < m; i++) {
lb[i] = r3[i].Long();
rb[i + 1] += rb[i] + lb[i];
}
var at = 0L;
var ans = 0L;
for (int i = 0; i <= n; i++) {
at += la[i];
var left = -1;
var right = rb.Length - 1;
if (k - at < 0)
break;
if (rb[1] > k)
continue;
var mid = 0;
while (right - left > 1) {
mid = left + (right - left) / 2;
if (rb[mid] >= k - at) {
right = mid;
} else
left = mid;
}
if (rb[right] > k - at) {
right = left;
}
ans = Math.Max(ans, right + i);
}
WriteRead(ans);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
| 8
| 679
| 21
|
using System;
using System.Linq;
namespace ABC172 {
class C {
static void Main(string[] args) {
// var CA = Enumerable.Repeat(0, (int)N).Select(_ =>
// Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
var NMK = Console.ReadLine().Split().Select(long.Parse).ToArray();
var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
var B = Console.ReadLine().Split().Select(long.Parse).ToArray();
var N = NMK[0];
var M = NMK[1];
var K = NMK[2];
var Acs = new long[N + 1];
for (int i = 0; i < N; i++) {
Acs[i + 1] = A[i] + Acs[i];
}
// Console.WriteLine(string.Join(" ", Acs));
var Bcs = new long[M + 1];
for (int i = 0; i < M; i++) {
Bcs[i + 1] = B[i] + Bcs[i];
}
var Bcsmax = Bcs.Max();
// Console.WriteLine(string.Join(" ", Bcs));
var max = 0;
var tmpmax = 0;
for (int i = 1; i < N + 1; i++) {
if (K < Acs[i])
continue;
tmpmax = i;
var tmp = K - Acs[i];
// var b = Array.BinarySearch(B, tmp);
if (0 <= Array.BinarySearch(Bcs, tmp)) {
tmpmax += Array.BinarySearch(Bcs, tmp);
} else {
if (Bcsmax <= tmp)
tmpmax += ~Array.BinarySearch(Bcs, tmp);
else
tmpmax += ~Array.BinarySearch(Bcs, tmp) - 1;
// Console.WriteLine(Bcsmax);
}
max = Math.Max(max, tmpmax);
}
Console.WriteLine(max);
}
}
}
|
using System;
using System.Linq;
namespace ABC172 {
class C {
static void Main(string[] args) {
// var CA = Enumerable.Repeat(0, (int)N).Select(_ =>
// Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
var NMK = Console.ReadLine().Split().Select(long.Parse).ToArray();
var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
var B = Console.ReadLine().Split().Select(long.Parse).ToArray();
var N = NMK[0];
var M = NMK[1];
var K = NMK[2];
var Acs = new long[N + 1];
for (int i = 0; i < N; i++) {
Acs[i + 1] = A[i] + Acs[i];
}
// Console.WriteLine(string.Join(" ", Acs));
var Bcs = new long[M + 1];
for (int i = 0; i < M; i++) {
Bcs[i + 1] = B[i] + Bcs[i];
}
var Bcsmax = Bcs.Max();
// Console.WriteLine(string.Join(" ", Bcs));
var max = 0;
var tmpmax = 0;
for (int i = 0; i < N + 1; i++) {
if (K < Acs[i])
continue;
tmpmax = i;
var tmp = K - Acs[i];
// var b = Array.BinarySearch(B, tmp);
if (0 <= Array.BinarySearch(Bcs, tmp)) {
tmpmax += Array.BinarySearch(Bcs, tmp);
} else {
// if (Bcsmax <= tmp) tmpmax += ~Array.BinarySearch(Bcs, tmp);
// else
tmpmax += ~Array.BinarySearch(Bcs, tmp) - 1;
// Console.WriteLine(Bcsmax);
}
max = Math.Max(max, tmpmax);
}
Console.WriteLine(max);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["-", 75, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 1, 0, 11, 12, 241, 0, 92], ["-", 0, 11, 12, 241, 0, 213, 63, 214, 205, 22], ["-", 0, 11, 12, 241, 0, 213, 63, 214, 0, 131], ["-", 0, 11, 12, 241, 0, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 241, 0, 213, 3, 4, 0, 24], ["-", 12, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 11, 12, 241, 0, 213, 3, 4, 0, 21], ["-", 0, 11, 12, 241, 0, 213, 3, 4, 0, 25], ["-", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95]]
| 8
| 359
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static int[] A, B;
static int N, M, K;
static void INPUT() {
N = NextInt();
M = NextInt();
K = NextInt();
A = LineInt();
B = LineInt();
}
static void OUT() {
var sa = new Stack<int>();
var sb = new Queue<int>();
foreach (var b in B)
sb.Enqueue(b);
long a = 0;
var i = 0;
var max = 0;
while (i < N) {
if (a + A[i] <= K) {
a += A[i];
sa.Push(A[i++]);
} else
break;
}
long k = K - a;
while (sb.Any() && k >= sb.Peek()) {
k -= sb.Dequeue();
i++;
}
max = i;
while (sa.Any()) {
while (sb.Any() && k >= sb.Peek()) {
k -= sb.Dequeue();
i++;
max = Math.Max(max, i);
}
k += sa.Pop();
i--;
}
Console.WriteLine(max);
}
static void Main(string[] args) {
#if DEBUG
// TESTINPUT();
INPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() {}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static int[] A, B;
static int N, M, K;
static void INPUT() {
N = NextInt();
M = NextInt();
K = NextInt();
A = LineInt();
B = LineInt();
}
static void OUT() {
var sa = new Stack<int>();
var sb = new Queue<int>();
foreach (var b in B)
sb.Enqueue(b);
long a = 0;
var i = 0;
var max = 0;
while (i < N) {
if (a + A[i] <= K) {
a += A[i];
sa.Push(A[i++]);
} else
break;
}
long k = K - a;
while (sb.Any() && k >= sb.Peek()) {
k -= sb.Dequeue();
i++;
}
max = i;
while (sa.Any()) {
k += sa.Pop();
i--;
while (sb.Any() && k >= sb.Peek()) {
k -= sb.Dequeue();
i++;
max = Math.Max(max, i);
}
}
Console.WriteLine(max);
}
static void Main(string[] args) {
#if DEBUG
// TESTINPUT();
INPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() {}
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {}
|
[["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 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, 68], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 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, 68]]
| 8
| 647
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
namespace C_ABC172 {
class MainClass {
static long[] s, a, b;
public static void Main(string[] args) {
s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
a = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
b = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
long n = s[0];
long m = s[1];
long k = s[2];
var sa = new List<long>();
var sb = new List<long>();
sa.Add(0);
sb.Add(0);
long atmp = 0;
long btmp = 0;
bool aover = false;
bool bover = false;
for (long i = 0; i <= Max(m, n); i++) {
if (!aover && !bover) {
atmp += a[i];
if (atmp <= k) {
sa.Add(atmp);
if (i == n - 1) {
WriteLine("here i:{0}", i);
aover = true;
}
} else {
aover = true;
}
btmp += b[i];
if (btmp <= k) {
sb.Add(btmp);
if (i == m - 1)
bover = true;
} else {
bover = true;
}
} else if (!aover) {
atmp += a[i];
if (atmp <= k) {
sa.Add(atmp);
if (i == n - 1)
aover = true;
} else {
aover = true;
}
} else if (!bover) {
btmp += b[i];
if (btmp <= k) {
sb.Add(btmp);
if (i == m - 1)
bover = true;
} else {
bover = true;
}
} else {
break;
}
}
// sa.ForEach(WriteLine);
// sb.ForEach(WriteLine);
long ans = 0;
var sbb = sb.ToArray();
int nowb = 0;
for (int i = sa.Count - 1; i >= 0; i--) {
long readlife = k - sa[i];
for (int j = nowb; j < sb.Count; j++) {
if (readlife - sb[j] < 0) {
nowb = j - 1;
break;
} else if (readlife - sb[j] == 0) {
nowb = j;
break;
} else {
nowb = j;
}
}
// WriteLine("i : {0} nowb : {1}",i,nowb);
ans = Max(ans, i + nowb);
}
WriteLine(ans);
}
public static int LowerBound<T>(T[] a, T v) {
return LowerBound(a, v, Comparer<T>.Default);
}
public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(a[mid], v);
if (res == -1)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
public static int UpperBound<T>(T[] a, T v) {
return UpperBound(a, v, Comparer<T>.Default);
}
public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(a[mid], v);
if (res <= 0)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
namespace C_ABC172 {
class MainClass {
static long[] s, a, b;
public static void Main(string[] args) {
s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
a = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
b = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
long n = s[0];
long m = s[1];
long k = s[2];
var sa = new List<long>();
var sb = new List<long>();
sa.Add(0);
sb.Add(0);
long atmp = 0;
long btmp = 0;
bool aover = false;
bool bover = false;
for (long i = 0; i <= Max(m, n); i++) {
if (!aover && !bover) {
atmp += a[i];
if (atmp <= k) {
sa.Add(atmp);
if (i == n - 1) {
// WriteLine("here i:{0}",i);
aover = true;
}
} else {
aover = true;
}
btmp += b[i];
if (btmp <= k) {
sb.Add(btmp);
if (i == m - 1)
bover = true;
} else {
bover = true;
}
} else if (!aover) {
atmp += a[i];
if (atmp <= k) {
sa.Add(atmp);
if (i == n - 1)
aover = true;
} else {
aover = true;
}
} else if (!bover) {
btmp += b[i];
if (btmp <= k) {
sb.Add(btmp);
if (i == m - 1)
bover = true;
} else {
bover = true;
}
} else {
break;
}
}
// sa.ForEach(WriteLine);
// sb.ForEach(WriteLine);
long ans = 0;
var sbb = sb.ToArray();
int nowb = 0;
for (int i = sa.Count - 1; i >= 0; i--) {
long readlife = k - sa[i];
for (int j = nowb; j < sb.Count; j++) {
if (readlife - sb[j] < 0) {
nowb = j - 1;
break;
} else if (readlife - sb[j] == 0) {
nowb = j;
break;
} else {
nowb = j;
}
}
// WriteLine("i : {0} nowb : {1}",i,nowb);
ans = Max(ans, i + nowb);
}
WriteLine(ans);
}
public static int LowerBound<T>(T[] a, T v) {
return LowerBound(a, v, Comparer<T>.Default);
}
public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(a[mid], v);
if (res == -1)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
public static int UpperBound<T>(T[] a, T v) {
return UpperBound(a, v, Comparer<T>.Default);
}
public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp) {
var l = 0;
var r = a.Length - 1;
while (l <= r) {
var mid = l + (r - l) / 2;
var res = cmp.Compare(a[mid], v);
if (res <= 0)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 826
| 9
|
using static System.Math;
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var m = int.Parse(line[1]);
var k = long.Parse(line[2]);
line = Console.ReadLine().Trim().Split(' ');
var a = Array.ConvertAll(line, int.Parse);
line = Console.ReadLine().Trim().Split(' ');
var b = Array.ConvertAll(line, int.Parse);
var t = getAns(a, b, k);
var t2 = getAns(b, a, k);
Console.WriteLine(Max(t, t2));
}
static int getAns(int[] a, int[] b, long k) {
var aL = a.Length;
var bL = b.Length;
var bsum = 0L;
var bcount = 0;
var p = 0;
for (int i = 0; i < bL; i++) {
bsum += b[i];
if (bsum > k) {
bsum -= b[i];
p = i;
break;
}
bcount++;
p++;
}
var res = bcount;
for (int i = 0; i < aL; i++) {
k -= a[i];
if (k < 0)
break;
while (p >= 0) {
if (bsum <= k)
break;
else
bsum -= b[p];
p--;
}
res = Max(res, i + 1 + p);
}
return res;
}
}
|
using static System.Math;
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var m = int.Parse(line[1]);
var k = long.Parse(line[2]);
line = Console.ReadLine().Trim().Split(' ');
var a = Array.ConvertAll(line, int.Parse);
line = Console.ReadLine().Trim().Split(' ');
var b = Array.ConvertAll(line, int.Parse);
var t = getAns(a, b, k);
Console.WriteLine(t);
}
static int getAns(int[] a, int[] b, long k) {
var aL = a.Length;
var bL = b.Length;
var bsum = 0L;
var bcount = 0;
var p = 0;
for (int i = 0; i < bL; i++) {
bsum += b[i];
if (bsum > k) {
bsum -= b[i];
p = i - 1;
break;
}
bcount++;
p++;
}
var res = bcount;
if (bcount == bL)
p = bL - 1;
for (int i = 0; i < aL; i++) {
k -= a[i];
if (k < 0)
break;
while (p >= 0) {
if (bsum <= k)
break;
else
bsum -= b[p];
p--;
}
res = Max(res, i + 2 + p);
}
return res;
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203]]
| 8
| 362
| 33
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace ABC172 {
using static Ex;
public class Solve {
public static void Main(string[] args) { new ABC_C(); }
}
public class ABC_A {
public ABC_A() {
var a = ReadInt;
(a + a * a + a * a * a).Cw();
}
}
public class ABC_B {
public ABC_B() {
var s = Read;
var t = Read;
var l = s.Length;
long ans = 0;
for (int i = 0; i < l; i++) {
if (s[i] != t[i])
ans++;
}
ans.Cw();
}
}
public class ABC_C {
//机 A, B があります。机 A には N 冊の本が、机 B には M 冊の本
// K分を超えないようにこの行為を繰り返すとき、最大で何冊の本
long n, m, k;
long[] a;
long[] b;
long max = 0;
public ABC_C() {
(n, m, k) = ReadLongArray().ToTpl3();
a = ReadLongArray();
b = ReadLongArray();
max = 0;
long now = 0;
long j = -1;
for (long i = 0; i < n; i++) {
now += a[i];
if (now > k) {
now -= a[i];
break;
}
Maxs(ref max, i);
j = i;
}
long g = 0;
while (now < k && g < m) {
now += b[g++];
if (now > k)
break;
Maxs(ref max, j + g + 1);
}
while (j >= 0) {
now -= a[j--];
while (now < k && g < m) {
now += b[g++];
if (now > k)
break;
Maxs(ref max, j + g + 1);
}
}
max.Cw();
}
}
public static class Ex {
public static void Cw(this object s) { Console.WriteLine(s); }
public static bool Mins<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
public static bool Maxs<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
public static void Swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
public static void Swap<T>(List<T> list, int i, int j) {
T tmp = list[j];
list[j] = list[i];
list[i] = tmp;
}
public static long Lcm(int x, int y) { return x / Gcd(x, y) * y; }
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }
public static string Read {
get { return Console.ReadLine().Trim(); }
}
public static int ReadInt {
get { return int.Parse(Read); }
}
public static long ReadLong {
get { return long.Parse(Read); }
}
public static double ReadDouble {
get { return double.Parse(Read); }
}
public static string[] ReadArray() { return Read.Split(' '); }
public static int[] ReadIntArray() {
return Read.Split(' ').Select(int.Parse).ToArray();
}
public static long[] ReadLongArray() {
return Read.Split(' ').Select(long.Parse).ToArray();
}
public static string[] ReadArray(long N) {
var v = new string[N];
for (long i = 0; i < N; ++i)
v[i] = Read;
return v;
}
public static int[] ReadIntArray(long N) {
var v = new int[N];
for (long i = 0; i < N; ++i)
v[i] = ReadInt;
return v;
}
public static long[] ReadLongArray(long N) {
var v = new long[N];
for (long i = 0; i < N; ++i)
v[i] = ReadLong;
return v;
}
public static (T, T) ToTpl2<T>(this T[] v) { return (v[0], v[1]); }
public static (T, T, T) ToTpl3<T>(this T[] v) { return (v[0], v[1], v[2]); }
public static (T, T, T, T) ToTpl4<T>(this T[] v) {
return (v[0], v[1], v[2], v[3]);
}
public static (T, T, T, T, T) ToTpl5<T>(this T[] v) {
return (v[0], v[1], v[2], v[3], v[4]);
}
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace ABC172 {
using static Ex;
public class Solve {
public static void Main(string[] args) { new ABC_C(); }
}
public class ABC_A {
public ABC_A() {
var a = ReadInt;
(a + a * a + a * a * a).Cw();
}
}
public class ABC_B {
public ABC_B() {
var s = Read;
var t = Read;
var l = s.Length;
long ans = 0;
for (int i = 0; i < l; i++) {
if (s[i] != t[i])
ans++;
}
ans.Cw();
}
}
public class ABC_C {
//机 A, B があります。机 A には N 冊の本が、机 B には M 冊の本
// K分を超えないようにこの行為を繰り返すとき、最大で何冊の本
long n, m, k;
long[] a;
long[] b;
long max = 0;
public ABC_C() {
(n, m, k) = ReadLongArray().ToTpl3();
a = ReadLongArray();
b = ReadLongArray();
max = 0;
long now = 0;
long j = -1;
for (long i = 0; i < n; i++) {
if (now + a[i] > k)
break;
now += a[i];
Maxs(ref max, i + 1);
j = i;
}
long g = 0;
while (now < k && g < m) {
now += b[g++];
if (now > k)
break;
Maxs(ref max, j + g + 1);
}
while (j >= 0) {
now -= a[j--];
while (now < k && g < m) {
now += b[g++];
if (now > k)
break;
Maxs(ref max, j + g + 1);
}
}
max.Cw();
}
}
public static class Ex {
public static void Cw(this object s) { Console.WriteLine(s); }
public static bool Mins<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
public static bool Maxs<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
public static void Swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
public static void Swap<T>(List<T> list, int i, int j) {
T tmp = list[j];
list[j] = list[i];
list[i] = tmp;
}
public static long Lcm(int x, int y) { return x / Gcd(x, y) * y; }
public static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }
public static string Read {
get { return Console.ReadLine().Trim(); }
}
public static int ReadInt {
get { return int.Parse(Read); }
}
public static long ReadLong {
get { return long.Parse(Read); }
}
public static double ReadDouble {
get { return double.Parse(Read); }
}
public static string[] ReadArray() { return Read.Split(' '); }
public static int[] ReadIntArray() {
return Read.Split(' ').Select(int.Parse).ToArray();
}
public static long[] ReadLongArray() {
return Read.Split(' ').Select(long.Parse).ToArray();
}
public static string[] ReadArray(long N) {
var v = new string[N];
for (long i = 0; i < N; ++i)
v[i] = Read;
return v;
}
public static int[] ReadIntArray(long N) {
var v = new int[N];
for (long i = 0; i < N; ++i)
v[i] = ReadInt;
return v;
}
public static long[] ReadLongArray(long N) {
var v = new long[N];
for (long i = 0; i < N; ++i)
v[i] = ReadLong;
return v;
}
public static (T, T) ToTpl2<T>(this T[] v) { return (v[0], v[1]); }
public static (T, T, T) ToTpl3<T>(this T[] v) { return (v[0], v[1], v[2]); }
public static (T, T, T, T) ToTpl4<T>(this T[] v) {
return (v[0], v[1], v[2], v[3]);
}
public static (T, T, T, T, T) ToTpl5<T>(this T[] v) {
return (v[0], v[1], v[2], v[3], v[4]);
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 1,220
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC172_C {
class Program {
static void Main(string[] args) {
int[] nmk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
List<int> a = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
List<int> b = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
int count_a = 0;
int count_b = 0;
int time = 0;
for (int i = 0; i < nmk[0]; i++) {
if (time + a[i] > nmk[2]) {
break;
}
count_a++;
time += a[i];
}
int max = count_a;
int time2 = 0;
for (int i = 0; i < nmk[1]; i++) {
if (time2 + b[i] > nmk[2]) {
break;
}
count_b++;
time2 += b[i];
while (time + time2 > nmk[2] && count_a > 0) {
count_a--;
time2 -= a[count_a];
}
max = Math.Max(max, count_a + count_b);
}
Console.WriteLine(max);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC172_C {
class Program {
static void Main(string[] args) {
int[] nmk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
List<int> a = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
List<int> b = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
int count_a = 0;
int count_b = 0;
int time = 0;
for (int i = 0; i < nmk[0]; i++) {
if (time + a[i] > nmk[2]) {
break;
}
count_a++;
time += a[i];
}
int max = count_a;
int time2 = 0;
for (int i = 0; i < nmk[1]; i++) {
if (time2 + b[i] > nmk[2]) {
break;
}
time2 += b[i];
count_b++;
while (time + time2 > nmk[2]) {
count_a--;
time -= a[count_a];
}
max = Math.Max(max, count_a + count_b);
}
Console.WriteLine(max);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 98], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 17, 47], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 12, 203], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22]]
| 8
| 301
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace C {
class Program {
static void Main(string[] args) {
string[] input_1 = (Console.ReadLine()).Split(" ");
int N = int.Parse(input_1[0]);
int M = int.Parse(input_1[1]);
long K = long.Parse(input_1[2]);
string[] input_2 = (Console.ReadLine()).Split(" ");
List<int> A_i = new List<int>();
foreach (string element in input_2) {
A_i.Add(int.Parse(element));
}
string[] input_3 = (Console.ReadLine()).Split(" ");
List<int> B_i = new List<int>();
foreach (string element in input_3) {
B_i.Add(int.Parse(element));
}
long current = 0;
int n = 0;
while (true) {
if (current > K) {
current -= A_i[n - 1];
n--;
break;
}
n++;
if (n > N) {
n--;
break;
}
current += A_i[n - 1];
}
int ans = n;
int m = 0;
while (true) {
while (true) {
if (current > K) {
current -= B_i[m - 1];
m--;
break;
}
m++;
if (m > M) {
m--;
break;
}
current += B_i[m - 1];
}
if (ans < n + m) {
ans = n + m;
}
n--;
if (n <= 0) {
n++;
break;
}
current -= A_i[n - 1];
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace C {
class Program {
static void Main(string[] args) {
string[] input_1 = (Console.ReadLine()).Split(" ");
int N = int.Parse(input_1[0]);
int M = int.Parse(input_1[1]);
long K = long.Parse(input_1[2]);
string[] input_2 = (Console.ReadLine()).Split(" ");
List<int> A_i = new List<int>();
foreach (string element in input_2) {
A_i.Add(int.Parse(element));
}
string[] input_3 = (Console.ReadLine()).Split(" ");
List<int> B_i = new List<int>();
foreach (string element in input_3) {
B_i.Add(int.Parse(element));
}
long current = 0;
int n = 0;
while (true) {
if (current > K) {
current -= A_i[n - 1];
n--;
break;
}
n++;
if (n > N) {
n--;
break;
}
current += A_i[n - 1];
}
int ans = n;
int m = 0;
while (true) {
while (true) {
if (current > K) {
current -= B_i[m - 1];
m--;
break;
}
m++;
if (m > M) {
m--;
break;
}
current += B_i[m - 1];
}
if (ans < n + m) {
ans = n + m;
}
if (n == 0) {
break;
}
current -= A_i[n - 1];
n--;
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 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, 68]]
| 8
| 383
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder.Abc172 {
class C {
public static void Main() {
var k = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Last();
var a =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var b =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
for (int i = 1; i < a.Length; i++)
a[i] += a[i - 1];
for (int i = 1; i < b.Length; i++)
b[i] += b[i - 1];
int max = 0;
int j = b.Length - 1;
for (int i = 0; i < a.Length; i++) {
while (j >= 0 && a[i] + b[j] > k)
j--;
if (j >= 0)
max = Math.Max(max, i + j + 2);
else {
while (i < a.Length && a[i] <= k)
max = Math.Max(max, ++i);
break;
}
}
Console.WriteLine(max);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder.Abc172 {
class C {
public static void Main() {
var k = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Last();
var a = ("0 " + Console.ReadLine())
.Split(' ')
.Select(x => long.Parse(x))
.ToArray();
var b = ("0 " + Console.ReadLine())
.Split(' ')
.Select(x => long.Parse(x))
.ToArray();
for (int i = 1; i < a.Length; i++)
a[i] += a[i - 1];
for (int i = 1; i < b.Length; i++)
b[i] += b[i - 1];
int max = 0;
int j = b.Length - 1;
for (int i = 0; i < a.Length; i++) {
while (j >= 0 && a[i] + b[j] > k)
j--;
if (j >= 0)
max = Math.Max(max, i + j);
else {
while (i < a.Length && a[i] <= k)
max = Math.Max(max, i++);
break;
}
}
Console.WriteLine(max);
}
}
}
|
[["+", 63, 214, 205, 213, 63, 214, 205, 23, 0, 24], ["+", 63, 214, 205, 23, 0, 16, 31, 5, 0, 62], ["+", 63, 214, 205, 23, 0, 16, 31, 5, 0, 222], ["+", 205, 213, 63, 214, 205, 23, 0, 16, 17, 72], ["+", 63, 214, 205, 213, 63, 214, 205, 23, 0, 25], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 12, 213, 3, 4, 0, 28, 0, 241, 0, 29], ["+", 12, 213, 3, 4, 0, 28, 0, 223, 0, 29]]
| 8
| 298
| 16
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
// ABC170
class ProgramA {
public void main() {
//入力
int a = int.Parse(Console.ReadLine());
//入力が0ならその位置を答で出す
Console.WriteLine(a + a * a + a * a * a);
}
}
class ProgramB {
public void main() {
//入力
string s = Console.ReadLine();
string t = Console.ReadLine();
int count = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] != t[i])
count++;
}
Console.WriteLine(count);
}
}
class ProgramC {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
long n = long.Parse(s[0]);
long m = long.Parse(s[1]);
long k = long.Parse(s[2]);
long[] one = new long[n];
long[] two = new long[m];
long[] dp = new long[m + n];
string[] s1 = Console.ReadLine().Split(' ');
string[] s2 = Console.ReadLine().Split(' ');
for (int i = 0; i < n; i++) {
if (i == 0)
one[i] = long.Parse(s1[i]);
else
one[i] = one[i - 1] + long.Parse(s1[i]);
}
for (int i = 0; i < m; i++) {
if (i == 0)
two[i] = long.Parse(s2[i]);
else
two[i] = two[i - 1] + long.Parse(s2[i]);
}
long ans = 0;
for (int i = 0; i < n; i++) {
long time = k - one[i];
long min = -1;
long max = m;
while (min + 1 != max) {
long t = (min + max) / 2;
if (two[t] <= time)
min = t;
else
max = t;
}
ans = Math.Max(i + min + 2, ans);
}
Console.WriteLine(ans);
}
}
class ProgramD {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
long ans = 0;
for (int i = 1; i <= n; i++) {
long count = n / i;
ans += (i + count * i) * count / 2;
}
Console.WriteLine(ans);
}
}
class ProgramE {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = long.Parse(s[i]);
long sum = a[0] ^ a[1];
for (int i = 2; i < n; i++)
sum = sum ^ a[i];
for (int i = 0; i < n; i++)
Console.Write((sum ^ a[i]) + " ");
}
}
}
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
// ABC170
class ProgramA {
public void main() {
//入力
int a = int.Parse(Console.ReadLine());
//入力が0ならその位置を答で出す
Console.WriteLine(a + a * a + a * a * a);
}
}
class ProgramB {
public void main() {
//入力
string s = Console.ReadLine();
string t = Console.ReadLine();
int count = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] != t[i])
count++;
}
Console.WriteLine(count);
}
}
class ProgramC {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
long n = long.Parse(s[0]);
long m = long.Parse(s[1]);
long k = long.Parse(s[2]);
long[] one = new long[n + 1];
long[] two = new long[m + 1];
long[] dp = new long[m + n];
string[] s1 = Console.ReadLine().Split(' ');
string[] s2 = Console.ReadLine().Split(' ');
for (int i = 0; i < n; i++) {
if (i == 0)
one[i + 1] = long.Parse(s1[i]);
else
one[i + 1] = one[i] + long.Parse(s1[i]);
}
for (int i = 0; i < m; i++) {
if (i == 0)
two[i + 1] = long.Parse(s2[i]);
else
two[i + 1] = two[i] + long.Parse(s2[i]);
}
long ans = 0;
for (int i = 0; i <= n; i++) {
long time = k - one[i];
if (time < 0)
continue;
long min = -1;
long max = m + 1;
while (min + 1 != max) {
long t = (min + max) / 2;
if (two[t] <= time)
min = t;
else
max = t;
}
ans = Math.Max(i + min, ans);
}
Console.WriteLine(ans);
}
}
class ProgramD {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
long ans = 0;
for (int i = 1; i <= n; i++) {
long count = n / i;
ans += (i + count * i) * count / 2;
}
Console.WriteLine(ans);
}
}
class ProgramE {
public void main() {
//入力
int n = int.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = long.Parse(s[i]);
long sum = a[0] ^ a[1];
for (int i = 2; i < n; i++)
sum = sum ^ a[i];
for (int i = 0; i < n; i++)
Console.Write((sum ^ a[i]) + " ");
}
}
}
|
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 775
| 30
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int m = int.Parse(input[1]);
int k = int.Parse(input[2]);
int[] a = new int[n];
int[] b = new int[m];
input = Console.ReadLine().Split(' ');
for (int i = 0; i < n; i++)
a[i] = int.Parse(input[i]);
input = Console.ReadLine().Split(' ');
for (int i = 0; i < m; i++)
b[i] = int.Parse(input[i]);
int read = 0;
long readTime = 0;
while (read < n) {
readTime += (long)a[read];
if (readTime > (long)k) {
readTime -= (long)a[read];
break;
}
read++;
}
int readA = read;
int readB = 0;
while (readB < m) {
readTime += (long)b[readB];
if (readTime > (long)k) {
readTime -= (long)b[readB];
break;
}
readB++;
}
Console.WriteLine(readA.ToString() + " " + readB.ToString());
read += readB;
for (int i = 0; i < readA; i++) {
readTime -= a[readA - 1 - i];
while (readB < m) {
readTime += (long)b[readB];
if (readTime > (long)k) {
readTime -= (long)b[readB];
break;
}
readB++;
}
if (read < readA - 1 - i + readB)
read = readA - 1 - i + readB;
}
Console.WriteLine(read);
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int n = int.Parse(input[0]);
int m = int.Parse(input[1]);
int k = int.Parse(input[2]);
int[] a = new int[n];
int[] b = new int[m];
input = Console.ReadLine().Split(' ');
for (int i = 0; i < n; i++)
a[i] = int.Parse(input[i]);
input = Console.ReadLine().Split(' ');
for (int i = 0; i < m; i++)
b[i] = int.Parse(input[i]);
int read = 0;
long readTime = 0;
while (read < n) {
readTime += (long)a[read];
if (readTime > (long)k) {
readTime -= (long)a[read];
break;
}
read++;
}
int readA = read;
int readB = 0;
while (readB < m) {
readTime += (long)b[readB];
if (readTime > (long)k) {
readTime -= (long)b[readB];
break;
}
readB++;
}
// Console.WriteLine(readA.ToString()+" "+readB.ToString());
read += readB;
for (int i = 0; i < readA; i++) {
readTime -= a[readA - 1 - i];
while (readB < m) {
readTime += (long)b[readB];
if (readTime > (long)k) {
readTime -= (long)b[readB];
break;
}
readB++;
}
if (read < readA - 1 - i + readB)
read = readA - 1 - i + readB;
}
Console.WriteLine(read);
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 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], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 430
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
static int BinSearchIndex(long v, long[] list) {
int minRange = 0;
int maxRange = list.Count();
while (minRange != maxRange) {
var center = (minRange + maxRange) / 2;
if (list[center] < v) {
minRange = center + 1;
} else {
maxRange = center;
}
}
return minRange;
}
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var N = vals[0];
var M = vals[1];
var K = vals[2];
var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var B = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
for (int i = 1; i < A.Length; i++) {
A[i] += A[i - 1];
}
for (int i = 1; i < B.Length; i++) {
B[i] += B[i - 1];
}
var best = 0;
for (int i = 0; i < A.Length; i++) {
if (A[i] > K) {
break;
}
var count = i + 1;
var t = K - A[i];
var index = BinSearchIndex(t, B);
while (0 <= index && (index >= B.Length || B[index] > t)) {
index--;
}
count += index + 1;
best = Math.Max(best, count);
}
Console.WriteLine(best);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
static int BinSearchIndex(long v, long[] list) {
int minRange = 0;
int maxRange = list.Count();
while (minRange != maxRange) {
var center = (minRange + maxRange) / 2;
if (list[center] < v) {
minRange = center + 1;
} else {
maxRange = center;
}
}
return minRange;
}
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var N = vals[0];
var M = vals[1];
var K = vals[2];
var A = new long [1]
.Concat(Console.ReadLine().Split(' ').Select(long.Parse))
.ToArray();
var B = new long [1]
.Concat(Console.ReadLine().Split(' ').Select(long.Parse))
.ToArray();
for (int i = 1; i < A.Length; i++) {
A[i] += A[i - 1];
}
for (int i = 1; i < B.Length; i++) {
B[i] += B[i - 1];
}
var best = 0;
for (int i = 0; i < A.Length; i++) {
if (A[i] > K) {
break;
}
var count = i;
var t = K - A[i];
var index = BinSearchIndex(t, B);
while (0 <= index && (index >= B.Length || B[index] > t)) {
index--;
}
count += index;
best = Math.Max(best, count);
}
Console.WriteLine(best);
}
}
|
[["+", 63, 214, 205, 213, 63, 214, 205, 227, 0, 228], ["+", 205, 213, 63, 214, 205, 227, 39, 224, 39, 199], ["+", 63, 214, 205, 227, 39, 224, 225, 226, 0, 70], ["+", 63, 214, 205, 227, 39, 224, 225, 226, 0, 203], ["+", 63, 214, 205, 227, 39, 224, 225, 226, 0, 73], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 380
| 22
|
using System;
class program {
static void Main() {
int n = int.Parse(Console.ReadLine());
ulong ans = 0;
for (int i = 1; i <= n; i++) {
ans += (ulong)(i * ((n / i) + 1) * (n / i) / 2);
}
Console.WriteLine(ans);
}
}
|
using System;
class program {
static void Main() {
ulong n = ulong.Parse(Console.ReadLine());
ulong ans = 0;
for (ulong i = 1; i <= n; i++) {
ans += i * ((n / i) + 1) * (n / i) / 2;
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 1, 0, 11, 12, 74, 51, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 74, 51, 23, 0, 25]]
| 8
| 83
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;
class Solver {
public Scanner sc;
public void Solve() {
int N, M;
sc.Make(out N, out M);
ModInt.Build(M + 1);
ModInt r = ModInt.Perm(M, N);
for (int i = 1; i <= N; i++) {
if (i % 2 == 1)
r -= ModInt.Comb(N, i) * ModInt.Perm(M - i, N - i);
else
r += ModInt.Comb(N, i) * ModInt.Perm(M - i, N - i);
}
Console.WriteLine(r * ModInt.Perm(M, N));
}
}
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; // i!
private static ModInt[] inv; // 1/i
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] = fac[0] = fac[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(int n) => fac[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Inv(int n) => inv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt FacInv(int n) => facinv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Comb(int n, int r) {
if (n < r)
return 0;
if (n == r)
return 1;
return fac[n] * facinv[r] * facinv[n - r];
}
public static ModInt Perm(int n, int r) {
if (n < r)
return 0;
if (n == r)
return 1;
return fac[n] * facinv[n - r];
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var sol = new Solver() { sc = new Scanner() };
// var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();
sol.Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
[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 void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] 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;
}
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 string Concat<T>(this IEnumerable<T> A,
string sp) => string.Join(sp, A);
public static IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
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);
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 void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
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 Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
public static implicit
operator Pair<T1, T2>((T1 f, T2 s)p) => new Pair<T1, T2>(p.f, p.s);
}
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 Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
public static implicit operator Pair<T1, T2, T3>((T1 f, T2 s, T3 t)p) =>
new Pair<T1, T2, T3>(p.f, p.s, p.t);
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;
class Solver {
public Scanner sc;
public void Solve() {
int N, M;
sc.Make(out N, out M);
ModInt.Build(M + 1);
ModInt r = ModInt.Perm(M, N);
for (int i = 1; i <= N; i++) {
if (i % 2 == 1)
r -= ModInt.Comb(N, i) * ModInt.Perm(M - i, N - i);
else
r += ModInt.Comb(N, i) * ModInt.Perm(M - i, N - i);
}
Console.WriteLine(r * ModInt.Perm(M, N));
}
}
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; // i!
private static ModInt[] inv; // 1/i
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] = fac[0] = fac[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(int n) => fac[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Inv(int n) => inv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt FacInv(int n) => facinv[n];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt Comb(int n, int r) {
if (n < r)
return 0;
if (n == r)
return 1;
return fac[n] * facinv[r] * facinv[n - r];
}
public static ModInt Perm(int n, int r) {
if (n < r)
return 0;
return fac[n] * facinv[n - r];
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var sol = new Solver() { sc = new Scanner() };
// var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();
sol.Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
[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 void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] 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;
}
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 string Concat<T>(this IEnumerable<T> A,
string sp) => string.Join(sp, A);
public static IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
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);
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 void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
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 Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
public static implicit
operator Pair<T1, T2>((T1 f, T2 s)p) => new Pair<T1, T2>(p.f, p.s);
}
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 Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
public static implicit operator Pair<T1, T2, T3>((T1 f, T2 s, T3 t)p) =>
new Pair<T1, T2, T3>(p.f, p.s, p.t);
}
#endregion
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35]]
| 8
| 2,757
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
class Program {
static void Main() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var solver = new Solver(sw);
// var t = new Thread(solver.solve, 1 << 28); // 256 MB
// t.Start();
// t.Join();
solver.solve();
sw.Flush();
}
}
class Solver {
StreamWriter sw;
Scan sc;
void Prt(string a) => sw.WriteLine(a);
void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
void Prt(params object[] a) => Prt(string.Join(" ", a));
public Solver(StreamWriter sw) {
this.sw = sw;
this.sc = new Scan();
}
public void solve() {
int n = sc.Int;
var a = sc.LongArr;
long x = a[0], y = a[1];
long z = 0;
for (int i = 2; i < n; i++) {
z ^= a[i];
}
long sum = x + y, xor = z;
var bits = new int[50];
int cz = 0;
for (int i = 50 - 1; i >= 0; i--) {
int fsum = (int)((sum >> i) & 1) + cz * 2;
int fxor = (int)((xor >> i) & 1);
bool ok = false;
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 2; k++) {
int sm = j + k;
int xr = j & 1;
if (fsum == sm && xr == fxor) {
Assert(!ok);
ok = true;
bits[i] = j;
cz = k;
}
}
}
if (!ok) {
Prt(-1);
return;
}
}
var dp = new long[2];
dp[0] = -LM;
for (int i = 50 - 1; i >= 0; i--) {
var nex = new long[2];
nex[0] = -LM;
if (bits[i] == 0) {
if (((x >> i) & 1) == 1) {
nex[0] = Math.Max(nex[0], Math.Max(dp[0], dp[1]) * 2);
} else {
nex[0] = Math.Max(nex[0], dp[0] * 2);
nex[1] = Math.Max(nex[1], dp[1] * 2);
}
} else if (bits[i] == 1) {
if (((x >> i) & 1) == 1) {
nex[1] = Math.Max(nex[1], dp[1] * 2 + 1);
nex[0] = Math.Max(nex[0], Math.Max(dp[0] * 2 + 1, dp[1] * 2));
} else {
nex[1] = Math.Max(nex[1], dp[1] * 2);
nex[0] = Math.Max(nex[0], dp[0] * 2 + 1);
}
} else {
if (((x >> i) & 1) == 1) {
nex[1] = Math.Max(nex[1], dp[1] * 2 + 1);
nex[0] = Math.Max(nex[0], dp[0] * 2 + 1);
} else {
nex[0] = Math.Max(nex[0], dp[0] * 2 + 1);
}
}
dp = nex;
}
long ans = dp.Max();
Prt(ans <= 0 ? -1 : x - ans);
}
}
class pair<T, U> : IComparable<pair<T, U>> {
public T v1;
public U v2;
public pair() : this(default(T), default(U)) {}
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) {
int c = Comparer<T>.Default.Compare(v1, a.v1);
return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
}
public override string ToString() => v1 + " " + v2;
public void Deconstruct(out T a, out U b) {
a = v1;
b = v2;
}
}
static class util {
public static readonly int M = 1000000007;
// public static readonly int M = 998244353;
public static readonly long LM = 1L << 60;
public static readonly double eps = 1e-11;
public static void DBG(string a) => Console.Error.WriteLine(a);
public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
public static void DBG(params object[] a) => DBG(string.Join(" ", a));
public static void Assert(params bool[] conds) {
if (conds.Any(x => !x))
throw new Exception();
}
public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1,
v2);
public static int CompareList<T>(IList<T> a, IList<T> b)
where T : IComparable<T> {
for (int i = 0; i < a.Count && i < b.Count; i++)
if (a[i].CompareTo(b[i]) != 0)
return a[i].CompareTo(b[i]);
return a.Count.CompareTo(b.Count);
}
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h
&& j >= 0 && j < w;
public static readonly int[] dd = { 0, 1, 0, -1 };
// static readonly string dstring = "RDLU";
public static IEnumerable<P>
adjacents(int i, int j) => Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k], j + dd[k ^ 1]));
public static IEnumerable<P> adjacents(int i, int j, int h, int w) =>
adjacents(i, j).Where(p => inside(p.v1, p.v2, h, w));
public static IEnumerable<P> adjacents(this P p) => adjacents(p.v1, p.v2);
public static IEnumerable<P> adjacents(this P p, int h,
int w) => adjacents(p.v1, p.v2, h, w);
public static IEnumerable<int> all_subset(this int p) {
for (int i = 0;; i = i - p & p) {
yield return i;
if (i == p)
break;
}
}
public static Dictionary<T, int>
compress<T>(this IEnumerable<T> a) => a.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
public static Dictionary<T, int>
compress<T>(params IEnumerable<T>[] a) => compress(a.SelectMany(x => x));
public static T[] inv<T>(this Dictionary<T, int> dic) {
var res = new T[dic.Count];
foreach (var item in dic)
res[item.Value] = item.Key;
return res;
}
public static void swap<T>(ref T a, ref T b)
where T : struct {
var t = a;
a = b;
b = t;
}
public static void swap<T>(this IList<T> a, int i, int j)
where T : struct {
var t = a[i];
a[i] = a[j];
a[j] = t;
}
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
}
class Scan {
StreamReader sr;
public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scan(string path) { sr = new StreamReader(path); }
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => ReadLine.Trim();
public string ReadLine => sr.ReadLine();
public pair<T, U> Pair<T, U>() {
T a;
U b;
Multi(out a, out b);
return new pair<T, U>(a, b);
}
public P P => Pair<int, int>();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr =>
Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
public void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
class Program {
static void Main() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var solver = new Solver(sw);
// var t = new Thread(solver.solve, 1 << 28); // 256 MB
// t.Start();
// t.Join();
solver.solve();
sw.Flush();
}
}
class Solver {
StreamWriter sw;
Scan sc;
void Prt(string a) => sw.WriteLine(a);
void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
void Prt(params object[] a) => Prt(string.Join(" ", a));
public Solver(StreamWriter sw) {
this.sw = sw;
this.sc = new Scan();
}
public void solve() {
int n = sc.Int;
var a = sc.LongArr;
long x = a[0], y = a[1];
long z = 0;
for (int i = 2; i < n; i++) {
z ^= a[i];
}
long sum = x + y, xor = z;
var bits = new int[50];
int cz = 0;
for (int i = 50 - 1; i >= 0; i--) {
int fsum = (int)((sum >> i) & 1) + cz * 2;
int fxor = (int)((xor >> i) & 1);
bool ok = false;
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 2; k++) {
int sm = j + k;
int xr = j & 1;
if (fsum == sm && xr == fxor) {
Assert(!ok);
ok = true;
bits[i] = j;
cz = k;
}
}
}
if (!ok) {
Prt(-1);
return;
}
}
var dp = new long[2];
dp[0] = -LM;
for (int i = 50 - 1; i >= 0; i--) {
var nex = new long[2];
nex[0] = -LM;
if (bits[i] == 0) {
if (((x >> i) & 1) == 1) {
nex[0] = Math.Max(nex[0], Math.Max(dp[0], dp[1]) * 2);
} else {
nex[0] = Math.Max(nex[0], dp[0] * 2);
nex[1] = Math.Max(nex[1], dp[1] * 2);
}
} else if (bits[i] == 1) {
if (((x >> i) & 1) == 1) {
nex[1] = Math.Max(nex[1], dp[1] * 2 + 1);
nex[0] = Math.Max(nex[0], Math.Max(dp[0] * 2 + 1, dp[1] * 2));
} else {
nex[1] = Math.Max(nex[1], dp[1] * 2);
nex[0] = Math.Max(nex[0], dp[0] * 2 + 1);
}
} else {
if (((x >> i) & 1) == 1) {
nex[1] = Math.Max(nex[1], dp[1] * 2 + 1);
nex[0] = Math.Max(nex[0], dp[0] * 2 + 1);
} else {
nex[0] = Math.Max(nex[0], dp[0] * 2 + 1);
}
}
dp = nex;
}
long ans = x - dp.Max();
if (ans >= x || ans < 0 || (x - ans ^ y + ans) != z) {
Prt(-1);
} else {
Prt(ans);
}
}
}
class pair<T, U> : IComparable<pair<T, U>> {
public T v1;
public U v2;
public pair() : this(default(T), default(U)) {}
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) {
int c = Comparer<T>.Default.Compare(v1, a.v1);
return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
}
public override string ToString() => v1 + " " + v2;
public void Deconstruct(out T a, out U b) {
a = v1;
b = v2;
}
}
static class util {
public static readonly int M = 1000000007;
// public static readonly int M = 998244353;
public static readonly long LM = 1L << 60;
public static readonly double eps = 1e-11;
public static void DBG(string a) => Console.Error.WriteLine(a);
public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
public static void DBG(params object[] a) => DBG(string.Join(" ", a));
public static void Assert(params bool[] conds) {
if (conds.Any(x => !x))
throw new Exception();
}
public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1,
v2);
public static int CompareList<T>(IList<T> a, IList<T> b)
where T : IComparable<T> {
for (int i = 0; i < a.Count && i < b.Count; i++)
if (a[i].CompareTo(b[i]) != 0)
return a[i].CompareTo(b[i]);
return a.Count.CompareTo(b.Count);
}
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h
&& j >= 0 && j < w;
public static readonly int[] dd = { 0, 1, 0, -1 };
// static readonly string dstring = "RDLU";
public static IEnumerable<P>
adjacents(int i, int j) => Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k], j + dd[k ^ 1]));
public static IEnumerable<P> adjacents(int i, int j, int h, int w) =>
adjacents(i, j).Where(p => inside(p.v1, p.v2, h, w));
public static IEnumerable<P> adjacents(this P p) => adjacents(p.v1, p.v2);
public static IEnumerable<P> adjacents(this P p, int h,
int w) => adjacents(p.v1, p.v2, h, w);
public static IEnumerable<int> all_subset(this int p) {
for (int i = 0;; i = i - p & p) {
yield return i;
if (i == p)
break;
}
}
public static Dictionary<T, int>
compress<T>(this IEnumerable<T> a) => a.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
public static Dictionary<T, int>
compress<T>(params IEnumerable<T>[] a) => compress(a.SelectMany(x => x));
public static T[] inv<T>(this Dictionary<T, int> dic) {
var res = new T[dic.Count];
foreach (var item in dic)
res[item.Value] = item.Key;
return res;
}
public static void swap<T>(ref T a, ref T b)
where T : struct {
var t = a;
a = b;
b = t;
}
public static void swap<T>(this IList<T> a, int i, int j)
where T : struct {
var t = a[i];
a[i] = a[j];
a[j] = t;
}
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
}
class Scan {
StreamReader sr;
public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scan(string path) { sr = new StreamReader(path); }
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => ReadLine.Trim();
public string ReadLine => sr.ReadLine();
public pair<T, U> Pair<T, U>() {
T a;
U b;
Multi(out a, out b);
return new pair<T, U>(a, b);
}
public P P => Pair<int, int>();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr =>
Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
public void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["-", 3, 4, 0, 28, 0, 41, 64, 241, 0, 33], ["-", 3, 4, 0, 28, 0, 41, 64, 241, 0, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 140], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 72], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 2,580
| 38
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
class Solver {
public Scanner sc;
public void Solve() {
var N = sc.Int;
var A = sc.ArrLong;
var xor = 0L;
for (int i = 2; i < N; i++)
xor ^= A[i];
var S = A[0] + A[1];
if ((S + xor) % 2 == 1)
Fail(-1);
var D = (S - xor) / 2;
if (D < 0 || D >= A[0] || (D & xor) != 0)
Fail(-1);
var res = D;
for (int i = 50 - 1; i >= 0; i--) {
if ((1 & xor >> i) == 1 && (res ^ (1L << i)) < A[0])
res += 1L << i;
}
if (res == 0)
Fail(-1);
Console.WriteLine(A[0] - res);
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var sol = new Solver() { sc = new Scanner() };
// var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();
sol.Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
[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 void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] 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;
}
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 string Concat<T>(this IEnumerable<T> A,
string sp) => string.Join(sp, A);
public static IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
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);
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 void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
class Solver {
public Scanner sc;
public void Solve() {
var N = sc.Int;
var A = sc.ArrLong;
var xor = 0L;
for (int i = 2; i < N; i++)
xor ^= A[i];
var S = A[0] + A[1];
if ((A[0] ^ A[1] ^ xor) == 0)
Fail(0);
if ((S + xor) % 2 == 1)
Fail(-1);
var D = (S - xor) / 2;
if (D < 0 || D >= A[0] || (D & xor) != 0)
Fail(-1);
var res = D;
for (int i = 50 - 1; i >= 0; i--) {
if ((1 & xor >> i) == 1 && (res ^ (1L << i)) < A[0])
res += 1L << i;
}
if (res == 0)
Fail(-1);
Console.WriteLine(A[0] - res);
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var sol = new Solver() { sc = new Scanner() };
// var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join();
sol.Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
[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 void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] 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;
}
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 string Concat<T>(this IEnumerable<T> A,
string sp) => string.Join(sp, A);
public static IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int ArgMax<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
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);
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 void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
#endregion
|
[["+", 31, 23, 0, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 140], ["+", 31, 23, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 140], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24]]
| 8
| 1,703
| 23
|
using System;
using CompLib.Util;
public class Program {
private int N;
private long[] A;
public void Solve() {
var sc = new Scanner();
N = sc.NextInt();
A = sc.LongArray();
long other = 0;
for (int i = 2; i < N; i++) {
other ^= A[i];
}
// xorが0だと後手勝ち
// 非0だと先手
// A_0 xor A_1 がotherになるようにする
// and はこれになる
long and = (A[0] + A[1] - other);
if (and % 2 != 0) {
Console.WriteLine("-1");
return;
}
and /= 2;
// A_0を超えないかつ最大
long f = A[0] + A[1] - and * 2;
if ((f & and) > 0) {
Console.WriteLine("-1");
return;
}
long tmp = and;
for (int i = 50; i >= 0; i--) {
if ((f & (1L << i)) == 0)
continue;
if ((tmp | (1L << i)) > A[0])
continue;
tmp |= (1L << i);
}
if (tmp == 0) {
Console.WriteLine("-1");
return;
}
long ans = A[0] - tmp;
long ans2 = A[0] + A[1] - tmp;
if ((tmp ^ ans2) != other) {
Console.WriteLine("-1");
return;
}
Console.WriteLine(ans);
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using CompLib.Util;
public class Program {
private int N;
private long[] A;
public void Solve() {
var sc = new Scanner();
N = sc.NextInt();
A = sc.LongArray();
long other = 0;
for (int i = 2; i < N; i++) {
other ^= A[i];
}
// xorが0だと後手勝ち
// 非0だと先手
// A_0 xor A_1 がotherになるようにする
// and はこれになる
long and = (A[0] + A[1] - other);
if (and % 2 != 0) {
Console.WriteLine("-1");
return;
}
and /= 2;
if (and > A[0]) {
Console.WriteLine("-1");
return;
}
// A_0を超えないかつ最大
long f = A[0] + A[1] - and * 2;
if ((f & and) > 0) {
Console.WriteLine("-1");
return;
}
long tmp = and;
for (int i = 50; i >= 0; i--) {
if ((f & (1L << i)) == 0)
continue;
if ((tmp | (1L << i)) > A[0])
continue;
tmp |= (1L << i);
}
if (tmp == 0) {
Console.WriteLine("-1");
return;
}
long ans = A[0] - tmp;
long ans2 = A[0] + A[1] - tmp;
if ((tmp ^ ans2) != other) {
Console.WriteLine("-1");
return;
}
Console.WriteLine(ans);
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 635
| 22
|
using System;
public class Solve {
static void Main(string[] args) {
var value = Console.ReadLine();
if (value[0] < 'A')
Console.WriteLine("a");
else
Console.WriteLine("A");
}
}
|
using System;
public class Solve {
static void Main(string[] args) {
var value = Console.ReadLine();
if (value[0] < 'a')
Console.WriteLine("A");
else
Console.WriteLine("a");
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 58
| 6
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder.Contest.A {
static class Program {
public static void Solve(Scanner cin) {
var s = cin.Read();
if (s[0] >= 'A')
Console.WriteLine("A");
else
Console.WriteLine("a");
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
Solve(cin);
Console.Out.Flush();
}
}
class Scanner {
string[] s;
int i;
char[] separator = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Read() => ReadString();
public string ReadString() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return ReadString();
i = 0;
return s[i++];
}
public string[] ReadStringArray(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadString();
}
return Array;
}
public int ReadInt() { return int.Parse(ReadString()); }
public int[] ReadIntArray(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadInt() + add;
}
return Array;
}
public long ReadLong() { return long.Parse(ReadString()); }
public long[] ReadLongArray(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadLong() + add;
}
return Array;
}
public double ReadDouble() { return double.Parse(ReadString()); }
public double[] ReadDoubleArray(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadDouble() + add;
}
return Array;
}
public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(),
typeof(T1));
public (T1, T2) ReadValue<T1, T2>() {
var inputs = ReadStringArray(2);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
return (v1, v2);
}
public (T1, T2, T3) ReadValue<T1, T2, T3>() {
var inputs = ReadStringArray(3);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
return (v1, v2, v3);
}
public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var inputs = ReadStringArray(4);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
return (v1, v2, v3, v4);
}
public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var inputs = ReadStringArray(5);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
return (v1, v2, v3, v4, v5);
}
public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() {
var inputs = ReadStringArray(6);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
return (v1, v2, v3, v4, v5, v6);
}
public (T1, T2, T3, T4, T5, T6,
T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() {
var inputs = ReadStringArray(7);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7));
return (v1, v2, v3, v4, v5, v6, v7);
}
public T1[] ReadValueArray<T1>(int N) {
var v1 = new T1[N];
for (int i = 0; i < N; i++) {
v1[i] = ReadValue<T1>();
}
return v1;
}
public (T1[], T2[]) ReadValueArray<T1, T2>(int N) {
var (v1, v2) = (new T1[N], new T2[N]);
for (int i = 0; i < N; i++) {
var (t1, t2) = ReadValue<T1, T2>();
v1[i] = t1;
v2[i] = t2;
}
return (v1, v2);
}
public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) {
var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3) = ReadValue<T1, T2, T3>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
}
return (v1, v2, v3);
}
public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) {
var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
}
return (v1, v2, v3, v4);
}
public (T1[], T2[], T3[], T4[],
T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) {
var (v1, v2, v3, v4, v5) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
}
return (v1, v2, v3, v4, v5);
}
public (T1[], T2[], T3[], T4[], T5[],
T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) {
var (v1, v2, v3, v4, v5, v6) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
}
return (v1, v2, v3, v4, v5, v6);
}
public (T1[], T2[], T3[], T4[], T5[], T6[],
T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) {
var (v1, v2, v3, v4, v5, v6, v7) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N],
new T7[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6, t7) =
ReadValue<T1, T2, T3, T4, T5, T6, T7>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
v7[i] = t7;
}
return (v1, v2, v3, v4, v5, v6, v7);
}
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder.Contest.A {
static class Program {
public static void Solve(Scanner cin) {
var s = cin.Read();
if (s[0] >= 'a')
Console.WriteLine("a");
else
Console.WriteLine("A");
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
Solve(cin);
Console.Out.Flush();
}
}
class Scanner {
string[] s;
int i;
char[] separator = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Read() => ReadString();
public string ReadString() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return ReadString();
i = 0;
return s[i++];
}
public string[] ReadStringArray(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadString();
}
return Array;
}
public int ReadInt() { return int.Parse(ReadString()); }
public int[] ReadIntArray(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadInt() + add;
}
return Array;
}
public long ReadLong() { return long.Parse(ReadString()); }
public long[] ReadLongArray(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadLong() + add;
}
return Array;
}
public double ReadDouble() { return double.Parse(ReadString()); }
public double[] ReadDoubleArray(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadDouble() + add;
}
return Array;
}
public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(),
typeof(T1));
public (T1, T2) ReadValue<T1, T2>() {
var inputs = ReadStringArray(2);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
return (v1, v2);
}
public (T1, T2, T3) ReadValue<T1, T2, T3>() {
var inputs = ReadStringArray(3);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
return (v1, v2, v3);
}
public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var inputs = ReadStringArray(4);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
return (v1, v2, v3, v4);
}
public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var inputs = ReadStringArray(5);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
return (v1, v2, v3, v4, v5);
}
public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() {
var inputs = ReadStringArray(6);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
return (v1, v2, v3, v4, v5, v6);
}
public (T1, T2, T3, T4, T5, T6,
T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() {
var inputs = ReadStringArray(7);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7));
return (v1, v2, v3, v4, v5, v6, v7);
}
public T1[] ReadValueArray<T1>(int N) {
var v1 = new T1[N];
for (int i = 0; i < N; i++) {
v1[i] = ReadValue<T1>();
}
return v1;
}
public (T1[], T2[]) ReadValueArray<T1, T2>(int N) {
var (v1, v2) = (new T1[N], new T2[N]);
for (int i = 0; i < N; i++) {
var (t1, t2) = ReadValue<T1, T2>();
v1[i] = t1;
v2[i] = t2;
}
return (v1, v2);
}
public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) {
var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3) = ReadValue<T1, T2, T3>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
}
return (v1, v2, v3);
}
public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) {
var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
}
return (v1, v2, v3, v4);
}
public (T1[], T2[], T3[], T4[],
T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) {
var (v1, v2, v3, v4, v5) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
}
return (v1, v2, v3, v4, v5);
}
public (T1[], T2[], T3[], T4[], T5[],
T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) {
var (v1, v2, v3, v4, v5, v6) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
}
return (v1, v2, v3, v4, v5, v6);
}
public (T1[], T2[], T3[], T4[], T5[], T6[],
T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) {
var (v1, v2, v3, v4, v5, v6, v7) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N],
new T7[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6, t7) =
ReadValue<T1, T2, T3, T4, T5, T6, T7>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
v7[i] = t7;
}
return (v1, v2, v3, v4, v5, v6, v7);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 2,454
| 6
|
using System;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
int s = Console.Read();
if (('A' <= s) && (s <= 'Z')) {
Console.WriteLine("A");
} else if (('a' <= s) && (s <= 'a')) {
Console.WriteLine("a");
}
}
}
}
|
using System;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
int s = Console.Read();
if (('A' <= s) && (s <= 'Z')) {
Console.Write('A');
} else if (('a' <= s) && (s <= 'z')) {
Console.Write('a');
}
}
}
}
|
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 15, 16, 12, 23, 0, 16, 12, 252, 0, 253], ["+", 15, 16, 12, 23, 0, 16, 12, 252, 0, 253]]
| 8
| 90
| 14
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var a = Console.ReadLine();
var A = a.ToLower();
if (a == A) {
Console.WriteLine(a.ToUpper());
} else {
Console.WriteLine(A);
}
}
}
}
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var a = Console.ReadLine();
var A = a.ToLower();
if (a == A) {
Console.WriteLine("a");
} else {
Console.WriteLine("A");
}
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 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
| 69
| 8
|
using System;
namespace Contest {
class Program {
static void Main(string[] args) {
var a = Console.ReadLine();
if (Char.IsUpper(a[0])) {
Console.WriteLine(a.ToLower());
} else {
Console.WriteLine(a.ToUpper());
}
}
}
}
|
using System;
namespace Contest {
class Program {
static void Main(string[] args) {
var a = Console.ReadLine();
if (Char.IsUpper(a[0])) {
Console.WriteLine("A");
} else {
Console.WriteLine("a");
}
}
}
}
|
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 70
| 14
|
using System;
using System.Text;
using static ConsoleReader;
class Program {
static void Main(string[] args) {
var a = Read<char>();
char result;
if (char.IsLower(a))
result = char.ToUpper(a);
else
result = char.ToLower(a);
Console.WriteLine(result);
}
}
public static class IntExtentions {
public static void Times(this int n, Action<int> action) {
for (var i = 0; i < n; i++) {
action(i);
}
}
public static void Times(this(int n, int m) dimensions,
Action<int, int> action) {
var (n, m) = dimensions;
n.Times(i => m.Times(j => action(i, j)));
}
}
public static class ConsoleReader {
public static T Read<T>()
where T : IConvertible {
var inputBuffer = new StringBuilder();
int currChar;
while ((currChar = Console.Read()) != -1) {
if (!char.IsWhiteSpace((char)currChar)) {
inputBuffer.Append((char)currChar);
} else if (inputBuffer.Length != 0) {
break;
}
}
return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
}
public static T[] ReadArray<T>(int count)
where T : IConvertible {
if (count < 0) {
throw new ArgumentOutOfRangeException(nameof(count),
$"'{nameof(count)}' must be >= 0");
}
var result = new T[count];
for (var i = 0; i < count; i++) {
result[i] = Read<T>();
}
return result;
}
}
|
using System;
using System.Text;
using static ConsoleReader;
class Program {
static void Main(string[] args) {
var a = Read<char>();
char result;
if (char.IsLower(a))
result = 'a';
else
result = 'A';
Console.WriteLine(result);
}
}
public static class IntExtentions {
public static void Times(this int n, Action<int> action) {
for (var i = 0; i < n; i++) {
action(i);
}
}
public static void Times(this(int n, int m) dimensions,
Action<int, int> action) {
var (n, m) = dimensions;
n.Times(i => m.Times(j => action(i, j)));
}
}
public static class ConsoleReader {
public static T Read<T>()
where T : IConvertible {
var inputBuffer = new StringBuilder();
int currChar;
while ((currChar = Console.Read()) != -1) {
if (!char.IsWhiteSpace((char)currChar)) {
inputBuffer.Append((char)currChar);
} else if (inputBuffer.Length != 0) {
break;
}
}
return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
}
public static T[] ReadArray<T>(int count)
where T : IConvertible {
if (count < 0) {
throw new ArgumentOutOfRangeException(nameof(count),
$"'{nameof(count)}' must be >= 0");
}
var result = new T[count];
for (var i = 0; i < count; i++) {
result[i] = Read<T>();
}
return result;
}
}
|
[["-", 64, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 57, 64, 1, 0, 11, 12, 252, 0, 104], ["-", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 75, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 75, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 75, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 75, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 75, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 1, 0, 11, 12, 252, 0, 104], ["+", 0, 57, 75, 1, 0, 11, 12, 252, 0, 253]]
| 8
| 369
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program {
static void Main(string[] args) {
// 入力
string[] sS = System.Console.ReadLine().Trim().Split(' ');
int iN = int.Parse(sS[0]);
sS = System.Console.ReadLine().Trim().Split(' ');
int iOut = 0;
for (int i = 0; i < sS.Length; i++) {
int iA = int.Parse(sS[i]);
if (i % 2 == 0 && iA % 2 == 1) {
iOut += 1;
} // マスが奇数(0始まりなので1ずれる)で中身も奇数
}
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// 解析 // 出力
System.Console.WriteLine("{0}", iOut.ToString().Trim());
// 解析 // 出力
System.Console.WriteLine("{0}", iOut.ToString().Trim());
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program {
static void Main(string[] args) {
// 入力
string[] sS = System.Console.ReadLine().Trim().Split(' ');
int iN = int.Parse(sS[0]);
sS = System.Console.ReadLine().Trim().Split(' ');
int iOut = 0;
for (int i = 0; i < sS.Length; i++) {
int iA = int.Parse(sS[i]);
if (i % 2 == 0 && iA % 2 == 1) {
iOut += 1;
} // マスが奇数(0始まりなので1ずれる)で中身も奇数
}
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// 解析 // 出力
System.Console.WriteLine("{0}", iOut.ToString().Trim());
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
|
[["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 271
| 21
|
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine().Trim());
string[] line = Console.ReadLine().Trim().Split(' ');
var a = Array.ConvertAll(line, int.Parse);
var count = 0;
for (int i = 0; i < n / 2; i += 2)
if (a[i] % 2 == 1)
count++;
Console.WriteLine(count);
}
}
|
using System;
public class Hello {
public static void Main() {
var n = int.Parse(Console.ReadLine().Trim());
string[] line = Console.ReadLine().Trim().Split(' ');
var a = Array.ConvertAll(line, int.Parse);
var count = 0;
for (int i = 0; i < n; i++)
if (i % 2 == 0 && a[i] % 2 == 1)
count++;
Console.WriteLine(count);
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 85], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["-", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 8, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["+", 8, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 7, 8, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 57, 15, 16, 17, 98]]
| 8
| 113
| 11
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
long N = long.Parse(Console.ReadLine());
long[] A =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
int cnt = A.Where((v, i) => i % 2 == 1 && v % 2 == 1).Count();
Console.WriteLine(cnt);
}
}
}
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
long N = long.Parse(Console.ReadLine());
int[] A = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
int cnt = A.Where((v, i) => i % 2 == 0).Count((v) => v % 2 != 0);
Console.WriteLine(cnt);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 218, 8, 16, 31, 16, 31, 16, 17, 109], ["-", 0, 218, 8, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 28, 0, 218, 8, 16, 31, 16, 17, 60], ["-", 0, 28, 0, 218, 8, 16, 31, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 98], ["-", 0, 218, 8, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 17, 109], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 79]]
| 8
| 161
| 21
|
using System;
using System.Collections.Generic;
// using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var n = Read().Long();
var ans = 0;
for (int i = 1; i <= n; i++) {
var start = (int)Math.Sqrt(i / 6);
for (int x = 1; x <= 84; x++) {
if (x * x > i) {
break;
}
for (int y = x; y <= 84; y++) {
if (x * x + y * y + x * y + y > i) {
break;
}
for (int z = y; z <= 84; z++) {
if (x * x + y * y + z * z + x * y + y * z + z * x > i) {
break;
}
if (x * x + y * y + z * z + x * y + y * z + z * x == i) {
if (x == y && y == z) {
ans++;
} else if (x == y && y != z) {
ans += 3;
} else if (x != y && x == z) {
ans += 3;
} else {
ans += 6;
}
}
}
}
}
Write(ans);
ans = 0;
}
Read();
// WriteRead(1);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
// using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var n = Read().Long();
var ans = 0;
for (int i = 1; i <= n; i++) {
var start = (int)Math.Sqrt(i / 6);
for (int x = 1; x <= 100; x++) {
if (x * x > i) {
break;
}
for (int y = x; y <= 100; y++) {
if (x * x + y * y + x * y + y > i) {
break;
}
for (int z = y; z <= 100; z++) {
if (x * x + y * y + z * z + x * y + y * z + z * x > i) {
break;
}
if (x * x + y * y + z * z + x * y + y * z + z * x == i) {
if (x == y && y == z) {
ans++;
} else if (x != y && x != z && y != z) {
ans += 6;
} else {
ans += 3;
}
}
}
}
}
Write(ans);
ans = 0;
}
Read();
// WriteRead(1);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 17, 79], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 79], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 57, 75, 57, 0, 25], ["-", 64, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 57, 64, 196, 0, 57, 75, 57, 0, 95], ["-", 64, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["-", 64, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["-", 75, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 79], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 75, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 75, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 1,386
| 31
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace AtCoder.C {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var N = ReadLong();
var f = new long[N + 1];
for (int x = 1; x <= 100; x++) {
for (int y = 1; y <= 100; y++) {
for (int z = 1; z <= 100; z++) {
var n = x * x + y * y + z * z + x * y + y * z + z * x;
if (n < N) {
f[n]++;
}
}
}
}
var sb = new StringBuilder();
for (int i = 1; i <= N; i++) {
sb.AppendLine(f[i].ToString());
}
return sb.ToString().Trim();
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder.C {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var N = ReadLong();
var f = new long[N + 1];
for (int x = 1; x <= 100; x++) {
for (int y = 1; y <= 100; y++) {
for (int z = 1; z <= 100; z++) {
var n = x * x + y * y + z * z + x * y + y * z + z * x;
if (n <= N) {
f[n]++;
}
}
}
}
var sb = new StringBuilder();
for (int i = 1; i <= N; i++) {
sb.AppendLine(f[i].ToString());
}
File.WriteAllText("x.txt", sb.ToString().Trim());
return sb.ToString().Trim();
}
#region Console.Read
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static (long, long) Read2Longs() {
var ls = ReadLongs();
return (ls[0], ls[1]);
}
public static (long, long, long) Read3Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2]);
}
public static (long, long, long, long) Read4Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3]);
}
public static (long, long, long, long, long) Read5Longs() {
var ls = ReadLongs();
return (ls[0], ls[1], ls[2], ls[3], ls[4]);
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
[["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 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, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 509
| 26
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
private static void Main(string[] args) {
var n = Scanner.Integer();
var values = Enumerable.Range(1, n).Select(Check).Select(x => x.ToString());
OutAllLine(values);
}
private static int Check(int val) {
int count = 0;
for (int x = 1; x <= (int)Math.Sqrt(val); x++) {
for (int y = x; y <= (int)Math.Sqrt(val - x * x); y++) {
for (int z = y; z <= (int)Math.Sqrt(val - x * x - y * y); z++) {
if (x * x + y * y + z * z + x * y + y * z + z * x == val) {
if (x == y && y == z) {
count += 1;
} else {
count += 3;
}
}
}
}
}
return count;
}
#region Utility
static readonly StreamScanner Scanner =
new StreamScanner(Console.OpenStandardInput());
/// <summary> 一括出力 </summary>
private static void OutAllLine(IEnumerable<dynamic> items) {
var sb = new StringBuilder();
foreach (var result in items) {
sb.Append(result + "\n");
}
sb = sb.Remove(sb.Length - 1, 1);
Console.WriteLine(sb);
}
/// <summary> 素数判定 </summary>
public static bool IsPrime(int num) {
if (num < 2) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static IEnumerable<int> PrimeFactors(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
#endregion
}
#region Utility Class
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
/// <summary> 数値読み込み </summary>
public List<long> ArrayLong(int count = 0) {
var scan = new List<long>();
for (int i = 0; i < count; i++) {
scan.Add(Long());
}
return scan;
}
/// <summary> 数値読み込み </summary>
public List<int> ArrayInt(int count = 0) {
var scan = new List<int>();
for (int i = 0; i < count; i++) {
scan.Add(Integer());
}
return scan;
}
}
public class Mod109 {
public const int _7 = 1000000007;
public const int _9 = 1000000009;
public const int _3 = 998244353;
private readonly int ModValue;
public Mod109(int modValue = Mod109._7) { ModValue = modValue; }
/// <summary> 和 </summary>
public long Addition(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current + num) % ModValue));
}
/// <summary> 差 </summary>
public long Subtraction(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current - num) % ModValue));
}
/// <summary> 積 </summary>
public long Multiplication(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
1, (current, num) => ModifyPositive((current * num) % ModValue));
}
private long ModifyPositive(long value) {
return value < 0 ? (value + ModValue) : value;
}
}
public class BitArrayMaker {
public List<int> Integer(int bitValue, int length) {
var list = new List<int>();
for (int i = 0; i < length; i++) {
if (bitValue % 2 == 1) {
list.Add(i);
}
bitValue /= 2;
}
return list;
}
public bool[] Boolean(int bitValue, int length) {
var list = new bool[length];
for (int i = 0; i < length; i++) {
list[i] = bitValue % 2 == 1;
bitValue /= 2;
}
return list;
}
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
private static void Main(string[] args) {
var n = Scanner.Integer();
var values = Enumerable.Range(1, n).Select(Check).Select(x => x.ToString());
OutAllLine(values);
}
private static int Check(int val) {
int count = 0;
for (int x = 1; x <= (int)Math.Sqrt(val); x++) {
for (int y = x; y <= (int)Math.Sqrt(val - x * x); y++) {
for (int z = y; z <= (int)Math.Sqrt(val - x * x - y * y); z++) {
if (x * x + y * y + z * z + x * y + y * z + z * x == val) {
if (x == y && y == z) {
count += 1;
} else if (x == y || y == z || z == x) {
count += 3;
} else {
count += 6;
}
}
}
}
}
return count;
}
#region Utility
static readonly StreamScanner Scanner =
new StreamScanner(Console.OpenStandardInput());
/// <summary> 一括出力 </summary>
private static void OutAllLine(IEnumerable<dynamic> items) {
var sb = new StringBuilder();
foreach (var result in items) {
sb.Append(result + "\n");
}
sb = sb.Remove(sb.Length - 1, 1);
Console.WriteLine(sb);
}
/// <summary> 素数判定 </summary>
public static bool IsPrime(int num) {
if (num < 2) {
return false;
}
if (num == 2) {
return true;
}
if (num % 2 == 0) {
return false;
}
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
public static IEnumerable<int> PrimeFactors(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) //※1
{
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
#endregion
}
#region Utility Class
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (int)Long(); }
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
/// <summary> 数値読み込み </summary>
public List<long> ArrayLong(int count = 0) {
var scan = new List<long>();
for (int i = 0; i < count; i++) {
scan.Add(Long());
}
return scan;
}
/// <summary> 数値読み込み </summary>
public List<int> ArrayInt(int count = 0) {
var scan = new List<int>();
for (int i = 0; i < count; i++) {
scan.Add(Integer());
}
return scan;
}
}
public class Mod109 {
public const int _7 = 1000000007;
public const int _9 = 1000000009;
public const int _3 = 998244353;
private readonly int ModValue;
public Mod109(int modValue = Mod109._7) { ModValue = modValue; }
/// <summary> 和 </summary>
public long Addition(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current + num) % ModValue));
}
/// <summary> 差 </summary>
public long Subtraction(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
0, (current, num) => ModifyPositive((current - num) % ModValue));
}
/// <summary> 積 </summary>
public long Multiplication(IEnumerable<long> nums) {
return nums.Aggregate<long, long>(
1, (current, num) => ModifyPositive((current * num) % ModValue));
}
private long ModifyPositive(long value) {
return value < 0 ? (value + ModValue) : value;
}
}
public class BitArrayMaker {
public List<int> Integer(int bitValue, int length) {
var list = new List<int>();
for (int i = 0; i < length; i++) {
if (bitValue % 2 == 1) {
list.Add(i);
}
bitValue /= 2;
}
return list;
}
public bool[] Boolean(int bitValue, int length) {
var list = new bool[length];
for (int i = 0; i < length; i++) {
list[i] = bitValue % 2 == 1;
bitValue /= 2;
}
return list;
}
}
#endregion
}
|
[["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 106], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 17, 106], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 95], ["+", 64, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 1,296
| 21
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
// var NX = Console.ReadLine().Split(' ').Select(x =>
// long.Parse(x)).ToArray(); var L = long.Parse(Console.ReadLine());
Solve();
}
static void Solve() {
// var NM = Console.ReadLine().Split(' ').Select(x =>
// long.Parse(x)).ToArray();
var N = long.Parse(Console.ReadLine());
var X = Console.ReadLine();
var SumOne = 0;
for (int i = 0; i < N; i++) {
if (X[i] == '1')
SumOne++;
}
var ReverseOne = SumOne - 1;
var ReverseZro = SumOne + 1;
long ReverseOneSum = 0;
long ReverseZroSum = 0;
for (int i = (int)N - 1; i >= 0; i--) {
if (X[i] == '1')
ReverseOneSum += Pow(2, (N - 1 - i), ReverseOne);
ReverseOneSum %= ReverseOne;
}
for (int i = (int)N - 1; i >= 0; i--) {
if (X[i] == '1')
ReverseZroSum += Pow(2, (N - 1 - i), ReverseZro);
ReverseZroSum %= ReverseZro;
}
// for (int i = (int)N - 1; i >= 0; i--)
//{
// if (X[i] == '1')
// {
// var tmp = ReverseOneSum - Pow(2, (N - 1 - i), ReverseOne);
// tmp %= ReverseOne;
// Console.WriteLine(Cul(tmp,1));
// }
// else
// {
// var tmp = ReverseZroSum - Pow(2, (N - 1 - i), ReverseZro);
// tmp %= ReverseZro;
// Console.WriteLine(Cul(tmp, 1));
// }
//}
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
var tmp = ReverseOneSum - Pow(2, (N - 1 - i), ReverseOne);
tmp = (tmp + ReverseOne) % ReverseOne;
Console.WriteLine(Cul(tmp, 1));
} else {
var tmp = ReverseZroSum + Pow(2, (N - 1 - i), ReverseZro);
tmp = (tmp + ReverseZro) % ReverseZro;
Console.WriteLine(Cul(tmp, 1));
}
}
}
static long Cul(long num, long count) {
if (num <= 0) {
return count;
} else {
var str = Convert.ToString(num, 2);
var countone = 0;
for (int i = 0; i < str.Length; i++) {
if (str[i] == '1')
countone++;
}
return Cul(num % countone, count + 1);
}
}
static long Pow(long n, long p, int mod = (int)1e9 + 7) {
if (p == 0)
return 1; // nの0乗は1
else if (p % 2 == 0) {
var x = Pow(n, p / 2, mod);
return (x * x) % mod;
} else {
return Pow(n, p - 1, mod) * n % mod;
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
// var NX = Console.ReadLine().Split(' ').Select(x =>
// long.Parse(x)).ToArray(); var L = long.Parse(Console.ReadLine());
Solve();
}
static void Solve() {
// var NM = Console.ReadLine().Split(' ').Select(x =>
// long.Parse(x)).ToArray();
var N = long.Parse(Console.ReadLine());
var X = Console.ReadLine();
// N = 2 * 100000;
// X = new StringBuilder().Insert(0, "1", 200000).ToString();
var SumOne = 0;
for (int i = 0; i < N; i++) {
if (X[i] == '1')
SumOne++;
}
var ReverseOne = SumOne - 1;
var ReverseZro = SumOne + 1;
long ReverseOneSum = 0;
long ReverseZroSum = 0;
if (ReverseOne > 0) {
for (int i = (int)N - 1; i >= 0; i--) {
if (X[i] == '1')
ReverseOneSum += Pow(2, (N - 1 - i), ReverseOne);
ReverseOneSum %= ReverseOne;
}
}
for (int i = (int)N - 1; i >= 0; i--) {
if (X[i] == '1')
ReverseZroSum += Pow(2, (N - 1 - i), ReverseZro);
ReverseZroSum %= ReverseZro;
}
// for (int i = (int)N - 1; i >= 0; i--)
//{
// if (X[i] == '1')
// {
// var tmp = ReverseOneSum - Pow(2, (N - 1 - i), ReverseOne);
// tmp %= ReverseOne;
// Console.WriteLine(Cul(tmp,1));
// }
// else
// {
// var tmp = ReverseZroSum - Pow(2, (N - 1 - i), ReverseZro);
// tmp %= ReverseZro;
// Console.WriteLine(Cul(tmp, 1));
// }
//}
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
if (ReverseOne == 0) {
Console.WriteLine(0);
continue;
}
var tmp = ReverseOneSum - Pow(2, (N - 1 - i), ReverseOne);
tmp = (tmp + ReverseOne) % ReverseOne;
Console.WriteLine(Cul(tmp, 1));
} else {
var tmp = ReverseZroSum + Pow(2, (N - 1 - i), ReverseZro);
tmp = (tmp + ReverseZro) % ReverseZro;
Console.WriteLine(Cul(tmp, 1));
}
}
}
static long Cul(long num, long count) {
if (num <= 0) {
return count;
} else {
var str = Convert.ToString(num, 2);
var countone = 0;
for (int i = 0; i < str.Length; i++) {
if (str[i] == '1')
countone++;
}
return Cul(num % countone, count + 1);
}
}
static long Pow(long n, long p, int mod = (int)1e9 + 7) {
if (p == 0)
return 1; // nの0乗は1
else if (p % 2 == 0) {
var x = Pow(n, p / 2, mod);
return (x * x) % mod;
} else {
return Pow(n, p - 1, mod) * n % mod;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 64, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 555
| 25
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.Remoting;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static Dictionary<long, long> primeDic = new Dictionary<long, long>();
static int kTotal = 100;
static void Solve() {
var n = Input.NextInt();
var x = Input.Next();
int popcountX = CalcPopCount(x);
var xl = new int[n];
for (int i = 0; i < n; i++) {
xl[i] = x[i] - '0';
}
int div_p = CalcDiv(xl, popcountX + 1);
int div_m = CalcDiv(xl, popcountX - 1);
var power2_p = new int[n];
power2_p[0] = 1; // 2のべき乗(mod pcx+1
var power2_m = new int[n];
power2_m[0] = 1; // 2のべき乗(mod pcx-1
for (int i = 1; i < n; i++) {
power2_p[i] = power2_p[i - 1] * 2 % (popcountX + 1);
if (popcountX - 1 >= 1) {
power2_m[i] = power2_m[i - 1] * 2 % (popcountX - 1);
}
}
var ans = new int[n];
for (int i = 0; i < n; ++i) {
int ansi = 1;
// 一回目の操作
int work = 0;
if (x[i] == '0') {
work = (div_p + power2_p[n - i - 1]) % (popcountX + 1);
} else {
if (popcountX - 1 >= 1) {
work =
(div_m - power2_m[n - i - 1] + (popcountX - 1)) % (popcountX - 1);
}
}
// 0 になるまで続けるでえ
while (work > 0) {
work = work % CalcPopCount(work);
ansi++;
}
ans[i] = ansi;
}
for (int i = 0; i < ans.Length; i++) {
Console.WriteLine(ans[i]);
}
}
static int CalcDiv(int[] xl, int mod) {
if (mod <= 0) {
return -1;
}
int ans = 0;
for (int i = 0; i < xl.Length; ++i) {
ans = (ans * 2) % mod;
ans = (ans + xl[i]) % mod;
}
return ans;
}
static int CalcPopCount(int n) {
int ans = 0;
for (int i = 0; i < 32; i++) {
if ((n & (1 << i)) != 0) {
ans++;
}
}
return ans;
}
static int CalcPopCount(string x) {
int popcountX = 0;
for (int i = 0; i < x.Length; i++) {
if (x[i] == '1') {
popcountX++;
}
}
return popcountX;
}
static void div(int n, int d) {
int m = 1, q = 0;
while (d <= n) {
d <<= 1;
m <<= 1;
}
while (1 < m) {
d >>= 1;
m >>= 1;
if (n >= d) {
n -= d;
q |= m;
}
}
// q=商 / n=余り
}
#region よく使う便利関数
private static void TrialDivision(long m) {
for (long i = 2; i * i <= m; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
primeDic.Add(i, ex);
}
}
if (m >= 2) {
primeDic.Add(m, 1);
}
// note まぁ1は違うよね
}
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Runtime.Remoting;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static Dictionary<long, long> primeDic = new Dictionary<long, long>();
static int kTotal = 100;
static void Solve() {
var n = Input.NextInt();
var x = Input.Next();
int popcountX = CalcPopCount(x);
var xl = new int[n];
for (int i = 0; i < n; i++) {
xl[i] = x[i] - '0';
}
int div_p = CalcDiv(xl, popcountX + 1);
int div_m = CalcDiv(xl, popcountX - 1);
var power2_p = new int[n];
power2_p[0] = 1; // 2のべき乗(mod pcx+1
var power2_m = new int[n];
power2_m[0] = 1; // 2のべき乗(mod pcx-1
for (int i = 1; i < n; i++) {
power2_p[i] = power2_p[i - 1] * 2 % (popcountX + 1);
if (popcountX - 1 >= 1) {
power2_m[i] = power2_m[i - 1] * 2 % (popcountX - 1);
}
}
var ans = new int[n];
for (int i = 0; i < n; ++i) {
if (xl[i] == 1 && popcountX - 1 == 0) {
continue;
} // xiが0のため操作回数0
// 一回目の操作
int ansi = 1;
int work = 0;
if (x[i] == '0') {
work = (div_p + power2_p[n - i - 1]) % (popcountX + 1);
} else {
work =
(div_m - power2_m[n - i - 1] + (popcountX - 1)) % (popcountX - 1);
}
// 0 になるまで続けるでえ
while (work > 0) {
work = work % CalcPopCount(work);
ansi++;
}
ans[i] = ansi;
}
for (int i = 0; i < ans.Length; i++) {
Console.WriteLine(ans[i]);
}
}
static int CalcDiv(int[] xl, int mod) {
if (mod <= 0) {
return -1;
}
int ans = 0;
for (int i = 0; i < xl.Length; ++i) {
ans = (ans * 2) % mod;
ans = (ans + xl[i]) % mod;
}
return ans;
}
static int CalcPopCount(int n) {
int ans = 0;
for (int i = 0; i < 32; i++) {
if ((n & (1 << i)) != 0) {
ans++;
}
}
return ans;
}
static int CalcPopCount(string x) {
int popcountX = 0;
for (int i = 0; i < x.Length; i++) {
if (x[i] == '1') {
popcountX++;
}
}
return popcountX;
}
static void div(int n, int d) {
int m = 1, q = 0;
while (d <= n) {
d <<= 1;
m <<= 1;
}
while (1 < m) {
d >>= 1;
m >>= 1;
if (n >= d) {
n -= d;
q |= m;
}
}
// q=商 / n=余り
}
#region よく使う便利関数
private static void TrialDivision(long m) {
for (long i = 2; i * i <= m; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
primeDic.Add(i, ex);
}
}
if (m >= 2) {
primeDic.Add(m, 1);
}
// note まぁ1は違うよね
}
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["-", 75, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 75, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["-", 75, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["-", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 3,123
| 29
|
using System;
//毎回PopCount求めると時間足りない..
// 110100110(2)=422(10)とするとPC=5
//なのでほかのPCは3(1->0)か4(0->1)になる
//早い段階であまりだけ取ることが計算量を減らすためのポイント
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int[] X = new int[n];
for (int i = 0; i < n; i++) {
X[i] = s[i] - '0';
}
//元の数のPCを求める
int pc = 0;
foreach (var x in X)
pc += x;
// 0->1か1->0の分岐
int[] Ans = new int[n];
for (int b = 0; b < 2; b++) {
int npc = pc;
if (b == 0)
npc++; // 0->1
else
npc--; // 1->0
// 2進を10進に戻しつつ、余りをとる
int r0 = 0; //元の割った余り
for (int i = 0; i < n; i++) {
r0 = (2 * r0) % npc;
r0 += X[i];
}
//置き換え
int k = 1;
for (int i = n - 1; i >= 0; i--) {
int r;
if (X[i] == b) {
if (b == 0)
r = (r0 + k) % npc;
else
r = (r0 - k + npc) % npc;
Ans[i] = F(r) + 1;
}
k = (2 * k) % npc;
}
}
for (int i = 0; i < n; i++) {
Console.WriteLine(Ans[i]);
}
}
static public int F(int x) {
if (x == 0)
return 0;
return F(x % Pcnt(x)) + 1;
}
static public int Pcnt(int z) {
int ret = 0;
while (z > 0) {
if (z % 2 == 1)
ret++;
z /= 2;
}
return ret;
}
}
// TLE
// class Program
//{
// static void Main()
// {
// int n = int.Parse(Console.ReadLine());
// string x = Console.ReadLine();
// int v = 0;
// for(int i = 0; i < n; i++)
// {
// if(x[n - i - 1]=='1')v += (int)Math.Pow(2, i);
// }
// for(int i=0; i < n; i++)
// {
// int temp = v;
// if (x[i] == '1') temp -= (int)Math.Pow(2, n-i-1);
// if (x[i] == '0') temp += (int)Math.Pow(2, n-i-1);
// int cnt = 0;
// while (temp > 0)
// {
// int p=Popcount(temp);
// temp %= p;
// cnt++;
// }
// Console.WriteLine(cnt);
// }
// }
// static public int Popcount(int z)
// {
// int ret = 0;
// while (z > 0)
// {
// if (z % 2 == 1) ret++;
// z /= 2;
// }
// return ret;
// }
//}
// namespace C
//{
// class Program
// {
// static void Main(string[] args)
// {
// int n = int.Parse(Console.ReadLine());
// string x = Console.ReadLine();
// for (int i = 0; i < n; i++)
// {
// int t = 0;
// for (int j = 0; j < n; j++)
// {
// int p = (int)Math.Pow(2, j);
// if (n - j - 1 == i)
// {
// if (x[n - j - 1] == '0') t += 1 * p;
// }
// else
// {
// if (x[n - j - 1] == '1') t += 1 * p;
// }
// }
// int cnt = 0;
// for (; ; )
// {
// int r = Popcount(t);
// if (r == 0) break;
// cnt++;
// t %= r;
// }
// Console.WriteLine(cnt);
// }
// }
// static public int Popcount(int z)
// {
// int ret = 0;
// while (z > 0)
// {
// if (z % 2 == 1) ret++;
// z /= 2;
// }
// return ret;
// }
// }
//}
|
using System;
//毎回PopCount求めると時間足りない..
// 110100110(2)=422(10)とするとPC=5
//なのでほかのPCは3(1->0)か4(0->1)になる
//早い段階であまりだけ取ることが計算量を減らすためのポイント
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
int[] X = new int[n];
for (int i = 0; i < n; i++) {
X[i] = s[i] - '0';
}
//元の数のPCを求める
int pc = 0;
foreach (var x in X)
pc += x;
// 0->1か1->0の分岐
int[] Ans = new int[n];
for (int b = 0; b < 2; b++) {
int npc = pc;
if (b == 0)
npc++; // 0->1
else
npc--; // 1->0
if (npc <= 0)
continue;
// 2進を10進に戻しつつ、余りをとる
int r0 = 0; //元の割った余り
for (int i = 0; i < n; i++) {
r0 = (2 * r0) % npc;
r0 += X[i];
}
//置き換え
int k = 1;
for (int i = n - 1; i >= 0; i--) {
int r;
if (X[i] == b) {
if (b == 0)
r = (r0 + k) % npc;
else
r = (r0 - k + npc) % npc;
Ans[i] = F(r) + 1;
}
k = (2 * k) % npc;
}
}
for (int i = 0; i < n; i++) {
Console.WriteLine(Ans[i]);
}
}
static public int F(int x) {
if (x == 0)
return 0;
return F(x % Pcnt(x)) + 1;
}
static public int Pcnt(int z) {
int ret = 0;
while (z > 0) {
if (z % 2 == 1)
ret++;
z /= 2;
}
return ret;
}
}
// TLE
// class Program
//{
// static void Main()
// {
// int n = int.Parse(Console.ReadLine());
// string x = Console.ReadLine();
// int v = 0;
// for(int i = 0; i < n; i++)
// {
// if(x[n - i - 1]=='1')v += (int)Math.Pow(2, i);
// }
// for(int i=0; i < n; i++)
// {
// int temp = v;
// if (x[i] == '1') temp -= (int)Math.Pow(2, n-i-1);
// if (x[i] == '0') temp += (int)Math.Pow(2, n-i-1);
// int cnt = 0;
// while (temp > 0)
// {
// int p=Popcount(temp);
// temp %= p;
// cnt++;
// }
// Console.WriteLine(cnt);
// }
// }
// static public int Popcount(int z)
// {
// int ret = 0;
// while (z > 0)
// {
// if (z % 2 == 1) ret++;
// z /= 2;
// }
// return ret;
// }
//}
// namespace C
//{
// class Program
// {
// static void Main(string[] args)
// {
// int n = int.Parse(Console.ReadLine());
// string x = Console.ReadLine();
// for (int i = 0; i < n; i++)
// {
// int t = 0;
// for (int j = 0; j < n; j++)
// {
// int p = (int)Math.Pow(2, j);
// if (n - j - 1 == i)
// {
// if (x[n - j - 1] == '0') t += 1 * p;
// }
// else
// {
// if (x[n - j - 1] == '1') t += 1 * p;
// }
// }
// int cnt = 0;
// for (; ; )
// {
// int r = Popcount(t);
// if (r == 0) break;
// cnt++;
// t %= r;
// }
// Console.WriteLine(cnt);
// }
// }
// static public int Popcount(int z)
// {
// int ret = 0;
// while (z > 0)
// {
// if (z % 2 == 1) ret++;
// z /= 2;
// }
// return ret;
// }
// }
//}
|
[["+", 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, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
| 8
| 459
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.Aising_2020 {
class D {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
int n = ReadInt();
string x = Read();
int popCnt = 0;
for (int i = 0; i < n; i++) {
if (x[i] == '1') {
popCnt++;
}
}
if (popCnt == 0) {
for (int i = 0; i < n; i++) {
WriteLine(1);
}
return;
}
if (popCnt == 1) {
for (int i = 0; i < n; i++) {
if (x[n - 1] == '1') {
if (x[i] == '1') {
WriteLine(0);
} else {
WriteLine(2);
}
} else {
if (x[i] == '1') {
WriteLine(0);
} else {
WriteLine(1);
}
}
}
return;
}
int[] modsPlus = new int[n];
int[] modsMinus = new int[n];
modsPlus[0] = 1 % (popCnt + 1);
modsMinus[0] = 1 % (popCnt - 1);
int baseModPlus = 0;
int baseModMinus = 0;
if (x[n - 1] == '1') {
baseModPlus += modsPlus[0];
baseModMinus += modsMinus[0];
}
for (int i = 1; i < n; i++) {
modsPlus[i] = (modsPlus[i - 1] * 2) % (popCnt + 1);
modsMinus[i] = (modsMinus[i - 1] * 2) % (popCnt - 1);
if (x[n - 1 - i] == '1') {
baseModPlus += modsPlus[i];
baseModPlus %= popCnt + 1;
baseModMinus += modsMinus[i];
baseModMinus %= popCnt - 1;
}
}
for (int i = 0; i < n; i++) {
int mod;
if (x[i] == '1') {
mod = baseModMinus + (popCnt - 1 - modsMinus[n - 1 - i]);
mod %= popCnt - 1;
} else {
mod = baseModPlus + modsPlus[n - 1 - i];
mod %= popCnt + 1;
}
int cnt = 1;
while (mod > 0) {
int popCntTmp = 0;
int div = 1;
while (div <= mod) {
if ((mod & div) > 0) {
popCntTmp++;
}
div *= 2;
}
mod %= popCntTmp;
cnt++;
}
WriteLine(cnt);
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.Aising_2020 {
class D {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
int n = ReadInt();
string x = Read();
int popCnt = 0;
for (int i = 0; i < n; i++) {
if (x[i] == '1') {
popCnt++;
}
}
if (popCnt == 0) {
for (int i = 0; i < n; i++) {
WriteLine(1);
}
return;
}
if (popCnt == 1) {
for (int i = 0; i < n; i++) {
if (x[n - 1] == '1') {
if (x[i] == '1') {
WriteLine(0);
} else {
WriteLine(2);
}
} else {
if (i == n - 1) {
WriteLine(2);
} else if (x[i] == '1') {
WriteLine(0);
} else {
WriteLine(1);
}
}
}
return;
}
int[] modsPlus = new int[n];
int[] modsMinus = new int[n];
modsPlus[0] = 1 % (popCnt + 1);
modsMinus[0] = 1 % (popCnt - 1);
int baseModPlus = 0;
int baseModMinus = 0;
if (x[n - 1] == '1') {
baseModPlus += modsPlus[0];
baseModMinus += modsMinus[0];
}
for (int i = 1; i < n; i++) {
modsPlus[i] = (modsPlus[i - 1] * 2) % (popCnt + 1);
modsMinus[i] = (modsMinus[i - 1] * 2) % (popCnt - 1);
if (x[n - 1 - i] == '1') {
baseModPlus += modsPlus[i];
baseModPlus %= popCnt + 1;
baseModMinus += modsMinus[i];
baseModMinus %= popCnt - 1;
}
}
for (int i = 0; i < n; i++) {
int mod;
if (x[i] == '1') {
mod = baseModMinus + (popCnt - 1 - modsMinus[n - 1 - i]);
mod %= popCnt - 1;
} else {
mod = baseModPlus + modsPlus[n - 1 - i];
mod %= popCnt + 1;
}
int cnt = 1;
while (mod > 0) {
int popCntTmp = 0;
int div = 1;
while (div <= mod) {
if ((mod & div) > 0) {
popCntTmp++;
}
div *= 2;
}
mod %= popCntTmp;
cnt++;
}
WriteLine(cnt);
}
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 24]]
| 8
| 791
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int n = sc.NextInt();
string s = sc.Next();
int count = s.Where(c => c == '1').Count();
if (count == 0) {
for (int i = 0; i < n; i++) {
Console.WriteLine(1);
}
return;
}
int[] answers = new int[count + 10];
for (int i = 1; i < count + 10; i++) {
int num = i;
int answer = 0;
while (num != 0) {
string str = Convert.ToString(num, 2);
num = num % str.Where(c => c == '1').Count();
answer++;
}
answers[i] = answer;
}
long totalA = 0;
long totalB = 0;
int currentA = 1;
int currentB = 1;
for (int i = 0; i < n; i++) {
string c = s.Substring(n - i - 1, 1);
if (c == "1") {
if (count != 1) {
totalA += currentA % (count - 1);
totalA = totalA % (count - 1);
}
totalB += currentB % (count + 1);
totalB = totalB % (count + 1);
}
currentA *= 2;
currentA = currentA % (count - 1);
currentB *= 2;
currentB = currentB % (count + 1);
}
currentA = 1;
currentB = 1;
List<int> numbers = new List<int>();
for (int i = 0; i < n; i++) {
string c = s.Substring(n - i - 1, 1);
if (c == "1") {
if (count == 1) {
numbers.Add(0);
} else {
long tmp = totalA - currentA % (count - 1);
tmp = tmp % (count - 1);
if (tmp < 0) {
tmp += (count - 1);
}
numbers.Add(answers[tmp] + 1);
}
} else {
long tmp = totalB + currentB % (count + 1);
tmp = tmp % (count + 1);
numbers.Add(answers[tmp] + 1);
}
currentA *= 2;
currentA = currentA % (count - 1);
currentB *= 2;
currentB = currentB % (count + 1);
}
numbers.Reverse();
foreach (var ans in numbers) {
Console.WriteLine(ans);
}
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int n = sc.NextInt();
string s = sc.Next();
int count = s.Where(c => c == '1').Count();
if (count == 0) {
for (int i = 0; i < n; i++) {
Console.WriteLine(1);
}
return;
}
int[] answers = new int[count + 10];
for (int i = 1; i < count + 10; i++) {
int num = i;
int answer = 0;
while (num != 0) {
string str = Convert.ToString(num, 2);
num = num % str.Where(c => c == '1').Count();
answer++;
}
answers[i] = answer;
}
long totalA = 0;
long totalB = 0;
int currentA = 1;
int currentB = 1;
for (int i = 0; i < n; i++) {
string c = s.Substring(n - i - 1, 1);
if (c == "1") {
if (count != 1) {
totalA += currentA % (count - 1);
totalA = totalA % (count - 1);
}
totalB += currentB % (count + 1);
totalB = totalB % (count + 1);
}
if (count != 1) {
currentA *= 2;
currentA = currentA % (count - 1);
}
currentB *= 2;
currentB = currentB % (count + 1);
}
currentA = 1;
currentB = 1;
List<int> numbers = new List<int>();
for (int i = 0; i < n; i++) {
string c = s.Substring(n - i - 1, 1);
if (c == "1") {
if (count == 1) {
numbers.Add(0);
} else {
long tmp = totalA - currentA % (count - 1);
tmp = tmp % (count - 1);
if (tmp < 0) {
tmp += (count - 1);
}
numbers.Add(answers[tmp] + 1);
}
} else {
long tmp = totalB + currentB % (count + 1);
tmp = tmp % (count + 1);
numbers.Add(answers[tmp] + 1);
}
if (count != 1) {
currentA *= 2;
currentA = currentA % (count - 1);
}
currentB *= 2;
currentB = currentB % (count + 1);
}
numbers.Reverse();
foreach (var ans in numbers) {
Console.WriteLine(ans);
}
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["+", 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, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 856
| 16
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
static void Main(string[] args) {
checked {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var N = vals[0];
var X = Console.ReadLine();
var cnt1A = X.Count(x => x == '1');
var cnt1B = cnt1A - 1;
// X=0,1の処理
if (cnt1A == 0) {
for (int i = 0; i < N; i++) {
Console.WriteLine(1);
}
} else if (cnt1A == 1) {
for (int i = 0; i < N; i++) {
if (X[i] == '1')
Console.WriteLine(0);
else if (X[N - 1] == '1' && i != N - 1)
Console.WriteLine(2);
else
Console.WriteLine(1);
}
} else {
cnt1A++;
int[] modA = new int[N];
int[] modB = new int[N];
modA[0] = 1;
modB[0] = 1;
for (int i = 1; i < N; i++) {
modA[i] = (modA[i - 1] * 2) % cnt1A;
modB[i] = (modB[i - 1] * 2) % cnt1B;
}
long modAsum = 0;
long modBsum = 0;
for (int i = 0; i < N; i++) {
if (X[N - 1 - i] == '1') {
modAsum = (modAsum + modA[i]) % cnt1A;
modBsum = (modBsum + modB[i]) % cnt1B;
}
}
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
int K = (int)(modBsum - modB[N - 1 - i]) % cnt1B;
K = (cnt1B + K) % cnt1B;
int ans = 1;
while (K != 0) {
/*int Kp = propcnt(K);
if (Kp == 0)
{
break;
}*/
K = K % propcnt(K);
ans++;
}
Console.WriteLine(ans);
}
if (X[i] == '0') {
int K = (int)(modAsum + modA[N - 1 - i]) % cnt1A;
K = (cnt1A + K) % cnt1A;
int ans = 1;
while (K != 0) {
K = K % propcnt(K);
ans++;
}
Console.WriteLine(ans);
}
}
// var ans = A.Where((x,i)=> (x%2==1 && i%2==0)).Count();
}
}
// Console.WriteLine(propcnt(8));
Console.Out.Flush();
}
static public int propcnt(int n) {
int result = 0;
for (int i = 0; i < 25; i++) {
result += (n >> i) % 2;
}
return result;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
static void Main(string[] args) {
checked {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var N = vals[0];
var X = Console.ReadLine();
var cnt1A = X.Count(x => x == '1');
var cnt1B = cnt1A - 1;
// X=0,1の処理
if (cnt1A == 0) {
for (int i = 0; i < N; i++) {
Console.WriteLine(1);
}
} else if (cnt1A == 1) {
for (int i = 0; i < N; i++) {
if (X[i] == '1')
Console.WriteLine(0);
else if (i == N - 1)
Console.WriteLine(2);
else if (X[N - 1] == '1')
Console.WriteLine(2);
else
Console.WriteLine(1);
}
} else {
cnt1A++;
int[] modA = new int[N];
int[] modB = new int[N];
modA[0] = 1;
modB[0] = 1;
for (int i = 1; i < N; i++) {
modA[i] = (modA[i - 1] * 2) % cnt1A;
modB[i] = (modB[i - 1] * 2) % cnt1B;
}
long modAsum = 0;
long modBsum = 0;
for (int i = 0; i < N; i++) {
if (X[N - 1 - i] == '1') {
modAsum = (modAsum + modA[i]) % cnt1A;
modBsum = (modBsum + modB[i]) % cnt1B;
}
}
for (int i = 0; i < N; i++) {
if (X[i] == '1') {
int K = (int)(modBsum - modB[N - 1 - i]) % cnt1B;
K = (cnt1B + K) % cnt1B;
int ans = 1;
while (K != 0) {
/*int Kp = propcnt(K);
if (Kp == 0)
{
break;
}*/
K = K % propcnt(K);
ans++;
}
Console.WriteLine(ans);
}
if (X[i] == '0') {
int K = (int)(modAsum + modA[N - 1 - i]) % cnt1A;
K = (cnt1A + K) % cnt1A;
int ans = 1;
while (K != 0) {
K = K % propcnt(K);
ans++;
}
Console.WriteLine(ans);
}
}
// var ans = A.Where((x,i)=> (x%2==1 && i%2==0)).Count();
}
}
// Console.WriteLine(propcnt(8));
Console.Out.Flush();
}
static public int propcnt(int n) {
int result = 0;
for (int i = 0; i < 25; i++) {
result += (n >> i) % 2;
}
return result;
}
}
}
|
[["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 33], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 79], ["-", 75, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["-", 75, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["-", 75, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
| 8
| 644
| 22
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
int[] func = new int[200001];
int[] popcount = new int[200001];
for (int i = 1; i < 200001; i++) {
popcount[i] = popcount[i / 2] + i % 2;
int buf = i % popcount[i];
func[i] = func[buf] + 1;
}
string[] input = Read();
int n = int.Parse(input[0]);
char[] x = Read() [0].ToCharArray();
bool[] bit = new bool[n];
int count1 = 0;
for (int i = 0; i < n; i++) {
if (x[n - i - 1] == '1') {
bit[i] = true;
count1++;
}
}
int[][] amari = new int [n][];
int[] amariBase = new int[2];
int[] add = new int[] { -1, 1 };
if (count1 < 2)
add[0] = 0;
amari[0] = new int[2];
for (int j = 0; j < 2; j++)
amari[0][j] = 1 % (count1 + add[j]);
if (bit[0])
for (int j = 0; j < 2; j++)
amariBase[j] = amari[0][j];
for (int i = 1; i < n; i++) {
amari[i] = new int[2];
for (int j = 0; j < 2; j++)
amari[i][j] = (amari[i - 1][j] * 2) % (count1 + add[j]);
if (bit[i])
for (int j = 0; j < 2; j++)
amariBase[j] = (amariBase[j] + amari[i][j]) % (count1 + add[j]);
}
for (int i = 0; i < n; i++) {
int idx = n - i - 1;
int addIdx = bit[idx] ? 0 : 1;
if (count1 + add[addIdx] == 0) {
Write(0);
continue;
}
int buf = amariBase[addIdx] + amari[idx][addIdx] * add[addIdx];
if (buf < 0)
buf += count1 + add[addIdx];
buf = buf % (count1 + add[addIdx]);
Write(func[buf] + 1);
}
}
static string[] Read() { return Console.ReadLine().Split(' '); }
static void Write(object o) { Console.WriteLine(o.ToString()); }
}
|
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
int[] func = new int[200001];
int[] popcount = new int[200001];
for (int i = 1; i < 200001; i++) {
popcount[i] = popcount[i / 2] + i % 2;
int buf = i % popcount[i];
func[i] = func[buf] + 1;
}
string[] input = Read();
int n = int.Parse(input[0]);
char[] x = Read() [0].ToCharArray();
bool[] bit = new bool[n];
int count1 = 0;
for (int i = 0; i < n; i++) {
if (x[n - i - 1] == '1') {
bit[i] = true;
count1++;
}
}
int[][] amari = new int [n][];
int[] amariBase = new int[2];
int[] add = new int[] { -1, 1 };
// if(count1<2) add[0] = 0;
amari[0] = new int[2];
for (int j = 0; j < 2; j++)
amari[0][j] = 1 % Math.Max(count1 + add[j], 1);
if (bit[0]) {
for (int j = 0; j < 2; j++)
amariBase[j] = amari[0][j];
}
for (int i = 1; i < n; i++) {
amari[i] = new int[2];
for (int j = 0; j < 2; j++)
amari[i][j] = (amari[i - 1][j] * 2) % Math.Max(count1 + add[j], 1);
if (bit[i])
for (int j = 0; j < 2; j++)
amariBase[j] =
(amariBase[j] + amari[i][j]) % Math.Max(count1 + add[j], 1);
}
for (int i = 0; i < n; i++) {
int idx = n - i - 1;
int addIdx = bit[idx] ? 0 : 1;
if (count1 + add[addIdx] == 0) {
Write(0);
continue;
}
int buf = amariBase[addIdx] + amari[idx][addIdx] * add[addIdx];
if (buf < 0)
buf += count1 + add[addIdx];
buf = buf % (count1 + add[addIdx]);
Write(func[buf] + 1);
}
}
static string[] Read() { return Console.ReadLine().Split(' '); }
static void Write(object o) { Console.WriteLine(o.ToString()); }
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["-", 64, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 64, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 12, 213, 3, 4, 0, 21], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 617
| 30
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.