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
|
|---|---|---|---|---|---|
// デバッグ実行:Ctrl+F5
using System;
class Program {
static void Main(string[] args) {
String line;
line = Console.ReadLine();
String[] words = line.Split(' ');
int N = int.Parse(line);
int maxX = 100, maxY = 100, minX = 0, minY = 0;
if (N == 1) {
// そのまま出力?
line = Console.ReadLine();
words = line.Split(' ');
Console.WriteLine(words[0] + " " + words[1] + " " + words[2]);
return;
}
Tuple<int, int, int>[] dataset = new Tuple<int, int, int>[N];
for (int i = 0; i < N; i++) {
line = Console.ReadLine();
words = line.Split(' ');
dataset[i] = new Tuple<int, int, int>(
int.Parse(words[0]), int.Parse(words[1]), int.Parse(words[2]));
}
bool stop = false;
int result_x = 0;
int result_y = 0;
int H_kouho = -1;
int result_h = 0;
for (int x = 0; x < 101; x++) {
for (int y = 0; y < 101; y++) {
stop = false;
H_kouho = -1;
int H = 0;
for (int i = 0; i < N; i++) {
if (dataset[i].Item3 != 0) {
H = dataset[i].Item3 + Math.Abs(dataset[i].Item1 - x) +
Math.Abs(dataset[i].Item2 - y);
if (H_kouho == -1) {
H_kouho = H;
} else if (H != H_kouho) {
stop = true;
break;
}
}
}
for (int i = 0; i < N; i++) {
if (dataset[i].Item3 != 0) {
result_h = dataset[i].Item3 +
Math.Abs(dataset[i].Item1 - result_x) +
Math.Abs(dataset[i].Item2 - result_y);
break;
}
}
for (int i = 0; i < N; i++) {
if (dataset[i].Item3 == 0 &&
result_h > Math.Abs(dataset[i].Item1 - x) +
Math.Abs(dataset[i].Item2 - y)) {
H = Math.Abs(dataset[i].Item1 - x) + Math.Abs(dataset[i].Item2 - y);
if (result_h != H) {
stop = true;
break;
}
}
}
if (!stop) {
// 答えのXとY
result_x = x;
result_y = y;
break;
}
}
if (!stop)
break;
}
result_h = 0;
for (int i = 0; i < N; i++) {
if (dataset[i].Item3 != 0) {
result_h = dataset[i].Item3 + Math.Abs(dataset[i].Item1 - result_x) +
Math.Abs(dataset[i].Item2 - result_y);
break;
}
}
Console.WriteLine(result_x + " " + result_y + " " + result_h);
}
}
|
// デバッグ実行:Ctrl+F5
using System;
class Program {
static void Main(string[] args) {
String line;
line = Console.ReadLine();
String[] words = line.Split(' ');
int N = int.Parse(line);
int maxX = 100, maxY = 100, minX = 0, minY = 0;
if (N == 1) {
// そのまま出力?
line = Console.ReadLine();
words = line.Split(' ');
Console.WriteLine(words[0] + " " + words[1] + " " + words[2]);
return;
}
Tuple<int, int, int>[] dataset = new Tuple<int, int, int>[N];
for (int i = 0; i < N; i++) {
line = Console.ReadLine();
words = line.Split(' ');
dataset[i] = new Tuple<int, int, int>(
int.Parse(words[0]), int.Parse(words[1]), int.Parse(words[2]));
}
bool stop = false;
int result_x = 0;
int result_y = 0;
int H_kouho = -1;
int result_h = 0;
for (int x = 0; x < 101; x++) {
for (int y = 0; y < 101; y++) {
stop = false;
H_kouho = -1;
int H = 0;
for (int i = 0; i < N; i++) {
if (dataset[i].Item3 != 0) {
H = dataset[i].Item3 + Math.Abs(dataset[i].Item1 - x) +
Math.Abs(dataset[i].Item2 - y);
if (H_kouho == -1) {
H_kouho = H;
} else if (H != H_kouho) {
stop = true;
break;
}
}
}
for (int i = 0; i < N; i++) {
if (dataset[i].Item3 != 0) {
result_h = dataset[i].Item3 + Math.Abs(dataset[i].Item1 - x) +
Math.Abs(dataset[i].Item2 - y);
break;
}
}
for (int i = 0; i < N; i++) {
if (dataset[i].Item3 == 0 &&
result_h > Math.Abs(dataset[i].Item1 - x) +
Math.Abs(dataset[i].Item2 - y)) {
H = Math.Abs(dataset[i].Item1 - x) + Math.Abs(dataset[i].Item2 - y);
if (result_h != H) {
stop = true;
break;
}
}
}
if (!stop) {
// 答えのXとY
result_x = x;
result_y = y;
break;
}
}
if (!stop)
break;
}
result_h = 0;
for (int i = 0; i < N; i++) {
if (dataset[i].Item3 != 0) {
result_h = dataset[i].Item3 + Math.Abs(dataset[i].Item1 - result_x) +
Math.Abs(dataset[i].Item2 - result_y);
break;
}
}
Console.WriteLine(result_x + " " + result_y + " " + result_h);
}
}
|
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 688
| 4
|
using System;
using System.Linq;
namespace D {
class Program {
static void Main(string[] args) {
int[] IN =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
long n = IN[0];
long m = IN[1];
for (long i = m / n; i >= 2; i--) {
if (m % i == 0) {
Console.WriteLine(i);
break;
}
}
}
}
}
|
using System;
using System.Linq;
namespace D {
class Program {
static void Main(string[] args) {
int[] IN =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
long n = IN[0];
long m = IN[1];
for (long i = m / n; i >= 1; i--) {
if (m % i == 0) {
Console.WriteLine(i);
break;
}
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 114
| 2
|
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) {
//問題クラスを展開
ProgramD a = new ProgramD();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
//数値入力する
string[] s = Console.ReadLine().Split(' ');
//それぞれの文字列で答えを出す
if ((int.Parse(s[0]) * int.Parse(s[1])) % 2 == 1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
class ProgramB {
public void main() {
//入力
string input = Console.ReadLine();
int n = int.Parse(input);
string[] num = new string[n];
// char型で読み込み、int型に変換。そこから数を足して、char型に戻す
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (num.Contains(s) == true) {
Console.WriteLine("No");
return;
}
if (i == 0) {
num[0] = s;
} else {
if (num[i - 1][num[i - 1].Length - 1] != s[0]) {
Console.WriteLine("No");
return;
}
num[i] = s;
}
}
Console.WriteLine("Yes");
}
}
class ProgramC {
public void main() {
//入力
string[] input = Console.ReadLine().Split();
long n = long.Parse(input[0]);
long x = long.Parse(input[1]);
string[] s = Console.ReadLine().Split();
long[] a = new long[n];
//
for (int i = 0; i < n; i++)
a[i] = Math.Abs(long.Parse(s[i]) - x);
if (n == 1) {
Console.WriteLine(a[0]);
return;
}
long ans = gcd(a[0], a[1]);
for (int i = 2; i < n; i++)
ans = gcd(ans, a[i]);
//答え出力
Console.WriteLine(ans);
}
/*最大公約数を求める関数*/
static long gcd(long p, long q) {
if (p < q) {
long temp = p;
p = q;
q = temp;
}
long r = 1;
while (r != 0) {
r = p % q;
p = q;
q = r;
}
return p;
}
}
class ProgramD {
public void main() {
//入力
string[] input = Console.ReadLine().Split();
long n = long.Parse(input[0]);
long m = long.Parse(input[1]);
long ans = 0;
// 2変数に分離
for (int i = 1; i <= Math.Sqrt(m); i++) {
if (m % i == 0) {
if (m / i >= n) {
ans = Math.Max(ans, i);
} else if (i >= n)
ans = Math.Max(ans, m / i);
}
}
//答え出力
Console.WriteLine(ans);
}
}
}
|
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) {
//問題クラスを展開
ProgramD a = new ProgramD();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
//数値入力する
string[] s = Console.ReadLine().Split(' ');
//それぞれの文字列で答えを出す
if ((int.Parse(s[0]) * int.Parse(s[1])) % 2 == 1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
class ProgramB {
public void main() {
//入力
string input = Console.ReadLine();
int n = int.Parse(input);
string[] num = new string[n];
// char型で読み込み、int型に変換。そこから数を足して、char型に戻す
for (int i = 0; i < n; i++) {
string s = Console.ReadLine();
if (num.Contains(s) == true) {
Console.WriteLine("No");
return;
}
if (i == 0) {
num[0] = s;
} else {
if (num[i - 1][num[i - 1].Length - 1] != s[0]) {
Console.WriteLine("No");
return;
}
num[i] = s;
}
}
Console.WriteLine("Yes");
}
}
class ProgramC {
public void main() {
//入力
string[] input = Console.ReadLine().Split();
long n = long.Parse(input[0]);
long x = long.Parse(input[1]);
string[] s = Console.ReadLine().Split();
long[] a = new long[n];
//
for (int i = 0; i < n; i++)
a[i] = Math.Abs(long.Parse(s[i]) - x);
if (n == 1) {
Console.WriteLine(a[0]);
return;
}
long ans = gcd(a[0], a[1]);
for (int i = 2; i < n; i++)
ans = gcd(ans, a[i]);
//答え出力
Console.WriteLine(ans);
}
/*最大公約数を求める関数*/
static long gcd(long p, long q) {
if (p < q) {
long temp = p;
p = q;
q = temp;
}
long r = 1;
while (r != 0) {
r = p % q;
p = q;
q = r;
}
return p;
}
}
class ProgramD {
public void main() {
//入力
string[] input = Console.ReadLine().Split();
long n = long.Parse(input[0]);
long m = long.Parse(input[1]);
long ans = 1;
// 2変数に分離
for (int i = 1; i <= Math.Sqrt(m); i++) {
if (m % i == 0) {
if (m / i >= n) {
ans = Math.Max(ans, i);
if (i >= n)
ans = Math.Max(ans, m / i);
}
}
}
//答え出力
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 697
| 5
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Myon {
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
// メンバ変数---
long N;
long M;
// -------------
void calc() {
N = cin.nextInt();
M = cin.nextInt();
// Mの約数リスト
long ret = 0;
for (long i = 2; i < Math.Sqrt(M) + 1; i++) {
if (M % i == 0) {
if (i * N <= M) {
ret = Math.Max(ret, i);
}
if (M / i * N <= M) {
ret = Math.Max(ret, M / i);
}
}
}
write(ret);
}
void write(string v) { Console.WriteLine(v); }
void write(int v) { Console.WriteLine(v); }
void write(double v) { Console.WriteLine(v); }
void write(long v) { Console.WriteLine(v); }
int Pow(int x, int y) {
return (int)Math.Pow(double.Parse(x.ToString()),
double.Parse(y.ToString()));
}
double Pow(double x, double y) { return Math.Pow(x, y); }
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Myon {
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
// メンバ変数---
long N;
long M;
// -------------
void calc() {
N = cin.nextInt();
M = cin.nextInt();
// Mの約数リスト
long ret = 0;
for (long i = 1; i < Math.Sqrt(M) + 1; i++) {
if (M % i == 0) {
if (i * N <= M) {
ret = Math.Max(ret, i);
}
if (M / i * N <= M) {
ret = Math.Max(ret, M / i);
}
}
}
write(ret);
}
void write(string v) { Console.WriteLine(v); }
void write(int v) { Console.WriteLine(v); }
void write(double v) { Console.WriteLine(v); }
void write(long v) { Console.WriteLine(v); }
int Pow(int x, int y) {
return (int)Math.Pow(double.Parse(x.ToString()),
double.Parse(y.ToString()));
}
double Pow(double x, double y) { return Math.Pow(x, y); }
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 669
| 2
|
using System;
namespace ABC112_D___Partition {
class Program {
static void Main(string[] args) { Console.WriteLine(solver()); }
static int solver() {
var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var N = NM[0];
var M = NM[1];
for (int i = 2; i <= M / 2; i++) {
if (M % i == 0 && i >= N)
return M / i;
}
return 1;
}
}
}
|
using System;
namespace ABC112_D___Partition {
class Program {
static void Main(string[] args) { Console.WriteLine(solver()); }
static int solver() {
var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
var N = NM[0];
var M = NM[1];
for (int i = N; i <= M / 2; i++) {
if (M % i == 0)
return M / i;
}
return 1;
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 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, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 117
| 6
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
static List<ulong> Divisor(ulong input) {
List<ulong> result = new List<ulong>();
for (ulong i = 2; i * i <= input; i++) {
if (0 == input % i) {
result.Add(i);
if (i * i != input) {
result.Add(input / i);
}
}
}
return result;
}
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int N = int.Parse(s[0]);
int M = int.Parse(s[1]);
List<ulong> div = Divisor((ulong)M);
div.Sort();
int ans = 1;
int index = 0;
for (index = 0; index < div.Count; index++) {
if ((int)div[index] >= N) {
break;
}
}
ans = M / (int)div[index];
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;
namespace SolutionCS {
class Program {
static List<ulong> Divisor(ulong input) {
List<ulong> result = new List<ulong>();
for (ulong i = 1; i * i <= input; i++) {
if (0 == input % i) {
result.Add(i);
if (i * i != input) {
result.Add(input / i);
}
}
}
return result;
}
static void Main(string[] args) {
string[] s = Console.ReadLine().Split(' ');
int N = int.Parse(s[0]);
int M = int.Parse(s[1]);
List<ulong> div = Divisor((ulong)M);
div.Sort();
int ans = 1;
int index = 0;
for (index = 0; index < div.Count; index++) {
if ((int)div[index] >= N) {
break;
}
}
ans = M / (int)div[index];
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 253
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Procon {
public Procon() {}
static void Main(string[] agrs) { new Procon().Do(); }
Scanner cin;
public void Do() {
cin = new Scanner();
long N = cin.nextLong();
long M = cin.nextLong();
double X = Math.Sqrt(M);
long ans = 0;
for (int i = 1; i < X; i++) {
if (M % i == 0) {
if (i >= N) {
ans = Math.Max(M / i, ans);
} else if (M / i >= N) {
ans = Math.Max(i, ans);
}
}
}
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
int max_i;
public Scanner() {
s = new string[0];
max_i = 0;
i = 0;
}
public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
} else {
return s[i++];
}
}
public int nextInt() { return int.Parse(nextString()); }
public long nextLong() { return long.Parse(nextString()); }
public double nextDouble() { return double.Parse(nextString()); }
public string[] arrayString() { return Console.ReadLine().Split(' '); }
public int[] arrayInt() {
string[] str = Console.ReadLine().Split(' ');
int[] array = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = int.Parse(str[i]);
}
return array;
}
public long[] arrayLong() {
string[] str = Console.ReadLine().Split(' ');
long[] array = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = long.Parse(str[i]);
}
return array;
}
public double[] arrayDouble() {
string[] str = Console.ReadLine().Split(' ');
double[] array = new double[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = double.Parse(str[i]);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Procon {
public Procon() {}
static void Main(string[] agrs) { new Procon().Do(); }
Scanner cin;
public void Do() {
cin = new Scanner();
long N = cin.nextLong();
long M = cin.nextLong();
double X = Math.Sqrt(M);
long ans = 0;
for (int i = 1; i <= X; i++) {
if (M % i == 0) {
if (i >= N) {
ans = Math.Max(M / i, ans);
} else if (M / i >= N) {
ans = Math.Max(i, ans);
}
}
}
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
int max_i;
public Scanner() {
s = new string[0];
max_i = 0;
i = 0;
}
public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
} else {
return s[i++];
}
}
public int nextInt() { return int.Parse(nextString()); }
public long nextLong() { return long.Parse(nextString()); }
public double nextDouble() { return double.Parse(nextString()); }
public string[] arrayString() { return Console.ReadLine().Split(' '); }
public int[] arrayInt() {
string[] str = Console.ReadLine().Split(' ');
int[] array = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = int.Parse(str[i]);
}
return array;
}
public long[] arrayLong() {
string[] str = Console.ReadLine().Split(' ');
long[] array = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = long.Parse(str[i]);
}
return array;
}
public double[] arrayDouble() {
string[] str = Console.ReadLine().Split(' ');
double[] array = new double[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = double.Parse(str[i]);
}
return array;
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 581
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using static System.Math;
using System.Text;
namespace Program {
public static class ABC112D {
static public void Solve() {
var N = NextLong;
var M = NextLong;
foreach (var item in Divisor(M).OrderByDescending(e => e).Skip(1)) {
if (N * item <= M) {
Console.WriteLine(item);
break;
}
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
Solve();
Console.Out.Flush();
}
static Random rand = new Random();
static class Console_ {
private static Queue<string> param = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static int NextInt => int.Parse(Console_.NextString());
static long NextLong => long.Parse(Console_.NextString());
static double NextDouble => double.Parse(Console_.NextString());
static string NextString => Console_.NextString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<int>
NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<long>
NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<double> NextDoubleList(int N) =>
Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<string> NextStringList(int N) =>
Enumerable.Repeat(0, N).Select(_ => NextString).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T> Repeat<T>(T v, int n) => Enumerable.Repeat<T>(v, n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<T> Sort<T>(List<T> l)
where T : IComparable {
var tmp = l.ToArray();
Array.Sort(tmp);
return tmp.ToList();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<T> Sort<T>(List<T> l, Comparison<T> comp)
where T : IComparable {
var tmp = l.ToArray();
Array.Sort(tmp, comp);
return tmp.ToList();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<T> RevSort<T>(List<T> l)
where T : IComparable {
var tmp = l.ToArray();
Array.Sort(tmp, (x, y) => y.CompareTo(x));
return tmp.ToList();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<T> RevSort<T>(List<T> l, Comparison<T> comp)
where T : IComparable {
var tmp = l.ToArray();
Array.Sort(tmp, (x, y) => comp(y, x));
return tmp.ToList();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Prime(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
class PQ<T>
where T : IComparable {
private List<T> h;
private Comparison<T> c;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Peek => h[0];
public int Count => h.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TKey, TValue>
where TKey : IComparable {
private PQ<Tuple<TKey, TValue>> q;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<TKey> c, bool asc = true) {
q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<TKey> c, bool asc = true) {
q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v));
public Tuple<TKey, TValue> Peek => q.Peek;
public int Count => q.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<TKey, TValue> Pop() => q.Pop();
}
class Mod {
static public long _mod = 1000000007;
private long _val = 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mod() {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mod(long x) {
if (x < _mod && x >= 0)
_val = x;
else if ((_val = x % _mod) < 0)
_val += _mod;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator Mod(long x) => new Mod(x);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator long(Mod x) => x._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(Mod x, Mod y) {
var t = x._val + y._val;
return new Mod() { _val = t < _mod ? t : t - _mod };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(Mod x, long y) => x._val + y;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(long x, Mod y) => x + y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(Mod x, Mod y) {
var t = x._val - y._val;
return new Mod() { _val = t < _mod ? t : t - _mod };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(Mod x, long y) => x._val - y;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(long x, Mod y) => x - y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(Mod x, Mod y) => x._val == y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(Mod x, long y) => x._val == y;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(long x, Mod y) => x == y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(Mod x, Mod y) => x._val != y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(Mod x, long y) => x._val != y;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(long x, Mod y) => x != y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
override public bool Equals(object obj) => obj == null
? false
: _val == ((Mod)obj)._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Mod obj) => obj == null ? false : _val == obj._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode() => _val.GetHashCode();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => _val.ToString();
static private List<Mod> _fact = new List<Mod>();
static private List<Mod> _ifact = new List<Mod>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static private void Build(int n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
if (i == 0L) {
_fact.Add(1);
_ifact.Add(1);
} else {
_fact.Add(_fact[i - 1] * i);
_ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2));
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Comb(int n, int k) {
Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _ifact[n - k] * _ifact[k] * _fact[n];
}
}
class Mat<T> {
private T[,] m;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mat(T[,] v) { m = (T[,])v.Clone(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v);
public T this[int r, int c] {
get { return m[r, c]; }
set { m[r, c] = value; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)x;
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)b[r, c];
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)x;
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)b[r, c];
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] *= (dynamic)x;
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, Mat<T> b) {
var nr = a.m.GetLength(0);
var nc = b.m.GetLength(1);
var tm = new T[nr, nc];
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j)
tm[i, j] = (dynamic)0;
for (int r = 0; r < nr; ++r)
for (int c = 0; c < nc; ++c)
for (int i = 0; i < a.m.GetLength(1); ++i)
tm[r, c] += a[r, i] * (dynamic)b[i, c];
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> Pow(Mat<T> x, long y) {
var n = x.m.GetLength(0);
var t = (Mat<T>)new T[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i, j] = (dynamic)(i == j ? 1 : 0);
while (y != 0) {
if ((y & 1) == 1)
t *= x;
x *= x;
y >>= 1;
}
return t;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Mod Pow(Mod x, long y) => Mod.Pow(x, y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void _Build(int n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
if (i == 0L)
_fact.Add(1);
else
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Comb(int n, int k) {
_Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[n] / _fact[k] / _fact[n - k];
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using static System.Math;
using System.Text;
namespace Program {
public static class ABC112D {
static public void Solve() {
var N = NextLong;
var M = NextLong;
foreach (var item in Divisor(M).OrderByDescending(e => e)) {
if (N * item <= M) {
Console.WriteLine(item);
break;
}
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
Solve();
Console.Out.Flush();
}
static Random rand = new Random();
static class Console_ {
private static Queue<string> param = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static int NextInt => int.Parse(Console_.NextString());
static long NextLong => long.Parse(Console_.NextString());
static double NextDouble => double.Parse(Console_.NextString());
static string NextString => Console_.NextString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<int>
NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<long>
NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<double> NextDoubleList(int N) =>
Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<string> NextStringList(int N) =>
Enumerable.Repeat(0, N).Select(_ => NextString).ToList();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<T> Repeat<T>(T v, int n) => Enumerable.Repeat<T>(v, n);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<T> Sort<T>(List<T> l)
where T : IComparable {
var tmp = l.ToArray();
Array.Sort(tmp);
return tmp.ToList();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<T> Sort<T>(List<T> l, Comparison<T> comp)
where T : IComparable {
var tmp = l.ToArray();
Array.Sort(tmp, comp);
return tmp.ToList();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<T> RevSort<T>(List<T> l)
where T : IComparable {
var tmp = l.ToArray();
Array.Sort(tmp, (x, y) => y.CompareTo(x));
return tmp.ToList();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static List<T> RevSort<T>(List<T> l, Comparison<T> comp)
where T : IComparable {
var tmp = l.ToArray();
Array.Sort(tmp, (x, y) => comp(y, x));
return tmp.ToList();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Prime(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
class PQ<T>
where T : IComparable {
private List<T> h;
private Comparison<T> c;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Peek => h[0];
public int Count => h.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TKey, TValue>
where TKey : IComparable {
private PQ<Tuple<TKey, TValue>> q;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, Comparison<TKey> c, bool asc = true) {
q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(Comparison<TKey> c, bool asc = true) {
q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v));
public Tuple<TKey, TValue> Peek => q.Peek;
public int Count => q.Count;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Tuple<TKey, TValue> Pop() => q.Pop();
}
class Mod {
static public long _mod = 1000000007;
private long _val = 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mod() {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mod(long x) {
if (x < _mod && x >= 0)
_val = x;
else if ((_val = x % _mod) < 0)
_val += _mod;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator Mod(long x) => new Mod(x);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator long(Mod x) => x._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(Mod x, Mod y) {
var t = x._val + y._val;
return new Mod() { _val = t < _mod ? t : t - _mod };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(Mod x, long y) => x._val + y;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator +(long x, Mod y) => x + y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(Mod x, Mod y) {
var t = x._val - y._val;
return new Mod() { _val = t < _mod ? t : t - _mod };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(Mod x, long y) => x._val - y;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator -(long x, Mod y) => x - y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(Mod x, Mod y) => x._val == y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(Mod x, long y) => x._val == y;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator ==(long x, Mod y) => x == y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(Mod x, Mod y) => x._val != y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(Mod x, long y) => x._val != y;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public bool operator !=(long x, Mod y) => x != y._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
override public bool Equals(object obj) => obj == null
? false
: _val == ((Mod)obj)._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Mod obj) => obj == null ? false : _val == obj._val;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode() => _val.GetHashCode();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => _val.ToString();
static private List<Mod> _fact = new List<Mod>();
static private List<Mod> _ifact = new List<Mod>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static private void Build(int n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
if (i == 0L) {
_fact.Add(1);
_ifact.Add(1);
} else {
_fact.Add(_fact[i - 1] * i);
_ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2));
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mod Comb(int n, int k) {
Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _ifact[n - k] * _ifact[k] * _fact[n];
}
}
class Mat<T> {
private T[,] m;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Mat(T[,] v) { m = (T[,])v.Clone(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v);
public T this[int r, int c] {
get { return m[r, c]; }
set { m[r, c] = value; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)x;
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator +(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)b[r, c];
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)x;
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator -(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)b[r, c];
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] *= (dynamic)x;
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> operator *(Mat<T> a, Mat<T> b) {
var nr = a.m.GetLength(0);
var nc = b.m.GetLength(1);
var tm = new T[nr, nc];
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j)
tm[i, j] = (dynamic)0;
for (int r = 0; r < nr; ++r)
for (int c = 0; c < nc; ++c)
for (int i = 0; i < a.m.GetLength(1); ++i)
tm[r, c] += a[r, i] * (dynamic)b[i, c];
return new Mat<T>(tm);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static public Mat<T> Pow(Mat<T> x, long y) {
var n = x.m.GetLength(0);
var t = (Mat<T>)new T[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i, j] = (dynamic)(i == j ? 1 : 0);
while (y != 0) {
if ((y & 1) == 1)
t *= x;
x *= x;
y >>= 1;
}
return t;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static Mod Pow(Mod x, long y) => Mod.Pow(x, y);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void _Build(int n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
if (i == 0L)
_fact.Add(1);
else
_fact.Add(_fact[i - 1] * i);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long Comb(int n, int k) {
_Build(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[n] / _fact[k] / _fact[n - k];
}
}
}
|
[["-", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24], ["-", 0, 210, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 8, 196, 0, 210, 12, 213, 3, 4, 0, 25]]
| 8
| 4,139
| 5
|
using System;
using System.Collections.Generic;
// using System.Linq;
class Program {
static void Main(string[] args) {
// 入力フェーズ
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int M = int.Parse(input[1]);
// Mの約数のうちM/N以下の物を探す
// Mの約数を探す
int max = (int)Math.Sqrt(M);
List<int> div = new List<int>();
for (int i = 2; i <= max; i++) {
if (M % i == 0) {
div.Add(i);
div.Add(M / i);
}
}
div.Sort();
for (int i = div.Count - 1; i >= 0; i--) {
if (div[i] <= M / N) {
Console.WriteLine(div[i] + "");
break;
}
}
}
class point {
public int x { set; get; }
public int y { set; get; }
public int h { set; get; }
}
}
|
using System;
using System.Collections.Generic;
// using System.Linq;
class Program {
static void Main(string[] args) {
// 入力フェーズ
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int M = int.Parse(input[1]);
// Mの約数のうちM/N以下の物を探す
// Mの約数を探す
int max = (int)Math.Sqrt(M);
List<int> div = new List<int>();
// div.Add(1);
for (int i = 1; i <= max; i++) {
if (M % i == 0) {
div.Add(i);
div.Add(M / i);
}
}
div.Sort();
for (int i = div.Count - 1; i >= 0; i--) {
if (div[i] <= M / N) {
Console.WriteLine(div[i] + "");
break;
}
}
}
class point {
public int x { set; get; }
public int y { set; get; }
public int h { set; get; }
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 227
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
}
class Program {
static Scanner cin = new Scanner();
static void Main(string[] args) {
int N = cin.Int();
int M = cin.Int();
for (int g = M / N; g >= 1; g--) {
if (M % g == 0)
Console.WriteLine(g);
break;
}
Console.ReadLine();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
}
class Program {
static Scanner cin = new Scanner();
static void Main(string[] args) {
int N = cin.Int();
int M = cin.Int();
for (int g = M / N; g >= 1; g--) {
if (M % g == 0) {
Console.WriteLine(g);
break;
}
}
Console.ReadLine();
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 375
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] a_asArgs) {
int[] l_aiInput =
Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int l_iN = l_aiInput[0];
int l_iM = l_aiInput[1];
for (int l_iD = l_iM / l_iN; l_iD > 1; l_iD--) {
if (l_iM % l_iD == 0) {
Console.WriteLine(l_iD);
break;
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] a_asArgs) {
int[] l_aiInput =
Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int l_iN = l_aiInput[0];
int l_iM = l_aiInput[1];
for (int l_iD = l_iM / l_iN; l_iD >= 1; l_iD--) {
if (l_iM % l_iD == 0) {
Console.WriteLine(l_iD);
break;
}
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20]]
| 8
| 121
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
int n = (int)input[0];
long m = input[1];
var rtm = Math.Pow(m, 0.5);
if (n == 1) {
Console.WriteLine(m);
return;
}
var prev = m;
for (int i = 1; i <= rtm; i++) {
if (m % i != 0)
continue;
if (n <= i) {
Console.WriteLine(i);
return;
}
if (m / i < n) {
Console.WriteLine(prev);
return;
}
prev = i;
}
Console.WriteLine(prev);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
int n = (int)input[0];
long m = input[1];
var rtm = Math.Pow(m, 0.5);
if (n == 1) {
Console.WriteLine(m);
return;
}
var prev = m;
for (int i = 1; i <= rtm; i++) {
if (m % i != 0)
continue;
if (n <= i) {
Console.WriteLine(m / i);
return;
}
if (m / i < n) {
Console.WriteLine(prev);
return;
}
prev = i;
}
Console.WriteLine(prev);
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
| 8
| 183
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class P {
static void Main() {
string[] s = Console.ReadLine().Split();
int n = int.Parse(s[0]);
int m = int.Parse(s[1]);
int u = m / n;
for (int i = u; i > 0; i++) {
if (m % i == 0) {
Console.WriteLine(i);
return;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class P {
static void Main() {
string[] s = Console.ReadLine().Split();
int n = int.Parse(s[0]);
int m = int.Parse(s[1]);
int u = m / n;
for (int i = u; i > 0; i--) {
if (m % i == 0) {
Console.WriteLine(i);
return;
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
| 8
| 109
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace AtCoder {
class Program {
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
static int Solve(int N, int M) {
var D = new List<int>();
for (int i = 2; i * i <= M; ++i) {
if (M % i == 0) {
D.Add(i);
D.Add(M / i);
}
}
return D.Where(d => d <= M / N).Max();
}
static void Main(string[] args) {
var V = ReadInts();
Console.WriteLine(Solve(V[0], V[1]));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace AtCoder {
class Program {
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
static int Solve(int N, int M) {
var D = new List<int>();
for (int i = 1; i * i <= M; ++i) {
if (M % i == 0) {
D.Add(i);
D.Add(M / i);
}
}
return D.Where(d => d <= M / N).Max();
}
static void Main(string[] args) {
var V = ReadInts();
Console.WriteLine(Solve(V[0], V[1]));
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 307
| 2
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
long A = long.Parse(str[0]);
long B = long.Parse(str[1]);
var list = enum_div(B);
list.Sort();
long ans = 1;
for (var i = 0; i < list.Count; i++) {
if (list[list.Count - 1 - i] <= B / A) {
ans = list[list.Count - 1 - i];
break;
}
}
Console.WriteLine(ans);
}
public static List<long> enum_div(long n) {
var list = new List<long>();
for (var i = 1; i * i <= n; i++) {
if (n % i == 0) {
list.Add(i);
if (i * i != n) {
list.Add(n - i);
}
}
}
return list;
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
long A = long.Parse(str[0]);
long B = long.Parse(str[1]);
var list = enum_div(B);
list.Sort();
long ans = 1;
for (var i = 0; i < list.Count; i++) {
if (list[list.Count - 1 - i] <= B / A) {
ans = list[list.Count - 1 - i];
break;
}
}
Console.WriteLine(ans);
}
public static List<long> enum_div(long n) {
var list = new List<long>();
for (var i = 1; i * i <= n; i++) {
if (n % i == 0) {
list.Add(i);
if (i * i != n) {
list.Add(n / i);
}
}
}
return list;
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
| 8
| 225
| 2
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
long[] inpt =
Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
int numCount = (int)inpt[0];
long ans = 0;
for (long i = 1; i * i < inpt[1]; i++) {
if (inpt[1] % i == 0) {
long i2 = inpt[1] / i;
if (i2 >= numCount) {
ans = Math.Max(i, ans);
}
if (i >= numCount) {
ans = Math.Max(i2, ans);
}
}
}
Console.WriteLine(ans);
}
public class Reader {
static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
100000 1000000000
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
long[] inpt =
Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
int numCount = (int)inpt[0];
long ans = 0;
for (long i = 1; i * i <= inpt[1]; i++) {
if (inpt[1] % i == 0) {
long i2 = inpt[1] / i;
if (i2 >= numCount) {
ans = Math.Max(i, ans);
}
if (i >= numCount) {
ans = Math.Max(i2, ans);
}
}
}
Console.WriteLine(ans);
}
public class Reader {
static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
1 1
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
| 8
| 287
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { new Program().Calc(); }
Scanner cin;
public Program() {}
void Calc() {
cin = new Scanner();
string n = cin.next();
char[] ans = n.ToCharArray();
for (int i = 0; i < 2; ++i) {
if (ans[i] == '9') {
ans[i] = '1';
} else {
ans[i] = '9';
}
}
string ansStr = new string(ans);
Console.WriteLine(ansStr);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { new Program().Calc(); }
Scanner cin;
public Program() {}
void Calc() {
cin = new Scanner();
string n = cin.next();
char[] ans = n.ToCharArray();
for (int i = 0; i < 3; ++i) {
if (ans[i] == '9') {
ans[i] = '1';
} else {
ans[i] = '9';
}
}
string ansStr = new string(ans);
Console.WriteLine(ansStr);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 509
| 2
|
using System;
namespace abc111_a {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
for (int i = 0; i < 3; i++)
Console.Write(s[0] == '1' ? 9 : 1);
Console.WriteLine();
}
}
}
|
using System;
namespace abc111_a {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
for (int i = 0; i < 3; i++)
Console.Write(s[i] == '1' ? 9 : 1);
Console.WriteLine();
}
}
}
|
[["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 69
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sample1 {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
char[] cha = new char[3];
for (int i = 0; i < str.Length; i++) {
if (str[i] == '1') {
cha[i] = '9';
}
if (str[i] == '9') {
cha[i] = '1';
}
cha[i] = str[i];
}
Console.WriteLine(str);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sample1 {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
char[] cha = new char[3];
for (int i = 0; i < str.Length; i++) {
if (str[i] == '1') {
cha[i] = '9';
} else if (str[i] == '9') {
cha[i] = '1';
} else {
cha[i] = str[i];
}
}
Console.WriteLine(cha);
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 46], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 145
| 6
|
using System;
public class Contest {
public static void Main(string[] args) {
string p = args[0];
string r = string.Empty;
for (int i = 0; i < p.Length; i++) {
r += (char)((10 - (p[i] - '0')) + '0');
}
Console.WriteLine(r);
}
}
|
using System;
public class Contest {
public static void Main(string[] args) {
string p = Console.ReadLine();
string r = string.Empty;
for (int i = 0; i < p.Length; i++) {
r += (char)((10 - (p[i] - '0')) + '0');
}
Console.WriteLine(r);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 86
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
//入力
var a = int.Parse(Console.ReadLine());
int b = a / 111;
var c = (b + 1) * 111;
Console.WriteLine("{0}", c);
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
//入力
var a = int.Parse(Console.ReadLine());
int b = (a - 1) / 111;
var c = (b + 1) * 111;
Console.WriteLine("{0}", c);
Console.ReadKey();
}
}
}
|
[["+", 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]]
| 8
| 96
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static void Main() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
for (int i = 1; i < 9; i++) {
if (111 * i >= n) {
Console.WriteLine(111 * i);
break;
}
}
Console.Out.Flush();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static void Main() {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
for (int i = 1; i <= 9; i++) {
if (111 * i >= n) {
Console.WriteLine(111 * i);
break;
}
}
Console.Out.Flush();
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 161
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { new Program().Calc(); }
Scanner cin;
public Program() {}
void Calc() {
cin = new Scanner();
int n = cin.nextInt();
int contest = 0;
for (int i = 1; i <= 9; ++i) {
contest = i * 100 + i * 10 + i;
if (n <= i) {
break;
}
}
Console.WriteLine(contest);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) { new Program().Calc(); }
Scanner cin;
public Program() {}
void Calc() {
cin = new Scanner();
int n = cin.nextInt();
int contest = 0;
for (int i = 1; i <= 9; ++i) {
contest = i * 100 + i * 10 + i;
if (n <= contest) {
break;
}
}
Console.WriteLine(contest);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 482
| 2
|
using System;
class Program {
static void Main(string[] args) {
Write((int)(Read() - 1 / 111) * 111 + 111);
}
static void Write(string s) {
Console.WriteLine(s);
return;
}
static void Write(long n) {
Console.WriteLine(n.ToString());
return;
}
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
static long Read() { return long.Parse(Console.ReadLine()); }
static long[] Read(long n) {
long[] p = new long[n];
string[] t = Console.ReadLine().Split(' ');
for (long i = 0; i < n; i++) {
p[i] = long.Parse(t[i]);
}
return p;
}
static long abs(long n) { return (n > 0) ? n : -n; }
static long gcd(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = gcd(p, n[i]);
}
return p;
}
static long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); }
static long lcm(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = lcm(p, n[i]);
}
return p;
}
static long lcm(long a, long b) { return a * b / gcd(a, b); }
static long max(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p > n[i]) ? p : n[i];
}
return p;
}
static long min(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p < n[i]) ? p : n[i];
}
return p;
}
static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
static string clip(string s, int start, int count) {
if (start + count < s.Length) {
s = s.Remove(start + count);
}
if (start > 0) {
s = s.Remove(0, start);
}
return s;
}
}
|
using System;
class Program {
static void Main(string[] args) {
Write((int)((Read() - 1) / 111) * 111 + 111);
}
static void Write(string s) {
Console.WriteLine(s);
return;
}
static void Write(long n) {
Console.WriteLine(n.ToString());
return;
}
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
static long Read() { return long.Parse(Console.ReadLine()); }
static long[] Read(long n) {
long[] p = new long[n];
string[] t = Console.ReadLine().Split(' ');
for (long i = 0; i < n; i++) {
p[i] = long.Parse(t[i]);
}
return p;
}
static long abs(long n) { return (n > 0) ? n : -n; }
static long gcd(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = gcd(p, n[i]);
}
return p;
}
static long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); }
static long lcm(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = lcm(p, n[i]);
}
return p;
}
static long lcm(long a, long b) { return a * b / gcd(a, b); }
static long max(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p > n[i]) ? p : n[i];
}
return p;
}
static long min(params long[] n) {
long p = n[0];
for (long i = 1; i < n.Length; i++) {
p = (p < n[i]) ? p : n[i];
}
return p;
}
static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
static string clip(string s, int start, int count) {
if (start + count < s.Length) {
s = s.Remove(start + count);
}
if (start > 0) {
s = s.Remove(0, start);
}
return s;
}
}
|
[["+", 31, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 74, 51, 23, 0, 16, 31, 23, 0, 25]]
| 8
| 639
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder111 {
class Program {
static void Main(string[] args) {
int input = int.Parse(Console.ReadLine());
int res =
Enumerable.Range(1, 9).Select(x => x * 111).Where(x => x > input).Min();
Console.WriteLine(res);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder111 {
class Program {
static void Main(string[] args) {
int input = int.Parse(Console.ReadLine());
int res = Enumerable.Range(1, 9)
.Select(x => x * 111)
.Where(x => x >= input)
.Min();
Console.WriteLine(res);
}
}
}
|
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20]]
| 8
| 101
| 2
|
using static System.Console;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
var n = ReadLine();
var nInt = int.Parse(n);
var nca = n.ToCharArray();
var nDoublets = Doublets(nca[0]);
WriteLine((nInt <= nDoublets) ? nDoublets : (char)(nca[0] + 1));
}
private static int Doublets(char c) {
var cs = c.ToString();
return int.Parse(cs + cs + cs);
}
}
}
|
using static System.Console;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
var n = ReadLine();
var nInt = int.Parse(n);
var nca = n.ToCharArray();
var nDoublets = Doublets(nca[0]);
WriteLine((nInt <= nDoublets) ? nDoublets : Doublets((char)(nca[0] + 1)));
}
private static int Doublets(char c) {
var cs = c.ToString();
return int.Parse(cs + cs + cs);
}
}
}
|
[["+", 3, 4, 0, 28, 0, 41, 75, 213, 63, 22], ["+", 75, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25]]
| 8
| 116
| 3
|
using System;
namespace ABC111_B {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
for (int i = 111; i <= 999; i += 111) {
if (n < i) {
Console.WriteLine(i);
return;
}
}
}
}
}
|
using System;
namespace ABC111_B {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
for (int i = 111; i <= 999; i += 111) {
if (n <= i) {
Console.WriteLine(i);
return;
}
}
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 70
| 2
|
using System;
namespace ABC111 {
class Program {
static void Main(string[] args) {
int x = int.Parse(Console.ReadLine());
int a = (x - 1) / 111 + 1;
Console.WriteLine(x * a);
}
}
}
|
using System;
namespace ABC111 {
class Program {
static void Main(string[] args) {
int x = int.Parse(Console.ReadLine());
int a = (x - 1) / 111 + 1;
Console.WriteLine(111 * a);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203]]
| 8
| 58
| 2
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var kl = new Dictionary<int, int>();
var gl = new Dictionary<int, int>();
var n = Read().Int();
var r = ReadSplit();
for (int i = 0; i < n; i++) {
var v = r[i].Int();
if (i % 2 == 0) {
if (kl.ContainsKey(v)) {
kl[v]++;
} else {
kl.Add(v, 1);
}
} else {
if (gl.ContainsKey(v)) {
gl[v]++;
} else {
gl.Add(v, 1);
}
}
}
var k = kl.OrderBy(x => x.Value).ToArray();
var g = gl.OrderBy(x => x.Value).ToArray();
var ans = 0;
if (k.First().Key == g.First().Key) {
var skc = k.Length >= 2 ? k[1].Value : 0;
var sgc = g.Length >= 2 ? g[1].Value : 0;
if (skc >= sgc) {
ans = n - (skc + g[0].Value);
} else {
ans = n - (sgc + k[0].Value);
}
} else {
ans = n - (k.First().Value + g.First().Value);
}
WriteRead(ans);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
public class Program {
private static long mod = 1000000007;
private static long max = 999999999999;
static void Main(string[] args) {
var kl = new Dictionary<int, int>();
var gl = new Dictionary<int, int>();
var n = Read().Int();
var r = ReadSplit();
for (int i = 0; i < n; i++) {
var v = r[i].Int();
if (i % 2 == 0) {
if (kl.ContainsKey(v)) {
kl[v]++;
} else {
kl.Add(v, 1);
}
} else {
if (gl.ContainsKey(v)) {
gl[v]++;
} else {
gl.Add(v, 1);
}
}
}
var k = kl.OrderByDescending(x => x.Value).ToArray();
var g = gl.OrderByDescending(x => x.Value).ToArray();
var ans = 0;
if (k.First().Key == g.First().Key) {
var skc = k.Length >= 2 ? k[1].Value : 0;
var sgc = g.Length >= 2 ? g[1].Value : 0;
if (skc >= sgc) {
ans = n - (skc + g[0].Value);
} else {
ans = n - (sgc + k[0].Value);
}
} else {
ans = n - (k.First().Value + g.First().Value);
}
WriteRead(ans);
}
public static string Read() { return Console.ReadLine(); }
public static string[] ReadSplit() { return Console.ReadLine().Split(' '); }
public static void WriteRead(object str) {
Console.WriteLine(str);
Read();
}
public static void Write(object str) { Console.WriteLine(str); }
private static bool ChangeMin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
private static bool ChangekMax<T>(ref T a, T b)
where T : IComparable {
if (b.CompareTo(a) > 0) {
a = b;
return true;
}
return false;
}
/*優先度付きキュー*/
class PriorityQueue<T>
where T : IComparable<T> {
public readonly T[] Array;
public readonly bool Greater;
public int Count { get; private set; } = 0;
public PriorityQueue(int capacity, bool greater = true) {
this.Array = new T[capacity];
this.Greater = greater;
}
public void Enqueue(T item) {
this.Array[this.Count] = item;
this.Count += 1;
this.UpHeap();
}
public T Dequeue() {
// 先頭要素を末尾にして再構成
this.Swap(0, this.Count - 1);
this.Count -= 1;
this.DownHeap();
return this.Array[this.Count];
}
private void UpHeap() {
var n = this.Count - 1;
while (n != 0) {
// 親要素の座標
var parent = (n - 1) / 2;
if (this.Compare(this.Array[n], this.Array[parent]) > 0) {
this.Swap(n, parent);
n = parent;
} else {
break;
}
}
}
private void DownHeap() {
var parent = 0;
while (true) {
var child = 2 * parent + 1;
if (child > this.Count - 1)
break;
if (child < this.Count - 1 &&
this.Compare(this.Array[child], this.Array[child + 1]) < 0) {
// 左より右の子のほうが大きい値の場合、右を入れ替え対象にする
child += 1;
}
if (this.Compare(this.Array[parent], this.Array[child]) < 0) {
this.Swap(parent, child);
parent = child;
} else {
break;
}
}
}
// aとbを比較する
private int Compare(T a, T b) {
var c = a.CompareTo(b);
if (!this.Greater) {
c = -c;
}
return c;
}
// aとbを入れ替える
private void Swap(int a, int b) {
var tmp = this.Array[a];
this.Array[a] = this.Array[b];
this.Array[b] = tmp;
}
}
private static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
//要素数Nを引数として渡し、0~N-1でできた順列をすべて返す
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
//配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
}
}
public static class Extentions {
public static int Int(this object obj) { return int.Parse(obj.ToString()); }
public static long Long(this object obj) {
return long.Parse(obj.ToString());
}
public static decimal Decimal(this object obj) {
return decimal.Parse(obj.ToString());
}
public static double Double(this object obj) {
return double.Parse(obj.ToString());
}
public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key)
where T2 : struct {
T2 value;
if (d.TryGetValue(key, out value)) {
return value;
}
return new T2();
}
}
|
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
| 8
| 1,440
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class ACCEPTED {
public void Solve() {
var n = Int1;
var v = Ints;
var x = v.Where((p, i) => i % 2 == 0)
.GroupBy(a => a)
.Select(g => new { n = g.Key, c = g.Count() })
.OrderByDescending(a => a.c)
.ToArray();
var y = v.Where((p, i) => i % 2 == 0)
.GroupBy(a => a)
.Select(g => new { n = g.Key, c = g.Count() })
.OrderByDescending(a => a.c)
.ToArray();
if (x[0].n != y[0].n) {
Write(n - x[0].c - y[0].c);
} else {
Write(n - Max(x[0].c + ((y.Length > 1) ? y[1].c : 0),
(((x.Length > 1) ? x[1].c : 0) + y[0].c)));
}
}
}
public static class Graph {}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) {
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
public static Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public static List<long> DivisorEnumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var ACCEPTED = new ACCEPTED();
ACCEPTED.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class ACCEPTED {
public void Solve() {
var n = Int1;
var v = Ints;
var x = v.Where((p, i) => i % 2 == 0)
.GroupBy(a => a)
.Select(g => new { n = g.Key, c = g.Count() })
.OrderByDescending(a => a.c)
.ToArray();
var y = v.Where((p, i) => i % 2 == 1)
.GroupBy(a => a)
.Select(g => new { n = g.Key, c = g.Count() })
.OrderByDescending(a => a.c)
.ToArray();
if (x[0].n != y[0].n) {
Write(n - x[0].c - y[0].c);
} else {
Write(n - Max(x[0].c + ((y.Length > 1) ? y[1].c : 0),
(((x.Length > 1) ? x[1].c : 0) + y[0].c)));
}
}
}
public static class Graph {}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const int MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Pow(long i, long N, long MOD = 1000000007) {
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
public static Dictionary<long, int> PrimeFactorization(long N) {
var ret = new Dictionary<long, int>();
for (long i = 2; i * i <= N; ++i) {
int cnt = 0;
while (N % i == 0) {
cnt++;
N /= i;
}
if (cnt != 0)
ret[i] = cnt;
}
if (N >= 2)
ret[N] = 1;
return ret;
}
public static List<long> DivisorEnumrate(long N) {
var ret = new List<long>();
for (long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
}
return ret;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var ACCEPTED = new ACCEPTED();
ACCEPTED.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] HorizontalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Horizontalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203]]
| 8
| 1,269
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace MyProgram {
class AtCoder {
static void Main() {
var N = int.Parse(Console.ReadLine());
var v = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var dict_odd = new Dictionary<int, int>();
var dict_even = new Dictionary<int, int>();
for (var i = 0; i < N; i++) {
if (i % 2 == 0) {
if (!dict_odd.ContainsKey(v[i]))
dict_odd[v[i]] = 0;
dict_odd[v[i]]++;
} else if (i % 2 == 1) {
if (!dict_even.ContainsKey(v[i]))
dict_even[v[i]] = 0;
dict_even[v[i]]++;
}
}
var odd_list = new List<Arr>();
var even_list = new List<Arr>();
foreach (var key in dict_odd.Keys) {
var a = new Arr();
a.key = key;
a.value = dict_odd[key];
odd_list.Add(a);
}
foreach (var key in dict_even.Keys) {
var a = new Arr();
a.key = key;
a.value = dict_even[key];
even_list.Add(a);
}
odd_list.Sort(delegate(Arr a, Arr b) { return b.value - a.value; });
even_list.Sort(delegate(Arr a, Arr b) { return b.value - a.value; });
int result;
if (odd_list[0].key != even_list[0].key) {
result = N - odd_list[0].value - even_list[0].value;
} else if (N > 4) {
result = Math.Min(N - odd_list[1].value - even_list[0].value,
N - odd_list[0].value - even_list[1].value);
} else {
result = N / 2;
}
System.Console.WriteLine(result);
}
}
public class Arr {
public int key;
public int value;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace MyProgram {
class AtCoder {
static void Main() {
var N = int.Parse(Console.ReadLine());
var v = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var dict_odd = new Dictionary<int, int>();
var dict_even = new Dictionary<int, int>();
for (var i = 0; i < N; i++) {
if (i % 2 == 0) {
if (!dict_odd.ContainsKey(v[i]))
dict_odd[v[i]] = 0;
dict_odd[v[i]]++;
} else if (i % 2 == 1) {
if (!dict_even.ContainsKey(v[i]))
dict_even[v[i]] = 0;
dict_even[v[i]]++;
}
}
var odd_list = new List<Arr>();
var even_list = new List<Arr>();
foreach (var key in dict_odd.Keys) {
var a = new Arr();
a.key = key;
a.value = dict_odd[key];
odd_list.Add(a);
}
foreach (var key in dict_even.Keys) {
var a = new Arr();
a.key = key;
a.value = dict_even[key];
even_list.Add(a);
}
odd_list.Sort(delegate(Arr a, Arr b) { return b.value - a.value; });
even_list.Sort(delegate(Arr a, Arr b) { return b.value - a.value; });
int result;
if (odd_list[0].key != even_list[0].key) {
result = N - odd_list[0].value - even_list[0].value;
} else if (odd_list.Count() > 1) {
result = Math.Min(N - odd_list[1].value - even_list[0].value,
N - odd_list[0].value - even_list[1].value);
} else {
result = N / 2;
}
System.Console.WriteLine(result);
}
}
public class Arr {
public int key;
public int value;
}
}
|
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 75, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 75, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203]]
| 8
| 470
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using ll = System.Int64;
public class Contest {
static void Swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static void Swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
Swap1(ref a, ref b);
} // b の方が小さければ交換
static bool Chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
static bool Chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
static T[][] InitMat<T>(long len1, long len2, T val) {
T[][] m = new T[len1][];
for (int i = 0; i < m.Length; i++)
m[i] = Enumerable.Repeat(val, (int)len2).ToArray();
return m;
}
static T[][][] InitMat<T>(long len1, long len2, long len3, T val) {
T[][][] m = new T[len1][][];
for (int i = 0; i < m.Length; i++)
m[i] = InitMat(len2, len3, val);
return m;
}
public const long MOD1 = 1000000007; // 10^9+7
public static void Main() { Solve_C(); }
public static void Solve_A() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_B() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_C() {
ll n;
ll[] v;
MyIO.ReadMulti(out n);
MyIO.ReadArray(out v);
Dictionary<ll, ll> d1 = new Dictionary<ll, ll>();
Dictionary<ll, ll> d2 = new Dictionary<ll, ll>();
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
if (!d1.ContainsKey(v[i]))
d1[v[i]] = 0;
d1[v[i]]++;
} else {
if (!d2.ContainsKey(v[i]))
d2[v[i]] = 0;
d2[v[i]]++;
}
}
VT<ll, ll>[] l1 = new VT<ll, ll>[d1.Count + 1];
VT<ll, ll>[] l2 = new VT<ll, ll>[d2.Count + 1];
ll k = 0;
foreach (var e in d1) {
l1[k++] = new VT<ll, ll>(e.Key, e.Value);
}
l1[k++] = new VT<ll, ll>(-1, 0);
k = 0;
foreach (var e in d2) {
l2[k++] = new VT<ll, ll>(e.Key, e.Value);
}
l2[k++] = new VT<ll, ll>(-1, 0);
Array.Sort(l1, (x, y) => (int)(y.Item2 - x.Item2));
Array.Sort(l2, (x, y) => (int)(y.Item2 - x.Item2));
long ans =
n - l1[0].Item1 != l2[0].Item1
? l1[0].Item2 + l2[0].Item2
: Math.Max(l1[0].Item2 + l2[1].Item2, l1[1].Item2 + l2[0].Item2);
MyIO.WriteMulti(ans);
}
public static void Solve_D() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_E() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_F() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(long n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(long n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(long n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using ll = System.Int64;
public class Contest {
static void Swap1<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
static void Swap2<T>(ref T a, ref T b)
where T : IComparable {
if (a.CompareTo(b) == 1)
Swap1(ref a, ref b);
} // b の方が小さければ交換
static bool Chmin<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == 1) {
a = b;
return true;
}
return false;
} // b の方が小さければ a を更新
static bool Chmax<T>(ref T a, T b)
where T : IComparable {
if (a.CompareTo(b) == -1) {
a = b;
return true;
}
return false;
} // b の方が大きければ a を更新
static T[][] InitMat<T>(long len1, long len2, T val) {
T[][] m = new T[len1][];
for (int i = 0; i < m.Length; i++)
m[i] = Enumerable.Repeat(val, (int)len2).ToArray();
return m;
}
static T[][][] InitMat<T>(long len1, long len2, long len3, T val) {
T[][][] m = new T[len1][][];
for (int i = 0; i < m.Length; i++)
m[i] = InitMat(len2, len3, val);
return m;
}
public const long MOD1 = 1000000007; // 10^9+7
public static void Main() { Solve_C(); }
public static void Solve_A() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_B() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_C() {
ll n;
ll[] v;
MyIO.ReadMulti(out n);
MyIO.ReadArray(out v);
Dictionary<ll, ll> d1 = new Dictionary<ll, ll>();
Dictionary<ll, ll> d2 = new Dictionary<ll, ll>();
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
if (!d1.ContainsKey(v[i]))
d1[v[i]] = 0;
d1[v[i]]++;
} else {
if (!d2.ContainsKey(v[i]))
d2[v[i]] = 0;
d2[v[i]]++;
}
}
VT<ll, ll>[] l1 = new VT<ll, ll>[d1.Count + 1];
VT<ll, ll>[] l2 = new VT<ll, ll>[d2.Count + 1];
ll k = 0;
foreach (var e in d1)
l1[k++] = new VT<ll, ll>(e.Key, e.Value);
l1[k++] = new VT<ll, ll>(-1, 0);
k = 0;
foreach (var e in d2)
l2[k++] = new VT<ll, ll>(e.Key, e.Value);
l2[k++] = new VT<ll, ll>(-1, 0);
Array.Sort(l1, (x, y) => (int)(y.Item2 - x.Item2));
Array.Sort(l2, (x, y) => (int)(y.Item2 - x.Item2));
long ans =
n - (l1[0].Item1 != l2[0].Item1 ? l1[0].Item2 + l2[0].Item2
: Math.Max(l1[0].Item2 + l2[1].Item2,
l1[1].Item2 + l2[0].Item2));
MyIO.WriteMulti(ans);
}
public static void Solve_D() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_E() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
public static void Solve_F() {
ll n, m;
MyIO.ReadMulti(out n, out m);
long ans = 0;
MyIO.WriteMulti(ans);
}
}
#region MyIO
public struct VT<T, U> {
public T Item1;
public U Item2;
public VT(T a, U b) {
Item1 = a;
Item2 = b;
}
}
public struct VT<T, U, V> {
public T Item1;
public U Item2;
public V Item3;
public VT(T a, U b, V c) {
Item1 = a;
Item2 = b;
Item3 = c;
}
}
public struct VT<T, U, V, W> {
public T Item1;
public U Item2;
public V Item3;
public W Item4;
public VT(T a, U b, V c, W d) {
Item1 = a;
Item2 = b;
Item3 = c;
Item4 = d;
}
}
public class Printer : System.IO.StreamWriter {
public override IFormatProvider FormatProvider {
get { return System.Globalization.CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
}
public static class MyIO {
private static char[] splitter = new char[] { ' ' };
private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
private static T cv<T>(string s) =>
eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>()
? ct<T, double>(double.Parse(
s, System.Globalization.CultureInfo.InvariantCulture))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public static string[] ReadMulti<T>(out T a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(ar[0]);
return ar;
}
public static string[] ReadMulti<T, U>(out T a, out U b) {
var ar = ReadMulti<T>(out a);
b = cv<U>(ar[1]);
return ar;
}
public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
var ar = ReadMulti<T, U>(out a, out b);
c = cv<V>(ar[2]);
return ar;
}
public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c,
out W d) {
var ar = ReadMulti<T, U, V>(out a, out b, out c);
d = cv<W>(ar[3]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c,
out W d, out X e) {
var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d);
e = cv<X>(ar[4]);
return ar;
}
public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c,
out W d, out X e,
out Y f) {
var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e);
f = cv<Y>(ar[5]);
return ar;
}
public static string[] ReadArray<T>(out T[] a) {
var ar = Console.ReadLine().Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
a = ar.Select(cv<T>).ToArray();
return ar;
}
public static string[][] ReadLines<T>(long n, out T[] a) {
a = new T[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadMulti(out a[i]);
return arr;
}
public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) {
a = new VT<T, U>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
arr[i] = ReadMulti(out o, out p);
a[i] = new VT<T, U>(o, p);
}
return arr;
}
public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) {
a = new VT<T, U, V>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
arr[i] = ReadMulti(out o, out p, out q);
a[i] = new VT<T, U, V>(o, p, q);
}
return arr;
}
public static string[][] ReadLines<T, U, V, W>(long n,
out VT<T, U, V, W>[] a) {
a = new VT<T, U, V, W>[n];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++) {
T o;
U p;
V q;
W r;
arr[i] = ReadMulti(out o, out p, out q, out r);
a[i] = new VT<T, U, V, W>(o, p, q, r);
}
return arr;
}
public static string[][] ReadMatrix<T>(long n, out T[][] a) {
a = new T[n][];
string[][] arr = new string[n][];
for (int i = 0; i < n; i++)
arr[i] = ReadArray(out a[i]);
return arr;
}
private static void wwp(Action act) {
var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}"
: "{0}";
public static void WriteMulti(params object[] a) {
wwp(() => {
for (int i = 0; i < a.Length; i++) {
string fs = wfm(a[i].GetType()) +
((i < a.Length - 1) ? " " : Environment.NewLine);
Console.Write(fs, a[i]);
}
});
}
public static void WriteArray<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T));
string fs1 = fs + " ";
string fs2 = fs + Environment.NewLine;
for (int i = 0; i < a.Length; i++)
Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]);
});
}
public static void WriteLines<T>(T[] a) {
wwp(() => {
string fs = wfm(typeof(T)) + Environment.NewLine;
foreach (T x in a)
Console.Write(fs, x);
});
}
}
#endregion
|
[["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 41, 75, 213, 3, 4, 0, 25]]
| 8
| 2,777
| 6
|
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, ' '));
return;
}
public void Solve(ConsoleInput cin) {
var n = cin.ReadInt;
var v = cin.ReadIntArray(n);
bool fg = true;
foreach (var elem in v) {
if (elem != v[0]) {
fg = false;
}
}
if (true) {
Console.WriteLine(n / 2);
return;
}
var evens = v.Where((ValueTuple, index) => index % 2 == 0).ToList();
var odds = v.Where((ValueTuple, index) => index % 2 == 1).ToList();
var evenMode = GetMode(evens);
var oddMode = GetMode(odds);
if (evenMode.first != oddMode.first) {
int ans = 0;
ans += GetDiff(evens, evenMode.first);
ans += GetDiff(odds, oddMode.first);
Console.WriteLine(ans);
return;
} else {
int ans1 = 0;
int ans2 = 0;
ans1 += GetDiff(evens, evenMode.first);
ans1 += GetDiff(odds, oddMode.second);
ans2 += GetDiff(evens, evenMode.second);
ans2 += GetDiff(odds, oddMode.first);
Console.WriteLine(Min(ans1, ans2));
return;
}
}
public class MyMode {
public int first { get; set; }
public int second { get; set; }
}
public MyMode GetMode(List<int> numList) {
var dict = new Dictionary<int, int>();
foreach (var elem in numList) {
if (!dict.ContainsKey(elem)) {
dict.Add(elem, 1);
} else {
dict[elem]++;
}
}
var orderedDict = dict.OrderByDescending((x) => x.Value).ToList();
var myMode = new MyMode();
if (orderedDict.Count == 1) {
myMode.first = orderedDict[0].Key;
myMode.second = orderedDict[0].Key;
} else {
myMode.first = orderedDict[0].Key;
myMode.second = orderedDict[1].Key;
}
return myMode;
}
public int GetDiff(List<int> original, int mode) {
int count = 0;
foreach (var elem in original) {
if (elem != mode) {
count++;
}
}
return count;
}
}
public static class Extensions {
public static string Reverse(this string sourse) {
char[] chrAry = sourse.ToCharArray();
Array.Reverse(chrAry);
return new string(chrAry);
}
}
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, ' '));
return;
}
public void Solve(ConsoleInput cin) {
var n = cin.ReadInt;
var v = cin.ReadIntArray(n);
bool fg = true;
foreach (var elem in v) {
if (elem != v[0]) {
fg = false;
}
}
if (fg) {
Console.WriteLine(n / 2);
return;
}
var evens = v.Where((ValueTuple, index) => index % 2 == 0).ToList();
var odds = v.Where((ValueTuple, index) => index % 2 == 1).ToList();
var evenMode = GetMode(evens);
var oddMode = GetMode(odds);
if (evenMode.first != oddMode.first) {
int ans = 0;
ans += GetDiff(evens, evenMode.first);
ans += GetDiff(odds, oddMode.first);
Console.WriteLine(ans);
return;
} else {
int ans1 = 0;
int ans2 = 0;
ans1 += GetDiff(evens, evenMode.first);
ans1 += GetDiff(odds, oddMode.second);
ans2 += GetDiff(evens, evenMode.second);
ans2 += GetDiff(odds, oddMode.first);
Console.WriteLine(Min(ans1, ans2));
return;
}
}
public class MyMode {
public int first { get; set; }
public int second { get; set; }
}
public MyMode GetMode(List<int> numList) {
var dict = new Dictionary<int, int>();
foreach (var elem in numList) {
if (!dict.ContainsKey(elem)) {
dict.Add(elem, 1);
} else {
dict[elem]++;
}
}
var orderedDict = dict.OrderByDescending((x) => x.Value).ToList();
var myMode = new MyMode();
if (orderedDict.Count == 1) {
myMode.first = orderedDict[0].Key;
myMode.second = orderedDict[0].Key;
} else {
myMode.first = orderedDict[0].Key;
myMode.second = orderedDict[1].Key;
}
return myMode;
}
public int GetDiff(List<int> original, int mode) {
int count = 0;
foreach (var elem in original) {
if (elem != mode) {
count++;
}
}
return count;
}
}
public static class Extensions {
public static string Reverse(this string sourse) {
char[] chrAry = sourse.ToCharArray();
Array.Reverse(chrAry);
return new string(chrAry);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22]]
| 8
| 932
| 2
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine().Split(' ');
var d = new int[n];
for (int i = 0; i < n; i++) {
d[i] = int.Parse(s[i]);
}
var maps = new[] { new Dictionary<int, int>(), new Dictionary<int, int>() };
for (int i = 0; i < d.Length; i++) {
if (maps[i % 2].ContainsKey(d[i])) {
maps[i % 2][d[i]]++;
} else {
maps[i % 2][d[i]] = 1;
}
}
var maxs = new[] {
new[] {
new KeyValuePair<int, int>(),
new KeyValuePair<int, int>(),
},
new[] {
new KeyValuePair<int, int>(),
new KeyValuePair<int, int>(),
},
};
for (int i = 0; i < 2; i++) {
var max = maxs[i];
var map = maps[i];
foreach (var item in map) {
if (max[1].Value < item.Value) {
if (max[0].Value < item.Value) {
max[1] = max[0];
max[0] = item;
} else {
max[1] = item;
}
}
}
}
var dx = new[] { 0, 0, 1 };
var dy = new[] { 0, 1, 0 };
var ans = int.MaxValue;
for (int i = 0; i < 3; i++) {
if (maxs[0][dx[i]].Key != maxs[1][dy[i]].Key) {
ans = Math.Min(ans, maxs[0][dx[i]].Value + maxs[1][dy[i]].Value);
}
}
Console.WriteLine(n - ans);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var s = Console.ReadLine().Split(' ');
var d = new int[n];
for (int i = 0; i < n; i++) {
d[i] = int.Parse(s[i]);
}
var maps = new[] { new Dictionary<int, int>(), new Dictionary<int, int>() };
for (int i = 0; i < d.Length; i++) {
if (maps[i % 2].ContainsKey(d[i])) {
maps[i % 2][d[i]]++;
} else {
maps[i % 2][d[i]] = 1;
}
}
var maxs = new[] {
new[] {
new KeyValuePair<int, int>(),
new KeyValuePair<int, int>(),
},
new[] {
new KeyValuePair<int, int>(),
new KeyValuePair<int, int>(),
},
};
for (int i = 0; i < 2; i++) {
var max = maxs[i];
var map = maps[i];
foreach (var item in map) {
if (max[1].Value < item.Value) {
if (max[0].Value < item.Value) {
max[1] = max[0];
max[0] = item;
} else {
max[1] = item;
}
}
}
}
var dx = new[] { 0, 0, 1 };
var dy = new[] { 0, 1, 0 };
var ans = int.MinValue;
for (int i = 0; i < 3; i++) {
if (maxs[0][dx[i]].Key != maxs[1][dy[i]].Key) {
ans = Math.Max(ans, maxs[0][dx[i]].Value + maxs[1][dy[i]].Value);
}
}
Console.WriteLine(n - ans);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22]]
| 8
| 476
| 4
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
int itemCount = int.Parse(Reader.ReadLine());
int[] list =
Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
Dictionary<int, int> lst1 = new Dictionary<int, int>();
Dictionary<int, int> lst2 = new Dictionary<int, int>();
for (int i = 0; i < list.Length; i++) {
if (i % 2 == 0) {
if (lst1.ContainsKey(list[i])) {
lst1[list[i]]++;
} else {
lst1[list[i]] = 1;
}
} else {
if (lst2.ContainsKey(list[i])) {
lst2[list[i]]++;
} else {
lst2[list[i]] = 1;
}
}
}
int ans = 0;
List<KeyValuePair<int, int>> l1 =
lst1.OrderByDescending(a => a.Value).ToList();
List<KeyValuePair<int, int>> l2 =
lst2.OrderByDescending(a => a.Value).ToList();
int tmp1 = l1.First().Value;
if (l1.First().Key == l2.First().Key) {
if (l2.Count > 1) {
ans += l2[1].Value;
}
} else {
ans += l2.First().Value;
}
int tmp2 = l2.First().Value;
if (l2.First().Key == l1.First().Key) {
if (l1.Count > 1) {
ans += l1[1].Value;
}
} else {
ans += l1.First().Value;
}
ans = itemCount - Math.Max(tmp1, tmp2);
Console.WriteLine(ans);
}
public class Reader {
static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
4
1 1 1 1
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
int itemCount = int.Parse(Reader.ReadLine());
int[] list =
Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
Dictionary<int, int> lst1 = new Dictionary<int, int>();
Dictionary<int, int> lst2 = new Dictionary<int, int>();
for (int i = 0; i < list.Length; i++) {
if (i % 2 == 0) {
if (lst1.ContainsKey(list[i])) {
lst1[list[i]]++;
} else {
lst1[list[i]] = 1;
}
} else {
if (lst2.ContainsKey(list[i])) {
lst2[list[i]]++;
} else {
lst2[list[i]] = 1;
}
}
}
int ans = 0;
List<KeyValuePair<int, int>> l1 =
lst1.OrderByDescending(a => a.Value).ToList();
List<KeyValuePair<int, int>> l2 =
lst2.OrderByDescending(a => a.Value).ToList();
int tmp1 = l1.First().Value;
if (l1.First().Key == l2.First().Key) {
if (l2.Count > 1) {
tmp1 += l2[1].Value;
}
} else {
tmp1 += l2.First().Value;
}
int tmp2 = l2.First().Value;
if (l2.First().Key == l1.First().Key) {
if (l1.Count > 1) {
tmp2 += l1[1].Value;
}
} else {
tmp2 += l1.First().Value;
}
ans = itemCount - Math.Max(tmp1, tmp2);
Console.WriteLine(ans);
}
public class Reader {
static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
6
105 119 105 119 105 119
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
| 8
| 538
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var array = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
var oddDict = new Dictionary<int, int>();
var eveDict = new Dictionary<int, int>();
for (var i = 0; i < n; i++) {
if (i % 2 == 0)
oddDict[array[i]] = 0;
else
eveDict[array[i]] = 0;
}
for (var i = 0; i < n; i++) {
if (i % 2 == 0)
oddDict[array[i]]++;
else
eveDict[array[i]]++;
}
oddDict = oddDict.OrderByDescending(k => k.Value)
.ToDictionary(t => t.Key, t => t.Value);
eveDict = eveDict.OrderByDescending(k => k.Value)
.ToDictionary(t => t.Key, t => t.Value);
var oddMax = oddDict.First().Key;
var eveMax = eveDict.First().Key;
// 最大値が同じ場合はずらせないか考慮する
// 2番目に大きい数値が大きいほうをずらす
var oddArrayKey = oddDict.Keys.ToArray();
var oddArrayValue = oddDict.Values.ToArray();
var eveArrayKey = eveDict.Keys.ToArray();
var eveArrayValue = eveDict.Values.ToArray();
// 完全に同じ条件の場合は特殊処理
if (oddArrayKey.Length == 1 && eveArrayKey.Length == 1 &&
oddArrayValue[0] == eveArrayValue[0]) {
Console.WriteLine(n / 2);
return;
}
for (var i = 0; i < n / 2; i++) {
if (oddArrayKey[i] == eveArrayKey[i]) {
var ooo = oddArrayValue[i] + eveArrayValue[i + 1];
var eee = eveArrayValue[i] + oddArrayValue[i + 1];
if (ooo > eee) {
oddMax = oddArrayKey[i];
eveMax = eveArrayKey[i + 1];
break;
} else {
oddMax = oddArrayKey[i + 1];
eveMax = eveArrayKey[i];
break;
}
} else
break;
}
// oddMaxとeveMaxではない数値を数える
var total = 0;
for (var i = 0; i < n; i++) {
if (i % 2 == 0 && array[i] != oddMax)
total++;
if (i % 2 == 1 && array[i] != eveMax)
total++;
}
Console.WriteLine(total);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var array = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray();
var oddDict = new Dictionary<int, int>();
var eveDict = new Dictionary<int, int>();
for (var i = 0; i < n; i++) {
if (i % 2 == 0)
oddDict[array[i]] = 0;
else
eveDict[array[i]] = 0;
}
for (var i = 0; i < n; i++) {
if (i % 2 == 0)
oddDict[array[i]]++;
else
eveDict[array[i]]++;
}
oddDict = oddDict.OrderByDescending(k => k.Value)
.ToDictionary(t => t.Key, t => t.Value);
eveDict = eveDict.OrderByDescending(k => k.Value)
.ToDictionary(t => t.Key, t => t.Value);
var oddMax = oddDict.First().Key;
var eveMax = eveDict.First().Key;
// 最大値が同じ場合はずらせないか考慮する
// 2番目に大きい数値が大きいほうをずらす
var oddArrayKey = oddDict.Keys.ToArray();
var oddArrayValue = oddDict.Values.ToArray();
var eveArrayKey = eveDict.Keys.ToArray();
var eveArrayValue = eveDict.Values.ToArray();
// 完全に同じ条件の場合は特殊処理
if (oddArrayKey.Length == 1 && eveArrayKey.Length == 1 &&
oddArrayKey[0] == eveArrayKey[0]) {
Console.WriteLine(n / 2);
return;
}
for (var i = 0; i < n / 2; i++) {
if (oddArrayKey[i] == eveArrayKey[i]) {
var ooo = oddArrayValue[i] + eveArrayValue[i + 1];
var eee = eveArrayValue[i] + oddArrayValue[i + 1];
if (ooo > eee) {
oddMax = oddArrayKey[i];
eveMax = eveArrayKey[i + 1];
break;
} else {
oddMax = oddArrayKey[i + 1];
eveMax = eveArrayKey[i];
break;
}
} else
break;
}
// oddMaxとeveMaxではない数値を数える
var total = 0;
for (var i = 0; i < n; i++) {
if (i % 2 == 0 && array[i] != oddMax)
total++;
if (i % 2 == 1 && array[i] != eveMax)
total++;
}
Console.WriteLine(total);
}
}
}
|
[["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22]]
| 8
| 530
| 4
|
#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Globalization;
#if DEBUG
using System.Diagnostics;
#endif
namespace at103 {
class Program {
static string _inputFilename = "input.txt";
static string _outputFilename = "output.txt";
static bool _useFileInput = false;
const string _delim = "!";
static void Main(string[] args) {
StreamWriter file = null;
#if DEBUG
var testNumber = 0;
var timer = new Stopwatch();
foreach (var test in GetTests()) {
timer.Start();
var defaultColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"<!-- TEST #{testNumber} -->");
Console.ForegroundColor = defaultColor;
Console.SetIn(test);
#else
if (_useFileInput) {
Console.SetIn(File.OpenText(_inputFilename));
file = new StreamWriter(_outputFilename);
Console.SetOut(file);
}
#endif
try {
#if DEBUG
Solution(testNumber);
#else
Solution(0);
#endif
} finally {
#if DEBUG
#else
if (_useFileInput) {
file.Close();
}
#endif
}
#if DEBUG
timer.Stop();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine(
$"<!-- TEST #{testNumber} FINISHED IN {timer.Elapsed.ToString(@"ss\:fff")}-->");
Console.ForegroundColor = defaultColor;
timer.Reset();
testNumber++;
}
#endif
}
static void Solution(int testNumber) {
#region SOLUTION
var n = ReadInt();
var a = ReadIntArray();
var max = 1000 * 100;
var odd = new int[max + 1];
var even = new int[max + 1];
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
odd[a[i]]++;
} else {
even[a[i]]++;
}
}
var on = new int[max + 1];
var en = new int[max + 1];
for (int i = 0; i < max + 1; i++) {
on[i] = i;
en[i] = i;
}
Array.Sort(odd, on);
Array.Sort(even, en);
if (on[max] != en[max]) {
Console.WriteLine(n - odd[max] - odd[max]);
} else {
if (odd[max] + even[max - 1] > even[max] + odd[max - 1]) {
Console.WriteLine(n - (odd[max] + even[max - 1]));
} else {
Console.WriteLine(n - (even[max] + odd[max - 1]));
}
}
// var maxOdd = 0;
// var maxOdd2 = 0;
// var on = -1;
// var on2 = -1;
// var maxEven = 0;
// var maxEven2 = 0;
// var en = -1;
// var en2 = -1;
// var oddStreak = 1;
// var evenStreak = 1;
// for (int i = 1; i < n / 2; i++)
//{
// if (odd[i] == odd[i - 1])
// {
// oddStreak++;
// }
// else
// {
// oddStreak = 1;
// if (oddStreak >= maxOdd)
// {
// maxOdd2 = maxOdd;
// maxOdd = oddStreak;
// on2 = on;
// on = odd[i - 1];
// }
// else if (oddStreak > maxOdd2)
// {
// maxOdd2 = oddStreak;
// }
// }
// if (even[i] == even[i - 1])
// {
// evenStreak++;
// }
// else
// {
// evenStreak = 1;
// if (evenStreak >= maxEven)
// {
// maxEven2 = maxEven;
// maxEven = evenStreak;
// }
// else if (evenStreak > maxEven2)
// {
// maxEven2 = evenStreak;
// }
// }
//}
// if (oddStreak >= maxOdd)
//{
// maxOdd2 = maxOdd;
// maxOdd = oddStreak;
//}
// else if (oddStreak > maxOdd2)
//{
// maxOdd2 = oddStreak;
//}
// if (evenStreak >= maxEven)
//{
// maxEven2 = maxEven;
// maxEven = evenStreak;
//}
// else if (evenStreak > maxEven2)
//{
// maxEven2 = evenStreak;
//}
// Console.WriteLine(n - maxEven - maxOdd);
// var n = readInt();
// var m = readInt();
// var a = readIntArray();
// var b = readIntArray();
#endregion
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine()
.Split(' ')
.Where(i => !string.IsNullOrEmpty(i))
.Select(i => int.Parse(i))
.ToArray();
}
static long[] ReadLongArray() {
return Console.ReadLine()
.Split(' ')
.Where(i => !string.IsNullOrEmpty(i))
.Select(i => long.Parse(i))
.ToArray();
}
#if DEBUG
static IEnumerable<TextReader> GetTests() {
var tests = new List<string>();
var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
using (
var resource = new StreamReader(
Assembly.GetCallingAssembly().GetManifestResourceStream(resName))) {
while (true) {
var nextText = new StringBuilder();
var endOfFile = false;
while (true) {
var line = resource.ReadLine();
endOfFile = line == null;
if (endOfFile) {
break;
}
if (line.Equals(_delim, StringComparison.Ordinal)) {
break;
}
nextText.AppendLine(line);
}
yield return new StringReader(nextText.ToString());
if (endOfFile) {
break;
}
}
}
}
#endif
}
}
|
#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Globalization;
#if DEBUG
using System.Diagnostics;
#endif
namespace at103 {
class Program {
static string _inputFilename = "input.txt";
static string _outputFilename = "output.txt";
static bool _useFileInput = false;
const string _delim = "!";
static void Main(string[] args) {
StreamWriter file = null;
#if DEBUG
var testNumber = 0;
var timer = new Stopwatch();
foreach (var test in GetTests()) {
timer.Start();
var defaultColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"<!-- TEST #{testNumber} -->");
Console.ForegroundColor = defaultColor;
Console.SetIn(test);
#else
if (_useFileInput) {
Console.SetIn(File.OpenText(_inputFilename));
file = new StreamWriter(_outputFilename);
Console.SetOut(file);
}
#endif
try {
#if DEBUG
Solution(testNumber);
#else
Solution(0);
#endif
} finally {
#if DEBUG
#else
if (_useFileInput) {
file.Close();
}
#endif
}
#if DEBUG
timer.Stop();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine(
$"<!-- TEST #{testNumber} FINISHED IN {timer.Elapsed.ToString(@"ss\:fff")}-->");
Console.ForegroundColor = defaultColor;
timer.Reset();
testNumber++;
}
#endif
}
static void Solution(int testNumber) {
#region SOLUTION
var n = ReadInt();
var a = ReadIntArray();
var max = 1000 * 100;
var odd = new int[max + 1];
var even = new int[max + 1];
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
odd[a[i]]++;
} else {
even[a[i]]++;
}
}
var on = new int[max + 1];
var en = new int[max + 1];
for (int i = 0; i < max + 1; i++) {
on[i] = i;
en[i] = i;
}
Array.Sort(odd, on);
Array.Sort(even, en);
if (on[max] != en[max]) {
Console.WriteLine(n - even[max] - odd[max]);
} else {
if (odd[max] + even[max - 1] > even[max] + odd[max - 1]) {
Console.WriteLine(n - (odd[max] + even[max - 1]));
} else {
Console.WriteLine(n - (even[max] + odd[max - 1]));
}
}
// var maxOdd = 0;
// var maxOdd2 = 0;
// var on = -1;
// var on2 = -1;
// var maxEven = 0;
// var maxEven2 = 0;
// var en = -1;
// var en2 = -1;
// var oddStreak = 1;
// var evenStreak = 1;
// for (int i = 1; i < n / 2; i++)
//{
// if (odd[i] == odd[i - 1])
// {
// oddStreak++;
// }
// else
// {
// oddStreak = 1;
// if (oddStreak >= maxOdd)
// {
// maxOdd2 = maxOdd;
// maxOdd = oddStreak;
// on2 = on;
// on = odd[i - 1];
// }
// else if (oddStreak > maxOdd2)
// {
// maxOdd2 = oddStreak;
// }
// }
// if (even[i] == even[i - 1])
// {
// evenStreak++;
// }
// else
// {
// evenStreak = 1;
// if (evenStreak >= maxEven)
// {
// maxEven2 = maxEven;
// maxEven = evenStreak;
// }
// else if (evenStreak > maxEven2)
// {
// maxEven2 = evenStreak;
// }
// }
//}
// if (oddStreak >= maxOdd)
//{
// maxOdd2 = maxOdd;
// maxOdd = oddStreak;
//}
// else if (oddStreak > maxOdd2)
//{
// maxOdd2 = oddStreak;
//}
// if (evenStreak >= maxEven)
//{
// maxEven2 = maxEven;
// maxEven = evenStreak;
//}
// else if (evenStreak > maxEven2)
//{
// maxEven2 = evenStreak;
//}
// Console.WriteLine(n - maxEven - maxOdd);
// var n = readInt();
// var m = readInt();
// var a = readIntArray();
// var b = readIntArray();
#endregion
}
static int ReadInt() { return int.Parse(Console.ReadLine()); }
static long ReadLong() { return long.Parse(Console.ReadLine()); }
static int[] ReadIntArray() {
return Console.ReadLine()
.Split(' ')
.Where(i => !string.IsNullOrEmpty(i))
.Select(i => int.Parse(i))
.ToArray();
}
static long[] ReadLongArray() {
return Console.ReadLine()
.Split(' ')
.Where(i => !string.IsNullOrEmpty(i))
.Select(i => long.Parse(i))
.ToArray();
}
#if DEBUG
static IEnumerable<TextReader> GetTests() {
var tests = new List<string>();
var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
using (
var resource = new StreamReader(
Assembly.GetCallingAssembly().GetManifestResourceStream(resName))) {
while (true) {
var nextText = new StringBuilder();
var endOfFile = false;
while (true) {
var line = resource.ReadLine();
endOfFile = line == null;
if (endOfFile) {
break;
}
if (line.Equals(_delim, StringComparison.Ordinal)) {
break;
}
nextText.AppendLine(line);
}
yield return new StringReader(nextText.ToString());
if (endOfFile) {
break;
}
}
}
}
#endif
}
}
|
[["-", 0, 28, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 12, 204, 205, 22]]
| 8
| 980
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Solution {
static void Main() {
var n = int.Parse(Console.ReadLine());
var v = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var a = new Dictionary<int, int>();
var b = new Dictionary<int, int>();
for (int i = 0; i < v.Length; i++) {
if (i % 2 == 0) {
if (!a.ContainsKey(v[i])) {
a[v[i]] = 0;
}
a[v[i]]++;
} else {
if (!b.ContainsKey(v[i])) {
b[v[i]] = 0;
}
b[v[i]]++;
}
}
var a1 = a.OrderByDescending(x => x.Value).First();
var a2 = new KeyValuePair<int, int>(-1, 0);
if (a.Any(x => x.Key != a1.Key)) {
a2 =
a.Where(x => x.Key != a1.Key).OrderByDescending(x => x.Value).First();
}
var b1 = b.OrderByDescending(x => x.Value).First();
var b2 = new KeyValuePair<int, int>(-1, 0);
if (b.Any(x => x.Key != b1.Key)) {
b2 =
b.Where(x => x.Key != b1.Key).OrderByDescending(x => x.Value).First();
}
int result;
if (a1.Key != b1.Key || a1.Value == a2.Value || b1.Value == b2.Value) {
result = (n / 2 - a1.Value) + (n / 2 - b1.Value);
} else {
if (a1.Value == b1.Value) {
result =
Math.Min(n / 2 - a2.Value, 2 / n - b2.Value) + (n / 2 - a1.Value);
} else if (a1.Value > b1.Value) {
result = (n / 2 - a1.Value) + (n / 2 - b2.Value);
} else {
result = (n / 2 - a2.Value) + (n / 2 - b1.Value);
}
}
Console.WriteLine(result);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Solution {
static void Main() {
var n = int.Parse(Console.ReadLine());
var v = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
var a = new Dictionary<int, int>();
var b = new Dictionary<int, int>();
for (int i = 0; i < v.Length; i++) {
if (i % 2 == 0) {
if (!a.ContainsKey(v[i])) {
a[v[i]] = 0;
}
a[v[i]]++;
} else {
if (!b.ContainsKey(v[i])) {
b[v[i]] = 0;
}
b[v[i]]++;
}
}
var a1 = a.OrderByDescending(x => x.Value).First();
var a2 = new KeyValuePair<int, int>(-1, 0);
if (a.Any(x => x.Key != a1.Key)) {
a2 =
a.Where(x => x.Key != a1.Key).OrderByDescending(x => x.Value).First();
}
var b1 = b.OrderByDescending(x => x.Value).First();
var b2 = new KeyValuePair<int, int>(-1, 0);
if (b.Any(x => x.Key != b1.Key)) {
b2 =
b.Where(x => x.Key != b1.Key).OrderByDescending(x => x.Value).First();
}
int result;
if (a1.Key != b1.Key || a1.Value == a2.Value || b1.Value == b2.Value) {
result = (n / 2 - a1.Value) + (n / 2 - b1.Value);
} else {
if (a1.Value == b1.Value) {
result =
Math.Min(n / 2 - a2.Value, n / 2 - b2.Value) + (n / 2 - a1.Value);
} else if (a1.Value > b1.Value) {
result = (n / 2 - a1.Value) + (n / 2 - b2.Value);
} else {
result = (n / 2 - a2.Value) + (n / 2 - b1.Value);
}
}
Console.WriteLine(result);
}
}
|
[["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 203], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 85], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 85], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203]]
| 8
| 528
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace easy_Atcoder {
class Program {
static void Main(string[] args) {
int[] ABC = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
Array.Sort(ABC);
Console.WriteLine(ABC[0] * 10 + ABC[1] + ABC[2]);
}
// float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
// long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// long N = NK[0];
// long K = NK[1];
// long K = long.Parse(Console.ReadLine());
// int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// string S = Console.ReadLine();
// int x = int.Parse(Console.ReadLine());
// int b = int.Parse(Console.ReadLine());
// int N = int.Parse(Console.ReadLine());
// float N = float.Parse(Console.ReadLine());
// string c = Console.ReadLine();
// string B = Console.ReadLine();
// string[] s = Console.ReadLine().Split();
// var s = (new string[] { Console.ReadLine(), Console.ReadLine(),
// Console.ReadLine() }).Select(float.Parse); float[] a =
// Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X =
// Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new
// int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[]
// s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new
// Dictionary<long,long>(); for(int i=0;i<s[0];i++){
// long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
// else{hs.Add(q[0],q[1]);}
// }
// //最小公倍数
// static long Lcm(long a, long b)
// {
// return a/Gcd(a,b)*b;
// }
// //最大公約数
// static long Gcd(long m, long n)
// {
// if(n==0)return m;
// return Gcd(n,m%n);
// }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace easy_Atcoder {
class Program {
static void Main(string[] args) {
int[] ABC = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
Array.Sort(ABC);
Console.WriteLine(ABC[2] * 10 + ABC[0] + ABC[1]);
}
// float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
// long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// long N = NK[0];
// long K = NK[1];
// long K = long.Parse(Console.ReadLine());
// int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// string S = Console.ReadLine();
// int x = int.Parse(Console.ReadLine());
// int b = int.Parse(Console.ReadLine());
// int N = int.Parse(Console.ReadLine());
// float N = float.Parse(Console.ReadLine());
// string c = Console.ReadLine();
// string B = Console.ReadLine();
// string[] s = Console.ReadLine().Split();
// var s = (new string[] { Console.ReadLine(), Console.ReadLine(),
// Console.ReadLine() }).Select(float.Parse); float[] a =
// Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X =
// Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new
// int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[]
// s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new
// Dictionary<long,long>(); for(int i=0;i<s[0];i++){
// long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
// if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
// else{hs.Add(q[0],q[1]);}
// }
// //最小公倍数
// static long Lcm(long a, long b)
// {
// return a/Gcd(a,b)*b;
// }
// //最大公約数
// static long Gcd(long m, long n)
// {
// if(n==0)return m;
// return Gcd(n,m%n);
// }
}
}
|
[["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 123
| 6
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int n = 100;
/*
long n = long.Parse(Console.ReadLine());
long[] input = new long[5];
for(int a = 0; a < 5; a++)
{
input[a]=long.Parse(Console.ReadLine());
}
*/
int[] input =
Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
Console.WriteLine(input.Sum() + input.OrderBy(i => -i).ToArray()[0] * 10);
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int n = 100;
/*
long n = long.Parse(Console.ReadLine());
long[] input = new long[5];
for(int a = 0; a < 5; a++)
{
input[a]=long.Parse(Console.ReadLine());
}
*/
int[] input =
Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
Console.WriteLine(input.Sum() + input.OrderBy(i => -i).ToArray()[0] * 9);
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
[["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203]]
| 8
| 108
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var logos = Console.ReadLine().Split(' ');
var ML = new MaximizeLogo(logos);
var max = ML.CalcMax();
Console.WriteLine(max);
}
}
public class MaximizeLogo {
string[] logos;
int max;
public MaximizeLogo(string[] logos) { this.logos = logos; }
public int CalcMax() {
var logos_int = new List<int>();
foreach (var logo in logos) {
int p;
if (!int.TryParse(logo, out p)) {
return -1;
} else {
logos_int.Add(p);
}
}
logos_int = logos_int.OrderBy(v => v).ToList();
return logos_int[0] + logos_int[1] + 10 * logos_int[1];
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var logos = Console.ReadLine().Split(' ');
var ML = new MaximizeLogo(logos);
var max = ML.CalcMax();
Console.WriteLine(max);
}
}
public class MaximizeLogo {
string[] logos;
int max;
public MaximizeLogo(string[] logos) { this.logos = logos; }
public int CalcMax() {
var logos_int = new List<int>();
foreach (var logo in logos) {
int p;
if (!int.TryParse(logo, out p)) {
return -1;
} else {
logos_int.Add(p);
}
}
logos_int = logos_int.OrderBy(v => v).ToList();
return logos_int[0] + logos_int[1] + 10 * logos_int[2];
}
}
|
[["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 192
| 2
|
using System;
using System.Linq;
namespace abc110_a {
class program {
static void Main(string[] args) {
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int ans;
if (x[0] > x[1] && x[0] > x[2]) {
ans = 10 * x[0] + x[1] + x[2];
} else {
if (x[1] > x[0] && x[1] > x[2]) {
ans = 10 * x[1] + x[0] + x[2];
} else {
ans = 10 * x[2] + x[0] + x[1];
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
namespace abc110_a {
class program {
static void Main(string[] args) {
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int ans;
if (x[0] >= x[1] && x[0] >= x[2]) {
ans = 10 * x[0] + x[1] + x[2];
} else {
if (x[1] >= x[0] && x[1] >= x[2]) {
ans = 10 * x[1] + x[0] + x[2];
} else {
ans = 10 * x[2] + x[0] + x[1];
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["-", 75, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 75, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 20]]
| 8
| 174
| 8
|
// デバッグ実行:Ctrl+F5
using System;
class Program {
static void Main(string[] args) {
String line;
line = Console.ReadLine();
String[] words = line.Split(' ');
int A, B, C;
int result;
A = int.Parse(words[0]);
B = int.Parse(words[1]);
C = int.Parse(words[2]);
if (A > B && A > C) {
result = A * 10 + B + C;
} else if (B > A && B > C) {
result = B * 10 + A + C;
} else
result = C * 10 + A + B;
Console.WriteLine(result);
}
}
|
// デバッグ実行:Ctrl+F5
using System;
class Program {
static void Main(string[] args) {
String line;
line = Console.ReadLine();
String[] words = line.Split(' ');
int A, B, C;
int result;
A = int.Parse(words[0]);
B = int.Parse(words[1]);
C = int.Parse(words[2]);
if (A > B && A > C) {
result = A * 10 + B + C;
} else if (B > C) {
result = B * 10 + A + C;
} else
result = C * 10 + A + B;
Console.WriteLine(result);
}
}
|
[["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 47]]
| 8
| 153
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long[] NMXY =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long[] x =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long[] y =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
String result = "War";
int Xmax = (int)x.Max();
int Ymin = (int)y.Min();
if (Xmax < Ymin) {
for (int Z = (int)NMXY[2]; Z <= (int)NMXY[3]; Z++) {
if (Xmax < Z && Z <= Ymin) {
result = "No War";
break;
}
}
}
////X < Z <= Y
// if(NMXY[2] < y.Min() && y.Min() <= NMXY[3])
//{
// //x < z <= y
// if (x.Max() < y.Min())
// {
// result = "No War";
// }
//}
Console.WriteLine(result);
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long[] NMXY =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long[] x =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
long[] y =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
String result = "War";
int Xmax = (int)x.Max();
int Ymin = (int)y.Min();
if (Xmax < Ymin) {
for (int Z = (int)NMXY[2] + 1; Z <= (int)NMXY[3]; Z++) {
if (Xmax < Z && Z <= Ymin) {
result = "No War";
break;
}
}
}
////X < Z <= Y
// if(NMXY[2] < y.Min() && y.Min() <= NMXY[3])
//{
// //x < z <= y
// if (x.Max() < y.Min())
// {
// result = "No War";
// }
//}
Console.WriteLine(result);
}
}
}
// 文字列の入力
// string s = Console.ReadLine();
// 整数の入力
// long n = long.Parse(Console.ReadLine());
// 文字列配列の入力
// string[] inputStrArray = Console.ReadLine().Split(' ');
// 整数配列の入力
// long[] inputLongArray = Console.ReadLine().Split(' ').Select(i =>
// long.Parse(i)).ToArray();
|
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 267
| 2
|
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();
int m = sc.NextInt();
int x = sc.NextInt();
int y = sc.NextInt();
int[] xs = sc.IntArray();
int[] ys = sc.IntArray();
string answer =
xs.Max() < ys.Min() && xs.Max() <= y && ys.Min() > x ? "No War" : "War";
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int n = sc.NextInt();
int m = sc.NextInt();
int x = sc.NextInt();
int y = sc.NextInt();
int[] xs = sc.IntArray();
int[] ys = sc.IntArray();
string answer =
xs.Max() < ys.Min() && xs.Max() < y && ys.Min() > x ? "No War" : "War";
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 41, 15, 16, 31, 16, 12, 16, 17, 19], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 17, 18]]
| 8
| 438
| 2
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
int x = Console.ReadLine().Split().Select(int.Parse).ToArray().Max();
int y = Console.ReadLine().Split().Select(int.Parse).ToArray().Min();
Console.WriteLine(solve(x, y, s[2], s[3]) ? "No war" : "War");
}
static bool solve(int x, int y, int X, int Y) {
for (int i = -100; i <= 100; i++) {
if (i > X && i <= Y && i > x && i <= y)
return true;
}
return false;
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
int x = Console.ReadLine().Split().Select(int.Parse).ToArray().Max();
int y = Console.ReadLine().Split().Select(int.Parse).ToArray().Min();
Console.WriteLine(solve(x, y, s[2], s[3]) ? "No War" : "War");
}
static bool solve(int x, int y, int X, int Y) {
for (int i = -100; i <= 100; i++) {
if (i > X && i <= Y && i > x && i <= y)
return true;
}
return false;
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222]]
| 8
| 194
| 2
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
int x = Console.ReadLine()
.Split()
.Select(int.Parse)
.ToArray()
.Concat(new[] { s[2] })
.Max();
int y = Console.ReadLine()
.Split()
.Select(int.Parse)
.ToArray()
.Concat(new[] { s[3] })
.Min();
Console.WriteLine(x < y ? "No war" : "War");
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
int x = Console.ReadLine()
.Split()
.Select(int.Parse)
.ToArray()
.Concat(new[] { s[2] })
.Max();
int y = Console.ReadLine()
.Split()
.Select(int.Parse)
.ToArray()
.Concat(new[] { s[3] })
.Min();
Console.WriteLine(x < y ? "No War" : "War");
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222]]
| 8
| 148
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B._1_Dimensional_World_s_Tale {
class Program {
static void Main(string[] args) {
var NMXY =
Console.ReadLine().Split(null).Select(x => int.Parse(x)).ToList();
var N = NMXY[0];
var M = NMXY[1];
var X = NMXY[2];
var Y = NMXY[3];
var Xn =
Console.ReadLine().Split(null).Select(x => int.Parse(x)).ToList();
var Yn =
Console.ReadLine().Split(null).Select(x => int.Parse(x)).ToList();
Xn.Add(X);
Yn.Add(Y);
if (Xn.Max() < Yn.Min())
Console.WriteLine("No Wor");
else
Console.WriteLine("Wor");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B._1_Dimensional_World_s_Tale {
class Program {
static void Main(string[] args) {
var NMXY =
Console.ReadLine().Split(null).Select(x => int.Parse(x)).ToList();
var N = NMXY[0];
var M = NMXY[1];
var X = NMXY[2];
var Y = NMXY[3];
var Xn =
Console.ReadLine().Split(null).Select(x => int.Parse(x)).ToList();
var Yn =
Console.ReadLine().Split(null).Select(x => int.Parse(x)).ToList();
Xn.Add(X);
Yn.Add(Y);
if (Xn.Max() < Yn.Min())
Console.WriteLine("No War");
else
Console.WriteLine("War");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 217
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]B - 1 Dimensional World's Tale
var line = ReadLine();
int x = line[2];
int y = line[3];
var xCoords = ReadLine().OrderByDescending(c => c).ToList();
int xMax = xCoords[0];
var yCoords = ReadLine().OrderBy(c => c).ToList();
int yMin = yCoords[0];
for (int i = xMax + 1; i <= yMin; i++) {
if (i > x && x <= y) {
Console.WriteLine("No War");
return;
}
}
Console.WriteLine("War");
}
static List<int> ReadLine() {
var line = Console.ReadLine().TrimEnd();
var array = line.Split(' ');
var numbers = new List<int>();
foreach (var s in array) {
int num = int.Parse(s);
numbers.Add(num);
}
return numbers;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]B - 1 Dimensional World's Tale
var line = ReadLine();
int x = line[2];
int y = line[3];
var xCoords = ReadLine().OrderByDescending(c => c).ToList();
int xMax = xCoords[0];
var yCoords = ReadLine().OrderBy(c => c).ToList();
int yMin = yCoords[0];
for (int i = xMax + 1; i <= yMin; i++) {
if (i > x && i <= y) {
Console.WriteLine("No War");
return;
}
}
Console.WriteLine("War");
}
static List<int> ReadLine() {
var line = Console.ReadLine().TrimEnd();
var array = line.Split(' ');
var numbers = new List<int>();
foreach (var s in array) {
int num = int.Parse(s);
numbers.Add(num);
}
return numbers;
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
| 8
| 235
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace MyProgram {
public class Program {
public static void Main(string[] args) {
int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int N = n[0];
int M = n[1];
int X = n[2];
int Y = n[3];
int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int[] y = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
Array.Sort(x);
Array.Sort(y);
bool War = true;
for (int i = X; i <= Y; i++) {
if (i > x[x.Length - 1] && i <= y[0]) {
War = false;
}
}
if (War)
Console.WriteLine("War");
else
Console.WriteLine("No War");
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace MyProgram {
public class Program {
public static void Main(string[] args) {
int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int N = n[0];
int M = n[1];
int X = n[2];
int Y = n[3];
int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int[] y = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
Array.Sort(x);
Array.Sort(y);
bool War = true;
for (int i = X + 1; i <= Y; i++) {
if (i > x[x.Length - 1] && i <= y[0]) {
War = false;
}
}
if (War)
Console.WriteLine("War");
else
Console.WriteLine("No War");
}
}
}
|
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 259
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var xCityNum = input[0];
var yCityNum = input[1];
var xCapital = input[2];
var yCapital = input[3];
var xNums = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var yNums = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
Array.Sort(xNums);
Array.Sort(yNums);
var max = xNums[xCityNum - 1];
var min = yNums[0];
if (max > min) {
WriteLine("War");
return;
}
if (xCapital > yCapital || xCapital >= min || yCapital < max) {
WriteLine("War");
return;
}
WriteLine("No War");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var xCityNum = input[0];
var yCityNum = input[1];
var xCapital = input[2];
var yCapital = input[3];
var xNums = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var yNums = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
Array.Sort(xNums);
Array.Sort(yNums);
var max = xNums[xCityNum - 1];
var min = yNums[0];
if (max >= min) {
WriteLine("War");
return;
}
if (xCapital >= yCapital || xCapital >= min || yCapital <= max) {
WriteLine("War");
return;
}
WriteLine("No War");
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
| 8
| 230
| 6
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
var inputNMXY =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var maxX = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Max();
var minY = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Min();
var X = inputNMXY[2];
var Y = inputNMXY[3];
if ((X < Y) && (maxX <= minY) && (X < minY) && (maxX < Y)) {
Console.WriteLine("No War");
return;
}
Console.WriteLine("War");
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
var inputNMXY =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var maxX = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Max();
var minY = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Min();
var X = inputNMXY[2];
var Y = inputNMXY[3];
if ((X <= Y) && (maxX < minY) && (X < minY) && (maxX < Y)) {
Console.WriteLine("No War");
return;
}
Console.WriteLine("War");
}
}
|
[["-", 31, 16, 31, 16, 31, 23, 0, 16, 17, 18], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 19], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 17, 19], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 17, 18]]
| 8
| 183
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var S = sc.ReadStr();
var T = sc.ReadStr();
var map = new HashMap<char, char>();
for (int i = 0; i < S.Length; i++) {
if (map[S[i]] != 0 && map[S[i]] != T[i]) {
Console.WriteLine("No");
return;
}
map[S[i]] = T[i];
}
S = new string(S.Distinct().ToArray());
T = new string(T.Distinct().ToArray());
if (S.Length != T.Length) {
Console.WriteLine("No");
} else {
Console.WriteLine("OK");
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
class HashMap<K, V> : Dictionary<K, V>
where V : new() {
private V DefaltValue = new V();
public HashMap() {}
public HashMap(V defaultValue) { this.DefaltValue = new V(); }
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
}
set { base[i] = value; }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var S = sc.ReadStr();
var T = sc.ReadStr();
var map = new HashMap<char, char>();
for (int i = 0; i < S.Length; i++) {
if (map[S[i]] != 0 && map[S[i]] != T[i]) {
Console.WriteLine("No");
return;
}
map[S[i]] = T[i];
}
S = new string(S.Distinct().ToArray());
T = new string(T.Distinct().ToArray());
if (S.Length != T.Length) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
class HashMap<K, V> : Dictionary<K, V>
where V : new() {
private V DefaltValue = new V();
public HashMap() {}
public HashMap(V defaultValue) { this.DefaltValue = new V(); }
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue;
}
set { base[i] = value; }
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 808
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Program {
static void Main() {
string[] ST = { ReadLine(), ReadLine() };
string S = ST[0];
string T = ST[1];
Dictionary<char, List<int>> charMapS = new Dictionary<char, List<int>>();
Dictionary<char, List<int>> charMapT = new Dictionary<char, List<int>>();
for (int i = 0; i < S.Length; i++) {
if (charMapS.ContainsKey(S[i]))
charMapS[S[i]].Add(i);
else
charMapS.Add(S[i], new List<int>() { 1 });
}
for (int i = 0; i < T.Length; i++) {
if (charMapT.ContainsKey(T[i]))
charMapT[T[i]].Add(i);
else
charMapT.Add(T[i], new List<int>() { 1 });
}
foreach (var item in charMapS) {
char c = T[item.Value[0]];
for (int i = 1; i < item.Value.Count; i++) {
if (T[item.Value[i]] != c) {
WriteLine("No");
ReadLine();
return;
}
}
}
foreach (var item in charMapT) {
char c = S[item.Value[0]];
for (int i = 1; i < item.Value.Count; i++) {
if (S[item.Value[i]] != c) {
WriteLine("No");
ReadLine();
return;
}
}
}
WriteLine("Yes");
ReadLine();
}
#region Reader
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrN() { return Console.ReadLine().Split(' '); }
static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); }
static int[] ReadIntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); }
static long[] ReadLongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
static long[,] ReadLongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = ReadLongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
static Tuple<string, string>[] ReadTupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = ReadStrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<long, long>[] ReadTupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<int, int>[] ReadTupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = ReadIntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<double, double>[] ReadTupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
static Dictionary<int, HashSet<int>> ReadAdjacencyList(int N, int M) {
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 = ReadIntN();
dict[ab[0]].Add(ab[1]);
dict[ab[1]].Add(ab[0]);
}
return dict;
}
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Program {
static void Main() {
string[] ST = { ReadLine(), ReadLine() };
string S = ST[0];
string T = ST[1];
Dictionary<char, List<int>> charMapS = new Dictionary<char, List<int>>();
Dictionary<char, List<int>> charMapT = new Dictionary<char, List<int>>();
for (int i = 0; i < S.Length; i++) {
if (charMapS.ContainsKey(S[i]))
charMapS[S[i]].Add(i);
else
charMapS.Add(S[i], new List<int>() { i });
}
for (int i = 0; i < T.Length; i++) {
if (charMapT.ContainsKey(T[i]))
charMapT[T[i]].Add(i);
else
charMapT.Add(T[i], new List<int>() { i });
}
foreach (var item in charMapS) {
char c = T[item.Value[0]];
for (int i = 1; i < item.Value.Count; i++) {
if (T[item.Value[i]] != c) {
WriteLine("No");
ReadLine();
return;
}
}
}
foreach (var item in charMapT) {
char c = S[item.Value[0]];
for (int i = 1; i < item.Value.Count; i++) {
if (S[item.Value[i]] != c) {
WriteLine("No");
ReadLine();
return;
}
}
}
WriteLine("Yes");
ReadLine();
}
#region Reader
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrN() { return Console.ReadLine().Split(' '); }
static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); }
static int[] ReadIntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); }
static long[] ReadLongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
static long[,] ReadLongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = ReadLongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
static Tuple<string, string>[] ReadTupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = ReadStrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<long, long>[] ReadTupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<int, int>[] ReadTupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = ReadIntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<double, double>[] ReadTupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
static Dictionary<int, HashSet<int>> ReadAdjacencyList(int N, int M) {
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 = ReadIntN();
dict[ab[0]].Add(ab[1]);
dict[ab[1]].Add(ab[0]);
}
return dict;
}
#endregion
}
|
[["-", 3, 4, 0, 28, 0, 230, 10, 229, 0, 203], ["+", 3, 4, 0, 28, 0, 230, 10, 229, 0, 22]]
| 8
| 1,164
| 4
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
public static class Program {
static void Main() {
char[] s = Console.ReadLine().ToCharArray();
char[] t = Console.ReadLine().ToCharArray();
Dictionary<char, char> S_pair = new Dictionary<char, char>();
Dictionary<char, char> T_pair = new Dictionary<char, char>();
String ans = "Yes";
for (int i = 0; i < s.Length; i++) {
if (S_pair.ContainsKey(s[i]) && S_pair[s[i]] != t[i]) {
ans = "No";
return;
} else if (T_pair.ContainsKey(t[i]) && T_pair[t[i]] != s[i]) {
ans = "No";
return;
} else {
S_pair[s[i]] = t[i];
T_pair[t[i]] = s[i];
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
public static class Program {
static void Main() {
char[] s = Console.ReadLine().ToCharArray();
char[] t = Console.ReadLine().ToCharArray();
Dictionary<char, char> S_pair = new Dictionary<char, char>();
Dictionary<char, char> T_pair = new Dictionary<char, char>();
String ans = "Yes";
for (int i = 0; i < s.Length; i++) {
if (S_pair.ContainsKey(s[i]) && S_pair[s[i]] != t[i]) {
ans = "No";
} else if (T_pair.ContainsKey(t[i]) && T_pair[t[i]] != s[i]) {
ans = "No";
} else {
S_pair[s[i]] = t[i];
T_pair[t[i]] = s[i];
}
}
Console.WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 75, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 231
| 4
|
using System;
using System.Collections.Generic;
namespace ABC110_C {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
var t = Console.ReadLine();
var dics = new Dictionary<char, char>();
var dict = new Dictionary<char, char>();
for (int i = 0; i < s.Length; i++) {
if (dics.ContainsKey(s[i]) && dics[s[i]] == t[i])
continue;
else if (dics.ContainsKey(s[i]) && dict[s[i]] != t[i]) {
Console.WriteLine("No");
return;
}
if (dict.ContainsKey(t[i]) && dict[t[i]] == s[i])
continue;
else if (dict.ContainsKey(t[i]) && dict[t[i]] != s[i]) {
Console.WriteLine("No");
return;
}
dics.Add(s[i], t[i]);
dict.Add(t[i], s[i]);
}
Console.WriteLine("Yes");
}
}
}
|
using System;
using System.Collections.Generic;
namespace ABC110_C {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
var t = Console.ReadLine();
var dics = new Dictionary<char, char>();
var dict = new Dictionary<char, char>();
for (int i = 0; i < s.Length; i++) {
if (dics.ContainsKey(s[i]) && dics[s[i]] == t[i])
continue;
else if (dics.ContainsKey(s[i]) && dics[s[i]] != t[i]) {
Console.WriteLine("No");
return;
}
if (dict.ContainsKey(t[i]) && dict[t[i]] == s[i])
continue;
else if (dict.ContainsKey(t[i]) && dict[t[i]] != s[i]) {
Console.WriteLine("No");
return;
}
dics.Add(s[i], t[i]);
dict.Add(t[i], s[i]);
}
Console.WriteLine("Yes");
}
}
}
|
[["-", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 16, 31, 204, 205, 22]]
| 8
| 262
| 2
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC110D {
class Program {
static int n;
static void Main(string[] args) {
n = RInt;
var m = RInt;
var divs = Factors(m);
Mlong ans = 1;
Mlong.nCkInit(n + 100);
foreach (var d in divs) {
ans *= Mlong.nCk(d.Value + n - 1, d.Value);
}
if (m == 1)
ans = 1;
Console.WriteLine(ans);
}
/// <summary>
/// 自然数nの素因数分解 O(√n)
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static SortedDictionary<long, int> Factors(long n) {
SortedDictionary<long, int> ret = new SortedDictionary<long, int>();
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
if (ret.ContainsKey(i))
ret[i]++;
else
ret.Add(i, 1);
n /= i;
}
}
if (n != 1)
ret[n]++;
return ret;
}
}
/// <summary>
/// Mod計算型 若干遅いかも
/// </summary>
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
static class Debug {
static public void Draw2D<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 ABC110D {
class Program {
static int n;
static void Main(string[] args) {
n = RInt;
var m = RInt;
var divs = Factors(m);
Mlong ans = 1;
Mlong.nCkInit(n + 100);
foreach (var d in divs) {
ans *= Mlong.nCk(d.Value + n - 1, d.Value);
}
if (m == 1)
ans = 1;
Console.WriteLine(ans);
}
/// <summary>
/// 自然数nの素因数分解 O(√n)
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static SortedDictionary<long, int> Factors(long n) {
SortedDictionary<long, int> ret = new SortedDictionary<long, int>();
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
if (ret.ContainsKey(i))
ret[i]++;
else
ret.Add(i, 1);
n /= i;
}
}
if (n != 1)
ret.Add(n, 1);
return ret;
}
}
/// <summary>
/// Mod計算型 若干遅いかも
/// </summary>
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
static class Debug {
static public void Draw2D<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
}
}
}
|
[["-", 64, 1, 0, 223, 0, 204, 206, 207, 0, 70], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["-", 64, 1, 0, 223, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 21], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25]]
| 8
| 1,300
| 9
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC110.D(); }
class ABC110 {
public static void C() {
var S = ReadStr();
var T = ReadStr();
var dict1 = new Dictionary<char, char>();
var dict2 = new Dictionary<char, char>();
for (int i = 0; i < S.Length; ++i) {
var s = S[i];
var t = T[i];
if (dict1.ContainsKey(s)) {
if (dict1[s] != t) {
Console.WriteLine("No");
return;
}
} else {
dict1.Add(s, t);
}
if (dict2.ContainsKey(t)) {
if (dict2[t] != s) {
Console.WriteLine("No");
return;
}
} else {
dict2.Add(t, s);
}
}
Console.WriteLine("Yes");
}
public static void D() {
var nm = ReadLongN();
var N = (int)nm[0];
var M = nm[1];
var fact = Util.Factorize(M);
var comb = Util.Combin(N * 2, Util.P);
long prod = 1;
foreach (var kvp in fact) {
var v = kvp.Value;
prod = (prod * comb(v + N - 1, v)) % Util.P;
}
Console.WriteLine(prod);
}
}
class Util {
public static readonly long P = 1000000007;
public static long Inverse(long a, long 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 static long[] Facts(int n, long p) {
var facts = new long[n + 1];
facts[0] = 1;
for (int i = 1; i <= n; ++i) {
facts[i] = (i * facts[i - 1]) % p;
}
return facts;
}
public static Func<int, int, long> Combin(int n, long P) {
var fact = Facts(n, P);
var inv = fact.Select(x => Inverse(x, P)).ToArray();
return (N, M) => {
if (N < 0 || N < M || M < 0) {
return 0;
}
return (((fact[N] * inv[M]) % P) * inv[N - M]) % P;
};
}
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;
}
}
#region Reader
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrN() { return Console.ReadLine().Split(' '); }
static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); }
static int[] ReadIntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); }
static long[] ReadLongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
static long[,] ReadLongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = ReadLongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
static Tuple<string, string>[] ReadTupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = ReadStrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<long, long>[] ReadTupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<int, int>[] ReadTupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = ReadIntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<double, double>[] ReadTupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
static Dictionary<int, HashSet<int>> ReadAdjacencyList(int N, int M) {
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 = ReadIntN();
dict[ab[0]].Add(ab[1]);
dict[ab[1]].Add(ab[0]);
}
return dict;
}
#endregion
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { ABC110.D(); }
class ABC110 {
public static void C() {
var S = ReadStr();
var T = ReadStr();
var dict1 = new Dictionary<char, char>();
var dict2 = new Dictionary<char, char>();
for (int i = 0; i < S.Length; ++i) {
var s = S[i];
var t = T[i];
if (dict1.ContainsKey(s)) {
if (dict1[s] != t) {
Console.WriteLine("No");
return;
}
} else {
dict1.Add(s, t);
}
if (dict2.ContainsKey(t)) {
if (dict2[t] != s) {
Console.WriteLine("No");
return;
}
} else {
dict2.Add(t, s);
}
}
Console.WriteLine("Yes");
}
public static void D() {
var nm = ReadLongN();
var N = (int)nm[0];
var M = nm[1];
var fact = Util.Factorize(M);
var comb = Util.Combin(N * 2 + 1000, Util.P);
long prod = 1;
foreach (var kvp in fact) {
var v = kvp.Value;
prod = (prod * comb(v + N - 1, v)) % Util.P;
}
Console.WriteLine(prod);
}
}
class Util {
public static readonly long P = 1000000007;
public static long Inverse(long a, long 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 static long[] Facts(int n, long p) {
var facts = new long[n + 1];
facts[0] = 1;
for (int i = 1; i <= n; ++i) {
facts[i] = (i * facts[i - 1]) % p;
}
return facts;
}
public static Func<int, int, long> Combin(int n, long P) {
var fact = Facts(n, P);
var inv = fact.Select(x => Inverse(x, P)).ToArray();
return (N, M) => {
if (N < 0 || N < M || M < 0) {
return 0;
}
return (((fact[N] * inv[M]) % P) * inv[N - M]) % P;
};
}
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;
}
}
#region Reader
static string ReadStr() { return Console.ReadLine(); }
static string[] ReadStrN() { return Console.ReadLine().Split(' '); }
static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); }
static int[] ReadIntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); }
static long[] ReadLongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
static long[,] ReadLongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = ReadLongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
static Tuple<string, string>[] ReadTupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = ReadStrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<long, long>[] ReadTupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<int, int>[] ReadTupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = ReadIntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
static Tuple<double, double>[] ReadTupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = ReadLongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
static Dictionary<int, HashSet<int>> ReadAdjacencyList(int N, int M) {
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 = ReadIntN();
dict[ab[0]].Add(ab[1]);
dict[ab[1]].Add(ab[0]);
}
return dict;
}
#endregion
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 1,522
| 2
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
var s = sc.Ia;
Cb r = new Cb(s[0] << 1);
var pf = new Pf(s[1]);
Mint ans = 1;
pf.Get((k, v) => { ans *= r.C1(s[0] + v - 1, v); });
Console.WriteLine("{0}", ans);
}
}
public class Pf {
public Dictionary<long, int> hs = new Dictionary<long, int>();
public Pf(long n) {
if (n % 2 == 0) {
int p = 0;
while ((n & 1) == 0) {
n >>= 1;
p++;
}
hs.Add(2, p);
}
var q = (int)Sqrt(n) + 1;
for (int i = 3; n != 1 && i < q; i += 2) {
if (n % i == 0) {
int p = 0;
while (n % i == 0) {
n /= i;
p++;
}
q = (int)Sqrt(n) + 1;
hs.Add(i, p);
}
}
if (n != 1) {
hs.Add(n, 1);
}
}
public void Get(Action<long, int> f) {
foreach (var e in hs) {
f(e.Key, e.Value);
}
}
}
public class Cb {
private const int mod = (int)1e9 + 7;
public long[] r;
public Cb(int n) {
r = new long[n];
r[0] = 1;
for (int i = 1; i < n; i++) {
r[i] = (r[i - 1] * i) % mod;
}
}
public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; }
public long C2(long n, long k) {
long l = 1;
n %= mod;
for (int i = 1; i <= k; i++) {
l = (l * (n - i + 1)) % mod;
l = (l * Mi(i)) % mod;
}
return l;
}
public long P1(long n, long k) {
return n < k ? 0 : (r[n] * Mi(r[n - k])) % mod;
}
public long Mi(long a) {
a = (a + mod) % mod;
long b = mod, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
a ^= b;
b ^= a;
a ^= b;
u -= t * v;
u ^= v;
v ^= u;
u ^= v;
}
u %= mod;
if (u < 0) {
u += mod;
}
return u % mod;
}
}
public struct Mint {
const int mod = (int)1e9 + 7;
private long d;
public Mint(long d) { this.d = d; }
public static implicit operator Mint(long d) { return new Mint(d % mod); }
public static explicit operator long(Mint d) { return d.d; }
public override string ToString() { return d.ToString(); }
public static Mint operator +(Mint a, long b) {
a.d = (a.d + b) % mod;
return a;
}
public static Mint operator +(Mint a, Mint b) {
a.d = (a.d + b.d) % mod;
return a;
}
public static Mint operator -(Mint a, long b) {
a.d = (mod + a.d - b) % mod;
return a;
}
public static Mint operator -(Mint a, Mint b) {
a.d = (mod + a.d - b.d) % mod;
return a;
}
public static Mint operator *(Mint a, long b) {
a.d = (a.d * b) % mod;
return a;
}
public static Mint operator *(Mint a, Mint b) {
a.d = (a.d * b.d) % mod;
return a;
}
public static Mint operator /(Mint a, long b) {
a.d = (a.d * Mi(b)) % mod;
return a;
}
public static Mint operator /(Mint a, Mint b) {
a.d = (a.d * Mi(b.d)) % mod;
return a;
}
private static long Mi(long a) {
a = (a + mod) % mod;
long b = mod, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
a ^= b;
b ^= a;
a ^= b;
u -= t * v;
u ^= v;
v ^= u;
u ^= v;
}
u %= mod;
if (u < 0) {
u += mod;
}
return u % mod;
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
double.Parse);
}
public double[] Da3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
static void Main() {
Sc sc = new Sc();
var s = sc.Ia;
Cb r = new Cb(s[0] + 45);
var pf = new Pf(s[1]);
Mint ans = 1;
pf.Get((k, v) => { ans *= r.C1(s[0] + v - 1, v); });
Console.WriteLine("{0}", ans);
}
}
public class Pf {
public Dictionary<long, int> hs = new Dictionary<long, int>();
public Pf(long n) {
if (n % 2 == 0) {
int p = 0;
while ((n & 1) == 0) {
n >>= 1;
p++;
}
hs.Add(2, p);
}
var q = (int)Sqrt(n) + 1;
for (int i = 3; n != 1 && i < q; i += 2) {
if (n % i == 0) {
int p = 0;
while (n % i == 0) {
n /= i;
p++;
}
q = (int)Sqrt(n) + 1;
hs.Add(i, p);
}
}
if (n != 1) {
hs.Add(n, 1);
}
}
public void Get(Action<long, int> f) {
foreach (var e in hs) {
f(e.Key, e.Value);
}
}
}
public class Cb {
private const int mod = (int)1e9 + 7;
public long[] r;
public Cb(int n) {
r = new long[n];
r[0] = 1;
for (int i = 1; i < n; i++) {
r[i] = (r[i - 1] * i) % mod;
}
}
public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; }
public long C2(long n, long k) {
long l = 1;
n %= mod;
for (int i = 1; i <= k; i++) {
l = (l * (n - i + 1)) % mod;
l = (l * Mi(i)) % mod;
}
return l;
}
public long P1(long n, long k) {
return n < k ? 0 : (r[n] * Mi(r[n - k])) % mod;
}
public long Mi(long a) {
a = (a + mod) % mod;
long b = mod, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
a ^= b;
b ^= a;
a ^= b;
u -= t * v;
u ^= v;
v ^= u;
u ^= v;
}
u %= mod;
if (u < 0) {
u += mod;
}
return u % mod;
}
}
public struct Mint {
const int mod = (int)1e9 + 7;
private long d;
public Mint(long d) { this.d = d; }
public static implicit operator Mint(long d) { return new Mint(d % mod); }
public static explicit operator long(Mint d) { return d.d; }
public override string ToString() { return d.ToString(); }
public static Mint operator +(Mint a, long b) {
a.d = (a.d + b) % mod;
return a;
}
public static Mint operator +(Mint a, Mint b) {
a.d = (a.d + b.d) % mod;
return a;
}
public static Mint operator -(Mint a, long b) {
a.d = (mod + a.d - b) % mod;
return a;
}
public static Mint operator -(Mint a, Mint b) {
a.d = (mod + a.d - b.d) % mod;
return a;
}
public static Mint operator *(Mint a, long b) {
a.d = (a.d * b) % mod;
return a;
}
public static Mint operator *(Mint a, Mint b) {
a.d = (a.d * b.d) % mod;
return a;
}
public static Mint operator /(Mint a, long b) {
a.d = (a.d * Mi(b)) % mod;
return a;
}
public static Mint operator /(Mint a, Mint b) {
a.d = (a.d * Mi(b.d)) % mod;
return a;
}
private static long Mi(long a) {
a = (a + mod) % mod;
long b = mod, u = 1, v = 0;
while (b > 0) {
long t = a / b;
a -= t * b;
a ^= b;
b ^= a;
a ^= b;
u -= t * v;
u ^= v;
v ^= u;
u ^= v;
}
u %= mod;
if (u < 0) {
u += mod;
}
return u % mod;
}
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
int.Parse);
}
public int[] Ia3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
long.Parse);
}
public long[] La3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(int a) {
return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(),
double.Parse);
}
public double[] Da3(bool a, int b, bool c, int d) {
return Array.ConvertAll(((a ? b.ToString() + " " : "") +
Console.ReadLine() + (c ? " " + d.ToString() : ""))
.Split(),
double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
[["-", 0, 230, 3, 4, 0, 28, 0, 16, 17, 151], ["-", 0, 230, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 2,112
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
var cin = new Scanner2();
int n = cin.Int();
int m = cin.Int();
var factors = GetPrimeFactors(m);
if (factors.Count == 0) {
Console.WriteLine(0);
return;
}
long max = factors.Max(x => x.Value);
ModCounting.InitializeFactorial(n + max);
ModInt ans = 1;
foreach (long key in factors.Keys) {
ans *= ModCounting.HomogeneousProduct(n, factors[key]);
}
Console.WriteLine(ans.Value);
}
public static Dictionary<long, long> GetPrimeFactors(long value) {
var factors = new Dictionary<long, long>();
for (long i = 2; i * i <= value; ++i) {
while (value % i == 0) {
if (factors.ContainsKey(i) == false) {
factors[i] = 1;
} else {
factors[i] += 1;
}
value /= i;
}
}
if (value != 1) {
factors[value] = 1;
}
return factors;
}
}
public struct ModInt {
public static long Mod { get; set; } = (long)1e9 + 7;
public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); }
public static ModInt Pow(long value, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, value = value * value % Mod) {
if ((k & 1) == 1) {
ret = ret * value % Mod;
}
}
return new ModInt(ret);
}
public static ModInt Inverse(ModInt value) { return Pow(value, Mod - 2); }
public long Value;
public ModInt(long value) {
value %= Mod;
if (value < 0) {
value += Mod;
}
Value = value;
}
public static ModInt operator +(ModInt lhs, ModInt rhs) {
lhs.Value += rhs.Value;
if (lhs.Value >= Mod) {
lhs.Value -= Mod;
}
return lhs;
}
public static ModInt operator -(ModInt lhs, ModInt rhs) {
lhs.Value -= rhs.Value;
if (lhs.Value < 0) {
lhs.Value += Mod;
}
return lhs;
}
public static ModInt operator *(ModInt lhs, ModInt rhs) {
return new ModInt(lhs.Value * rhs.Value % Mod);
}
public static ModInt operator /(ModInt lhs, ModInt rhs) {
long exp = Mod - 2;
while (exp > 0) {
if (exp % 2 > 0) {
lhs *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return lhs;
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0) {
n += Mod;
}
return new ModInt(n);
}
public override string ToString() { return Value.ToString(); }
}
public static class ModCounting {
private static long p_;
private static long[] factorial_;
private static long[] inverseFactorial_;
private static long[] inverse_;
public static void InitializeFactorial(long max, long p = 1000000007) {
p_ = p;
factorial_ = new long[max + 1];
inverseFactorial_ = new long[max + 1];
inverse_ = new long[max + 1];
factorial_[0] = factorial_[1] = 1;
inverseFactorial_[0] = inverseFactorial_[1] = 1;
inverse_[1] = 1;
for (int i = 2; i <= max; i++) {
factorial_[i] = factorial_[i - 1] * i % p;
inverse_[i] = p - inverse_[p % i] * (p / i) % p;
inverseFactorial_[i] = inverseFactorial_[i - 1] * inverse_[i] % p;
}
}
public static long Factorial(long n) {
if (n < 0) {
return 0;
}
return factorial_[n];
}
public static long InverseFactorial(long n) {
if (n < 0) {
return 0;
}
return inverseFactorial_[n];
}
public static long Inverse(long n) {
if (n < 0) {
return 0;
}
return inverse_[n];
}
public static long Permutation(long n, long k) {
if (n < k || (n < 0 || k < 0)) {
return 0;
}
return factorial_[n] * inverseFactorial_[n - k] % p_;
}
public static long RepeatedPermutation(long n, long k) {
long ret = 1;
for (k %= p_ - 1; k > 0; k >>= 1, n = n * n % p_) {
if ((k & 1) == 1) {
ret = ret * n % p_;
}
}
return ret;
}
public static long Combination(long n, long k) {
if (n < k || (n < 0 || k < 0)) {
return 0;
}
return factorial_[n] *
(inverseFactorial_[k] * inverseFactorial_[n - k] % p_) % p_;
}
public static long HomogeneousProduct(long n, long k) {
if (n < 0 || k < 0) {
return 0;
}
return Combination(n + k - 1, k);
}
}
public class Scanner2 {
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private readonly Func<string> reader_;
private string[] buf_;
private int index_;
public Scanner2(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;
}
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_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
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.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
var cin = new Scanner2();
int n = cin.Int();
int m = cin.Int();
var factors = GetPrimeFactors(m);
if (factors.Count == 0) {
Console.WriteLine(1);
return;
}
long max = factors.Max(x => x.Value);
ModCounting.InitializeFactorial(n + max);
ModInt ans = 1;
foreach (long key in factors.Keys) {
ans *= ModCounting.HomogeneousProduct(n, factors[key]);
}
Console.WriteLine(ans.Value);
}
public static Dictionary<long, long> GetPrimeFactors(long value) {
var factors = new Dictionary<long, long>();
for (long i = 2; i * i <= value; ++i) {
while (value % i == 0) {
if (factors.ContainsKey(i) == false) {
factors[i] = 1;
} else {
factors[i] += 1;
}
value /= i;
}
}
if (value != 1) {
factors[value] = 1;
}
return factors;
}
}
public struct ModInt {
public static long Mod { get; set; } = (long)1e9 + 7;
public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); }
public static ModInt Pow(long value, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, value = value * value % Mod) {
if ((k & 1) == 1) {
ret = ret * value % Mod;
}
}
return new ModInt(ret);
}
public static ModInt Inverse(ModInt value) { return Pow(value, Mod - 2); }
public long Value;
public ModInt(long value) {
value %= Mod;
if (value < 0) {
value += Mod;
}
Value = value;
}
public static ModInt operator +(ModInt lhs, ModInt rhs) {
lhs.Value += rhs.Value;
if (lhs.Value >= Mod) {
lhs.Value -= Mod;
}
return lhs;
}
public static ModInt operator -(ModInt lhs, ModInt rhs) {
lhs.Value -= rhs.Value;
if (lhs.Value < 0) {
lhs.Value += Mod;
}
return lhs;
}
public static ModInt operator *(ModInt lhs, ModInt rhs) {
return new ModInt(lhs.Value * rhs.Value % Mod);
}
public static ModInt operator /(ModInt lhs, ModInt rhs) {
long exp = Mod - 2;
while (exp > 0) {
if (exp % 2 > 0) {
lhs *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return lhs;
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0) {
n += Mod;
}
return new ModInt(n);
}
public override string ToString() { return Value.ToString(); }
}
public static class ModCounting {
private static long p_;
private static long[] factorial_;
private static long[] inverseFactorial_;
private static long[] inverse_;
public static void InitializeFactorial(long max, long p = 1000000007) {
p_ = p;
factorial_ = new long[max + 1];
inverseFactorial_ = new long[max + 1];
inverse_ = new long[max + 1];
factorial_[0] = factorial_[1] = 1;
inverseFactorial_[0] = inverseFactorial_[1] = 1;
inverse_[1] = 1;
for (int i = 2; i <= max; i++) {
factorial_[i] = factorial_[i - 1] * i % p;
inverse_[i] = p - inverse_[p % i] * (p / i) % p;
inverseFactorial_[i] = inverseFactorial_[i - 1] * inverse_[i] % p;
}
}
public static long Factorial(long n) {
if (n < 0) {
return 0;
}
return factorial_[n];
}
public static long InverseFactorial(long n) {
if (n < 0) {
return 0;
}
return inverseFactorial_[n];
}
public static long Inverse(long n) {
if (n < 0) {
return 0;
}
return inverse_[n];
}
public static long Permutation(long n, long k) {
if (n < k || (n < 0 || k < 0)) {
return 0;
}
return factorial_[n] * inverseFactorial_[n - k] % p_;
}
public static long RepeatedPermutation(long n, long k) {
long ret = 1;
for (k %= p_ - 1; k > 0; k >>= 1, n = n * n % p_) {
if ((k & 1) == 1) {
ret = ret * n % p_;
}
}
return ret;
}
public static long Combination(long n, long k) {
if (n < k || (n < 0 || k < 0)) {
return 0;
}
return factorial_[n] *
(inverseFactorial_[k] * inverseFactorial_[n - k] % p_) % p_;
}
public static long HomogeneousProduct(long n, long k) {
if (n < 0 || k < 0) {
return 0;
}
return Combination(n + k - 1, k);
}
}
public class Scanner2 {
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private readonly Func<string> reader_;
private string[] buf_;
private int index_;
public Scanner2(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;
}
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_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
public void Save(string text) {
if (string.IsNullOrWhiteSpace(filePath_)) {
return;
}
File.WriteAllText(filePath_ + "_output.txt", text);
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 1,591
| 2
|
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;
internal partial class Solver {
List<int> Factorize(int x) {
var r = new List<int>();
for (int i = 2; i * i < x; i++) {
int cnt = 0;
while (x % i == 0) {
x /= i;
cnt++;
}
if (cnt > 0)
r.Add(cnt);
}
if (x > 1)
r.Add(1);
return r;
}
public void Run() {
var n = ni();
var m = ni();
int mod = 1000000007;
var f = Factorize(m);
var b = new Binomial(100000 * 2, mod);
long ans = 1;
foreach (var x in f) {
ans *= b.H(x, n);
ans %= mod;
}
cout.WriteLine(ans);
}
}
public class Binomial {
private readonly long[] factorial;
private readonly long[] inverseFactorial;
private readonly long[] inverse;
private readonly int mod;
public Binomial(int size, int primeMod) {
size++;
factorial = new long[size];
inverseFactorial = new long[size];
inverse = new long[size];
mod = primeMod;
Setup(size);
}
private void Setup(int size) {
factorial[0] = factorial[1] = 1;
inverseFactorial[0] = inverseFactorial[1] = 1;
inverse[1] = 1;
for (int i = 2; i < size; i++) {
factorial[i] = factorial[i - 1] * i % mod;
inverse[i] = (mod - (mod / i) * inverse[mod % i] % mod);
inverseFactorial[i] = inverseFactorial[i - 1] * inverse[i] % mod;
}
}
private long C(int s, int t) {
if (s < 0 || t < 0 || s < t) {
return 0;
}
if (t == 0 || s == t) {
return 1;
}
if (s >= mod) {
return C(s % mod, t % mod) * C(s / mod, t / mod) % mod; // Lucas' theorem
}
return factorial[s] * inverseFactorial[t] % mod * inverseFactorial[s - t] %
mod;
}
public long this[int s, int t] {
get { return C(s, t); }
}
public long P(int s, int t) {
if (s < 0 || t < 0 || s < t)
return 0;
return factorial[s] * inverseFactorial[s - t] % mod;
}
public long H(int s, int t) {
if (s < 0 || t < 0)
return 0;
if (s == 0 && t == 0)
return 1;
return C(s + t - 1, s);
}
public long H1(int s, int t) { return H(s - t, t); }
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#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 });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
internal static class LinqPadExtension {
[Conditional("DEBUG")]
public static void Dump<T>(this T obj) {
#if DEBUG
LINQPad.Extensions.Dump(obj);
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
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 (TokenQueue.Count == 0) {
if (!StockTokens()) {
throw new InvalidOperationException();
}
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0) {
return true;
}
return StockTokens();
}
private static readonly char[] _separator = new[] { ' ', '\t' };
private bool StockTokens() {
while (true) {
string line = Reader.ReadLine();
if (line == null) {
return false;
}
string[] tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0) {
continue;
}
foreach (string token in tokens) {
TokenQueue.Enqueue(token);
}
return true;
}
}
}
|
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;
internal partial class Solver {
List<int> Factorize(int x) {
var r = new List<int>();
for (int i = 2; i * i <= x; i++) {
int cnt = 0;
while (x % i == 0) {
x /= i;
cnt++;
}
if (cnt > 0)
r.Add(cnt);
}
if (x > 1)
r.Add(1);
return r;
}
public void Run() {
var n = ni();
var m = ni();
int mod = 1000000007;
var f = Factorize(m);
var b = new Binomial(100000 * 2, mod);
long ans = 1;
foreach (var x in f) {
ans *= b.H(x, n);
ans %= mod;
}
cout.WriteLine(ans);
}
}
public class Binomial {
private readonly long[] factorial;
private readonly long[] inverseFactorial;
private readonly long[] inverse;
private readonly int mod;
public Binomial(int size, int primeMod) {
size++;
factorial = new long[size];
inverseFactorial = new long[size];
inverse = new long[size];
mod = primeMod;
Setup(size);
}
private void Setup(int size) {
factorial[0] = factorial[1] = 1;
inverseFactorial[0] = inverseFactorial[1] = 1;
inverse[1] = 1;
for (int i = 2; i < size; i++) {
factorial[i] = factorial[i - 1] * i % mod;
inverse[i] = (mod - (mod / i) * inverse[mod % i] % mod);
inverseFactorial[i] = inverseFactorial[i - 1] * inverse[i] % mod;
}
}
private long C(int s, int t) {
if (s < 0 || t < 0 || s < t) {
return 0;
}
if (t == 0 || s == t) {
return 1;
}
if (s >= mod) {
return C(s % mod, t % mod) * C(s / mod, t / mod) % mod; // Lucas' theorem
}
return factorial[s] * inverseFactorial[t] % mod * inverseFactorial[s - t] %
mod;
}
public long this[int s, int t] {
get { return C(s, t); }
}
public long P(int s, int t) {
if (s < 0 || t < 0 || s < t)
return 0;
return factorial[s] * inverseFactorial[s - t] % mod;
}
public long H(int s, int t) {
if (s < 0 || t < 0)
return 0;
if (s == 0 && t == 0)
return 1;
return C(s + t - 1, s);
}
public long H1(int s, int t) { return H(s - t, t); }
}
// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
public static void Main(string[] args) {
#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 });
new Solver(Console.In, Console.Out).Run();
Console.Out.Flush();
#endif
}
#pragma warning disable IDE0052
private readonly TextReader cin;
private readonly TextWriter cout;
#pragma warning restore IDE0052
public Solver(TextReader reader, TextWriter writer) : base(reader) {
cin = reader;
cout = writer;
}
public Solver(string input, TextWriter writer)
: this(new StringReader(input), writer) {}
#pragma warning disable IDE1006
#pragma warning disable IDE0051
private int ni() { return NextInt(); }
private int[] ni(int n) { return NextIntArray(n); }
private long nl() { return NextLong(); }
private long[] nl(int n) { return NextLongArray(n); }
private double nd() { return NextDouble(); }
private double[] nd(int n) { return NextDoubleArray(n); }
private string ns() { return Next(); }
private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}
internal static class LinqPadExtension {
[Conditional("DEBUG")]
public static void Dump<T>(this T obj) {
#if DEBUG
LINQPad.Extensions.Dump(obj);
#endif
}
}
public class Scanner {
private readonly TextReader Reader;
private readonly Queue<string> TokenQueue = new Queue<string>();
private readonly CultureInfo ci = CultureInfo.InvariantCulture;
public Scanner() : this(Console.In) {}
public Scanner(TextReader reader) { Reader = reader; }
public int NextInt() { return int.Parse(Next(), ci); }
public long NextLong() { return long.Parse(Next(), ci); }
public double NextDouble() { return double.Parse(Next(), ci); }
public string[] NextArray(int size) {
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 (TokenQueue.Count == 0) {
if (!StockTokens()) {
throw new InvalidOperationException();
}
}
return TokenQueue.Dequeue();
}
public bool HasNext() {
if (TokenQueue.Count > 0) {
return true;
}
return StockTokens();
}
private static readonly char[] _separator = new[] { ' ', '\t' };
private bool StockTokens() {
while (true) {
string line = Reader.ReadLine();
if (line == null) {
return false;
}
string[] tokens =
line.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0) {
continue;
}
foreach (string token in tokens) {
TokenQueue.Enqueue(token);
}
return true;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 1,530
| 2
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static bool[] isPrimes = makePrimeList(100000); // i-1が素数かどうか
static long factMax = 200000; // nCkにおけるnの最大値
static long[] factorials = new long[factMax + 1]; // i!(mod p)を先にメモ
static long[] factorialRs = new long[factMax + 1]; // i!^-1(mod p), pは素数
static void Main() {
long p = 1000000007;
string[] input = Console.ReadLine().Split(' ');
long n = long.Parse(input[0]);
int m = int.Parse(input[1]);
long answer = 1;
factorials[0] = 1;
factorialRs[factMax] = DivideModFactorial(factMax, p);
for (long i = 1; i <= factMax; i++) {
factorials[i] = (factorials[i - 1] * i) % p; // i!(mod p)
factorialRs[factMax - i] =
(factorialRs[factMax + 1 - i] * (factMax + 1 - i)) %
p; //逆元も先にメモ
}
List<long> factList = Factoring(n);
int countMemo = 0;
for (int i = 0; i < factList.Count(); i++) {
if (i == 0)
countMemo++;
else if (factList[i] == factList[i - 1])
countMemo++;
else {
answer *= factorials[countMemo + (m - 1)];
answer %= p;
answer *= factorialRs[countMemo];
answer %= p;
answer *= factorialRs[m - 1];
answer %= p;
countMemo = 1;
}
}
if (countMemo > 0) {
answer *= factorials[countMemo + (m - 1)];
answer %= p;
answer *= factorialRs[countMemo];
answer %= p;
answer *= factorialRs[m - 1];
answer %= p;
}
// Console.WriteLine(answer+"a");
long answerMulMemo = 0;
if (n > 0) {
for (int i = 0; i <= m; i += 2) {
// Console.WriteLine(answer);
answerMulMemo += Comb(m, i, p);
answerMulMemo %= p;
}
} else {
for (int i = 1; i <= m; i += 2) {
answerMulMemo += Comb(m, i, p);
answerMulMemo %= p;
}
}
// answer *= answerMulMemo;
answer %= p;
Console.WriteLine(answer);
}
static List<long> Factoring(
long
originalNum) { // makePrimeListによるisPrimesを用いて、引数をO(√n)で素因数分解。リストには同じ数も含む。
//例えば1は{},12は{2,2,3},17は{17}を返す。
List<long> answers = new List<long>();
for (long i = 2; i <= Math.Sqrt(originalNum); i++) {
if (!isPrimes[i - 1])
continue; //素数でないとき
else {
while (originalNum % i == 0) {
originalNum /= i;
answers.Add(i);
}
}
}
if (originalNum != 1)
answers.Add(originalNum);
return answers;
}
static bool[] makePrimeList(
long
maxPrime) { //「引数1以上」max以下の素数判定を、エラトステネスの篩を用いてO(n)。
bool[] isPrimes = new bool[maxPrime]; //素数リスト
isPrimes[0] = false; // 1は素数でないのでfalse
for (long i = 1; i < maxPrime; i++)
isPrimes[i] = true; //素数と仮定してtrue
for (long i = 2; i <= Math.Sqrt(maxPrime); i++) {
if (isPrimes[i - 1]) {
for (long j = i * 2; j <= maxPrime; j += i) {
isPrimes[j - 1] = false; //素数でないのでfalse
}
}
}
return isPrimes;
}
static long MathPow(long x, long a) //戻り値はx^a。O(loga)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
}
memo *= memo;
num *= 2;
}
return answer;
}
static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p)。O(loga)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x % p;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
answer %= p;
}
memo *= memo;
memo %= p;
num *= 2;
}
return answer;
}
static long DivideModReverse(long x,
long p) //戻り値はx^-1(mod p), pは素数。O(logp)
{
long answer = DivideMod(x, p - 2, p);
return answer;
}
static long ModFactorial(long x, long p) //戻り値はx!(mod p)
{
long answer = 1;
for (int i = 2; i <= x; i++) {
answer *= i;
answer %= p;
}
return answer;
}
static long DivideModFactorial(long x, long p) //戻り値はx!^-1(mod p), pは素数
{
long answer = 1;
for (long i = x; i >= 2; i--) {
answer *= DivideModReverse(i, p);
answer %= p;
}
return answer;
}
static long Comb(long a, long b, long p) //戻り値は組み合わせC(a,b)のmod p
{
if (a - b < 0)
return 0; //引数a-bが負なら0を返す
long answer = 1;
answer *= factorials[a];
answer %= p;
answer *= factorialRs[a - b];
answer %= p;
answer *= factorialRs[b];
answer %= p;
return answer;
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static bool[] isPrimes = makePrimeList(100000); // i-1が素数かどうか
static long factMax = 200000; // nCkにおけるnの最大値
static long[] factorials = new long[factMax + 1]; // i!(mod p)を先にメモ
static long[] factorialRs = new long[factMax + 1]; // i!^-1(mod p), pは素数
static void Main() {
long p = 1000000007;
string[] input = Console.ReadLine().Split(' ');
long m = long.Parse(input[0]);
int n = int.Parse(input[1]);
long answer = 1;
factorials[0] = 1;
factorialRs[factMax] = DivideModFactorial(factMax, p);
for (long i = 1; i <= factMax; i++) {
factorials[i] = (factorials[i - 1] * i) % p; // i!(mod p)
factorialRs[factMax - i] =
(factorialRs[factMax + 1 - i] * (factMax + 1 - i)) %
p; //逆元も先にメモ
}
List<long> factList = Factoring(n);
int countMemo = 0;
for (int i = 0; i < factList.Count(); i++) {
if (i == 0)
countMemo++;
else if (factList[i] == factList[i - 1])
countMemo++;
else {
answer *= factorials[countMemo + (m - 1)];
answer %= p;
answer *= factorialRs[countMemo];
answer %= p;
answer *= factorialRs[m - 1];
answer %= p;
countMemo = 1;
}
}
if (countMemo > 0) {
answer *= factorials[countMemo + (m - 1)];
answer %= p;
answer *= factorialRs[countMemo];
answer %= p;
answer *= factorialRs[m - 1];
answer %= p;
}
// Console.WriteLine(answer+"a");
long answerMulMemo = 0;
if (n > 0) {
for (int i = 0; i <= m; i += 2) {
// Console.WriteLine(answer);
answerMulMemo += Comb(m, i, p);
answerMulMemo %= p;
}
} else {
for (int i = 1; i <= m; i += 2) {
answerMulMemo += Comb(m, i, p);
answerMulMemo %= p;
}
}
// answer *= answerMulMemo;
answer %= p;
Console.WriteLine(answer);
}
static List<long> Factoring(
long
originalNum) { // makePrimeListによるisPrimesを用いて、引数をO(√n)で素因数分解。リストには同じ数も含む。
//例えば1は{},12は{2,2,3},17は{17}を返す。
List<long> answers = new List<long>();
for (long i = 2; i <= Math.Sqrt(originalNum); i++) {
if (!isPrimes[i - 1])
continue; //素数でないとき
else {
while (originalNum % i == 0) {
originalNum /= i;
answers.Add(i);
}
}
}
if (originalNum != 1)
answers.Add(originalNum);
return answers;
}
static bool[] makePrimeList(
long
maxPrime) { //「引数1以上」max以下の素数判定を、エラトステネスの篩を用いてO(n)。
bool[] isPrimes = new bool[maxPrime]; //素数リスト
isPrimes[0] = false; // 1は素数でないのでfalse
for (long i = 1; i < maxPrime; i++)
isPrimes[i] = true; //素数と仮定してtrue
for (long i = 2; i <= Math.Sqrt(maxPrime); i++) {
if (isPrimes[i - 1]) {
for (long j = i * 2; j <= maxPrime; j += i) {
isPrimes[j - 1] = false; //素数でないのでfalse
}
}
}
return isPrimes;
}
static long MathPow(long x, long a) //戻り値はx^a。O(loga)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
}
memo *= memo;
num *= 2;
}
return answer;
}
static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p)。O(loga)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x % p;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
answer %= p;
}
memo *= memo;
memo %= p;
num *= 2;
}
return answer;
}
static long DivideModReverse(long x,
long p) //戻り値はx^-1(mod p), pは素数。O(logp)
{
long answer = DivideMod(x, p - 2, p);
return answer;
}
static long ModFactorial(long x, long p) //戻り値はx!(mod p)
{
long answer = 1;
for (int i = 2; i <= x; i++) {
answer *= i;
answer %= p;
}
return answer;
}
static long DivideModFactorial(long x, long p) //戻り値はx!^-1(mod p), pは素数
{
long answer = 1;
for (long i = x; i >= 2; i--) {
answer *= DivideModReverse(i, p);
answer %= p;
}
return answer;
}
static long Comb(long a, long b, long p) //戻り値は組み合わせC(a,b)のmod p
{
if (a - b < 0)
return 0; //引数a-bが負なら0を返す
long answer = 1;
answer *= factorials[a];
answer %= p;
answer *= factorialRs[a - b];
answer %= p;
answer *= factorialRs[b];
answer %= p;
return answer;
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22]]
| 8
| 1,050
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace ProgrammingContest {
class Writer : IDisposable {
private System.IO.TextWriter Out { get; }
private StringBuilder Sb { get; }
private bool IsReactive { get; }
public Writer(string path) : this(new System.IO.StreamWriter(path)) {}
public Writer(bool isReactive) : this(null, isReactive) {}
public Writer(System.IO.TextWriter writer = null, bool isReactive = false) {
this.Out = (writer ?? Console.Out);
this.IsReactive = isReactive;
if (!this.IsReactive) {
this.Sb = new StringBuilder();
}
}
public void Dispose() {
if (!this.IsReactive) {
this.Out.Write(Sb.ToString());
}
if (!this.Out.Equals(Console.Out)) {
this.Out.Dispose();
}
}
public void Write(object val) {
if (this.IsReactive) {
this.Out.Write(val.ToString());
this.Out.Flush();
} else {
this.Sb.Append(val.ToString());
}
}
public void WriteFormat(string format, params object[] vals) {
if (this.IsReactive) {
this.Out.Write(format, vals);
this.Out.Flush();
} else {
this.Sb.AppendFormat(format, vals);
}
}
public void WriteLine(object val = null) =>
this.WriteFormat((val?.ToString() ?? string.Empty) + Environment.NewLine);
public void WriteLine(int val) => this.WriteLine(val.ToString());
public void WriteLine(long val) => this.WriteLine(val.ToString());
public void WriteLine(string val) => this.WriteLine((object)val);
public void WriteLine(string format, params object[] vals) =>
this.WriteFormat(format + Environment.NewLine, vals);
}
class Scanner : IDisposable {
private Queue<string> Buffer { get; }
private char[] Sep { get; }
private System.IO.TextReader Reader { get; }
public Scanner(string path, char[] sep = null)
: this(new System.IO.StreamReader(path), sep) {}
public Scanner(System.IO.TextReader reader = null, char[] sep = null) {
this.Buffer = new Queue<string>();
this.Sep = (sep ?? new char[] { ' ' });
this.Reader = (reader ?? Console.In);
}
private void CheckBuffer() {
if (this.Buffer.Count == 0 && this.Reader.Peek() != -1) {
string str = string.Empty;
for (; string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str);
str = this.Reader.ReadLine())
;
var strs = str.Split(this.Sep).Where(
el => !(string.IsNullOrEmpty(el) || string.IsNullOrWhiteSpace(el)));
foreach (var el in strs) {
this.Buffer.Enqueue(el);
}
}
}
public void Dispose() {
if (!this.Reader.Equals(Console.In)) {
this.Reader.Dispose();
}
}
public string Next() {
this.CheckBuffer();
return this.Buffer.Dequeue();
}
public string[] GetStringArray(int N) =>
Enumerable.Range(0, N).Select(e => this.Next()).ToArray();
public int NextInt() => int.Parse(this.Next());
public int[] GetIntArray(int N) =>
Enumerable.Range(0, N).Select(e => this.NextInt()).ToArray();
public double NextDouble() => double.Parse(this.Next());
public double[] GetdoubleArray(int N) =>
Enumerable.Range(0, N).Select(e => this.NextDouble()).ToArray();
public long NextLong() => long.Parse(this.Next());
public long[] GetLongArray(int N) =>
Enumerable.Range(0, N).Select(e => this.NextLong()).ToArray();
public bool IsEnd {
get {
this.CheckBuffer();
return this.Buffer.Count == 0;
}
}
}
class MainClass : IDisposable {
private Scanner Sc { get; }
private Writer Wr { get; }
private string InFilePath => "in.txt";
private string OutFilePath => "out.txt";
public MainClass() {
this.Wr = new Writer(this.IsReactive);
// this.Wr = new Writer(this.OutFilePath);
#if DEBUG
if (!this.IsReactive) {
this.Sc = new Scanner(this.InFilePath);
} else {
this.Sc = new Scanner();
}
#else
this.Sc = new Scanner();
#endif
this.Solve();
}
static void Main(string[] args) {
using (new MainClass()) {}
}
public void Dispose() {
this.Sc?.Dispose();
this.Wr?.Dispose();
#if DEBUG
Console.WriteLine("press any key to continue...");
Console.ReadKey();
#endif
}
const int MAX = (int)1e5 + 10;
const int MOD = (int)1e9 + 7;
ModCalc mc = new ModCalc(MAX, MOD);
void Solve() {
int N = Sc.NextInt();
int M = Sc.NextInt();
var d = CalcPrimeFactor(M);
long ans = 1;
foreach (var el in d) {
ans = mc.Mul(ans, mc.Combination(el.Value + N - 1, el.Value));
}
Wr.WriteLine(ans);
}
private bool IsReactive => false; // TODO: reactive check !!
IReadOnlyDictionary<long, int> CalcPrimeFactor(long val) {
Dictionary<long, int> dic = new Dictionary<long, int>();
for (long i = 2; i * i <= val; i++) {
while (val % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 1);
} else {
dic[i]++;
}
val /= i;
}
}
if (val > 1) {
if (dic.ContainsKey(val))
dic[val]++;
else
dic.Add(val, 1);
}
return dic;
}
}
class ModCalc {
private readonly int maxVal;
private readonly int mod;
private readonly long[] memoFact;
private readonly long[] memoInvFact;
public ModCalc(int maxVal, int mod) {
this.maxVal = maxVal;
this.mod = mod;
this.memoFact = new long[maxVal + 1];
this.memoFact[0] = 1;
for (int i = 0; i < maxVal; i++) {
this.memoFact[i + 1] = Mul(i + 1, this.memoFact[i]);
}
this.memoInvFact = new long[maxVal + 1];
for (int i = 0; i < maxVal + 1; i++) {
this.memoInvFact[i] = Inverse(this.memoFact[i]);
}
}
/// <summary>
/// 法modで加算を行う
/// </summary>
/// <param name="left">左辺値</param>
/// <param name="right">右辺値</param>
/// <returns>引数を加算した値</returns>
public long Add(long left, long right) => (left % mod + right % mod) % mod;
/// <summary>
/// 法modで減算を行う
/// </summary>
/// <param name="left">左辺値</param>
/// <param name="right">右辺値</param>
/// <returns>引数を減算した値</returns>
public long Sub(long left, long right) => Add(left, -right % mod + mod);
/// <summary>
/// 法modで乗算を行う
/// </summary>
/// <param name="left">左辺値</param>
/// <param name="right">右辺値</param>
/// <returns>引数を乗算した値</returns>
public long Mul(long left, long right) => (left % mod) * (right % mod) % mod;
/// <summary>
/// 法modで除算を行う
/// </summary>
/// <param name="left">左辺値</param>
/// <param name="right">右辺値</param>
/// <returns>引数を除算した値</returns>
public long Div(long left, long right) => Mul(left, Inverse(right));
/// <summary>
/// 法modで逆数を求める
/// </summary>
/// <param name="value">もとの値</param>
/// <returns>引数の値の逆数</returns>
public long Inverse(long value) => PowMod(value, mod - 2);
/// <summary>
/// 法modでバイナリ法により累乗を求める
/// </summary>
/// <param name="a">底</param>
/// <param name="p">指数</param>
/// <returns>法modでのa^p</returns>
public long PowMod(long a, long p) {
if (p == 0) {
return 1;
} else if (p % 2 == 1) {
return Mul(a, PowMod(a, p - 1));
} else {
var tmp = PowMod(a, p / 2);
return Mul(tmp, tmp);
}
}
/// <summary>
/// 法modで階乗を求める
/// </summary>
/// <param name="N">基準値</param>
/// <returns>法modでのN!</returns>
public long Fact(int N) => memoFact[N];
/// <summary>
/// 法modで階乗値の逆数を求める
/// </summary>
/// <param name="N">基準</param>
/// <returns>法modでのNの逆数</returns>
public long InvFact(int N) => memoInvFact[N];
/// <summary>
/// 法modで順列数を求める
/// </summary>
/// <param name="n">元の数</param>
/// <param name="r">選ぶ数</param>
/// <returns>法modでのnPr</returns>
public long Permutation(int n, int r) => Fact(n) * InvFact(n - r);
/// <summary>
/// 法modで組み合わせ数を求める
/// </summary>
/// <param name="n">元の数</param>
/// <param name="r">選ぶ数</param>
/// <returns>法modでのnCr</returns>
public long Combination(int n, int r) => Mul(Mul(Fact(n), InvFact(r)),
InvFact(n - r));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace ProgrammingContest {
class Writer : IDisposable {
private System.IO.TextWriter Out { get; }
private StringBuilder Sb { get; }
private bool IsReactive { get; }
public Writer(string path) : this(new System.IO.StreamWriter(path)) {}
public Writer(bool isReactive) : this(null, isReactive) {}
public Writer(System.IO.TextWriter writer = null, bool isReactive = false) {
this.Out = (writer ?? Console.Out);
this.IsReactive = isReactive;
if (!this.IsReactive) {
this.Sb = new StringBuilder();
}
}
public void Dispose() {
if (!this.IsReactive) {
this.Out.Write(Sb.ToString());
}
if (!this.Out.Equals(Console.Out)) {
this.Out.Dispose();
}
}
public void Write(object val) {
if (this.IsReactive) {
this.Out.Write(val.ToString());
this.Out.Flush();
} else {
this.Sb.Append(val.ToString());
}
}
public void WriteFormat(string format, params object[] vals) {
if (this.IsReactive) {
this.Out.Write(format, vals);
this.Out.Flush();
} else {
this.Sb.AppendFormat(format, vals);
}
}
public void WriteLine(object val = null) =>
this.WriteFormat((val?.ToString() ?? string.Empty) + Environment.NewLine);
public void WriteLine(int val) => this.WriteLine(val.ToString());
public void WriteLine(long val) => this.WriteLine(val.ToString());
public void WriteLine(string val) => this.WriteLine((object)val);
public void WriteLine(string format, params object[] vals) =>
this.WriteFormat(format + Environment.NewLine, vals);
}
class Scanner : IDisposable {
private Queue<string> Buffer { get; }
private char[] Sep { get; }
private System.IO.TextReader Reader { get; }
public Scanner(string path, char[] sep = null)
: this(new System.IO.StreamReader(path), sep) {}
public Scanner(System.IO.TextReader reader = null, char[] sep = null) {
this.Buffer = new Queue<string>();
this.Sep = (sep ?? new char[] { ' ' });
this.Reader = (reader ?? Console.In);
}
private void CheckBuffer() {
if (this.Buffer.Count == 0 && this.Reader.Peek() != -1) {
string str = string.Empty;
for (; string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str);
str = this.Reader.ReadLine())
;
var strs = str.Split(this.Sep).Where(
el => !(string.IsNullOrEmpty(el) || string.IsNullOrWhiteSpace(el)));
foreach (var el in strs) {
this.Buffer.Enqueue(el);
}
}
}
public void Dispose() {
if (!this.Reader.Equals(Console.In)) {
this.Reader.Dispose();
}
}
public string Next() {
this.CheckBuffer();
return this.Buffer.Dequeue();
}
public string[] GetStringArray(int N) =>
Enumerable.Range(0, N).Select(e => this.Next()).ToArray();
public int NextInt() => int.Parse(this.Next());
public int[] GetIntArray(int N) =>
Enumerable.Range(0, N).Select(e => this.NextInt()).ToArray();
public double NextDouble() => double.Parse(this.Next());
public double[] GetdoubleArray(int N) =>
Enumerable.Range(0, N).Select(e => this.NextDouble()).ToArray();
public long NextLong() => long.Parse(this.Next());
public long[] GetLongArray(int N) =>
Enumerable.Range(0, N).Select(e => this.NextLong()).ToArray();
public bool IsEnd {
get {
this.CheckBuffer();
return this.Buffer.Count == 0;
}
}
}
class MainClass : IDisposable {
private Scanner Sc { get; }
private Writer Wr { get; }
private string InFilePath => "in.txt";
private string OutFilePath => "out.txt";
public MainClass() {
this.Wr = new Writer(this.IsReactive);
// this.Wr = new Writer(this.OutFilePath);
#if DEBUG
if (!this.IsReactive) {
this.Sc = new Scanner(this.InFilePath);
} else {
this.Sc = new Scanner();
}
#else
this.Sc = new Scanner();
#endif
this.Solve();
}
static void Main(string[] args) {
using (new MainClass()) {}
}
public void Dispose() {
this.Sc?.Dispose();
this.Wr?.Dispose();
#if DEBUG
Console.WriteLine("press any key to continue...");
Console.ReadKey();
#endif
}
const int MAX = (int)2e5 + 10;
const int MOD = (int)1e9 + 7;
ModCalc mc = new ModCalc(MAX, MOD);
void Solve() {
int N = Sc.NextInt();
int M = Sc.NextInt();
var d = CalcPrimeFactor(M);
long ans = 1;
foreach (var el in d) {
ans = mc.Mul(ans, mc.Combination(el.Value + N - 1, el.Value));
}
Wr.WriteLine(ans);
}
private bool IsReactive => false; // TODO: reactive check !!
IReadOnlyDictionary<long, int> CalcPrimeFactor(long val) {
Dictionary<long, int> dic = new Dictionary<long, int>();
for (long i = 2; i * i <= val; i++) {
while (val % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 1);
} else {
dic[i]++;
}
val /= i;
}
}
if (val > 1) {
if (dic.ContainsKey(val))
dic[val]++;
else
dic.Add(val, 1);
}
return dic;
}
}
class ModCalc {
private readonly int maxVal;
private readonly int mod;
private readonly long[] memoFact;
private readonly long[] memoInvFact;
public ModCalc(int maxVal, int mod) {
this.maxVal = maxVal;
this.mod = mod;
this.memoFact = new long[maxVal + 1];
this.memoFact[0] = 1;
for (int i = 0; i < maxVal; i++) {
this.memoFact[i + 1] = Mul(i + 1, this.memoFact[i]);
}
this.memoInvFact = new long[maxVal + 1];
for (int i = 0; i < maxVal + 1; i++) {
this.memoInvFact[i] = Inverse(this.memoFact[i]);
}
}
/// <summary>
/// 法modで加算を行う
/// </summary>
/// <param name="left">左辺値</param>
/// <param name="right">右辺値</param>
/// <returns>引数を加算した値</returns>
public long Add(long left, long right) => (left % mod + right % mod) % mod;
/// <summary>
/// 法modで減算を行う
/// </summary>
/// <param name="left">左辺値</param>
/// <param name="right">右辺値</param>
/// <returns>引数を減算した値</returns>
public long Sub(long left, long right) => Add(left, -right % mod + mod);
/// <summary>
/// 法modで乗算を行う
/// </summary>
/// <param name="left">左辺値</param>
/// <param name="right">右辺値</param>
/// <returns>引数を乗算した値</returns>
public long Mul(long left, long right) => (left % mod) * (right % mod) % mod;
/// <summary>
/// 法modで除算を行う
/// </summary>
/// <param name="left">左辺値</param>
/// <param name="right">右辺値</param>
/// <returns>引数を除算した値</returns>
public long Div(long left, long right) => Mul(left, Inverse(right));
/// <summary>
/// 法modで逆数を求める
/// </summary>
/// <param name="value">もとの値</param>
/// <returns>引数の値の逆数</returns>
public long Inverse(long value) => PowMod(value, mod - 2);
/// <summary>
/// 法modでバイナリ法により累乗を求める
/// </summary>
/// <param name="a">底</param>
/// <param name="p">指数</param>
/// <returns>法modでのa^p</returns>
public long PowMod(long a, long p) {
if (p == 0) {
return 1;
} else if (p % 2 == 1) {
return Mul(a, PowMod(a, p - 1));
} else {
var tmp = PowMod(a, p / 2);
return Mul(tmp, tmp);
}
}
/// <summary>
/// 法modで階乗を求める
/// </summary>
/// <param name="N">基準値</param>
/// <returns>法modでのN!</returns>
public long Fact(int N) => memoFact[N];
/// <summary>
/// 法modで階乗値の逆数を求める
/// </summary>
/// <param name="N">基準</param>
/// <returns>法modでのNの逆数</returns>
public long InvFact(int N) => memoInvFact[N];
/// <summary>
/// 法modで順列数を求める
/// </summary>
/// <param name="n">元の数</param>
/// <param name="r">選ぶ数</param>
/// <returns>法modでのnPr</returns>
public long Permutation(int n, int r) => Fact(n) * InvFact(n - r);
/// <summary>
/// 法modで組み合わせ数を求める
/// </summary>
/// <param name="n">元の数</param>
/// <param name="r">選ぶ数</param>
/// <returns>法modでのnCr</returns>
public long Combination(int n, int r) => Mul(Mul(Fact(n), InvFact(r)),
InvFact(n - r));
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 74, 51, 250], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 51, 250]]
| 8
| 1,845
| 2
|
using MathX;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ABC110D___Factorization {
public class Program {
public static readonly int MOD = (int)Math.Pow(10, 9) + 7;
public static void Main(string[] args) {
checked {
string[] line = Console.ReadLine().Trim().Split(' ');
int n = int.Parse(line[0]);
int m = int.Parse(line[1]);
List<int> primes =
MathX.MathX.PrimeFactor(m).Select(x => (int)x).ToList();
Dictionary<int, int> primesDic = new Dictionary<int, int>();
foreach (int i in primes) {
if (primesDic.ContainsKey(i))
primesDic[i]++;
else
primesDic.Add(i, 1);
}
long rlt = 1;
foreach (KeyValuePair<int, int> i in primesDic) {
rlt *=
(int)MathX.MathX.Combination(i.Value + n - 1, i.Value, MOD) % MOD;
}
Console.WriteLine(rlt % MOD);
}
}
}
}
namespace MathX {
public class MathX {
//●最小公倍数
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
//●最大公約数
public static long Gcd(long a, long b) {
if (a < b)
return Gcd(b, a); // 引数を入替えて自分を呼び出す
if (b == 0)
return a; //一方が0の場合は、もう片方の数自身がGCD
long d = 0;
do {
d = a % b;
a = b;
b = d;
} while (d != 0);
return a;
}
//●素因数分解(ポラード・ロー素因数分解法)
public static IEnumerable<long> PrimeFactor(long n) {
while (n > 1) {
long factor = GetFactor(n);
yield return factor;
n = n / factor;
}
}
private static long GetFactor(long n, int seed = 1) {
if (n % 2 == 0)
return 2;
if (IsPrime(n))
return n;
long x = 2, y = 2, d = 1;
long count = 0;
while (d == 1) {
count++;
x = f(x, n, seed);
y = f(f(y, n, seed), n, seed);
d = Gcd(Math.Abs(x - y), n);
}
if (d == n)
// 見つからなかった、乱数発生のシードを変えて再挑戦。
return GetFactor(n, seed + 1);
// 素数でない可能性もあるので、再度呼び出す
return GetFactor(d);
}
private static int[] seeds = new int[] { 3, 5, 7, 11, 13, 17 };
private static long f(long x, long n, int seed) {
return (seeds[seed % 6] * x + seed) % n;
}
//●素数判定
public static bool IsPrime(long number) {
long boundary = (long)Math.Floor(Math.Sqrt(number));
if (number == 1)
return false;
if (number == 2)
return true;
for (long i = 2; i <= boundary; ++i) {
if (number % i == 0)
return false;
}
return true;
}
//●階乗
public static long Factorial(long n, long mod = 0) {
checked {
if (n == 0)
return 1L;
if (mod == 0) {
return n * Factorial(n - 1);
} else {
return n * Factorial(n - 1, mod) % mod;
}
}
}
//●組み合わせの数
public static long Combination(long n, long r, long mod = 0) {
checked {
long ans = 1;
if (r > n / 2)
return Combination(n, n - r, mod); //計算量を減らす(5C4 = 5C1)
long div = 1;
for (int i = 0; i < r; i++) {
ans *= n - i;
div *= i + 1;
if (mod != 0) {
ans %= mod;
div %= mod;
}
}
if (mod != 0) {
ans *= Powmod(div, mod - 2, mod);
return ans % mod;
} else
return ans / div;
}
}
//●mod下での累乗計算
public static long Powmod(long a, long p, long mod) {
checked {
long ans = 1;
long mul = a;
for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
if ((p & 1) == 1)
ans = (ans * mul) % mod;
}
return ans;
}
}
}
}
|
using MathX;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ABC110D___Factorization {
public class Program {
public static readonly int MOD = (int)Math.Pow(10, 9) + 7;
public static void Main(string[] args) {
checked {
string[] line = Console.ReadLine().Trim().Split(' ');
int n = int.Parse(line[0]);
int m = int.Parse(line[1]);
List<int> primes =
MathX.MathX.PrimeFactor(m).Select(x => (int)x).ToList();
Dictionary<int, int> primesDic = new Dictionary<int, int>();
foreach (int i in primes) {
if (primesDic.ContainsKey(i))
primesDic[i]++;
else
primesDic.Add(i, 1);
}
long rlt = 1;
foreach (KeyValuePair<int, int> i in primesDic) {
rlt *= MathX.MathX.Combination(i.Value + n - 1, i.Value, MOD);
rlt %= MOD;
}
Console.WriteLine(rlt % MOD);
}
}
}
}
namespace MathX {
public class MathX {
//●最小公倍数
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
//●最大公約数
public static long Gcd(long a, long b) {
if (a < b)
return Gcd(b, a); // 引数を入替えて自分を呼び出す
if (b == 0)
return a; //一方が0の場合は、もう片方の数自身がGCD
long d = 0;
do {
d = a % b;
a = b;
b = d;
} while (d != 0);
return a;
}
//●素因数分解(ポラード・ロー素因数分解法)
public static IEnumerable<long> PrimeFactor(long n) {
while (n > 1) {
long factor = GetFactor(n);
yield return factor;
n = n / factor;
}
}
private static long GetFactor(long n, int seed = 1) {
if (n % 2 == 0)
return 2;
if (IsPrime(n))
return n;
long x = 2, y = 2, d = 1;
long count = 0;
while (d == 1) {
count++;
x = f(x, n, seed);
y = f(f(y, n, seed), n, seed);
d = Gcd(Math.Abs(x - y), n);
}
if (d == n)
// 見つからなかった、乱数発生のシードを変えて再挑戦。
return GetFactor(n, seed + 1);
// 素数でない可能性もあるので、再度呼び出す
return GetFactor(d);
}
private static int[] seeds = new int[] { 3, 5, 7, 11, 13, 17 };
private static long f(long x, long n, int seed) {
return (seeds[seed % 6] * x + seed) % n;
}
//●素数判定
public static bool IsPrime(long number) {
long boundary = (long)Math.Floor(Math.Sqrt(number));
if (number == 1)
return false;
if (number == 2)
return true;
for (long i = 2; i <= boundary; ++i) {
if (number % i == 0)
return false;
}
return true;
}
//●階乗
public static long Factorial(long n, long mod = 0) {
checked {
if (n == 0)
return 1L;
if (mod == 0) {
return n * Factorial(n - 1);
} else {
return n * Factorial(n - 1, mod) % mod;
}
}
}
//●組み合わせの数
public static long Combination(long n, long r, long mod = 0) {
checked {
long ans = 1;
if (r > n / 2)
return Combination(n, n - r, mod); //計算量を減らす(5C4 = 5C1)
long div = 1;
for (int i = 0; i < r; i++) {
ans *= n - i;
div *= i + 1;
if (mod != 0) {
ans %= mod;
div %= mod;
}
}
if (mod != 0) {
ans *= Powmod(div, mod - 2, mod);
return ans % mod;
} else
return ans / div;
}
}
//●mod下での累乗計算
public static long Powmod(long a, long p, long mod) {
checked {
long ans = 1;
long mul = a;
for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
if ((p & 1) == 1)
ans = (ans * mul) % mod;
}
return ans;
}
}
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 74, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 0, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132]]
| 8
| 934
| 7
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
long N = long.Parse(str[0]);
long M = long.Parse(str[1]);
long mod = 1000000007;
List<long> list = PrimeFactors(M);
long ans = 1;
while (true) {
long p = 0;
long t = list[0];
while (true) {
p += 1;
list.RemoveAt(0);
if (list.Count == 0) {
break;
}
if (list[0] != t) {
break;
}
}
ans = ans * Ncr(N + p - 1, p, mod) % mod;
if (list.Count == 0) {
break;
}
}
Console.WriteLine(ans);
}
public static List<long> PrimeFactors(long n) {
long i = 2;
long tmp = n;
var list = new List<long>();
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
list.Add(i);
} else {
i++;
}
}
if (tmp != 1) {
list.Add(tmp);
}
return list;
}
public static long Mpow(long x, long n, long m) {
long ans = 1;
while (n > 0) {
if (n % 2 == 1) {
ans = ans * x % m;
n -= 1;
}
x = x * x % m;
n /= 2;
}
return ans;
}
public static long Ncr(long n, long r, long m) {
long ans = 1;
for (var i = n - r + 1; i <= n; i++) {
ans = ans * i % m;
}
for (var i = 2; i <= r; i++) {
ans = ans * Mpow(i, m - 2, m) % m;
}
return ans;
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split();
long N = long.Parse(str[0]);
long M = long.Parse(str[1]);
long mod = 1000000007;
List<long> list = PrimeFactors(M);
long ans = 1;
while (list.Count > 0) {
long p = 0;
long t = list[0];
while (true) {
p += 1;
list.RemoveAt(0);
if (list.Count == 0) {
break;
}
if (list[0] != t) {
break;
}
}
ans = ans * Ncr(N + p - 1, p, mod) % mod;
if (list.Count == 0) {
break;
}
}
Console.WriteLine(ans);
}
public static List<long> PrimeFactors(long n) {
long i = 2;
long tmp = n;
var list = new List<long>();
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
list.Add(i);
} else {
i++;
}
}
if (tmp != 1) {
list.Add(tmp);
}
return list;
}
public static long Mpow(long x, long n, long m) {
long ans = 1;
while (n > 0) {
if (n % 2 == 1) {
ans = ans * x % m;
n -= 1;
}
x = x * x % m;
n /= 2;
}
return ans;
}
public static long Ncr(long n, long r, long m) {
long ans = 1;
for (var i = n - r + 1; i <= n; i++) {
ans = ans * i % m;
}
for (var i = 2; i <= r; i++) {
ans = ans * Mpow(i, m - 2, m) % m;
}
return ans;
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 8, 196, 0, 52, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 52, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203]]
| 8
| 426
| 6
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var N = sc.ReadInt();
var X = sc.ReadInt();
var A = sc.ReadIntArray(N);
Array.Sort(A);
var now = X;
var ans = 0;
for (int i = 0; i < N; i++) {
if (now >= A[i]) {
now -= A[i];
ans++;
}
}
if (ans == N)
ans--;
Console.WriteLine(ans);
Console.Out.Flush();
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var N = sc.ReadInt();
var X = sc.ReadInt();
var A = sc.ReadIntArray(N);
Array.Sort(A);
var now = X;
var ans = 0;
for (int i = 0; i < N; i++) {
if (now >= A[i]) {
now -= A[i];
ans++;
}
}
if (ans == N && now > 0)
ans--;
Console.WriteLine(ans);
Console.Out.Flush();
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 1,137
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var line = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
var H = line[0];
var W = line[1];
var K = line[2];
var dp = new int[H + 1, W];
dp[0, 0] = 1;
for (var hi = 0; hi < H; hi++) {
for (var wi = 0; wi < W; wi++) {
for (var bit = 0; bit < (1 << (W - 1)) - 1; bit++) {
var invalid = false;
for (var i = 0; i < W - 2; i++) {
if ((bit & (1 << i)) != 0 && (bit & (1 << (i + 1))) != 0) {
invalid = true;
}
}
if (invalid)
continue;
var mod = 1000000007;
if ((bit & (1 << (wi - 1))) != 0 && wi - 1 >= 0) {
dp[hi + 1, wi - 1] += dp[hi, wi];
dp[hi + 1, wi - 1] %= mod;
} else if ((bit & (1 << wi)) != 0 && wi + 1 < W) {
dp[hi + 1, wi + 1] += dp[hi, wi];
dp[hi + 1, wi + 1] %= mod;
} else {
dp[hi + 1, wi] += dp[hi, wi];
dp[hi + 1, wi] %= mod;
}
}
}
}
Console.WriteLine(dp[H, K - 1]);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var line = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
var H = line[0];
var W = line[1];
var K = line[2];
var dp = new int[H + 1, W];
dp[0, 0] = 1;
for (var hi = 0; hi < H; hi++) {
for (var wi = 0; wi < W; wi++) {
for (var bit = 0; bit < (1 << (W - 1)); bit++) {
var invalid = false;
for (var i = 0; i < W - 2; i++) {
if ((bit & (1 << i)) != 0 && (bit & (1 << (i + 1))) != 0) {
invalid = true;
}
}
if (invalid)
continue;
var mod = 1000000007;
if ((bit & (1 << (wi - 1))) != 0 && wi - 1 >= 0) {
dp[hi + 1, wi - 1] += dp[hi, wi];
dp[hi + 1, wi - 1] %= mod;
} else if ((bit & (1 << wi)) != 0 && wi + 1 < W) {
dp[hi + 1, wi + 1] += dp[hi, wi];
dp[hi + 1, wi + 1] %= mod;
} else {
dp[hi + 1, wi] += dp[hi, wi];
dp[hi + 1, wi] %= mod;
}
}
}
}
Console.WriteLine(dp[H, K - 1]);
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 386
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
class Dmondai {
static void Main() {
const long Mod = 1000000007;
var line =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
var H = line[0];
var W = line[1];
var K = line[2];
//縦棒が一つしかない場合は1
if (W == 1) {
Console.WriteLine(1);
return;
}
//それぞれの位置の横棒の数を保存する
var arrayH = new long[W];
//ビット探索
//横の線のあるなしを全列挙する
var bitList = new List<string>();
for (int i = 0; i < (1 << (W - 1)); ++i) {
//二進数に変換、
var value = Convert.ToString((i), 2);
//空いている桁は0埋めする
var bit = value.PadLeft(W - 1, '0');
//横棒が二つ続いた場合、処理をスキップさせるためのフラグ
var isContinue = true;
//横棒が二つ続くことはないので、その場合を除く
for (int j = 0; j < W - 2; ++j) {
if (bit[j] == '1' && bit[j + 1] == '1') {
isContinue = false;
break;
}
}
//横棒が二つ続かないパターン(正当なあみだくじ)
if (isContinue) {
bitList.Add(bit);
for (int j = 0; j < W - 1; ++j)
if (bit[j] == '1')
arrayH[j]++;
}
}
//ビットりすと内にある数を保存(横棒のパターン)
long bitCount = bitList.Count();
//動的計画法
//各ポイントにおいて何通りのパターンがあるかを保存し、
//それを利用しつつ下へ下る
//保存する器を用意
// H横棒の数、いま行でどこにいるか、0~H
// W横棒の数、いま列でどこにいるか、0~W-1
var ansArray = new long[H + 1, W];
//行のループ
for (int i = 0; i <= H; ++i) {
//列のループ
for (int j = 0; j < W; ++j) {
if (i == 0) {
// 0,0地点は始点=1
if (j == 0)
ansArray[i, j] = 1;
else
ansArray[i, j] = 0;
}
//列が0のとき
else if (j == 0) {
//真上
var temp = (ansArray[i - 1, j] * (bitCount - arrayH[0])) % Mod;
//右
temp = (temp + (ansArray[i - 1, j + 1] * arrayH[0])) % Mod;
ansArray[i, j] = temp;
}
//列がW-1のとき(一番右端)
else if (j == W - 1) {
//真上
var temp = (ansArray[i - 1, j] * (bitCount - arrayH[W - 1])) % Mod;
//左
temp = (temp + (ansArray[i - 1, j - 1] * arrayH[W - 1])) % Mod;
ansArray[i, j] = temp;
}
//それ以外
else {
//真上
var temp =
(ansArray[i - 1, j] * (bitCount - (arrayH[j - 1] + arrayH[j]))) %
Mod;
//左
temp = (temp + (ansArray[i - 1, j - 1] * arrayH[j - 1])) % Mod;
//右
temp = (temp + (ansArray[i - 1, j + 1] * arrayH[j])) % Mod;
ansArray[i, j] = temp;
}
}
}
Console.WriteLine(ansArray[H, K - 1]);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Dmondai {
static void Main() {
const long Mod = 1000000007;
var line =
Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
var H = line[0];
var W = line[1];
var K = line[2];
//縦棒が一つしかない場合は1
if (W == 1) {
Console.WriteLine(1);
return;
}
//それぞれの位置の横棒の数を保存する
var arrayH = new long[W - 1];
//ビット探索
//横の線のあるなしを全列挙する
var bitList = new List<string>();
for (int i = 0; i < (1 << (W - 1)); ++i) {
//二進数に変換、
var value = Convert.ToString((i), 2);
//空いている桁は0埋めする
var bit = value.PadLeft(W - 1, '0');
//横棒が二つ続いた場合、処理をスキップさせるためのフラグ
var isContinue = true;
//横棒が二つ続くことはないので、その場合を除く
for (int j = 0; j < W - 2; ++j) {
if (bit[j] == '1' && bit[j + 1] == '1') {
isContinue = false;
break;
}
}
//横棒が二つ続かないパターン(正当なあみだくじ)
if (isContinue) {
bitList.Add(bit);
for (int j = 0; j < W - 1; ++j)
if (bit[j] == '1')
arrayH[j]++;
}
}
//ビットりすと内にある数を保存(横棒のパターン)
long bitCount = bitList.Count();
//動的計画法
//各ポイントにおいて何通りのパターンがあるかを保存し、
//それを利用しつつ下へ下る
//保存する器を用意
// H横棒の数、いま行でどこにいるか、0~H
// W横棒の数、いま列でどこにいるか、0~W-1
var ansArray = new long[H + 1, W];
//行のループ
for (int i = 0; i <= H; ++i) {
//列のループ
for (int j = 0; j < W; ++j) {
if (i == 0) {
// 0,0地点は始点=1
if (j == 0)
ansArray[i, j] = 1;
else
ansArray[i, j] = 0;
}
//列が0のとき
else if (j == 0) {
//真上
var temp = (ansArray[i - 1, j] * (bitCount - arrayH[0])) % Mod;
//右
temp = (temp + (ansArray[i - 1, j + 1] * arrayH[0])) % Mod;
ansArray[i, j] = temp;
}
//列がW-1のとき(一番右端)
else if (j == W - 1) {
//真上
var temp = (ansArray[i - 1, j] * (bitCount - arrayH[W - 2])) % Mod;
//左
temp = (temp + (ansArray[i - 1, j - 1] * arrayH[W - 2])) % Mod;
ansArray[i, j] = temp;
}
//それ以外
else {
//真上
var temp =
(ansArray[i - 1, j] * (bitCount - (arrayH[j - 1] + arrayH[j]))) %
Mod;
//左
temp = (temp + (ansArray[i - 1, j - 1] * arrayH[j - 1])) % Mod;
//右
temp = (temp + (ansArray[i - 1, j + 1] * arrayH[j])) % Mod;
ansArray[i, j] = temp;
}
}
}
Console.WriteLine(ansArray[H, K - 1]);
}
}
|
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 33], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 652
| 6
|
using System;
class A {
static void Main() {
int i;
var x = Console.ReadLine();
if (x.Length == 3) {
char[] y = x.ToCharArray();
for (i = 2; i < 0; i--) {
Console.Write("{0}", y[i]);
}
} else
Console.Write("{0}", x);
}
}
|
using System;
class A {
static void Main() {
int i;
var x = Console.ReadLine();
if (x.Length == 3) {
char[] y = x.ToCharArray();
for (i = 2; i >= 0; i--) {
Console.Write("{0}", y[i]);
}
} else
Console.Write("{0}", x);
}
}
|
[["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 20]]
| 8
| 88
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sample1 {
class Program {
static void Main(string[] args) {
char[] rts = new char[3];
string str = Console.ReadLine();
if (str.Length == 2) {
Console.WriteLine($"{str}");
} else if (str.Length == 3) {
for (int i = 0; i < str.Length; i++) {
rts[i] = str[str.Length - 1 - i];
}
Console.WriteLine($"{rts}");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sample1 {
class Program {
static void Main(string[] args) {
char[] rts = new char[3];
string str = Console.ReadLine();
if (str.Length == 2) {
Console.WriteLine($"{str}");
} else if (str.Length == 3) {
for (int i = 0; i < str.Length; i++) {
rts[i] = str[str.Length - 1 - i];
}
Console.WriteLine(rts);
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62]]
| 8
| 143
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var str = ReadLine();
if (str.Length == 2)
WriteLine(2);
else {
var result = "";
for (var i = 0; i < 3; i++)
result += str[2 - i];
WriteLine(result);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var str = ReadLine();
if (str.Length == 2)
WriteLine(str);
else {
var result = "";
for (var i = 0; i < 3; i++)
result += str[2 - i];
WriteLine(result);
}
}
}
|
[["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 105
| 2
|
using System;
class Program {
static void Main() {
string r = Console.ReadLine();
int A = int.Parse(r.Split(' ')[0]);
int B = int.Parse(r.Split(' ')[1]);
int X = int.Parse(r.Split(' ')[2]);
for (bool f = true; --X > 1; f = !f) {
if (f) {
B += (A /= 2);
} else {
A += (B /= 2);
}
}
//出力
Console.WriteLine(A.ToString() + " " + B.ToString());
}
}
|
using System;
class Program {
static void Main() {
string r = Console.ReadLine();
int A = int.Parse(r.Split(' ')[0]);
int B = int.Parse(r.Split(' ')[1]);
int X = int.Parse(r.Split(' ')[2]);
for (bool f = true; X-- > 0; f = !f) {
if (f) {
B += (A /= 2);
} else {
A += (B /= 2);
}
}
//出力
Console.WriteLine(A.ToString() + " " + B.ToString());
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 31, 241, 0, 68], ["+", 8, 196, 0, 7, 15, 16, 31, 223, 0, 68], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 149
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var N = Int1;
var A = VerticalRead(N);
Array.Sort(A);
if (N % 2 == 0) {
long ans = 0;
;
for (int i = 0; i < N / 2 - 1; ++i)
ans -= 2 * A[i];
for (int i = N / 2 + 1; i < N; ++i)
ans += 2 * A[i];
ans -= A[N / 2];
ans += A[N / 2 + 1];
Write(ans);
return;
}
long ans1 = 0;
for (int i = 0; i < (N - 3) / 2; ++i) {
ans1 -= 2 * A[i];
}
ans1 -= A[(N - 3) / 2] * 2;
ans1 += A[(N - 3) / 2 + 1] + A[(N - 3) / 2 + 2];
for (int i = (N - 3) / 2 + 3; i < N; ++i) {
ans1 += 2 * A[i];
}
long ans2 = 0;
for (int i = 0; i < (N - 3) / 2; ++i) {
ans2 -= 2 * A[i];
}
for (int i = (N - 3) / 2 + 3; i < N; ++i) {
ans2 += 2 * A[i];
}
ans2 += A[(N - 3) / 2 + 2] * 2;
ans2 -= A[(N - 3) / 2 + 1] + A[(N - 3) / 2];
Write(Max(ans1, ans2));
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = n; i >= n - r + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var N = Int1;
var A = VerticalRead(N);
Array.Sort(A);
if (N % 2 == 0) {
long ans = 0;
;
for (int i = 0; i < N / 2 - 1; ++i)
ans -= 2 * A[i];
for (int i = N / 2 + 1; i < N; ++i)
ans += 2 * A[i];
ans -= A[N / 2 - 1];
ans += A[N / 2];
Write(ans);
return;
}
long ans1 = 0;
for (int i = 0; i < (N - 3) / 2; ++i) {
ans1 -= 2 * A[i];
}
ans1 -= A[(N - 3) / 2] * 2;
ans1 += A[(N - 3) / 2 + 1] + A[(N - 3) / 2 + 2];
for (int i = (N - 3) / 2 + 3; i < N; ++i) {
ans1 += 2 * A[i];
}
long ans2 = 0;
for (int i = 0; i < (N - 3) / 2; ++i) {
ans2 -= 2 * A[i];
}
for (int i = (N - 3) / 2 + 3; i < N; ++i) {
ans2 += 2 * A[i];
}
ans2 += A[(N - 3) / 2 + 2] * 2;
ans2 -= A[(N - 3) / 2 + 1] + A[(N - 3) / 2];
Write(Max(ans1, ans2));
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = n; i >= n - r + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 1,242
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var A = sc.ReadLongArray(N);
Array.Sort(A);
var l = 0;
var r = N - 1;
var list = new LinkedList<long>();
for (int i = 0; i < N; i++) {
long max = 0;
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
var now = j == 0 ? A[l] : A[r];
long val = 0;
if (list.Count > 0)
val = Math.Abs(now - (k == 0 ? list.First.Value : list.Last.Value));
max = Math.Max(max, val);
}
}
var done = false;
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
var now = j == 0 ? A[l] : A[r];
long val = 0;
if (list.Count > 0)
val = Math.Abs(now - (k == 0 ? list.First.Value : list.Last.Value));
if (val == max) {
if (k == 0)
list.AddFirst(now);
else
list.AddLast(now);
if (j == 0)
l++;
else
r--;
done = true;
break;
}
}
if (done)
break;
}
}
long ans = 0;
var a = list.ToArray();
long prev = 0;
foreach (var now in list.Skip(1)) {
ans += Math.Abs(now - prev);
prev = now;
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var A = sc.ReadLongArray(N);
Array.Sort(A);
var l = 0;
var r = N - 1;
var list = new LinkedList<long>();
for (int i = 0; i < N; i++) {
long max = 0;
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
var now = j == 0 ? A[l] : A[r];
long val = 0;
if (list.Count > 0)
val = Math.Abs(now - (k == 0 ? list.First.Value : list.Last.Value));
max = Math.Max(max, val);
}
}
var done = false;
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
var now = j == 0 ? A[l] : A[r];
long val = 0;
if (list.Count > 0)
val = Math.Abs(now - (k == 0 ? list.First.Value : list.Last.Value));
if (val == max) {
if (k == 0)
list.AddFirst(now);
else
list.AddLast(now);
if (j == 0)
l++;
else
r--;
done = true;
break;
}
}
if (done)
break;
}
}
long ans = 0;
var a = list.ToArray();
long prev = list.First.Value;
foreach (var now in list.Skip(1)) {
ans += Math.Abs(now - prev);
prev = now;
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 200, 0, 212, 0, 214, 205, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 214, 205, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 214, 205, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
| 8
| 1,374
| 6
|
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AtCoder {
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.OrdinalIgnoreCase);
return s.ToList();
}
public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); }
public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); }
public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); }
public static int PopCount(this int bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}
}
partial class AtCoder {
public string GetStr() { return Console.ReadLine().Trim(); }
public char GetChar() { return Console.ReadLine().Trim()[0]; }
public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<int>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<int>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
dic[a].Add(b);
if (isDirected == false)
dic[b].Add(a);
}
return dic;
}
Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<Edge>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<Edge>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
var c = input[2];
dic[a].Add(new Edge(b, c));
if (isDirected == false)
dic[b].Add(new Edge(a, c));
}
return dic;
}
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);
void Multi<T>(out T a) => a = cv<T>(GetStr());
void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e,
out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
class Edge {
public Edge(int to, long length) {
To = to;
Length = length;
}
public int To { get; set; }
public long Length { get; set; }
}
class Comparable : IComparable<Comparable> {
public Comparable(int value) { Value = value; }
public int Value { get; set; }
public int CompareTo(Comparable c) {
var a = Math.Abs(Value);
var b = Math.Abs(c.Value);
return a > b ? 1 : a == b ? 0 : -1;
}
}
class Comparer<T> : IComparer<T> {
public int Compare(T t1, T t2) { return 1; }
}
partial class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new AtCoder().Solve();
Console.Out.Flush();
Console.Read();
}
}
public partial class AtCoder {
public void Solve() {
int N = GetInt();
var n = -1;
for (int i = 2; i * (i + 1) <= 2 * N; i++) {
if (i * (i + 1) == 2 * N)
n = i;
}
if (n == -1) {
Console.WriteLine("No");
return;
}
var ans = new List<int>[n + 1];
for (int i = 0; i < n + 1; i++) {
ans[i] = new List<int>();
}
var cnt = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i; j++) {
ans[i].Add(cnt);
ans[i + j + 1].Add(cnt);
cnt++;
}
}
Console.WriteLine("Yes");
Console.WriteLine(n + 1);
for (int i = 0; i < n + 1; i++) {
Console.WriteLine(n + " " + string.Join(" ", ans[i]));
}
}
}
}
|
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace AtCoder {
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.OrdinalIgnoreCase);
return s.ToList();
}
public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); }
public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); }
public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); }
public static int PopCount(this int bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}
}
partial class AtCoder {
public string GetStr() { return Console.ReadLine().Trim(); }
public char GetChar() { return Console.ReadLine().Trim()[0]; }
public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
public T[][] CreateJaggedArray<T>(int H, int W, T value) {
return Enumerable.Repeat(0, H)
.Select(s => Enumerable.Repeat(value, W).ToArray())
.ToArray();
}
public int[][] GetIntJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetIntArray().ToArray())
.ToArray();
}
public long[][] GetLongJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetLongArray().ToArray())
.ToArray();
}
public char[][] GetCharJaggedArray(int N) {
return Enumerable.Repeat(0, N)
.Select(s => GetStr().ToCharArray())
.ToArray();
}
public double[][] GetDoubleJaggedArray(int N) {
return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray();
}
Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<int>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<int>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
dic[a].Add(b);
if (isDirected == false)
dic[b].Add(a);
}
return dic;
}
Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M,
bool isDirected,
bool isNode_0indexed) {
var dic = new Dictionary<int, List<Edge>>();
foreach (var e in Enumerable.Range(0, N)) {
dic.Add(e, new List<Edge>());
}
for (int i = 0; i < M; i++) {
var input = GetIntArray();
var a = isNode_0indexed ? input[0] : input[0] - 1;
var b = isNode_0indexed ? input[1] : input[1] - 1;
var c = input[2];
dic[a].Add(new Edge(b, c));
if (isDirected == false)
dic[b].Add(new Edge(a, c));
}
return dic;
}
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);
void Multi<T>(out T a) => a = cv<T>(GetStr());
void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e,
out Y f) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
f = cv<Y>(ar[5]);
}
}
class Edge {
public Edge(int to, long length) {
To = to;
Length = length;
}
public int To { get; set; }
public long Length { get; set; }
}
class Comparable : IComparable<Comparable> {
public Comparable(int value) { Value = value; }
public int Value { get; set; }
public int CompareTo(Comparable c) {
var a = Math.Abs(Value);
var b = Math.Abs(c.Value);
return a > b ? 1 : a == b ? 0 : -1;
}
}
class Comparer<T> : IComparer<T> {
public int Compare(T t1, T t2) { return 1; }
}
partial class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new AtCoder().Solve();
Console.Out.Flush();
Console.Read();
}
}
public partial class AtCoder {
public void Solve() {
int N = GetInt();
var n = -1;
for (int i = 1; i * (i + 1) <= 2 * N; i++) {
if (i * (i + 1) == 2 * N)
n = i;
}
if (n == -1) {
Console.WriteLine("No");
return;
}
var ans = new List<int>[n + 1];
for (int i = 0; i < n + 1; i++) {
ans[i] = new List<int>();
}
var cnt = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i; j++) {
ans[i].Add(cnt);
ans[i + j + 1].Add(cnt);
cnt++;
}
}
Console.WriteLine("Yes");
Console.WriteLine(n + 1);
for (int i = 0; i < n + 1; i++) {
Console.WriteLine(n + " " + string.Join(" ", ans[i]));
}
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 2,166
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;
namespace AtCoderTemplate {
class ProgramF {
static void Main() {
int n = NextInt;
int comb = 3, size = 3;
while (comb < n)
comb += size++;
if (comb != n) {
System.Console.WriteLine("No");
return;
}
System.Console.WriteLine("Yes");
System.Console.WriteLine(size);
var matrix = Enumerable.Range(0, size)
.Select(_ => Enumerable.Repeat(0, size - 1).ToArray())
.ToArray();
int row = 0, column = 0;
for (int i = 1; i <= comb; i++) {
if (column == size - 1)
column = ++row;
matrix[row][column] = i;
matrix[column + 1][row] = i;
column++;
}
System.Console.WriteLine(string.Join(
"\n", matrix.Select(l => $"{size - 1} {string.Join(" ", l)}")));
}
}
}
namespace Library {
class Input {
static IEnumerator<string> enumerator =
new string[] {}.AsEnumerable().GetEnumerator();
public static string Line => Console.ReadLine();
public static string[] StrArr => Line.Split(' ');
public static int NextInt => int.Parse(NextWord());
public static long NextLong => long.Parse(NextWord());
public static List<int> IntList => StrArr.Select(int.Parse).ToList();
public static List<long> LongList => StrArr.Select(long.Parse).ToList();
public static IEnumerable<long[]> TakeLine(int N) {
return Enumerable.Repeat(0, N).Select(
_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
}
public static string NextWord() {
while (!enumerator.MoveNext()) {
enumerator = StrArr.AsEnumerable().GetEnumerator();
}
return enumerator.Current;
}
}
}
namespace Library {
class Modular {
public const int mod = 1000000007;
public readonly long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % mod;
return new Modular((m < 0) ? m + mod : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, mod - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % mod));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
}
}
namespace Library {
class MyMath {
public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); }
public static long Sqrt(long n) {
if (n < 0)
return 0;
long a = 0, tmp = 0, b = 0;
for (int i = 62; i >= 0; i -= 2) {
tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
a = a << 1 | tmp;
n -= (((b << 1) + 1) * tmp) << i;
b = (b << 1) + tmp + tmp;
}
return a;
}
public static long Nck(int n, int k) {
if (k == 0)
return 1;
if (n == 0)
return 0;
return n * Nck(n - 1, k - 1) / k;
}
}
}
namespace Library {
public class PriorityQueue<T> {
readonly List<T> _heap = new List<T>();
readonly Comparison<T> _comparison;
public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; }
public PriorityQueue() : this(Comparer<T>.Default.Compare) {}
public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {}
public void Enqueue(T item) {
_heap.Add(item);
int childID = _heap.Count - 1;
int parentID = (childID - 1) / 2;
while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) {
Swap(parentID, childID);
childID = parentID;
parentID = (parentID - 1) / 2;
}
}
public T Dequeue() {
var first = _heap.First();
_heap[0] = _heap.Last();
_heap.RemoveAt(_heap.Count - 1);
int parentID = 0;
int childID = parentID * 2 + 2;
if (childID >= _heap.Count ||
_comparison(_heap[childID], _heap[childID - 1]) > 0)
childID--;
while (childID < _heap.Count &&
_comparison(_heap[parentID], _heap[childID]) > 0) {
Swap(parentID, childID);
parentID = childID;
childID = parentID * 2 + 2;
if (childID >= _heap.Count ||
_comparison(_heap[childID], _heap[childID - 1]) > 0)
childID--;
}
return first;
}
void Swap(int parent, int child) {
var tmp = _heap[parent];
_heap[parent] = _heap[child];
_heap[child] = tmp;
}
public T Peek() { return _heap[0]; }
public int Count => _heap.Count;
public bool Any() { return _heap.Any(); }
public List<T> Data => _heap;
}
}
namespace Library {
public class UnionFind {
public int[] Parents { get; set; }
public UnionFind(int size) {
Parents = Enumerable.Repeat(-1, size).ToArray();
}
public int Find(int num) {
if (Parents[num] < 0)
return num;
Parents[num] = Find(Parents[num]);
return Parents[num];
}
public int Size(int num) { return -Parents[Find(num)]; }
public bool Same(int a, int b) { return Find(a) == Find(b); }
public void Unite(int a, int b) {
int x = Find(a), y = Find(b);
if (Size(x) > Size(y)) {
Parents[x] += Parents[y];
Parents[y] = x;
} else {
Parents[y] += Parents[x];
Parents[x] = y;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;
namespace AtCoderTemplate {
class ProgramF {
static void Main() {
int n = NextInt;
int comb = 1, size = 2;
while (comb < n)
comb += size++;
if (comb != n) {
System.Console.WriteLine("No");
return;
}
System.Console.WriteLine("Yes");
System.Console.WriteLine(size);
var matrix = Enumerable.Range(0, size)
.Select(_ => Enumerable.Repeat(0, size - 1).ToArray())
.ToArray();
int row = 0, column = 0;
for (int i = 1; i <= comb; i++) {
if (column == size - 1)
column = ++row;
matrix[row][column] = i;
matrix[column + 1][row] = i;
column++;
}
System.Console.WriteLine(string.Join(
"\n", matrix.Select(l => $"{size - 1} {string.Join(" ", l)}")));
}
}
}
namespace Library {
class Input {
static IEnumerator<string> enumerator =
new string[] {}.AsEnumerable().GetEnumerator();
public static string Line => Console.ReadLine();
public static string[] StrArr => Line.Split(' ');
public static int NextInt => int.Parse(NextWord());
public static long NextLong => long.Parse(NextWord());
public static List<int> IntList => StrArr.Select(int.Parse).ToList();
public static List<long> LongList => StrArr.Select(long.Parse).ToList();
public static IEnumerable<long[]> TakeLine(int N) {
return Enumerable.Repeat(0, N).Select(
_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
}
public static string NextWord() {
while (!enumerator.MoveNext()) {
enumerator = StrArr.AsEnumerable().GetEnumerator();
}
return enumerator.Current;
}
}
}
namespace Library {
class Modular {
public const int mod = 1000000007;
public readonly long value;
public Modular(long value) { this.value = value; }
public static implicit operator Modular(long a) {
var m = a % mod;
return new Modular((m < 0) ? m + mod : m);
}
public static Modular operator +(Modular a, Modular b) {
return a.value + b.value;
}
public static Modular operator -(Modular a, Modular b) {
return a.value - b.value;
}
public static Modular operator *(Modular a, Modular b) {
return a.value * b.value;
}
public static Modular Pow(Modular a, int n) {
switch (n) {
case 0:
return 1;
case 1:
return a;
default:
var p = Pow(a, n / 2);
return p * p * Pow(a, n % 2);
}
}
public static Modular operator /(Modular a, Modular b) {
return a * Pow(b, mod - 2);
}
private static readonly List<int> facs = new List<int> { 1 };
private static Modular Fac(int n) {
for (int i = facs.Count; i <= n; ++i) {
facs.Add((int)(Math.BigMul(facs.Last(), i) % mod));
}
return facs[n];
}
public static Modular Ncr(int n, int r) {
return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(Modular a) { return (int)a.value; }
}
}
namespace Library {
class MyMath {
public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); }
public static long Sqrt(long n) {
if (n < 0)
return 0;
long a = 0, tmp = 0, b = 0;
for (int i = 62; i >= 0; i -= 2) {
tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
a = a << 1 | tmp;
n -= (((b << 1) + 1) * tmp) << i;
b = (b << 1) + tmp + tmp;
}
return a;
}
public static long Nck(int n, int k) {
if (k == 0)
return 1;
if (n == 0)
return 0;
return n * Nck(n - 1, k - 1) / k;
}
}
}
namespace Library {
public class PriorityQueue<T> {
readonly List<T> _heap = new List<T>();
readonly Comparison<T> _comparison;
public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; }
public PriorityQueue() : this(Comparer<T>.Default.Compare) {}
public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {}
public void Enqueue(T item) {
_heap.Add(item);
int childID = _heap.Count - 1;
int parentID = (childID - 1) / 2;
while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) {
Swap(parentID, childID);
childID = parentID;
parentID = (parentID - 1) / 2;
}
}
public T Dequeue() {
var first = _heap.First();
_heap[0] = _heap.Last();
_heap.RemoveAt(_heap.Count - 1);
int parentID = 0;
int childID = parentID * 2 + 2;
if (childID >= _heap.Count ||
_comparison(_heap[childID], _heap[childID - 1]) > 0)
childID--;
while (childID < _heap.Count &&
_comparison(_heap[parentID], _heap[childID]) > 0) {
Swap(parentID, childID);
parentID = childID;
childID = parentID * 2 + 2;
if (childID >= _heap.Count ||
_comparison(_heap[childID], _heap[childID - 1]) > 0)
childID--;
}
return first;
}
void Swap(int parent, int child) {
var tmp = _heap[parent];
_heap[parent] = _heap[child];
_heap[child] = tmp;
}
public T Peek() { return _heap[0]; }
public int Count => _heap.Count;
public bool Any() { return _heap.Any(); }
public List<T> Data => _heap;
}
}
namespace Library {
public class UnionFind {
public int[] Parents { get; set; }
public UnionFind(int size) {
Parents = Enumerable.Repeat(-1, size).ToArray();
}
public int Find(int num) {
if (Parents[num] < 0)
return num;
Parents[num] = Find(Parents[num]);
return Parents[num];
}
public int Size(int num) { return -Parents[Find(num)]; }
public bool Same(int a, int b) { return Find(a) == Find(b); }
public void Unite(int a, int b) {
int x = Find(a), y = Find(b);
if (Size(x) > Size(y)) {
Parents[x] += Parents[y];
Parents[y] = x;
} else {
Parents[y] += Parents[x];
Parents[x] = y;
}
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 1,638
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
/**
* 部分集合の組が共通の要素を一つもつので、共通要素から元の部分集合を構成する。
* S1,S2 => A
* S1,S3 => B
* ならば、S1 = {A,B}ということがわかる。
* また、kC2個のパターンが存在しており、それはNと一致していなければならない。
* したがって、以下の方針で問題を解くことが可能となる。
* ①N=kC2からkを確定する。
* ②kC2の組み合わせを網羅して、共通要素を昇順に割り当てる
* ③共通要素をあつめて部分集合Siを構成する
*
* <see cref="http://tutuz.hateblo.jp/entry/2018/10/28/085507"/>
*/
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
int k = 0;
for (int i = N; i >= 1; i--) {
if (2 * N == i * (i - 1)) {
k = i;
break;
}
}
if (N == 1) {
Console.WriteLine("Yes");
Console.WriteLine(1);
Console.WriteLine("1 1");
Console.WriteLine("1 1");
return;
}
if (k == 0) {
Console.WriteLine("No");
return;
}
var S = new List<List<int>>(k);
var indexList = new int[k];
for (int i = 0; i < k; i++) {
indexList[i] = i;
S.Add(new List<int>(N));
}
var combList = Combination.Enumerate(indexList, 2, false).ToArray();
var n = 1;
foreach (var comb in combList) {
S[comb[0]].Add(n);
S[comb[1]].Add(n);
n++;
}
Console.WriteLine("Yes");
Console.WriteLine(k);
for (int i = 0; i < S.Count; i++) {
var ans = new System.Text.StringBuilder();
var count = S[i].Count;
ans.Append(count);
foreach (var value in S[i]) {
ans.Append(" " + value);
}
Console.WriteLine(ans);
}
}
/**
* 組み合わせを求める
* <see cref="https://qiita.com/gushwell/items/74a96f56ccb64db3660c"/>
*/
public static class Combination {
public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k,
bool withRepetition) {
if (k == 1) {
foreach (var item in items)
yield return new T[] { item };
yield break;
}
foreach (var item in items) {
var leftside = new T[] { item };
// item よりも前のものを除く (順列と組み合わせの違い)
// 重複を許さないので、unusedから item そのものも取り除く
var unused =
withRepetition
? items
: items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();
foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
yield return leftside.Concat(rightside).ToArray();
}
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
/**
* 部分集合の組が共通の要素を一つもつので、共通要素から元の部分集合を構成する。
* S1,S2 => A
* S1,S3 => B
* ならば、S1 = {A,B}ということがわかる。
* また、kC2個のパターンが存在しており、それはNと一致していなければならない。
* したがって、以下の方針で問題を解くことが可能となる。
* ①N=kC2からkを確定する。
* ②kC2の組み合わせを網羅して、共通要素を昇順に割り当てる
* ③共通要素をあつめて部分集合Siを構成する
*
* <see cref="http://tutuz.hateblo.jp/entry/2018/10/28/085507"/>
*/
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
int k = 0;
for (int i = N; i >= 1; i--) {
if (2 * N == i * (i - 1)) {
k = i;
break;
}
}
if (N == 1) {
Console.WriteLine("Yes");
Console.WriteLine(2);
Console.WriteLine("1 1");
Console.WriteLine("1 1");
return;
}
if (k == 0) {
Console.WriteLine("No");
return;
}
var S = new List<List<int>>(k);
var indexList = new int[k];
for (int i = 0; i < k; i++) {
indexList[i] = i;
S.Add(new List<int>(N));
}
var combList = Combination.Enumerate(indexList, 2, false).ToArray();
var n = 1;
foreach (var comb in combList) {
S[comb[0]].Add(n);
S[comb[1]].Add(n);
n++;
}
Console.WriteLine("Yes");
Console.WriteLine(k);
for (int i = 0; i < S.Count; i++) {
var ans = new System.Text.StringBuilder();
var count = S[i].Count;
ans.Append(count);
foreach (var value in S[i]) {
ans.Append(" " + value);
}
Console.WriteLine(ans);
}
}
/**
* 組み合わせを求める
* <see cref="https://qiita.com/gushwell/items/74a96f56ccb64db3660c"/>
*/
public static class Combination {
public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k,
bool withRepetition) {
if (k == 1) {
foreach (var item in items)
yield return new T[] { item };
yield break;
}
foreach (var item in items) {
var leftside = new T[] { item };
// item よりも前のものを除く (順列と組み合わせの違い)
// 重複を許さないので、unusedから item そのものも取り除く
var unused =
withRepetition
? items
: items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();
foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
yield return leftside.Concat(rightside).ToArray();
}
}
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 512
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
class Dmondai {
static void Main() {
var N = Int32.Parse(Console.ReadLine());
var k = 0;
for (int i = 0; i <= N; ++i)
if (i * (i - 1) == 2 * N)
k = i;
if (k == 0) {
Console.WriteLine("No");
return;
}
Console.WriteLine("Yes");
Console.WriteLine(k);
var array = new int[k, k - 1];
for (int i = 0; i < k; ++i)
for (int j = 0; j < k - 1; ++j)
array[i, j] = -1;
for (int i = 0; i < k; ++i) {
Console.Write(k - 1);
var num = 0;
var index = 1;
for (int j = 0; j < k - 1; ++j) {
Console.Write(" ");
if (i == 0)
num = j + 1;
else if (i == 1) {
if (j == 0)
num = j + 1;
else
num = array[i - 1, k - 2] + j;
} else {
if (i <= j) {
num = array[i - 1, k - 2] + index;
index++;
} else
num = array[j, i - 1];
}
array[i, j] = num;
Console.Write(num);
}
Console.WriteLine();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Dmondai {
static void Main() {
var N = Int32.Parse(Console.ReadLine());
var k = 0;
for (int i = 0; i <= N; ++i)
if (i * (i + 1) == 2 * N)
k = i + 1;
if (k == 0) {
Console.WriteLine("No");
return;
}
Console.WriteLine("Yes");
Console.WriteLine(k);
var array = new int[k, k - 1];
for (int i = 0; i < k; ++i)
for (int j = 0; j < k - 1; ++j)
array[i, j] = -1;
for (int i = 0; i < k; ++i) {
Console.Write(k - 1);
var num = 0;
var index = 1;
for (int j = 0; j < k - 1; ++j) {
Console.Write(" ");
if (i == 0)
num = j + 1;
else if (i == 1) {
if (j == 0)
num = j + 1;
else
num = array[i - 1, k - 2] + j;
} else {
if (i <= j) {
num = array[i - 1, k - 2] + index;
index++;
} else
num = array[j, i - 1];
}
array[i, j] = num;
Console.Write(num);
}
Console.WriteLine();
}
}
}
|
[["-", 15, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 8, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 57, 64, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 339
| 4
|
using System;
class Program {
static void Main() {
long n = long.Parse(Console.ReadLine());
long a = 0, b = 0;
for (long i = 2; i <= n; i++) {
if (i * (i + 1) == n * 2) {
a = i;
b = i + 1;
break;
}
}
if (a == 0) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
Console.WriteLine("{0}", b);
long[][] arr = new long [b][];
long k = 1;
for (long i = 0; i < b; i++) {
arr[i] = new long[a + 1];
arr[i][0] = a;
for (long j = 1; j < b; j++) {
if (i < j) {
arr[i][j] = k;
k++;
} else {
arr[i][j] = arr[j - 1][i];
}
}
Console.WriteLine(String.Join(" ", arr[i]));
}
}
}
}
|
using System;
class Program {
static void Main() {
long n = long.Parse(Console.ReadLine());
long a = 0, b = 0;
for (long i = 0; i <= n; i++) {
if (i * (i + 1) == n * 2) {
a = i;
b = i + 1;
break;
}
}
if (a == 0) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
Console.WriteLine("{0}", b);
long[][] arr = new long [b][];
long k = 1;
for (long i = 0; i < b; i++) {
arr[i] = new long[a + 1];
arr[i][0] = a;
for (long j = 1; j < b; j++) {
if (i < j) {
arr[i][j] = k;
k++;
} else {
arr[i][j] = arr[j - 1][i];
}
}
Console.WriteLine(String.Join(" ", arr[i]));
}
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 257
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var o = Ints;
var N = o[0];
var M = o[1];
var S = Str;
var T = Str;
var x = LCM(N, M);
var a = N / GCD(N, M);
var b = x / GCD(N, M);
for (int i = 0; i < GCD(N, M); ++i) {
var p = (int)a * i;
var q = (int)b * i;
if (S[p] != T[q]) {
Put(-1);
return;
}
}
Put(x);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
if (r > n - r)
r = n - r;
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno = (Deno * i) % MOD;
Nume = Nume * (n - i + 1) % MOD;
}
return (Nume * inv(Deno)) % MOD;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
public static long inv(long x, int MOD = 1000000007) {
return Power(x, MOD - 2, MOD);
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
public static string ConvertBase(long N, int K) {
StringBuilder ret = new StringBuilder();
while (N > 0) {
var r = N % K;
N /= K;
ret.Append(r);
}
return new string(ret.ToString().ToCharArray().Reverse().ToArray());
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Put(string a) => Console.WriteLine(a);
public static void Put(params object[] i) => Put(string.Join(" ", i));
public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a));
public static void VerticalPut<T>(IEnumerable<T> a) {
foreach (var z in a)
Put(z);
}
public static void YN(bool i) {
if (i)
Put("Yes");
else
Put("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var o = Ints;
var N = o[0];
var M = o[1];
var S = Str;
var T = Str;
var x = LCM(N, M);
var a = N / GCD(N, M);
var b = M / GCD(N, M);
for (int i = 0; i < GCD(N, M); ++i) {
var p = (int)a * i;
var q = (int)b * i;
if (S[p] != T[q]) {
Put(-1);
return;
}
}
Put(x);
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long a, long b, long MOD = 1000000007) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
public static long Power2(long a, long b) // i^N
{
long res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
public static long GCD(long a, long b) {
while (b > 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static long LCM(long a, long b) => (b / GCD(a, b)) * a;
public static long Comb(long n, long r, int MOD = 1000000007) {
if (r > n - r)
r = n - r;
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno = (Deno * i) % MOD;
Nume = Nume * (n - i + 1) % MOD;
}
return (Nume * inv(Deno)) % MOD;
}
public static long Comb2(long n, long r) {
long Nume = 1;
long Deno = 1;
if (r > n - r)
r = n - r;
for (long i = 1; i <= r; ++i) {
Deno *= i;
Nume *= n - i + 1;
}
return Nume / Deno;
}
public static long inv(long x, int MOD = 1000000007) {
return Power(x, MOD - 2, MOD);
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
public static string ConvertBase(long N, int K) {
StringBuilder ret = new StringBuilder();
while (N > 0) {
var r = N % K;
N /= K;
ret.Append(r);
}
return new string(ret.ToString().ToCharArray().Reverse().ToArray());
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Put(string a) => Console.WriteLine(a);
public static void Put(params object[] i) => Put(string.Join(" ", i));
public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a));
public static void VerticalPut<T>(IEnumerable<T> a) {
foreach (var z in a)
Put(z);
}
public static void YN(bool i) {
if (i)
Put("Yes");
else
Put("No");
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22]]
| 8
| 1,163
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var nm = ReadLib.ReadAsIntArray();
var s = Console.ReadLine();
var t = Console.ReadLine();
Console.WriteLine(Calculation.Calculate(nm[0], nm[1], s, t));
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class Calculation {
internal static long Calculate(int n, int m, string s, string t) {
var lcm = MyMath.Lcm(n, m);
var dn = (int)(lcm / n);
var nths = Enumerable.Range(0, n).Select(i => 1 + Math.BigMul(i, dn));
var dm = (int)(lcm / m);
var mths = Enumerable.Range(0, m).Select(i => i + Math.BigMul(i, dm));
var intersectNth = nths.Intersect(mths);
foreach (var i in intersectNth) {
var nth = (int)((i - 1) / dn);
var mth = (int)((i - 1) / dm);
if (s[nth] != t[mth]) {
return -1;
}
}
return lcm;
}
}
static class ReadLib {
public static long ReadAsLong() { return long.Parse(Console.ReadLine()); }
public static int ReadAsInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadAsIntArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) + step)
.ToArray();
}
public static long[] ReadAsLongArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => long.Parse(s) + step)
.ToArray();
}
public static ulong[] ReadAsULongArray() {
return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
}
public static string[] ReadAsStringArray() {
return Console.ReadLine().Split(' ');
}
public static int[] ReadNTimesAsInt(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => int.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static int[][] ReadNTimesAsIntArray(int n, int step = 0) {
return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray();
}
public static string[] ReadNTimesAsString(int n) {
return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray();
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
public static ModCombination ModCombination(int maxN, int mod = 1000000007) {
return new ModCombination(maxN, mod);
}
/// <summary>a^n mod</summary>
public static int ModPow(int a, int n, int mod = 1000000007) {
var res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける
}
a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2
n >>= 1;
}
return res;
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator -(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value - item2.Value;
if (value < 0) {
value += item1.Mod;
}
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
return item1 + new ModInt(item2, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
return item1 * new ModInt(item2, item1.Mod);
}
public static ModInt operator -(ModInt item1, int item2) {
return item1 - new ModInt(item2, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
/// <summary>組み合わせ</summary>
class ModCombination {
private int mod;
private int[] fac;
private int[] finv;
private int[] inv;
public ModCombination(int max, int mod = 1000000007) {
this.mod = mod;
fac = new int[max]; // modが法のn!の列
inv = new int[max]; // indexの逆元の列
finv = new int[max]; // modを法とした、invの累積の累積
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める
var s = Math.BigMul(inv[mod % i], mod / i) % mod;
inv[i] = (int)(mod - s);
// iに対する逆元を求める
finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod);
}
}
/// <summary>nCk</summary>
public int Calculation(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (int)(Math.BigMul(fac[n],
(int)(Math.BigMul(finv[k], finv[n - k]) % mod)) %
mod);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var nm = ReadLib.ReadAsIntArray();
var s = Console.ReadLine();
var t = Console.ReadLine();
Console.WriteLine(Calculation.Calculate(nm[0], nm[1], s, t));
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class Calculation {
internal static long Calculate(int n, int m, string s, string t) {
var lcm = MyMath.Lcm(n, m);
var dn = (int)(lcm / n);
var nths = Enumerable.Range(0, n).Select(i => 1 + Math.BigMul(i, dn));
var dm = (int)(lcm / m);
var mths = Enumerable.Range(0, m).Select(i => 1 + Math.BigMul(i, dm));
var intersectNth = nths.Intersect(mths);
foreach (var i in intersectNth) {
var nth = (int)((i - 1) / dn);
var mth = (int)((i - 1) / dm);
if (s[nth] != t[mth]) {
return -1;
}
}
return lcm;
}
}
static class ReadLib {
public static long ReadAsLong() { return long.Parse(Console.ReadLine()); }
public static int ReadAsInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadAsIntArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) + step)
.ToArray();
}
public static long[] ReadAsLongArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => long.Parse(s) + step)
.ToArray();
}
public static ulong[] ReadAsULongArray() {
return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
}
public static string[] ReadAsStringArray() {
return Console.ReadLine().Split(' ');
}
public static int[] ReadNTimesAsInt(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => int.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static int[][] ReadNTimesAsIntArray(int n, int step = 0) {
return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray();
}
public static string[] ReadNTimesAsString(int n) {
return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray();
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
public static ModCombination ModCombination(int maxN, int mod = 1000000007) {
return new ModCombination(maxN, mod);
}
/// <summary>a^n mod</summary>
public static int ModPow(int a, int n, int mod = 1000000007) {
var res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける
}
a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2
n >>= 1;
}
return res;
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator -(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value - item2.Value;
if (value < 0) {
value += item1.Mod;
}
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
return item1 + new ModInt(item2, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
return item1 * new ModInt(item2, item1.Mod);
}
public static ModInt operator -(ModInt item1, int item2) {
return item1 - new ModInt(item2, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
/// <summary>組み合わせ</summary>
class ModCombination {
private int mod;
private int[] fac;
private int[] finv;
private int[] inv;
public ModCombination(int max, int mod = 1000000007) {
this.mod = mod;
fac = new int[max]; // modが法のn!の列
inv = new int[max]; // indexの逆元の列
finv = new int[max]; // modを法とした、invの累積の累積
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める
var s = Math.BigMul(inv[mod % i], mod / i) % mod;
inv[i] = (int)(mod - s);
// iに対する逆元を求める
finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod);
}
}
/// <summary>nCk</summary>
public int Calculation(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (int)(Math.BigMul(fac[n],
(int)(Math.BigMul(finv[k], finv[n - k]) % mod)) %
mod);
}
}
|
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 203]]
| 8
| 2,155
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
int M = cin.nextInt();
string S = cin.next();
string T = cin.next();
long ans = long.MaxValue;
for (int t = 1; t <= M; t++) {
long L = (long)N * t;
if (L % N != 0)
continue;
if (L % M != 0)
continue;
long stepA = L / N;
long stepB = L / M;
int i = 0;
int j = 0;
bool flag = true;
while (i < N && j < M) {
if (i * stepA == j * stepB) {
if (S[i] != T[j]) {
flag = false;
break;
}
i++;
j++;
} else if (i * stepB < j * stepB)
i++;
else
j++;
}
if (flag) {
ans = L;
break;
}
}
if (ans == long.MaxValue)
ans = -1;
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
int M = cin.nextInt();
string S = cin.next();
string T = cin.next();
long ans = long.MaxValue;
for (int t = 1; t <= M; t++) {
long L = (long)N * t;
if (L % N != 0)
continue;
if (L % M != 0)
continue;
long stepA = L / N;
long stepB = L / M;
int i = 0;
int j = 0;
bool flag = true;
while (i < N && j < M) {
if (i * stepA == j * stepB) {
if (S[i] != T[j]) {
flag = false;
break;
}
i++;
j++;
} else if (i * stepA < j * stepB)
i++;
else
j++;
}
if (flag) {
ans = L;
break;
}
}
if (ans == long.MaxValue)
ans = -1;
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
[["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22]]
| 8
| 661
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
// using System.Text;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
// using System.Numerics;
// using static System.Math;
using pair = Pair<int, int>;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
void chmax<T>(ref T a, T b)
where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
void chmin<T>(ref T a, T b)
where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }
void solve() {
int N = cin.nextint;
var ID = new int[2 * N];
var P = new int[2 * N];
var J = new pair[N];
long red = 0;
long blue = 0;
for (int i = 0; i < N; i++) {
ID[2 * i] = i;
ID[2 * i + 1] = i;
P[2 * i] = cin.nextint;
P[2 * i + 1] = cin.nextint;
red += P[2 * i];
blue += P[2 * i + 1];
J[i] = new pair(P[2 * i], P[2 * i + 1]);
}
long ans = Math.Min(red, blue);
Array.Sort(P, ID);
var cnt = new int[N];
long sum = 0;
for (int i = 0; i < N; i++) {
cnt[ID[i]]++;
sum += P[i];
}
for (int i = 0; i < N; i++) {
if (cnt[i] == 2) {
chmin(ref ans, sum);
} else if (cnt[i] == 1) {
if (ID[N - 1] == i) {
chmin(ref ans, sum - ID[N - 2] + Math.Max(J[i].f, J[i].s));
} else {
chmin(ref ans, sum - ID[N - 1] + Math.Max(J[i].f, J[i].s));
}
} else {
chmin(ref ans, sum - ID[N - 1] - ID[N - 2] + J[i].f + J[i].s);
}
}
WriteLine(ans);
}
}
class Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T f;
public U s;
public Pair(T f, U s) {
this.f = f;
this.s = s;
}
public int CompareTo(Pair<T, U> a) {
return f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
}
public override string ToString() { return f + " " + s; }
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan {
get { return ReadLine().Split(); }
}
public int[] scanint {
get { return Array.ConvertAll(scan, int.Parse); }
}
public long[] scanlong {
get { return Array.ConvertAll(scan, long.Parse); }
}
public double[] scandouble {
get { return Array.ConvertAll(scan, double.Parse); }
}
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint {
get { return int.Parse(next); }
}
public long nextlong {
get { return long.Parse(next); }
}
public double nextdouble {
get { return double.Parse(next); }
}
public string join<T>(IEnumerable<T> values) {
return string.Join(" ", values);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
// using System.Text;
// using System.Text.RegularExpressions;
// using System.Globalization;
// using System.Diagnostics;
using static System.Console;
// using System.Numerics;
// using static System.Math;
using pair = Pair<int, int>;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
void chmax<T>(ref T a, T b)
where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
void chmin<T>(ref T a, T b)
where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }
void solve() {
int N = cin.nextint;
var ID = new int[2 * N];
var P = new int[2 * N];
var J = new pair[N];
long red = 0;
long blue = 0;
for (int i = 0; i < N; i++) {
ID[2 * i] = i;
ID[2 * i + 1] = i;
P[2 * i] = cin.nextint;
P[2 * i + 1] = cin.nextint;
red += P[2 * i];
blue += P[2 * i + 1];
J[i] = new pair(P[2 * i], P[2 * i + 1]);
}
long ans = Math.Min(red, blue);
Array.Sort(P, ID);
var cnt = new int[N];
long sum = 0;
for (int i = 0; i < N; i++) {
cnt[ID[i]]++;
sum += P[i];
}
for (int i = 0; i < N; i++) {
if (cnt[i] == 2) {
chmin(ref ans, sum);
} else if (cnt[i] == 1) {
if (ID[N - 1] == i) {
chmin(ref ans, sum - P[N - 2] + Math.Max(J[i].f, J[i].s));
} else {
chmin(ref ans, sum - P[N - 1] + Math.Max(J[i].f, J[i].s));
}
} else {
chmin(ref ans, sum - P[N - 1] - P[N - 2] + J[i].f + J[i].s);
}
}
WriteLine(ans);
}
}
class Pair<T, U> : IComparable<Pair<T, U>>
where T : IComparable<T>
where U : IComparable<U> {
public T f;
public U s;
public Pair(T f, U s) {
this.f = f;
this.s = s;
}
public int CompareTo(Pair<T, U> a) {
return f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
}
public override string ToString() { return f + " " + s; }
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan {
get { return ReadLine().Split(); }
}
public int[] scanint {
get { return Array.ConvertAll(scan, int.Parse); }
}
public long[] scanlong {
get { return Array.ConvertAll(scan, long.Parse); }
}
public double[] scandouble {
get { return Array.ConvertAll(scan, double.Parse); }
}
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint {
get { return int.Parse(next); }
}
public long nextlong {
get { return long.Parse(next); }
}
public double nextdouble {
get { return double.Parse(next); }
}
public string join<T>(IEnumerable<T> values) {
return string.Join(" ", values);
}
}
|
[["-", 0, 28, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 12, 204, 205, 22], ["-", 31, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["+", 31, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["-", 0, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 31, 16, 12, 204, 205, 22]]
| 8
| 971
| 8
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static ABC122_20200406A.Input;
namespace ABC122_20200406A {
static class Input {
private static Func<string, T[]>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray();
private static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(string[]))
return _ => (T)(object)_.Split(' ');
if (t == typeof(int[]))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(long[]))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(double[]))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
private static T Convert<T>(string s) => Convert<T>()(s);
private static string String() => Console.ReadLine();
private static string[] String(long rowNumber) =>
new bool [rowNumber].Select(_ => String()).ToArray();
public static void Cin<T>(out T a) => a = Convert<T>(String());
public static void Cin<T1, T2>(out T1 a1, out T2 a2) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
}
public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
}
public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
}
public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4, out T5 a5) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
}
public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2,
out T3 a3, out T4 a4,
out T5 a5, out T6 a6) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
set(v[5], out a6);
}
private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s);
public static void
Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray();
public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) {
l1 = new T1[n];
l2 = new T2[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i]);
}
public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2,
out T3[] l3) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i]);
}
public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2,
out T3[] l3, out T4[] l4) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
l4 = new T4[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i], out l4[i]);
}
public static void Cin<T>(out T[] a) => a = Convert<T[]>(String());
public static void Cin<T>(long h, out T[][] map) => map =
String(h).Select(Convert<T[]>()).ToArray();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
public void Solve() {
string n;
Cin(out n);
if (n[0] == '1') {
Console.WriteLine("Hello World");
return;
}
int a, b;
Cin(out a, out b);
Console.WriteLine(a + b);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static ABC122_20200406A.Input;
namespace ABC122_20200406A {
static class Input {
private static Func<string, T[]>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray();
private static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(string[]))
return _ => (T)(object)_.Split(' ');
if (t == typeof(int[]))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(long[]))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(double[]))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
private static T Convert<T>(string s) => Convert<T>()(s);
private static string String() => Console.ReadLine();
private static string[] String(long rowNumber) =>
new bool [rowNumber].Select(_ => String()).ToArray();
public static void Cin<T>(out T a) => a = Convert<T>(String());
public static void Cin<T1, T2>(out T1 a1, out T2 a2) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
}
public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
}
public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
}
public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4, out T5 a5) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
}
public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2,
out T3 a3, out T4 a4,
out T5 a5, out T6 a6) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
set(v[5], out a6);
}
private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s);
public static void
Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray();
public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) {
l1 = new T1[n];
l2 = new T2[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i]);
}
public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2,
out T3[] l3) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i]);
}
public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2,
out T3[] l3, out T4[] l4) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
l4 = new T4[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i], out l4[i]);
}
public static void Cin<T>(out T[] a) => a = Convert<T[]>(String());
public static void Cin<T>(long h, out T[][] map) => map =
String(h).Select(Convert<T[]>()).ToArray();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
public void Solve() {
string n;
Cin(out n);
if (n[0] == '1') {
Console.WriteLine("Hello World");
return;
}
int a, b;
Cin(out a);
Cin(out b);
Console.WriteLine(a + b);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 1,427
| 5
|
using System;
namespace okayama__112 {
class Program {
static void Main(string[] args)
{
int n;
n = int.Parse(Console.ReadLine());
switch (n) {
case 1:
Console.WriteLine("Hell World");
break;
case 2:
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Console.WriteLine(a + b);
break;
}
}
}
}
|
using System;
namespace okayama__112 {
class Program {
static void Main(string[] args)
{
int n;
n = int.Parse(Console.ReadLine());
switch (n) {
case 1:
Console.WriteLine("Hello World");
break;
case 2:
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
Console.WriteLine(a + b);
break;
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 100
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.NothingToLearn {
class ABC112_A {
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();
if (n == 1) {
WriteLine("Hello world");
} else {
int a = ReadInt();
int b = ReadInt();
WriteLine(a + b);
}
}
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.NothingToLearn {
class ABC112_A {
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();
if (n == 1) {
WriteLine("Hello World");
} else {
int a = ReadInt();
int b = ReadInt();
WriteLine(a + b);
}
}
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, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 328
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC112A {
class Program {
static void Main(string[] args) {
int A, B, N, x;
N = int.Parse(Console.ReadLine());
if (N == 1)
//{ A = int.Parse(Console.ReadLine());
// B = int.Parse(Console.ReadLine());
// Console.WriteLine(A + B); }
Console.WriteLine("Hellow World");
else
{
A = int.Parse(Console.ReadLine());
B = int.Parse(Console.ReadLine());
Console.WriteLine(A + B);
}
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC112A {
class Program {
static void Main(string[] args) {
int A, B, N;
N = int.Parse(Console.ReadLine());
if (N == 1)
Console.WriteLine("Hello World");
else
{
A = int.Parse(Console.ReadLine());
B = int.Parse(Console.ReadLine());
Console.WriteLine(A + B);
}
Console.ReadKey();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 130
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Runtime.CompilerServices;
using static System.Console;
using static System.Math;
using static Ex;
using static Util;
using static IO_Z;
class AC {
/*------------------------------------------------------------------*/
void Solve() {
int n, a, b;
I(out n);
if (n == 1) {
"Hello Wprld".Prt();
} else {
I(out a, out b);
(a + b).Prt();
}
}
/*------------------------------------------------------------------*/
void Test() {
//--- TEST ---//
}
public static void Main(string[] args) => new AC().Stream();
private void Stream() {
SetOut(IO_Z.StreamWriter);
/*
var exStdIn = new http://System.IO .StreamReader("stdin.txt");
SetIn(exStdIn);
Test();
*/
Solve();
Flush();
}
}
static class IO_Z {
private static int Size = 1 << 12;
private static readonly Stream Stream = OpenStandardInput();
private static readonly byte[] Buffer = new byte[Size];
private static int _ptr = 0, _buffLen = 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool HasNextByte() {
if (_ptr < _buffLen)
return true;
_ptr = 0;
_buffLen = Stream.Read(Buffer, 0, Size);
return _buffLen > 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static byte ReadByte() {
if (HasNextByte())
return Buffer[_ptr++];
else
throw new EndOfStreamException("inputの末尾の改行がないとerror");
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsAscii(int c) => '!' <= c && c <= '~';
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static char NextChar() {
var b = ReadByte();
while (!IsAscii(b))
b = ReadByte();
return (char)b;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static string Next() {
var sb = new StringBuilder();
for (var b = NextChar(); IsAscii(b); b = (char)ReadByte())
sb.Append(b);
return sb.ToString();
}
public static string Str => Next();
public static char Cha => NextChar();
public static int Int => int.Parse(Next());
public static long Long => long.Parse(Next());
public static double Double => double.Parse(Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Scan<T>(ref T x) {
if (x is int)
__refvalue(__makeref(x), int) = int.Parse(Next());
else if (x is long)
__refvalue(__makeref(x), long) = long.Parse(Next());
else if (x is double)
__refvalue(__makeref(x), double) = double.Parse(Next());
else if (x is char)
__refvalue(__makeref(x), char) = NextChar();
else
__refvalue(__makeref(x), string) = Next();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T>(out T t) {
t = default(T);
Scan(ref t);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU>(out T t, out TU u) {
I(out t);
I(out u);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU, TV>(out T t, out TU u, out TV v) {
I(out t, out u);
I(out v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
I(out t, out u);
I(out v, out w);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
I(out t, out u, out v);
I(out w, out x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v,
out TW w, out TX x, out TY y) {
I(out t, out u, out v);
I(out w, out x, out y);
}
public static void I<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
I(out a[i]);
}
public static void I<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i)
I(out a[i], out b[i]);
}
public static void I<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (var i = 0; i < n; ++i)
I(out a[i], out b[i], out c[i]);
}
public static void I<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
I(out a[i, j]);
}
public static readonly StreamWriter StreamWriter =
new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public static void Flush() => Out.Flush();
public static void Prt<T>(this T x) => WriteLine(x);
public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x));
}
static class Ex {
public static T[] Arr<T>(params T[] xs) => xs;
public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) {
foreach (var x in xs)
f(x);
}
}
static class Util {
public static T IF<T>(bool b, Func<T> fTrue, Func<T> fFalse) {
if (b)
return fTrue();
else
return fFalse();
}
public static T LOCAL<T>(Func<T> f) => f();
public static void FOR(int a, int b, int n, Action<int> f) {
for (int i = a; i < b; i += n)
f(i);
}
public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f);
public static void REP(int a, Action<int> f) => FOR(0, a, f);
public static void
REP(int a, int b, Action<int, int> f) => REP(a, i => REP(b, j => f(i, j)));
public static void REP(int a, int b, int c, Action<int, int, int> f) =>
REP(a, i => REP(b, j => REP(c, k => f(i, j, k))));
public static T MIN<T>(params T[] xs) => xs.Min();
public static T MAX<T>(params T[] xs) => xs.Max();
public static IEnumerable<int> RANGE(int s,
int e) => Enumerable.Range(s, e - s + 1);
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Runtime.CompilerServices;
using static System.Console;
using static System.Math;
using static Ex;
using static Util;
using static IO_Z;
class AC {
/*------------------------------------------------------------------*/
void Solve() {
int n, a, b;
I(out n);
if (n == 1) {
"Hello World".Prt();
} else {
I(out a, out b);
(a + b).Prt();
}
}
/*------------------------------------------------------------------*/
void Test() {
//--- TEST ---//
}
public static void Main(string[] args) => new AC().Stream();
private void Stream() {
SetOut(IO_Z.StreamWriter);
/*
var exStdIn = new http://System.IO .StreamReader("stdin.txt");
SetIn(exStdIn);
Test();
*/
Solve();
Flush();
}
}
static class IO_Z {
private static int Size = 1 << 12;
private static readonly Stream Stream = OpenStandardInput();
private static readonly byte[] Buffer = new byte[Size];
private static int _ptr = 0, _buffLen = 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool HasNextByte() {
if (_ptr < _buffLen)
return true;
_ptr = 0;
_buffLen = Stream.Read(Buffer, 0, Size);
return _buffLen > 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static byte ReadByte() {
if (HasNextByte())
return Buffer[_ptr++];
else
throw new EndOfStreamException("inputの末尾の改行がないとerror");
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsAscii(int c) => '!' <= c && c <= '~';
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static char NextChar() {
var b = ReadByte();
while (!IsAscii(b))
b = ReadByte();
return (char)b;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static string Next() {
var sb = new StringBuilder();
for (var b = NextChar(); IsAscii(b); b = (char)ReadByte())
sb.Append(b);
return sb.ToString();
}
public static string Str => Next();
public static char Cha => NextChar();
public static int Int => int.Parse(Next());
public static long Long => long.Parse(Next());
public static double Double => double.Parse(Next());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Scan<T>(ref T x) {
if (x is int)
__refvalue(__makeref(x), int) = int.Parse(Next());
else if (x is long)
__refvalue(__makeref(x), long) = long.Parse(Next());
else if (x is double)
__refvalue(__makeref(x), double) = double.Parse(Next());
else if (x is char)
__refvalue(__makeref(x), char) = NextChar();
else
__refvalue(__makeref(x), string) = Next();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T>(out T t) {
t = default(T);
Scan(ref t);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU>(out T t, out TU u) {
I(out t);
I(out u);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU, TV>(out T t, out TU u, out TV v) {
I(out t, out u);
I(out v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
I(out t, out u);
I(out v, out w);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
I(out t, out u, out v);
I(out w, out x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void I<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v,
out TW w, out TX x, out TY y) {
I(out t, out u, out v);
I(out w, out x, out y);
}
public static void I<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
I(out a[i]);
}
public static void I<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i)
I(out a[i], out b[i]);
}
public static void I<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (var i = 0; i < n; ++i)
I(out a[i], out b[i], out c[i]);
}
public static void I<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
I(out a[i, j]);
}
public static readonly StreamWriter StreamWriter =
new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public static void Flush() => Out.Flush();
public static void Prt<T>(this T x) => WriteLine(x);
public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x));
}
static class Ex {
public static T[] Arr<T>(params T[] xs) => xs;
public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) {
foreach (var x in xs)
f(x);
}
}
static class Util {
public static T IF<T>(bool b, Func<T> fTrue, Func<T> fFalse) {
if (b)
return fTrue();
else
return fFalse();
}
public static T LOCAL<T>(Func<T> f) => f();
public static void FOR(int a, int b, int n, Action<int> f) {
for (int i = a; i < b; i += n)
f(i);
}
public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f);
public static void REP(int a, Action<int> f) => FOR(0, a, f);
public static void
REP(int a, int b, Action<int, int> f) => REP(a, i => REP(b, j => f(i, j)));
public static void REP(int a, int b, int c, Action<int, int, int> f) =>
REP(a, i => REP(b, j => REP(c, k => f(i, j, k))));
public static T MIN<T>(params T[] xs) => xs.Min();
public static T MAX<T>(params T[] xs) => xs.Max();
public static IEnumerable<int> RANGE(int s,
int e) => Enumerable.Range(s, e - s + 1);
}
|
[["-", 0, 1, 0, 213, 63, 214, 205, 5, 0, 222], ["+", 0, 1, 0, 213, 63, 214, 205, 5, 0, 222]]
| 8
| 1,716
| 2
|
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
class P {
static void Main() {
int i = int.Parse(Console.ReadLine());
if (i == 0) {
Console.WriteLine("Hello World");
return;
}
Console.WriteLine(int.Parse(Console.ReadLine()) +
int.Parse(Console.ReadLine()));
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
class P {
static void Main() {
int i = int.Parse(Console.ReadLine());
if (i == 1) {
Console.WriteLine("Hello World");
return;
}
Console.WriteLine(int.Parse(Console.ReadLine()) +
int.Parse(Console.ReadLine()));
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 131
| 2
|
//#define TEST
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Diagnostics;
class p {
static void Main() {
int[] nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
int n = nx[0], x = nx[1];
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(a);
#if TEST
foreach (var i in a)
Console.Write("{0} ", i);
Console.WriteLine();
#endif
int ans = 0;
int sum = 0;
for (int i = 0;; i++) {
try {
sum += a[i];
if (sum > x) {
ans = i;
break;
}
} catch {
ans = n;
break;
}
}
if (a.Sum() < x)
ans = n - 1;
Console.WriteLine(ans);
}
}
|
//#define TEST
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Diagnostics;
class p {
static void Main() {
int[] nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
int n = nx[0], x = nx[1];
long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
Array.Sort(a);
#if TEST
foreach (var i in a)
Console.Write("{0} ", i);
Console.WriteLine();
#endif
int ans = 0;
int sum = 0;
for (int i = 0;; i++) {
try {
sum += (int)a[i];
if (sum > x) {
ans = i;
break;
}
} catch {
ans = n;
break;
}
}
if (a.Sum() < x)
ans = n - 1;
Console.WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 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]]
| 8
| 219
| 7
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.AGC027 {
class Program {
static void Main() {
var sc = new Scanner();
var n = sc.Nextint();
var x = sc.Nextint();
var a = sc.Arrayint(n);
if (a.Sum() == x) {
Console.WriteLine(n);
return;
}
Array.Sort(a);
var total = 0;
for (var i = 0; i < n; i++) {
total += a[i];
if (total > x) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(n - 1);
return;
}
}
class Scanner {
string[] s;
long i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return Next();
i = 0;
return s[i++];
}
public int Nextint() { return int.Parse(Next()); }
public int[] Arrayint(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Nextint() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (long i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(long N, double add = 0) {
double[] Array = new double[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
public decimal NextDecimal() { return decimal.Parse(Next()); }
public decimal[] ArrayDecimal(long N, decimal add = 0) {
decimal[] Array = new decimal[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDecimal();
}
return Array;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.AGC027 {
class Program {
static void Main() {
var sc = new Scanner();
var n = sc.Nextint();
var x = sc.NextLong();
var a = sc.ArrayLong(n);
if (a.Sum() == x) {
Console.WriteLine(n);
return;
}
Array.Sort(a);
var total = 0L;
for (var i = 0; i < n; i++) {
total += a[i];
if (total > x) {
Console.WriteLine(i);
return;
}
}
Console.WriteLine(n - 1);
return;
}
}
class Scanner {
string[] s;
long i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return Next();
i = 0;
return s[i++];
}
public int Nextint() { return int.Parse(Next()); }
public int[] Arrayint(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Nextint() + add;
}
return Array;
}
public long NextLong() { return long.Parse(Next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (long i = 0; i < N; i++) {
Array[i] = NextLong() + add;
}
return Array;
}
public double NextDouble() { return double.Parse(Next()); }
public double[] ArrayDouble(long N, double add = 0) {
double[] Array = new double[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDouble() + add;
}
return Array;
}
public decimal NextDecimal() { return decimal.Parse(Next()); }
public decimal[] ArrayDecimal(long N, decimal add = 0) {
decimal[] Array = new decimal[N];
for (long i = 0; i < N; i++) {
Array[i] = NextDecimal();
}
return Array;
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 596
| 6
|
using System;
class Program {
static void Main() {
int[] s = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
Array.Sort(a);
int ans = 0;
for (int i = 0; i < s[0]; i++) {
s[1] -= a[i];
if (s[1] > -1) {
ans++;
}
}
if (s[1] > 0) {
ans--;
}
Console.WriteLine("{0}", ans);
}
}
|
using System;
class Program {
static void Main() {
long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
long[] a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
Array.Sort(a);
long ans = 0;
for (long i = 0; i < s[0]; i++) {
s[1] -= a[i];
if (s[1] > -1) {
ans++;
}
}
if (s[1] > 0) {
ans--;
}
Console.WriteLine("{0}", ans);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 143
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
using Number = System.Int64;
class Solver {
Scanner sc = new Scanner();
//
public void Solve() {
int N, M;
sc.Make(out N, out M);
var s = ReadLine();
var edge = Create(N, () => new List<int>());
for (var i = 0; i < M; i++) {
int a, b;
sc.Make(out a, out b);
a--;
b--;
edge[a].Add(b);
edge[b].Add(a);
}
var ct = new Pi[N];
var del = new bool[N];
var q = new Queue<int>();
for (var i = 0; i < N; i++) {
int a = 0, b = 0;
foreach (var e in edge[i]) {
if (s[e] == 'A')
a++;
else
b++;
}
if (a == 0 || b == 0) {
del[i] = true;
q.Enqueue(i);
}
ct[i] = new Pi(a, b);
}
while (q.Any()) {
var p = q.Dequeue();
foreach (var e in edge[p])
if (!del[e]) {
if (s[p] == 'A')
ct[e].v1--;
else
ct[e].v2--;
if (ct[e].v1 == 0 || ct[e].v2 == 0) {
del[e] = true;
q.Enqueue(e);
}
}
}
WriteLine(del.Any(p => p) ? "Yes" : "No");
}
}
#region Template
public class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == 1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == -1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T v1, ref T v2) {
var t = v2;
v2 = v1;
v1 = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(),
Next<T2>());
public Pair<T1, T2, T3> PairMake<T1, T2, T3>() =>
new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Tie(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Tie(out T1 a, out T2 b, out T3 c) {
Tie(out a, out b);
c = v3;
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;
using Number = System.Int64;
class Solver {
Scanner sc = new Scanner();
//
public void Solve() {
int N, M;
sc.Make(out N, out M);
var s = ReadLine();
var edge = Create(N, () => new List<int>());
for (var i = 0; i < M; i++) {
int a, b;
sc.Make(out a, out b);
a--;
b--;
edge[a].Add(b);
edge[b].Add(a);
}
var ct = new Pi[N];
var del = new bool[N];
var q = new Queue<int>();
for (var i = 0; i < N; i++) {
int a = 0, b = 0;
foreach (var e in edge[i]) {
if (s[e] == 'A')
a++;
else
b++;
}
if (a == 0 || b == 0) {
del[i] = true;
q.Enqueue(i);
}
ct[i] = new Pi(a, b);
}
while (q.Any()) {
var p = q.Dequeue();
foreach (var e in edge[p])
if (!del[e]) {
if (s[p] == 'A')
ct[e].v1--;
else
ct[e].v2--;
if (ct[e].v1 == 0 || ct[e].v2 == 0) {
del[e] = true;
q.Enqueue(e);
}
}
}
WriteLine(del.Any(p => !p) ? "Yes" : "No");
}
}
#region Template
public class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve();
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == 1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T num, T val)
where T : IComparable<T> {
if (num.CompareTo(val) == -1) {
num = val;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T v1, ref T v2) {
var t = v2;
v2 = v1;
v1 = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(),
Next<T2>());
public Pair<T1, T2, T3> PairMake<T1, T2, T3>() =>
new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Tie(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Tie(out T1 a, out T2 b, out T3 c) {
Tie(out a, out b);
c = v3;
}
}
#endregion
|
[["+", 3, 4, 0, 28, 0, 218, 8, 241, 0, 111]]
| 8
| 1,845
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC109A {
class Program {
static void Main(string[] args) {
var word = Console.ReadLine().Split();
int a = int.Parse(word[0]);
int b = int.Parse(word[1]);
var max = new int[3] { 1, 2, 3 };
int c, d, e;
c = a * b * max[0];
d = a * b * max[1];
e = a * b * max[2];
if (c % 2 == 0 || d % 2 == 0 || e % 2 == 0) {
Console.WriteLine("Yes");
} else
Console.WriteLine("No");
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC109A {
class Program {
static void Main(string[] args) {
var word = Console.ReadLine().Split();
int a = int.Parse(word[0]);
int b = int.Parse(word[1]);
var max = new int[3] { 1, 2, 3 };
int c, d, e;
c = a * b * max[0];
d = a * b * max[1];
e = a * b * max[2];
if (c % 2 == 0 && d % 2 == 0 && e % 2 == 0) {
Console.WriteLine("No");
} else
Console.WriteLine("Yes");
Console.ReadKey();
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 188
| 8
|
using System;
namespace AtCoder.ABC110 {
public class A {
public static void Solve() {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
Console.WriteLine((a * b) % 2 == 0 ? "Yes" : "No");
}
}
}
namespace AtCoder {
class Program {
static void Main(string[] args) { ABC110.A.Solve(); }
}
}
|
using System;
namespace AtCoder.ABC110 {
public class A {
public static void Solve() {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
Console.WriteLine((a * b) % 2 == 0 ? "No" : "Yes");
}
}
}
namespace AtCoder {
class Program {
static void Main(string[] args) { ABC110.A.Solve(); }
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 116
| 4
|
using System;
class Program {
static void Main() {
var sl = Console.ReadLine().Split(' ');
var a = int.Parse(sl[0]);
var b = int.Parse(sl[0]);
for (var c = 1; c <= 3; c++)
if ((a * b * c) % 2 != 0) {
Console.WriteLine("Yes");
return;
}
Console.WriteLine("No");
}
}
|
using System;
class Program {
static void Main() {
var sl = Console.ReadLine().Split(' ');
var a = int.Parse(sl[0]);
var b = int.Parse(sl[1]);
for (var c = 1; c <= 3; c++)
if ((a * b * c) % 2 != 0) {
Console.WriteLine("Yes");
return;
}
Console.WriteLine("No");
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 106
| 2
|
using System;
namespace ABC333A {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var A = int.Parse(input[0]);
var B = int.Parse(input[1]);
var flag = false;
for (int C = 1; C < 4; C++) {
if ((A * B * C) % 2 != 0) {
flag = true;
}
}
if (flag) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
}
|
using System;
namespace ABC333A {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var A = int.Parse(input[0]);
var B = int.Parse(input[1]);
var flag = false;
for (int C = 1; C < 4; C++) {
if ((A * B * C) % 2 != 0) {
flag = true;
}
}
if (flag) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 132
| 4
|
using System;
class MainClass {
public static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
string ans = "Yes";
if (a % 2 == 0 && b % 2 == 0) {
ans = "No";
}
Console.WriteLine(ans);
}
}
|
using System;
class MainClass {
public static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
string ans = "Yes";
if (a % 2 == 0 || b % 2 == 0) {
ans = "No";
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106]]
| 8
| 99
| 2
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line[0]);
var b = int.Parse(line[1]);
if (a * b % 2 == 0)
Console.WriteLine("No");
else
Console.WriteLine("YES");
}
}
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var a = int.Parse(line[0]);
var b = int.Parse(line[1]);
if (a * b % 2 == 0)
Console.WriteLine("No");
else
Console.WriteLine("Yes");
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 93
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
List<string> list = new List<string>();
int dameflg = 0;
for (int i = 0; i < N; i++) {
list.Add(Console.ReadLine());
if (i >= 1 && list[i].Substring(0, 0) !=
list[i - 1].Substring(list[i - 1].Length, 0)) {
dameflg++;
}
}
int baseCount = list.Count;
int distinctCount = (from x in list select x).Distinct().Count();
if (baseCount == distinctCount && dameflg == 0) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
List<string> list = new List<string>();
int dameflg = 0;
for (int i = 0; i < N; i++) {
list.Add(Console.ReadLine());
if (i >= 1 && list[i].Substring(0, 1) !=
list[i - 1].Substring(list[i - 1].Length - 1, 1)) {
dameflg++;
}
}
int baseCount = list.Count;
int distinctCount = (from x in list select x).Distinct().Count();
if (baseCount == distinctCount && dameflg == 0) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 12, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 198
| 6
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.