buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var x = cin.nextInt();
var y = cin.nextInt();
for (int tu = 0; tu <= x; tu++) {
var ka = x - tu;
var ans = tu * 2 + ka * 4;
if (ans == y) {
Console.WriteLine("YES");
return;
}
}
Console.WriteLine("NO");
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var x = cin.nextInt();
var y = cin.nextInt();
for (int tu = 0; tu <= x; tu++) {
var ka = x - tu;
var ans = tu * 2 + ka * 4;
if (ans == y) {
Console.WriteLine("Yes");
return;
}
}
Console.WriteLine("No");
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public int[] DPArrayInt(int N, int ex) {
int[] Array = new int[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextInt();
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public long[] DPArrayLong(int N, int ex) {
long[] Array = new long[N + ex];
for (int i = 0; i < N; i++) {
Array[i] = nextLong();
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 619
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Tasks {
public class C {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var (X, N) = Scanner.Scan<int, int>();
if (N == 0) {
Console.ReadLine();
Console.WriteLine(X);
return;
}
var P = Scanner.ScanEnumerable<int>().ToArray();
var list = Enumerable.Range(-1, 102).Except(P).ToArray();
var answer = (int)1e9;
var delta = (int)1e9;
foreach (var x in list) {
if (delta <= Math.Abs(X - x))
continue;
answer = x;
delta = Math.Abs(X - x);
}
Console.WriteLine(answer);
}
public static class Scanner {
private static Queue<string> queue = new Queue<string>();
public static T Next<T>() {
if (!queue.Any())
foreach (var item in Console.ReadLine().Trim().Split(" "))
queue.Enqueue(item);
return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
}
public static T Scan<T>() => Next<T>();
public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(),
Next<T3>());
public static (T1, T2, T3,
T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(),
Next<T3>(), Next<T4>());
public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() =>
(Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
public static IEnumerable<T>
ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(
x => (T)Convert.ChangeType(x, typeof(T)));
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Tasks {
public class C {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var (X, N) = Scanner.Scan<int, int>();
if (N == 0) {
Console.ReadLine();
Console.WriteLine(X);
return;
}
var P = Scanner.ScanEnumerable<int>().ToArray();
var list = Enumerable.Range(-1, 103).Except(P).ToArray();
var answer = (int)1e9;
var delta = (int)1e9;
foreach (var x in list) {
if (delta <= Math.Abs(X - x))
continue;
answer = x;
delta = Math.Abs(X - x);
}
Console.WriteLine(answer);
}
public static class Scanner {
private static Queue<string> queue = new Queue<string>();
public static T Next<T>() {
if (!queue.Any())
foreach (var item in Console.ReadLine().Trim().Split(" "))
queue.Enqueue(item);
return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
}
public static T Scan<T>() => Next<T>();
public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(),
Next<T3>());
public static (T1, T2, T3,
T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(),
Next<T3>(), Next<T4>());
public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() =>
(Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
public static IEnumerable<T>
ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(
x => (T)Convert.ChangeType(x, typeof(T)));
}
}
}
|
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 583
| 2
|
using System;
using System.Linq;
class IDONTKNOWCSHARP {
public static void Main() {
string[] values = Console.ReadLine().Split(
new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
int X = int.Parse(values[0]);
int N = int.Parse(values[1]);
int[] nums = Convert(Console.ReadLine().Split(
new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
int kouho1, kouho2;
int temp = 1;
while (true) {
if (!nums.Contains(X - temp)) {
kouho1 = X - temp;
break;
}
temp++;
}
temp = 1;
while (true) {
if (!nums.Contains(X + temp)) {
kouho2 = X + temp;
break;
}
temp++;
}
if (Math.Abs(kouho1 - X) > Math.Abs(kouho2 - X)) {
Console.WriteLine(kouho2 - X);
} else {
Console.WriteLine(kouho1 - X);
}
}
static int[] Convert(string[] v) {
var temp = new int[v.Length];
for (int i = 0; i < temp.Length; i++) {
temp[i] = int.Parse(v[i]);
}
return temp;
}
}
|
using System;
using System.Linq;
class IDONTKNOWCSHARP {
public static void Main() {
string[] values = Console.ReadLine().Split(
new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
int X = int.Parse(values[0]);
int N = int.Parse(values[1]);
int[] nums = Convert(Console.ReadLine().Split(
new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
int kouho1, kouho2;
int temp = 0;
while (true) {
if (!nums.Contains(X - temp)) {
kouho1 = X - temp;
break;
}
temp++;
}
temp = 0;
while (true) {
if (!nums.Contains(X + temp)) {
kouho2 = X + temp;
break;
}
temp++;
}
if (Math.Abs(kouho1 - X) > Math.Abs(kouho2 - X)) {
Console.WriteLine(kouho2);
} else {
Console.WriteLine(kouho1);
}
}
static int[] Convert(string[] v) {
var temp = new int[v.Length];
for (int i = 0; i < temp.Length; i++) {
temp[i] = int.Parse(v[i]);
}
return temp;
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 284
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int X = input[0];
int N = input[1];
if (N == 0) {
Console.WriteLine(X);
return;
}
int[] num = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 1; i <= 100; i++) {
if (!num.Contains(X - i)) {
Console.WriteLine(X - i);
return;
}
if (!num.Contains(X + i)) {
Console.WriteLine(X + i);
return;
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int X = input[0];
int N = input[1];
if (N == 0) {
Console.WriteLine(X);
return;
}
int[] num = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0; i <= 100; i++) {
if (!num.Contains(X - i)) {
Console.WriteLine(X - i);
return;
}
if (!num.Contains(X + i)) {
Console.WriteLine(X + i);
return;
}
}
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 197
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public int[] Sarray() {
return ReadLine().Split().Select(int.Parse).ToArray();
}
static public List<int> Slist() {
var t = ReadLine();
if (t.Trim().Length == 0)
return new List<int>();
return new List<int>(t.Split().Select(int.Parse));
}
static void Main(string[] args) {
var xn = Sarray();
var x = xn[0];
var n = xn[1];
var pn = Slist();
var ans = 101;
for (var i = 0; i <= 101; i++) {
if (Math.Abs(x - i) < Math.Abs(x - ans) && !pn.Contains(i))
ans = i;
}
WriteLine(ans);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public int[] Sarray() {
return ReadLine().Split().Select(int.Parse).ToArray();
}
static public List<int> Slist() {
var t = ReadLine();
if (t.Trim().Length == 0)
return new List<int>();
return new List<int>(t.Split().Select(int.Parse));
}
static void Main(string[] args) {
var xn = Sarray();
var x = xn[0];
var n = xn[1];
var pn = Slist();
var ans = 102;
for (var i = 0; i <= 101; i++) {
if (Math.Abs(x - i) < Math.Abs(x - ans) && !pn.Contains(i))
ans = i;
}
WriteLine(ans);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 278
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (x < y)
gcd(y, x);
while (y > 0) {
var z = x % y;
x = y;
y = z;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
var xn = Reads();
var x = xn[0];
var n = xn[1];
long[] p = new long[n];
if (n != 0)
p = Reads();
long ans = -100;
for (int i = -100; i <= 100; i++) {
if (!p.Contains(i) && Math.Abs(ans - x) > Math.Abs(i - x))
ans = i;
}
WriteLine(ans);
Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (x < y)
gcd(y, x);
while (y > 0) {
var z = x % y;
x = y;
y = z;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
var xn = Reads();
var x = xn[0];
var n = xn[1];
long[] p = new long[n];
if (n != 0)
p = Reads();
long ans = -100;
for (int i = -100; i <= 200; i++) {
if (!p.Contains(i) && Math.Abs(ans - x) > Math.Abs(i - x))
ans = i;
}
WriteLine(ans);
Out.Flush();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 307
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
hoge();
System.Console.ReadLine();
}
public static void hoge() {
var vars =
System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var x = vars[0];
var n = vars[1];
if (n == 0) {
System.Console.ReadLine();
Console.WriteLine(x);
return;
}
var p = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var ans = Enumerable.Range(1, 100).Where(v => !p.Contains(v)).ToList();
ans.Add(0);
ans.Add(-1);
ans = ans.OrderByDescending(v => v).ToList();
var sa = int.MaxValue;
var kotae = -1;
foreach (var v in ans) {
if (Math.Abs(v - x) <= sa) {
kotae = v;
sa = (int)Math.Abs(v - x);
}
}
Console.WriteLine(kotae);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
hoge();
System.Console.ReadLine();
}
public static void hoge() {
var vars =
System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var x = vars[0];
var n = vars[1];
if (n == 0) {
System.Console.ReadLine();
Console.WriteLine(x);
return;
}
var p = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var ans = Enumerable.Range(1, 100).Where(v => !p.Contains(v)).ToList();
ans.Add(0);
ans.Add(101);
ans = ans.OrderByDescending(v => v).ToList();
var sa = int.MaxValue;
var kotae = -1;
foreach (var v in ans) {
if (Math.Abs(v - x) <= sa) {
kotae = v;
sa = (int)Math.Abs(v - x);
}
}
Console.WriteLine(kotae);
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 268
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
//入力を保持する
var XN = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
var X = XN[0];
var N = XN[1];
// Ps配列が空の場合はXを出力して回答とする
if (N == 0) {
Console.WriteLine(X);
return;
}
var Ps = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
// Psを昇順に並び替える
Array.Sort(Ps);
// NのPs内に存在するかチェック
var idx = Array.IndexOf(Ps, N);
// NがPs配列に存在しない場合はXを出力して回答とする
if (idx == -1) {
Console.WriteLine(X);
return;
}
// Ps内に含まれないXに最も近い数字を±1をしながら検索する
var n = 1;
while (true) {
if (Array.IndexOf(Ps, X - n) == -1) {
Console.WriteLine(X - n);
break;
}
if (Array.IndexOf(Ps, X + n) == -1) {
Console.WriteLine(X + n);
break;
}
n += 1;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
//入力を保持する
var XN = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
var X = XN[0];
var N = XN[1];
// Ps配列が空の場合はXを出力して回答とする
if (N == 0) {
Console.WriteLine(X);
return;
}
var Ps = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
// Psを昇順に並び替える
Array.Sort(Ps);
// NのPs内に存在するかチェック
var idx = Array.IndexOf(Ps, X);
// NがPs配列に存在しない場合はXを出力して回答とする
if (idx == -1) {
Console.WriteLine(X);
return;
}
// Ps内に含まれないXに最も近い数字を±1をしながら検索する
var n = 1;
while (true) {
if (Array.IndexOf(Ps, X - n) == -1) {
Console.WriteLine(X - n);
break;
}
if (Array.IndexOf(Ps, X + n) == -1) {
Console.WriteLine(X + n);
break;
}
n += 1;
}
}
}
|
[["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 235
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
Program pg = new Program();
Console.WriteLine(pg.Exe());
}
public int Exe() {
int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int target_val = input[0];
int answer = target_val;
int num_cnt = input[1];
//数列の長さが0の場合、目標値が答えとなるので返す
if (num_cnt == 0)
return answer;
else
answer = 999999;
List<int> num_list = new List<int>(100);
for (int i = 0; i <= 100; i++) {
num_list.Add(i);
}
List<int> exclusion_numlist = new List<int>(
Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
IEnumerable<int> results = num_list.Except(exclusion_numlist);
int temp = 0;
int temptgt = answer - target_val;
foreach (int i in results) {
temp = Math.Abs(i - target_val);
if (temptgt > temp) {
answer = i;
temptgt = temp;
} else if (temptgt == temp && answer > i) {
answer = i;
temptgt = temp;
}
}
return answer;
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
Program pg = new Program();
Console.WriteLine(pg.Exe());
}
public int Exe() {
int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int target_val = input[0];
int answer = target_val;
int num_cnt = input[1];
//数列の長さが0の場合、目標値が答えとなるので返す
if (num_cnt == 0)
return answer;
else
answer = 999999;
List<int> num_list = new List<int>(200);
for (int i = 0; i <= 101; i++) {
num_list.Add(i);
}
List<int> exclusion_numlist = new List<int>(
Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse));
IEnumerable<int> results = num_list.Except(exclusion_numlist);
int temp = 0;
int temptgt = answer - target_val;
foreach (int i in results) {
temp = Math.Abs(i - target_val);
if (temptgt > temp) {
answer = i;
temptgt = temp;
} else if (temptgt == temp && answer > i) {
answer = i;
temptgt = temp;
}
}
return answer;
}
}
|
[["-", 0, 212, 0, 230, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 230, 3, 4, 0, 28, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 282
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public const long DpInf = 99999999999999;
public static void Main(string[] args) {
var p = Input().ToInt();
if (p[1] == 0) {
Console.WriteLine(p[0]);
return;
}
var a = Input().ToInt();
int ind = 0;
Array.Sort(a);
int min = 999;
int minInd = 999;
for (int i = 0; i <= 100; i++) {
if (ind < a.Length && i == a[ind]) {
ind++;
continue;
}
if (Math.Abs(i - p[0]) <= min) {
int min2 = Math.Min(Math.Abs(i - p[0]), min);
if ((min2 == min && minInd > i) || min2 < min) {
minInd = i;
min = min2;
}
}
}
Console.WriteLine(minInd);
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(); }
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str, int offset = 0) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt() + offset;
return r;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public const long DpInf = 99999999999999;
public static void Main(string[] args) {
var p = Input().ToInt();
if (p[1] == 0) {
Console.WriteLine(p[0]);
return;
}
var a = Input().ToInt();
int ind = 0;
Array.Sort(a);
int min = 999;
int minInd = 999;
for (int i = -100; i <= 101; i++) {
if (ind < a.Length && i == a[ind]) {
ind++;
continue;
}
if (Math.Abs(i - p[0]) <= min) {
int min2 = Math.Min(Math.Abs(i - p[0]), min);
if ((min2 == min && minInd > i) || min2 < min) {
minInd = i;
min = min2;
}
}
}
Console.WriteLine(minInd);
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(); }
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str, int offset = 0) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt() + offset;
return r;
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 423
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abcdef {
public class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// Input int array
int[] inputArray =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
int x = inputArray[0];
int n = inputArray[1];
if (n == 0) {
Console.WriteLine(x.ToString());
Console.Out.Flush();
return;
}
var hashSet = Console.ReadLine()
.Split(' ')
.Select(i => int.Parse(i))
.ToHashSet<int>();
// Write Code
bool foundUpper = false, foundLower = false;
int lowerResult = 0, upperResult = 0;
int diff = 0;
while (foundUpper == false && foundUpper == false) {
if (!hashSet.Contains(x - diff)) {
foundLower = true;
lowerResult = x - diff;
}
if (!hashSet.Contains(x + diff)) {
foundUpper = true;
upperResult = x + diff;
}
diff++;
}
if (foundLower == true) {
Console.WriteLine(lowerResult.ToString());
} else {
Console.WriteLine(upperResult.ToString());
}
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abcdef {
public class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// Input int array
int[] inputArray =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
int x = inputArray[0];
int n = inputArray[1];
if (n == 0) {
Console.WriteLine(x.ToString());
Console.Out.Flush();
return;
}
var hashSet = Console.ReadLine()
.Split(' ')
.Select(i => int.Parse(i))
.ToHashSet<int>();
// Write Code
bool foundUpper = false, foundLower = false;
int lowerResult = 0, upperResult = 0;
int diff = 0;
while (foundLower == false && foundUpper == false) {
if (!hashSet.Contains(x - diff)) {
foundLower = true;
lowerResult = x - diff;
}
if (!hashSet.Contains(x + diff)) {
foundUpper = true;
upperResult = x + diff;
}
diff++;
}
if (foundLower == true) {
Console.WriteLine(lowerResult.ToString());
} else {
Console.WriteLine(upperResult.ToString());
}
Console.Out.Flush();
}
}
}
|
[["-", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22]]
| 8
| 322
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace ABC170 {
using static Ex;
public class Solve {
public static void Main(string[] args) { new ABC_C(); }
}
public class ABC_A {
public ABC_A() {
var x = ReadIntArray();
for (int i = 0; i < x.Length; i++) {
if (x[i] != (i + 1)) {
(i + 1).Cw();
return;
}
}
}
}
public class ABC_B {
//総数はX匹で、それらの足の総数はY本
int x, y;
public ABC_B() {
(x, y) = ReadIntArray().ToTpl2();
// 2x-4x
int all = 2 * x;
if (all == y) {
"Yes".Cw();
return;
}
for (int i = 1; i <= x; i++) {
all += 2;
if (all == y) {
"Yes".Cw();
return;
}
}
"No".Cw();
}
}
public class ABC_C {
int x, n;
public ABC_C() {
(x, n) = ReadIntArray().ToTpl2();
if (n == 0) {
x.Cw();
return;
}
var p = ReadIntArray();
var set = new HashSet<int>(p);
int pl = x + 1;
int mi = x - 1;
while (true) {
if (!set.Any(v => v == mi)) {
mi.Cw();
return;
}
if (!set.Any(v => v == pl)) {
pl.Cw();
return;
}
pl++;
mi--;
}
}
}
public class ABC_D {
public ABC_D() {}
}
public class ABC_E {
public ABC_E() {}
}
public class ABC_F {
public ABC_F() {}
}
public static class Ex {
public static void Cw(this object s) { Console.WriteLine(s); }
public static bool Mins<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
public static bool Maxs<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
public static void Swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
public static void Swap<T>(List<T> list, int i, int j) {
T tmp = list[j];
list[j] = list[i];
list[i] = tmp;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }
public static string Read {
get { return Console.ReadLine().Trim(); }
}
public static int ReadInt {
get { return int.Parse(Read); }
}
public static long ReadLong {
get { return long.Parse(Read); }
}
public static double ReadDouble {
get { return double.Parse(Read); }
}
public static string[] ReadArray() { return Read.Split(' '); }
public static int[] ReadIntArray() {
return Read.Split(' ').Select(int.Parse).ToArray();
}
public static long[] ReadLongArray() {
return Read.Split(' ').Select(long.Parse).ToArray();
}
public static string[] ReadArray(long N) {
var v = new string[N];
for (long i = 0; i < N; ++i)
v[i] = Read;
return v;
}
public static int[] ReadIntArray(long N) {
var v = new int[N];
for (long i = 0; i < N; ++i)
v[i] = ReadInt;
return v;
}
public static long[] ReadLongArray(long N) {
var v = new long[N];
for (long i = 0; i < N; ++i)
v[i] = ReadLong;
return v;
}
public static (T, T) ToTpl2<T>(this T[] v) { return (v[0], v[1]); }
public static (T, T, T) ToTpl3<T>(this T[] v) { return (v[0], v[1], v[2]); }
public static (T, T, T, T) ToTpl4<T>(this T[] v) {
return (v[0], v[1], v[2], v[3]);
}
public static (T, T, T, T, T) ToTpl5<T>(this T[] v) {
return (v[0], v[1], v[2], v[3], v[4]);
}
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace ABC170 {
using static Ex;
public class Solve {
public static void Main(string[] args) { new ABC_C(); }
}
public class ABC_A {
public ABC_A() {
var x = ReadIntArray();
for (int i = 0; i < x.Length; i++) {
if (x[i] != (i + 1)) {
(i + 1).Cw();
return;
}
}
}
}
public class ABC_B {
//総数はX匹で、それらの足の総数はY本
int x, y;
public ABC_B() {
(x, y) = ReadIntArray().ToTpl2();
// 2x-4x
int all = 2 * x;
if (all == y) {
"Yes".Cw();
return;
}
for (int i = 1; i <= x; i++) {
all += 2;
if (all == y) {
"Yes".Cw();
return;
}
}
"No".Cw();
}
}
public class ABC_C {
int x, n;
public ABC_C() {
(x, n) = ReadIntArray().ToTpl2();
if (n == 0) {
x.Cw();
return;
}
var p = ReadIntArray();
var set = new HashSet<int>(p);
int pl = x;
int mi = x;
while (true) {
if (!set.Any(v => v == mi)) {
mi.Cw();
return;
}
if (!set.Any(v => v == pl)) {
pl.Cw();
return;
}
pl++;
mi--;
}
}
}
public class ABC_D {
public ABC_D() {}
}
public class ABC_E {
public ABC_E() {}
}
public class ABC_F {
public ABC_F() {}
}
public static class Ex {
public static void Cw(this object s) { Console.WriteLine(s); }
public static bool Mins<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
public static bool Maxs<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
public static void Swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
public static void Swap<T>(List<T> list, int i, int j) {
T tmp = list[j];
list[j] = list[i];
list[i] = tmp;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }
public static string Read {
get { return Console.ReadLine().Trim(); }
}
public static int ReadInt {
get { return int.Parse(Read); }
}
public static long ReadLong {
get { return long.Parse(Read); }
}
public static double ReadDouble {
get { return double.Parse(Read); }
}
public static string[] ReadArray() { return Read.Split(' '); }
public static int[] ReadIntArray() {
return Read.Split(' ').Select(int.Parse).ToArray();
}
public static long[] ReadLongArray() {
return Read.Split(' ').Select(long.Parse).ToArray();
}
public static string[] ReadArray(long N) {
var v = new string[N];
for (long i = 0; i < N; ++i)
v[i] = Read;
return v;
}
public static int[] ReadIntArray(long N) {
var v = new int[N];
for (long i = 0; i < N; ++i)
v[i] = ReadInt;
return v;
}
public static long[] ReadLongArray(long N) {
var v = new long[N];
for (long i = 0; i < N; ++i)
v[i] = ReadLong;
return v;
}
public static (T, T) ToTpl2<T>(this T[] v) { return (v[0], v[1]); }
public static (T, T, T) ToTpl3<T>(this T[] v) { return (v[0], v[1], v[2]); }
public static (T, T, T, T) ToTpl4<T>(this T[] v) {
return (v[0], v[1], v[2], v[3]);
}
public static (T, T, T, T, T) ToTpl5<T>(this T[] v) {
return (v[0], v[1], v[2], v[3], v[4]);
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33]]
| 8
| 1,191
| 4
|
using System;
namespace ABC170C {
class Program {
static void Main(string[] args) {
string[] strs = Console.ReadLine().Split();
int x = int.Parse(strs[0]);
int n = int.Parse(strs[1]);
string p = Console.ReadLine();
if (p == "") {
Console.WriteLine(x);
Console.ReadLine();
return;
}
int[] intP = Array.ConvertAll(p.Split(), int.Parse);
Array.Sort(intP);
int index = Array.BinarySearch(intP, x);
if (index == -1) {
Console.WriteLine(x);
Console.ReadLine();
return;
} else {
int i = 1;
while (true) {
if (index - i < 0) {
Console.WriteLine(x - i);
Console.ReadLine();
return;
} else {
if (intP[index - i] != x - i) {
Console.WriteLine(x - i);
Console.ReadLine();
return;
}
}
if (index + i >= n) {
Console.WriteLine(x + i);
Console.ReadLine();
return;
} else {
if (intP[index + i] != x + i) {
Console.WriteLine(x + i);
Console.ReadLine();
return;
}
}
i++;
}
}
}
}
}
|
using System;
namespace ABC170C {
class Program {
static void Main(string[] args) {
string[] strs = Console.ReadLine().Split();
int x = int.Parse(strs[0]);
int n = int.Parse(strs[1]);
string p = Console.ReadLine();
if (p == "") {
Console.WriteLine(x);
Console.ReadLine();
return;
}
int[] intP = Array.ConvertAll(p.Split(), int.Parse);
Array.Sort(intP);
int index = Array.BinarySearch(intP, x);
if (index < 0) {
Console.WriteLine(x);
Console.ReadLine();
return;
} else {
int i = 1;
while (true) {
if (index - i < 0) {
Console.WriteLine(x - i);
Console.ReadLine();
return;
} else {
if (intP[index - i] != x - i) {
Console.WriteLine(x - i);
Console.ReadLine();
return;
}
}
if (index + i >= n) {
Console.WriteLine(x + i);
Console.ReadLine();
return;
} else {
if (intP[index + i] != x + i) {
Console.WriteLine(x + i);
Console.ReadLine();
return;
}
}
i++;
}
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 300
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
public static class Program {
public static void Main() {
var data = Console.ReadLine().Split();
var x = int.Parse(data[0]);
var n = int.Parse(data[1]);
var p = Console.ReadLine()
.Split()
.Where(s => s != "")
.Select(s => int.Parse(s))
.ToList();
Console.WriteLine(Enumerable.Range(0, 101)
.Where(i => !p.Contains(i))
.OrderBy(i => Math.Abs(x - i))
.ThenBy(i => i)
.First());
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public static class Program {
public static void Main() {
var data = Console.ReadLine().Split();
var x = int.Parse(data[0]);
var n = int.Parse(data[1]);
var p = Console.ReadLine()
.Split()
.Where(s => s != "")
.Select(s => int.Parse(s))
.ToList();
Console.WriteLine(Enumerable.Range(0, 102)
.Where(i => !p.Contains(i))
.OrderBy(i => Math.Abs(x - i))
.ThenBy(i => i)
.First());
}
}
|
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 159
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC170C {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var x = int.Parse(input[0]);
var n = int.Parse(input[1]);
if (n == 0) {
Console.WriteLine(x);
} else {
var numbers = Console.ReadLine().Split(' ');
var numList = new List<int>();
var numDic = new Dictionary<int, int>();
for (var i = 1; i <= 1000; i++) {
if (!numbers.Contains(i.ToString())) {
numDic.Add(i, Math.Abs(i - x));
}
}
var min = numDic.Values.Min();
var ansList = new List<int>();
foreach (var num in numDic) {
if (num.Value == min) {
ansList.Add(num.Key);
}
}
Console.WriteLine(ansList.Min());
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC170C {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split(' ');
var x = int.Parse(input[0]);
var n = int.Parse(input[1]);
if (n == 0) {
Console.WriteLine(x);
} else {
var numbers = Console.ReadLine().Split(' ');
var numList = new List<int>();
var numDic = new Dictionary<int, int>();
for (var i = 0; i <= 101; i++) {
if (!numbers.Contains(i.ToString())) {
numDic.Add(i, Math.Abs(i - x));
}
}
var min = numDic.Values.Min();
var ansList = new List<int>();
foreach (var num in numDic) {
if (num.Value == min) {
ansList.Add(num.Key);
}
}
Console.WriteLine(ansList.Min());
}
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 75, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 243
| 4
|
// Rextester.Program.Main is the entry point for your code. Don't change it.
// Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester {
public class Program {
public static void Main(string[] args) {
List<int> info = Cin();
int x = info[0];
int n = info[1];
if (n == 0) {
Cout(x);
return;
}
List<int> nums = Cin().Distinct().OrderBy(t => t).ToList();
int idx = nums.IndexOf(x);
if (idx == -1) {
Cout(x);
return;
}
int li = 0;
int ri = nums.Count - 1;
// Left.
for (int i = idx - 1; i >= 0; i--) {
if (nums[i] + 1 != nums[i + 1]) {
li = i + 1;
break;
}
}
// Right.
for (int i = idx + 1; i < nums.Count; i++) {
if (nums[i - 1] + 1 != nums[i]) {
ri = i - 1;
break;
}
}
int left = nums[li] - 1;
int right = nums[ri] + 1;
if (x - left <= x + right)
Cout(left);
else
Cout(right);
}
public static List<int> Cin() {
return Console.ReadLine().Split().Select(t => int.Parse(t)).ToList();
}
public static void Cout(int s) { Console.WriteLine(s); }
}
}
|
// Rextester.Program.Main is the entry point for your code. Don't change it.
// Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester {
public class Program {
public static void Main(string[] args) {
List<int> info = Cin();
int x = info[0];
int n = info[1];
if (n == 0) {
Cout(x);
return;
}
List<int> nums = Cin().Distinct().OrderBy(t => t).ToList();
int idx = nums.IndexOf(x);
if (idx == -1) {
Cout(x);
return;
}
int li = 0;
int ri = nums.Count - 1;
// Left.
for (int i = idx - 1; i >= 0; i--) {
if (nums[i] + 1 != nums[i + 1]) {
li = i + 1;
break;
}
}
// Right.
for (int i = idx + 1; i < nums.Count; i++) {
if (nums[i - 1] + 1 != nums[i]) {
ri = i - 1;
break;
}
}
int left = nums[li] - 1;
int right = nums[ri] + 1;
if (x - left <= right - x)
Cout(left);
else
Cout(right);
}
public static List<int> Cin() {
return Console.ReadLine().Split().Select(t => int.Parse(t)).ToList();
}
public static void Cout(int s) { Console.WriteLine(s); }
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 339
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数配列の入力
var inputLongArray =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var x = inputLongArray[0];
var n = inputLongArray[1];
var result = x;
if (n != 0) {
// 整数配列の入力
var inputLongArray2 =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var array = inputLongArray2;
result = find(x, array);
}
Console.WriteLine(result);
Console.Out.Flush();
}
private static int find(int x, int[] array) {
if (!array.Contains(x))
return x;
var except = Enumerable.Range(0, 101).Except(array);
var result =
except.Select(i => new { element = i, diff = Math.Abs(x - i) })
.OrderBy(s => s.diff)
.ThenBy(s => s.element)
.First();
return result.element;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数配列の入力
var inputLongArray =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var x = inputLongArray[0];
var n = inputLongArray[1];
var result = x;
if (n != 0) {
// 整数配列の入力
var inputLongArray2 =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var array = inputLongArray2;
result = find(x, array);
}
Console.WriteLine(result);
Console.Out.Flush();
}
private static int find(int x, int[] array) {
if (!array.Contains(x))
return x;
var except = Enumerable.Range(0, 102).Except(array);
var result =
except.Select(i => new { element = i, diff = Math.Abs(x - i) })
.OrderBy(s => s.diff)
.ThenBy(s => s.element)
.First();
return result.element;
}
}
}
|
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 311
| 2
|
using System;
using System.Collections.Generic;
using System.Text;
namespace ABC0613 {
class Program {
static void Main(string[] args) {
string[] inp = Console.ReadLine().Split(' ');
int ans = int.MaxValue;
if (inp[1] == "0") {
ans = int.Parse(inp[0]);
} else {
int x = int.Parse(inp[0]);
int n = int.Parse(inp[1]);
string[] array = Console.ReadLine().Split(' ');
List<int> list = new List<int>();
foreach (string str in array) {
int hoge = int.Parse(str);
list.Add(hoge);
}
for (int i = 1; i < 1000; i++) {
int temp = x - i;
if (!list.Contains(temp)) {
ans = temp;
break;
}
temp = x + i;
if (!list.Contains(temp)) {
ans = temp;
break;
}
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
namespace ABC0613 {
class Program {
static void Main(string[] args) {
string[] inp = Console.ReadLine().Split(' ');
int ans = int.MaxValue;
if (inp[1] == "0") {
ans = int.Parse(inp[0]);
} else {
int x = int.Parse(inp[0]);
int n = int.Parse(inp[1]);
string[] array = Console.ReadLine().Split(' ');
List<int> list = new List<int>();
foreach (string str in array) {
int hoge = int.Parse(str);
list.Add(hoge);
}
for (int i = 0; i < 1000; i++) {
int temp = x - i;
if (!list.Contains(temp)) {
ans = temp;
break;
}
temp = x + i;
if (!list.Contains(temp)) {
ans = temp;
break;
}
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 243
| 2
|
using System;
using System.Linq;
namespace C {
class Program {
static void Main(string[] args) {
int[] XN =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
if (XN[1] == 0) {
System.Console.WriteLine(XN[0]);
return;
}
int[] Ps =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int answer = 0;
int i = 1;
while (true) {
if (!Ps.Contains(XN[0] - i)) {
answer = XN[0] - i;
break;
}
if (!Ps.Contains(XN[0] + i)) {
answer = XN[0] + i;
break;
}
i++;
}
Console.WriteLine(answer);
}
}
}
|
using System;
using System.Linq;
namespace C {
class Program {
static void Main(string[] args) {
int[] XN =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
if (XN[1] == 0) {
System.Console.WriteLine(XN[0]);
return;
}
int[] Ps =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int answer = 0;
int i = 0;
while (true) {
if (!Ps.Contains(XN[0] - i)) {
answer = XN[0] - i;
break;
}
if (!Ps.Contains(XN[0] + i)) {
answer = XN[0] + i;
break;
}
i++;
}
Console.WriteLine(answer);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 202
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
int[] arr1 =
Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
int x = arr1[0];
int n = arr1[1];
if (n == 0) {
Console.WriteLine(x);
return;
}
int[] arr =
Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
int min = 1000;
int minVal = 0;
int[] allArr = new int[101];
for (int i = 0; i <= 100; i++) {
allArr[i] = i;
}
var arrOther =
arr.Concat(allArr).GroupBy(v => v).Where(v => v.Count() == 1);
foreach (var element in arrOther) {
if (Math.Abs(element.Key - x) < min) {
minVal = element.Key;
min = Math.Abs(element.Key - x);
} else if (Math.Abs(element.Key - x) == min) {
minVal = (element.Key < minVal) ? element.Key : minVal;
}
}
Console.WriteLine(minVal);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
int[] arr1 =
Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
int x = arr1[0];
int n = arr1[1];
if (n == 0) {
Console.WriteLine(x);
return;
}
int[] arr =
Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
int min = 1000;
int minVal = 0;
int[] allArr = new int[141];
for (int i = -20; i <= 120; i++) {
allArr[i + 20] = i;
}
var arrOther =
arr.Concat(allArr).GroupBy(v => v).Where(v => v.Count() == 1);
foreach (var element in arrOther) {
if (Math.Abs(element.Key - x) < min) {
minVal = element.Key;
min = Math.Abs(element.Key - x);
} else if (Math.Abs(element.Key - x) == min) {
minVal = (element.Key < minVal) ? element.Key : minVal;
}
}
Console.WriteLine(minVal);
}
}
|
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 296
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数配列の入力
var inputLongArray =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var x = inputLongArray[0];
var n = inputLongArray[1];
var pp = Console.ReadLine();
string result = string.Empty;
if (n == 0) {
result = x.ToString();
} else {
var p = pp.Split(' ').Select(i => int.Parse(i)).ToArray();
var tmp = Enumerable.Range(1, 100);
var ans = new Dictionary<int, int>();
foreach (var item in tmp) {
if (p.Contains(item))
continue;
ans.Add(item, Math.Abs(item - x));
}
result =
ans.Where(r => r.Value == ans.Values.Min()).First().Key.ToString();
}
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionC {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数配列の入力
var inputLongArray =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var x = inputLongArray[0];
var n = inputLongArray[1];
var pp = Console.ReadLine();
string result = string.Empty;
if (n == 0) {
result = x.ToString();
} else {
var p = pp.Split(' ').Select(i => int.Parse(i)).ToArray();
var tmp = Enumerable.Range(0, 102);
var ans = new Dictionary<int, int>();
foreach (var item in tmp) {
if (p.Contains(item))
continue;
ans.Add(item, Math.Abs(item - x));
}
result =
ans.Where(r => r.Value == ans.Values.Min()).First().Key.ToString();
}
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
[["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 297
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace PaizaTest {
class Program {
static void Main(string[] args) {
var XN = Console.ReadLine().Split().Select(int.Parse).ToList();
if (XN[1] == 0) {
Console.WriteLine(XN[0]);
return;
}
var p = Console.ReadLine().Split().Select(int.Parse).ToList();
var nums = new List<int>();
for (int i = -101; i <= 100; i++) {
if (p.Contains(i)) {
continue;
}
nums.Add(i);
}
nums.Sort();
var minimum = int.MaxValue;
var result = 0;
foreach (var num in nums) {
if (minimum > Math.Abs(XN[0] - num)) {
minimum = Math.Abs(XN[0] - num);
result = num;
}
}
Console.WriteLine(result);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace PaizaTest {
class Program {
static void Main(string[] args) {
var XN = Console.ReadLine().Split().Select(int.Parse).ToList();
if (XN[1] == 0) {
Console.WriteLine(XN[0]);
return;
}
var p = Console.ReadLine().Split().Select(int.Parse).ToList();
var nums = new List<int>();
for (int i = -101; i <= 202; i++) {
if (p.Contains(i)) {
continue;
}
nums.Add(i);
}
nums.Sort();
var minimum = int.MaxValue;
var result = 0;
foreach (var num in nums) {
if (minimum > Math.Abs(XN[0] - num)) {
minimum = Math.Abs(XN[0] - num);
result = num;
}
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 223
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
//入力を保持する
var N = int.Parse(Console.ReadLine());
var As = Console.ReadLine()
.Split()
.Select(e => int.Parse(e))
.OrderBy(e => e)
.ToArray();
// As配列内に1が1つ存在している場合は1以外は1によりすべて割り切れるため1が回答となる
if ((As.Count(e => e == 1) == 1)) {
Console.WriteLine("1");
return;
}
// 1が1よりも多く存在している場合、1も1で割り切れるため0が回答となる
if ((As.Count(e => e == 1) > 1)) {
Console.WriteLine("0");
return;
}
var max = (int)1e6;
// As配列に含まれる数字の数をカウントするためNがとりうる最大の数分配列を準備する
var cnt = new int[max];
for (var num = 0; num < N; num++) {
cnt[As[num]]++;
}
// Asに含まれる数字の倍数すべてをbool型で保持する
//-->割り切れないというのは言い換えればAiがその他の数の倍数にならないということ
var baisuFlgs = new bool[max];
foreach (var i in As.Distinct()) {
var temp = i;
while (temp + i <= max) {
temp += i;
baisuFlgs[temp] = true;
}
}
// cnt配列内にAiの数が1であり、かつbaisuFlags配列内にAiの倍数のインデックスがFalseであればカントアップしていく
var ans = 0;
for (var i = 0; i < N; i++) {
if (baisuFlgs[As[i]] == false && cnt[As[i]] == 1) {
ans++;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
//入力を保持する
var N = int.Parse(Console.ReadLine());
var As = Console.ReadLine()
.Split()
.Select(e => int.Parse(e))
.OrderBy(e => e)
.ToArray();
// As配列内に1が1つ存在している場合は1以外は1によりすべて割り切れるため1が回答となる
if ((As.Count(e => e == 1) == 1)) {
Console.WriteLine("1");
return;
}
// 1が1よりも多く存在している場合、1も1で割り切れるため0が回答となる
if ((As.Count(e => e == 1) > 1)) {
Console.WriteLine("0");
return;
}
var max = (int)1e6;
// As配列に含まれる数字の数をカウントするためNがとりうる最大の数分配列を準備する
var cnt = new int[max + 10];
for (var num = 0; num < N; num++) {
cnt[As[num]]++;
}
// Asに含まれる数字の倍数すべてをbool型で保持する
//-->割り切れないというのは言い換えればAiがその他の数の倍数にならないということ
var baisuFlgs = new bool[max + 1];
foreach (var i in As.Distinct()) {
var temp = i;
while (temp + i <= max) {
temp += i;
baisuFlgs[temp] = true;
}
}
// cnt配列内にAiの数が1であり、かつbaisuFlags配列内にAiの倍数のインデックスがFalseであればカントアップしていく
var ans = 0;
for (var i = 0; i < N; i++) {
if (baisuFlgs[As[i]] == false && cnt[As[i]] == 1) {
ans++;
}
}
Console.WriteLine(ans);
}
}
|
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
| 8
| 290
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
//入力を保持する
var N = int.Parse(Console.ReadLine());
var As = Console.ReadLine()
.Split()
.Select(e => int.Parse(e))
.OrderBy(e => e)
.ToArray();
// As配列内に1が1つ存在している場合は1以外は1によりすべて割り切れるため1が回答となる
if ((As.Count(e => e == 1) == 1)) {
Console.WriteLine("1");
}
// 1が1よりも多く存在している場合、1も1で割り切れるため0が回答となる
if ((As.Count(e => e == 1) > 1)) {
Console.WriteLine("0");
}
var max = (int)1e6;
// As配列に含まれる数字の数をカウントするためNがとりうる最大の数分配列を準備する
var cnt = new int[max + 10];
for (var num = 0; num < N; num++) {
cnt[As[num]]++;
}
// Asに含まれる数字の倍数すべてをbool型で保持する
//-->割り切れないというのは言い換えればAiがその他の数の倍数にならないということ
var baisuFlgs = new bool[max + 1];
foreach (var i in As.Distinct()) {
var temp = i;
while (temp + i <= max) {
temp += i;
baisuFlgs[temp] = true;
}
}
// cnt配列内にAiの数が1であり、かつbaisuFlags配列内にAiの倍数のインデックスがFalseであればカントアップしていく
var ans = 0;
for (var i = 0; i < N; i++) {
if (baisuFlgs[As[i]] == false && cnt[As[i]] == 1) {
ans++;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
//入力を保持する
var N = int.Parse(Console.ReadLine());
var As = Console.ReadLine()
.Split()
.Select(e => int.Parse(e))
.OrderBy(e => e)
.ToArray();
// As配列内に1が1つ存在している場合は1以外は1によりすべて割り切れるため1が回答となる
if ((As.Count(e => e == 1) == 1)) {
Console.WriteLine("1");
return;
}
// 1が1よりも多く存在している場合、1も1で割り切れるため0が回答となる
if ((As.Count(e => e == 1) > 1)) {
Console.WriteLine("0");
return;
}
var max = (int)1e6;
// As配列に含まれる数字の数をカウントするためNがとりうる最大の数分配列を準備する
var cnt = new int[max + 10];
for (var num = 0; num < N; num++) {
cnt[As[num]]++;
}
// Asに含まれる数字の倍数すべてをbool型で保持する
//-->割り切れないというのは言い換えればAiがその他の数の倍数にならないということ
var baisuFlgs = new bool[max + 1];
foreach (var i in As.Distinct()) {
var temp = i;
while (temp + i <= max) {
temp += i;
baisuFlgs[temp] = true;
}
}
// cnt配列内にAiの数が1であり、かつbaisuFlags配列内にAiの倍数のインデックスがFalseであればカントアップしていく
var ans = 0;
for (var i = 0; i < N; i++) {
if (baisuFlgs[As[i]] == false && cnt[As[i]] == 1) {
ans++;
}
}
Console.WriteLine(ans);
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 290
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var A = sc.ReadIntArray(N);
// 数列内の1の個数を数える
var count1 = A.Count(a => a == 1);
if (count1 == 1) {
// 1の個数が1個の時、1だけ割り切る数がない
Console.WriteLine(1);
return;
}
if (count1 > 1) {
// 1の個数が2個以上の時、全部の数が割り切れる
Console.WriteLine(0);
return;
}
var max = (int)1e6;
// 数の個数を数えておく
var count = new int[max + 10];
for (int i = 0; i < N; i++) {
count[A[i]]++;
}
// ほかの数の倍数にならない数を記録する
var baisuuCount = new int[max + 1];
for (int i = 0; i < N; i++) {
// 今の数の倍数をすべて記録する
var now = 0;
while (now + A[i] <= max) {
now += A[i];
baisuuCount[now]++;
}
}
var ans = 0;
for (int i = 0; i < N; i++) {
// 倍数が1つだけの時、自分自身だけなのでダメ
if (baisuuCount[A[i]] > 1)
ans++;
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var A = sc.ReadIntArray(N);
// 数列内の1の個数を数える
var count1 = A.Count(a => a == 1);
if (count1 == 1) {
// 1の個数が1個の時、1だけ割り切る数がない
Console.WriteLine(1);
return;
}
if (count1 > 1) {
// 1の個数が2個以上の時、全部の数が割り切れる
Console.WriteLine(0);
return;
}
var max = (int)1e6;
// 数の個数を数えておく
var count = new int[max + 10];
for (int i = 0; i < N; i++) {
count[A[i]]++;
}
// ほかの数の倍数にならない数を記録する
var baisuuCount = new int[max + 1];
for (int i = 0; i < N; i++) {
// 今の数の倍数をすべて記録する
var now = 0;
while (now + A[i] <= max) {
now += A[i];
baisuuCount[now]++;
}
}
var ans = 0;
for (int i = 0; i < N; i++) {
// 倍数が1つだけの時、自分自身だけなのでOK
if (baisuuCount[A[i]] <= 1)
ans++;
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 1,274
| 2
|
using System;
namespace ABC170D {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine().Trim());
int max_i = (int)1e6 + 2;
int[] x = new int[max_i];
bool[] f = new bool[max_i];
var t = Console.ReadLine().Trim().Split(' ');
for (int i = 0; i < N; i++) {
x[int.Parse(t[i])]++;
f[int.Parse(t[i])] = true;
}
int ans = 0;
for (int i = 0; i < max_i; i++) {
if (x[i] > 0) {
if (x[i] == 1)
ans++;
for (int j = i; j < max_i; j += i)
f[j] = false;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
namespace ABC170D {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine().Trim());
int max_i = (int)1e6 + 2;
int[] x = new int[max_i];
bool[] f = new bool[max_i];
var t = Console.ReadLine().Trim().Split(' ');
for (int i = 0; i < N; i++) {
x[int.Parse(t[i])]++;
f[int.Parse(t[i])] = true;
}
int ans = 0;
for (int i = 0; i < max_i; i++) {
if (x[i] > 0) {
if (x[i] == 1 && f[i])
ans++;
for (int j = i; j < max_i; j += i)
f[j] = false;
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 210
| 5
|
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(' ');
for (int i = 0; i < 5; i++) {
if (s[i] == "0")
Console.WriteLine(i + 1);
}
}
}
class ProgramB {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
//答え出力
if (b % 2 == 1) {
Console.WriteLine("No");
return;
}
if (a * 2 <= b && b <= 4 * a)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
class ProgramC {
public void main() {
//入力(decimal型だと桁精度が27桁ぐらいまである
string[] s = Console.ReadLine().Split(' ');
int x = int.Parse(s[0]);
int n = int.Parse(s[1]);
string[] a = Console.ReadLine().Split(' ');
int[] dif = new int[100];
for (int i = 0; i < n; i++)
dif[int.Parse(a[i]) - 1]++;
long ans1 = 0;
long ans2 = 0;
for (int i = x - 1; i <= 100; i++) {
if (i == 100) {
ans1 = 101;
break;
}
if (dif[i] == 0) {
ans1 = i + 1;
break;
}
}
for (int i = x - 1; i >= -1; i--) {
if (i == -1) {
ans2 = 0;
break;
}
if (dif[i] == 0) {
ans2 = i + 1;
break;
}
}
if (ans1 == ans2)
Console.WriteLine(ans1);
else if ((ans1 - x) < (x - ans2))
Console.WriteLine(ans1);
else
Console.WriteLine(ans2);
}
}
class ProgramD {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = long.Parse(s[i]);
if (n == 1) {
Console.WriteLine(1);
return;
}
Array.Sort(a);
if (a[0] == 1) {
if (a[0] == a[1])
Console.WriteLine(0);
else
Console.WriteLine(1);
return;
}
long[] flag = new long[a[n - 1]];
//同じ数があるか探す
for (int i = 0; i < n - 1; i++) {
if (a[i] == a[i + 1]) {
flag[a[i] - 1] = 1;
}
}
//それぞれのかずで残るか検討
for (int i = 0; i < n; i++) {
if (flag[a[i] - 1] == 1)
continue;
long t = a[i];
t += a[i];
while (t <= a[n - 1]) {
flag[t - 1] = 1;
t += a[i];
}
}
//判定
long ans = 0;
for (int i = 0; i < n; i++) {
if (flag[a[i] - 1] == 0)
ans++;
}
//答え出力
Console.WriteLine(ans);
}
}
class ProgramE {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
long[] a = new long[n];
long[] b = new long[n];
//下限をa,上限をbとする
for (int i = 0; i < n; i++) {
string[] s = Console.ReadLine().Split(' ');
a[i] = long.Parse(s[0]);
b[i] = long.Parse(s[1]);
}
// a,bを小さい順に並べる
Array.Sort(a);
Array.Sort(b);
long min = 0;
long max = 0;
//偶数個のときは中央二つの和を考える、奇数個は中央を考える
if (n % 2 == 0) {
min = a[n / 2] + a[n / 2 - 1];
max = b[n / 2] + b[n / 2 - 1];
} else {
min = a[n / 2];
max = b[n / 2];
}
// minからmaxまでは全部中央値として取れるのでそれで出力する
Console.WriteLine(max - min + 1);
}
}
class ProgramF {
public void main() {
string[] s = Console.ReadLine().Split(' ');
int n = int.Parse(s[0]);
int num = int.Parse(s[1]);
long MOD = 998244353;
string[] a = Console.ReadLine().Split(' ');
long[,] dp = new long[n + 1, num + 1];
//初項設定
dp[0, 0] = 1;
// i番目までで、選び方によって出てくる和(j)を求める
for (int i = 0; i < n; i++)
for (int j = 0; j < num + 1; j++) {
long temp = j + long.Parse(a[i]);
// 3001以上は答にならないので省く
//入れる場合は、Tとして選んでかつその和に組み込むのでそのまま足す。
if (temp <= num) {
dp[i + 1, temp] += dp[i, j];
dp[i + 1, temp] %= MOD;
}
//いれない場合は集合として成立しているのでそのi番目を選ぼうが選ばなかろうが部分として考えなければよい。よって、2倍して拡張
dp[i + 1, j] += (dp[i, j] * 2) % MOD;
dp[i + 1, j] %= MOD;
}
//答はdp[n,num]で出てくる
Console.WriteLine(dp[n, num]);
}
}
}
|
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(' ');
for (int i = 0; i < 5; i++) {
if (s[i] == "0")
Console.WriteLine(i + 1);
}
}
}
class ProgramB {
public void main() {
//入力
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
//答え出力
if (b % 2 == 1) {
Console.WriteLine("No");
return;
}
if (a * 2 <= b && b <= 4 * a)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
}
class ProgramC {
public void main() {
//入力(decimal型だと桁精度が27桁ぐらいまである
string[] s = Console.ReadLine().Split(' ');
int x = int.Parse(s[0]);
int n = int.Parse(s[1]);
string[] a = Console.ReadLine().Split(' ');
int[] dif = new int[100];
for (int i = 0; i < n; i++)
dif[int.Parse(a[i]) - 1]++;
long ans1 = 0;
long ans2 = 0;
for (int i = x - 1; i <= 100; i++) {
if (i == 100) {
ans1 = 101;
break;
}
if (dif[i] == 0) {
ans1 = i + 1;
break;
}
}
for (int i = x - 1; i >= -1; i--) {
if (i == -1) {
ans2 = 0;
break;
}
if (dif[i] == 0) {
ans2 = i + 1;
break;
}
}
if (ans1 == ans2)
Console.WriteLine(ans1);
else if ((ans1 - x) < (x - ans2))
Console.WriteLine(ans1);
else
Console.WriteLine(ans2);
}
}
class ProgramD {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = long.Parse(s[i]);
if (n == 1) {
Console.WriteLine(1);
return;
}
Array.Sort(a);
if (a[0] == 1) {
if (a[0] == a[1])
Console.WriteLine(0);
else
Console.WriteLine(1);
return;
}
long[] flag = new long[a[n - 1]];
//同じ数があるか探す
for (int i = 0; i < n - 1; i++) {
if (a[i] == a[i + 1]) {
flag[a[i] - 1] = 2;
}
}
//それぞれのかずで残るか検討
for (int i = 0; i < n; i++) {
if (flag[a[i] - 1] == 1)
continue;
long t = a[i];
t += a[i];
while (t <= a[n - 1]) {
flag[t - 1] = 1;
t += a[i];
}
}
//判定
long ans = 0;
for (int i = 0; i < n; i++) {
if (flag[a[i] - 1] == 0)
ans++;
}
//答え出力
Console.WriteLine(ans);
}
}
class ProgramE {
public void main() {
//入力
long n = long.Parse(Console.ReadLine());
long[] a = new long[n];
long[] b = new long[n];
//下限をa,上限をbとする
for (int i = 0; i < n; i++) {
string[] s = Console.ReadLine().Split(' ');
a[i] = long.Parse(s[0]);
b[i] = long.Parse(s[1]);
}
// a,bを小さい順に並べる
Array.Sort(a);
Array.Sort(b);
long min = 0;
long max = 0;
//偶数個のときは中央二つの和を考える、奇数個は中央を考える
if (n % 2 == 0) {
min = a[n / 2] + a[n / 2 - 1];
max = b[n / 2] + b[n / 2 - 1];
} else {
min = a[n / 2];
max = b[n / 2];
}
// minからmaxまでは全部中央値として取れるのでそれで出力する
Console.WriteLine(max - min + 1);
}
}
class ProgramF {
public void main() {
string[] s = Console.ReadLine().Split(' ');
int n = int.Parse(s[0]);
int num = int.Parse(s[1]);
long MOD = 998244353;
string[] a = Console.ReadLine().Split(' ');
long[,] dp = new long[n + 1, num + 1];
//初項設定
dp[0, 0] = 1;
// i番目までで、選び方によって出てくる和(j)を求める
for (int i = 0; i < n; i++)
for (int j = 0; j < num + 1; j++) {
long temp = j + long.Parse(a[i]);
// 3001以上は答にならないので省く
//入れる場合は、Tとして選んでかつその和に組み込むのでそのまま足す。
if (temp <= num) {
dp[i + 1, temp] += dp[i, j];
dp[i + 1, temp] %= MOD;
}
//いれない場合は集合として成立しているのでそのi番目を選ぼうが選ばなかろうが部分として考えなければよい。よって、2倍して拡張
dp[i + 1, j] += (dp[i, j] * 2) % MOD;
dp[i + 1, j] %= MOD;
}
//答はdp[n,num]で出てくる
Console.WriteLine(dp[n, num]);
}
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 1,305
| 2
|
//
// ABC170D
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace AtCoder {
class ABC170D {
public static readonly long MOD_CONST =
1000000007; //(long)Math.Pow(10, 9) + 7;
static void Main(string[] args) {
//出力高速化
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
int N = int.Parse(Console.ReadLine());
List<int> An = Console.ReadLine()
.Split(' ')
.Select(_inputStr => int.Parse(_inputStr))
.ToList();
if (N == 1) {
Console.WriteLine(0);
return;
}
//小さいものを手前に
An.Sort();
//エラトステネスの篩
var AMax = An[N - 1];
var dp = new bool[AMax + 1];
//最初は全部trueにしておく。dp[i]はiよりiの約数がAnに無いならtrue,
//あるならfalse 例: dp[100]はAnに100より小さい100の約数がないならtrue
for (int i = 0; i < N; ++i) {
var x = An[i];
dp[x] = true;
}
int ans = 0;
//よくあるエラトステネスの篩では100までの素数を求めるため、100より小さい数で篩をかけていった
//ここではAnにある数で篩をかけていく
for (int i = 0; i < N; ++i) {
var x = An[i]; //篩にかける数
// xの倍数は全部条件を満たさない
if (dp[x] == false) {
continue;
} //もう篩に通していたならskip
//同じ数がAnにあると、2回ふるいにかけてしまうので除外
if (0 < i) {
if (x == An[i - 1]) {
dp[x] = false;
continue;
}
}
//ふるいにかける数xの倍数は全部falseにしていく
for (var y = x * 2; y <= AMax; y += x) {
dp[y] = false;
}
}
//ふるいに残った数
ans = dp.Count(a => a == true);
Console.WriteLine(ans);
}
//---------------------------------------------------------------------------------
#region MyLib
public static void getDistinctList<T>(List<T> src, out List<T> dst) {
var iter = src.Distinct();
dst = new List<T>();
foreach (var item in iter) {
dst.Add(item);
}
}
/// <summary>
/// グラフ系
/// </summary>
public class Node {
public Node(long val) {
this.Value = val;
this.Children = new List<Node>();
}
public Node(long val, List<Node> children) {
this.Value = val;
this.Children = children;
}
public long Value { get; set; }
public List<Node> Children { get; set; }
}
/// <summary>
/// Clamping
/// </summary>
/// <typeparam name="T">比較型</typeparam>
/// <param name="x">clampしたい値</param>
/// <param name="min">最小値</param>
/// <param name="max">最大値</param>
/// <returns>clamp済みの値</returns>
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T> {
if (x.CompareTo(min) < 0) {
return min;
} else if (x.CompareTo(max) > 0) {
return max;
} else
return x;
// return Math.Max(Math.Min(x, max), min);
}
/// <summary>
/// 指定された底log_baseでの, 対数を計算
/// </summary>
/// <param name="x"></param>
/// <param name="log_base">指定の底</param>
/// <returns></returns>
public static double LogBase(double x, double log_base) {
// log_b(N) = log_a(N) / log_a(B)より
return Math.Log(x) / Math.Log(log_base);
}
/// <summary>
/// 初項a, 公差d, 項数nの数列の和
/// </summary>
/// <param name="n">求めたいところ</param>
/// <returns>初項からxまで足した値</returns>
static long SumSeries(long a, long d, long n) {
return (2 * a + (n - 1) * d) * n / 2;
}
/// <summary>
/// 累積和の配列を計算する
/// Sum[ a[0], a[i] )がs[i+1]に入っている
/// s[0] : 0 //一切和を取らない場合
/// s[1] : ls[0] //a[0] + s[0] = a[0]
/// s[2] : ls[1] + s[1] //a[1] + a[0]
/// ...
/// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0]
/// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0]
///
/// 例: [1, 7)の和(a[1] + ... + a[6])
/// s[1] = a[0] //[0, 1)
/// s[7] = a[0] + a[1] + ... + a[6] //[0, 7)
/// よってs[7] - s[1]);
/// </summary>
/// <param name="ls">計算したい配列</param>
/// <returns>累積和配列</returns>
static List<long> AggregateSumList(List<long> a) {
var s = new List<long>(a.Count + 1);
if (a.Count == 0) {
return s;
}
s.Add(0); // s[0] = 0
for (int i = 0; i < a.Count; ++i) {
s.Add(a[i] + s[i]);
}
return s;
}
/// <summary>
/// 与えられた数が素数かどうかを計算する
/// </summary>
/// <param name="num">対象数</param>
/// <returns>true:素数, false:素数ではない(合成数)</returns>
public static bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
/// <summary>
/// 順列mPnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Permutation(long m, long n) {
long ret = 1;
for (var i = 0; i < n; ++i) {
ret *= m - i;
}
return ret;
}
/// <summary>
/// 組み合わせmCnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Combination(long m, long n) {
if (m == n || n == 0) {
return 1;
}
long ans = 1;
for (var i = 1; i <= n; ++i) {
ans = ans * (m - i + 1) / i;
}
return ans;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
static long Lcm(long m, long n) {
var gcd = Gcd(m, n);
// return (m * n) / gcd;
return m / gcd * n; //桁あふれ対策
}
#endregion MyLib
}
}
|
//
// ABC170D
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_d
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace AtCoder {
class ABC170D {
public static readonly long MOD_CONST =
1000000007; //(long)Math.Pow(10, 9) + 7;
static void Main(string[] args) {
//出力高速化
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
int N = int.Parse(Console.ReadLine());
List<int> An = Console.ReadLine()
.Split(' ')
.Select(_inputStr => int.Parse(_inputStr))
.ToList();
if (N == 1) {
Console.WriteLine(1);
return;
}
//小さいものを手前に
An.Sort();
//エラトステネスの篩
var AMax = An[N - 1];
var dp = new bool[AMax + 1];
//最初は全部trueにしておく。dp[i]はiよりiの約数がAnに無いならtrue,
//あるならfalse 例: dp[100]はAnに100より小さい100の約数がないならtrue
for (int i = 0; i < N; ++i) {
var x = An[i];
dp[x] = true;
}
int ans = 0;
//よくあるエラトステネスの篩では100までの素数を求めるため、100より小さい数で篩をかけていった
//ここではAnにある数で篩をかけていく
for (int i = 0; i < N; ++i) {
var x = An[i]; //篩にかける数
// xの倍数は全部条件を満たさない
if (dp[x] == false) {
continue;
} //もう篩に通していたならskip
//同じ数がAnにあると、2回ふるいにかけてしまうので除外
if (0 < i) {
if (x == An[i - 1]) {
dp[x] = false;
continue;
}
}
//ふるいにかける数xの倍数は全部falseにしていく
for (var y = x * 2; y <= AMax; y += x) {
dp[y] = false;
}
}
//ふるいに残った数
ans = dp.Count(a => a == true);
Console.WriteLine(ans);
}
//---------------------------------------------------------------------------------
#region MyLib
public static void getDistinctList<T>(List<T> src, out List<T> dst) {
var iter = src.Distinct();
dst = new List<T>();
foreach (var item in iter) {
dst.Add(item);
}
}
/// <summary>
/// グラフ系
/// </summary>
public class Node {
public Node(long val) {
this.Value = val;
this.Children = new List<Node>();
}
public Node(long val, List<Node> children) {
this.Value = val;
this.Children = children;
}
public long Value { get; set; }
public List<Node> Children { get; set; }
}
/// <summary>
/// Clamping
/// </summary>
/// <typeparam name="T">比較型</typeparam>
/// <param name="x">clampしたい値</param>
/// <param name="min">最小値</param>
/// <param name="max">最大値</param>
/// <returns>clamp済みの値</returns>
public static T Clamp<T>(T x, T min, T max)
where T : IComparable<T> {
if (x.CompareTo(min) < 0) {
return min;
} else if (x.CompareTo(max) > 0) {
return max;
} else
return x;
// return Math.Max(Math.Min(x, max), min);
}
/// <summary>
/// 指定された底log_baseでの, 対数を計算
/// </summary>
/// <param name="x"></param>
/// <param name="log_base">指定の底</param>
/// <returns></returns>
public static double LogBase(double x, double log_base) {
// log_b(N) = log_a(N) / log_a(B)より
return Math.Log(x) / Math.Log(log_base);
}
/// <summary>
/// 初項a, 公差d, 項数nの数列の和
/// </summary>
/// <param name="n">求めたいところ</param>
/// <returns>初項からxまで足した値</returns>
static long SumSeries(long a, long d, long n) {
return (2 * a + (n - 1) * d) * n / 2;
}
/// <summary>
/// 累積和の配列を計算する
/// Sum[ a[0], a[i] )がs[i+1]に入っている
/// s[0] : 0 //一切和を取らない場合
/// s[1] : ls[0] //a[0] + s[0] = a[0]
/// s[2] : ls[1] + s[1] //a[1] + a[0]
/// ...
/// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0]
/// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0]
///
/// 例: [1, 7)の和(a[1] + ... + a[6])
/// s[1] = a[0] //[0, 1)
/// s[7] = a[0] + a[1] + ... + a[6] //[0, 7)
/// よってs[7] - s[1]);
/// </summary>
/// <param name="ls">計算したい配列</param>
/// <returns>累積和配列</returns>
static List<long> AggregateSumList(List<long> a) {
var s = new List<long>(a.Count + 1);
if (a.Count == 0) {
return s;
}
s.Add(0); // s[0] = 0
for (int i = 0; i < a.Count; ++i) {
s.Add(a[i] + s[i]);
}
return s;
}
/// <summary>
/// 与えられた数が素数かどうかを計算する
/// </summary>
/// <param name="num">対象数</param>
/// <returns>true:素数, false:素数ではない(合成数)</returns>
public static bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = Math.Sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
/// <summary>
/// 順列mPnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Permutation(long m, long n) {
long ret = 1;
for (var i = 0; i < n; ++i) {
ret *= m - i;
}
return ret;
}
/// <summary>
/// 組み合わせmCnを計算する
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public static long Combination(long m, long n) {
if (m == n || n == 0) {
return 1;
}
long ans = 1;
for (var i = 1; i <= n; ++i) {
ans = ans * (m - i + 1) / i;
}
return ans;
}
static long Gcd(long m, long n) {
if (n == 0)
return m;
return Gcd(n, m % n);
}
static long Lcm(long m, long n) {
var gcd = Gcd(m, n);
// return (m * n) / gcd;
return m / gcd * n; //桁あふれ対策
}
#endregion MyLib
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 1,026
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Abc170D {
public static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var max = a.Last();
var divisible = new bool[max + 1];
var exist = new bool[max + 1];
foreach (var x in a) {
if (divisible[x])
continue;
if (exist[x])
divisible[x] = true;
else
exist[x] = true;
int y = x * 2;
while (y <= max) {
divisible[y] = true;
y += x;
}
}
int count = 0;
for (int i = 0; i <= max; i++)
if (exist[i] && !divisible[i])
count++;
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Abc170D {
public static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var max = a.Max();
var divisible = new bool[max + 1];
var exist = new bool[max + 1];
foreach (var x in a) {
if (divisible[x])
continue;
if (exist[x])
divisible[x] = true;
else
exist[x] = true;
int y = x * 2;
while (y <= max) {
divisible[y] = true;
y += x;
}
}
int count = 0;
for (int i = 0; i <= max; i++)
if (exist[i] && !divisible[i])
count++;
Console.WriteLine(count);
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 216
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
#region library
static int n = 0;
static int m = 0;
static int r = 0;
static int c = 0;
static int x = 0;
static int y = 0;
static string s = "";
static string[] ss;
static long sum = 0;
static long cnt = 0;
static long max = -1;
static long min = 2147483647;
static bool flg = false;
static bool flg2 = false;
static string alpha = "abcdefghijklmnopqrstuvwxyz";
static long mod = 1000000007;
static long[] arr;
static char[,] map;
static long[,] imap;
public class Input {
static readonly char[] separator = { ' ', '\r', '\n' };
readonly StreamReader sr;
readonly Queue<string> queue;
public Input(string path = "") {
queue = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
public bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
queue.Enqueue(elem);
}
return true;
}
public bool Any() { return queue.Any() || Read(); }
bool Read() {
if (!SetText(sr.ReadLine()))
return false;
if (!queue.Any())
return Read();
return queue.Any();
}
public string Next() {
if (!queue.Any() && !Read()) {
return "";
}
return queue.Dequeue();
}
bool Accumulate(int n) {
while (queue.Count() < n) {
if (!Read())
return false;
}
return true;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) {
if (!Accumulate(n))
return null;
var a = new T[n];
for (int i = 0; i < n; i++)
a[i] = add(parse(queue.Dequeue()), offset);
return a;
}
public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); }
public int[] NextInt(int n, int offset = 0) {
return NextT(n, offset, int.Parse, (x, y) => x + y);
}
public long[] NextLong(int n, long offset = 0) {
return NextT(n, offset, long.Parse, (x, y) => x + y);
}
public double[] NextDouble(int n, double offset = 0.0) {
return NextT(n, offset, double.Parse, (x, y) => x + y);
}
}
static Input input;
static int Int() { return input.NextInt(); }
static long Long() { return input.NextLong(); }
static double Double() { return input.NextDouble(); }
static string Text() { return input.Next(); }
static void wl(object obj = null) { Console.WriteLine(obj); }
static void w(object obj) { Console.Write(obj); }
static void Yes() { wl("YES"); }
static void No() { wl("NO"); }
static void Sum() { wl(sum); }
static void Cnt() { wl(cnt); }
static void SetArray(long num = -1) {
if (n == 0) {
n = Int();
}
arr = new long[n];
for (int i = 0; i < n; i++) {
if (num == -1)
arr[i] = Int();
else
arr[i] = num;
}
}
static void ShowArray() {
for (int i = 0; i < arr.Length; i++) {
if (i > 0)
w(" ");
w(arr[i]);
}
wl();
}
static void SetMap(char def = '@') {
if (r == 0 && c == 0) {
r = Int();
c = Int();
}
map = new char[r, c];
for (int i = 0; i < r; i++) {
if (def == '@')
s = Text();
for (int j = 0; j < c; j++) {
map[i, j] = (def == '@') ? s[j] : def;
}
}
}
static void SetIMap(long def = -1) {
if (r == 0 && c == 0) {
r = Int();
c = Int();
}
imap = new long[r, c];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
imap[i, j] = (def == -1) ? Int() : def;
}
}
}
static void ShowMap() {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
w(map[i, j]);
}
wl();
}
}
static void ShowIMap() {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
w(imap[i, j]);
}
wl();
}
}
#endregion
#region main
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
input = new Input();
Solve();
Console.Out.Flush();
}
public static void Solve() {
long n = Int();
while (n > 0) {
n--;
s = alpha[(int)n % 26] + s;
n /= 26;
}
wl(s);
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
#region library
static int n = 0;
static int m = 0;
static int r = 0;
static int c = 0;
static int x = 0;
static int y = 0;
static string s = "";
static string[] ss;
static long sum = 0;
static long cnt = 0;
static long max = -1;
static long min = 2147483647;
static bool flg = false;
static bool flg2 = false;
static string alpha = "abcdefghijklmnopqrstuvwxyz";
static long mod = 1000000007;
static long[] arr;
static char[,] map;
static long[,] imap;
public class Input {
static readonly char[] separator = { ' ', '\r', '\n' };
readonly StreamReader sr;
readonly Queue<string> queue;
public Input(string path = "") {
queue = new Queue<string>();
if (string.IsNullOrEmpty(path)) {
sr = new StreamReader(Console.OpenStandardInput());
} else {
sr = new StreamReader(path);
}
}
public void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
public bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
queue.Enqueue(elem);
}
return true;
}
public bool Any() { return queue.Any() || Read(); }
bool Read() {
if (!SetText(sr.ReadLine()))
return false;
if (!queue.Any())
return Read();
return queue.Any();
}
public string Next() {
if (!queue.Any() && !Read()) {
return "";
}
return queue.Dequeue();
}
bool Accumulate(int n) {
while (queue.Count() < n) {
if (!Read())
return false;
}
return true;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public double NextDouble() { return double.Parse(Next()); }
T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) {
if (!Accumulate(n))
return null;
var a = new T[n];
for (int i = 0; i < n; i++)
a[i] = add(parse(queue.Dequeue()), offset);
return a;
}
public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); }
public int[] NextInt(int n, int offset = 0) {
return NextT(n, offset, int.Parse, (x, y) => x + y);
}
public long[] NextLong(int n, long offset = 0) {
return NextT(n, offset, long.Parse, (x, y) => x + y);
}
public double[] NextDouble(int n, double offset = 0.0) {
return NextT(n, offset, double.Parse, (x, y) => x + y);
}
}
static Input input;
static int Int() { return input.NextInt(); }
static long Long() { return input.NextLong(); }
static double Double() { return input.NextDouble(); }
static string Text() { return input.Next(); }
static void wl(object obj = null) { Console.WriteLine(obj); }
static void w(object obj) { Console.Write(obj); }
static void Yes() { wl("YES"); }
static void No() { wl("NO"); }
static void Sum() { wl(sum); }
static void Cnt() { wl(cnt); }
static void SetArray(long num = -1) {
if (n == 0) {
n = Int();
}
arr = new long[n];
for (int i = 0; i < n; i++) {
if (num == -1)
arr[i] = Int();
else
arr[i] = num;
}
}
static void ShowArray() {
for (int i = 0; i < arr.Length; i++) {
if (i > 0)
w(" ");
w(arr[i]);
}
wl();
}
static void SetMap(char def = '@') {
if (r == 0 && c == 0) {
r = Int();
c = Int();
}
map = new char[r, c];
for (int i = 0; i < r; i++) {
if (def == '@')
s = Text();
for (int j = 0; j < c; j++) {
map[i, j] = (def == '@') ? s[j] : def;
}
}
}
static void SetIMap(long def = -1) {
if (r == 0 && c == 0) {
r = Int();
c = Int();
}
imap = new long[r, c];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
imap[i, j] = (def == -1) ? Int() : def;
}
}
}
static void ShowMap() {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
w(map[i, j]);
}
wl();
}
}
static void ShowIMap() {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
w(imap[i, j]);
}
wl();
}
}
#endregion
#region main
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
input = new Input();
Solve();
Console.Out.Flush();
}
public static void Solve() {
long n = Long();
while (n > 0) {
n--;
s = alpha[(int)(n % 26)] + s;
n /= 26;
}
wl(s);
}
#endregion
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 206, 207, 0, 28, 0, 74, 51, 23, 0, 24], ["+", 206, 207, 0, 28, 0, 74, 51, 23, 0, 25]]
| 8
| 1,429
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var result = Calc26Base(N);
var sb = new StringBuilder();
foreach (var item in result) {
char chr = (char)(item - 1 + 'a');
sb.Append(chr);
}
Console.WriteLine(sb.ToString());
}
private static List<long> Calc26Base(long n) {
var result = new List<long>();
while (n != 0) {
result.Add(n % 26);
n = n / 26;
}
result.Reverse();
return result;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var result = Calc26Base(N);
var sb = new StringBuilder();
foreach (var item in result) {
char chr = (char)(item + 'a');
sb.Append(chr);
}
Console.WriteLine(sb.ToString());
}
private static List<long> Calc26Base(long n) {
var result = new List<long>();
while (n != 0) {
n--;
result.Add(n % 26);
n = n / 26;
}
result.Reverse();
return result;
}
}
|
[["-", 0, 74, 51, 23, 0, 16, 31, 16, 17, 33], ["-", 0, 74, 51, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 164
| 5
|
using System;
using System.Globalization;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
namespace atcoder1 {
class Program {
static void Main(string[] args) {
string input = Console.ReadLine();
long n = long.Parse(input);
string name = "";
while (n != 0) {
char alpha;
var num = n % 26;
if (num != 26) {
alpha = (char)(96 + num);
} else {
alpha = (char)(96 + 26);
}
name = alpha + name;
n--;
n /= 26;
}
Console.WriteLine(name.ToString());
}
}
}
|
using System;
using System.Globalization;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
namespace atcoder1 {
class Program {
static void Main(string[] args) {
string input = Console.ReadLine();
long n = long.Parse(input);
string name = "";
while (n != 0) {
char alpha;
var num = n % 26;
if (num == 0) {
alpha = (char)(96 + 26);
} else {
alpha = (char)(96 + num);
}
name = alpha + name;
n--;
n /= 26;
}
Console.WriteLine(name.ToString());
}
}
}
|
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 11, 12, 74, 51, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 74, 51, 23, 0, 16, 12, 203], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 12, 22]]
| 8
| 144
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc171_c {
class Program {
static void Main(string[] args) {
var N = CIn.ReadInt();
var list = new List<char>();
while (N > 0) {
list.Add((char)((N - 1) % 26 + 'a'));
N = (N - 1) / 26;
}
for (var i = list.Count - 1; i >= 0; i--) {
Console.Write(list[i]);
}
}
}
class CIn {
private static readonly Queue<string> fieldBuffer = new Queue<string>();
public static string Read() {
if (fieldBuffer.Count == 0) {
foreach (var field in Console.ReadLine().Split()) {
fieldBuffer.Enqueue(field);
}
}
return fieldBuffer.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static string[] ReadStringArray(long n) {
var array = new string[n];
for (var i = 0; i < n; i++) {
array[i] = Read();
}
return array;
}
public static int[] ReadIntArray(long n) {
var array = new int[n];
for (var i = 0; i < n; i++) {
array[i] = ReadInt();
}
return array;
}
public static long[] ReadLongArray(long n) {
var array = new long[n];
for (var i = 0; i < n; i++) {
array[i] = ReadLong();
}
return array;
}
public static double[] ReadDoubleArray(long n) {
var array = new double[n];
for (var i = 0; i < n; i++) {
array[i] = ReadDouble();
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc171_c {
class Program {
static void Main(string[] args) {
var N = CIn.ReadLong();
var list = new List<char>();
while (N > 0) {
list.Add((char)((N - 1) % 26 + 'a'));
N = (N - 1) / 26;
}
for (var i = list.Count - 1; i >= 0; i--) {
Console.Write(list[i]);
}
}
}
class CIn {
private static readonly Queue<string> fieldBuffer = new Queue<string>();
public static string Read() {
if (fieldBuffer.Count == 0) {
foreach (var field in Console.ReadLine().Split()) {
fieldBuffer.Enqueue(field);
}
}
return fieldBuffer.Dequeue();
}
public static int ReadInt() => int.Parse(Read());
public static long ReadLong() => long.Parse(Read());
public static double ReadDouble() => double.Parse(Read());
public static string[] ReadStringArray(long n) {
var array = new string[n];
for (var i = 0; i < n; i++) {
array[i] = Read();
}
return array;
}
public static int[] ReadIntArray(long n) {
var array = new int[n];
for (var i = 0; i < n; i++) {
array[i] = ReadInt();
}
return array;
}
public static long[] ReadLongArray(long n) {
var array = new long[n];
for (var i = 0; i < n; i++) {
array[i] = ReadLong();
}
return array;
}
public static double[] ReadDoubleArray(long n) {
var array = new double[n];
for (var i = 0; i < n; i++) {
array[i] = ReadDouble();
}
return array;
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 450
| 2
|
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml.Schema;
namespace AtCoder {
static class Program_D {
class Solver {
int ri => sc.Integer();
long rl => sc.Long();
double rd => sc.Double();
string rs => sc.Scan();
StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
private long baseNum = 26;
// 149-C - One Quadrillion and One Dalmatians
public void Solve() {
var n = rl;
var keta = CalcKeta(n);
var a = CreateArray(keta.Item1, keta.Item2);
var str = new string(a.Select(tmp => (char)('a' + tmp)).ToArray());
Wl(str);
// TestKeta();
// TestBaseArray();
}
private void TestBaseArray() {
var vals = new int[] { 0, 26 - 1, 26,
27, 28, 26 * 26 - 1,
26 * 26, 26 * 26 + 1, 26 * 26 * 26 - 1,
26 * 26 * 26 };
foreach (var val in vals) {
var a = CreateArray(4, val);
// var str = string.Join("",a.Select(tmp => $"[{tmp}]"));
var str = new string(a.Select(tmp => (char)('a' + tmp)).ToArray());
Wl($"{val} : {str}");
}
}
void TestKeta() {
var vals = new int[] { 1, 26, 27, 702, 703, 18278, 18279 };
foreach (var val in vals) {
var keta = CalcKeta(val);
Wl($"{val} => {keta.Item1}, {keta.Item2}");
}
}
Tuple<int, long> CalcKeta(long n) {
long test = 0;
for (int i = 1; i < 10; ++i) {
long nextTest = test + Pow(baseNum, i);
if (n <= nextTest) {
return Tuple.Create(i, n - test - 1);
}
test = nextTest;
}
return Tuple.Create(-1, -1L);
}
// nthは0オフセット.
int[] CreateArray(int keta, long val) {
var result = new int[keta];
for (int i = 0; i < keta; ++i) {
result[i] = (int)(val % baseNum);
val /= baseNum;
}
Array.Reverse(result);
return result;
}
// ----------------------------------------------------------------------------
private static long Pow(long a, long b) {
long result = 1;
for (int i = 0; i < b; ++i) {
result *= a;
}
return result;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
string Rl() { return Console.ReadLine(); }
void Wl(UInt64 val) { Console.WriteLine(val); }
void Wl(Int64 val) { Console.WriteLine(val); }
void Wl(uint val) { Console.WriteLine(val); }
void Wl(int val) { Console.WriteLine(val); }
void Wl(double val) { Console.WriteLine(val); }
void Wl(string mes) { Console.WriteLine(mes); }
public int Int() { return int.Parse(Console.ReadLine()); }
public int[] Ints(int subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) - subtract)
.ToArray();
}
public Int64[] Int64s(Int64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => Int64.Parse(s) - subtract)
.ToArray();
}
public UInt64[] UInt64s(UInt64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => UInt64.Parse(s) - subtract)
.ToArray();
}
}
static void Main(string[] args) {
// Console.SetOut(new Printer(Console.OpenStandardOutput()) { AutoFlush =
// false });
new Solver().Solve();
// Console.Out.Flush();
}
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider =>
CultureInfo.InvariantCulture;
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
struct ModInt {
const int MOD = 1000000007;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => a.Data + b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => a.Data - b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div;
long p = MOD;
long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml.Schema;
namespace AtCoder {
static class Program_D {
class Solver {
int ri => sc.Integer();
long rl => sc.Long();
double rd => sc.Double();
string rs => sc.Scan();
StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
private long baseNum = 26;
// 149-C - One Quadrillion and One Dalmatians
public void Solve() {
var n = rl;
var keta = CalcKeta(n);
var a = CreateArray(keta.Item1, keta.Item2);
var str = new string(a.Select(tmp => (char)('a' + tmp)).ToArray());
Wl(str);
// TestKeta();
// TestBaseArray();
}
private void TestBaseArray() {
var vals = new int[] { 0, 26 - 1, 26,
27, 28, 26 * 26 - 1,
26 * 26, 26 * 26 + 1, 26 * 26 * 26 - 1,
26 * 26 * 26 };
foreach (var val in vals) {
var a = CreateArray(4, val);
// var str = string.Join("",a.Select(tmp => $"[{tmp}]"));
var str = new string(a.Select(tmp => (char)('a' + tmp)).ToArray());
Wl($"{val} : {str}");
}
}
void TestKeta() {
var vals = new int[] { 1, 26, 27, 702, 703, 18278, 18279 };
foreach (var val in vals) {
var keta = CalcKeta(val);
Wl($"{val} => {keta.Item1}, {keta.Item2}");
}
}
Tuple<long, long> CalcKeta(long n) {
long test = 0;
for (long i = 1; i < 100; ++i) {
long nextTest = test + Pow(baseNum, i);
if (n <= nextTest) {
return Tuple.Create(i, n - test - 1);
}
test = nextTest;
}
return Tuple.Create(-1L, -1L);
}
// nthは0オフセット.
int[] CreateArray(long keta, long val) {
var result = new int[keta];
for (int i = 0; i < keta; ++i) {
result[i] = (int)(val % baseNum);
val /= baseNum;
}
Array.Reverse(result);
return result;
}
// ----------------------------------------------------------------------------
private static long Pow(long a, long b) {
long result = 1;
for (int i = 0; i < b; ++i) {
result *= a;
}
return result;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
string Rl() { return Console.ReadLine(); }
void Wl(UInt64 val) { Console.WriteLine(val); }
void Wl(Int64 val) { Console.WriteLine(val); }
void Wl(uint val) { Console.WriteLine(val); }
void Wl(int val) { Console.WriteLine(val); }
void Wl(double val) { Console.WriteLine(val); }
void Wl(string mes) { Console.WriteLine(mes); }
public int Int() { return int.Parse(Console.ReadLine()); }
public int[] Ints(int subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) - subtract)
.ToArray();
}
public Int64[] Int64s(Int64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => Int64.Parse(s) - subtract)
.ToArray();
}
public UInt64[] UInt64s(UInt64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => UInt64.Parse(s) - subtract)
.ToArray();
}
}
static void Main(string[] args) {
// Console.SetOut(new Printer(Console.OpenStandardOutput()) { AutoFlush =
// false });
new Solver().Solve();
// Console.Out.Flush();
}
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider =>
CultureInfo.InvariantCulture;
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
struct ModInt {
const int MOD = 1000000007;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => a.Data + b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => a.Data - b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div;
long p = MOD;
long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
[["-", 8, 201, 0, 195, 39, 236, 237, 238, 0, 199], ["+", 8, 201, 0, 195, 39, 236, 237, 238, 0, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199]]
| 8
| 1,706
| 10
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace AtCoder {
static class Program_D {
class Solver {
int ri => sc.Integer();
long rl => sc.Long();
double rd => sc.Double();
string rs => sc.Scan();
public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
public void Solve() {
var n = rl;
int pmax = 100;
var memo = new long[pmax];
int keta = 0;
for (; keta < pmax; ++keta) {
long pow = 1;
for (int p = 0; p < keta; ++p) {
pow *= 26;
}
if (keta == 0)
memo[keta] = 0;
else
memo[keta] = memo[keta - 1] + pow;
if (n < memo[keta])
break;
}
keta--;
var last = n - memo[keta] - 1;
var name = new List<int>();
for (int i = 0; i <= keta; ++i) {
int mod = (int)(last % 26);
last = last / 26;
name.Add(mod);
}
name.Reverse();
char[] v = name.Select(tmp => (char)('a' + tmp)).ToArray();
Console.WriteLine(v);
}
// ----------------------------------------------------------------------------
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
string Rl() { return Console.ReadLine(); }
void Wl(UInt64 val) { Console.WriteLine(val); }
void Wl(Int64 val) { Console.WriteLine(val); }
void Wl(uint val) { Console.WriteLine(val); }
void Wl(int val) { Console.WriteLine(val); }
void Wl(double val) { Console.WriteLine(val); }
void Wl(string mes) { Console.WriteLine(mes); }
public int Int() { return int.Parse(Console.ReadLine()); }
public int[] Ints(int subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) - subtract)
.ToArray();
}
public Int64[] Int64s(Int64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => Int64.Parse(s) - subtract)
.ToArray();
}
public UInt64[] UInt64s(UInt64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => UInt64.Parse(s) - subtract)
.ToArray();
}
}
static void Main(string[] args) {
Console.SetOut(
new Printer(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve();
Console.Out.Flush();
}
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider =>
CultureInfo.InvariantCulture;
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
struct ModInt {
const int MOD = 1000000007;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => a.Data + b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => a.Data - b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div;
long p = MOD;
long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace AtCoder {
static class Program_D {
class Solver {
int ri => sc.Integer();
long rl => sc.Long();
double rd => sc.Double();
string rs => sc.Scan();
public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
public void Solve() {
var n = rl;
int pmax = 100;
var memo = new long[pmax];
int keta = 0;
for (; keta < pmax; ++keta) {
long pow = 1;
for (int p = 0; p < keta; ++p) {
pow *= 26;
}
if (keta == 0)
memo[keta] = 0;
else
memo[keta] = memo[keta - 1] + pow;
if (n - 1 < memo[keta])
break;
}
keta--;
var last = n - memo[keta] - 1;
var name = new List<int>();
for (int i = 0; i <= keta; ++i) {
int mod = (int)(last % 26);
last = last / 26;
name.Add(mod);
}
name.Reverse();
char[] v = name.Select(tmp => (char)('a' + tmp)).ToArray();
Console.WriteLine(v);
}
// ----------------------------------------------------------------------------
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
string Rl() { return Console.ReadLine(); }
void Wl(UInt64 val) { Console.WriteLine(val); }
void Wl(Int64 val) { Console.WriteLine(val); }
void Wl(uint val) { Console.WriteLine(val); }
void Wl(int val) { Console.WriteLine(val); }
void Wl(double val) { Console.WriteLine(val); }
void Wl(string mes) { Console.WriteLine(mes); }
public int Int() { return int.Parse(Console.ReadLine()); }
public int[] Ints(int subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) - subtract)
.ToArray();
}
public Int64[] Int64s(Int64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => Int64.Parse(s) - subtract)
.ToArray();
}
public UInt64[] UInt64s(UInt64 subtract) {
return Console.ReadLine()
.Split(' ')
.Select(s => UInt64.Parse(s) - subtract)
.ToArray();
}
}
static void Main(string[] args) {
Console.SetOut(
new Printer(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve();
Console.Out.Flush();
}
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider =>
CultureInfo.InvariantCulture;
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
struct ModInt {
const int MOD = 1000000007;
long Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ModInt(long data) {
if ((Data = data % MOD) < 0)
Data += MOD;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator long(ModInt modInt) => modInt.Data;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ModInt(long val) => new ModInt(val);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, ModInt b) {
long res = a.Data + b.Data;
return new ModInt() { Data = res >= MOD ? res - MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator +(ModInt a, long b) => a.Data + b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, ModInt b) {
long res = a.Data - b.Data;
return new ModInt() { Data = res < 0 ? res + MOD : res };
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator -(ModInt a, long b) => a.Data - b;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator *(ModInt a, ModInt b) => new ModInt() {
Data = a.Data * b.Data % MOD
};
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => Data.ToString();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static long GetInverse(long a) {
long div;
long p = MOD;
long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 1,478
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public int[] Sarray() {
return ReadLine().Split().Select(int.Parse).ToArray();
}
static public List<int> Slist() {
var t = ReadLine();
if (t.Trim().Length == 0)
return new List<int>();
return new List<int>(t.Split().Select(int.Parse));
}
static void Main(string[] args) {
var n = Sarray()[0];
var ans = "";
while (0 < n) {
n -= 1;
ans += (char)('a' + n % 26);
n /= 26;
}
WriteLine(string.Join("", ans.Reverse()));
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;
namespace ConsoleApp2 {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<int> Slist() {
var t = ReadLine();
if (t.Trim().Length == 0)
return new List<int>();
return new List<int>(t.Split().Select(int.Parse));
}
static void Main(string[] args) {
var n = Sarray()[0];
var ans = "";
while (0 < n) {
n -= 1;
ans += (char)('a' + n % 26);
n /= 26;
}
WriteLine(string.Join("", ans.Reverse()));
}
}
}
|
[["-", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 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
| 254
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder171 {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var ans = string.Empty;
while (true) {
var i = n % 26;
ans = Convert.ToChar(0x60 + i) + ans;
n = n / 26;
if (n <= 0)
break;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder171 {
class Program {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var ans = string.Empty;
while (true) {
n--; // a-zの変換を0-25にするため
var i = n % 26;
ans = Convert.ToChar(0x61 + i) + ans;
n = n / 26;
if (n <= 0)
break;
}
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 203]]
| 8
| 114
| 5
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
// 整数の入力
int n = int.Parse(Console.ReadLine());
String name = "";
for (; n > 0;) {
n -= 1;
name += Convert.ToString((char)(n % 26 + 97));
n /= 26;
}
//出力
Console.WriteLine(name.Reverse().ToArray());
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
// 整数の入力
long n = long.Parse(Console.ReadLine());
String name = "";
for (; n > 0;) {
n -= 1;
name += Convert.ToString((char)(n % 26 + 97));
n /= 26;
}
//出力
Console.WriteLine(name.Reverse().ToArray());
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 96
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
//アルファベットテーブルを作成する
var alpha = new string[26] { "a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "X", "y", "Z" };
var N = long.Parse(Console.ReadLine());
var e = 1L;
var cnt = 1;
while (e * 26 < N) {
N = N - (long)Math.Pow(26, cnt);
// 26の階乗の数より小さいかチェックするための変数を設ける
e *= 26;
cnt++;
}
N--;
var ans = "";
//最後尾の文字列から順に回答を組み立てていく
for (int num = cnt - 1; 0 <= num; num--) {
ans = ans + alpha[N % 26];
N /= 26;
}
//順番が逆順なので反転して直す
Console.WriteLine(String.Join("", ans.Reverse()));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello {
public static void Main() {
//アルファベットテーブルを作成する
var alpha = new string[26] { "a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z" };
var N = long.Parse(Console.ReadLine());
var e = 1L;
var cnt = 1;
while (e * 26 < N) {
N = N - (long)Math.Pow(26, cnt);
// 26の階乗の数より小さいかチェックするための変数を設ける
e *= 26;
cnt++;
}
N--;
var ans = "";
//最後尾の文字列から順に回答を組み立てていく
for (int num = cnt - 1; 0 <= num; num--) {
ans = ans + alpha[N % 26];
N /= 26;
}
//順番が逆順なので反転して直す
Console.WriteLine(String.Join("", ans.Reverse()));
}
}
|
[["-", 0, 212, 0, 227, 0, 229, 0, 5, 0, 222], ["+", 0, 212, 0, 227, 0, 229, 0, 5, 0, 222]]
| 8
| 264
| 4
|
using System;
using System.Collections.Generic;
public class Program {
public static void Main(String[] args) {
Int64 a = Convert.ToInt64(Console.ReadLine());
var lst = new List<char>();
for (int i = 1; i < 11; ++i) {
if (a <= (long)Math.Pow(26, i)) {
a -= 1;
for (int j = 0; j < i; ++j) {
lst.Add((char)((int)'a' + (a % 26)));
a /= 26;
}
break;
} else {
a -= (long)Math.Pow(26, i);
}
}
// Console.WriteLine(a);
lst.Reverse();
foreach (var item in lst) {
Console.Write(item);
}
Console.WriteLine();
}
}
|
using System;
using System.Collections.Generic;
public class Program {
public static void Main(String[] args) {
Int64 a = Convert.ToInt64(Console.ReadLine());
var lst = new List<char>();
for (int i = 1; i < 99; ++i) {
if (a <= (long)Math.Pow(26, i)) {
a -= 1;
for (int j = 0; j < i; ++j) {
lst.Add((char)((int)'a' + (a % 26)));
a /= 26;
}
break;
} else {
a -= (long)Math.Pow(26, i);
}
}
// Console.WriteLine(a);
lst.Reverse();
foreach (var item in lst) {
Console.Write(item);
}
Console.WriteLine();
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 181
| 2
|
using System;
using System.Linq;
namespace C3 {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
n -= 1;
string answerRev = "";
for (int l = 1; l < 15; l++) {
if (n >= Math.Pow(26, l)) {
n -= (int)Math.Pow(26, l);
continue;
}
answerRev = "";
for (int i = 0; i < l; i++) {
int d = n % 26;
answerRev += (char)(d + 'a');
n /= 26;
}
break;
}
string answer = new string(answerRev.Reverse().ToArray());
Console.WriteLine(answer);
}
}
}
|
using System;
using System.Linq;
namespace C3 {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
n -= 1;
string answerRev = "";
for (long l = 1; l < 15; l++) {
if (n >= Math.Pow(26, l)) {
n -= (long)Math.Pow(26, l);
continue;
}
answerRev = "";
for (long i = 0; i < l; i++) {
long d = n % 26;
answerRev += (char)(d + 'a');
n /= 26;
}
break;
}
string answer = new string(answerRev.Reverse().ToArray());
Console.WriteLine(answer);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 169
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoderPractice {
class OneQuadrillionAndOneDalmatians {
static void Main(string[] args) {
ulong n = ulong.Parse(Console.ReadLine());
n -= 1;
string name = "";
char[] az = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'n', 'm', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
while (n > 25) {
name += az[n % 26];
n /= 26;
n--;
// Console.WriteLine(n);
}
name += az[n];
Console.WriteLine(string.Concat(name.Reverse()));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoderPractice {
class OneQuadrillionAndOneDalmatians {
static void Main(string[] args) {
ulong n = ulong.Parse(Console.ReadLine());
n -= 1;
string name = "";
char[] az = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
while (n > 25) {
name += az[n % 26];
n /= 26;
n--;
// Console.WriteLine(n);
}
name += az[n];
Console.WriteLine(string.Concat(name.Reverse()));
}
}
}
|
[["-", 0, 212, 0, 227, 0, 229, 0, 252, 0, 253], ["+", 0, 212, 0, 227, 0, 229, 0, 252, 0, 253]]
| 8
| 233
| 4
|
using System;
public class Hello {
public static void Main() {
var n = long.Parse(Console.ReadLine().Trim());
var p = 1L;
var w = 0L;
var count = 0;
while (w <= n) {
p *= 26;
w += p;
count++;
}
var t = n - (w - p);
getAns(t, count);
}
static void getAns(long t, int count) {
var a = "abcdefghijklmnopqrstuvwxyz";
var a2 = a.ToCharArray();
t--;
var res = new char[count];
for (int i = 0; i < count; i++) {
var rt = (int)(t % 26);
res[count - i - 1] = a[rt];
t /= 26;
}
Console.WriteLine(new string(res));
}
}
|
using System;
public class Hello {
public static void Main() {
var n = long.Parse(Console.ReadLine().Trim());
var p = 1L;
var w = 0L;
var count = 0;
while (w < n) {
p *= 26;
w += p;
count++;
}
var t = n - (w - p);
getAns(t, count);
}
static void getAns(long t, int count) {
var a = "abcdefghijklmnopqrstuvwxyz";
var a2 = a.ToCharArray();
t--;
var res = new char[count];
for (int i = 0; i < count; i++) {
var rt = (int)(t % 26);
res[count - i - 1] = a[rt];
t /= 26;
}
Console.WriteLine(new string(res));
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18]]
| 8
| 183
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;
namespace AtCoderTemplate {
class Program {
static void Main(string[] args) {
string[] str;
str = Console.ReadLine().Split(' ');
long N = int.Parse(str[0]);
string ans = "";
for (int i = 1; i < 100; i++) {
if (N <= Math.Pow(26, i)) {
N -= 1;
for (int j = 0; j < i; j++) {
ans = ((char)('a' + (N % 26))).ToString() + ans;
N /= 26;
}
break;
} else {
N -= (long)Math.Pow(26, i);
}
}
Console.WriteLine(ans);
}
}
class MyLibrary {
// 自作の関数
public static int MyFunction(int n) { return 0; }
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;
namespace AtCoderTemplate {
class Program {
static void Main(string[] args) {
string[] str;
str = Console.ReadLine().Split(' ');
long N = long.Parse(str[0]);
string ans = "";
for (int i = 1; i < 100; i++) {
if (N <= Math.Pow(26, i)) {
N -= 1;
for (int j = 0; j < i; j++) {
ans = ((char)('a' + (N % 26))).ToString() + ans;
N /= 26;
}
break;
} else {
N -= (long)Math.Pow(26, i);
}
}
Console.WriteLine(ans);
}
}
class MyLibrary {
// 自作の関数
public static int MyFunction(int n) { return 0; }
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 225
| 2
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
// 入力
int x = int.Parse(Console.ReadLine());
int q = 0;
int r = 0;
string ans = "";
while (x != 0) {
x--;
r = x % 26;
q = x / 26;
ans += ((char)(r + 97)).ToString();
// Console.WriteLine($"q = {q}, r = {r}, char = {(char)(r + 97)}");
x = q;
}
Console.WriteLine(new string(ans.Reverse().ToArray()));
}
}
|
using System;
using System.Linq;
class Program {
static void Main(string[] args) {
// 入力
long x = long.Parse(Console.ReadLine());
long q = 0;
long r = 0;
string ans = "";
while (x != 0) {
x--;
r = x % 26;
q = x / 26;
ans += ((char)(r + 97)).ToString();
// Console.WriteLine($"q = {q}, r = {r}, char = {(char)(r + 97)}");
x = q;
}
Console.WriteLine(new string(ans.Reverse().ToArray()));
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
| 8
| 118
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadLong();
var p = 1L;
var count = 1;
while (p * 26 <= N) {
p *= 26;
N -= p;
count++;
}
N--;
var a = new int[count];
for (int i = 0; i < count; i++) {
if (N == 0)
break;
a[i] += (int)(N % 26);
N /= 26;
}
var ans = "";
for (int i = count - 1; i >= 0; i--) {
ans += (char)('a' + a[i]);
}
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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadLong();
var p = 1L;
var count = 1;
while (p * 26 < N) {
p *= 26;
N -= p;
count++;
}
N--;
var a = new int[count];
for (int i = 0; i < count; i++) {
if (N == 0)
break;
a[i] += (int)(N % 26);
N /= 26;
}
var ans = "";
for (int i = count - 1; i >= 0; i--) {
ans += (char)('a' + a[i]);
}
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, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18]]
| 8
| 1,196
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;
public class Program {
public static void Main() {
var n = long.Parse(Console.ReadLine());
var name = GetExcelColumnName(n);
Console.WriteLine(name);
}
// original:
// https://www.it-swarm.dev/ja/c%23/%E5%88%97%E7%95%AA%E5%8F%B7%EF%BC%88%E4%BE%8B%EF%BC%9A127%EF%BC%89%E3%82%92excel%E5%88%97%EF%BC%88%E4%BE%8B%EF%BC%9Aaa%EF%BC%89%E3%81%AB%E5%A4%89%E6%8F%9B%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/958456720/
private static string GetExcelColumnName(long columnNumber) {
var dividend = columnNumber;
var columnName = String.Empty;
var modulo = 0L;
while (dividend > 0) {
modulo = (dividend - 1) % 26;
columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
dividend = (long)((dividend - modulo) / 26);
}
return columnName;
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;
public class Program {
public static void Main() {
var n = long.Parse(Console.ReadLine());
var name = GetExcelColumnName(n);
Console.WriteLine(name);
}
// original:
// https://www.it-swarm.dev/ja/c%23/%E5%88%97%E7%95%AA%E5%8F%B7%EF%BC%88%E4%BE%8B%EF%BC%9A127%EF%BC%89%E3%82%92excel%E5%88%97%EF%BC%88%E4%BE%8B%EF%BC%9Aaa%EF%BC%89%E3%81%AB%E5%A4%89%E6%8F%9B%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/958456720/
private static string GetExcelColumnName(long columnNumber) {
var dividend = columnNumber;
var columnName = String.Empty;
var modulo = 0L;
while (dividend > 0) {
modulo = (dividend - 1) % 26;
columnName = Convert.ToChar('a' + modulo).ToString() + columnName;
dividend = (long)((dividend - modulo) / 26);
}
return columnName;
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 252, 0, 104], ["+", 3, 4, 0, 28, 0, 16, 31, 252, 0, 253]]
| 8
| 148
| 4
|
using System;
using System.Collections.Generic;
namespace ABC171Test {
class Program {
static void Main() {
long N = long.Parse(Console.ReadLine());
List<char> alplist = new List<char>();
for (int code = 0x61; code < 0x7b; code++)
alplist.Add(Convert.ToChar(code));
long S = 0;
int k = 1;
long buf = N;
var result = string.Empty;
buf = 0;
while (S <= N) {
buf = S;
S += (long)Math.Pow(26, k);
k++;
}
long row = N - buf - 1;
int l = k - 1;
while (l > 0) {
long b = (long)Math.Pow(26, l - 1);
int al = (int)(row / b);
row = row % b;
result += alplist[al];
l--;
}
Console.WriteLine(result);
}
}
}
|
using System;
using System.Collections.Generic;
namespace ABC171Test {
class Program {
static void Main() {
long N = long.Parse(Console.ReadLine());
List<char> alplist = new List<char>();
for (int code = 0x61; code < 0x7b; code++)
alplist.Add(Convert.ToChar(code));
long S = 0;
int k = 1;
long buf = N;
var result = string.Empty;
buf = 0;
while (S < N) {
buf = S;
S += (long)Math.Pow(26, k);
k++;
}
long row = N - buf - 1;
int l = k - 1;
while (l > 0) {
long b = (long)Math.Pow(26, l - 1);
int al = (int)(row / b);
row = row % b;
result += alplist[al];
l--;
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18]]
| 8
| 210
| 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;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var n = sc.I;
n--;
var ans = "";
while (n >= 0) {
ans = (char)(n % 26 + 'a') + ans;
n /= 26;
n--;
}
Console.WriteLine("{0}", ans);
}
}
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(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).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;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var n = sc.L;
n--;
var ans = "";
while (n >= 0) {
ans = (char)(n % 26 + 'a') + ans;
n /= 26;
n--;
}
Console.WriteLine("{0}", ans);
}
}
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(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).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, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
| 8
| 862
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC171_C {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
long N = long.Parse(str);
string ans = string.Empty;
while (N != 0) {
long mod = N % 26;
ans = (char)('a' + mod - 1) + ans;
N /= 26;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC171_C {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
long N = long.Parse(str);
string ans = string.Empty;
while (N != 0) {
N--;
long mod = N % 26;
ans = (char)('a' + mod) + ans;
N /= 26;
}
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 12, 16, 31, 74, 51, 23, 0, 16, 17, 33], ["-", 12, 16, 31, 74, 51, 23, 0, 16, 12, 203]]
| 8
| 115
| 5
|
using System;
using System.Collections.Generic;
namespace C {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
List<int> n = new List<int>();
while (N / 26 != 0) {
if (N % 26 == 0) {
n.Add(26);
N = N / 26 - 1;
} else {
n.Add(N % 26);
N = N / 26;
}
}
if (N != 0) {
n.Add(N);
}
char[] map = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
List<char> ans_char = new List<char>();
for (int i = n.Count - 1; i >= 0; i--) {
ans_char.Add(map[n[i] - 1]);
}
string ans = "";
foreach (char element in ans_char) {
ans = ans + element;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
namespace C {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
List<long> n = new List<long>();
while (N / 26 != 0) {
if (N % 26 == 0) {
n.Add(26);
N = N / 26 - 1;
} else {
n.Add(N % 26);
N = N / 26;
}
}
if (N != 0) {
n.Add(N);
}
char[] map = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
List<char> ans_char = new List<char>();
for (int i = n.Count - 1; i >= 0; i--) {
ans_char.Add(map[n[i] - 1]);
}
string ans = "";
foreach (char element in ans_char) {
ans = ans + element;
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
| 8
| 313
| 8
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
namespace ForAtcoder {
class Program {
static void Main(string[] args) {
char[] alpha = "zabcdefghijklmnopqrstuvwxy".ToCharArray();
long n = long.Parse(Console.ReadLine());
string result = "";
do {
result = alpha[n % 26] + result;
n = n / 26;
} while (n != 0);
Console.WriteLine(result);
}
}
}
|
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
namespace ForAtcoder {
class Program {
static void Main(string[] args) {
char[] alpha = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
long n = long.Parse(Console.ReadLine());
string result = "";
do {
n--;
result = alpha[n % 26] + result;
n = n / 26;
} while (n != 0);
Console.WriteLine(result);
}
}
}
|
[["-", 0, 212, 0, 213, 63, 214, 205, 5, 0, 222], ["+", 0, 212, 0, 213, 63, 214, 205, 5, 0, 222], ["+", 0, 82, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 82, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 82, 8, 196, 0, 1, 0, 35]]
| 8
| 106
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC171 {
class Program {
static void Main(string[] args) { c(); }
public static void c() {
long n = long.Parse(Console.ReadLine());
string ans = "";
while (true) {
if (n < 27) {
char c = (char)(96 + n);
ans += c;
n -= 26;
} else if (n % 26 != 0) {
long kari = n % 26;
char c = (char)(96 + kari);
ans += c;
n /= 26;
} else if (n % 26 == 0) {
ans += "z";
n /= 26;
}
if (n <= 0)
break;
}
string ans1 = new string(ans.Reverse().ToArray());
Console.WriteLine(ans1);
}
// 1000000000000001
// 999999999999999
// 200000000000000
// 300000000000000
// 400000000000000
// 500000000000000
// 600000000000000
// 650000000000000
// 700000000000000
// 800000000000000
// 900000000000000
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC171 {
class Program {
static void Main(string[] args) { c(); }
public static void c() {
long n = long.Parse(Console.ReadLine());
string ans = "";
while (true) {
if (n < 27) {
char c = (char)(96 + n);
ans += c;
n -= 26;
} else if (n % 26 != 0) {
long kari = n % 26;
char c = (char)(96 + kari);
ans += c;
n /= 26;
} else if (n % 26 == 0) {
ans += "z";
n /= 26;
n--;
}
if (n <= 0)
break;
}
string ans1 = new string(ans.Reverse().ToArray());
Console.WriteLine(ans1);
}
// 1000000000000001
// 999999999999999
// 200000000000000
// 300000000000000
// 400000000000000
// 500000000000000
// 600000000000000
// 650000000000000
// 700000000000000
// 800000000000000
// 900000000000000
}
}
|
[["+", 75, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 75, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 214
| 3
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
List<char> tmp = new List<char>();
while (N != 0) {
int a = (int)N % 26;
tmp.Add((char)(a == 0 ? 122 : a + 96));
N = N / 26;
if (a == 0) {
N--;
}
}
tmp.Reverse();
Console.WriteLine(new String(tmp.ToArray()));
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
List<char> tmp = new List<char>();
while (N != 0) {
long a = N % 26;
tmp.Add((char)(a == 0 ? 122 : a + 96));
N = N / 26;
if (a == 0) {
N--;
}
}
tmp.Reverse();
Console.WriteLine(new String(tmp.ToArray()));
}
}
|
[["-", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25]]
| 8
| 129
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public long a;
public long b;
public long kosu;
public Pair(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Pair2 : IComparable {
public long a;
public long b;
public long kosu;
public long teki;
public Mlong jikkou = 1;
public Pair2(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair2 kore = (Pair2)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Dps : IComparable {
long[,] dp;
long i;
public Dps(long i, long n) {
this.i = i;
dp = new long[n, 100001];
}
public int CompareTo(object obj) {
Dps dps = (Dps)obj;
return i.CompareTo(dps.i);
}
}
class Program {
static List<int>[] togo;
static long[][,] dpps;
static bool[] visited;
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long n = scan.Long();
long now = 26;
long mae = 0;
int i = 0;
if (n <= 26) {
char kore = (char)(n + 96);
Console.WriteLine(kore);
return;
}
for (i = 0; i < 1000000; i++) {
if (now + mae >= n)
break;
long tmp = mae;
mae += now;
now *= 26;
}
string core = Convert10to36(n - mae - 1);
bool tt = false;
core = new string(core.Reverse().ToArray());
for (int k = i; k >= 0; k--) {
Console.Write(core[k]);
}
Console.WriteLine();
}
private static string Change35toZ(int intZ) {
string Change35toZ = "0";
if (intZ >= 0 && intZ < 26) {
// if (intZ > 9) intZ += 7;
intZ += 97;
Change35toZ = Convert.ToChar(intZ).ToString();
}
return Change35toZ;
}
// 10進数(0~2821109907455)を36進数に変換
private static string Convert10to36(long lngZ) {
string Convert10to36 = "";
long l;
int i;
for (int i1 = 7; i1 >= 0; i1--) {
l = (long)Math.Pow(26, i1);
i = (int)(lngZ / l);
l = i * l;
lngZ -= l;
Convert10to36 += Change35toZ(i);
}
return Convert10to36;
}
static void shuffle(Pair2[] ary) {
System.Random rng = new System.Random();
int n = ary.Length;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
var tmp = new Pair2(ary[k].a, ary[k].b);
ary[k] = new Pair2(ary[n].a, ary[n].b);
ary[n] = new Pair2(tmp.a, tmp.b);
}
}
static bool DFS(int now, int last) {
visited[now] = true;
for (int i = 0; i < togo[now].Count; i++) {
if (togo[now][i] == last) {
continue;
}
if (visited[togo[now][i]]) {
return false;
}
if (!DFS(togo[now][i], now)) {
return false;
}
}
return true;
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static void Soinsubunkai(long num) {
long m = num;
for (long i = 2; i * i < num; i++) {
long j = 0;
for (j = 0; j < num; j++) {
if (m % i == 0) {
m /= i;
}
}
// i^j | num,i^{j+1} not divide num
}
if (m != 1) {
//素因数が一つ残っている(k*k>numな素因数は高々一つ)
}
}
/* static List<CPair<long, long>> SoinsuBunkai(long num)
{
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++)
{
if (num % i != 0) { continue; }
yakusu.Add(i);
if (i * i != num) { yakusu2.Add(num / i); }
}
for (int i = 0; i < yakusu.Count; i++)
{
if (num % yakusu[i] != 0) { continue; }
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++)
{
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--)
{
if (num % yakusu2[i] != 0) { continue; }
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++)
{
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}*/
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public List<int> Topological_Sort(List<List<Edge>> G) {
var ret = new List<int>();
var Nodes = new Queue<int>();
int N = G.Count();
var Link = new int[N];
for (var i = 0; i < N; i++) {
Link[i] = 0;
}
for (var i = 0; i < N; i++) {
foreach (var nx in G[i]) {
Link[nx.to]++;
}
}
for (var i = 0; i < N; i++) {
if (Link[i] == 0) {
Nodes.Enqueue(i);
}
}
while (Nodes.Any()) {
var nd = Nodes.Dequeue();
ret.Add(nd);
foreach (var nx in G[nd]) {
Link[nx.to]--;
if (Link[nx.to] == 0) {
Nodes.Enqueue(nx.to);
}
}
}
return ret;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(long n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(long n, long m) {
char[,] kore = new char[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public bool Any() { return _root != null; }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public T max() {
SB_BinarySearchTree<T>.Node ima = _root;
while (ima.RChild != null) {
ima = ima.RChild;
}
return ima.Value;
}
public T min() {
SB_BinarySearchTree<T>.Node ima = _root;
while (ima.LChild != null) {
ima = ima.LChild;
}
return ima.Value;
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
public class SortedMultiSet<T> : IEnumerable<T> {
private SortedDictionary<T, int> _dict;
public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); }
public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); }
public bool Contains(T item) { return _dict.ContainsKey(item); }
public void Add(T item) {
if (_dict.ContainsKey(item))
_dict[item]++;
else
_dict[item] = 1;
}
public void Add(IEnumerable<T> items) {
foreach (var item in items)
Add(item);
}
public void Remove(T item) {
if (!_dict.ContainsKey(item))
throw new ArgumentException();
if (--_dict[item] == 0)
_dict.Remove(item);
}
// Return the last value in the multiset
public T Peek() {
if (!_dict.Any())
throw new NullReferenceException();
return _dict.Last().Key;
}
// Return the last value in the multiset and remove it.
public T Pop() {
T item = Peek();
Remove(item);
return item;
}
public IEnumerator<T> GetEnumerator() {
foreach (var kvp in _dict)
for (int i = 0; i < kvp.Value; i++)
yield return kvp.Key;
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public long a;
public long b;
public long kosu;
public Pair(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Pair2 : IComparable {
public long a;
public long b;
public long kosu;
public long teki;
public Mlong jikkou = 1;
public Pair2(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair2 kore = (Pair2)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Dps : IComparable {
long[,] dp;
long i;
public Dps(long i, long n) {
this.i = i;
dp = new long[n, 100001];
}
public int CompareTo(object obj) {
Dps dps = (Dps)obj;
return i.CompareTo(dps.i);
}
}
class Program {
static List<int>[] togo;
static long[][,] dpps;
static bool[] visited;
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long n = scan.Long();
long now = 26;
long mae = 0;
int i = 0;
if (n <= 26) {
char kore = (char)(n + 96);
Console.WriteLine(kore);
return;
}
for (i = 0; i < 1000000; i++) {
if (now + mae >= n)
break;
long tmp = mae;
mae += now;
now *= 26;
}
string core = Convert10to36(n - mae - 1);
bool tt = false;
core = new string(core.Reverse().ToArray());
for (int k = i; k >= 0; k--) {
Console.Write(core[k]);
}
Console.WriteLine();
}
private static string Change35toZ(int intZ) {
string Change35toZ = "0";
if (intZ >= 0 && intZ < 26) {
// if (intZ > 9) intZ += 7;
intZ += 97;
Change35toZ = Convert.ToChar(intZ).ToString();
}
return Change35toZ;
}
// 10進数(0~2821109907455)を36進数に変換
private static string Convert10to36(long lngZ) {
string Convert10to36 = "";
long l;
int i;
for (int i1 = 15; i1 >= 0; i1--) {
l = (long)Math.Pow(26, i1);
i = (int)(lngZ / l);
l = i * l;
lngZ -= l;
Convert10to36 += Change35toZ(i);
}
return Convert10to36;
}
static void shuffle(Pair2[] ary) {
System.Random rng = new System.Random();
int n = ary.Length;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
var tmp = new Pair2(ary[k].a, ary[k].b);
ary[k] = new Pair2(ary[n].a, ary[n].b);
ary[n] = new Pair2(tmp.a, tmp.b);
}
}
static bool DFS(int now, int last) {
visited[now] = true;
for (int i = 0; i < togo[now].Count; i++) {
if (togo[now][i] == last) {
continue;
}
if (visited[togo[now][i]]) {
return false;
}
if (!DFS(togo[now][i], now)) {
return false;
}
}
return true;
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static void Soinsubunkai(long num) {
long m = num;
for (long i = 2; i * i < num; i++) {
long j = 0;
for (j = 0; j < num; j++) {
if (m % i == 0) {
m /= i;
}
}
// i^j | num,i^{j+1} not divide num
}
if (m != 1) {
//素因数が一つ残っている(k*k>numな素因数は高々一つ)
}
}
/* static List<CPair<long, long>> SoinsuBunkai(long num)
{
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++)
{
if (num % i != 0) { continue; }
yakusu.Add(i);
if (i * i != num) { yakusu2.Add(num / i); }
}
for (int i = 0; i < yakusu.Count; i++)
{
if (num % yakusu[i] != 0) { continue; }
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++)
{
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--)
{
if (num % yakusu2[i] != 0) { continue; }
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++)
{
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}*/
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public List<int> Topological_Sort(List<List<Edge>> G) {
var ret = new List<int>();
var Nodes = new Queue<int>();
int N = G.Count();
var Link = new int[N];
for (var i = 0; i < N; i++) {
Link[i] = 0;
}
for (var i = 0; i < N; i++) {
foreach (var nx in G[i]) {
Link[nx.to]++;
}
}
for (var i = 0; i < N; i++) {
if (Link[i] == 0) {
Nodes.Enqueue(i);
}
}
while (Nodes.Any()) {
var nd = Nodes.Dequeue();
ret.Add(nd);
foreach (var nx in G[nd]) {
Link[nx.to]--;
if (Link[nx.to] == 0) {
Nodes.Enqueue(nx.to);
}
}
}
return ret;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(long n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(long n, long m) {
char[,] kore = new char[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public bool Any() { return _root != null; }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public T max() {
SB_BinarySearchTree<T>.Node ima = _root;
while (ima.RChild != null) {
ima = ima.RChild;
}
return ima.Value;
}
public T min() {
SB_BinarySearchTree<T>.Node ima = _root;
while (ima.LChild != null) {
ima = ima.LChild;
}
return ima.Value;
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
public class SortedMultiSet<T> : IEnumerable<T> {
private SortedDictionary<T, int> _dict;
public SortedMultiSet() { _dict = new SortedDictionary<T, int>(); }
public SortedMultiSet(IEnumerable<T> items) : this() { Add(items); }
public bool Contains(T item) { return _dict.ContainsKey(item); }
public void Add(T item) {
if (_dict.ContainsKey(item))
_dict[item]++;
else
_dict[item] = 1;
}
public void Add(IEnumerable<T> items) {
foreach (var item in items)
Add(item);
}
public void Remove(T item) {
if (!_dict.ContainsKey(item))
throw new ArgumentException();
if (--_dict[item] == 0)
_dict.Remove(item);
}
// Return the last value in the multiset
public T Peek() {
if (!_dict.Any())
throw new NullReferenceException();
return _dict.Last().Key;
}
// Return the last value in the multiset and remove it.
public T Pop() {
T item = Peek();
Remove(item);
return item;
}
public IEnumerator<T> GetEnumerator() {
foreach (var kvp in _dict)
for (int i = 0; i < kvp.Value; i++)
yield return kvp.Key;
}
IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); }
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 12,404
| 2
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Numerics;
namespace ABC171.C {
using static Util;
using static Math;
public class Solver : SolverBase {
public void Run() {
var N = ReadLong();
StringBuilder revSb = new StringBuilder();
while (0 < N) {
N = DivRem(N, 26, out var r);
if (r == 0) {
r = 25;
} else {
r -= 1;
}
char c = (char)('a' + r);
revSb.Append(c);
}
var ans = revSb.ToString().ReverseStr();
WriteLine(ans);
}
#if !MYHOME
static void Main(string[] args) { new Solver().Run(); }
#endif
}
public static class Util {
/// <summary>反転した新しいstringを返す</summary>
public static string ReverseStr(this string s) {
return new string(s.Reverse().ToArray());
}
public static int Gcd(int a, int b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public readonly static long MOD = 1000000007;
public static string JoinString<T>(IEnumerable<T> array) {
var sb = new StringBuilder();
foreach (var item in array) {
sb.Append(item);
sb.Append(", ");
}
return sb.ToString();
}
public static void InitArray<T>(T[] ary, T value) {
for (int i = 0; i < ary.Length; i++) {
ary[i] = value;
}
}
public static void InitDP2<T>(T[,] dp, T value) {
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
dp[i, j] = value;
}
}
}
public static void InitDP3<T>(T[,,] dp, T value) {
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
for (int k = 0; k < dp.GetLength(2); k++) {
dp[i, j, k] = value;
}
}
}
}
/// <summary>charでも対応可能なMax</summary>
public static T Max<T>(T a, T b)
where T : IComparable { return 0 <= a.CompareTo(b) ? a : b; }
/// <summary>3要素以上に対応するMax</summary>
public static T Max<T>(params T[] nums)
where T : IComparable {
if (nums.Length == 0)
return default(T);
T max = nums[0];
for (int i = 1; i < nums.Length; i++) {
max = max.CompareTo(nums[i]) > 0 ? max : nums[i];
}
return max;
}
/// <summary>charでも対応可能なMin</summary>
public static T Min<T>(T a, T b)
where T : IComparable { return 0 < a.CompareTo(b) ? b : a; }
/// <summary>3要素以上に対応するMin</summary>
public static T Min<T>(params T[] nums)
where T : IComparable {
if (nums.Length == 0)
return default(T);
T min = nums[0];
for (int i = 1; i < nums.Length; i++) {
min = min.CompareTo(nums[i]) < 0 ? min : nums[i];
}
return min;
}
///< summary>targetValueに一番近い値を返す</summary>
public static long Nearest(long targetValue, params long[] values) {
Debug.Assert(0 < values.Length);
long minDiff = long.MaxValue;
long ans = long.MaxValue;
foreach (var v in values) {
var diff = Math.Abs(v - targetValue);
if (ReplaceIfSmaller(ref minDiff, diff)) {
ans = v;
}
}
return ans;
}
/// <summary>
/// ソート済み配列 ary に同じ値の要素が含まれている?
/// ※ソート順は昇順/降順どちらでもよい
/// </summary>
public static bool HasDuplicateInSortedArray<T>(T[] ary)
where T : IComparable, IComparable<T> {
if (ary.Length <= 1)
return false;
var lastNum = ary[ary.Length - 1];
foreach (var n in ary) {
if (lastNum.CompareTo(n) == 0) {
return true;
} else {
lastNum = n;
}
}
return false;
}
///< summary>v が r より大きい場合、r に v
///< を代入し、trueを返す。それ以外(同値の場合を含む)は何もせずfalseを返す</summary>
public static bool ReplaceIfBigger<T>(ref T r, T v)
where T : IComparable {
if (r.CompareTo(v) < 0) {
r = v;
return true;
} else {
return false;
}
}
///< summary>v が r よりが小さい場合、r に v
///< を代入し、trueを返す。それ以外(同値の場合を含む)は何もせずfalseを返す</summary>
public static bool ReplaceIfSmaller<T>(ref T r, T v)
where T : IComparable {
if (0 < r.CompareTo(v)) {
r = v;
return true;
} else {
return false;
}
}
public static void Swap<T>(ref T a, ref T b)
where T : class {
var tmp = a;
a = b;
b = tmp;
}
/// <summary>
/// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder
/// をセットする。
/// </summary>
public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key,
int adder) {
if (dic.ContainsKey(key)) {
dic[key] += adder;
} else {
dic[key] = adder;
}
}
/// <summary>
/// 文字列 s が chars に含まれる文字を含んでいるか?
/// </summary>
public static bool ContainsAny(this string s, char[] chars) {
for (int j = 0; j < s.Length; j++) {
if (chars.Contains(s[j]))
return true;
}
return false;
}
/// <summary>
/// 二分探索
/// ※条件を満たす最小のidxを返す
/// ※満たすものがない場合は ary.Length を返す
/// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提
/// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。
/// </summary>
/// <param name="ary">探索対象配列 ★ソート済みであること</param>
/// <param name="key">探索値
/// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param>
public static int BinarySearch<T>(T[] ary, T key)
where T : IComparable, IComparable<T> {
int left = -1;
int right = ary.Length;
while (1 < right - left) {
var mid = left + (right - left) / 2;
if (IsOK(ary, mid, key)) {
right = mid;
} else {
left = mid;
}
}
// left は条件を満たさない最大の値、right
// は条件を満たす最小の値になっている
return right;
}
public static bool IsOK<T>(T[] ary, int idx, T key)
where T : IComparable, IComparable<T> {
// key <= ary[idx] と同じ意味
return key.CompareTo(ary[idx]) <= 0;
}
/// <summary>
/// nの 2進数における下からd(0-indexed)桁目のbitが立っている?
/// </summary>
public static int GetBit(long n, int d) {
if (0 == (n & (1L << d)))
return 0;
else
return 1;
}
}
public class SolverBase {
virtual protected string ReadLine() => Console.ReadLine();
virtual protected string ReadString() => ReadLine();
virtual protected int ReadInt() => int.Parse(ReadLine());
virtual protected long ReadLong() => long.Parse(ReadLine());
virtual protected string[] ReadStringArray() => ReadLine().Split(' ');
virtual protected void ReadString2(out string a, out string b) {
var ary = ReadStringArray();
a = ary[0];
b = ary[1];
}
virtual protected void ReadString3(out string a, out string b,
out string c) {
var ary = ReadStringArray();
a = ary[0];
b = ary[1];
c = ary[2];
}
virtual protected char[] ReadCharArray() => ReadLine()
.Split(' ')
.Select<string, char>(
s => s[0])
.ToArray();
virtual protected int[] ReadIntArray() => ReadLine()
.Split(' ')
.Select<string, int>(
s => int.Parse(s))
.ToArray();
virtual protected void ReadInt2(out int a, out int b) {
var ary = ReadIntArray();
a = ary[0];
b = ary[1];
}
virtual protected void ReadInt3(out int a, out int b, out int c) {
var ary = ReadIntArray();
a = ary[0];
b = ary[1];
c = ary[2];
}
virtual protected void ReadInt4(out int a, out int b, out int c,
out int d) {
var ary = ReadIntArray();
a = ary[0];
b = ary[1];
c = ary[2];
d = ary[3];
}
virtual protected long[] ReadLongArray() => ReadLine()
.Split(' ')
.Select<string, long>(
s => long.Parse(s))
.ToArray();
virtual protected void ReadLong2(out long a, out long b) {
var ary = ReadLongArray();
a = ary[0];
b = ary[1];
}
virtual protected void ReadLong3(out long a, out long b, out long c) {
var ary = ReadLongArray();
a = ary[0];
b = ary[1];
c = ary[2];
}
virtual protected void ReadLong4(out long a, out long b, out long c,
out long d) {
var ary = ReadLongArray();
a = ary[0];
b = ary[1];
c = ary[2];
d = ary[3];
}
virtual protected double[] ReadDoubleArray() => ReadLine()
.Split(' ')
.Select<string, double>(
s =>
double.Parse(s))
.ToArray();
virtual protected void WriteLine(string line) => Console.WriteLine(line);
virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}");
virtual protected void WriteLine<T>(T value)
where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) {
var sb = new StringBuilder();
foreach (var a in arrayOfArray) {
foreach (var c in a) {
sb.Append(c);
}
sb.AppendLine();
}
WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void Dump(double d) => Console.WriteLine($"{d:F9}");
[Conditional("DEBUG")]
protected void Dump<T>(T x) => Console.WriteLine(x);
[Conditional("DEBUG")]
protected void DumpArray<T>(IEnumerable<T> array) {
string s = Util.JoinString(array);
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(s);
//_writer.WriteLine(s);
}
[Conditional("DEBUG")]
protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) {
var sb = new StringBuilder();
foreach (var a in arrayOfArray) {
foreach (var c in a) {
sb.Append(c);
}
sb.AppendLine();
}
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(sb.ToString());
//_writer.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) {
var sb = new StringBuilder();
foreach (var a in arrayOfArray) {
sb.AppendLine(Util.JoinString(a));
}
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(sb.ToString());
//_writer.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpGrid(bool[,] grid) {
var sb = new StringBuilder();
for (int i = 0; i < grid.GetLength(0); i++) {
for (int j = 0; j < grid.GetLength(1); j++) {
sb.Append(grid[i, j] ? "x " : ". ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpGrid(char[,] grid) {
var sb = new StringBuilder();
for (int i = 0; i < grid.GetLength(0); i++) {
for (int j = 0; j < grid.GetLength(1); j++) {
sb.Append(grid[i, j]);
sb.Append(" ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpDP<T>(T[,] dp)
where T : IFormattable {
var sb = new StringBuilder();
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
sb.Append(dp[i, j]);
sb.Append(", ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpDP3_Keta<T>(T[,,] dp)
where T : IFormattable {
var sb = new StringBuilder();
for (int i = 0; i < dp.GetLength(0); i++) {
sb.Append($"{i,2}: ");
for (int j = 0; j < dp.GetLength(1); j++) {
sb.Append($"{dp[i, j, 0]}-{dp[i, j, 1]}");
sb.Append(", ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Numerics;
namespace ABC171.C {
using static Util;
using static Math;
public class Solver : SolverBase {
public void Run() {
var N = ReadLong();
StringBuilder revSb = new StringBuilder();
while (0 < N) {
N = DivRem(N, 26, out var r);
if (r == 0) {
r = 25;
--N;
} else {
--r;
}
char c = (char)('a' + r);
revSb.Append(c);
}
var ans = revSb.ToString().ReverseStr();
WriteLine(ans);
}
#if !MYHOME
static void Main(string[] args) { new Solver().Run(); }
#endif
}
public static class Util {
/// <summary>反転した新しいstringを返す</summary>
public static string ReverseStr(this string s) {
return new string(s.Reverse().ToArray());
}
public static int Gcd(int a, int b) {
if (a < b)
// 引数を入替えて自分を呼び出す
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
public readonly static long MOD = 1000000007;
public static string JoinString<T>(IEnumerable<T> array) {
var sb = new StringBuilder();
foreach (var item in array) {
sb.Append(item);
sb.Append(", ");
}
return sb.ToString();
}
public static void InitArray<T>(T[] ary, T value) {
for (int i = 0; i < ary.Length; i++) {
ary[i] = value;
}
}
public static void InitDP2<T>(T[,] dp, T value) {
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
dp[i, j] = value;
}
}
}
public static void InitDP3<T>(T[,,] dp, T value) {
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
for (int k = 0; k < dp.GetLength(2); k++) {
dp[i, j, k] = value;
}
}
}
}
/// <summary>charでも対応可能なMax</summary>
public static T Max<T>(T a, T b)
where T : IComparable { return 0 <= a.CompareTo(b) ? a : b; }
/// <summary>3要素以上に対応するMax</summary>
public static T Max<T>(params T[] nums)
where T : IComparable {
if (nums.Length == 0)
return default(T);
T max = nums[0];
for (int i = 1; i < nums.Length; i++) {
max = max.CompareTo(nums[i]) > 0 ? max : nums[i];
}
return max;
}
/// <summary>charでも対応可能なMin</summary>
public static T Min<T>(T a, T b)
where T : IComparable { return 0 < a.CompareTo(b) ? b : a; }
/// <summary>3要素以上に対応するMin</summary>
public static T Min<T>(params T[] nums)
where T : IComparable {
if (nums.Length == 0)
return default(T);
T min = nums[0];
for (int i = 1; i < nums.Length; i++) {
min = min.CompareTo(nums[i]) < 0 ? min : nums[i];
}
return min;
}
///< summary>targetValueに一番近い値を返す</summary>
public static long Nearest(long targetValue, params long[] values) {
Debug.Assert(0 < values.Length);
long minDiff = long.MaxValue;
long ans = long.MaxValue;
foreach (var v in values) {
var diff = Math.Abs(v - targetValue);
if (ReplaceIfSmaller(ref minDiff, diff)) {
ans = v;
}
}
return ans;
}
/// <summary>
/// ソート済み配列 ary に同じ値の要素が含まれている?
/// ※ソート順は昇順/降順どちらでもよい
/// </summary>
public static bool HasDuplicateInSortedArray<T>(T[] ary)
where T : IComparable, IComparable<T> {
if (ary.Length <= 1)
return false;
var lastNum = ary[ary.Length - 1];
foreach (var n in ary) {
if (lastNum.CompareTo(n) == 0) {
return true;
} else {
lastNum = n;
}
}
return false;
}
///< summary>v が r より大きい場合、r に v
///< を代入し、trueを返す。それ以外(同値の場合を含む)は何もせずfalseを返す</summary>
public static bool ReplaceIfBigger<T>(ref T r, T v)
where T : IComparable {
if (r.CompareTo(v) < 0) {
r = v;
return true;
} else {
return false;
}
}
///< summary>v が r よりが小さい場合、r に v
///< を代入し、trueを返す。それ以外(同値の場合を含む)は何もせずfalseを返す</summary>
public static bool ReplaceIfSmaller<T>(ref T r, T v)
where T : IComparable {
if (0 < r.CompareTo(v)) {
r = v;
return true;
} else {
return false;
}
}
public static void Swap<T>(ref T a, ref T b)
where T : class {
var tmp = a;
a = b;
b = tmp;
}
/// <summary>
/// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder
/// をセットする。
/// </summary>
public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key,
int adder) {
if (dic.ContainsKey(key)) {
dic[key] += adder;
} else {
dic[key] = adder;
}
}
/// <summary>
/// 文字列 s が chars に含まれる文字を含んでいるか?
/// </summary>
public static bool ContainsAny(this string s, char[] chars) {
for (int j = 0; j < s.Length; j++) {
if (chars.Contains(s[j]))
return true;
}
return false;
}
/// <summary>
/// 二分探索
/// ※条件を満たす最小のidxを返す
/// ※満たすものがない場合は ary.Length を返す
/// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提
/// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。
/// </summary>
/// <param name="ary">探索対象配列 ★ソート済みであること</param>
/// <param name="key">探索値
/// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param>
public static int BinarySearch<T>(T[] ary, T key)
where T : IComparable, IComparable<T> {
int left = -1;
int right = ary.Length;
while (1 < right - left) {
var mid = left + (right - left) / 2;
if (IsOK(ary, mid, key)) {
right = mid;
} else {
left = mid;
}
}
// left は条件を満たさない最大の値、right
// は条件を満たす最小の値になっている
return right;
}
public static bool IsOK<T>(T[] ary, int idx, T key)
where T : IComparable, IComparable<T> {
// key <= ary[idx] と同じ意味
return key.CompareTo(ary[idx]) <= 0;
}
/// <summary>
/// nの 2進数における下からd(0-indexed)桁目のbitが立っている?
/// </summary>
public static int GetBit(long n, int d) {
if (0 == (n & (1L << d)))
return 0;
else
return 1;
}
}
public class SolverBase {
virtual protected string ReadLine() => Console.ReadLine();
virtual protected string ReadString() => ReadLine();
virtual protected int ReadInt() => int.Parse(ReadLine());
virtual protected long ReadLong() => long.Parse(ReadLine());
virtual protected string[] ReadStringArray() => ReadLine().Split(' ');
virtual protected void ReadString2(out string a, out string b) {
var ary = ReadStringArray();
a = ary[0];
b = ary[1];
}
virtual protected void ReadString3(out string a, out string b,
out string c) {
var ary = ReadStringArray();
a = ary[0];
b = ary[1];
c = ary[2];
}
virtual protected char[] ReadCharArray() => ReadLine()
.Split(' ')
.Select<string, char>(
s => s[0])
.ToArray();
virtual protected int[] ReadIntArray() => ReadLine()
.Split(' ')
.Select<string, int>(
s => int.Parse(s))
.ToArray();
virtual protected void ReadInt2(out int a, out int b) {
var ary = ReadIntArray();
a = ary[0];
b = ary[1];
}
virtual protected void ReadInt3(out int a, out int b, out int c) {
var ary = ReadIntArray();
a = ary[0];
b = ary[1];
c = ary[2];
}
virtual protected void ReadInt4(out int a, out int b, out int c,
out int d) {
var ary = ReadIntArray();
a = ary[0];
b = ary[1];
c = ary[2];
d = ary[3];
}
virtual protected long[] ReadLongArray() => ReadLine()
.Split(' ')
.Select<string, long>(
s => long.Parse(s))
.ToArray();
virtual protected void ReadLong2(out long a, out long b) {
var ary = ReadLongArray();
a = ary[0];
b = ary[1];
}
virtual protected void ReadLong3(out long a, out long b, out long c) {
var ary = ReadLongArray();
a = ary[0];
b = ary[1];
c = ary[2];
}
virtual protected void ReadLong4(out long a, out long b, out long c,
out long d) {
var ary = ReadLongArray();
a = ary[0];
b = ary[1];
c = ary[2];
d = ary[3];
}
virtual protected double[] ReadDoubleArray() => ReadLine()
.Split(' ')
.Select<string, double>(
s =>
double.Parse(s))
.ToArray();
virtual protected void WriteLine(string line) => Console.WriteLine(line);
virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}");
virtual protected void WriteLine<T>(T value)
where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) {
var sb = new StringBuilder();
foreach (var a in arrayOfArray) {
foreach (var c in a) {
sb.Append(c);
}
sb.AppendLine();
}
WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void Dump(double d) => Console.WriteLine($"{d:F9}");
[Conditional("DEBUG")]
protected void Dump<T>(T x) => Console.WriteLine(x);
[Conditional("DEBUG")]
protected void DumpArray<T>(IEnumerable<T> array) {
string s = Util.JoinString(array);
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(s);
//_writer.WriteLine(s);
}
[Conditional("DEBUG")]
protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) {
var sb = new StringBuilder();
foreach (var a in arrayOfArray) {
foreach (var c in a) {
sb.Append(c);
}
sb.AppendLine();
}
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(sb.ToString());
//_writer.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) {
var sb = new StringBuilder();
foreach (var a in arrayOfArray) {
sb.AppendLine(Util.JoinString(a));
}
// Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。
Console.WriteLine(sb.ToString());
//_writer.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpGrid(bool[,] grid) {
var sb = new StringBuilder();
for (int i = 0; i < grid.GetLength(0); i++) {
for (int j = 0; j < grid.GetLength(1); j++) {
sb.Append(grid[i, j] ? "x " : ". ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpGrid(char[,] grid) {
var sb = new StringBuilder();
for (int i = 0; i < grid.GetLength(0); i++) {
for (int j = 0; j < grid.GetLength(1); j++) {
sb.Append(grid[i, j]);
sb.Append(" ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpDP<T>(T[,] dp)
where T : IFormattable {
var sb = new StringBuilder();
for (int i = 0; i < dp.GetLength(0); i++) {
for (int j = 0; j < dp.GetLength(1); j++) {
sb.Append(dp[i, j]);
sb.Append(", ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
[Conditional("DEBUG")]
protected void DumpDP3_Keta<T>(T[,,] dp)
where T : IFormattable {
var sb = new StringBuilder();
for (int i = 0; i < dp.GetLength(0); i++) {
sb.Append($"{i,2}: ");
for (int j = 0; j < dp.GetLength(1); j++) {
sb.Append($"{dp[i, j, 0]}-{dp[i, j, 1]}");
sb.Append(", ");
}
sb.AppendLine();
}
Console.WriteLine(sb.ToString());
}
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 241, 0, 68], ["+", 0, 57, 64, 196, 0, 1, 0, 241, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 241, 0, 68], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 2,822
| 6
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
var N = vals[0] - 1;
var S = new List<char>();
long strln = 1;
long offset = 0;
long pow = 26;
while (offset + pow <= N) {
strln++;
offset += pow;
pow *= 26;
}
N = N - offset;
for (int i = 0; i < strln; i++) {
S.Add((char)('a' + (int)N % 26));
N /= 26;
}
S.Reverse();
var B = new StringBuilder();
foreach (var item in S) {
B.Append(item);
}
Console.WriteLine(B.ToString());
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace contest_Csharp {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var vals =
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
var N = vals[0] - 1;
var S = new List<char>();
long strln = 1;
long offset = 0;
long pow = 26;
while (offset + pow <= N) {
strln++;
offset += pow;
pow *= 26;
}
N = N - offset;
for (int i = 0; i < strln; i++) {
S.Add((char)('a' + (int)(N % 26)));
N /= 26;
}
S.Reverse();
var B = new StringBuilder();
foreach (var item in S) {
B.Append(item);
}
Console.WriteLine(B.ToString());
Console.Out.Flush();
}
}
}
|
[["+", 51, 23, 0, 16, 12, 74, 51, 23, 0, 24], ["+", 51, 23, 0, 16, 12, 74, 51, 23, 0, 25]]
| 8
| 258
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace c {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var result = hoge(N).ToLower();
Console.WriteLine(result);
}
static string hoge(int self) {
int n = self % 26;
n = (n == 0) ? 26 : n;
string s = ((char)(n + 64)).ToString();
if (self == n)
return s;
return hoge((self - n) / 26) + s;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace c {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
var result = hoge(N).ToLower();
Console.WriteLine(result);
}
static string hoge(long self) {
long n = self % 26;
n = (n == 0) ? 26 : n;
string s = ((char)(n + 64)).ToString();
if (self == n)
return s;
return hoge((self - n) / 26) + s;
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 136
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var alphabet = "zabcdefghijklmnopqrstuvwxy";
var N = ReadLineLong();
var num = 26;
var Name = "";
while (true) {
var m = (int)(N % num);
N = N / num;
Name = alphabet[m].ToString() + Name;
if (N == 0) {
break;
}
}
Console.WriteLine(Name);
}
#region 使いまわし
static string ReadLineStr() { return Console.ReadLine(); }
static int ReadLineInt() { return Convert.ToInt32(Console.ReadLine()); }
static (int, int) ReadLineInt2() {
var temp = Console.ReadLine().Split(' ');
return (Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1]));
}
static long ReadLineLong() { return Convert.ToInt64(Console.ReadLine()); }
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var N = ReadLineLong();
var num = 26;
var Name = "";
while (true) {
N--;
var m = (int)(N % num);
N = N / num;
Name = alphabet[m].ToString() + Name;
if (N == 0) {
break;
}
}
Console.WriteLine(Name);
}
#region 使いまわし
static string ReadLineStr() { return Console.ReadLine(); }
static int ReadLineInt() { return Convert.ToInt32(Console.ReadLine()); }
static (int, int) ReadLineInt2() {
var temp = Console.ReadLine().Split(' ');
return (Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1]));
}
static long ReadLineLong() { return Convert.ToInt64(Console.ReadLine()); }
#endregion
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 8
| 220
| 5
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Policy;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
checked {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// TestCaseMaker.MakeTestCase1("../TextFile2.txt");
// MyDebugger.Test(process, "../TextFile2.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
}
static object process(TextReader input) {
// 1000000000000001
var n = long.Parse(input.ReadLine());
// 26進数
var sb = new StringBuilder();
while (n > 0) {
var x = (n % 26);
if (x == 0) {
x = 26;
var c = ('a' - 1) + x;
sb.Append((char)c);
n /= 26;
n /= 26;
} else {
var c = ('a' - 1) + x;
sb.Append((char)c);
n /= 26;
}
}
var sb2 = new StringBuilder(sb.Length);
for (int i = 0; i < sb.Length; i++) {
sb2.Append(sb[sb.Length - i - 1]);
}
return sb2;
}
static int[] ToIntArray(string strs, int n) {
var ret = new int[n];
if (n == 0)
return ret;
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Policy;
class Program {
const string Yes = "Yes";
const string No = "No";
const char White = '.';
const char Black = '#';
const long Mod = 1000000007;
static void Main(string[] args) {
checked {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
// TestCaseMaker.MakeTestCase1("../TextFile2.txt");
// MyDebugger.Test(process, "../TextFile2.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
#endif
}
}
static object process(TextReader input) {
// 1000000000000001
var n = long.Parse(input.ReadLine());
// 26進数
var sb = new StringBuilder();
while (n > 0) {
// Debug.WriteLine(n);
var x = (n % 26);
if (x == 0) {
x = 26;
var c = ('a' - 1) + x;
sb.Append((char)c);
n /= 26;
n -= 1;
} else {
var c = ('a' - 1) + x;
sb.Append((char)c);
n /= 26;
}
}
var sb2 = new StringBuilder(sb.Length);
for (int i = 0; i < sb.Length; i++) {
sb2.Append(sb[sb.Length - i - 1]);
}
return sb2;
}
static int[] ToIntArray(string strs, int n) {
var ret = new int[n];
if (n == 0)
return ret;
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 90], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 390
| 4
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static Dictionary<long, long> primeDic = new Dictionary<long, long>();
static void Solve() {
var n = Input.NextLong();
var list = new List<char>();
int idx = 0;
while (n > 0) {
long c = (n - 1) % 26;
list.Add((char)('a' + c));
n = n / 26;
}
list.Reverse();
var ans = new string(list.ToArray());
Console.WriteLine(ans);
}
#region よく使う便利関数
private static void TrialDivision(long m) {
for (long i = 2; i * i <= m; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
primeDic.Add(i, ex);
}
}
if (m >= 2) {
primeDic.Add(m, 1);
}
// note まぁ1は違うよね
}
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static Dictionary<long, long> primeDic = new Dictionary<long, long>();
static void Solve() {
var n = Input.NextLong();
var list = new List<char>();
int idx = 0;
while (n > 0) {
long c = (n - 1) % 26;
list.Add((char)('a' + c));
n = (n - 1) / 26;
}
list.Reverse();
var ans = new string(list.ToArray());
Console.WriteLine(ans);
}
#region よく使う便利関数
private static void TrialDivision(long m) {
for (long i = 2; i * i <= m; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
primeDic.Add(i, ex);
}
}
if (m >= 2) {
primeDic.Add(m, 1);
}
// note まぁ1は違うよね
}
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
| 8
| 2,585
| 4
|
using System;
class C {
public static void Main() {
int s = int.Parse(Console.ReadLine());
var C = new C();
string i = C.GetColumnName(s).ToLower();
Console.WriteLine(i);
}
public string GetColumnName(int index) {
string str = "";
do {
str = Convert.ToChar(index % 26 + 0x41) + str;
} while ((index = index / 26 - 1) != -1);
return str;
}
}
|
using System;
class C {
public static void Main() {
long s = long.Parse(Console.ReadLine()) - 1;
var C = new C();
string i = C.GetColumnName(s).ToLower();
Console.WriteLine(i);
}
public string GetColumnName(long index) {
string str = "";
do {
str = Convert.ToChar(index % 26 + 0x41) + str;
} while ((index = index / 26 - 1) != -1);
return str;
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199]]
| 8
| 110
| 8
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
// var line = ReadLine().Split(' ').Select(value =>
// int.Parse(value)).ToArray();
var n = long.Parse(ReadLine());
var name = new StringBuilder();
while (n > 1) {
var mod = n % 26L;
if (mod == 0) {
mod = 26;
}
name.Append((char)('a' - 1L + mod));
n /= 26L;
}
var answer = new StringBuilder();
foreach (var c in name.ToString().Reverse()) {
answer.Append(c);
}
WriteLine(answer);
}
}
}
|
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
// var line = ReadLine().Split(' ').Select(value =>
// int.Parse(value)).ToArray();
var n = long.Parse(ReadLine());
var name = new StringBuilder();
while (n > 0) {
var mod = n % 26L;
if (mod == 0) {
mod = 26;
}
name.Append((char)('a' - 1L + mod));
n--;
n /= 26L;
}
var answer = new StringBuilder();
foreach (var c in name.ToString().Reverse()) {
answer.Append(c);
}
WriteLine(answer);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68]]
| 8
| 159
| 5
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long b = 26;
List<long> L = new List<long>();
L.Add(0);
L.Add(b);
while (true) {
if (L[L.Count - 1] >= N)
break;
b *= 26;
L.Add(L[L.Count - 1] + b);
}
int Len = L.Count - 1;
long h = N - L[L.Count - 2] - 1;
// Console.WriteLine("Len:{0}, h:{1}",Len, h);
List<char> ans = new List<char>();
for (int i = 0; i < Len; i++) {
ans.Add((char)('a' + (h % 26)));
h /= 26;
}
ans.Reverse();
Console.WriteLine(new String(ans.ToArray()));
}
long N;
public Sol() { N = ri(); }
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long b = 26;
List<long> L = new List<long>();
L.Add(0);
L.Add(b);
while (true) {
if (L[L.Count - 1] >= N)
break;
b *= 26;
L.Add(L[L.Count - 1] + b);
}
int Len = L.Count - 1;
long h = N - L[L.Count - 2] - 1;
// Console.WriteLine("Len:{0}, h:{1}",Len, h);
List<char> ans = new List<char>();
for (int i = 0; i < Len; i++) {
ans.Add((char)('a' + (h % 26)));
h /= 26;
}
ans.Reverse();
Console.WriteLine(new String(ans.ToArray()));
}
long N;
public Sol() { N = rl(); }
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22]]
| 8
| 472
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionD {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数の入力
int n = int.Parse(Console.ReadLine());
// 整数配列の入力
var a =
Console.ReadLine().Split(' ').Select(j => long.Parse(j)).ToArray();
// 整数の入力
int q = int.Parse(Console.ReadLine());
var countArray = new long[100001];
for (int i = 0; i < a.Length; i++) {
countArray[a[i]]++;
}
long result = a.Max();
for (int i = 0; i < q; i++) {
var bc = Console.ReadLine().Split().Select(long.Parse).ToArray();
result += (bc[1] - bc[0]) * countArray[bc[0]];
countArray[bc[1]] += countArray[bc[0]];
countArray[bc[0]] = 0;
Console.WriteLine(result);
}
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionD {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数の入力
int n = int.Parse(Console.ReadLine());
// 整数配列の入力
var a =
Console.ReadLine().Split(' ').Select(j => long.Parse(j)).ToArray();
// 整数の入力
int q = int.Parse(Console.ReadLine());
var countArray = new long[100001];
for (int i = 0; i < a.Length; i++) {
countArray[a[i]]++;
}
long result = a.Sum();
for (int i = 0; i < q; i++) {
var bc = Console.ReadLine().Split().Select(long.Parse).ToArray();
result += (bc[1] - bc[0]) * countArray[bc[0]];
countArray[bc[1]] += countArray[bc[0]];
countArray[bc[0]] = 0;
Console.WriteLine(result);
}
Console.Out.Flush();
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 289
| 2
|
using System;
using System.Collections.Generic;
namespace abc171 {
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var aList = ReadNumList();
var aTable = new Dictionary<long, long>();
foreach (var a in aList) {
if (aTable.ContainsKey(a)) {
++aTable[a];
} else {
aTable.Add(a, 1);
}
}
var firstTotal = Total(aTable);
var currentTotal = firstTotal;
var q = int.Parse(Console.ReadLine());
var queryList = new List<KeyValuePair<long, long>>();
for (var i = 0; i < q; ++i) {
var bc = Console.ReadLine().Split(' ');
var kv =
new KeyValuePair<long, long>(long.Parse(bc[0]), long.Parse(bc[1]));
queryList.Add(kv);
}
for (var i = 0; i < q; ++i) {
var b = queryList[i].Key;
var c = queryList[i].Value;
var diff = 0L;
if (aTable.ContainsKey(b)) {
diff = (c - b) * aTable[b];
if (aTable.ContainsKey(c)) {
aTable[c] += aTable[b];
} else {
aTable[c] = aTable[b];
}
aTable.Remove(b);
currentTotal += diff;
Console.WriteLine(currentTotal);
}
}
}
static int[] ReadNumList() {
var line = Console.ReadLine().Split(' ');
var numList = new int[line.Length];
for (var i = 0; i < line.Length; ++i) {
numList[i] = int.Parse(line[i]);
}
return numList;
}
static long Total(Dictionary<long, long> aTable) {
var total = 0L;
foreach (var kv in aTable) {
total += kv.Key * kv.Value;
}
return total;
}
}
}
|
using System;
using System.Collections.Generic;
namespace abc171 {
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine());
var aList = ReadNumList();
var aTable = new Dictionary<long, long>();
foreach (var a in aList) {
if (aTable.ContainsKey(a)) {
++aTable[a];
} else {
aTable.Add(a, 1);
}
}
var firstTotal = Total(aTable);
var currentTotal = firstTotal;
var q = int.Parse(Console.ReadLine());
var queryList = new List<KeyValuePair<long, long>>();
for (var i = 0; i < q; ++i) {
var bc = Console.ReadLine().Split(' ');
var kv =
new KeyValuePair<long, long>(long.Parse(bc[0]), long.Parse(bc[1]));
queryList.Add(kv);
}
for (var i = 0; i < q; ++i) {
var b = queryList[i].Key;
var c = queryList[i].Value;
var diff = 0L;
if (aTable.ContainsKey(b)) {
diff = (c - b) * aTable[b];
if (aTable.ContainsKey(c)) {
aTable[c] += aTable[b];
} else {
aTable[c] = aTable[b];
}
aTable.Remove(b);
currentTotal += diff;
}
Console.WriteLine(currentTotal);
}
}
static int[] ReadNumList() {
var line = Console.ReadLine().Split(' ');
var numList = new int[line.Length];
for (var i = 0; i < line.Length; ++i) {
numList[i] = int.Parse(line[i]);
}
return numList;
}
static long Total(Dictionary<long, long> aTable) {
var total = 0L;
foreach (var kv in aTable) {
total += kv.Key * kv.Value;
}
return total;
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 441
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder.Question {
public class QuestionD {
public static void Main(string[] args) {
var n = ReadHelper.ReadValue<int>();
var ai = ReadHelper.ReadValues<int>();
var q = ReadHelper.ReadValue<int>();
var bc = new List<(int b, int c)>();
for (int i = 0; i < q; i++) {
var (b, c) = ReadHelper.ReadValue<int, int>();
bc.Add((b, c));
}
var dic = new Dictionary<int, int>();
foreach (var a in ai) {
if (!dic.ContainsKey(a)) {
dic.Add(a, 0);
}
dic[a]++;
}
var sum = dic.Select(kv => (long)(kv.Key * kv.Value)).Sum();
foreach (var item in bc) {
if (!dic.ContainsKey(item.b)) {
Console.WriteLine(sum);
}
if (!dic.ContainsKey(item.c)) {
dic.Add(item.c, 0);
}
var b = dic[item.b];
dic[item.c] += b;
var sabun = (item.c - item.b) * b;
sum += sabun;
dic.Remove(item.b);
Console.WriteLine(sum);
}
}
static class ReadHelper {
internal static T ReadValue<T>() {
return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
}
internal static (T1, T2) ReadValue<T1, T2>() {
var input = Console.ReadLine().Split(' ');
return ((T1)Convert.ChangeType(input[0], typeof(T1)),
(T2)Convert.ChangeType(input[1], typeof(T2)));
}
internal static (T1, T2, T3) ReadValue<T1, T2, T3>() {
var input = Console.ReadLine().Split(' ');
return ((T1)Convert.ChangeType(input[0], typeof(T1)),
(T2)Convert.ChangeType(input[1], typeof(T2)),
(T3)Convert.ChangeType(input[2], typeof(T3)));
}
internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var input = Console.ReadLine().Split(' ');
return ((T1)Convert.ChangeType(input[0], typeof(T1)),
(T2)Convert.ChangeType(input[1], typeof(T2)),
(T3)Convert.ChangeType(input[2], typeof(T3)),
(T4)Convert.ChangeType(input[3], typeof(T4)));
}
internal static T[] ReadValues<T>() {
var input = Console.ReadLine().Split(' ');
return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
}
}
static class MathAlgorithm {
internal static bool IsPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
var sqrt = Math.Sqrt(n);
for (int i = 3; i <= sqrt; i += 2)
if (n % i == 0)
return false;
return true;
}
internal static IEnumerable<long> EnumeratePrimes(long n) {
var i = 2L;
while (i * i <= n) {
if (n % i == 0) {
n /= i;
yield return i;
} else {
i += i == 2 ? 1 : 2;
}
}
if (n != 1)
yield return n;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder.Question {
public class QuestionD {
public static void Main(string[] args) {
var n = ReadHelper.ReadValue<int>();
var ai = ReadHelper.ReadValues<int>();
var q = ReadHelper.ReadValue<int>();
var bc = new List<(int b, int c)>();
for (int i = 0; i < q; i++) {
var (b, c) = ReadHelper.ReadValue<int, int>();
bc.Add((b, c));
}
var dic = new Dictionary<int, int>();
foreach (var a in ai) {
if (!dic.ContainsKey(a)) {
dic.Add(a, 0);
}
dic[a]++;
}
var sum = dic.Select(kv => (long)(kv.Key * kv.Value)).Sum();
foreach (var item in bc) {
if (!dic.ContainsKey(item.b)) {
Console.WriteLine(sum);
continue;
}
if (!dic.ContainsKey(item.c)) {
dic.Add(item.c, 0);
}
var b = dic[item.b];
dic[item.c] += b;
var sabun = (item.c - item.b) * b;
sum += sabun;
dic.Remove(item.b);
Console.WriteLine(sum);
}
}
static class ReadHelper {
internal static T ReadValue<T>() {
return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
}
internal static (T1, T2) ReadValue<T1, T2>() {
var input = Console.ReadLine().Split(' ');
return ((T1)Convert.ChangeType(input[0], typeof(T1)),
(T2)Convert.ChangeType(input[1], typeof(T2)));
}
internal static (T1, T2, T3) ReadValue<T1, T2, T3>() {
var input = Console.ReadLine().Split(' ');
return ((T1)Convert.ChangeType(input[0], typeof(T1)),
(T2)Convert.ChangeType(input[1], typeof(T2)),
(T3)Convert.ChangeType(input[2], typeof(T3)));
}
internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var input = Console.ReadLine().Split(' ');
return ((T1)Convert.ChangeType(input[0], typeof(T1)),
(T2)Convert.ChangeType(input[1], typeof(T2)),
(T3)Convert.ChangeType(input[2], typeof(T3)),
(T4)Convert.ChangeType(input[3], typeof(T4)));
}
internal static T[] ReadValues<T>() {
var input = Console.ReadLine().Split(' ');
return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
}
}
static class MathAlgorithm {
internal static bool IsPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
var sqrt = Math.Sqrt(n);
for (int i = 3; i <= sqrt; i += 2)
if (n % i == 0)
return false;
return true;
}
internal static IEnumerable<long> EnumeratePrimes(long n) {
var i = 2L;
while (i * i <= n) {
if (n % i == 0) {
n /= i;
yield return i;
} else {
i += i == 2 ? 1 : 2;
}
}
if (n != 1)
yield return n;
}
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35]]
| 8
| 842
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
static public string al = "abcdefghijklmnopqrstuvwxyz";
public static void Main() {
// •ûj
//
var n = rint();
var a = inta();
Array.Sort(a);
var checker = new bool[1000001];
var count = 0;
for (int i = 0; i < n; i++) {
if (checker[a[i]])
continue;
if (i < n - 1) {
if (a[i] < a[i + 1])
count++;
}
for (int j = 1; j * a[i] <= 1000000; j++) {
checker[j * a[i]] = true;
}
}
WriteLine(count);
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
if (n < r)
return 0;
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//Šeí“Çæ
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
static public string al = "abcdefghijklmnopqrstuvwxyz";
public static void Main() {
// •ûj
//
var n = rint();
var a = inta();
Array.Sort(a);
var checker = new bool[1000001];
var count = 0;
for (int i = 0; i < n; i++) {
if (checker[a[i]])
continue;
if (i < n - 1) {
if (a[i] < a[i + 1])
count++;
} else {
count++;
}
for (int j = 1; j * a[i] <= 1000000; j++) {
checker[j * a[i]] = true;
}
}
WriteLine(count);
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
if (n < r)
return 0;
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//Šeí“Çæ
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 1,233
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public long a;
public long b;
public long kosu;
public Pair(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Pair2 : IComparable {
public long a;
public long b;
public long kosu;
public long teki;
public Mlong jikkou = 1;
public Pair2(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair2 kore = (Pair2)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Dps : IComparable {
long[,] dp;
long i;
public Dps(long i, long n) {
this.i = i;
dp = new long[n, 100001];
}
public int CompareTo(object obj) {
Dps dps = (Dps)obj;
return i.CompareTo(dps.i);
}
}
class Program {
static List<int>[] togo;
static long[][,] dpps;
static bool[] visited;
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long n = scan.Long();
bool[] mas = new bool[100001];
long[] a = scan.Long(n);
long ans = n;
Array.Sort(a);
// Set<long> ma = new Set<long>();
for (long i = 0; i < n; i++) {
for (long j = 1; j * j <= a[i]; j++) {
if (i < n - 1 && a[i] == a[i + 1]) {
ans--;
break;
}
if (a[i] % j == 0 && mas[j]) {
ans--;
break;
}
if (a[i] % j == 0 && mas[a[i] / j]) {
ans--;
break;
}
}
mas[a[i]] = true;
}
Console.WriteLine(ans);
}
static void shuffle(Pair2[] ary) {
System.Random rng = new System.Random();
int n = ary.Length;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
var tmp = new Pair2(ary[k].a, ary[k].b);
ary[k] = new Pair2(ary[n].a, ary[n].b);
ary[n] = new Pair2(tmp.a, tmp.b);
}
}
static bool DFS(int now, int last) {
visited[now] = true;
for (int i = 0; i < togo[now].Count; i++) {
if (togo[now][i] == last) {
continue;
}
if (visited[togo[now][i]]) {
return false;
}
if (!DFS(togo[now][i], now)) {
return false;
}
}
return true;
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static void Soinsubunkai(long num) {
long m = num;
for (long i = 2; i * i < num; i++) {
long j = 0;
for (j = 0; j < num; j++) {
if (m % i == 0) {
m /= i;
}
}
// i^j | num,i^{j+1} not divide num
}
if (m != 1) {
//素因数が一つ残っている(k*k>numな素因数は高々一つ)
}
}
/* static List<CPair<long, long>> SoinsuBunkai(long num)
{
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++)
{
if (num % i != 0) { continue; }
yakusu.Add(i);
if (i * i != num) { yakusu2.Add(num / i); }
}
for (int i = 0; i < yakusu.Count; i++)
{
if (num % yakusu[i] != 0) { continue; }
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++)
{
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--)
{
if (num % yakusu2[i] != 0) { continue; }
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++)
{
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}*/
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public List<int> Topological_Sort(List<List<Edge>> G) {
var ret = new List<int>();
var Nodes = new Queue<int>();
int N = G.Count();
var Link = new int[N];
for (var i = 0; i < N; i++) {
Link[i] = 0;
}
for (var i = 0; i < N; i++) {
foreach (var nx in G[i]) {
Link[nx.to]++;
}
}
for (var i = 0; i < N; i++) {
if (Link[i] == 0) {
Nodes.Enqueue(i);
}
}
while (Nodes.Any()) {
var nd = Nodes.Dequeue();
ret.Add(nd);
foreach (var nx in G[nd]) {
Link[nx.to]--;
if (Link[nx.to] == 0) {
Nodes.Enqueue(nx.to);
}
}
}
return ret;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(long n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(long n, long m) {
char[,] kore = new char[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;
namespace Atcoder {
public class CPair<T, U> : IComparable
where T : IComparable<T> {
public readonly T Item1;
public readonly U Item2;
public int CompareTo(object obj) {
CPair<T, U> castedObj = (CPair<T, U>)obj;
return this.Item1.CompareTo(castedObj.Item1);
}
public CPair(T t, U u) {
Item1 = t;
Item2 = u;
}
}
class Pair : IComparable {
public long a;
public long b;
public long kosu;
public Pair(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Pair2 : IComparable {
public long a;
public long b;
public long kosu;
public long teki;
public Mlong jikkou = 1;
public Pair2(long A, long B) {
a = A;
b = B;
}
public int CompareTo(object obj) {
Pair2 kore = (Pair2)obj;
if (a != kore.a) {
return a.CompareTo(kore.a);
}
return b.CompareTo(kore.b);
}
/* public static bool operator <=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x <= p2.x; }
else { return p1.a <= p2.a; }
}
public static bool operator >=(Pair p1, Pair p2)
{
if (p1.x != p2.x) { return p1.x >= p2.x; }
else { return p1.a >= p2.a; }
}*/
}
class Dps : IComparable {
long[,] dp;
long i;
public Dps(long i, long n) {
this.i = i;
dp = new long[n, 100001];
}
public int CompareTo(object obj) {
Dps dps = (Dps)obj;
return i.CompareTo(dps.i);
}
}
class Program {
static List<int>[] togo;
static long[][,] dpps;
static bool[] visited;
static void Main(string[] args) {
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
long n = scan.Long();
bool[] mas = new bool[1000001];
long[] a = scan.Long(n);
long ans = n;
Array.Sort(a);
// Set<long> ma = new Set<long>();
for (long i = 0; i < n; i++) {
for (long j = 1; j * j <= a[i]; j++) {
if (i < n - 1 && a[i] == a[i + 1]) {
ans--;
break;
}
if (a[i] % j == 0 && mas[j]) {
ans--;
break;
}
if (a[i] % j == 0 && mas[a[i] / j]) {
ans--;
break;
}
}
mas[a[i]] = true;
}
Console.WriteLine(ans);
}
static void shuffle(Pair2[] ary) {
System.Random rng = new System.Random();
int n = ary.Length;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
var tmp = new Pair2(ary[k].a, ary[k].b);
ary[k] = new Pair2(ary[n].a, ary[n].b);
ary[n] = new Pair2(tmp.a, tmp.b);
}
}
static bool DFS(int now, int last) {
visited[now] = true;
for (int i = 0; i < togo[now].Count; i++) {
if (togo[now][i] == last) {
continue;
}
if (visited[togo[now][i]]) {
return false;
}
if (!DFS(togo[now][i], now)) {
return false;
}
}
return true;
}
static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int binary_search(int key, int[] moto) {
int ng = -1;
int ok = moto.Length;
while (Math.Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key, moto)) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
static int[] Togo;
static bool CheckBipartite(int now, int prev, List<int>[] g,
int c = 0) // 0,-1が想定
{
if (Togo == null)
Togo = Enumerable.Repeat(-1, g.Length).ToArray();
foreach (var next in g[now]) {
if (next == prev)
continue;
var nextc = Togo[next];
if (nextc >= 0 && nextc == c)
return false;
if (nextc >= 0)
continue;
Togo[next] = (c + 1) % 2;
var res = CheckBipartite(next, now, g, (c + 1) % 2);
if (res == false)
return false;
}
return true;
}
static bool isOK(int index, int key, int[] moto) { return moto[index] > key; }
public static int bitCount(int k) {
uint i = (uint)k;
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
i = (i + (i >> 4)) & 0x0f0f0f0f;
i = i + (i >> 8);
i = i + (i >> 16);
return (int)i & 0x3f;
}
static int check(long moto, long tai) {
if (tai % moto != 0) {
return 0;
}
while (tai > 1) {
if (tai % moto == 0) {
tai /= moto;
} else if (tai > moto) {
tai %= moto;
} else {
tai -= moto;
}
}
if (tai == 1) {
return 1;
} else {
return 0;
}
}
static bool NextPermutation(int[] array) {
var size = array.Length;
var ok = false;
// array[i]<array[i+1]を満たす最大のiを求める
int i = size - 2;
for (; 0 <= i; i--) {
if (array[i] < array[i + 1]) {
ok = true;
break;
}
}
//全ての要素が降順の場合、NextPermutationは存在しない
if (ok == false)
return false;
// array[i]<array[j]を満たす最大のjを求める
int j = size - 1;
for (;; j--) {
if (array[i] < array[j])
break;
}
// iとjの要素をswapする
var tmp = array[i];
array[i] = array[j];
array[j] = tmp;
// i以降の要素を反転させる
Array.Reverse(array, i + 1, size - (i + 1));
return true;
}
static List<int[]> GetAllPermutation(int N) {
var res = new List<int[]>();
var array = Enumerable.Range(0, N).ToArray();
do {
var copy = new int[N];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static List<int[]> GetAllPermutation(int[] array) {
var size = array.Length;
var res = new List<int[]>();
do {
var copy = new int[size];
array.CopyTo(copy, 0);
res.Add(copy);
} while (NextPermutation(array));
return res;
}
static long Syakutori(
int[] a,
long
k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
{
long sum = 0;
int right = 0;
long ans = 0;
for (int left = 0; left < a.Length; left++) {
while (right < a.Length && sum < k) {
sum += a[right];
right++;
}
if (k <= sum) {
ans += a.Length - right + 1;
}
if (left == right) {
right++;
} else {
sum -= a[left];
}
}
return ans;
}
static int[] zalgo(String s) {
int n = s.Length;
int[] ret = new int[n];
ret[0] = n;
int i = 1, j = 0;
while (i < n) {
while (i + j < n && s[j] == s[i + j])
++j;
ret[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < n && k + ret[k] < j) {
ret[i + k] = ret[k];
++k;
}
i += k;
j -= k;
}
return ret;
}
static int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
public static List<long> factorialMemo = new List<long>() { 1 };
static long Fact(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
static int[] yousogotoplus(int[] a, int[] b) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[i];
}
return c;
}
static int[] yousogotoplus(int[] a, int[,] b, int l) {
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++) {
c[i] = a[i] + b[l, i];
}
return c;
}
static int[] yousogotoplus(int[,] a, int l) {
int[] c = new int[a.GetLength(1)];
for (int i = 0; i < a.GetLength(1); i++) {
c[i] = a[l, i];
}
return c;
}
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[LowerBound(dp, a[i])] = a[i];
}
return LowerBound(dp, long.MaxValue - 1);
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static void Soinsubunkai(long num) {
long m = num;
for (long i = 2; i * i < num; i++) {
long j = 0;
for (j = 0; j < num; j++) {
if (m % i == 0) {
m /= i;
}
}
// i^j | num,i^{j+1} not divide num
}
if (m != 1) {
//素因数が一つ残っている(k*k>numな素因数は高々一つ)
}
}
/* static List<CPair<long, long>> SoinsuBunkai(long num)
{
List<CPair<long, long>> primes = new List<CPair<long, long>>();
List<long> yakusu = new List<long>();
List<long> yakusu2 = new List<long>();
for (int i = 2; i * i <= num; i++)
{
if (num % i != 0) { continue; }
yakusu.Add(i);
if (i * i != num) { yakusu2.Add(num / i); }
}
for (int i = 0; i < yakusu.Count; i++)
{
if (num % yakusu[i] != 0) { continue; }
int j = 0;
for (j = 0; num % yakusu[i] == 0; j++)
{
num /= yakusu[i];
}
primes.Add(new CPair<long, long>(yakusu[i], j));
}
for (int i = yakusu2.Count - 1; i > 0; i--)
{
if (num % yakusu2[i] != 0) { continue; }
int j = 0;
for (j = 0; num % yakusu2[i] == 0; j++)
{
num /= yakusu2[i];
}
primes.Add(new CPair<long, long>(yakusu2[i], j));
}
return primes;
}*/
static IEnumerable<int> Primes(int maxnum) {
// var sieve = new BitArray(maxnum + 1, true);
bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray();
int squareroot = (int)Math.Sqrt(maxnum);
for (int i = 2; i <= squareroot; i++) {
if (sieve[i] == false)
continue;
for (int n = i * 2; n <= maxnum; n += i)
sieve[n] = false;
}
for (int i = 2; i <= maxnum; i++)
if (sieve[i] == true)
yield return i;
}
/* static long[] SoinsuBunkai(long num)
{
if (num == 1)
return new long[] { 1 };
List<long> primes = new List<long>();
long n = DivideWith(num, 2, primes);
n = DivideWith(n, 3, primes);
n = DivideWith(n, 5, primes);
long i = 0;
while (n > 1)
{
int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 };
foreach (var p in ps)
{
// 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8...
は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break;
}
i += 30;
}
return primes.ToArray();
}*/
public static int h;
public static int w;
public static int BFS(int height, int width, char[,] map) {
int[] dx = new int[] { -1, 0, 0, 1 };
int[] dy = new int[] { 0, 1, -1, 0 };
bool[,] visited = new bool[h, w];
int[,] len = new int[h, w];
var queue = new Queue<Tuple<int, int>>();
queue.Enqueue(new Tuple<int, int>(height, width));
int max = 0;
visited[height, width] = true;
while (queue.Count > 0) {
var now = queue.Dequeue();
for (int i = 0; i < 4; i++) {
int ny = now.Item1 + dy[i];
int nx = now.Item2 + dx[i];
if (ny >= h || ny < 0 || nx >= w || nx < 0)
continue;
if (visited[ny, nx] || map[ny, nx] == '#')
continue;
visited[ny, nx] = true;
len[ny, nx] = len[now.Item1, now.Item2] + 1;
max = Math.Max(max, len[ny, nx]);
queue.Enqueue(new Tuple<int, int>(ny, nx));
}
}
return max;
}
static public List<int> Topological_Sort(List<List<Edge>> G) {
var ret = new List<int>();
var Nodes = new Queue<int>();
int N = G.Count();
var Link = new int[N];
for (var i = 0; i < N; i++) {
Link[i] = 0;
}
for (var i = 0; i < N; i++) {
foreach (var nx in G[i]) {
Link[nx.to]++;
}
}
for (var i = 0; i < N; i++) {
if (Link[i] == 0) {
Nodes.Enqueue(i);
}
}
while (Nodes.Any()) {
var nd = Nodes.Dequeue();
ret.Add(nd);
foreach (var nx in G[nd]) {
Link[nx.to]--;
if (Link[nx.to] == 0) {
Nodes.Enqueue(nx.to);
}
}
}
return ret;
}
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = Array.ConvertAll(array, x => initialvalue);
}
static int[] Manacher(string S) {
int i = 0, j = 0;
int[] R = new int[S.Length];
while (i < S.Length) {
while (i - j >= 0 && i + j < S.Length && S[i - j] == S[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && k + R[i - k] < j) {
R[i + k] = R[i - k];
++k;
}
i += k;
j -= k;
}
return R;
}
/* static Pair[] a;
static int SaikiZentansaku(List<int>now,int count,int last,int n,int m)
{
List<int> next = new List<int>();
for (int i = 0; i < now.Count; i++)
{
next.Add(now[i]);
}
next.Add(last);
var kore = next.ToArray();
int ans = 0;
if(count==n)
{
for (int i = 0; i < a.Length; i++)
{
int A = a[i].a;
int b = a[i].b;
int c = a[i].c;
int d = a[i].x;
if (kore[b] - kore[A] == c) { ans += d; }
}
return ans;
}
for (int i = last; i <= m; i++)
{
ans = Math.Max(ans, SaikiZentansaku(next, count + 1, i, n, m));
}
return ans;
}*/
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(long n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(long n, long m) {
char[,] kore = new char[n, m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
kore[i, j] = Char();
}
}
return kore;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public long[] Long(long n) {
long[] kore = new long[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public Mlong[] MLong(long n) {
Mlong[] kore = new Mlong[n];
for (int i = 0; i < n; i++) {
kore[i] = Long();
}
return kore;
}
public long[,] Long(long h, long w) {
long[,] kore = new long[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = Long();
}
}
return kore;
}
public int Integer() { return (int)Long(); }
public Mint[] MInteger(long n) {
Mint[] kore = new Mint[n];
for (int i = 0; i < n; i++) {
kore[i] = Integer();
}
return kore;
}
public int[] Integer(long n) {
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = (int)Long();
}
return kore;
}
public int[,] Integer(long h, long w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
kore[i, j] = (int)Long();
}
}
return kore;
}
public int[] StringToInt(int n) {
char[] s = Scan().ToCharArray();
int[] kore = new int[n];
for (int i = 0; i < n; i++) {
kore[i] = s[i] - '0';
}
return kore;
}
public int[,] StringToInt(int h, int w) {
int[,] kore = new int[h, w];
for (int i = 0; i < h; i++) {
char[] s = Scan().ToCharArray();
for (int j = 0; j < w; j++) {
kore[i, j] = s[j] - '0';
}
}
return kore;
}
public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
public class UnionFind {
public int[] data;
public UnionFind(int size) {
data = new int[size];
for (int i = 0; i < size; i++)
data[i] = -1;
}
public bool Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (data[y] < data[x]) {
var tmp = y;
y = x;
x = tmp;
}
data[x] += data[y];
data[y] = x;
}
return x != y;
}
public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); }
}
public class Mlong : IComparable {
private static long mod = 1000000007;
public long num;
public Mlong(long num) { this.num = num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mlong operator +(Mlong x, Mlong y) {
return new Mlong((x.num + y.num) % mod);
}
public static Mlong operator -(Mlong x, Mlong y) {
return new Mlong((x.num - y.num + mod) % mod);
}
public static Mlong operator *(Mlong x, Mlong y) {
return new Mlong((long)(((1L * x.num) * y.num) % mod));
}
public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); }
static long GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return x2 + mod;
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return x1 + mod;
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; }
public static implicit operator Mlong(long x) { return new Mlong(x); }
public static Mlong operator %(Mlong x, Mlong y) {
return new Mlong(x.num % y.num);
}
public static explicit operator long(Mlong x) { return x.num; }
public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; }
public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; }
public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; }
public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; }
public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; }
public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; }
public Mlong Pow(Mlong n) {
Mlong pow = this;
Mlong res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n = n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); }
public static List<Mlong> factorialMemo = new List<Mlong>() { 1 };
static Mlong Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mlong Comb(Mlong n, Mlong a) {
Mlong buf1 = 1;
Mlong buf2 = 1;
for (long i = 0; i < a.num; i++) {
buf1 *= n - i;
buf2 *= (i + 1);
}
return buf1.modjyo(buf2);
}
public static Mlong Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mlong x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mlong kore = (Mlong)obj;
return num.CompareTo(kore.num);
}
}
public class Mint : IComparable {
public static int mod = 1000000007;
public int num;
public Mint(int Num) { num = Num; }
public override int GetHashCode() { return num.GetHashCode(); }
public override bool Equals(object obj) { return num.Equals(obj); }
public static Mint operator +(Mint x, Mint y) {
return new Mint((x.num + y.num) % mod);
}
public static Mint operator -(Mint x, Mint y) {
return new Mint((x.num - y.num + mod) % mod);
}
public static Mint operator *(Mint x, Mint y) {
return new Mint((int)(((1L * x.num) * y.num) % mod));
}
public Mint hutujyo(Mint x) { return new Mint(num / x.num); }
static int GetInverse(long a) {
long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1;
while (true) {
if (p == 1)
return (int)(x2 + mod);
div = a / p;
x1 -= x2 * div;
y1 -= y2 * div;
a %= p;
if (a == 1)
return (int)(x1 + mod);
div = p / a;
x2 -= x1 * div;
y2 -= y1 * div;
p %= a;
}
}
public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; }
/* public Mint modjyo(Mint x)
{
return num * x.Pow(mod - 2);
}*/
public static implicit operator Mint(int x) { return new Mint(x); }
public static Mint[] Toarray(int[] x) {
Mint[] buf = new Mint[x.Length];
for (int i = 0; i < x.Length; i++) {
buf[i] = x[i];
}
return buf;
}
public static explicit operator int(Mint x) { return x.num; }
public static Mint operator %(Mint x, Mint y) {
return new Mint(x.num % y.num);
}
public static bool operator ==(Mint x, Mint y) { return x.num == y.num; }
public static bool operator !=(Mint x, Mint y) { return x.num != y.num; }
public static bool operator<(Mint x, Mint y) { return x.num < y.num; }
public static bool operator>(Mint x, Mint y) { return x.num > y.num; }
public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; }
public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; }
public Mint Pow(Mint n) {
Mint pow = this;
Mint res = 1;
while (n > 0) {
if (n % 2 == 1) {
res *= pow;
}
pow *= pow;
n.hutujyo(2);
}
/* if (n == 1) { return this % mod; }
if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
Mint buf = Pow(n.hutujyo(2));
return (buf * buf) % mod;*/
return res;
}
public static Mint Pow(Mint a, Mint n) { return a.Pow(n); }
public static List<Mint> factorialMemo = new List<Mint>() { 1 };
static Mint Factorial(int x) {
for (int i = factorialMemo.Count; i <= x; i++)
factorialMemo.Add(factorialMemo.Last() * i);
return factorialMemo[x];
}
public static Mint Comb(int n, int r) {
return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r));
}
public static void WriteLine(Mint x) { Console.WriteLine(x.num); }
public int CompareTo(object obj) {
Mint kore = (Mint)obj;
return num.CompareTo(kore.num);
}
}
public class PriorityQueue<T> : IEnumerable<T> {
private readonly List<T> _data = new List<T>();
private readonly IComparer<T> _comparer;
private readonly bool _isDescending;
public PriorityQueue(IComparer<T> comparer, bool isDescending = true) {
_comparer = comparer;
_isDescending = isDescending;
}
public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
: this(Comparer<T>.Create(comparison), isDescending) {}
public PriorityQueue(bool isDescending = true)
: this(Comparer<T>.Default, isDescending) {}
public void Enqueue(T item) {
_data.Add(item);
var childIndex = _data.Count - 1;
while (childIndex > 0) {
var parentIndex = (childIndex - 1) / 2;
if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
break;
Swap(childIndex, parentIndex);
childIndex = parentIndex;
}
}
public T Dequeue() {
var lastIndex = _data.Count - 1;
var firstItem = _data[0];
_data[0] = _data[lastIndex];
_data.RemoveAt(lastIndex--);
var parentIndex = 0;
while (true) {
var childIndex = parentIndex * 2 + 1;
if (childIndex > lastIndex)
break;
var rightChild = childIndex + 1;
if (rightChild <= lastIndex &&
Compare(_data[rightChild], _data[childIndex]) < 0)
childIndex = rightChild;
if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
break;
Swap(parentIndex, childIndex);
parentIndex = childIndex;
}
return firstItem;
}
public T Peek() { return _data[0]; }
private void Swap(int a, int b) {
var tmp = _data[a];
_data[a] = _data[b];
_data[b] = tmp;
}
private int Compare(T a, T b) {
return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
}
public int Count => _data.Count;
public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
public class Tree {
public Node[] Nodes;
public List<int[]> hen;
public class Node {
public int? parent = null;
public List<int[]> children = new List<int[]>();
public int parentcolor = -1;
}
public Tree(int kosu) {
Nodes = new Node[kosu];
for (int i = 0; i < Nodes.Length; i++) {
Nodes[i] = new Node();
}
hen = new List<int[]>();
}
public void Connect(int oya, int ko, int id) {
hen.Add(new int[] { oya, ko, 0 });
Nodes[oya].children.Add(new int[] { ko, id });
Nodes[ko].parent = oya;
}
}
/// <summary>
/// Self-Balancing Binary Search Tree
/// (using Randamized BST)
/// </summary>
public class SB_BinarySearchTree<T>
where T : IComparable {
public class Node {
public T Value;
public Node LChild;
public Node RChild;
public int Count; // size of the sub tree
public Node(T v) {
Value = v;
Count = 1;
}
}
static Random _rnd = new Random();
public static int Count(Node t) { return t == null ? 0 : t.Count; }
static Node Update(Node t) {
t.Count = Count(t.LChild) + Count(t.RChild) + 1;
return t;
}
public static Node Merge(Node l, Node r) {
if (l == null || r == null)
return l == null ? r : l;
if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) {
l.RChild = Merge(l.RChild, r);
return Update(l);
} else {
r.LChild = Merge(l, r.LChild);
return Update(r);
}
}
/// <summary>
/// split as [0, k), [k, n)
/// </summary>
public static Tuple<Node, Node> Split(Node t, int k) {
if (t == null)
return new Tuple<Node, Node>(null, null);
if (k <= Count(t.LChild)) {
var s = Split(t.LChild, k);
t.LChild = s.Item2;
return new Tuple<Node, Node>(s.Item1, Update(t));
} else {
var s = Split(t.RChild, k - Count(t.LChild) - 1);
t.RChild = s.Item1;
return new Tuple<Node, Node>(Update(t), s.Item2);
}
}
public static Node Remove(Node t, T v) {
if (Find(t, v) == null)
return t;
return RemoveAt(t, LowerBound(t, v));
}
public static Node RemoveAt(Node t, int k) {
var s = Split(t, k);
var s2 = Split(s.Item2, 1);
return Merge(s.Item1, s2.Item2);
}
public static bool Contains(Node t, T v) { return Find(t, v) != null; }
public static Node Find(Node t, T v) {
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0)
t = t.LChild;
else if (cmp < 0)
t = t.RChild;
else
break;
}
return t;
}
public static Node FindByIndex(Node t, int idx) {
if (t == null)
return null;
var currentIdx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
if (currentIdx == idx)
return t;
if (currentIdx > idx) {
t = t.LChild;
currentIdx -= (Count(t == null ? null : t.RChild) + 1);
} else {
t = t.RChild;
currentIdx += (Count(t == null ? null : t.LChild) + 1);
}
}
return null;
}
public static int UpperBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var ret = Int32.MaxValue;
var idx = Count(t) - Count(t.RChild) - 1;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp > 0) {
ret = Math.Min(ret, idx);
t = t.LChild;
idx -= (Count(t == null ? null : t.RChild) + 1);
} else if (cmp <= 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
}
}
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static int LowerBound(Node t, T v) {
var torg = t;
if (t == null)
return -1;
var idx = Count(t) - Count(t.RChild) - 1;
var ret = Int32.MaxValue;
while (t != null) {
var cmp = t.Value.CompareTo(v);
if (cmp >= 0) {
if (cmp == 0)
ret = Math.Min(ret, idx);
t = t.LChild;
if (t == null)
ret = Math.Min(ret, idx);
idx -= t == null ? 0 : (Count(t.RChild) + 1);
} else if (cmp < 0) {
t = t.RChild;
idx += (Count(t == null ? null : t.LChild) + 1);
if (t == null)
return idx;
}
}
// return ret;
return ret == Int32.MaxValue ? Count(torg) : ret;
}
public static Node Insert(Node t, T v) {
var ub = LowerBound(t, v);
return InsertByIdx(t, ub, v);
}
static Node InsertByIdx(Node t, int k, T v) {
var s = Split(t, k);
return Merge(Merge(s.Item1, new Node(v)), s.Item2);
}
public static IEnumerable<T> Enumerate(Node t) {
var ret = new List<T>();
Enumerate(t, ret);
return ret;
}
static void Enumerate(Node t, List<T> ret) {
if (t == null)
return;
Enumerate(t.LChild, ret);
ret.Add(t.Value);
Enumerate(t.RChild, ret);
}
}
/// <summary>
/// C-like set
/// </summary>
public class Set<T>
where T : IComparable {
protected SB_BinarySearchTree<T>.Node _root;
public T this[int idx] {
get { return ElementAt(idx); }
}
public int Count() { return SB_BinarySearchTree<T>.Count(_root); }
public virtual void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else {
if (SB_BinarySearchTree<T>.Find(_root, v) != null)
return;
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public void Clear() { _root = null; }
public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); }
public bool Contains(T v) {
return SB_BinarySearchTree<T>.Contains(_root, v);
}
public T ElementAt(int k) {
var node = SB_BinarySearchTree<T>.FindByIndex(_root, k);
if (node == null)
throw new IndexOutOfRangeException();
return node.Value;
}
public int Count(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v) -
SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int LowerBound(T v) {
return SB_BinarySearchTree<T>.LowerBound(_root, v);
}
public int UpperBound(T v) {
return SB_BinarySearchTree<T>.UpperBound(_root, v);
}
public Tuple<int, int> EqualRange(T v) {
if (!Contains(v))
return new Tuple<int, int>(-1, -1);
return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v),
SB_BinarySearchTree<T>.UpperBound(_root, v) - 1);
}
public List<T> ToList() {
return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root));
}
}
/// <summary>
/// C-like multiset
/// </summary>
public class MultiSet<T> : Set<T>
where T : IComparable {
public override void Insert(T v) {
if (_root == null)
_root = new SB_BinarySearchTree<T>.Node(v);
else
_root = SB_BinarySearchTree<T>.Insert(_root, v);
}
}
public class RollingHashSlow {
public const long B = (long)1e5 + 7;
public const long MOD = (long)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public long[] Power { get; set; }
public long[] Hash { get; set; }
public RollingHashSlow(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new long[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = (this.Power[i] * B) % MOD;
}
// ハッシュを前計算する
this.Hash = new long[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD;
}
}
// S[l, r) のハッシュ値を求める
public long Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD);
if (hash < 0)
hash += MOD;
return hash;
}
}
class RollingHashFast {
public const ulong B = (ulong)1e9 + 7;
public string S { get; set; }
public int N { get; set; }
public ulong[] Power { get; set; }
public ulong[] Hash { get; set; }
public RollingHashFast(string s) {
this.S = s;
this.N = s.Length;
// B^nを計算しておく
this.Power = new ulong[this.N + 1];
this.Power[0] = 1;
for (int i = 0; i < N; i++) {
this.Power[i + 1] = this.Power[i] * B;
}
// ハッシュを前計算する
this.Hash = new ulong[this.N + 1];
for (int i = 0; i < N; i++) {
this.Hash[i + 1] = this.Hash[i] * B + S[i];
}
}
// [l, r) のハッシュ値を求める
public ulong Get(int l, int r) {
var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]);
return hash;
}
}
class Segtree<T> {
int n;
T[] tree;
Func<T, T, T> f;
T exnum;
public Segtree(int m, Func<T, T, T> f, T ex) {
this.f = f;
this.exnum = ex;
n = 1;
while (n < m)
n <<= 1;
tree = new T[(n << 1) - 1];
for (int i = 0; i < tree.Length; i++)
tree[i] = ex;
}
public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) {
for (int i = 0; i < m; ++i)
tree[i + n - 1] = ini;
all_update();
}
public void assign_without_update(int j, T x) { tree[j + n - 1] = x; }
public void update(int j, T x) {
int i = j + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) >> 1;
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
}
public void all_update() {
for (int i = n - 2; i >= 0; i--)
tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
}
public T look(int i) { return tree[i + n - 1]; }
// [s, t)
public T run(int s, int t) { return query(s, t, 0, 0, n); }
T query(int s, int t, int k, int l, int r) {
if (r <= s || t <= l)
return exnum;
if (s <= l && r <= t)
return tree[k];
return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1),
query(s, t, (k + 1) << 1, (l + r) >> 1, r));
}
}
public class WarshallFloyd {
public int V { get; set; }
public long[,] DP { get; set; }
public long INF = long.MaxValue;
public bool[] Negative;
public WarshallFloyd(int v) {
this.V = v;
this.DP = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
this.DP[i, j] = INF;
}
this.DP[i, i] = 0;
}
}
public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; }
public long[,] CalcMinCost() {
this.Negative = new bool[V];
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]);
}
}
}
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (DP[i, k] == INF || DP[k, j] == INF)
continue;
if (DP[i, j] > DP[i, k] + DP[k, j]) {
this.Negative[i] = true;
this.Negative[j] = true;
this.Negative[k] = true;
}
}
}
}
return DP;
}
public long GetMinCost(int a, int b) { return DP[a, b]; }
public bool IsINF(int a, int b) { return DP[a, b] >= INF; }
public bool IsNegative(params int[] vs) {
if (vs.Length == 0)
vs = Enumerable.Range(0, V).ToArray();
foreach (var v in vs) {
if (Negative[v])
return true;
}
return false;
}
}
/// <summary>
/// Get min cost between two points
/// </summary>
public class Dijkstra {
private int maxIndex = -1;
private const int INF = Int32.MaxValue;
private int[,] _edgeArray;
/// <summary>
/// Dijkstra, get min cost between two points
/// should not contain negatie cost path
/// </summary>
/// <param name="size">max index of vertices</param>
public Dijkstra(int size) {
maxIndex = size + 1;
_edgeArray = new int[maxIndex, maxIndex];
for (int i = 0; i < _edgeArray.GetLength(0); i++) {
for (int j = 0; j < _edgeArray.GetLength(1); j++) {
_edgeArray[i, j] = INF;
if (i == j)
_edgeArray[i, j] = 0;
}
}
}
// Add a path(no direction) with its cost
public void AddPath(int s, int t, int cost) {
_edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost);
_edgeArray[t, s] = _edgeArray[s, t];
}
// Get the min cost between s and t
// return Int32.MaxValue if no path
public int GetMinCost(int s, int t) {
int[] cost = new int[maxIndex];
for (int i = 0; i < cost.Length; i++)
cost[i] = INF;
cost[s] = 0;
var priorityQueue = new PriorityQueue<CPair<int, int>>();
priorityQueue.Enqueue(new CPair<int, int>(0, s));
while (priorityQueue.Count() > 0) {
var costDestinationPair = priorityQueue.Dequeue();
if (cost[costDestinationPair.Item2] < costDestinationPair.Item1)
continue;
for (int i = 0; i < maxIndex; i++) {
int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF
? INF
: costDestinationPair.Item1 +
_edgeArray[costDestinationPair.Item2, i];
if (newCostToi < cost[i]) {
cost[i] = newCostToi;
priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i));
}
}
}
return cost[t];
}
}
class Deque<T> : IEnumerable<T> {
public T this[int i] {
get { return this.Buffer[(this.FirstIndex + i) % this.Capacity]; }
set {
if (i < 0)
throw new ArgumentOutOfRangeException();
this.Buffer[(this.FirstIndex + i) % this.Capacity] = value;
}
}
private T[] Buffer;
private int Capacity;
private int FirstIndex;
private int LastIndex {
get { return (this.FirstIndex + this.Length) % this.Capacity; }
}
public int Length;
public Deque(int capacity = 16) {
this.Capacity = capacity;
this.Buffer = new T[this.Capacity];
this.FirstIndex = 0;
}
public void PushBack(T data) {
if (this.Length == this.Capacity)
this.Resize();
this.Buffer[this.LastIndex] = data;
this.Length++;
}
public void PushFront(T data) {
if (this.Length == this.Capacity)
this.Resize();
var index = this.FirstIndex - 1;
if (index < 0)
index = this.Capacity - 1;
this.Buffer[index] = data;
this.Length++;
this.FirstIndex = index;
}
public T PopBack() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[this.Length - 1];
this.Length--;
return data;
}
public T PopFront() {
if (this.Length == 0)
throw new InvalidOperationException("データが空です。");
var data = this[0];
this.FirstIndex++;
this.FirstIndex %= this.Capacity;
this.Length--;
return data;
}
private void Resize() {
var newArray = new T[this.Capacity * 2];
for (int i = 0; i < this.Length; i++) {
newArray[i] = this[i];
}
this.FirstIndex = 0;
this.Capacity *= 2;
this.Buffer = newArray;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
IEnumerator IEnumerable.GetEnumerator() {
for (int i = 0; i < this.Length; i++) {
yield return this[i];
}
}
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
public class PotentializedUnionFind {
int _count;
int[] par, sizes, rank;
long[] weight;
public PotentializedUnionFind(int N) {
_count = N;
par = new int[N];
sizes = new int[N];
rank = new int[N];
weight = new long[N];
for (int i = 0; i < N; ++i) {
par[i] = i;
sizes[i] = 1;
rank[i] = 0;
}
}
int Root(int X) {
if (par[X] == X) {
return X;
} else {
int r = Root(par[X]);
weight[X] += weight[par[X]];
return (par[X] = r);
}
}
public bool Merge(int X, int Y, long W) {
W += GetWeight(X);
W -= GetWeight(Y);
X = Root(X);
Y = Root(Y);
if (X == Y)
return false;
--_count;
if (rank[X] < rank[Y]) {
par[X] = Y;
sizes[Y] += sizes[X];
weight[X] = -W;
} else {
par[Y] = X;
sizes[X] += sizes[Y];
if (rank[X] == rank[Y])
++rank[X];
weight[Y] = W;
}
return true;
}
public bool IsSame(int X, int Y) => Root(X) == Root(Y);
public int Count => _count;
public bool IsParent(int X) => X == Root(X);
public int GetParent(int X) => Root(X);
public int Size(int X) => sizes[Root(X)];
public long GetWeight(int X) {
Root(X);
return weight[X];
}
public long GetDiff(int X, int Y) => GetWeight(Y) - GetWeight(X);
}
public static class BellmanFord {
public class Vertex {
public long Distance { get; set; }
public Vertex() { Distance = long.MaxValue; }
}
public class Edge {
public int From { get; private set; }
public int To { get; private set; }
public long Weight { get; private set; }
public Edge(int from, int to, long weight) {
From = from;
To = to;
Weight = weight;
}
}
private static void GetReachable(int origin, ref HashSet<int> reached,
ref Dictionary<int, int[]> paths) {
if (reached.Contains(origin))
return;
reached.Add(origin);
if (paths.ContainsKey(origin) == false)
return;
foreach (var p in paths[origin])
GetReachable(p, ref reached, ref paths);
}
/// <summary>
/// null: 負の無限大
/// long.MaxValue: たどり着けない
/// その他: 距離
/// </summary>
public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges,
int source, int dest) {
var forwards =
rawEdges.GroupBy(x => x.From)
.ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray());
var reverses = rawEdges.GroupBy(x => x.To).ToDictionary(
x => x.Key, x => x.Select(xs => xs.From).ToArray());
var fromSource = new HashSet<int>();
var toDest = new HashSet<int>();
GetReachable(source, ref fromSource, ref forwards);
GetReachable(dest, ref toDest, ref reverses);
var edges = rawEdges.Where(e => fromSource.Contains(e.From))
.Where(e => fromSource.Contains(e.To))
.Where(e => toDest.Contains(e.From))
.Where(e => toDest.Contains(e.To))
.ToArray();
// initialize distances
var vertices = new List<Vertex>();
for (int i = 0; i < vertexCount; i++)
vertices.Add(new Vertex());
vertices[source].Distance = 0L;
// update distances
for (int i = 0; i < vertices.Count; i++) {
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance == long.MaxValue)
continue;
var newDistance = from.Distance + e.Weight;
if (to.Distance > newDistance) {
to.Distance = newDistance;
}
}
}
// check negative cycle
foreach (var e in edges) {
var from = vertices[e.From];
var to = vertices[e.To];
if (from.Distance + e.Weight < to.Distance)
return null;
}
return vertices[dest].Distance;
}
}
}
|
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
| 8
| 11,919
| 2
|
using System;
public class Hello {
public static void Main() {
var line = System.Console.ReadLine().Split(' ');
long A = long.Parse(line[0]);
long V = long.Parse(line[1]);
line = System.Console.ReadLine().Split(' ');
long B = long.Parse(line[0]);
long W = long.Parse(line[1]);
long T = long.Parse(System.Console.ReadLine());
long D = T * V - T * W;
long d = Math.Abs(A - B);
if (D > d) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
|
using System;
public class Hello {
public static void Main() {
var line = System.Console.ReadLine().Split(' ');
long A = long.Parse(line[0]);
long V = long.Parse(line[1]);
line = System.Console.ReadLine().Split(' ');
long B = long.Parse(line[0]);
long W = long.Parse(line[1]);
long T = long.Parse(System.Console.ReadLine());
long D = T * V - T * W;
long d = Math.Abs(A - B);
if (D >= d) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 171
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long a = sc.NextInt();
long v = sc.NextInt();
long b = sc.NextInt();
long w = sc.NextInt();
long t = sc.NextInt();
long dx = Math.Abs(a - b);
long dv = v - w;
bool ok = true;
if (dv <= 0) {
ok = false;
}
if (dv * t >= dx) {
ok = false;
}
string answer = ok ? "YES" : "NO";
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long a = sc.NextInt();
long v = sc.NextInt();
long b = sc.NextInt();
long w = sc.NextInt();
long t = sc.NextInt();
long dx = Math.Abs(a - b);
long dv = v - w;
bool ok = true;
if (dv <= 0) {
ok = false;
}
if (dv * t < dx) {
ok = false;
}
string answer = ok ? "YES" : "NO";
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 449
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace easy_Atcoder {
class Program {
static void Main(string[] args) {
long[] AV = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
long A = AV[0];
long V = AV[1];
long[] BW = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
long B = BW[0];
long W = BW[1];
long T = long.Parse(Console.ReadLine());
bool flag = false;
if (A > B) {
if (-1 * A + V * T >= -1 * B + W * T) {
flag = true;
}
} else {
if (A + V * T >= -B + W * T) {
flag = true;
}
}
Console.WriteLine(flag ? "YES" : "NO");
}
// 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) {
long[] AV = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
long A = AV[0];
long V = AV[1];
long[] BW = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
long B = BW[0];
long W = BW[1];
long T = long.Parse(Console.ReadLine());
bool flag = false;
if (A > B) {
if (-A + V * T >= -B + W * T) {
flag = true;
}
} else {
if (A + V * T >= B + W * T) {
flag = true;
}
}
Console.WriteLine(flag ? "YES" : "NO");
}
// 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);
// }
}
}
|
[["-", 15, 16, 31, 16, 31, 16, 31, 241, 0, 203], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["-", 15, 16, 12, 16, 31, 16, 31, 241, 0, 203], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 16, 12, 16, 31, 241, 0, 33]]
| 8
| 242
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var A = vals[0];
var V = vals[1];
vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var B = vals[0];
var W = vals[1];
var T = long.Parse(Console.ReadLine());
var d = Math.Abs(V - W);
if (d * T >= Math.Abs(A - B)) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public static void Main() {
var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var A = vals[0];
var V = vals[1];
vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
var B = vals[0];
var W = vals[1];
var T = long.Parse(Console.ReadLine());
var d = V - W;
if (d * T >= Math.Abs(A - B)) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
|
[["-", 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
| 177
| 5
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static Dictionary<long, long> primeDic = new Dictionary<long, long>();
static void Solve() {
var a = Input.NextLong();
var v = Input.NextLong();
var b = Input.NextLong();
var w = Input.NextLong();
var t = Input.NextLong();
if (w >= v) {
Console.WriteLine("NO");
return;
}
long dist = Math.Abs(b - a);
long vel = Math.Abs(v - w);
bool bo = (dist / vel <= t);
var ans = bo ? "YES" : "NO";
Console.WriteLine(ans);
}
#region よく使う便利関数
private static void TrialDivision(long m) {
for (long i = 2; i * i <= m; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
primeDic.Add(i, ex);
}
}
if (m >= 2) {
primeDic.Add(m, 1);
}
// note まぁ1は違うよね
}
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;
using System.IO;
using System.Net;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 1000001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static Dictionary<long, long> primeDic = new Dictionary<long, long>();
static void Solve() {
var a = Input.NextLong();
var v = Input.NextLong();
var b = Input.NextLong();
var w = Input.NextLong();
var t = Input.NextLong();
if (w >= v) {
Console.WriteLine("NO");
return;
}
long dist = Math.Abs(b - a);
long vel = Math.Abs(v - w);
bool bo = (dist <= t * vel);
var ans = bo ? "YES" : "NO";
Console.WriteLine(ans);
}
#region よく使う便利関数
private static void TrialDivision(long m) {
for (long i = 2; i * i <= m; i++) {
long ex = 0;
while (m % i == 0) {
ex++;
m /= i;
}
if (ex >= 1) {
primeDic.Add(i, ex);
}
}
if (m >= 2) {
primeDic.Add(m, 1);
}
// note まぁ1は違うよね
}
private static Dictionary<long, int> Factorize(long n) {
var dic = new Dictionary<long, int>();
for (long i = 2; i * i <= n; ++i) {
while (n % i == 0) {
if (!dic.ContainsKey(i)) {
dic.Add(i, 0);
}
dic[i]++;
n /= i;
}
}
if (n != 1) {
dic.Add(n, 1);
}
return dic;
}
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["-", 0, 212, 0, 23, 0, 16, 31, 16, 17, 85], ["-", 0, 212, 0, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 23, 0, 16, 12, 16, 17, 48], ["+", 0, 212, 0, 23, 0, 16, 12, 16, 12, 22]]
| 8
| 2,612
| 4
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ProblemB {
static bool SAIKI = false;
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var A = NN;
var V = NN;
var B = NN;
var W = NN;
var T = NN;
if (V <= W)
Console.WriteLine("NO");
else {
var dif = V - W;
var dist = Abs(A - B);
var jikan = dist / dif;
if (jikan <= T)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static LIB_FastIO fastio = new LIB_FastIODebug();
static public void Main(string[] args) {
if (args.Length == 0) {
fastio = new LIB_FastIO();
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
if (SAIKI) {
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
} else
Solve();
Console.Out.Flush();
}
static long NN => fastio.Long();
static double ND => fastio.Double();
static string NS => fastio.Scan();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IOrderedEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) =>
Enumerable.OrderBy(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x,
Func<T1, T2> selector) =>
Enumerable.OrderBy(x.OrderByRand(), selector);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) =>
Enumerable.OrderByDescending(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1>
OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) =>
Enumerable.OrderByDescending(x.OrderByRand(), selector);
static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) =>
x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<string>
OrderByDescending(this IEnumerable<string> x) =>
x.OrderByRand().OrderByDescending(e => e,
StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderByDescending(selector,
StringComparer.OrdinalIgnoreCase);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
}
}
namespace Library {
class LIB_FastIO {
public LIB_FastIO() { str = Console.OpenStandardInput(); }
readonly Stream str;
readonly byte[] buf = new byte[1024];
int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
virtual public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
virtual public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
virtual public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
class LIB_FastIODebug : LIB_FastIO {
Queue<string> param = new Queue<string>();
string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
public LIB_FastIODebug() {}
public override string Scan() => NextString();
public override long Long() => long.Parse(NextString());
public override double Double() => double.Parse(NextString());
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ProblemB {
static bool SAIKI = false;
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var A = NN;
var V = NN;
var B = NN;
var W = NN;
var T = NN;
if (V <= W)
Console.WriteLine("NO");
else {
var dif = V - W;
var dist = Abs(A - B);
var jikan = (dist - 1) / dif + 1;
if (jikan <= T)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static LIB_FastIO fastio = new LIB_FastIODebug();
static public void Main(string[] args) {
if (args.Length == 0) {
fastio = new LIB_FastIO();
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
if (SAIKI) {
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
} else
Solve();
Console.Out.Flush();
}
static long NN => fastio.Long();
static double ND => fastio.Double();
static string NS => fastio.Scan();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IOrderedEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) =>
Enumerable.OrderBy(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x,
Func<T1, T2> selector) =>
Enumerable.OrderBy(x.OrderByRand(), selector);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) =>
Enumerable.OrderByDescending(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1>
OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) =>
Enumerable.OrderByDescending(x.OrderByRand(), selector);
static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) =>
x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<string>
OrderByDescending(this IEnumerable<string> x) =>
x.OrderByRand().OrderByDescending(e => e,
StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderByDescending(selector,
StringComparer.OrdinalIgnoreCase);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
}
}
namespace Library {
class LIB_FastIO {
public LIB_FastIO() { str = Console.OpenStandardInput(); }
readonly Stream str;
readonly byte[] buf = new byte[1024];
int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
virtual public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
virtual public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
virtual public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
class LIB_FastIODebug : LIB_FastIO {
Queue<string> param = new Queue<string>();
string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
public LIB_FastIODebug() {}
public override string Scan() => NextString();
public override long Long() => long.Parse(NextString());
public override double Double() => double.Parse(NextString());
}
}
|
[["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 1,495
| 6
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
namespace tmnfipc2020 {
class Program {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (File.Exists("input.txt")) {
Console.SetIn(new StreamReader("input.txt"));
}
solve_tmnfipc2020B();
Console.Out.Flush();
}
public static void solve_tmnfipc2020B() {
int[] av = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int[] bw = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int t = Convert.ToInt32(Console.ReadLine());
// vx = wx + |a - b|
int d = Math.Abs(av[0] - bw[0]);
int x = av[1] - bw[1];
if (x <= 0) {
Console.WriteLine("NO");
} else {
if (d / x <= t) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
public static void solve_tmnfipc2020A() {
Console.WriteLine(Console.ReadLine().Substring(0, 3));
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
namespace tmnfipc2020 {
class Program {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
if (File.Exists("input.txt")) {
Console.SetIn(new StreamReader("input.txt"));
}
solve_tmnfipc2020B();
Console.Out.Flush();
}
public static void solve_tmnfipc2020B() {
int[] av = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int[] bw = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int t = Convert.ToInt32(Console.ReadLine());
// vx = wx + |a - b|
int d = Math.Abs(av[0] - bw[0]);
int x = av[1] - bw[1];
if (x <= 0) {
Console.WriteLine("NO");
} else {
if ((double)d / x <= t) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
public static void solve_tmnfipc2020A() {
Console.WriteLine(Console.ReadLine().Substring(0, 3));
}
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 0, 25]]
| 8
| 286
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6 {
class Program {
static void Main(string[] args) {
var seek = spr(RL()).Select(x => c2i(x));
var hide = spr(RL()).Select(x => c2i(x));
var left = c2i(RL());
var posseek = seek.First();
var moveseek = seek.Last();
var poshide = hide.First();
var movehide = hide.Last();
var ret = movehide < moveseek;
if (ret) {
ret = Math.Abs(poshide - posseek) <= (moveseek - movehide) * left;
}
Console.WriteLine(bool2ret(ret));
Console.ReadLine();
}
static string RL() { return Console.ReadLine().Trim(); }
static IEnumerable<string> spr(string s) { return s.Split(' '); }
static Int64 c2i(string c) { return Int64.Parse(c); }
// static double c2d(string c) { return double.Parse(c); }
static string bool2ret(bool b) { return b ? "Yes" : "No"; }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6 {
class Program {
static void Main(string[] args) {
var seek = spr(RL()).Select(x => c2i(x));
var hide = spr(RL()).Select(x => c2i(x));
var left = c2i(RL());
var posseek = seek.First();
var moveseek = seek.Last();
var poshide = hide.First();
var movehide = hide.Last();
var ret = movehide < moveseek;
if (ret) {
ret = Math.Abs(poshide - posseek) <= (moveseek - movehide) * left;
}
Console.WriteLine(bool2ret(ret));
Console.ReadLine();
}
static string RL() { return Console.ReadLine().Trim(); }
static IEnumerable<string> spr(string s) { return s.Split(' '); }
static Int64 c2i(string c) { return Int64.Parse(c); }
// static double c2d(string c) { return double.Parse(c); }
static string bool2ret(bool b) { return b ? "YES" : "NO"; }
}
}
|
[["-", 8, 196, 0, 37, 0, 41, 64, 5, 0, 222], ["+", 8, 196, 0, 37, 0, 41, 64, 5, 0, 222], ["-", 8, 196, 0, 37, 0, 41, 75, 5, 0, 222], ["+", 8, 196, 0, 37, 0, 41, 75, 5, 0, 222]]
| 8
| 258
| 4
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long a = long.Parse(input[0]);
long v = long.Parse(input[1]);
input = Console.ReadLine().Split(' ');
long b = long.Parse(input[0]);
long w = long.Parse(input[1]);
input = Console.ReadLine().Split(' ');
long t = long.Parse(input[0]);
bool success = false;
if (w >= v)
success = true;
else if (Math.Abs(a - b) > (v - w) * t)
success = true;
Console.WriteLine(success ? "No" : "Yes");
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long a = long.Parse(input[0]);
long v = long.Parse(input[1]);
input = Console.ReadLine().Split(' ');
long b = long.Parse(input[0]);
long w = long.Parse(input[1]);
input = Console.ReadLine().Split(' ');
long t = long.Parse(input[0]);
bool success = false;
if (w >= v)
success = true;
else if (Math.Abs(a - b) > (v - w) * t)
success = true;
Console.WriteLine(success ? "NO" : "YES");
}
}
|
[["-", 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
| 192
| 4
|
using System;
class Program {
static void Main(string[] args) {
string[] strInput = Console.ReadLine().Split(' ');
Int64 a = Int64.Parse(strInput[0]);
Int64 v = Int64.Parse(strInput[1]);
strInput = Console.ReadLine().Split(' ');
Int64 b = Int64.Parse(strInput[0]);
Int64 w = Int64.Parse(strInput[1]);
Int64 t = Int64.Parse(Console.ReadLine());
Int64 vel_diff = v - w;
Int64 distance = Math.Abs(a - b);
if (vel_diff <= 0) {
Console.WriteLine("NO");
return;
} else {
if (distance / vel_diff <= t) {
Console.WriteLine("YES");
return;
}
}
Console.WriteLine("NO");
return;
}
}
|
using System;
class Program {
static void Main(string[] args) {
string[] strInput = Console.ReadLine().Split(' ');
Int64 a = Int64.Parse(strInput[0]);
Int64 v = Int64.Parse(strInput[1]);
strInput = Console.ReadLine().Split(' ');
Int64 b = Int64.Parse(strInput[0]);
Int64 w = Int64.Parse(strInput[1]);
Int64 t = Int64.Parse(Console.ReadLine());
Int64 vel_diff = v - w;
Int64 distance = Math.Abs(a - b);
if (vel_diff <= 0) {
Console.WriteLine("NO");
return;
} else {
if (distance <= t * vel_diff) {
Console.WriteLine("YES");
return;
}
}
Console.WriteLine("NO");
return;
}
}
|
[["-", 75, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["-", 75, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 48], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 190
| 4
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace 東京海上日動2020B {
class Program {
static void Main(string[] args) {
var a = RLong;
var v = RLong;
var b = RLong;
var w = RLong;
var t = RLong;
bool ans;
if (a < b) {
ans = (v - w) * t > (b - a);
} else {
ans = (v - w) * t > (a - b);
}
if (ans)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}
}
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 東京海上日動2020B {
class Program {
static void Main(string[] args) {
var a = RLong;
var v = RLong;
var b = RLong;
var w = RLong;
var t = RLong;
bool ans;
if (a < b) {
ans = (v - w) * t >= (b - a);
} else {
ans = (v - w) * t >= (a - b);
}
if (ans)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}
}
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, 196, 0, 1, 0, 11, 12, 16, 17, 47], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 20], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 47], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 20]]
| 8
| 755
| 4
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
static void Main(string[] args) {
try {
SetOut(sw);
Solve.Answer();
Out.Flush();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var av = IO.RSLong;
var bw = IO.RSLong;
var t = IO.RLong;
if (av[0] <= bw[0]) {
if (av[0] + av[1] * t >= bw[0] + bw[1] * t) {
WriteLine("Yes");
} else
WriteLine("No");
return;
} else {
IO.WriteLineYes_or_No(av[0] - av[1] * t <= bw[0] - bw[1] * t);
}
}
}
public class IO {
#region Input
public static int RInt => int.Parse(ReadLine());
public static long RLong => long.Parse(ReadLine());
public static double RDouble => double.Parse(ReadLine());
public static string[] RSString => ReadLine().Split();
public static int[] RSInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToArray();
public static long[] RSLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToArray();
public static double[] RSDouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToArray();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES"
: "NO");
#endregion
}
public class Mod {
#region
private readonly static long M = 1000000007;
public static long Add(long a, long b) => (a * b) % M;
public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M
: (a - b) % M + M;
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
static void Main(string[] args) {
try {
SetOut(sw);
Solve.Answer();
Out.Flush();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var av = IO.RSLong;
var bw = IO.RSLong;
var t = IO.RLong;
if (av[0] <= bw[0]) {
if (av[0] + av[1] * t >= bw[0] + bw[1] * t) {
WriteLine("YES");
} else
WriteLine("NO");
return;
} else {
IO.WriteLineYES_or_NO(av[0] - av[1] * t <= bw[0] - bw[1] * t);
}
}
}
public class IO {
#region Input
public static int RInt => int.Parse(ReadLine());
public static long RLong => long.Parse(ReadLine());
public static double RDouble => double.Parse(ReadLine());
public static string[] RSString => ReadLine().Split();
public static int[] RSInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToArray();
public static long[] RSLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToArray();
public static double[] RSDouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToArray();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES"
: "NO");
#endregion
}
public class Mod {
#region
private readonly static long M = 1000000007;
public static long Add(long a, long b) => (a * b) % M;
public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M
: (a - b) % M + M;
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
| 8
| 576
| 6
|
using System;
using CompLib.Util;
public class Program {
public void Solve() {
var sc = new Scanner();
int a = sc.NextInt();
int v = sc.NextInt();
int b = sc.NextInt();
int w = sc.NextInt();
int t = sc.NextInt();
if (t > w) {
long dist = Math.Abs(a - b);
long diff = t - w;
// dist / diff <= t
// dist <= t * diff
Console.WriteLine(dist <= t * diff ? "YES" : "NO");
} else {
Console.WriteLine("NO");
}
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using CompLib.Util;
public class Program {
public void Solve() {
var sc = new Scanner();
int a = sc.NextInt();
int v = sc.NextInt();
int b = sc.NextInt();
int w = sc.NextInt();
int t = sc.NextInt();
if (v > w) {
long dist = Math.Abs(a - b);
long diff = v - w;
// dist / diff <= t
// dist <= t * diff
Console.WriteLine(dist <= t * diff ? "YES" : "NO");
} else {
Console.WriteLine("NO");
}
}
public static void Main(string[] args) => new Program().Solve();
}
namespace CompLib.Util {
using System;
using System.Linq;
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22]]
| 8
| 461
| 4
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public List<int> Update(IReadOnlyList<int> A) {
var B = Enumerable.Repeat(0, A.Count).ToList();
foreach (var i in Enumerable.Range(0, A.Count)) {
var l = Math.Max(0, i - A[i]);
B[l]++;
var r = Math.Min(A.Count - 1, i + A[i]);
if (r + 1 < A.Count) {
B[r + 1]--;
}
}
var sum = 0;
return Enumerable.Range(0, A.Count).Select(i => sum += B[i]).ToList();
}
public void Solve() {
var items =
Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToList();
var N = items[0];
var K = items[1];
var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToList();
foreach (var _ in Enumerable.Range(0, K)) {
A = this.Update(A);
if (A.All(elem => elem == N)) {
return;
}
};
Console.WriteLine(string.Join(" ", A));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace MyProject {
class Program {
static void Main(string[] args) {
#if Local
var sw = new Stopwatch();
sw.Start();
Console.SetIn(new StreamReader("input.in"));
#endif
var solver = new Solver();
solver.Solve();
#if Local
Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
}
}
class Solver {
public List<int> Update(IReadOnlyList<int> A) {
var B = Enumerable.Repeat(0, A.Count).ToList();
foreach (var i in Enumerable.Range(0, A.Count)) {
var l = Math.Max(0, i - A[i]);
B[l]++;
var r = Math.Min(A.Count - 1, i + A[i]);
if (r + 1 < A.Count) {
B[r + 1]--;
}
}
var sum = 0;
return Enumerable.Range(0, A.Count).Select(i => sum += B[i]).ToList();
}
public void Solve() {
var items =
Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToList();
var N = items[0];
var K = items[1];
var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToList();
foreach (var _ in Enumerable.Range(0, K)) {
A = this.Update(A);
if (A.All(elem => elem == N)) {
break;
}
};
Console.WriteLine(string.Join(" ", A));
}
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
| 8
| 401
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
int N, K;
sc.Make(out N, out K);
var A = sc.ArrInt;
for (int k = 0; k < K; k++) {
var na = new int[N];
for (int i = 0; i < N; i++) {
int lft = Max(0, i - A[i]);
na[lft]++;
var rgt = Min(N, i + A[i] + 1);
if (rgt != N)
na[rgt]--;
}
for (int i = 0; i < N - 1; i++) {
na[i + 1] += na[i];
}
A = na;
if (A.All(v => v == A[0]))
break;
}
Console.WriteLine(string.Join(" ", A));
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
}
#endregion
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Template;
using Pi = Pair<int, int>;
class Solver {
public void Solve(Scanner sc) {
int N, K;
sc.Make(out N, out K);
var A = sc.ArrInt;
for (int k = 0; k < K; k++) {
var na = new int[N];
for (int i = 0; i < N; i++) {
int lft = Max(0, i - A[i]);
na[lft]++;
var rgt = Min(N, i + A[i] + 1);
if (rgt != N)
na[rgt]--;
}
for (int i = 0; i < N - 1; i++) {
na[i + 1] += na[i];
}
A = na;
if (A.All(v => v == N))
break;
}
Console.WriteLine(string.Join(" ", A));
}
}
#region Template
public static class Template {
static void Main(string[] args) {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
new Solver().Solve(new Scanner());
Console.Out.Flush();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) > 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) < 0) {
a = b;
return true;
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(ref T a, ref T b) {
var t = b;
b = a;
a = t;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void swap<T>(this IList<T> A, int i, int j) {
var t = A[i];
A[i] = A[j];
A[j] = t;
}
public static T[] Create<T>(int n, Func<T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f();
return rt;
}
public static T[] Create<T>(int n, Func<int, T> f) {
var rt = new T[n];
for (var i = 0; i < rt.Length; ++i)
rt[i] = f(i);
return rt;
}
public static IEnumerable<T>
Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
for (var i = 0; i < Min(A.Length, B.Length); i++) {
int c = cmp(A[i], B[i]);
if (c > 0)
return 1;
else if (c < 0)
return -1;
}
if (A.Length == B.Length)
return 0;
if (A.Length > B.Length)
return 1;
else
return -1;
}
public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) {
cmp = cmp ?? Comparer<T>.Default.Compare;
T max = A[0];
int rt = 0;
for (int i = 1; i < A.Count; i++)
if (cmp(max, A[i]) < 0) {
max = A[i];
rt = i;
}
return rt;
}
public static T PopBack<T>(this List<T> A) {
var v = A[A.Count - 1];
A.RemoveAt(A.Count - 1);
return v;
}
public static void Fail<T>(T s) {
Console.WriteLine(s);
Console.Out.Close();
Environment.Exit(0);
}
}
public class Scanner {
public string Str => Console.ReadLine().Trim();
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
public int[] ArrInt1D(int n) => Create(n, () => Int);
public long[] ArrLong1D(int n) => Create(n, () => Long);
public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
private Queue<string> q = new Queue<string>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Next<T>() {
if (q.Count == 0)
foreach (var item in Str.Split(' '))
q.Enqueue(item);
return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
}
public void Make<T1>(out T1 v1) => v1 = Next<T1>();
public void Make<T1, T2>(out T1 v1, out T2 v2) {
v1 = Next<T1>();
v2 = Next<T2>();
}
public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) {
Make(out v1, out v2);
v3 = Next<T3>();
}
public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) {
Make(out v1, out v2, out v3);
v4 = Next<T4>();
}
public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5) {
Make(out v1, out v2, out v3, out v4);
v5 = Next<T5>();
}
public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6) {
Make(out v1, out v2, out v3, out v4, out v5);
v6 = Next<T6>();
}
public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3,
out T4 v4, out T5 v5, out T6 v6,
out T7 v7) {
Make(out v1, out v2, out v3, out v4, out v5, out v6);
v7 = Next<T7>();
}
// public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1,
// v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2,
// out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3,
// T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2,
// v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>> {
public T1 v1;
public T2 v2;
public Pair() {}
public Pair(T1 v1, T2 v2) {
this.v1 = v1;
this.v2 = v2;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2> p) {
var c = Comparer<T1>.Default.Compare(v1, p.v1);
if (c == 0)
c = Comparer<T2>.Default.Compare(v2, p.v2);
return c;
}
public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
public void Deconstruct(out T1 a, out T2 b) {
a = v1;
b = v2;
}
}
public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> {
public T3 v3;
public Pair() : base() {}
public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int CompareTo(Pair<T1, T2, T3> p) {
var c = base.CompareTo(p);
if (c == 0)
c = Comparer<T3>.Default.Compare(v3, p.v3);
return c;
}
public override string ToString() => $"{base.ToString()} {v3.ToString()}";
public void Deconstruct(out T1 a, out T2 b, out T3 c) {
Deconstruct(out a, out b);
c = v3;
}
}
#endregion
|
[["-", 0, 28, 0, 218, 8, 16, 12, 204, 205, 22], ["-", 0, 218, 8, 16, 12, 204, 206, 207, 0, 70], ["-", 8, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 218, 8, 16, 12, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22]]
| 8
| 2,022
| 5
|
using System;
namespace TEST {
class Program {
static void Main(string[] args) {
string[] c = Console.ReadLine().Split();
int a = int.Parse(c[0]);
int b = int.Parse(c[0]);
Console.WriteLine(a * b);
}
}
}
|
using System;
namespace TEST {
class Program {
static void Main(string[] args) {
string[] c = Console.ReadLine().Split();
int a = int.Parse(c[0]);
int b = int.Parse(c[1]);
Console.WriteLine(a * b);
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 72
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _169B {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine() ?? string.Empty);
var A =
Console.ReadLine()?.Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
var AList = new List<long>();
AList.AddRange(A);
long mul = 1;
if (AList.Contains(0)) {
Console.WriteLine(0);
return;
}
foreach (var ai in A) {
try {
mul = mul * ai;
if (mul > 1000000000000000000) {
Console.WriteLine(-1);
return;
}
} catch (OverflowException) {
Console.WriteLine(-1);
return;
}
}
Console.WriteLine(mul);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _169B {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine() ?? string.Empty);
var A =
Console.ReadLine()?.Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
var AList = new List<long>();
AList.AddRange(A);
long mul = 1;
if (AList.Contains(0)) {
Console.WriteLine(0);
return;
}
foreach (var ai in A) {
try {
mul = checked(mul * ai);
if (mul > 1000000000000000000) {
Console.WriteLine(-1);
return;
}
} catch (OverflowException) {
Console.WriteLine(-1);
return;
}
}
Console.WriteLine(mul);
}
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 12, 328, 0, 292], ["+", 8, 196, 0, 1, 0, 11, 12, 328, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 328, 0, 25]]
| 8
| 199
| 3
|
using System;
using System.Linq;
class program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] a = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long ans = 1;
Array.Sort(a);
if (a[0] == 0) {
Console.Write(0);
return;
}
for (int i = 0; i < n; i++) {
if (ans * a[i] > 1000000000000000000) {
Console.Write(-1);
return;
}
ans *= a[i];
}
Console.Write(ans);
}
}
|
using System;
using System.Linq;
class program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] a = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long ans = 1;
Array.Sort(a);
if (a[0] == 0) {
Console.Write(0);
return;
}
for (int i = 0; i < n; i++) {
if (ans > 1000000000000000000 / a[i]) {
Console.Write(-1);
return;
}
ans *= a[i];
}
Console.Write(ans);
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 145
| 6
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC {
class ProgramB {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var list =
Console.ReadLine().Split(" ").Select(x => long.Parse(x)).ToList();
if (list.Contains(0)) {
Console.WriteLine(0);
return;
}
var result = 1L;
for (var i = 0; i < n; i++) {
var r = 1e18 / result / list[i];
if (r < 0) {
result = -1;
break;
}
result *= list[i];
}
if (result > (long)1e18)
Console.WriteLine(-1);
else
Console.WriteLine(result);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC {
class ProgramB {
static void Main(string[] args) {
var n = long.Parse(Console.ReadLine());
var list =
Console.ReadLine().Split(" ").Select(x => long.Parse(x)).ToList();
if (list.Contains(0)) {
Console.WriteLine(0);
return;
}
var result = 1L;
for (var i = 0; i < n; i++) {
var r = 1e18 / list[i];
if (r < result) {
result = -1;
break;
}
result *= list[i];
}
if (result > (long)1e18)
Console.WriteLine(-1);
else
Console.WriteLine(result);
}
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 180
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Multiplication_B {
class Class2 {
static void Main() {
int n = int.Parse(Console.ReadLine());
if (n == 0) {
Console.WriteLine(0);
return;
}
string[] strArray = Console.ReadLine().Split(" ");
Array.Resize(ref strArray, n);
ulong[] longArray = strArray.Select(ulong.Parse).ToArray();
if (strArray.Contains("0")) {
Console.WriteLine(0);
}
ulong value = 1;
ulong max = (ulong)Math.Pow(10, 18);
if (n == 1) {
Console.WriteLine(value);
}
try {
checked {
foreach (ulong arrayMirror in longArray) {
value *= arrayMirror;
}
}
} catch (OverflowException ex) {
Console.WriteLine(-1);
return;
}
if (value > max) {
Console.WriteLine(-1);
} else {
Console.WriteLine(value);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Multiplication_B {
class Class2 {
static void Main() {
int n = int.Parse(Console.ReadLine());
if (n == 0) {
Console.WriteLine(0);
return;
}
string[] strArray = Console.ReadLine().Split(" ");
Array.Resize(ref strArray, n);
ulong[] longArray = strArray.Select(ulong.Parse).ToArray();
if (strArray.Contains("0")) {
Console.WriteLine(0);
return;
}
ulong value = 1;
ulong max = (ulong)Math.Pow(10, 18);
if (n == 1) {
Console.WriteLine(value);
}
try {
checked {
foreach (ulong arrayMirror in longArray) {
value *= arrayMirror;
}
}
} catch (OverflowException ex) {
Console.WriteLine(-1);
return;
}
if (value > max) {
Console.WriteLine(-1);
} else {
Console.WriteLine(value);
}
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 236
| 2
|
using System;
using System.IO;
using System.Collections.Generic;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var num = int.Parse(Console.ReadLine()); // 1行目:個数
string[] arr = Console.ReadLine().Split(' '); // 2行目:数値(文字列)の羅列
ulong sum = 1; //羅列を全てかけた値
//文字列変換して入れる
for (int i = 0; i < num; i++) {
if (ulong.Parse(arr[i]) == 0) {
Console.WriteLine(0);
return;
}
}
for (int i = 0; i < num; i++) {
try {
checked { sum *= ulong.Parse(arr[i]); }
} catch (OverflowException) {
Console.WriteLine(-1);
return;
}
}
if (sum > Math.Pow(10, 18)) {
Console.WriteLine(-1);
return;
} else {
Console.WriteLine(sum);
}
}
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var num = int.Parse(Console.ReadLine()); // 1行目:個数
string[] arr = Console.ReadLine().Split(' '); // 2行目:数値(文字列)の羅列
ulong sum = 1; //羅列を全てかけた値
//文字列変換して入れる
for (int i = 0; i < num; i++) {
if (ulong.Parse(arr[i]) == 0) {
Console.WriteLine(0);
return;
}
}
for (int i = 0; i < num; i++) {
try {
checked { sum *= ulong.Parse(arr[i]); }
} catch (OverflowException) {
Console.WriteLine(-1);
return;
}
}
if (sum > (ulong)Math.Pow(10, 18)) {
Console.WriteLine(-1);
return;
} else {
Console.WriteLine(sum);
}
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 25]]
| 8
| 201
| 3
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
ulong[] dArray =
Console.ReadLine().Split(' ').Select(i => ulong.Parse(i)).ToArray();
ulong total = 1;
ulong max = Convert.ToUInt64(Math.Pow(10d, 18d));
Array.Sort(dArray);
for (int d = 0; d < N; d++) {
try {
checked { total *= dArray[d]; }
if (total > max || total < 0) {
Console.WriteLine("-1");
}
} catch {
Console.WriteLine("-1");
return;
}
}
Console.WriteLine(total);
}
}
}
//文字列の入力
// 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();
// Console.WriteLine();
// Console.ReadKey();
//文字列の入力
// 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();
// Console.WriteLine();
// Console.ReadKey();
|
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
ulong[] dArray =
Console.ReadLine().Split(' ').Select(i => ulong.Parse(i)).ToArray();
ulong total = 1;
ulong max = Convert.ToUInt64(Math.Pow(10d, 18d));
Array.Sort(dArray);
for (int d = 0; d < N; d++) {
try {
checked { total *= dArray[d]; }
if (total > max || total < 0) {
Console.WriteLine("-1");
return;
}
} catch {
Console.WriteLine("-1");
return;
}
}
Console.WriteLine(total);
}
}
}
//文字列の入力
// 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();
// Console.WriteLine();
// Console.ReadKey();
//文字列の入力
// 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();
// Console.WriteLine();
// Console.ReadKey();
|
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 232
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_20190707_1 {
class Program {
static void Main(string[] args) {
try {
long N = long.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long[] l = new long[N];
for (long i = 0; i < N; i++) {
l[i] = long.Parse(s[i]);
}
long answer = 1;
Array.Sort(l);
for (int i = 0; i < N; i++) {
answer *= l[i];
if (answer > 1000000000000000000) {
Console.WriteLine("-1");
return;
}
}
Console.WriteLine(answer);
} catch (Exception e) {
Console.WriteLine("-1");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder_20190707_1 {
class Program {
static void Main(string[] args) {
try {
long N = long.Parse(Console.ReadLine());
string[] s = Console.ReadLine().Split(' ');
long[] l = new long[N];
for (long i = 0; i < N; i++) {
l[i] = long.Parse(s[i]);
}
long answer = 1;
Array.Sort(l);
for (int i = 0; i < N; i++) {
checked { answer *= l[i]; }
if (answer > 1000000000000000000) {
Console.WriteLine("-1");
return;
}
}
Console.WriteLine(answer);
} catch (Exception e) {
Console.WriteLine("-1");
}
}
}
}
|
[["+", 8, 196, 0, 7, 8, 196, 0, 287, 0, 292], ["+", 0, 7, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 287, 0, 196, 0, 46]]
| 8
| 200
| 3
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using Console = System.Console;
namespace Atcoder {
class Program {
private const long COMDIV = 1000000007;
static void Main(string[] args) {
long limit = 1000000000000000000;
var N = int.Parse(Console.ReadLine());
var As =
Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
long ret = 1;
if (As[0] == 0) {
Console.WriteLine(0);
return;
}
try {
for (int i = 0; i < N; i++) {
ret *= As[i];
}
if (ret > limit)
throw new Exception();
Console.WriteLine(ret);
} catch {
Console.WriteLine(-1);
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using Console = System.Console;
namespace Atcoder {
class Program {
private const long COMDIV = 1000000007;
static void Main(string[] args) {
long limit = 1000000000000000000;
var N = int.Parse(Console.ReadLine());
var As =
Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
long ret = 1;
if (As[0] == 0) {
Console.WriteLine(0);
return;
}
try {
checked {
for (int i = 0; i < N; i++) {
ret *= As[i];
}
if (ret > limit)
throw new Exception();
Console.WriteLine(ret);
}
} catch {
Console.WriteLine(-1);
}
}
}
}
|
[["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46]]
| 8
| 208
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
internal class QuestionB {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数の入力
long n = long.Parse(Console.ReadLine());
// 整数配列の入力
var inputLongArray =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
if (inputLongArray.Where(v => v == 0).Count() > 0) {
Console.WriteLine("0");
Console.Out.Flush();
return;
}
try {
var resultLong = inputLongArray.Aggregate((a, b) => a * b);
if ((resultLong - 1).ToString().Length >= 19) {
printMinusOne();
return;
}
string result = resultLong.ToString();
Console.WriteLine(result);
Console.Out.Flush();
} catch {
printMinusOne();
return;
}
}
private static void printMinusOne() {
string result = "-1";
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
internal class QuestionB {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
// 整数の入力
long n = long.Parse(Console.ReadLine());
// 整数配列の入力
var inputLongArray =
Console.ReadLine().Split(' ').Select(i => Decimal.Parse(i)).ToArray();
if (inputLongArray.Where(v => v == 0).Count() > 0) {
Console.WriteLine("0");
Console.Out.Flush();
return;
}
try {
var resultLong = inputLongArray.Aggregate((a, b) => a * b);
if ((resultLong - 1).ToString().Length >= 19) {
printMinusOne();
return;
}
string result = resultLong.ToString();
Console.WriteLine(result);
Console.Out.Flush();
} catch {
printMinusOne();
return;
}
}
private static void printMinusOne() {
string result = "-1";
Console.WriteLine(result);
Console.Out.Flush();
}
}
}
|
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 22]]
| 8
| 275
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionB {
public static void Main(string[] args) {
try {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
long n = long.Parse(Console.ReadLine());
var arr =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
if (arr.Contains(0)) {
Console.WriteLine(0);
} else {
long r = 1;
foreach (var i in arr) {
r = r * i;
if (r > 1000000000000000000) {
r = -1;
break;
}
}
Console.WriteLine(r.ToString());
}
Console.Out.Flush();
} catch (Exception e) {
Console.WriteLine(-1);
Console.Out.Flush();
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder.Abc {
class QuestionB {
public static void Main(string[] args) {
try {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
long n = long.Parse(Console.ReadLine());
var arr =
Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
if (arr.Contains(0)) {
Console.WriteLine(0);
} else {
checked {
long r = 1;
foreach (var i in arr) {
r = r * i;
if (r > 1000000000000000000) {
r = -1;
break;
}
}
Console.WriteLine(r.ToString());
}
}
Console.Out.Flush();
} catch (Exception e) {
Console.WriteLine(-1);
Console.Out.Flush();
}
}
}
}
|
[["+", 8, 196, 0, 57, 75, 196, 0, 287, 0, 292], ["+", 0, 57, 75, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 287, 0, 196, 0, 46]]
| 8
| 225
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ABC_169 {
class B {
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();
long[] array = ReadLongs();
long max = 1000000000000000000;
for (int i = 0; i < n; i++) {
if (array[i] == 0) {
WriteLine(-1);
return;
}
}
long val = 1;
for (int i = 0; i < n; i++) {
if (val > max / array[i]) {
WriteLine(-1);
return;
}
val *= array[i];
}
WriteLine(val);
}
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 decimal[] ReadDecimals() {
return Array.ConvertAll(Read().Split(), decimal.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.ABC_169 {
class B {
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();
long[] array = ReadLongs();
long max = 1000000000000000000;
for (int i = 0; i < n; i++) {
if (array[i] == 0) {
WriteLine(0);
return;
}
}
long val = 1;
for (int i = 0; i < n; i++) {
if (val > max / array[i]) {
WriteLine(-1);
return;
}
val *= array[i];
}
WriteLine(val);
}
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 decimal[] ReadDecimals() {
return Array.ConvertAll(Read().Split(), decimal.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 420
| 3
|
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();
long[] a = sc.LongArray();
if (a.Contains(0)) {
Console.WriteLine(0);
return;
}
long answer = 1;
for (int i = 0; i < n; i++) {
try {
checked {
answer *= a[i];
if (answer > 1e18) {
Console.Write(-1);
return;
}
}
} catch (OverflowException) {
Console.Write(-1);
return;
}
}
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();
long[] a = sc.LongArray();
if (a.Contains(0)) {
Console.WriteLine(0);
return;
}
long answer = 1;
for (int i = 0; i < n; i++) {
try {
checked {
answer *= a[i];
if (answer > (long)1e18) {
Console.Write(-1);
return;
}
}
} catch (OverflowException) {
Console.Write(-1);
return;
}
}
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, 196, 0, 57, 15, 16, 12, 74, 0, 24], ["+", 0, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["+", 0, 196, 0, 57, 15, 16, 12, 74, 0, 25]]
| 8
| 449
| 3
|
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();
long[] a = sc.LongArray();
if (a.Contains(0)) {
Console.WriteLine(0);
return;
}
ulong answer = 1;
for (int i = 0; i < n; i++) {
int digit1 = answer.ToString().Length;
int digit2 = a[i].ToString().Length;
if (digit1 + digit2 >= 21) {
Console.Write(-1);
return;
}
answer *= (ulong)a[i];
if (answer < 0 || answer > 1000000000000000000) {
Console.Write(-1);
return;
}
}
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();
long[] a = sc.LongArray();
if (a.Contains(0)) {
Console.WriteLine(0);
return;
}
decimal answer = 1;
for (int i = 0; i < n; i++) {
int digit1 = answer.ToString().Length;
int digit2 = a[i].ToString().Length;
if (digit1 + digit2 >= 21) {
Console.Write(-1);
return;
}
answer *= (decimal)a[i];
if (answer < 0 || answer > 1000000000000000000) {
Console.Write(-1);
return;
}
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199]]
| 8
| 479
| 4
|
using System;
using System.Linq;
public static class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var nums = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long result = 1;
if (nums.Contains(0)) {
Console.WriteLine("0");
return;
}
foreach (var num in nums) {
try {
result *= num;
if (result > 1000000000000000000) {
Console.WriteLine("-1");
return;
}
} catch (OverflowException e) {
Console.WriteLine("-1");
return;
}
}
Console.WriteLine(result);
}
}
|
using System;
using System.Linq;
public static class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var nums = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long result = 1;
if (nums.Contains(0)) {
Console.WriteLine("0");
return;
}
foreach (var num in nums) {
try {
checked {
result *= num;
if (result > 1000000000000000000) {
Console.WriteLine("-1");
return;
}
}
} catch (OverflowException e) {
Console.WriteLine("-1");
return;
}
}
Console.WriteLine(result);
}
}
|
[["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 287, 0, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 153
| 3
|
using System;
using System.Linq;
public class Test {
public static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(y => long.Parse(y)).ToArray();
int counter = 0;
long ans = 1;
long atcoder = 1000000000000000000;
for (int i = 0; i != n; i++) {
if (a[i] == 0) {
counter++;
break;
}
}
if (counter != 0) {
Console.WriteLine("0");
} else {
for (int j = 0; j != n; j++) {
if (ans * a[j] > atcoder) {
ans = -1;
break;
}
ans *= a[j];
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
public class Test {
public static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(y => long.Parse(y)).ToArray();
int counter = 0;
long ans = 1;
long atcoder = 1000000000000000000;
for (int i = 0; i != n; i++) {
if (a[i] == 0) {
counter++;
break;
}
}
if (counter != 0) {
Console.WriteLine("0");
} else {
for (int j = 0; j != n; j++) {
if (ans > atcoder / a[j]) {
ans = -1;
break;
}
ans *= a[j];
}
Console.WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
| 8
| 181
| 6
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.