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.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var s = Console.ReadLine();
var t = Console.ReadLine();
var answer = "UNRESTORABLE";
if (s.Length < t.Length) {
Console.WriteLine(answer);
return;
}
for (var i = s.Length - 1; i > t.Length - 1; i--) {
var tmp = s.ToCharArray();
var ok = true;
if (s[i] == t[t.Length - 1] || s[i] == '?') {
for (var j = 0; j < t.Length; j++) {
if (s[i - j] != t[t.Length - 1 - j] && s[i - j] != '?') {
ok = false;
break;
}
}
} else {
ok = false;
}
if (ok) {
for (var j = 0; j < t.Length; j++) {
tmp[i - j] = t[t.Length - 1 - j];
}
answer = new string(tmp);
answer = answer.Replace("?", "a");
break;
}
}
Console.WriteLine(answer);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var s = Console.ReadLine();
var t = Console.ReadLine();
var answer = "UNRESTORABLE";
if (s.Length < t.Length) {
Console.WriteLine(answer);
return;
}
for (var i = s.Length - 1; i >= t.Length - 1; i--) {
var tmp = s.ToCharArray();
var ok = true;
if (s[i] == t[t.Length - 1] || s[i] == '?') {
for (var j = 0; j < t.Length; j++) {
if (s[i - j] != t[t.Length - 1 - j] && s[i - j] != '?') {
ok = false;
break;
}
}
} else {
ok = false;
}
if (ok) {
for (var j = 0; j < t.Length; j++) {
tmp[i - j] = t[t.Length - 1 - j];
}
answer = new string(tmp);
answer = answer.Replace("?", "a");
break;
}
}
Console.WriteLine(answer);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20]]
| 8
| 339
| 2
|
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 int x;
public int y;
public int z;
public Pair(int X, int Y, int Z) {
x = X;
y = Y;
z = Z;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
static bool[] visited;
static List<int>[] togo;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
char[] s = scan.Scan().ToCharArray();
string t = scan.Scan();
int n = s.Length;
int count = -1;
for (int i = n - t.Length; i >= 0; i--) {
bool clear = true;
for (int j = 0; j < t.Length; j++) {
if (s[i + j] == '?') {
continue;
}
if (s[i + j] != t[j]) {
clear = false;
break;
}
}
if (clear) {
count = i;
}
}
if (count == -1) {
Console.WriteLine("UNRESTORABLE");
return;
}
for (int i = 0; i < t.Length; i++) {
s[count + i] = t[i];
}
for (int i = 0; i < n; i++) {
if (s[i] == '?') {
s[i] = 'a';
}
}
Console.WriteLine(new String(s));
}
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;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static 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);
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(int n, int 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.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;
}
}
}
|
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 int x;
public int y;
public int z;
public Pair(int X, int Y, int Z) {
x = X;
y = Y;
z = Z;
}
public int CompareTo(object obj) {
Pair kore = (Pair)obj;
return x.CompareTo(kore.x);
}
public static bool operator <=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x <= p2.x;
} else {
return p1.y <= p2.y;
}
}
public static bool operator >=(Pair p1, Pair p2) {
if (p1.x != p2.x) {
return p1.x >= p2.x;
} else {
return p1.y >= p2.y;
}
}
}
class Program {
static bool[] visited;
static List<int>[] togo;
static void Main(string[] args) {
long mod = 1000000007;
StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
char[] s = scan.Scan().ToCharArray();
string t = scan.Scan();
int n = s.Length;
int count = -1;
for (int i = n - t.Length; i >= 0; i--) {
bool clear = true;
for (int j = 0; j < t.Length; j++) {
if (s[i + j] == '?') {
continue;
}
if (s[i + j] != t[j]) {
clear = false;
break;
}
}
if (clear) {
count = i;
break;
}
}
if (count == -1) {
Console.WriteLine("UNRESTORABLE");
return;
}
for (int i = 0; i < t.Length; i++) {
s[count + i] = t[i];
}
for (int i = 0; i < n; i++) {
if (s[i] == '?') {
s[i] = 'a';
}
}
Console.WriteLine(new String(s));
}
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;
}
static int nibutan(int med, int[] a) // med以上が何個あるか
{
int mae = 0;
int ato = a.Length;
while (true) {
if (ato - mae <= 1) {
return mae;
}
int mid = (mae + ato) / 2;
if (a[mid] > med) {
ato = mid;
}
if (a[mid] <= med) {
mae = mid;
}
}
}
static long DivideWith(long m, long n, List<long> primes) {
while (m % n == 0) {
primes.Add(n);
m = m / n;
}
return m;
}
static 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);
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
private readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
public char[] Char(int n) {
char[] kore = new char[n];
for (int i = 0; i < n; i++) {
kore[i] = Char();
}
return kore;
}
public char[,] Char(int n, int 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.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;
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35]]
| 8
| 10,785
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
var s = Console.ReadLine();
var t = Console.ReadLine();
var dic = new Dictionary<string, int>() {};
for (int i = 0; i < s.Length; i++) {
bool ok = true;
StringBuilder sb = new StringBuilder("");
for (int k = 0; k < i; k++) {
if (s[k] == '?') {
sb.Append("a");
} else {
sb.Append(s[k]);
}
}
for (int k = 0; k < t.Length; k++) {
if (i + k == s.Length) {
ok = false;
break;
} else if (s[i + k] == '?') {
sb.Append(t[k]);
} else if (s[i + k] == t[k]) {
sb.Append(t[k]);
} else {
ok = false;
break;
}
}
if (ok) {
while (sb.Length < s.Length) {
if (s[sb.Length] == '?') {
sb.Append("a");
} else {
sb.Append(s[sb.Length]);
}
}
if (!dic.ContainsKey(sb.ToString())) {
dic.Add(sb.ToString(), 1);
}
}
}
// 出力
var ans = "";
if (dic.Count == 0) {
ans = "UNRESTORABLE";
} else {
ans = dic.OrderBy(val => val.Value).First().Key;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
var s = Console.ReadLine();
var t = Console.ReadLine();
var dic = new Dictionary<string, int>() {};
for (int i = 0; i < s.Length; i++) {
bool ok = true;
StringBuilder sb = new StringBuilder("");
for (int k = 0; k < i; k++) {
if (s[k] == '?') {
sb.Append("a");
} else {
sb.Append(s[k]);
}
}
for (int k = 0; k < t.Length; k++) {
if (i + k == s.Length) {
ok = false;
break;
} else if (s[i + k] == '?') {
sb.Append(t[k]);
} else if (s[i + k] == t[k]) {
sb.Append(t[k]);
} else {
ok = false;
break;
}
}
if (ok) {
while (sb.Length < s.Length) {
if (s[sb.Length] == '?') {
sb.Append("a");
} else {
sb.Append(s[sb.Length]);
}
}
if (!dic.ContainsKey(sb.ToString())) {
dic.Add(sb.ToString(), 1);
}
}
}
// 出力
var ans = "";
if (dic.Count == 0) {
ans = "UNRESTORABLE";
} else {
ans = dic.OrderBy(val => val.Key).First().Key;
}
Console.WriteLine(ans);
}
}
|
[["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22]]
| 8
| 394
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Asakatsu20200318D.Input;
namespace Asakatsu20200318D {
static class Input {
/// <summary>
/// 1行の入力をTに応じてリストに変換する関数を返す
/// </summary>
static Func<string, List<T>>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToList();
/// <summary>
/// 1行の入力をTに応じて変換する関数を返す
/// </summary>
static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(List<string>))
return _ => (T)(object)Cast<string>()(_);
if (t == typeof(List<int>))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(List<long>))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(List<double>))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
static string String() => Console.ReadLine();
static List<string>
String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToList();
/// <summary>
/// 1行の値の入力
/// </summary>
public static void @in<T>(out T a) => a = Convert<List<T>>()(String())[0];
public static void @in<T>(out T a1, out T a2) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
}
public static void @in<T>(out T a1, out T a2, out T a3) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
}
public static void @in<T>(out T a1, out T a2, out T a3, out T a4) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
}
public static void @in<T>(out T a1, out T a2, out T a3, out T a4, out T a5) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
a5 = v[4];
}
public static void
@in<T>(out T a1, out T a2, out T a3, out T a4, out T a5, out T a6) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
a5 = v[4];
a6 = v[5];
}
/// <summary>
/// 複数行の値の入力
/// </summary>
public static void @in<T>(long rowNumber, out List<T> l) => l =
String(rowNumber).Select(Convert<T>()).ToList();
public static void @in<T>(long rowNumber, out List<T> l1, out List<T> l2) {
l1 = new List<T>();
l2 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
}
}
public static void
@in<T>(long rowNumber, out List<T> l1, out List<T> l2, out List<T> l3) {
l1 = new List<T>();
l2 = new List<T>();
l3 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
l3.Add(l[2]);
}
}
public static void @in<T>(long rowNumber, out List<T> l1, out List<T> l2,
out List<T> l3, out List<T> l4) {
l1 = new List<T>();
l2 = new List<T>();
l3 = new List<T>();
l4 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
l3.Add(l[2]);
l4.Add(l[3]);
}
}
/// <summary>
/// 1行に書かれた複数の値の入力
/// </summary>
public static void
@in<T>(out List<T> lArr) => lArr = Convert<List<T>>()(String());
/// <summary>
/// h行の行列の入力
/// </summary>
public static void @in<T>(long h, out List<List<T>> map) => map =
String(h).Select(Convert<List<T>>()).ToList();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
private string S;
private string T;
public void Solve() {
@in(out S);
@in(out T);
List<string> ans = new List<string>();
// Sのi文字目からTが含まれると仮定する Tでない部分はなるべくAで埋める
for (int i = 0; i < S.Length - T.Length + 1; i++) {
char[] s = new char[S.Length];
bool unrestorable = false;
//各文字比べる
for (int j = 0; j < S.Length; j++) {
if (j < i) {
s[j] = S[j] == '?' ? 'a' : S[j];
continue;
}
if (j < T.Length + i) {
if (S[j] != '?' && S[j] != T[j - i]) {
unrestorable = true;
break;
}
s[j] = T[j - i];
continue;
}
s[j] = S[i] == '?' ? 'a' : S[i];
}
if (unrestorable) {
continue;
}
ans.Add(new string(s));
}
if (ans.Count > 0) {
ans.Sort();
Console.WriteLine(ans[0]);
} else {
Console.WriteLine("UNRESTORABLE");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Asakatsu20200318D.Input;
namespace Asakatsu20200318D {
static class Input {
/// <summary>
/// 1行の入力をTに応じてリストに変換する関数を返す
/// </summary>
static Func<string, List<T>>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToList();
/// <summary>
/// 1行の入力をTに応じて変換する関数を返す
/// </summary>
static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(List<string>))
return _ => (T)(object)Cast<string>()(_);
if (t == typeof(List<int>))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(List<long>))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(List<double>))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
static string String() => Console.ReadLine();
static List<string>
String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToList();
/// <summary>
/// 1行の値の入力
/// </summary>
public static void @in<T>(out T a) => a = Convert<List<T>>()(String())[0];
public static void @in<T>(out T a1, out T a2) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
}
public static void @in<T>(out T a1, out T a2, out T a3) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
}
public static void @in<T>(out T a1, out T a2, out T a3, out T a4) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
}
public static void @in<T>(out T a1, out T a2, out T a3, out T a4, out T a5) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
a5 = v[4];
}
public static void
@in<T>(out T a1, out T a2, out T a3, out T a4, out T a5, out T a6) {
var v = Convert<List<T>>()(String());
a1 = v[0];
a2 = v[1];
a3 = v[2];
a4 = v[3];
a5 = v[4];
a6 = v[5];
}
/// <summary>
/// 複数行の値の入力
/// </summary>
public static void @in<T>(long rowNumber, out List<T> l) => l =
String(rowNumber).Select(Convert<T>()).ToList();
public static void @in<T>(long rowNumber, out List<T> l1, out List<T> l2) {
l1 = new List<T>();
l2 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
}
}
public static void
@in<T>(long rowNumber, out List<T> l1, out List<T> l2, out List<T> l3) {
l1 = new List<T>();
l2 = new List<T>();
l3 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
l3.Add(l[2]);
}
}
public static void @in<T>(long rowNumber, out List<T> l1, out List<T> l2,
out List<T> l3, out List<T> l4) {
l1 = new List<T>();
l2 = new List<T>();
l3 = new List<T>();
l4 = new List<T>();
foreach (List<T> l in String(rowNumber).Select(Convert<List<T>>())) {
l1.Add(l[0]);
l2.Add(l[1]);
l3.Add(l[2]);
l4.Add(l[3]);
}
}
/// <summary>
/// 1行に書かれた複数の値の入力
/// </summary>
public static void
@in<T>(out List<T> lArr) => lArr = Convert<List<T>>()(String());
/// <summary>
/// h行の行列の入力
/// </summary>
public static void @in<T>(long h, out List<List<T>> map) => map =
String(h).Select(Convert<List<T>>()).ToList();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
private string S;
private string T;
public void Solve() {
@in(out S);
@in(out T);
List<string> ans = new List<string>();
// Sのi文字目からTが含まれると仮定する Tでない部分はなるべくAで埋める
for (int i = 0; i < S.Length - T.Length + 1; i++) {
char[] s = new char[S.Length];
bool unrestorable = false;
//各文字比べる
for (int j = 0; j < S.Length; j++) {
if (j < i) {
s[j] = S[j] == '?' ? 'a' : S[j];
continue;
}
if (j < T.Length + i) {
if (S[j] != '?' && S[j] != T[j - i]) {
unrestorable = true;
break;
}
s[j] = T[j - i];
continue;
}
s[j] = S[j] == '?' ? 'a' : S[j];
}
if (unrestorable) {
continue;
}
ans.Add(new string(s));
}
if (ans.Count > 0) {
ans.Sort();
Console.WriteLine(ans[0]);
} else {
Console.WriteLine("UNRESTORABLE");
}
}
}
}
|
[["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 41, 75, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 41, 75, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 1,620
| 4
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
//
var S = GetStr().Reverse().ToArray();
var T = GetStr().Reverse().ToArray();
char[] tS = new char[S.Length];
var f = false;
for (int i = 0; i < S.Length - T.Length; i++) {
var flag = true;
tS = new char[S.Length];
Array.Copy(S, 0, tS, 0, S.Length);
for (int j = 0; j < T.Length; j++) {
if (S[i + j] != T[j] && S[i + j] != '?') {
flag = false;
break;
} else {
tS[i + j] = T[j];
}
}
if (flag) {
tS = tS.Select(c => c == '?' ? 'a' : c).ToArray();
f = true;
break;
}
}
var ans = f ? new string(tS.Reverse().ToArray()) : "UNRESTORABLE";
Console.WriteLine(ans);
//
Console.Out.Flush();
Console.ReadKey();
}
static void Solve() {}
static public string GetStr() { return Console.ReadLine().Trim(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Split(' ').Select(char.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V>(out T a, out U b, out V c, out V d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<V>(ar[3]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
//
var S = GetStr().Reverse().ToArray();
var T = GetStr().Reverse().ToArray();
char[] tS = new char[S.Length];
var f = false;
for (int i = 0; i < S.Length - T.Length + 1; i++) {
var flag = true;
tS = new char[S.Length];
Array.Copy(S, 0, tS, 0, S.Length);
for (int j = 0; j < T.Length; j++) {
if (S[i + j] != T[j] && S[i + j] != '?') {
flag = false;
break;
} else {
tS[i + j] = T[j];
}
}
if (flag) {
tS = tS.Select(c => c == '?' ? 'a' : c).ToArray();
f = true;
break;
}
}
var ans = f ? new string(tS.Reverse().ToArray()) : "UNRESTORABLE";
Console.WriteLine(ans);
//
Console.Out.Flush();
Console.ReadKey();
}
static void Solve() {}
static public string GetStr() { return Console.ReadLine().Trim(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Split(' ').Select(char.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V>(out T a, out U b, out V c, out V d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<V>(ar[3]);
}
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 1,051
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace ABC076 {
class C {
static void Main(string[] args) {
string s = Console.ReadLine();
string t = Console.ReadLine();
bool isMatch = true;
List<string> sList = new List<string>();
var indexT = 0;
var indexS = 0;
for (int i = 0; i < s.Length - t.Length + 1; i++) {
isMatch = true;
indexS = i;
indexT = 0;
while (indexT < t.Length) {
if (s[indexS] != '?' && s[indexS] != t[indexT]) {
isMatch = false;
break;
}
indexS++;
indexT++;
}
if (isMatch) {
// Console.WriteLine("test");
string front = s.Substring(0, i);
string rear =
s.Substring(i + t.Length - 1, s.Length - front.Length - t.Length);
string res = front + t + rear;
res = res.Replace('?', 'a');
sList.Add(res);
}
}
sList = sList.OrderBy(x => x).ToList();
if (0 < sList.Count)
Console.WriteLine(sList[0]);
else
Console.WriteLine("UNRESTORABLE");
// Console.WriteLine("front : " + s.Substring(0, 0));
// Console.WriteLine("center : " + s.Substring(1, 2));
// Console.WriteLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace ABC076 {
class C {
static void Main(string[] args) {
string s = Console.ReadLine();
string t = Console.ReadLine();
bool isMatch = true;
List<string> sList = new List<string>();
var indexT = 0;
var indexS = 0;
for (int i = 0; i < s.Length - t.Length + 1; i++) {
isMatch = true;
indexS = i;
indexT = 0;
while (indexT < t.Length) {
if (s[indexS] != '?' && s[indexS] != t[indexT]) {
isMatch = false;
break;
}
indexS++;
indexT++;
}
if (isMatch) {
string front = s.Substring(0, i);
string rear =
s.Substring(i + t.Length, s.Length - front.Length - t.Length);
string res = front + t + rear;
res = res.Replace('?', 'a');
sList.Add(res);
}
}
sList = sList.OrderBy(x => x).ToList();
// Console.WriteLine(string.Join(" ", sList));
if (0 < sList.Count)
Console.WriteLine(sList[0]);
else
Console.WriteLine("UNRESTORABLE");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 293
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Numerics;
using System.Text.RegularExpressions;
class Myon {
// chokudaiさんのコードをコピペ
static Scanner cin;
public Myon() {}
public static int Main() {
// Console.SetOut(new Printer(Console.OpenStandardOutput()));
cin = new Scanner();
new Myon().calc();
return 0;
}
public void calc() {
char[] s = cin.next().ToArray<char>();
char[] t = cin.next().ToArray<char>();
int tempMaxLoc = -1;
for (int i = 0; i < s.Length; i++) {
bool isOK = true;
int j;
for (j = i; j < s.Length && j - i < t.Length; j++) {
if (s[j] != t[j - i] && s[j] != '?') {
isOK = false;
break;
}
}
if (j - i != t.Length)
isOK = false;
if (isOK)
tempMaxLoc = i;
}
if (tempMaxLoc == -1)
showL("UNRESTOREABLE");
else {
for (int i = 0; i < s.Length; i++) {
if (i >= tempMaxLoc && i < tempMaxLoc + t.Length) {
s[i] = t[i - tempMaxLoc];
} else if (s[i] == '?')
s[i] = 'a';
}
showL(new string(s));
}
}
public void calc_ABC076D() {
int n = cin.nextInt();
int[] t = cin.nextIntArr(n);
int[] v = cin.nextIntArr(n);
// k番目の拘束条件(t = Σti(i=0 ~ k-1) ~ Σti + tk) Σti(i=0 ~ k-1) を stk
// とかく
// (言い換えればk番目の拘束が始まる時間)
// は、言い換えればt = x において (v(x)を実際の速度として)
// x <= stk-1 ⇒ v(x) <= vk + (stk-1 + x)
// x >= stk ⇒ v(x) ∈ [vk - (stk - x), vk + (stk + x) ]
}
public void calcC() {
int n = cin.nextInt();
// System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
// sw.Start();
int m = cin.nextInt();
List<int> a = new List<int>(m);
List<int> b = new List<int>(m);
for (int i = 0; i < m; i++) {
a.Add(cin.nextInt());
b.Add(cin.nextInt());
}
int ans = 0;
List<int> bridge = new List<int>();
for (int i = 0; i < m; i++) {
tempConnected = new bool[n];
AddConnected(1, a, b, i);
bool allconnected = true;
for (int j = 0; j < n; j++)
if (!tempConnected[j]) {
allconnected = false;
break;
}
if (!allconnected) {
bridge.Add(i + 1);
ans++;
}
// else
//{
// showL($"{i + 1} is not bridge");
//}
}
showL(ans);
// sw.Stop();
// showL($"処理時間: {sw.ElapsedMilliseconds} [msec]");
}
bool[] tempConnected;
public void AddConnected(int index, List<int> a, List<int> b,
int ignoreingBridge = -1) {
// index番目のノードにつながるノードをconnectedにして、さらにaddconnectedを呼び出す
for (int i = 0; i < a.Count; i++) {
if (i == ignoreingBridge)
continue;
if (a[i] - 1 == index && !tempConnected[b[i] - 1]) {
tempConnected[b[i] - 1] = true;
AddConnected(b[i] - 1, a, b, ignoreingBridge);
} else if (b[i] - 1 == index && !tempConnected[a[i] - 1]) {
tempConnected[a[i] - 1] = true;
AddConnected(a[i] - 1, a, b, ignoreingBridge);
}
}
}
public void backetSort(ref int[] a) {
// max a << a.len に対して有効なソート
//よってa = int[] とする
long n = a.Length;
var count = new int[n];
var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index]
// = loc[i]
for (long i = 0; i < n; i++)
count[a[i]]++;
loc[0] = count[0] - 1;
for (long i = 0; i < n - 1; i++)
loc[i + 1] = loc[i] + count[i + 1];
long index = 0;
for (int i = 0; i < n; i++) {
while (index <= loc[i])
a[index++] = i; // incex <= loc[i] == index < loc[i] + 1
}
}
public static void showL<T>(T s) { Console.WriteLine(s); }
public static void show<T>(T s) { Console.Write(s); }
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
while (i >= s.Length) {
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
}
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] nextIntArr(long n) {
int[] output = new int[n];
for (int i = 0; i < n; i++)
output[i] = nextInt();
return output;
}
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
class SMath {
/// <summary>
/// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。
/// 12 なら 2,2,3 です。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<long> Factorization(long n) {
if (n <= 0)
return null;
List<long> output = new List<long>();
int i = 2;
long max = (long)Math.Sqrt(n);
;
while (n > 1) {
if (i > max) {
output.Add(n);
break;
}
while (n % i == 0) {
output.Add(i);
n /= i;
}
i++;
}
return output;
}
/// <summary>
/// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。
/// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1 remainder = 1です。(打ち切られない)
/// 13 = 0,0,...0 remainder = 2019
/// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる)
/// </summary>
/// <param name="n"></param>
/// <param name="remainder"></param>
/// <returns></returns>
public static List<long> Factorization(long n, out long remainder) {
// output[i] が i-1番目の素数の数を示す
//ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる)
remainder = 1;
if (n <= 0)
return null;
List<long> output = new List<long>();
long tempn = 2;
long max = (long)Math.Sqrt(n);
bool[] isNOTPrime = new bool[max + 1];
while (n > 1) {
if (tempn > max) {
remainder = n;
break;
}
if (!isNOTPrime[tempn]) {
output.Add(0);
while (n % tempn == 0) {
output[output.Count - 1]++;
n /= tempn;
}
for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn)
isNOTPrime[j] = true;
}
tempn++;
}
return output;
}
/// <summary>
/// i番目の素数をoutput[i-1]に返します。
/// ただしnより大きい素数については判定しません。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<long> GetPrimeNumbers(long n) {
if (n <= 0)
return null;
List<long> output = new List<long>();
long tempn = 2;
bool[] isNOTPrime = new bool[n + 1];
while (n > 1) {
if (tempn > n) {
break;
}
if (!isNOTPrime[tempn]) {
output.Add(tempn);
for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn)
isNOTPrime[j] = true;
}
tempn++;
}
return output;
}
private static long[][] combMemo;
private static int maxn_combination = -1;
public static long Combination(int n, int k) {
if (n < 0 || k > n)
return 0;
if (n == k || k == 0)
return 1;
if (k > n / 2)
return Combination(n, n - k);
if (maxn_combination < n) {
maxn_combination = n;
combMemo = new long [n + 1][];
}
if (combMemo[n] == null)
combMemo[n] = new long[n / 2 + 1];
if (combMemo[n][k] != 0)
return combMemo[n][k];
else {
combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1);
return combMemo[n][k];
}
}
public static long Gcd(long a, long b) {
if (a <= 0)
return -1;
// if (a > b) return gcd(b, a);
if (b == 0)
return a;
return Gcd(b, a % b);
}
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Numerics;
using System.Text.RegularExpressions;
class Myon {
// chokudaiさんのコードをコピペ
static Scanner cin;
public Myon() {}
public static int Main() {
// Console.SetOut(new Printer(Console.OpenStandardOutput()));
cin = new Scanner();
new Myon().calc();
return 0;
}
public void calc() {
char[] s = cin.next().ToArray<char>();
char[] t = cin.next().ToArray<char>();
int tempMaxLoc = -1;
for (int i = 0; i < s.Length; i++) {
bool isOK = true;
int j;
for (j = i; j < s.Length && j - i < t.Length; j++) {
if (s[j] != t[j - i] && s[j] != '?') {
isOK = false;
break;
}
}
if (j - i != t.Length)
isOK = false;
if (isOK)
tempMaxLoc = i;
}
if (tempMaxLoc == -1)
showL("UNRESTORABLE");
else {
for (int i = 0; i < s.Length; i++) {
if (i >= tempMaxLoc && i < tempMaxLoc + t.Length) {
s[i] = t[i - tempMaxLoc];
} else if (s[i] == '?')
s[i] = 'a';
}
showL(new string(s));
}
}
public void calc_ABC076D() {
int n = cin.nextInt();
int[] t = cin.nextIntArr(n);
int[] v = cin.nextIntArr(n);
// k番目の拘束条件(t = Σti(i=0 ~ k-1) ~ Σti + tk) Σti(i=0 ~ k-1) を stk
// とかく
// (言い換えればk番目の拘束が始まる時間)
// は、言い換えればt = x において (v(x)を実際の速度として)
// x <= stk-1 ⇒ v(x) <= vk + (stk-1 + x)
// x >= stk ⇒ v(x) ∈ [vk - (stk - x), vk + (stk + x) ]
}
public void calcC() {
int n = cin.nextInt();
// System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
// sw.Start();
int m = cin.nextInt();
List<int> a = new List<int>(m);
List<int> b = new List<int>(m);
for (int i = 0; i < m; i++) {
a.Add(cin.nextInt());
b.Add(cin.nextInt());
}
int ans = 0;
List<int> bridge = new List<int>();
for (int i = 0; i < m; i++) {
tempConnected = new bool[n];
AddConnected(1, a, b, i);
bool allconnected = true;
for (int j = 0; j < n; j++)
if (!tempConnected[j]) {
allconnected = false;
break;
}
if (!allconnected) {
bridge.Add(i + 1);
ans++;
}
// else
//{
// showL($"{i + 1} is not bridge");
//}
}
showL(ans);
// sw.Stop();
// showL($"処理時間: {sw.ElapsedMilliseconds} [msec]");
}
bool[] tempConnected;
public void AddConnected(int index, List<int> a, List<int> b,
int ignoreingBridge = -1) {
// index番目のノードにつながるノードをconnectedにして、さらにaddconnectedを呼び出す
for (int i = 0; i < a.Count; i++) {
if (i == ignoreingBridge)
continue;
if (a[i] - 1 == index && !tempConnected[b[i] - 1]) {
tempConnected[b[i] - 1] = true;
AddConnected(b[i] - 1, a, b, ignoreingBridge);
} else if (b[i] - 1 == index && !tempConnected[a[i] - 1]) {
tempConnected[a[i] - 1] = true;
AddConnected(a[i] - 1, a, b, ignoreingBridge);
}
}
}
public void backetSort(ref int[] a) {
// max a << a.len に対して有効なソート
//よってa = int[] とする
long n = a.Length;
var count = new int[n];
var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index]
// = loc[i]
for (long i = 0; i < n; i++)
count[a[i]]++;
loc[0] = count[0] - 1;
for (long i = 0; i < n - 1; i++)
loc[i + 1] = loc[i] + count[i + 1];
long index = 0;
for (int i = 0; i < n; i++) {
while (index <= loc[i])
a[index++] = i; // incex <= loc[i] == index < loc[i] + 1
}
}
public static void showL<T>(T s) { Console.WriteLine(s); }
public static void show<T>(T s) { Console.Write(s); }
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
while (i >= s.Length) {
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
}
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] nextIntArr(long n) {
int[] output = new int[n];
for (int i = 0; i < n; i++)
output[i] = nextInt();
return output;
}
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
class SMath {
/// <summary>
/// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。
/// 12 なら 2,2,3 です。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<long> Factorization(long n) {
if (n <= 0)
return null;
List<long> output = new List<long>();
int i = 2;
long max = (long)Math.Sqrt(n);
;
while (n > 1) {
if (i > max) {
output.Add(n);
break;
}
while (n % i == 0) {
output.Add(i);
n /= i;
}
i++;
}
return output;
}
/// <summary>
/// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。
/// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1 remainder = 1です。(打ち切られない)
/// 13 = 0,0,...0 remainder = 2019
/// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる)
/// </summary>
/// <param name="n"></param>
/// <param name="remainder"></param>
/// <returns></returns>
public static List<long> Factorization(long n, out long remainder) {
// output[i] が i-1番目の素数の数を示す
//ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる)
remainder = 1;
if (n <= 0)
return null;
List<long> output = new List<long>();
long tempn = 2;
long max = (long)Math.Sqrt(n);
bool[] isNOTPrime = new bool[max + 1];
while (n > 1) {
if (tempn > max) {
remainder = n;
break;
}
if (!isNOTPrime[tempn]) {
output.Add(0);
while (n % tempn == 0) {
output[output.Count - 1]++;
n /= tempn;
}
for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn)
isNOTPrime[j] = true;
}
tempn++;
}
return output;
}
/// <summary>
/// i番目の素数をoutput[i-1]に返します。
/// ただしnより大きい素数については判定しません。
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
public static List<long> GetPrimeNumbers(long n) {
if (n <= 0)
return null;
List<long> output = new List<long>();
long tempn = 2;
bool[] isNOTPrime = new bool[n + 1];
while (n > 1) {
if (tempn > n) {
break;
}
if (!isNOTPrime[tempn]) {
output.Add(tempn);
for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn)
isNOTPrime[j] = true;
}
tempn++;
}
return output;
}
private static long[][] combMemo;
private static int maxn_combination = -1;
public static long Combination(int n, int k) {
if (n < 0 || k > n)
return 0;
if (n == k || k == 0)
return 1;
if (k > n / 2)
return Combination(n, n - k);
if (maxn_combination < n) {
maxn_combination = n;
combMemo = new long [n + 1][];
}
if (combMemo[n] == null)
combMemo[n] = new long[n / 2 + 1];
if (combMemo[n][k] != 0)
return combMemo[n][k];
else {
combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1);
return combMemo[n][k];
}
}
public static long Gcd(long a, long b) {
if (a <= 0)
return -1;
// if (a > b) return gcd(b, a);
if (b == 0)
return a;
return Gcd(b, a % b);
}
public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; }
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 1,894
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var S = Console.ReadLine().ToCharArray();
var T = Console.ReadLine();
var answer = new List<string>();
for (int i = 0; i < S.Length - T.Length; i++) {
var tmpS = S.ToList().ToArray();
for (int k = 0; k < T.Length; k++) {
if (tmpS[i + k] == '?')
tmpS[i + k] = T[k];
if (tmpS[i + k] != T[k])
break;
}
if (string.Concat(tmpS).Contains(T)) {
answer.Add(string.Concat(tmpS).Replace('?', 'a'));
}
}
if (!answer.Any()) {
Console.WriteLine("UNRESTORABLE");
return;
}
answer.Sort();
Console.WriteLine(answer.First());
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var S = Console.ReadLine().ToCharArray();
var T = Console.ReadLine();
var answer = new List<string>();
for (int i = 0; i <= S.Length - T.Length; i++) {
var tmpS = S.ToList().ToArray();
for (int k = 0; k < T.Length; k++) {
if (tmpS[i + k] == '?')
tmpS[i + k] = T[k];
if (tmpS[i + k] != T[k])
break;
}
if (string.Concat(tmpS).Contains(T)) {
answer.Add(string.Concat(tmpS).Replace('?', 'a'));
}
}
if (!answer.Any()) {
Console.WriteLine("UNRESTORABLE");
return;
}
answer.Sort();
Console.WriteLine(answer.First());
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 235
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
private const int INF = 1000000007;
public static void Main() {
string S = NextString();
S = new string(S.Reverse().ToArray());
string ans = "";
string T = NextString();
T = new string(T.Reverse().ToArray());
int M = S.Length - T.Length;
bool a = false;
for (int i = 0; i < S.Length; i++) {
char c = S[i];
if (c == '?' || c == T[0]) {
bool flag = true;
for (int j = 0; j < T.Length; j++) {
if (i + j == S.Length) {
flag = false;
break;
}
if ((S[i + j] != T[j]) && (S[i + j] != '?'))
flag = false;
}
if (flag) {
a = true;
ans += T;
i += T.Length - 1;
} else
ans += c;
} else
ans += c;
}
ans = new string(ans.Reverse().ToArray());
if (!a) {
Console.WriteLine("UNRESTORABLE");
} else {
Console.WriteLine(ans.Replace('?', 'a'));
}
}
}
public class Input {
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Prog {
private const int INF = 1000000007;
public static void Main() {
string S = NextString();
S = new string(S.Reverse().ToArray());
string ans = "";
string T = NextString();
T = new string(T.Reverse().ToArray());
int M = S.Length - T.Length;
bool a = false;
for (int i = 0; i < S.Length; i++) {
char c = S[i];
if ((c == '?' || c == T[0]) && !a) {
bool flag = true;
for (int j = 0; j < T.Length; j++) {
if (i + j == S.Length) {
flag = false;
break;
}
if ((S[i + j] != T[j]) && (S[i + j] != '?'))
flag = false;
}
if (flag) {
a = true;
ans += T;
i += T.Length - 1;
} else
ans += c;
} else
ans += c;
}
ans = new string(ans.Reverse().ToArray());
if (!a) {
Console.WriteLine("UNRESTORABLE");
} else {
Console.WriteLine(ans.Replace('?', 'a'));
}
}
}
public class Input {
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 111], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 22]]
| 8
| 595
| 5
|
using System;
using System.Linq;
using System.Collections.Generic;
public class Program {
public static void Main() {
var s = string.Join("", Console.ReadLine().Reverse());
var t = string.Join("", Console.ReadLine().Reverse());
var a = "";
var can = false;
for (var i = 0; i < s.Length - t.Length; i++) {
for (var j = 0; j < t.Length; j++) {
if (t[j] == s[j + i] || s[j + i] == '?') {
can = true;
} else {
can = false;
break;
}
}
if (can) {
// Console.WriteLine("i={0} t.len={1} s.len={2}", i, t.Length,
// s.Length);
a = s.Substring(0, i) + t +
s.Substring(i + t.Length, s.Length - t.Length - i);
break;
}
}
Console.WriteLine(can ? string.Join("", a.Replace('?', 'a').Reverse())
: "UNRESTORABLE");
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
public class Program {
public static void Main() {
var s = string.Join("", Console.ReadLine().Reverse());
var t = string.Join("", Console.ReadLine().Reverse());
var a = "";
var can = false;
for (var i = 0; i < s.Length - t.Length + 1; i++) {
for (var j = 0; j < t.Length; j++) {
if (t[j] == s[j + i] || s[j + i] == '?') {
can = true;
} else {
// Console.WriteLine("FALSE i={0} j={1}", i, j);
can = false;
break;
}
}
if (can) {
// Console.WriteLine("i={0} t.len={1} s.len={2}", i, t.Length,
// s.Length);
a = s.Substring(0, i) + t +
s.Substring(i + t.Length, s.Length - t.Length - i);
break;
}
}
Console.WriteLine(can ? string.Join("", a.Replace('?', 'a').Reverse())
: "UNRESTORABLE");
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 241
| 2
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
class Program {
static void Main() {
int answer = 0;
string s = Console.ReadLine();
char[] ss = s.ToCharArray();
string tt = Console.ReadLine();
for (int i = ss.Length; i > tt.Length - 1; i--) {
for (int j = 0; j < tt.Length; j++) {
if (ss[i - j] != tt[tt.Length - 1 - j] && ss[i - j] != '?')
break;
if (j == tt.Length - 1) {
for (int k = 0; k < tt.Length; k++) {
ss[i - j] = tt[tt.Length - 1 - j];
}
for (int k = 0; k < ss.Length; k++) {
if (ss[k] == '?')
ss[k] = 'a';
}
Console.WriteLine(ss);
answer = 1;
break;
}
}
if (answer != 0)
break;
}
if (answer == 0)
Console.WriteLine("UNRESTORABLE");
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
class Program {
static void Main() {
int answer = 0;
string s = Console.ReadLine();
char[] ss = s.ToCharArray();
string tt = Console.ReadLine();
for (int i = ss.Length - 1; i >= tt.Length - 1; i--) {
for (int j = 0; j < tt.Length; j++) {
if (ss[i - j] != tt[tt.Length - 1 - j] && ss[i - j] != '?')
break;
if (j == tt.Length - 1) {
for (int k = 0; k < tt.Length; k++) {
ss[i - k] = tt[tt.Length - 1 - k];
}
for (int k = 0; k < ss.Length; k++) {
if (ss[k] == '?')
ss[k] = 'a';
}
Console.WriteLine(ss);
answer = 1;
break;
}
}
if (answer != 0)
break;
}
if (answer == 0)
Console.WriteLine("UNRESTORABLE");
}
}
|
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
| 8
| 256
| 8
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Program {
internal static void Main(string[] args) {
var S = ReadLine();
var T = ReadLine();
if (S.Contains(T)) {
WriteLine(S.Replace('?', 'a'));
return;
}
var Srev = string.Join("", S.Reverse());
var Trev = string.Join("", T.Reverse());
for (int i = 0; i < S.Length - T.Length - 1; i++) {
var tmp = Sub(Srev, Trev, i);
if (tmp != null) {
WriteLine(string.Join("", tmp.Reverse()).Replace('?', 'a'));
return;
}
}
WriteLine("UNRESTORABLE");
}
static char[] Sub(string Srev, string Trev, int i) {
var tmp = new char[Srev.Length];
Array.Copy(Srev.ToCharArray(), tmp, Srev.Length);
for (int j = 0; j < Trev.Length; j++) {
if (Srev[i + j] == Trev[j]) {
continue;
} else if (Srev[i + j] == '?') {
tmp[i + j] = Trev[j];
} else {
return null;
}
}
return tmp;
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Program {
internal static void Main(string[] args) {
var S = ReadLine();
var T = ReadLine();
if (S.Contains(T)) {
WriteLine(S.Replace('?', 'a'));
return;
}
var Srev = string.Join("", S.Reverse());
var Trev = string.Join("", T.Reverse());
for (int i = 0; i < S.Length - (T.Length - 1); i++) {
var tmp = Sub(Srev, Trev, i);
if (tmp != null) {
WriteLine(string.Join("", tmp.Reverse()).Replace('?', 'a'));
return;
}
}
WriteLine("UNRESTORABLE");
}
static char[] Sub(string Srev, string Trev, int i) {
var tmp = new char[Srev.Length];
Array.Copy(Srev.ToCharArray(), tmp, Srev.Length);
for (int j = 0; j < Trev.Length; j++) {
if (Srev[i + j] == Trev[j]) {
continue;
} else if (Srev[i + j] == '?') {
tmp[i + j] = Trev[j];
} else {
return null;
}
}
return tmp;
}
}
|
[["+", 0, 7, 15, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 7, 15, 16, 12, 16, 12, 23, 0, 25]]
| 8
| 313
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Program {
class MainClass {
////////////////////////////////////////////////////////////
string S, T;
void Solve() {
io.i(out S, out T);
S = S.Reversed();
T = T.Reversed();
var ans = S.ToCharArray();
var f = new bool[S.Length];
if (T.Length > S.Length) {
io.o("UNRESTORABLE");
}
var flag = true;
for (int i = 0; i < Math.Abs(S.Length - T.Length) + 1; ++i) {
ans = "a".Repeat(S.Length).ToCharArray();
for (int k = 0; k < S.Length; ++k) {
if (S[k] != '?') {
ans[k] = S[k];
}
}
flag = true;
for (int j = 0; j < Math.Min(S.Length, T.Length); ++j) {
if (S[i + j] != T[j]) {
if (S[i + j] == '?') {
ans[i + j] = T[j];
} else {
flag = false;
break;
}
} else {
//
}
}
if (flag)
break;
}
var Ans = ans.toString().Reversed();
if (!flag) {
io.o("UNRESTORABLE");
return;
} else {
for (int i = 0; i < ans.Length; ++i) {
io.or(Ans[i] == '?' ? 'a' : Ans[i]);
}
io.br();
}
}
////////////////////////////////////////////////////////////
public static void Main() { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
// void Stream() { Test(); io.writeFlush(); }
void Test() {}
#region MockMacro
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act) {
for (int i = a; i < b; ++i)
act(i);
}
void FORR(int a, int b, Action<int> act) {
for (int i = a - 1; i >= b; --i)
act(i);
}
#endregion
////////////////////////////////////////////////////////////
}
#region default
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public string[] arr => Console.ReadLine().Split(' ');
public char[] arrChar => Array.ConvertAll(arr, char.Parse);
public int[] arrInt => Array.ConvertAll(arr, int.Parse);
public long[] arrLong => Array.ConvertAll(arr, long.Parse);
public double[] arrDouble => Array.ConvertAll(arr, double.Parse);
public T i<T>() { return suitType<T>(String); }
public void i<T>(out T v) { v = suitType<T>(String); }
public void i<T, U>(out T v1, out U v2) {
i(out v1);
i(out v2);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
i(out v1);
i(out v2);
i(out v3);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
}
public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4,
out X v5) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
i(out v5);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = suitType<T>(String);
}
public void ini<T, U>(out T[] a, out U[] b, int n) {
a = new T[n];
b = new U[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<U>();
}
}
public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) {
a = new T[n];
b = new U[n];
c = new V[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<U>();
c[i] = i<V>();
}
}
public void ini<T, U>(out Tuple<T, U>[] t, int n) {
t = new Tuple<T, U>[n];
for (int j = 0; j < n; ++j) {
T i1;
U i2;
i(out i1);
i(out i2);
t[j] = Tuple.Create(i1, i2);
}
}
public void ini<T, U, V>(out Tuple<T, U, V>[] t, int n) {
t = new Tuple<T, U, V>[n];
for (int j = 0; j < n; ++j) {
T i1;
U i2;
V i3;
i(out i1);
i(out i2);
i(out i3);
t[j] = Tuple.Create(i1, i2, i3);
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
a[i, j] = i<T>();
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); }
public void o<T>(T[,] a) {
int a0 = a.GetLength(0), a1 = a.GetLength(1);
for (int i = 0; i < a0; ++i) {
for (int j = 0; j < a1 - 1; ++j)
Console.Write(a[i, j] + " ");
Console.WriteLine(a[i, a1 - 1]);
}
}
public void YN(bool f) { o(f ? "YES" : "NO"); }
public void Yn(bool f) { o(f ? "Yes" : "No"); }
public void yn(bool f) { o(f ? "yes" : "no"); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void or<T>(T a) { Console.Write(a); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
}
class PQueue<T>
where T : struct, IComparable<T> {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size;
private int type; // type=0->min
public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; }
public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) {
this.comparer = comparer;
}
public PQueue(Comparison<T> comparison) : this(16, comparison) {}
public PQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.comp = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (Compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
public bool Empty() { return !Any(); }
public bool Contains(T v) { return heap.Contains(v); }
private int Compare(T x, T y) {
return type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
}
class AssociativeArray<T> : IEnumerable {
public Dictionary<T, int> dic;
public AssociativeArray() { dic = new Dictionary<T, int>(); }
public AssociativeArray(params T[] a) {
dic = new Dictionary<T, int>();
Add(a);
}
public void Add(T a) {
if (!conK(a))
dic[a] = 0;
dic[a]++;
}
public void Add(params T[] a) {
a.Length.REP(i => {
if (!conK(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
});
}
public void Set(T k, int v) {
if (!dic.ContainsKey(k))
dic[k] = 0;
dic[k] = v;
}
public void Remove(params T[] a) {
a.Length.REP(i => {
if (conK(a[i]))
dic.Remove(a[i]);
});
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValSum => dic.Values.Sum();
public int KeyNum => dic.Keys.Count;
public int MaxVal => dic.Values.Max();
public int MinVal => dic.Values.Min();
public T MaxKey => MaxK();
public T MinKey => MinK();
public T MaxK() {
var maxV = MaxVal;
return dic.First(d => d.Value == maxV).Key;
}
public T MinK() {
var minV = MinVal;
return dic.First(d => d.Value == minV).Key;
}
public T[] MaxKeys() {
var maxV = MaxVal;
return dic.Where(kp => kp.Value == maxV)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public T[] MinKeys() {
var minV = MinVal;
return dic.Where(kp => kp.Value == minV)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public bool conK(T k) { return dic.ContainsKey(k); }
public bool anyK(params T[] k) { return k.Any(key => conK(key)); }
public bool allK(params T[] k) { return k.All(key => conK(key)); }
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
public T[] ValueSortedKey(bool inc = true) {
return (inc ? (dic.OrderBy(kp => kp.Value))
: (dic.OrderByDescending(kp => kp.Value)))
.ThenBy(kp => kp.Key)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public IEnumerator GetEnumerator() {
foreach (var kp in dic)
yield return kp;
}
//:sort->array
}
public struct edge : IComparable<edge> {
public int to;
public long cost;
public edge(int to, long cost) {
this.to = to;
this.cost = cost;
}
public int CompareTo(edge e) { return cost.CompareTo(e.cost); }
}
#endregion
#region test
// interface IField<T> { T Add(T that) ; T Subtract(T that); T
// Multiply(T that); T Devide(T that); }
#endregion
#region other
class Mat {
public long mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long ModC(long n, long r) {
if (r == 0 || n == r)
return 1;
if (n == 0)
return 0;
if (n < 0 || n < r)
throw new ArgumentException("n,r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long[,] C(int N) {
long[,] Co = new long[N + 1, N + 1];
(N + 1).REP(i => (i + 1).REP(j => Co[i, j] =
(j == 0 || j == i)
? 1L
: Co[i - 1, j - 1] + Co[i - 1, j]));
return Co;
}
public long DupC(long n, long r) { return ModC(n + r - 1, r); }
public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test
public bool isPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (long v = 3; v <= (long)Math.Sqrt(n); v += 2)
if (n % v == 0)
return false;
return true;
}
public long LCM(long a, long b) { return a * (b / GCD(a, b)); }
public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); }
public long GCD(long a, long b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public long GCD(params long[] array) {
return array.Aggregate((v, n) => GCD(v, n));
}
public T Max<T>(params T[] a) { return a.Max(); }
public T Min<T>(params T[] a) { return a.Min(); }
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public int mDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public int[] DigArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long DigArr2Num(IEnumerable<int> enu) {
return enu.Aggregate((v, n) => v * 10 + n);
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public long Tousa(long a, long d, long n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, long n) {
return n * (2 * a + (n - 1) * d) / 2;
}
public long[] EnuDivsor(long N) {
var ret = new SortedSet<long>();
for (long i = 1; i * i <= N; i++)
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
return ret.ToArray();
}
public Dictionary<long, long> PrimeFactor(long n) {
var ret = new Dictionary<long, long>();
for (int i = 2; i * i <= n; ++i) {
if (!ret.ContainsKey(i))
ret[i] = 0;
while (n % i == 0) {
++ret[i];
n /= i;
}
}
return ret.Where(kp => kp.Value != 0)
.ToDictionary(kp => kp.Key, kp => kp.Value);
}
public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<List<int>>();
for (int i = Arr.Length - 1; i >= 0; i--)
s.Push(new List<int>() { i });
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use) {
var ret = new List<int>();
cur.ForEach(X => ret.Add(Arr[X]));
yield return ret.ToArray();
} else
for (int i = Arr.Length - 1; i >= 0; i--)
if (!cur.Contains(i))
s.Push(new List<int>(cur) { i });
}
}
public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<List<int>>();
Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] }));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use)
yield return cur.ToArray();
else
Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<string[]> enuPart(string str) {
var s = new Stack<Tuple<string, List<string>, int>>();
s.Push(Tuple.Create(str[0].ToString(), new List<string>(), 1));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item3 >= str.Length)
yield return (new List<string>(cur.Item2) { cur.Item1 }).ToArray();
else {
s.Push(Tuple.Create(cur.Item1 + str[cur.Item3],
new List<string>(cur.Item2), cur.Item3 + 1));
s.Push(Tuple.Create(str[cur.Item3].ToString(),
new List<string>(cur.Item2) { cur.Item1 },
cur.Item3 + 1));
}
}
}
//そのうちrefacter
public List<int[]> gRangedArr(int content, int rangeStart, int rangeEnd) {
var result = new List<int[]>();
_gRangedArr(content - 1, new int[content], result, rangeStart, rangeEnd);
return result;
}
private void _gRangedArr(int n, int[] Arr, List<int[]> result, int rs,
int re) {
if (n < 0) {
result.Add(Arr);
return;
}
for (int i = rs; i <= re; ++i) {
var newArr = Arr.ToArray();
newArr[n] = i;
_gRangedArr(n - 1, newArr, result, rs, re);
}
}
}
#endregion
#region Data
class TreeDis { // TODO:shortestPath
public List<Tuple<long, long>>[] g;
public long[] a2other;
private int type;
public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
g.Length.REP(i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], 1L));
g[b[i]].Add(Tuple.Create(a[i], 1L));
});
}
public void Run(long[] a, long[] b, long[] w) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public long[] a2iArr(long a) {
a2other = new long[g.Count()];
if (type == 0)
BFS(a);
else
DFS(a);
return a2other;
}
private void BFS(long a) {
var q = new Queue<Tuple<long, long>>();
q.Enqueue(Tuple.Create(a, -1L));
while (q.Count > 0) {
var c = q.Dequeue();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
q.Enqueue(Tuple.Create(v.Item1, c.Item1));
}
}
}
private void DFS(long a) {
var s = new Stack<Tuple<long, long>>();
s.Push(Tuple.Create(a, -1L));
while (s.Count > 0) {
var c = s.Pop();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
s.Push(Tuple.Create(v.Item1, c.Item1));
}
}
}
}
class ShortestPath {
protected int I = -1; //辺は1~N
protected int V; //頂点数
protected int E; //辺の数
protected bool isNonDir = true; //有向?
public long INF = (long)1e15; //初期化
public long[] cost; //重み
public List<edge>[] Adj; //隣接リスト
public void Init(int n) {
I = n + 1;
V = n;
Adj = new List<edge>[I];
for (int i = 0; i < I; ++i)
Adj[i] = new List<edge>();
}
public void AddPath(int f, int t, long c = 1) {
E++;
Adj[f].Add(new edge(t, c));
if (isNonDir)
Adj[t].Add(new edge(f, c));
}
public void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i]);
}
public bool PathExist(int t) { return cost[t] != INF; }
}
class Dijkstra : ShortestPath {
public Dijkstra(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
Run(f);
return cost[t];
}
public long MinCost(int t) { return cost[t]; }
public void Run(int f) {
cost = new long[I];
for (int i = 0; i < I; ++i)
cost[i] = INF;
cost[f] = 0;
var pq = new PQueue<edge>();
pq.Enqueue(new edge(f, 0L));
while (!pq.Empty()) {
var cur = pq.Dequeue();
if (cost[cur.to] < cur.cost)
continue;
for (int i = 0; i < Adj[cur.to].Count; ++i) {
var tmp = Adj[cur.to][i];
if (cost[tmp.to] > cur.cost + tmp.cost) {
cost[tmp.to] = cur.cost + tmp.cost;
pq.Enqueue(new edge(tmp.to, cost[tmp.to]));
}
}
}
}
}
class BellmanFord : ShortestPath {
private bool[] neg;
public BellmanFord(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
Run(f);
return cost[t];
}
public long MinCost(int t) { return cost[t]; }
public void Run(int f) {
cost = new long[I];
cost.Set(INF);
cost[f] = 0;
neg = new bool[I];
for (int i = 0; i < I - 1; i++)
for (int j = 0; j < I; ++j)
for (int k = 0; k < Adj[j].Count; ++k) {
var cur = Adj[j][k];
if (cost[cur.to] > cost[j] + cur.cost)
cost[cur.to] = cost[j] + cur.cost;
}
for (int i = 0; i < I; i++)
for (int j = 0; j < I; ++j)
for (int k = 0; k < Adj[j].Count; ++k) {
var cur = Adj[j][k];
if (cost[cur.to] > cost[j] + cur.cost) {
cost[cur.to] = cost[j] + cur.cost;
neg[cur.to] = true;
}
if (neg[j])
neg[cur.to] = true;
}
}
public bool loopExist() { return neg[I - 1]; }
}
class WF : ShortestPath {
public WF() {}
public WF(bool isNonDir) { this.isNonDir = isNonDir; }
public void Run() {}
}
class WarshallFloyd {
private int E;
private bool isNonDir;
public long INF = (long)1e15;
public long[,] BefG;
public long[,] G;
public WarshallFloyd(bool isNonDir = true) { this.isNonDir = isNonDir; }
public void Init(int n) {
E = n + 1;
G = new long[E, E];
BefG = new long[E, E];
for (int i = 0; i < E; ++i)
for (int j = 0; j < E; ++j) {
G[i, j] = INF;
BefG[i, j] = INF;
}
for (int i = 0; i < E; ++i) {
G[i, i] = 0;
BefG[i, i] = 0;
}
}
public void AddPath(int f, int t, long c = 1) {
if (isNonDir) {
G[f, t] = c;
G[t, f] = c;
BefG[f, t] = c;
BefG[t, f] = c;
} else {
G[f, t] = c;
BefG[f, t] = c;
}
}
public void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], 1);
}
public void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void Run() { G = MinCostArr(); }
public long[,] MinCostArr() {
for (int i = 0; i < E; ++i)
for (int j = 0; j < E; ++j)
for (int k = 0; k < E; ++k)
G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]);
return G;
}
//使う?使わない?
public int[] MinPath(int from, int to) {
var ret = new List<int>();
var cur = from;
while (cur != to) {
ret.Add(cur);
for (int i = 1; i < E; ++i) {
if (BefG[cur, i] + G[i, to] == G[cur, to]) {
if (i == cur)
continue;
cur = i;
break;
}
}
}
ret.Add(cur);
return ret.ToArray();
}
public bool isMinPath(int a, int b, long c) {
for (int i = 0; i < E; ++i)
if (G[i, a] + c == G[i, b])
return true;
return false;
}
//全地点間を繋ぐ最小コスト
public long MinCost() {
long orig = 0;
for (int i = 0; i < E; ++i)
for (int j = i + 1; j < E; ++j) {
bool isOrig = true;
for (int k = 0; k < E; ++k) {
if (k == i || k == j)
continue;
if (G[i, j] == G[i, k] + G[k, j]) {
isOrig = false;
break;
}
}
if (isOrig)
orig += G[i, j];
}
return orig;
}
}
class UnionFind {
int[] dat;
public void Init(int n) {
dat = new int[n + 1];
for (int i = 0; i <= n; ++i)
dat[i] = -1;
}
public void Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x == y)
return;
if (dat[y] < dat[x])
swap(ref x, ref y);
dat[x] += dat[y];
dat[y] = x;
}
public bool Find(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return dat[x] < 0 ? x : dat[x] = Root(dat[x]); }
public int Size(int x) { return -dat[Root(x)]; }
void swap(ref int a, ref int b) {
int tmp = b;
b = a;
a = tmp;
}
}
class Kruskal : ShortestPath {
public Kruskal(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long Run() {
var uf = new UnionFind();
var ret = 0L;
var L = new List<Tuple<int, int, long>>();
uf.Init(V);
for (int i = 0; i < I; ++i)
for (int j = 0; j < Adj[i].Count; ++i)
L.Add(Tuple.Create(i, Adj[i][j].to, Adj[i][j].cost));
L = L.OrderBy(t => t.Item3).ToList();
for (int i = 0; i < L.Count; ++i)
if (!uf.Find(L[i].Item1, L[i].Item2)) {
ret += L[i].Item3;
uf.Unite(L[i].Item1, L[i].Item2);
}
return ret;
}
}
#endregion
#region Ex
static class StringEX {
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) { return toInt(c.ToString()); }
public static int toInt(this char[] c) { return toInt(new string(c)); }
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0;
}
public static long toLong(this char c) { return toLong(c.ToString()); }
public static long toLong(this char[] c) { return toLong(new string(c)); }
public static string toString(this char[] c) { return new string(c); }
}
static class NumericEx {
public static string pad0<T>(this T v, int n) {
return v.ToString().PadLeft(n, '0');
}
public static double RoundOff(this double v, int n) {
return Math.Round(v, n - 1, MidpointRounding.AwayFromZero);
}
public static bool Odd(this int v) { return v % 2 != 0; }
public static bool Odd(this long v) { return v % 2 != 0; }
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Sort(a);
Array.Reverse(a);
return a;
}
public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
}
public static int[] toIntArr(this string[] a) {
return Array.ConvertAll(a, int.Parse);
}
public static long[] toLongArr(this string[] a) {
return Array.ConvertAll(a, long.Parse);
}
public static double[] toDoubleArr(this string[] a) {
return Array.ConvertAll(a, double.Parse);
}
public static char[] toCharArr(this string[] a) {
return Array.ConvertAll(a, char.Parse);
}
public static int LowerBound<T>(this T[] a, T x)
where T : IComparable {
Array.Sort(a);
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) >= 0)
ub = mid;
else
lb = mid;
}
return ub;
}
public static int UpperBound<T>(this T[] a, T x)
where T : IComparable {
Array.Sort(a);
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) > 0)
ub = mid;
else
lb = mid;
}
return ub;
}
}
static class BitEx {
public static bool Any(this BitArray b) {
foreach (bool f in b)
if (f)
return true;
return false;
}
public static bool All(this BitArray b) {
foreach (bool f in b)
if (!f)
return false;
return true;
}
public static bool None(this BitArray b) { return !Any(b); }
public static void Flip(this BitArray b, int index) {
b.Set(index, !b.Get(index));
}
}
static class IEnumerableEx {}
static class Test {
public static int add(this int a, int b) { return a + b; }
public static double add(this double a, int b) { return a + b; }
public static double add(this int a, double b) { return a + b; }
public static double add(this double a, double b) { return a + b; }
public static long add(this long a, int b) { return a + b; }
public static long add(this int a, long b) { return a + b; }
public static long add(this long a, long b) { return a + b; }
}
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Program {
class MainClass {
////////////////////////////////////////////////////////////
string S, T;
void Solve() {
io.i(out S, out T);
S = S.Reversed();
T = T.Reversed();
var ans = S.ToCharArray();
var f = new bool[S.Length];
if (T.Length > S.Length) {
io.o("UNRESTORABLE");
return;
}
var flag = true;
for (int i = 0; i < Math.Abs(S.Length - T.Length) + 1; ++i) {
ans = "a".Repeat(S.Length).ToCharArray();
for (int k = 0; k < S.Length; ++k) {
if (S[k] != '?') {
ans[k] = S[k];
}
}
flag = true;
for (int j = 0; j < Math.Min(S.Length, T.Length); ++j) {
if (S[i + j] != T[j]) {
if (S[i + j] == '?') {
ans[i + j] = T[j];
} else {
flag = false;
break;
}
} else {
//
}
}
if (flag)
break;
}
var Ans = ans.toString().Reversed();
if (!flag) {
io.o("UNRESTORABLE");
return;
} else {
for (int i = 0; i < ans.Length; ++i) {
io.or(Ans[i] == '?' ? 'a' : Ans[i]);
}
io.br();
}
}
////////////////////////////////////////////////////////////
public static void Main() { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
// void Stream() { Test(); io.writeFlush(); }
void Test() {}
#region MockMacro
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act) {
for (int i = a; i < b; ++i)
act(i);
}
void FORR(int a, int b, Action<int> act) {
for (int i = a - 1; i >= b; --i)
act(i);
}
#endregion
////////////////////////////////////////////////////////////
}
#region default
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public string[] arr => Console.ReadLine().Split(' ');
public char[] arrChar => Array.ConvertAll(arr, char.Parse);
public int[] arrInt => Array.ConvertAll(arr, int.Parse);
public long[] arrLong => Array.ConvertAll(arr, long.Parse);
public double[] arrDouble => Array.ConvertAll(arr, double.Parse);
public T i<T>() { return suitType<T>(String); }
public void i<T>(out T v) { v = suitType<T>(String); }
public void i<T, U>(out T v1, out U v2) {
i(out v1);
i(out v2);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
i(out v1);
i(out v2);
i(out v3);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
}
public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4,
out X v5) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
i(out v5);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = suitType<T>(String);
}
public void ini<T, U>(out T[] a, out U[] b, int n) {
a = new T[n];
b = new U[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<U>();
}
}
public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) {
a = new T[n];
b = new U[n];
c = new V[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<U>();
c[i] = i<V>();
}
}
public void ini<T, U>(out Tuple<T, U>[] t, int n) {
t = new Tuple<T, U>[n];
for (int j = 0; j < n; ++j) {
T i1;
U i2;
i(out i1);
i(out i2);
t[j] = Tuple.Create(i1, i2);
}
}
public void ini<T, U, V>(out Tuple<T, U, V>[] t, int n) {
t = new Tuple<T, U, V>[n];
for (int j = 0; j < n; ++j) {
T i1;
U i2;
V i3;
i(out i1);
i(out i2);
i(out i3);
t[j] = Tuple.Create(i1, i2, i3);
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
a[i, j] = i<T>();
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); }
public void o<T>(T[,] a) {
int a0 = a.GetLength(0), a1 = a.GetLength(1);
for (int i = 0; i < a0; ++i) {
for (int j = 0; j < a1 - 1; ++j)
Console.Write(a[i, j] + " ");
Console.WriteLine(a[i, a1 - 1]);
}
}
public void YN(bool f) { o(f ? "YES" : "NO"); }
public void Yn(bool f) { o(f ? "Yes" : "No"); }
public void yn(bool f) { o(f ? "yes" : "no"); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void or<T>(T a) { Console.Write(a); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
}
class PQueue<T>
where T : struct, IComparable<T> {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size;
private int type; // type=0->min
public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; }
public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) {
this.comparer = comparer;
}
public PQueue(Comparison<T> comparison) : this(16, comparison) {}
public PQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.comp = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (Compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
public bool Empty() { return !Any(); }
public bool Contains(T v) { return heap.Contains(v); }
private int Compare(T x, T y) {
return type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
}
class AssociativeArray<T> : IEnumerable {
public Dictionary<T, int> dic;
public AssociativeArray() { dic = new Dictionary<T, int>(); }
public AssociativeArray(params T[] a) {
dic = new Dictionary<T, int>();
Add(a);
}
public void Add(T a) {
if (!conK(a))
dic[a] = 0;
dic[a]++;
}
public void Add(params T[] a) {
a.Length.REP(i => {
if (!conK(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
});
}
public void Set(T k, int v) {
if (!dic.ContainsKey(k))
dic[k] = 0;
dic[k] = v;
}
public void Remove(params T[] a) {
a.Length.REP(i => {
if (conK(a[i]))
dic.Remove(a[i]);
});
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValSum => dic.Values.Sum();
public int KeyNum => dic.Keys.Count;
public int MaxVal => dic.Values.Max();
public int MinVal => dic.Values.Min();
public T MaxKey => MaxK();
public T MinKey => MinK();
public T MaxK() {
var maxV = MaxVal;
return dic.First(d => d.Value == maxV).Key;
}
public T MinK() {
var minV = MinVal;
return dic.First(d => d.Value == minV).Key;
}
public T[] MaxKeys() {
var maxV = MaxVal;
return dic.Where(kp => kp.Value == maxV)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public T[] MinKeys() {
var minV = MinVal;
return dic.Where(kp => kp.Value == minV)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public bool conK(T k) { return dic.ContainsKey(k); }
public bool anyK(params T[] k) { return k.Any(key => conK(key)); }
public bool allK(params T[] k) { return k.All(key => conK(key)); }
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
public T[] ValueSortedKey(bool inc = true) {
return (inc ? (dic.OrderBy(kp => kp.Value))
: (dic.OrderByDescending(kp => kp.Value)))
.ThenBy(kp => kp.Key)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public IEnumerator GetEnumerator() {
foreach (var kp in dic)
yield return kp;
}
//:sort->array
}
public struct edge : IComparable<edge> {
public int to;
public long cost;
public edge(int to, long cost) {
this.to = to;
this.cost = cost;
}
public int CompareTo(edge e) { return cost.CompareTo(e.cost); }
}
#endregion
#region test
// interface IField<T> { T Add(T that) ; T Subtract(T that); T
// Multiply(T that); T Devide(T that); }
#endregion
#region other
class Mat {
public long mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long ModC(long n, long r) {
if (r == 0 || n == r)
return 1;
if (n == 0)
return 0;
if (n < 0 || n < r)
throw new ArgumentException("n,r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long[,] C(int N) {
long[,] Co = new long[N + 1, N + 1];
(N + 1).REP(i => (i + 1).REP(j => Co[i, j] =
(j == 0 || j == i)
? 1L
: Co[i - 1, j - 1] + Co[i - 1, j]));
return Co;
}
public long DupC(long n, long r) { return ModC(n + r - 1, r); }
public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test
public bool isPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (long v = 3; v <= (long)Math.Sqrt(n); v += 2)
if (n % v == 0)
return false;
return true;
}
public long LCM(long a, long b) { return a * (b / GCD(a, b)); }
public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); }
public long GCD(long a, long b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public long GCD(params long[] array) {
return array.Aggregate((v, n) => GCD(v, n));
}
public T Max<T>(params T[] a) { return a.Max(); }
public T Min<T>(params T[] a) { return a.Min(); }
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public int mDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public int[] DigArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long DigArr2Num(IEnumerable<int> enu) {
return enu.Aggregate((v, n) => v * 10 + n);
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public long Tousa(long a, long d, long n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, long n) {
return n * (2 * a + (n - 1) * d) / 2;
}
public long[] EnuDivsor(long N) {
var ret = new SortedSet<long>();
for (long i = 1; i * i <= N; i++)
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
return ret.ToArray();
}
public Dictionary<long, long> PrimeFactor(long n) {
var ret = new Dictionary<long, long>();
for (int i = 2; i * i <= n; ++i) {
if (!ret.ContainsKey(i))
ret[i] = 0;
while (n % i == 0) {
++ret[i];
n /= i;
}
}
return ret.Where(kp => kp.Value != 0)
.ToDictionary(kp => kp.Key, kp => kp.Value);
}
public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<List<int>>();
for (int i = Arr.Length - 1; i >= 0; i--)
s.Push(new List<int>() { i });
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use) {
var ret = new List<int>();
cur.ForEach(X => ret.Add(Arr[X]));
yield return ret.ToArray();
} else
for (int i = Arr.Length - 1; i >= 0; i--)
if (!cur.Contains(i))
s.Push(new List<int>(cur) { i });
}
}
public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<List<int>>();
Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] }));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use)
yield return cur.ToArray();
else
Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<string[]> enuPart(string str) {
var s = new Stack<Tuple<string, List<string>, int>>();
s.Push(Tuple.Create(str[0].ToString(), new List<string>(), 1));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item3 >= str.Length)
yield return (new List<string>(cur.Item2) { cur.Item1 }).ToArray();
else {
s.Push(Tuple.Create(cur.Item1 + str[cur.Item3],
new List<string>(cur.Item2), cur.Item3 + 1));
s.Push(Tuple.Create(str[cur.Item3].ToString(),
new List<string>(cur.Item2) { cur.Item1 },
cur.Item3 + 1));
}
}
}
//そのうちrefacter
public List<int[]> gRangedArr(int content, int rangeStart, int rangeEnd) {
var result = new List<int[]>();
_gRangedArr(content - 1, new int[content], result, rangeStart, rangeEnd);
return result;
}
private void _gRangedArr(int n, int[] Arr, List<int[]> result, int rs,
int re) {
if (n < 0) {
result.Add(Arr);
return;
}
for (int i = rs; i <= re; ++i) {
var newArr = Arr.ToArray();
newArr[n] = i;
_gRangedArr(n - 1, newArr, result, rs, re);
}
}
}
#endregion
#region Data
class TreeDis { // TODO:shortestPath
public List<Tuple<long, long>>[] g;
public long[] a2other;
private int type;
public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
g.Length.REP(i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], 1L));
g[b[i]].Add(Tuple.Create(a[i], 1L));
});
}
public void Run(long[] a, long[] b, long[] w) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public long[] a2iArr(long a) {
a2other = new long[g.Count()];
if (type == 0)
BFS(a);
else
DFS(a);
return a2other;
}
private void BFS(long a) {
var q = new Queue<Tuple<long, long>>();
q.Enqueue(Tuple.Create(a, -1L));
while (q.Count > 0) {
var c = q.Dequeue();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
q.Enqueue(Tuple.Create(v.Item1, c.Item1));
}
}
}
private void DFS(long a) {
var s = new Stack<Tuple<long, long>>();
s.Push(Tuple.Create(a, -1L));
while (s.Count > 0) {
var c = s.Pop();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
s.Push(Tuple.Create(v.Item1, c.Item1));
}
}
}
}
class ShortestPath {
protected int I = -1; //辺は1~N
protected int V; //頂点数
protected int E; //辺の数
protected bool isNonDir = true; //有向?
public long INF = (long)1e15; //初期化
public long[] cost; //重み
public List<edge>[] Adj; //隣接リスト
public void Init(int n) {
I = n + 1;
V = n;
Adj = new List<edge>[I];
for (int i = 0; i < I; ++i)
Adj[i] = new List<edge>();
}
public void AddPath(int f, int t, long c = 1) {
E++;
Adj[f].Add(new edge(t, c));
if (isNonDir)
Adj[t].Add(new edge(f, c));
}
public void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i]);
}
public bool PathExist(int t) { return cost[t] != INF; }
}
class Dijkstra : ShortestPath {
public Dijkstra(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
Run(f);
return cost[t];
}
public long MinCost(int t) { return cost[t]; }
public void Run(int f) {
cost = new long[I];
for (int i = 0; i < I; ++i)
cost[i] = INF;
cost[f] = 0;
var pq = new PQueue<edge>();
pq.Enqueue(new edge(f, 0L));
while (!pq.Empty()) {
var cur = pq.Dequeue();
if (cost[cur.to] < cur.cost)
continue;
for (int i = 0; i < Adj[cur.to].Count; ++i) {
var tmp = Adj[cur.to][i];
if (cost[tmp.to] > cur.cost + tmp.cost) {
cost[tmp.to] = cur.cost + tmp.cost;
pq.Enqueue(new edge(tmp.to, cost[tmp.to]));
}
}
}
}
}
class BellmanFord : ShortestPath {
private bool[] neg;
public BellmanFord(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
Run(f);
return cost[t];
}
public long MinCost(int t) { return cost[t]; }
public void Run(int f) {
cost = new long[I];
cost.Set(INF);
cost[f] = 0;
neg = new bool[I];
for (int i = 0; i < I - 1; i++)
for (int j = 0; j < I; ++j)
for (int k = 0; k < Adj[j].Count; ++k) {
var cur = Adj[j][k];
if (cost[cur.to] > cost[j] + cur.cost)
cost[cur.to] = cost[j] + cur.cost;
}
for (int i = 0; i < I; i++)
for (int j = 0; j < I; ++j)
for (int k = 0; k < Adj[j].Count; ++k) {
var cur = Adj[j][k];
if (cost[cur.to] > cost[j] + cur.cost) {
cost[cur.to] = cost[j] + cur.cost;
neg[cur.to] = true;
}
if (neg[j])
neg[cur.to] = true;
}
}
public bool loopExist() { return neg[I - 1]; }
}
class WF : ShortestPath {
public WF() {}
public WF(bool isNonDir) { this.isNonDir = isNonDir; }
public void Run() {}
}
class WarshallFloyd {
private int E;
private bool isNonDir;
public long INF = (long)1e15;
public long[,] BefG;
public long[,] G;
public WarshallFloyd(bool isNonDir = true) { this.isNonDir = isNonDir; }
public void Init(int n) {
E = n + 1;
G = new long[E, E];
BefG = new long[E, E];
for (int i = 0; i < E; ++i)
for (int j = 0; j < E; ++j) {
G[i, j] = INF;
BefG[i, j] = INF;
}
for (int i = 0; i < E; ++i) {
G[i, i] = 0;
BefG[i, i] = 0;
}
}
public void AddPath(int f, int t, long c = 1) {
if (isNonDir) {
G[f, t] = c;
G[t, f] = c;
BefG[f, t] = c;
BefG[t, f] = c;
} else {
G[f, t] = c;
BefG[f, t] = c;
}
}
public void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], 1);
}
public void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void Run() { G = MinCostArr(); }
public long[,] MinCostArr() {
for (int i = 0; i < E; ++i)
for (int j = 0; j < E; ++j)
for (int k = 0; k < E; ++k)
G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]);
return G;
}
//使う?使わない?
public int[] MinPath(int from, int to) {
var ret = new List<int>();
var cur = from;
while (cur != to) {
ret.Add(cur);
for (int i = 1; i < E; ++i) {
if (BefG[cur, i] + G[i, to] == G[cur, to]) {
if (i == cur)
continue;
cur = i;
break;
}
}
}
ret.Add(cur);
return ret.ToArray();
}
public bool isMinPath(int a, int b, long c) {
for (int i = 0; i < E; ++i)
if (G[i, a] + c == G[i, b])
return true;
return false;
}
//全地点間を繋ぐ最小コスト
public long MinCost() {
long orig = 0;
for (int i = 0; i < E; ++i)
for (int j = i + 1; j < E; ++j) {
bool isOrig = true;
for (int k = 0; k < E; ++k) {
if (k == i || k == j)
continue;
if (G[i, j] == G[i, k] + G[k, j]) {
isOrig = false;
break;
}
}
if (isOrig)
orig += G[i, j];
}
return orig;
}
}
class UnionFind {
int[] dat;
public void Init(int n) {
dat = new int[n + 1];
for (int i = 0; i <= n; ++i)
dat[i] = -1;
}
public void Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x == y)
return;
if (dat[y] < dat[x])
swap(ref x, ref y);
dat[x] += dat[y];
dat[y] = x;
}
public bool Find(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return dat[x] < 0 ? x : dat[x] = Root(dat[x]); }
public int Size(int x) { return -dat[Root(x)]; }
void swap(ref int a, ref int b) {
int tmp = b;
b = a;
a = tmp;
}
}
class Kruskal : ShortestPath {
public Kruskal(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long Run() {
var uf = new UnionFind();
var ret = 0L;
var L = new List<Tuple<int, int, long>>();
uf.Init(V);
for (int i = 0; i < I; ++i)
for (int j = 0; j < Adj[i].Count; ++i)
L.Add(Tuple.Create(i, Adj[i][j].to, Adj[i][j].cost));
L = L.OrderBy(t => t.Item3).ToList();
for (int i = 0; i < L.Count; ++i)
if (!uf.Find(L[i].Item1, L[i].Item2)) {
ret += L[i].Item3;
uf.Unite(L[i].Item1, L[i].Item2);
}
return ret;
}
}
#endregion
#region Ex
static class StringEX {
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) { return toInt(c.ToString()); }
public static int toInt(this char[] c) { return toInt(new string(c)); }
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0;
}
public static long toLong(this char c) { return toLong(c.ToString()); }
public static long toLong(this char[] c) { return toLong(new string(c)); }
public static string toString(this char[] c) { return new string(c); }
}
static class NumericEx {
public static string pad0<T>(this T v, int n) {
return v.ToString().PadLeft(n, '0');
}
public static double RoundOff(this double v, int n) {
return Math.Round(v, n - 1, MidpointRounding.AwayFromZero);
}
public static bool Odd(this int v) { return v % 2 != 0; }
public static bool Odd(this long v) { return v % 2 != 0; }
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Sort(a);
Array.Reverse(a);
return a;
}
public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
}
public static int[] toIntArr(this string[] a) {
return Array.ConvertAll(a, int.Parse);
}
public static long[] toLongArr(this string[] a) {
return Array.ConvertAll(a, long.Parse);
}
public static double[] toDoubleArr(this string[] a) {
return Array.ConvertAll(a, double.Parse);
}
public static char[] toCharArr(this string[] a) {
return Array.ConvertAll(a, char.Parse);
}
public static int LowerBound<T>(this T[] a, T x)
where T : IComparable {
Array.Sort(a);
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) >= 0)
ub = mid;
else
lb = mid;
}
return ub;
}
public static int UpperBound<T>(this T[] a, T x)
where T : IComparable {
Array.Sort(a);
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) > 0)
ub = mid;
else
lb = mid;
}
return ub;
}
}
static class BitEx {
public static bool Any(this BitArray b) {
foreach (bool f in b)
if (f)
return true;
return false;
}
public static bool All(this BitArray b) {
foreach (bool f in b)
if (!f)
return false;
return true;
}
public static bool None(this BitArray b) { return !Any(b); }
public static void Flip(this BitArray b, int index) {
b.Set(index, !b.Get(index));
}
}
static class IEnumerableEx {}
static class Test {
public static int add(this int a, int b) { return a + b; }
public static double add(this double a, int b) { return a + b; }
public static double add(this int a, double b) { return a + b; }
public static double add(this double a, double b) { return a + b; }
public static long add(this long a, int b) { return a + b; }
public static long add(this int a, long b) { return a + b; }
public static long add(this long a, long b) { return a + b; }
}
#endregion
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
| 8
| 9,273
| 2
|
using System;
namespace A {
class Program {
static void Main(string[] args) {
Console.WriteLine(Console.ReadLine().Contains("AC") ? "YES" : "NO");
#if DEBUG
Console.ReadLine();
#endif
}
}
}
|
using System;
namespace A {
class Program {
static void Main(string[] args) {
Console.WriteLine(Console.ReadLine().Contains("AC") ? "Yes" : "No");
#if DEBUG
Console.ReadKey();
#endif
}
}
}
|
[["-", 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, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
| 8
| 59
| 6
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
string S = re.s();
for (int i = 0; i < 4; i++) {
if (S[i] == 'A' && S[i + 1] == 'C') {
sb.Append("Yes\n");
return;
}
}
sb.Append("No\n");
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 1000000007; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
string S = re.s();
for (int i = 0; i < S.Length - 1; i++) {
if (S[i] == 'A' && S[i + 1] == 'C') {
sb.Append("Yes\n");
return;
}
}
sb.Append("No\n");
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 1000000007; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 1,736
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
long[] a = Read.longs();
long ans = (long)Math.Pow(3, 10);
long h = 1;
for (int i = 0; i < a.Length; i++) {
if (a[i] % 2 == 0) {
h *= 2;
}
}
Console.WriteLine(ans - h);
}
public static long gcd(long a, long b) {
while (true) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
a -= b;
} else {
b -= a;
}
}
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static bool IsPrime(long n) {
if (n < 2)
return false;
if (n == 2)
return true;
for (long i = 2; i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
}
public static class Read {
public static void outl(string n = "") {
Console.WriteLine(n);
return;
}
public static long Long() { return long.Parse(Console.ReadLine()); }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
long[] a = Read.longs();
long ans = (long)Math.Pow(3, n);
long h = 1;
for (int i = 0; i < a.Length; i++) {
if (a[i] % 2 == 0) {
h *= 2;
}
}
Console.WriteLine(ans - h);
}
public static long gcd(long a, long b) {
while (true) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
a -= b;
} else {
b -= a;
}
}
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static bool IsPrime(long n) {
if (n < 2)
return false;
if (n == 2)
return true;
for (long i = 2; i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
}
public static class Read {
public static void outl(string n = "") {
Console.WriteLine(n);
return;
}
public static long Long() { return long.Parse(Console.ReadLine()); }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
[["-", 0, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 74, 51, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 441
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var S = sc.ReadStr();
var ans = 0;
var l = 0;
var r = S.Length - 1;
while (l >= r) {
if (S[l] == S[r]) {
l++;
r--;
} else if (S[l] == 'x') {
ans++;
l++;
} else if (S[r] == 'x') {
ans++;
r--;
} else {
ans = -1;
break;
}
}
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() {
return Tuple.Create(this.ReadInt(), this.ReadInt());
}
public Tuple<int, int, int> ReadTup3() {
return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt());
}
public Tuple<int, int, int, int> ReadTup4() {
return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt(),
this.ReadInt());
}
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<int, int>[] ReadTupArray(int n) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup();
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3();
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4();
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var S = sc.ReadStr();
var ans = 0;
var l = 0;
var r = S.Length - 1;
while (l <= r) {
if (S[l] == S[r]) {
l++;
r--;
} else if (S[l] == 'x') {
ans++;
l++;
} else if (S[r] == 'x') {
ans++;
r--;
} else {
ans = -1;
break;
}
}
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() {
return Tuple.Create(this.ReadInt(), this.ReadInt());
}
public Tuple<int, int, int> ReadTup3() {
return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt());
}
public Tuple<int, int, int, int> ReadTup4() {
return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt(),
this.ReadInt());
}
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<int, int>[] ReadTupArray(int n) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup();
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3();
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4();
}
return array;
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 962
| 2
|
namespace AtCoder.ABC.CCFQ2017 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.IO;
using AtCoder.ABC.IO;
public class Quest {
public object Solve(Parser parser) {
var s = parser.ScanLine().ToArray();
var left = 0;
var right = s.Length - 1;
int n = 0;
while (left != right) {
char l = s[left];
char r = s[right];
if (l == r) {
left++;
right--;
continue;
}
if (l == 'x') {
left++;
n++;
continue;
} else if (r == 'x') {
right--;
n++;
continue;
}
return -1;
}
return n;
}
}
static class Program {
static void Main(string[] args) {
var i = new Parser(Console.OpenStandardInput());
var o = new Printer(Console.OpenStandardOutput());
var got = new Quest().Solve(i);
o.WriteLine(got);
o.Flush();
}
}
}
namespace AtCoder.ABC.IO {
#region IO
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
public class Parser {
public Parser(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof;
public bool IsEndOfStream {
get { return isEof; }
}
public IEnumerable<Parser> Take(int n) {
return Enumerable.Range(1, n).Select(_ => this);
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture)
: double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
#endregion
}
|
namespace AtCoder.ABC.CCFQ2017 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.IO;
using AtCoder.ABC.IO;
public class Quest {
public object Solve(Parser parser) {
var s = parser.ScanLine().ToArray();
var left = 0;
var right = s.Length - 1;
int n = 0;
while (left < right) {
char l = s[left];
char r = s[right];
if (l == r) {
left++;
right--;
continue;
}
if (l == 'x') {
left++;
n++;
continue;
} else if (r == 'x') {
right--;
n++;
continue;
}
return -1;
}
return n;
}
}
static class Program {
static void Main(string[] args) {
var i = new Parser(Console.OpenStandardInput());
var o = new Printer(Console.OpenStandardOutput());
var got = new Quest().Solve(i);
o.WriteLine(got);
o.Flush();
}
}
}
namespace AtCoder.ABC.IO {
#region IO
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
public class Parser {
public Parser(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof;
public bool IsEndOfStream {
get { return isEof; }
}
public IEnumerable<Parser> Take(int n) {
return Enumerable.Range(1, n).Select(_ => this);
}
private byte read() {
if (isEof)
return 0;
if (ptr < len)
return buf[ptr++];
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) > 0)
return buf[ptr++];
isEof = true;
return 0;
}
public char Char() {
byte b;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (;; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture)
: double.NaN;
}
static T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
#endregion
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18]]
| 8
| 1,076
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
List<char> L = new List<char>();
List<int> Lidx = new List<int>();
for (int i = 0; i < N; i++)
if (S[i] != 'x') {
L.Add(S[i]);
Lidx.Add(i);
}
if (L.Count == 0) {
Console.WriteLine(N % 2);
return;
}
if (!IsPalindromic(L)) {
Console.WriteLine(-1);
return;
}
int NN = L.Count;
int l = NN / 2;
int r = NN / 2;
if (NN % 2 == 0)
l--;
// Console.WriteLine("{0} {1}",l,r);
int ans = 0;
while (l > 0) {
int cl = Lidx[l] - Lidx[l - 1] - 1;
int cr = Lidx[r + 1] - Lidx[r] - 1;
ans += Math.Abs(cl - cr);
l--;
r++;
}
int cl0 = Lidx[l];
int cr0 = N - Lidx[r] - 1;
ans += Math.Abs(cl0 - cr0);
Console.WriteLine(ans);
}
bool IsPalindromic(List<char> L) {
int NN = L.Count;
int l = NN / 2;
int r = NN / 2;
if (NN % 2 == 0)
l--;
while (l >= 0) {
if (L[l] != L[r])
return false;
l--;
r++;
}
return true;
}
int N;
String S;
public Sol() {
S = rs();
N = S.Length;
}
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() {
List<char> L = new List<char>();
List<int> Lidx = new List<int>();
for (int i = 0; i < N; i++)
if (S[i] != 'x') {
L.Add(S[i]);
Lidx.Add(i);
}
if (L.Count == 0) {
Console.WriteLine(0);
return;
}
if (!IsPalindromic(L)) {
Console.WriteLine(-1);
return;
}
int NN = L.Count;
int l = NN / 2;
int r = NN / 2;
if (NN % 2 == 0)
l--;
// Console.WriteLine("{0} {1}",l,r);
int ans = 0;
while (l > 0) {
int cl = Lidx[l] - Lidx[l - 1] - 1;
int cr = Lidx[r + 1] - Lidx[r] - 1;
ans += Math.Abs(cl - cr);
l--;
r++;
}
int cl0 = Lidx[l];
int cr0 = N - Lidx[r] - 1;
ans += Math.Abs(cl0 - cr0);
Console.WriteLine(ans);
}
bool IsPalindromic(List<char> L) {
int NN = L.Count;
int l = NN / 2;
int r = NN / 2;
if (NN % 2 == 0)
l--;
while (l >= 0) {
if (L[l] != L[r])
return false;
l--;
r++;
}
return true;
}
int N;
String S;
public Sol() {
S = rs();
N = S.Length;
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 629
| 4
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml.Schema;
namespace AtCoder {
public class Solver {
private readonly IInputReader _inputReader;
private readonly IOutputWriter _outputWriter;
public Solver(IInputReader inputReader, IOutputWriter outputWriter) {
_inputReader = inputReader;
_outputWriter = outputWriter;
}
public void Solve() {
var (a, b, c) = _inputReader.ReadLine().ToInt3();
if (a == b)
_outputWriter.WriteLine(c.ToString());
if (a == c)
_outputWriter.WriteLine(b.ToString());
_outputWriter.WriteLine(a.ToString());
}
}
public static class Combination {
public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k,
bool withRepetition) {
if (k == 1) {
foreach (var item in items)
yield return new T[] { item };
yield break;
}
foreach (var item in items) {
var leftside = new T[] { item };
// item よりも前のものを除く (順列と組み合わせの違い)
// 重複を許さないので、unusedから item そのものも取り除く
var unused = withRepetition
? items
: items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();
foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
yield return leftside.Concat(rightside).ToArray();
}
}
}
}
internal class Program {
static void Main(string[] args) {
var reader = new ConsoleInputReader();
var writer = new ConsoleOutputWriter();
new Solver(reader, writer).Solve();
}
}
public interface IInputReader {
string ReadLine();
}
public interface IOutputWriter {
void WriteLine(string output);
}
internal class ConsoleInputReader : IInputReader {
public string ReadLine() => Console.ReadLine();
}
internal class ConsoleOutputWriter : IOutputWriter {
public void WriteLine(string output) => Console.WriteLine(output);
}
public static class StringExtensions {
public static char ToChar(this string text) => text[0];
public static string[] ToStringArray(this string text) =>
text.Split(' ').ToArray();
public static int ToInt(this string text) => int.Parse(text);
public static int[] ToIntArray(this string text) =>
text.Split(' ').Select(txt => txt.ToInt()).ToArray();
public static (int, int) ToInt2(this string text) {
var arr = text.ToIntArray();
return (arr[0], arr[1]);
}
public static (int, int, int) ToInt3(this string text) {
var arr = text.ToIntArray();
return (arr[0], arr[1], arr[2]);
}
public static long ToLong(this string text) => long.Parse(text);
public static long[] ToLongArray(this string text) =>
text.Split(' ').Select(txt => txt.ToLong()).ToArray();
public static string
ToJoinedString(this string[] texts,
string separator = "") => string.Join(separator, texts);
public static string ToJoinedString(this char[] chars) => string.Join("",
chars);
public static string ToYESNO(this bool b) => b ? "YES" : "NO";
public static string ToYesNo(this bool b) => b ? "Yes" : "No";
}
public struct ModLong : IEquatable<ModLong> {
private const long Mod = 1000000007;
private readonly long _value;
public ModLong(long value) { _value = (value % Mod + Mod) % Mod; }
public bool Equals(ModLong other) { return _value == other._value; }
public override bool Equals(object obj) {
return obj is ModLong other && Equals(other);
}
public override int GetHashCode() { return _value.GetHashCode(); }
public static bool operator ==(ModLong left, ModLong right) {
return left.Equals(right);
}
public static bool operator !=(ModLong left, ModLong right) {
return !left.Equals(right);
}
public static ModLong operator +(ModLong left, ModLong right) {
return (ModLong)(left._value + right._value);
}
public static ModLong operator -(ModLong left, ModLong right) {
return (ModLong)(left._value - right._value);
}
public static ModLong operator *(ModLong left, ModLong right) {
return (ModLong)(left._value * right._value);
}
public static ModLong operator /(ModLong left, ModLong right) {
return (ModLong)(left._value * Util.ModInv(right._value, Mod));
}
public static explicit operator long(ModLong num) { return num._value; }
public static explicit operator ModLong(long num) { return new ModLong(num); }
public override string ToString() => _value.ToString();
}
public class ModCombination {
private const int Max = 510000;
private const long Mod = 1000000007;
private long[] fac = new long[Max];
private long[] finv = new long[Max];
private long[] inv = new long[Max];
public ModCombination() {
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (var 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;
}
}
/// <summary>
/// mCn 組み合わせ
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public long Combination(long m, long n) {
if (m < n)
return 0;
if (m < 0 || n < 0)
return 0;
return fac[m] * (finv[n] * finv[m - n] % Mod) % Mod;
}
}
public class Util {
/// <summary>
/// a^n mod を計算する
/// </summary>
/// <param name="a"></param>
/// <param name="n"></param>
/// <param name="mod"></param>
/// <returns></returns>
public static long ModPow(long a, long n, long mod) {
long res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = res * a % mod;
}
a = a * a % mod;
n >>= 1;
}
return res;
}
/// <summary>
/// a^{-1} mod を計算する
/// </summary>
/// <param name="a"></param>
/// <param name="mod"></param>
/// <returns></returns>
public static long ModInv(long a, long mod) {
return ModPow(a, mod - 2, mod);
}
/// <summary>
/// 階乗
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static long ModFactional(long n) {
if (n < 0)
throw new ArgumentOutOfRangeException(nameof(n));
ModLong result = (ModLong)1;
for (var i = 1; i <= n; i++) {
result *= (ModLong)i;
}
return (long)result;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml.Schema;
namespace AtCoder {
public class Solver {
private readonly IInputReader _inputReader;
private readonly IOutputWriter _outputWriter;
public Solver(IInputReader inputReader, IOutputWriter outputWriter) {
_inputReader = inputReader;
_outputWriter = outputWriter;
}
public void Solve() {
var (a, b, c) = _inputReader.ReadLine().ToInt3();
if (a == b)
_outputWriter.WriteLine(c.ToString());
else if (a == c)
_outputWriter.WriteLine(b.ToString());
else
_outputWriter.WriteLine(a.ToString());
}
}
public static class Combination {
public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k,
bool withRepetition) {
if (k == 1) {
foreach (var item in items)
yield return new T[] { item };
yield break;
}
foreach (var item in items) {
var leftside = new T[] { item };
// item よりも前のものを除く (順列と組み合わせの違い)
// 重複を許さないので、unusedから item そのものも取り除く
var unused = withRepetition
? items
: items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();
foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
yield return leftside.Concat(rightside).ToArray();
}
}
}
}
internal class Program {
static void Main(string[] args) {
var reader = new ConsoleInputReader();
var writer = new ConsoleOutputWriter();
new Solver(reader, writer).Solve();
}
}
public interface IInputReader {
string ReadLine();
}
public interface IOutputWriter {
void WriteLine(string output);
}
internal class ConsoleInputReader : IInputReader {
public string ReadLine() => Console.ReadLine();
}
internal class ConsoleOutputWriter : IOutputWriter {
public void WriteLine(string output) => Console.WriteLine(output);
}
public static class StringExtensions {
public static char ToChar(this string text) => text[0];
public static string[] ToStringArray(this string text) =>
text.Split(' ').ToArray();
public static int ToInt(this string text) => int.Parse(text);
public static int[] ToIntArray(this string text) =>
text.Split(' ').Select(txt => txt.ToInt()).ToArray();
public static (int, int) ToInt2(this string text) {
var arr = text.ToIntArray();
return (arr[0], arr[1]);
}
public static (int, int, int) ToInt3(this string text) {
var arr = text.ToIntArray();
return (arr[0], arr[1], arr[2]);
}
public static long ToLong(this string text) => long.Parse(text);
public static long[] ToLongArray(this string text) =>
text.Split(' ').Select(txt => txt.ToLong()).ToArray();
public static string
ToJoinedString(this string[] texts,
string separator = "") => string.Join(separator, texts);
public static string ToJoinedString(this char[] chars) => string.Join("",
chars);
public static string ToYESNO(this bool b) => b ? "YES" : "NO";
public static string ToYesNo(this bool b) => b ? "Yes" : "No";
}
public struct ModLong : IEquatable<ModLong> {
private const long Mod = 1000000007;
private readonly long _value;
public ModLong(long value) { _value = (value % Mod + Mod) % Mod; }
public bool Equals(ModLong other) { return _value == other._value; }
public override bool Equals(object obj) {
return obj is ModLong other && Equals(other);
}
public override int GetHashCode() { return _value.GetHashCode(); }
public static bool operator ==(ModLong left, ModLong right) {
return left.Equals(right);
}
public static bool operator !=(ModLong left, ModLong right) {
return !left.Equals(right);
}
public static ModLong operator +(ModLong left, ModLong right) {
return (ModLong)(left._value + right._value);
}
public static ModLong operator -(ModLong left, ModLong right) {
return (ModLong)(left._value - right._value);
}
public static ModLong operator *(ModLong left, ModLong right) {
return (ModLong)(left._value * right._value);
}
public static ModLong operator /(ModLong left, ModLong right) {
return (ModLong)(left._value * Util.ModInv(right._value, Mod));
}
public static explicit operator long(ModLong num) { return num._value; }
public static explicit operator ModLong(long num) { return new ModLong(num); }
public override string ToString() => _value.ToString();
}
public class ModCombination {
private const int Max = 510000;
private const long Mod = 1000000007;
private long[] fac = new long[Max];
private long[] finv = new long[Max];
private long[] inv = new long[Max];
public ModCombination() {
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (var 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;
}
}
/// <summary>
/// mCn 組み合わせ
/// </summary>
/// <param name="m"></param>
/// <param name="n"></param>
/// <returns></returns>
public long Combination(long m, long n) {
if (m < n)
return 0;
if (m < 0 || n < 0)
return 0;
return fac[m] * (finv[n] * finv[m - n] % Mod) % Mod;
}
}
public class Util {
/// <summary>
/// a^n mod を計算する
/// </summary>
/// <param name="a"></param>
/// <param name="n"></param>
/// <param name="mod"></param>
/// <returns></returns>
public static long ModPow(long a, long n, long mod) {
long res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = res * a % mod;
}
a = a * a % mod;
n >>= 1;
}
return res;
}
/// <summary>
/// a^{-1} mod を計算する
/// </summary>
/// <param name="a"></param>
/// <param name="mod"></param>
/// <returns></returns>
public static long ModInv(long a, long mod) {
return ModPow(a, mod - 2, mod);
}
/// <summary>
/// 階乗
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static long ModFactional(long n) {
if (n < 0)
throw new ArgumentOutOfRangeException(nameof(n));
ModLong result = (ModLong)1;
for (var i = 1; i <= n; i++) {
result *= (ModLong)i;
}
return (long)result;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
| 8
| 1,429
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B {
class Program {
static void Main(string[] args) {
long[] L = new long[100];
L[0] = 2;
L[1] = 1;
for (int i = 2; i < 86; i++) {
L[i] = L[i - 1] + L[i - 2];
}
Console.WriteLine(L[int.Parse(Console.ReadLine())]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace B {
class Program {
static void Main(string[] args) {
long[] L = new long[100];
L[0] = 2;
L[1] = 1;
for (int i = 2; i < 89; i++) {
L[i] = L[i - 1] + L[i - 2];
}
Console.WriteLine(L[int.Parse(Console.ReadLine())]);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 125
| 2
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace FertiLib.Contest.C {
static class Program {
public static void Solve(Scanner cin) {
var a = cin.ReadString().Select(x => int.Parse(x.ToString())).ToArray();
for (int i = 0; i < 1; i++) {
for (int j = 0; j < 1; j++) {
for (int k = 0; k < 1; k++) {
int ans = a[0];
if (i == 0)
ans += a[1];
else
ans -= a[1];
if (j == 0)
ans += a[2];
else
ans -= a[2];
if (k == 0)
ans += a[3];
else
ans -= a[3];
if (ans == 7) {
Console.WriteLine(
$"{a[0]}{(i == 0 ? "+" : "-")}{a[1]}{(j == 0 ? "+" : "-")}{a[2]}{(k == 0 ? "+" : "-")}{a[3]}=7");
return;
}
}
}
}
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
Solve(cin);
Console.Out.Flush();
}
public static void
YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO");
public static void
YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No");
public static void
yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no");
public static bool Chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) >= 0)
return false;
a = b;
return true;
}
public static bool Chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) <= 0)
return false;
a = b;
return true;
}
}
static class Util {
public static string
Join<T>(this IEnumerable<T> x,
string separator = "") => string.Join(separator, x);
}
class Scanner {
string[] s;
int i;
char[] separator = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Read() => ReadString();
public string ReadString() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return ReadString();
i = 0;
return s[i++];
}
public string[] ReadStringArray(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadString();
}
return Array;
}
public int ReadInt() { return int.Parse(ReadString()); }
public int[] ReadIntArray(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadInt() + add;
}
return Array;
}
public long ReadLong() { return long.Parse(ReadString()); }
public long[] ReadLongArray(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadLong() + add;
}
return Array;
}
public double ReadDouble() { return double.Parse(ReadString()); }
public double[] ReadDoubleArray(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadDouble() + add;
}
return Array;
}
public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(),
typeof(T1));
public (T1, T2) ReadValue<T1, T2>() {
var inputs = ReadStringArray(2);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
return (v1, v2);
}
public (T1, T2, T3) ReadValue<T1, T2, T3>() {
var inputs = ReadStringArray(3);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
return (v1, v2, v3);
}
public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var inputs = ReadStringArray(4);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
return (v1, v2, v3, v4);
}
public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var inputs = ReadStringArray(5);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
return (v1, v2, v3, v4, v5);
}
public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() {
var inputs = ReadStringArray(6);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
return (v1, v2, v3, v4, v5, v6);
}
public (T1, T2, T3, T4, T5, T6,
T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() {
var inputs = ReadStringArray(7);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7));
return (v1, v2, v3, v4, v5, v6, v7);
}
public T1[] ReadValueArray<T1>(int N) {
var v1 = new T1[N];
for (int i = 0; i < N; i++) {
v1[i] = ReadValue<T1>();
}
return v1;
}
public (T1[], T2[]) ReadValueArray<T1, T2>(int N) {
var (v1, v2) = (new T1[N], new T2[N]);
for (int i = 0; i < N; i++) {
var (t1, t2) = ReadValue<T1, T2>();
v1[i] = t1;
v2[i] = t2;
}
return (v1, v2);
}
public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) {
var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3) = ReadValue<T1, T2, T3>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
}
return (v1, v2, v3);
}
public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) {
var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
}
return (v1, v2, v3, v4);
}
public (T1[], T2[], T3[], T4[],
T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) {
var (v1, v2, v3, v4, v5) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
}
return (v1, v2, v3, v4, v5);
}
public (T1[], T2[], T3[], T4[], T5[],
T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) {
var (v1, v2, v3, v4, v5, v6) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
}
return (v1, v2, v3, v4, v5, v6);
}
public (T1[], T2[], T3[], T4[], T5[], T6[],
T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) {
var (v1, v2, v3, v4, v5, v6, v7) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N],
new T7[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6, t7) =
ReadValue<T1, T2, T3, T4, T5, T6, T7>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
v7[i] = t7;
}
return (v1, v2, v3, v4, v5, v6, v7);
}
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace FertiLib.Contest.C {
static class Program {
public static void Solve(Scanner cin) {
var a = cin.ReadString().Select(x => int.Parse(x.ToString())).ToArray();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
int ans = a[0];
if (i == 0)
ans += a[1];
else
ans -= a[1];
if (j == 0)
ans += a[2];
else
ans -= a[2];
if (k == 0)
ans += a[3];
else
ans -= a[3];
if (ans == 7) {
Console.WriteLine(
$"{a[0]}{(i == 0 ? "+" : "-")}{a[1]}{(j == 0 ? "+" : "-")}{a[2]}{(k == 0 ? "+" : "-")}{a[3]}=7");
return;
}
}
}
}
}
public static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var cin = new Scanner();
Solve(cin);
Console.Out.Flush();
}
public static void
YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO");
public static void
YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No");
public static void
yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no");
public static bool Chmax<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) >= 0)
return false;
a = b;
return true;
}
public static bool Chmin<T>(ref T a, T b)
where T : IComparable<T> {
if (a.CompareTo(b) <= 0)
return false;
a = b;
return true;
}
}
static class Util {
public static string
Join<T>(this IEnumerable<T> x,
string separator = "") => string.Join(separator, x);
}
class Scanner {
string[] s;
int i;
char[] separator = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string Read() => ReadString();
public string ReadString() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return ReadString();
i = 0;
return s[i++];
}
public string[] ReadStringArray(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadString();
}
return Array;
}
public int ReadInt() { return int.Parse(ReadString()); }
public int[] ReadIntArray(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadInt() + add;
}
return Array;
}
public long ReadLong() { return long.Parse(ReadString()); }
public long[] ReadLongArray(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadLong() + add;
}
return Array;
}
public double ReadDouble() { return double.Parse(ReadString()); }
public double[] ReadDoubleArray(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = ReadDouble() + add;
}
return Array;
}
public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(),
typeof(T1));
public (T1, T2) ReadValue<T1, T2>() {
var inputs = ReadStringArray(2);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
return (v1, v2);
}
public (T1, T2, T3) ReadValue<T1, T2, T3>() {
var inputs = ReadStringArray(3);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
return (v1, v2, v3);
}
public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() {
var inputs = ReadStringArray(4);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
return (v1, v2, v3, v4);
}
public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() {
var inputs = ReadStringArray(5);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
return (v1, v2, v3, v4, v5);
}
public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() {
var inputs = ReadStringArray(6);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
return (v1, v2, v3, v4, v5, v6);
}
public (T1, T2, T3, T4, T5, T6,
T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() {
var inputs = ReadStringArray(7);
var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1));
var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2));
var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3));
var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4));
var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5));
var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6));
var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7));
return (v1, v2, v3, v4, v5, v6, v7);
}
public T1[] ReadValueArray<T1>(int N) {
var v1 = new T1[N];
for (int i = 0; i < N; i++) {
v1[i] = ReadValue<T1>();
}
return v1;
}
public (T1[], T2[]) ReadValueArray<T1, T2>(int N) {
var (v1, v2) = (new T1[N], new T2[N]);
for (int i = 0; i < N; i++) {
var (t1, t2) = ReadValue<T1, T2>();
v1[i] = t1;
v2[i] = t2;
}
return (v1, v2);
}
public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) {
var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3) = ReadValue<T1, T2, T3>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
}
return (v1, v2, v3);
}
public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) {
var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
}
return (v1, v2, v3, v4);
}
public (T1[], T2[], T3[], T4[],
T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) {
var (v1, v2, v3, v4, v5) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
}
return (v1, v2, v3, v4, v5);
}
public (T1[], T2[], T3[], T4[], T5[],
T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) {
var (v1, v2, v3, v4, v5, v6) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
}
return (v1, v2, v3, v4, v5, v6);
}
public (T1[], T2[], T3[], T4[], T5[], T6[],
T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) {
var (v1, v2, v3, v4, v5, v6, v7) =
(new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N],
new T7[N]);
for (int i = 0; i < N; i++) {
var (t1, t2, t3, t4, t5, t6, t7) =
ReadValue<T1, T2, T3, T4, T5, T6, T7>();
v1[i] = t1;
v2[i] = t2;
v3[i] = t3;
v4[i] = t4;
v5[i] = t5;
v6[i] = t6;
v7[i] = t7;
}
return (v1, v2, v3, v4, v5, v6, v7);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203]]
| 8
| 2,854
| 6
|
using System;
using System.Linq;
namespace Library {}
namespace AtCoder {
using Library;
class ABC079_C {
static bool Solve(int n, string Str, long sum, long[] input) {
if (n == 3) {
if (sum == 7)
Console.WriteLine(Str + "=7");
return true;
} else {
return Solve(n + 1, Str + "+" + input[n + 1].ToString(),
sum + input[n + 1], input) ||
Solve(n + 1, Str + "-" + input[n + 1].ToString(),
sum - input[n + 1], input);
}
}
static void Main(string[] args) {
long[] input =
Console.ReadLine().Select(i => long.Parse(i.ToString())).ToArray();
Solve(0, input[0].ToString(), input[0], input);
}
}
}
|
using System;
using System.Linq;
namespace Library {}
namespace AtCoder {
using Library;
class ABC079_C {
static bool Solve(int n, string Str, long sum, long[] input) {
if (n == 3) {
if (sum == 7) {
Console.WriteLine(Str + "=7");
return true;
} else
return false;
} else {
return Solve(n + 1, Str + "+" + input[n + 1].ToString(),
sum + input[n + 1], input) ||
Solve(n + 1, Str + "-" + input[n + 1].ToString(),
sum - input[n + 1], input);
}
}
static void Main(string[] args) {
long[] input =
Console.ReadLine().Select(i => long.Parse(i.ToString())).ToArray();
Solve(0, input[0].ToString(), input[0], input);
}
}
}
|
[["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 37, 0, 38], ["+", 64, 196, 0, 57, 75, 37, 0, 211, 0, 147]]
| 8
| 208
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var ABCD = Console.ReadLine();
for (var i = 0; i < 8; i++) {
int ans = int.Parse(ABCD[0].ToString());
var ansStr = $"{ABCD[0]}";
for (var k = 1; k < 4; k++) {
if ((i & (1 << k)) == 0) {
ans += int.Parse(ABCD[k].ToString());
ansStr += $"+{ABCD[k]}";
} else {
ans -= int.Parse(ABCD[k].ToString());
ansStr += $"-{ABCD[k]}";
}
}
if (ans == 7) {
Console.WriteLine($"{ansStr}=7");
return;
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var ABCD = Console.ReadLine();
for (var i = 0; i < 8; i++) {
int ans = int.Parse(ABCD[0].ToString());
var ansStr = $"{ABCD[0]}";
for (var k = 1; k < 4; k++) {
if ((i & (1 << (k - 1))) == 0) {
ans += int.Parse(ABCD[k].ToString());
ansStr += $"+{ABCD[k]}";
} else {
ans -= int.Parse(ABCD[k].ToString());
ansStr += $"-{ABCD[k]}";
}
}
if (ans == 7) {
Console.WriteLine($"{ansStr}=7");
return;
}
}
}
}
}
|
[["+", 0, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
| 8
| 223
| 4
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
string abcd = Console.ReadLine();
int a = int.Parse(abcd[0].ToString());
int c = int.Parse(abcd[1].ToString());
int b = int.Parse(abcd[2].ToString());
int d = int.Parse(abcd[3].ToString());
StringBuilder ans = new StringBuilder("");
var op1 = "";
var op2 = "";
var op3 = "";
if (a + b + c + d == 7) {
op1 = "+";
op2 = "+";
op3 = "+";
}
if (a + b - c + d == 7) {
op1 = "+";
op2 = "-";
op3 = "+";
}
if (a + b - c - d == 7) {
op1 = "+";
op2 = "-";
op3 = "-";
}
if (a + b + c - d == 7) {
op1 = "+";
op2 = "+";
op3 = "-";
}
if (a - b + c + d == 7) {
op1 = "-";
op2 = "+";
op3 = "+";
}
if (a - b - c + d == 7) {
op1 = "-";
op2 = "-";
op3 = "+";
}
if (a - b - c - d == 7) {
op1 = "-";
op2 = "-";
op3 = "-";
}
if (a - b + c - d == 7) {
op1 = "-";
op2 = "+";
op3 = "-";
}
ans.Append(a);
ans.Append(op1);
ans.Append(b);
ans.Append(op2);
ans.Append(c);
ans.Append(op3);
ans.Append(d);
ans.Append("=7");
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
string abcd = Console.ReadLine();
int a = int.Parse(abcd[0].ToString());
int b = int.Parse(abcd[1].ToString());
int c = int.Parse(abcd[2].ToString());
int d = int.Parse(abcd[3].ToString());
StringBuilder ans = new StringBuilder("");
var op1 = "";
var op2 = "";
var op3 = "";
if (a + b + c + d == 7) {
op1 = "+";
op2 = "+";
op3 = "+";
}
if (a + b - c + d == 7) {
op1 = "+";
op2 = "-";
op3 = "+";
}
if (a + b - c - d == 7) {
op1 = "+";
op2 = "-";
op3 = "-";
}
if (a + b + c - d == 7) {
op1 = "+";
op2 = "+";
op3 = "-";
}
if (a - b + c + d == 7) {
op1 = "-";
op2 = "+";
op3 = "+";
}
if (a - b - c + d == 7) {
op1 = "-";
op2 = "-";
op3 = "+";
}
if (a - b - c - d == 7) {
op1 = "-";
op2 = "-";
op3 = "-";
}
if (a - b + c - d == 7) {
op1 = "-";
op2 = "+";
op3 = "-";
}
ans.Append(a);
ans.Append(op1);
ans.Append(b);
ans.Append(op2);
ans.Append(c);
ans.Append(op3);
ans.Append(d);
ans.Append("=7");
Console.WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22]]
| 8
| 467
| 4
|
using System;
namespace C___Train_Ticket {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine();
var a = int.Parse(input[0].ToString());
var b = int.Parse(input[1].ToString());
var c = int.Parse(input[2].ToString());
var d = int.Parse(input[3].ToString());
if (a + b + c + d == 7)
Console.WriteLine($"{a}+{b}+{c}+{d}=7");
else if (a + b + c - d == 7)
Console.WriteLine($"{a}+{b}+{c}-{d}=7");
else if (a + b - c + d == 7)
Console.WriteLine($"{a}+{b}-{c}-{d}=7");
else if (a - b + c + d == 7)
Console.WriteLine($"{a}-{b}+{c}+{d}=7");
else if (a - b - c + d == 7)
Console.WriteLine($"{a}-{b}-{c}+{d}=7");
else if (a + b - c - d == 7)
Console.WriteLine($"{a}+{b}-{c}-{d}=7");
else if (a - b + c - d == 7)
Console.WriteLine($"{a}-{b}+{c}-{d}=7");
else if (a - b - c - d == 7)
Console.WriteLine($"{a}-{b}-{c}-{d}=7");
}
}
}
|
using System;
namespace C___Train_Ticket {
class Program {
static void Main(string[] args) {
var input = Console.ReadLine();
var a = int.Parse(input[0].ToString());
var b = int.Parse(input[1].ToString());
var c = int.Parse(input[2].ToString());
var d = int.Parse(input[3].ToString());
if (a + b + c + d == 7)
Console.WriteLine($"{a}+{b}+{c}+{d}=7");
else if (a + b + c - d == 7)
Console.WriteLine($"{a}+{b}+{c}-{d}=7");
else if (a + b - c + d == 7)
Console.WriteLine($"{a}+{b}-{c}+{d}=7");
else if (a - b + c + d == 7)
Console.WriteLine($"{a}-{b}+{c}+{d}=7");
else if (a - b - c + d == 7)
Console.WriteLine($"{a}-{b}-{c}+{d}=7");
else if (a + b - c - d == 7)
Console.WriteLine($"{a}+{b}-{c}-{d}=7");
else if (a - b + c - d == 7)
Console.WriteLine($"{a}-{b}+{c}-{d}=7");
else if (a - b - c - d == 7)
Console.WriteLine($"{a}-{b}-{c}-{d}=7");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296]]
| 8
| 394
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static string S;
static void INPUT() { S = NextString(); }
static void OUT() {
var t = S.ToCharArray().Select(__ => __ - '0').ToArray();
for (var b = 0; b < 8; b++) {
var a = t[0];
for (var i = 1; i <= 3; i++) {
a += (b >> i) % 2 == 0 ? t[i] : -t[i];
}
if (a == 7) {
var sb = new StringBuilder();
sb.Append(t[0]);
for (var i = 1; i <= 3; i++) {
sb.Append((b >> i) % 2 == 0 ? "+" : "-");
sb.Append(t[i]);
}
sb.Append("=7");
Console.WriteLine(sb.ToString());
return;
}
}
}
static void Main(string[] args) {
#if DEBUG
TESTINPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() { S = "1222"; }
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using static Input;
using static Util;
class Program {
static string S;
static void INPUT() { S = NextString(); }
static void OUT() {
var t = S.ToCharArray().Select(__ => __ - '0').ToArray();
for (var b = 0; b < 8; b++) {
var a = t[0];
for (var i = 1; i <= 3; i++) {
a += (b >> i - 1) % 2 == 0 ? t[i] : -t[i];
}
if (a == 7) {
var sb = new StringBuilder();
sb.Append(t[0]);
for (var i = 1; i <= 3; i++) {
sb.Append((b >> i - 1) % 2 == 0 ? "+" : "-");
sb.Append(t[i]);
}
sb.Append("=7");
Console.WriteLine(sb.ToString());
return;
}
}
}
static void Main(string[] args) {
#if DEBUG
TESTINPUT();
#else
INPUT();
#endif
OUT();
}
static void TESTINPUT() { S = "1222"; }
}
public class Input {
public const long MOD = 1000000007;
public const int INF = 1000000007;
private static Queue<string> q = new Queue<string>();
private static void Confirm() {
if (q.Count == 0)
foreach (var s in Console.ReadLine().Split(' '))
q.Enqueue(s);
}
public static int NextInt() {
Confirm();
return int.Parse(q.Dequeue());
}
public static long NextLong() {
Confirm();
return long.Parse(q.Dequeue());
}
public static string NextString() {
Confirm();
return q.Dequeue();
}
public static double NextDouble() {
Confirm();
return double.Parse(q.Dequeue());
}
public static int[] LineInt() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public static long[] LineLong() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
public static string[] LineString() {
return Console.ReadLine().Split(' ').ToArray();
}
public static double[] LineDouble() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
}
}
class Util {}
|
[["+", 31, 16, 31, 23, 0, 16, 12, 16, 17, 33], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 12, 203]]
| 8
| 599
| 4
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
int a = int.Parse(str.Substring(0, 1));
int b = int.Parse(str.Substring(1, 1));
int c = int.Parse(str.Substring(2, 1));
int d = int.Parse(str.Substring(3, 1));
string op1 = "";
string op2 = "";
string op3 = "";
for (int i = 0; i < 2; i++) {
int tmp = a;
if (i % 2 == 0) {
tmp += b;
op1 = "+";
} else {
tmp -= b;
op1 = "-";
}
for (int j = 0; j < 2; j++) {
if (j % 2 == 0) {
tmp += c;
op2 = "+";
} else {
tmp -= c;
op2 = "-";
}
if (tmp + d == 7) {
op3 = "+";
} else if (tmp - d == 7) {
op3 = "-";
} else
continue;
Console.WriteLine(a + op1 + b + op2 + c + op3 + d + "=7");
return;
}
}
}
}
}
|
using System;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
int a = int.Parse(str.Substring(0, 1));
int b = int.Parse(str.Substring(1, 1));
int c = int.Parse(str.Substring(2, 1));
int d = int.Parse(str.Substring(3, 1));
string op1 = "";
string op2 = "";
string op3 = "";
for (int i = 0; i < 2; i++) {
int tmp = a;
if (i % 2 == 0) {
tmp += b;
op1 = "+";
} else {
tmp -= b;
op1 = "-";
}
for (int j = 0; j < 2; j++) {
if (j % 2 == 0) {
tmp += c;
op2 = "+";
} else {
tmp -= 2 * c;
op2 = "-";
}
if (tmp + d == 7) {
op3 = "+";
} else if (tmp - d == 7) {
op3 = "-";
} else
continue;
Console.WriteLine(a + op1 + b + op2 + c + op3 + d + "=7");
return;
}
}
}
}
}
|
[["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 48]]
| 8
| 281
| 2
|
using System;
namespace ABC079_C_Train_Ticket {
internal class Program {
public static void Main(string[] args) {
string input = Console.ReadLine();
int a = int.Parse(input.Substring(0, 1));
int b = int.Parse(input.Substring(1, 1));
int c = int.Parse(input.Substring(2, 1));
int d = int.Parse(input.Substring(3, 1));
if (b + c + d == 7 - a) {
Console.WriteLine(a + "+" + b + "+" + c + "+" + d + "=" + 7);
} else if (-b + c + d == 7 - a) {
Console.WriteLine(a + "-" + b + "+" + c + "+" + d + "=" + 7);
} else if (-b - c + d == 7 - a) {
Console.WriteLine(a + "-" + b + "-" + c + "+" + d + "=" + 7);
} else if (-b - c - d == 7 - a) {
Console.WriteLine(a + "-" + b + "-" + c + "-" + d + "=" + 7);
} else if (-b + c - d == 7 - a) {
Console.WriteLine(a + "-" + b + "+" + c + "-" + d + "=" + 7);
} else if (b - c + d == 7 - a) {
Console.WriteLine(a + "+" + b + "-" + c + "+" + d + "=" + 7);
} else if (b - c - d == 7 - a) {
Console.WriteLine(a + "+" + b + "-" + c + "-" + d + "=" + 7);
} else if (b + c - d == 7 - a) {
Console.WriteLine(a + "+" + b + "+" + c + "-1" + d + "=" + 7);
}
}
}
}
|
using System;
namespace ABC079_C_Train_Ticket {
internal class Program {
public static void Main(string[] args) {
string input = Console.ReadLine();
int a = int.Parse(input.Substring(0, 1));
int b = int.Parse(input.Substring(1, 1));
int c = int.Parse(input.Substring(2, 1));
int d = int.Parse(input.Substring(3, 1));
if (b + c + d == 7 - a) {
Console.WriteLine(a + "+" + b + "+" + c + "+" + d + "=" + 7);
} else if (-b + c + d == 7 - a) {
Console.WriteLine(a + "-" + b + "+" + c + "+" + d + "=" + 7);
} else if (-b - c + d == 7 - a) {
Console.WriteLine(a + "-" + b + "-" + c + "+" + d + "=" + 7);
} else if (-b - c - d == 7 - a) {
Console.WriteLine(a + "-" + b + "-" + c + "-" + d + "=" + 7);
} else if (-b + c - d == 7 - a) {
Console.WriteLine(a + "-" + b + "+" + c + "-" + d + "=" + 7);
} else if (b - c + d == 7 - a) {
Console.WriteLine(a + "+" + b + "-" + c + "+" + d + "=" + 7);
} else if (b - c - d == 7 - a) {
Console.WriteLine(a + "+" + b + "-" + c + "-" + d + "=" + 7);
} else if (b + c - d == 7 - a) {
Console.WriteLine(a + "+" + b + "+" + c + "-" + d + "=" + 7);
}
}
}
}
|
[["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 222], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 222]]
| 8
| 472
| 2
|
using System;
using System.Linq;
namespace ABC079 {
class C {
static void Main(string[] args) {
var length = 4;
var s = Console.ReadLine();
var ABCD = s.Select(c => int.Parse(c.ToString())).ToArray();
var bits = (1 << (length - 1));
for (int i = 0; i < bits; i++) {
var sum = ABCD[0];
for (int j = 0; j < length - 1; j++)
if ((1 & (i >> (length - 2 - j))) == 1)
sum += ABCD[j + 1];
else
sum -= ABCD[j + 1];
if (sum == 7) {
var ans = ABCD[0].ToString();
for (int j = 0; j < length - 1; j++) {
if ((1 & (i >> (length - 2 - j))) == 1)
ans += "+" + ABCD[j + 1].ToString();
else
ans += "-" + ABCD[j + 1].ToString();
}
Console.WriteLine(ans);
return;
}
}
}
}
}
|
using System;
using System.Linq;
namespace ABC079 {
class C {
static void Main(string[] args) {
var length = 4;
var s = Console.ReadLine();
var ABCD = s.Select(c => int.Parse(c.ToString())).ToArray();
var bits = (1 << (length - 1));
for (int i = 0; i < bits; i++) {
var sum = ABCD[0];
for (int j = 0; j < length - 1; j++)
if ((1 & (i >> (length - 2 - j))) == 1)
sum += ABCD[j + 1];
else
sum -= ABCD[j + 1];
if (sum == 7) {
var ans = ABCD[0].ToString();
for (int j = 0; j < length - 1; j++) {
if ((1 & (i >> (length - 2 - j))) == 1)
ans += "+" + ABCD[j + 1].ToString();
else
ans += "-" + ABCD[j + 1].ToString();
}
ans += "=7";
Console.WriteLine(ans);
return;
}
}
}
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 260
| 6
|
using System;
namespace ABC097_C {
class Program {
static void Main(string[] args) {
var N = Console.ReadLine();
var A = int.Parse(N[0].ToString());
var B = int.Parse(N[1].ToString());
var C = int.Parse(N[2].ToString());
var D = int.Parse(N[3].ToString());
var s = "";
if (A + B + C + D == 7)
s = A + "+" + B + "+" + C + "+" + D + "=7";
if (A - B + C + D == 7)
s = A + "-" + B + "+" + C + "+" + D + "=7";
if (A + B - C + D == 7)
s = A + "+" + B + "-" + C + "+" + D + "=7";
if (A + B + C - D == 7)
s = A + "+" + B + "+" + C + "-" + D + "=7";
if (A - B - C + D == 7)
s = A + "-" + B + "-" + C + "-" + D + "=7";
if (A - B + C - D == 7)
s = A + "-" + B + "+" + C + "-" + D + "=7";
if (A + B - C - D == 7)
s = A + "+" + B + "-" + C + "-" + D + "=7";
if (A - B - C - D == 7)
s = A + "-" + B + "-" + C + "-" + D + "=7";
Console.WriteLine(s);
}
}
}
|
using System;
namespace ABC097_C {
class Program {
static void Main(string[] args) {
var N = Console.ReadLine();
var A = int.Parse(N[0].ToString());
var B = int.Parse(N[1].ToString());
var C = int.Parse(N[2].ToString());
var D = int.Parse(N[3].ToString());
var s = "";
if (A + B + C + D == 7)
s = A + "+" + B + "+" + C + "+" + D + "=7";
if (A - B + C + D == 7)
s = A + "-" + B + "+" + C + "+" + D + "=7";
if (A + B - C + D == 7)
s = A + "+" + B + "-" + C + "+" + D + "=7";
if (A + B + C - D == 7)
s = A + "+" + B + "+" + C + "-" + D + "=7";
if (A - B - C + D == 7)
s = A + "-" + B + "-" + C + "+" + D + "=7";
if (A - B + C - D == 7)
s = A + "-" + B + "+" + C + "-" + D + "=7";
if (A + B - C - D == 7)
s = A + "+" + B + "-" + C + "-" + D + "=7";
if (A - B - C - D == 7)
s = A + "-" + B + "-" + C + "-" + D + "=7";
Console.WriteLine(s);
}
}
}
|
[["-", 12, 16, 31, 16, 31, 16, 12, 5, 0, 222], ["+", 12, 16, 31, 16, 31, 16, 12, 5, 0, 222]]
| 8
| 416
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC79 {
class Program {
static void Main(string[] args) {
var a =
Console.ReadLine().Select(c => (int)Char.GetNumericValue(c)).ToArray();
if (a[0] + a[1] + a[2] + a[3] == 7)
Console.WriteLine($"{a[0]}+{a[1]}+{a[2]}+{a[3]}=7");
else if (a[0] + a[1] + a[2] - a[3] == 7)
Console.WriteLine($"{a[0]}+{a[1]}+{a[2]}-{a[3]}=7");
else if (a[0] + a[1] - a[2] + a[3] == 7)
Console.WriteLine($"{a[0]}+{a[1]}-{a[2]}+{a[3]}=7");
else if (a[0] + a[1] - a[2] - a[3] == 7)
Console.WriteLine($"{a[0]}+{a[1]}-{a[2]}-{a[3]}=7");
else if (a[0] - a[1] + a[2] + a[3] == 7)
Console.WriteLine($"{a[0]}-{a[1]}+{a[2]}+{a[3]}=7");
else if (a[0] - a[1] + a[2] - a[3] == 7)
Console.WriteLine($"{a[0]}-{a[1]}+{a[2]}+{a[3]}=7");
else if (a[0] - a[1] - a[2] + a[3] == 7)
Console.WriteLine($"{a[0]}-{a[1]}-{a[2]}+{a[3]}=7");
else if (a[0] - a[1] - a[2] - a[3] == 7)
Console.WriteLine($"{a[0]}-{a[1]}-{a[2]}-{a[3]}=7");
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC79 {
class Program {
static void Main(string[] args) {
var a =
Console.ReadLine().Select(c => (int)Char.GetNumericValue(c)).ToArray();
if (a[0] + a[1] + a[2] + a[3] == 7)
Console.WriteLine($"{a[0]}+{a[1]}+{a[2]}+{a[3]}=7");
else if (a[0] + a[1] + a[2] - a[3] == 7)
Console.WriteLine($"{a[0]}+{a[1]}+{a[2]}-{a[3]}=7");
else if (a[0] + a[1] - a[2] + a[3] == 7)
Console.WriteLine($"{a[0]}+{a[1]}-{a[2]}+{a[3]}=7");
else if (a[0] + a[1] - a[2] - a[3] == 7)
Console.WriteLine($"{a[0]}+{a[1]}-{a[2]}-{a[3]}=7");
else if (a[0] - a[1] + a[2] + a[3] == 7)
Console.WriteLine($"{a[0]}-{a[1]}+{a[2]}+{a[3]}=7");
else if (a[0] - a[1] + a[2] - a[3] == 7)
Console.WriteLine($"{a[0]}-{a[1]}+{a[2]}-{a[3]}=7");
else if (a[0] - a[1] - a[2] + a[3] == 7)
Console.WriteLine($"{a[0]}-{a[1]}-{a[2]}+{a[3]}=7");
else if (a[0] - a[1] - a[2] - a[3] == 7)
Console.WriteLine($"{a[0]}-{a[1]}-{a[2]}-{a[3]}=7");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296]]
| 8
| 566
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C {
class Program {
static IEnumerable<int> func(int a, int b) {
yield return a + b;
yield return a - b;
}
static void Main(string[] args) {
var A = Console.ReadLine().Select(x => int.Parse(x + "")).ToArray();
if (A[0] + A[1] + A[2] + A[3] == 7) {
Console.WriteLine($"{A[0]}+{A[1]}+{A[2]}+{A[3]}=7");
} else if (A[0] + A[1] + A[2] - A[3] == 7) {
Console.WriteLine($"{A[0]}+{A[1]}+{A[2]}-{A[3]}=7");
} else if (A[0] + A[1] - A[2] + A[3] == 7) {
Console.WriteLine($"{A[0]}+{A[1]}-{A[2]}+{A[3]}=7");
} else if (A[0] + A[1] - A[2] - A[3] == 7) {
Console.WriteLine($"{A[0]}+{A[1]}-{A[2]}-{A[3]}=7");
} else if (A[0] - A[1] + A[2] + A[3] == 7) {
Console.WriteLine($"{A[0]}-{A[1]}+{A[2]}+{A[3]}=7");
} else if (A[0] - A[1] + A[2] - A[3] == 7) {
Console.WriteLine($"{A[0]}-{A[1]}+{A[2]}-{A[3]}=7");
} else if (A[0] + A[1] + A[2] - A[3] == 7) {
Console.WriteLine($"{A[0]}+{A[1]}+{A[2]}-{A[3]}=7");
} else if (A[0] - A[1] - A[2] - A[3] == 7) {
Console.WriteLine($"{A[0]}-{A[1]}-{A[2]}-{A[3]}=7");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace C {
class Program {
static IEnumerable<int> func(int a, int b) {
yield return a + b;
yield return a - b;
}
static void Main(string[] args) {
var A = Console.ReadLine().Select(x => int.Parse(x + "")).ToArray();
if (A[0] + A[1] + A[2] + A[3] == 7) {
Console.WriteLine($"{A[0]}+{A[1]}+{A[2]}+{A[3]}=7");
} else if (A[0] + A[1] + A[2] - A[3] == 7) {
Console.WriteLine($"{A[0]}+{A[1]}+{A[2]}-{A[3]}=7");
} else if (A[0] + A[1] - A[2] + A[3] == 7) {
Console.WriteLine($"{A[0]}+{A[1]}-{A[2]}+{A[3]}=7");
} else if (A[0] + A[1] - A[2] - A[3] == 7) {
Console.WriteLine($"{A[0]}+{A[1]}-{A[2]}-{A[3]}=7");
} else if (A[0] - A[1] + A[2] + A[3] == 7) {
Console.WriteLine($"{A[0]}-{A[1]}+{A[2]}+{A[3]}=7");
} else if (A[0] - A[1] + A[2] - A[3] == 7) {
Console.WriteLine($"{A[0]}-{A[1]}+{A[2]}-{A[3]}=7");
} else if (A[0] - A[1] - A[2] + A[3] == 7) {
Console.WriteLine($"{A[0]}-{A[1]}-{A[2]}+{A[3]}=7");
} else if (A[0] - A[1] - A[2] - A[3] == 7) {
Console.WriteLine($"{A[0]}-{A[1]}-{A[2]}-{A[3]}=7");
}
}
}
}
|
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 72], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 33], ["-", 75, 57, 15, 16, 31, 16, 31, 16, 17, 72], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["-", 75, 57, 75, 57, 15, 16, 31, 16, 17, 33], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296]]
| 8
| 604
| 12
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.D {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var inputs = ReadLongs();
var H = inputs[0];
var W = inputs[1];
var C = new long[10, 10];
for (int i = 0; i < 10; i++) {
var c = ReadLongs();
for (int j = 0; j < 10; j++) {
C[i, j] = c[j];
}
}
var Counts = new long[10];
var A = new long[H, W];
for (int i = 0; i < H; i++) {
var a = ReadLongs();
for (int j = 0; j < W; j++) {
A[i, j] = a[j];
if (a[j] != -1) {
Counts[a[j]]++;
}
}
}
// 経由点
for (int via = 0; via < 10; via++) {
// 開始点
for (int start = 0; start < 10; start++) {
//終了点
for (int goal = 0; goal < 10; goal++) {
C[start, goal] =
Math.Min(C[start, goal], C[start, via] + C[via, goal]);
}
}
}
var totalCost = Enumerable.Range(0, 9)
.Where(x => x != 1)
.Select(x => C[x, 1] * Counts[x])
.Sum();
return totalCost;
}
#region Console
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace AtCoder.D {
public class Program {
public static void Main() {
var r = GetResult();
Debug.WriteLine(r);
Console.Write(r);
}
private static object GetResult() {
var inputs = ReadLongs();
var H = inputs[0];
var W = inputs[1];
var C = new long[10, 10];
for (int i = 0; i < 10; i++) {
var c = ReadLongs();
for (int j = 0; j < 10; j++) {
C[i, j] = c[j];
}
}
var Counts = new long[10];
var A = new long[H, W];
for (int i = 0; i < H; i++) {
var a = ReadLongs();
for (int j = 0; j < W; j++) {
A[i, j] = a[j];
if (a[j] != -1) {
Counts[a[j]]++;
}
}
}
// 経由点
for (int via = 0; via < 10; via++) {
// 開始点
for (int start = 0; start < 10; start++) {
//終了点
for (int goal = 0; goal < 10; goal++) {
C[start, goal] =
Math.Min(C[start, goal], C[start, via] + C[via, goal]);
}
}
}
var totalCost = Enumerable.Range(0, 10)
.Where(x => x != 1)
.Select(x => C[x, 1] * Counts[x])
.Sum();
return totalCost;
}
#region Console
public static string ReadText() { return Console.ReadLine(); }
public static List<string> ReadTexts() {
return Console.ReadLine().Split(' ').ToList();
}
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
}
#endregion
}
}
|
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 484
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Yorukatsu20200409D.Input;
namespace Yorukatsu20200409D {
static class Input {
private static Func<string, T[]>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray();
private static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(string[]))
return _ => (T)(object)_.Split(' ');
if (t == typeof(int[]))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(long[]))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(double[]))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
private static T Convert<T>(string s) => Convert<T>()(s);
private static string String() => Console.ReadLine();
private static string[] String(long rowNumber) =>
new bool [rowNumber].Select(_ => String()).ToArray();
public static void Cin<T>(out T a) => a = Convert<T>(String());
public static void Cin<T1, T2>(out T1 a1, out T2 a2) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
}
public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
}
public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
}
public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4, out T5 a5) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
}
public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2,
out T3 a3, out T4 a4,
out T5 a5, out T6 a6) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
set(v[5], out a6);
}
private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s);
public static void
Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray();
public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) {
l1 = new T1[n];
l2 = new T2[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i]);
}
public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2,
out T3[] l3) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i]);
}
public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2,
out T3[] l3, out T4[] l4) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
l4 = new T4[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i], out l4[i]);
}
public static void Cin<T>(out T[] a) => a = Convert<T[]>(String());
public static void Cin<T>(long h, out T[][] map) => map =
String(h).Select(Convert<T[]>()).ToArray();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
public void Solve() {
int h, w;
int[][] c;
int[][] a;
Cin(out h, out w);
c = new int [10][];
for (int i = 0; i < 10; i++) {
Cin(out c[i]);
}
a = new int [h][];
for (int i = 0; i < h; i++) {
Cin(out a[i]);
}
List<long> start = new List<long>();
List<long> end = new List<long>();
List<long> cost = new List<long>();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
start.Add(i);
end.Add(j);
cost.Add(c[i][j]);
}
}
var wf = new WarshallFloyd(10, 100, start, end, cost);
long ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (a[i][j] != -1) {
ans += wf.ArriveCost[a[i][j]][1];
}
}
}
Console.WriteLine(ans);
}
}
public class WarshallFloyd {
public static long INF = Int32.MaxValue;
public long[][] ArriveCost;
/// <summary>
/// ワーシャルフロイド法で頂点間最短経路を求める
/// </summary>
/// <param name="V">頂点の数</param>
/// <param name="K">辺の数</param>
/// <param name="A">経路の始点</param>
/// <param name="B">経路の終点</param>
/// <param name="C">経路のコスト</param>
public WarshallFloyd(long V, long K, List<long> A, List<long> B,
List<long> C) {
ArriveCost = Enumerable.Repeat(0, (int)V)
.Select(_ => Enumerable.Repeat(K + 1, (int)V).ToArray())
.ToArray();
for (int i = 0; i < V; i++) {
ArriveCost[i][i] = 0;
}
for (int i = 0; i < K; i++) {
ArriveCost[A[i]][B[i]] = Math.Min(ArriveCost[A[i]][B[i]], C[i]);
}
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
for (int k = 0; k < V; k++) {
ArriveCost[j][k] =
Math.Min(ArriveCost[j][k], ArriveCost[j][i] + ArriveCost[i][k]);
}
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Yorukatsu20200409D.Input;
namespace Yorukatsu20200409D {
static class Input {
private static Func<string, T[]>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray();
private static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(string[]))
return _ => (T)(object)_.Split(' ');
if (t == typeof(int[]))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(long[]))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(double[]))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
private static T Convert<T>(string s) => Convert<T>()(s);
private static string String() => Console.ReadLine();
private static string[] String(long rowNumber) =>
new bool [rowNumber].Select(_ => String()).ToArray();
public static void Cin<T>(out T a) => a = Convert<T>(String());
public static void Cin<T1, T2>(out T1 a1, out T2 a2) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
}
public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
}
public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
}
public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4, out T5 a5) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
}
public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2,
out T3 a3, out T4 a4,
out T5 a5, out T6 a6) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
set(v[5], out a6);
}
private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s);
public static void
Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray();
public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) {
l1 = new T1[n];
l2 = new T2[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i]);
}
public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2,
out T3[] l3) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i]);
}
public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2,
out T3[] l3, out T4[] l4) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
l4 = new T4[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i], out l4[i]);
}
public static void Cin<T>(out T[] a) => a = Convert<T[]>(String());
public static void Cin<T>(long h, out T[][] map) => map =
String(h).Select(Convert<T[]>()).ToArray();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
public void Solve() {
int h, w;
int[][] c;
int[][] a;
Cin(out h, out w);
c = new int [10][];
for (int i = 0; i < 10; i++) {
Cin(out c[i]);
}
a = new int [h][];
for (int i = 0; i < h; i++) {
Cin(out a[i]);
}
List<long> start = new List<long>();
List<long> end = new List<long>();
List<long> cost = new List<long>();
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
start.Add(i);
end.Add(j);
cost.Add(c[i][j]);
}
}
var wf = new WarshallFloyd(10, 100, start, end, cost);
long ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (a[i][j] != -1) {
ans += wf.ArriveCost[a[i][j]][1];
}
}
}
Console.WriteLine(ans);
}
}
public class WarshallFloyd {
public static long INF = Int32.MaxValue;
public long[][] ArriveCost;
/// <summary>
/// ワーシャルフロイド法で頂点間最短経路を求める
/// </summary>
/// <param name="V">頂点の数</param>
/// <param name="K">辺の数</param>
/// <param name="A">経路の始点</param>
/// <param name="B">経路の終点</param>
/// <param name="C">経路のコスト</param>
public WarshallFloyd(long V, long K, List<long> A, List<long> B,
List<long> C) {
ArriveCost = Enumerable.Repeat(0, (int)V)
.Select(_ => Enumerable.Repeat(INF, (int)V).ToArray())
.ToArray();
for (int i = 0; i < V; i++) {
ArriveCost[i][i] = 0;
}
for (int i = 0; i < K; i++) {
ArriveCost[A[i]][B[i]] = Math.Min(ArriveCost[A[i]][B[i]], C[i]);
}
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
for (int k = 0; k < V; k++) {
ArriveCost[j][k] =
Math.Min(ArriveCost[j][k], ArriveCost[j][i] + ArriveCost[i][k]);
}
}
}
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 205, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 1,929
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var solver = new Solver(sw);
// var t = new Thread(solver.solve, 1 << 26); // 64 MB
// t.Start();
// t.Join();
solver.solve();
sw.Flush();
}
}
class Solver {
StreamWriter sw;
Scan sc;
void Prt(string a) => sw.WriteLine(a);
void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
void Prt(params object[] a) => Prt(string.Join(" ", a));
public Solver(StreamWriter sw) {
this.sw = sw;
this.sc = new Scan();
}
public void solve() {
int h, w;
sc.Multi(out h, out w);
var d = new int [10][];
for (int i = 0; i < 10; i++) {
d[i] = sc.IntArr;
}
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
for (int k = 0; k < 10; ++k)
d[j][k] = Math.Min(d[j][k], d[j][i] + d[i][k]);
int ans = 0;
for (int i = 0; i < h; i++) {
ans += sc.IntArr.Where(x => x > 0).Sum(x => d[x][1]);
}
Prt(ans);
}
}
class pair<T, U> : IComparable<pair<T, U>> {
public T v1;
public U v2;
public pair() : this(default(T), default(U)) {}
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) {
int c = Comparer<T>.Default.Compare(v1, a.v1);
return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
}
public override string ToString() => v1 + " " + v2;
public void Deconstruct(out T a, out U b) {
a = v1;
b = v2;
}
}
static class util {
public static readonly int M = 1000000007;
// public static readonly int M = 998244353;
public static readonly long LM = 1L << 60;
public static readonly double eps = 1e-11;
public static void DBG(string a) => Console.Error.WriteLine(a);
public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
public static void DBG(params object[] a) => DBG(string.Join(" ", a));
public static void Assert(params bool[] conds) {
if (conds.Any(x => !x))
throw new Exception();
}
public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1,
v2);
public static int CompareList<T>(IList<T> a, IList<T> b)
where T : IComparable<T> {
for (int i = 0; i < a.Count && i < b.Count; i++)
if (a[i].CompareTo(b[i]) != 0)
return a[i].CompareTo(b[i]);
return a.Count.CompareTo(b.Count);
}
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h
&& j >= 0 && j < w;
static readonly int[] dd = { 0, 1, 0, -1 };
// static readonly string dstring = "RDLU";
public static P[] adjacents(int i,
int j) => Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k],
j + dd[k ^ 1]))
.ToArray();
public static P[] adjacents(int i, int j, int h, int w) =>
Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k], j + dd[k ^ 1]))
.Where(p => inside(p.v1, p.v2, h, w))
.ToArray();
public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);
public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2,
h, w);
public static Dictionary<T, int>
compress<T>(this IEnumerable<T> a) => a.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) =>
compress(a.Aggregate(Enumerable.Union));
public static T[] inv<T>(this Dictionary<T, int> dic) {
var res = new T[dic.Count];
foreach (var item in dic)
res[item.Value] = item.Key;
return res;
}
public static void swap<T>(ref T a, ref T b)
where T : struct {
var t = a;
a = b;
b = t;
}
public static void swap<T>(this IList<T> a, int i, int j)
where T : struct {
var t = a[i];
a[i] = a[j];
a[j] = t;
}
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
public static void Deconstruct<T>(this IList<T> v, out T a) { a = v[0]; }
public static void Deconstruct<T>(this IList<T> v, out T a, out T b) {
a = v[0];
b = v[1];
}
public static void Deconstruct<T>(this IList<T> v, out T a, out T b,
out T c) {
a = v[0];
b = v[1];
c = v[2];
}
public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c,
out T d) {
a = v[0];
b = v[1];
c = v[2];
d = v[3];
}
public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c,
out T d, out T e) {
a = v[0];
b = v[1];
c = v[2];
d = v[3];
e = v[4];
}
}
class Scan {
StreamReader sr;
public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scan(string path) { sr = new StreamReader(path); }
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => sr.ReadLine().Trim();
public pair<T, U> Pair<T, U>() {
T a;
U b;
Multi(out a, out b);
return new pair<T, U>(a, b);
}
public P P => Pair<int, int>();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr =>
Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
public void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
var solver = new Solver(sw);
// var t = new Thread(solver.solve, 1 << 26); // 64 MB
// t.Start();
// t.Join();
solver.solve();
sw.Flush();
}
}
class Solver {
StreamWriter sw;
Scan sc;
void Prt(string a) => sw.WriteLine(a);
void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
void Prt(params object[] a) => Prt(string.Join(" ", a));
public Solver(StreamWriter sw) {
this.sw = sw;
this.sc = new Scan();
}
public void solve() {
int h, w;
sc.Multi(out h, out w);
var d = new int [10][];
for (int i = 0; i < 10; i++) {
d[i] = sc.IntArr;
}
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
for (int k = 0; k < 10; ++k)
d[j][k] = Math.Min(d[j][k], d[j][i] + d[i][k]);
int ans = 0;
for (int i = 0; i < h; i++) {
ans += sc.IntArr.Where(x => x >= 0).Sum(x => d[x][1]);
}
Prt(ans);
}
}
class pair<T, U> : IComparable<pair<T, U>> {
public T v1;
public U v2;
public pair() : this(default(T), default(U)) {}
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) {
int c = Comparer<T>.Default.Compare(v1, a.v1);
return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2);
}
public override string ToString() => v1 + " " + v2;
public void Deconstruct(out T a, out U b) {
a = v1;
b = v2;
}
}
static class util {
public static readonly int M = 1000000007;
// public static readonly int M = 998244353;
public static readonly long LM = 1L << 60;
public static readonly double eps = 1e-11;
public static void DBG(string a) => Console.Error.WriteLine(a);
public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
public static void DBG(params object[] a) => DBG(string.Join(" ", a));
public static void Assert(params bool[] conds) {
if (conds.Any(x => !x))
throw new Exception();
}
public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1,
v2);
public static int CompareList<T>(IList<T> a, IList<T> b)
where T : IComparable<T> {
for (int i = 0; i < a.Count && i < b.Count; i++)
if (a[i].CompareTo(b[i]) != 0)
return a[i].CompareTo(b[i]);
return a.Count.CompareTo(b.Count);
}
public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h
&& j >= 0 && j < w;
static readonly int[] dd = { 0, 1, 0, -1 };
// static readonly string dstring = "RDLU";
public static P[] adjacents(int i,
int j) => Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k],
j + dd[k ^ 1]))
.ToArray();
public static P[] adjacents(int i, int j, int h, int w) =>
Enumerable.Range(0, dd.Length)
.Select(k => new P(i + dd[k], j + dd[k ^ 1]))
.Where(p => inside(p.v1, p.v2, h, w))
.ToArray();
public static P[] adjacents(this P p) => adjacents(p.v1, p.v2);
public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2,
h, w);
public static Dictionary<T, int>
compress<T>(this IEnumerable<T> a) => a.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) =>
compress(a.Aggregate(Enumerable.Union));
public static T[] inv<T>(this Dictionary<T, int> dic) {
var res = new T[dic.Count];
foreach (var item in dic)
res[item.Value] = item.Key;
return res;
}
public static void swap<T>(ref T a, ref T b)
where T : struct {
var t = a;
a = b;
b = t;
}
public static void swap<T>(this IList<T> a, int i, int j)
where T : struct {
var t = a[i];
a[i] = a[j];
a[j] = t;
}
public static T[] copy<T>(this IList<T> a) {
var ret = new T[a.Count];
for (int i = 0; i < a.Count; i++)
ret[i] = a[i];
return ret;
}
public static void Deconstruct<T>(this IList<T> v, out T a) { a = v[0]; }
public static void Deconstruct<T>(this IList<T> v, out T a, out T b) {
a = v[0];
b = v[1];
}
public static void Deconstruct<T>(this IList<T> v, out T a, out T b,
out T c) {
a = v[0];
b = v[1];
c = v[2];
}
public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c,
out T d) {
a = v[0];
b = v[1];
c = v[2];
d = v[3];
}
public static void Deconstruct<T>(this IList<T> v, out T a, out T b, out T c,
out T d, out T e) {
a = v[0];
b = v[1];
c = v[2];
d = v[3];
e = v[4];
}
}
class Scan {
StreamReader sr;
public Scan() { sr = new StreamReader(Console.OpenStandardInput()); }
public Scan(string path) { sr = new StreamReader(path); }
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => sr.ReadLine().Trim();
public pair<T, U> Pair<T, U>() {
T a;
U b;
Multi(out a, out b);
return new pair<T, U>(a, b);
}
public P P => Pair<int, int>();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public double[] DoubleArr => StrArr.Select(double.Parse).ToArray();
public string[] StrArr =>
Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
bool eq<T, U>() => typeof(T).Equals(typeof(U));
T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
public void Multi<T>(out T a) => a = cv<T>(Str);
public void Multi<T, U>(out T a, out U b) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
public void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = StrArr;
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
|
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20]]
| 8
| 2,350
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
class Simple {
int H, W;
int[,] c, A;
void Solve() {
// input
H = io.Int;
W = io.Int;
c = new int[10, 10];
A = new int[H, W];
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
c[i, j] = io.Int;
for (int i = 0; i < H; ++i)
for (int j = 0; j < W; ++j)
A[i, j] = io.Int;
// cal
var wf = new WarshallFloyd(10);
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
wf.AddPath(i, j, c[i, j]);
wf.Run();
var ans = 0L;
for (int i = 0; i < H; ++i)
for (int j = 0; j < W; ++j)
if (A[i, j] != -1)
ans += wf.MinCost(A[i, j], 1);
// ret
WriteLine(ans);
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) => new Simple().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class WarshallFloyd {
bool IsNonDir;
int VertexNum;
int EdgeNum;
long INF;
long[,] G;
public WarshallFloyd(int n, bool isNondir = true,
long inf = long.MaxValue / 2) {
IsNonDir = isNondir;
INF = inf;
Init(n);
}
public void Init(int n) {
VertexNum = n;
G = new long[VertexNum + 1, VertexNum + 1];
for (int i = 0; i < VertexNum + 1; ++i)
for (int j = 0; j < VertexNum + 1; ++j)
G[i, j] = INF;
}
public void AddPath(int f, int t, long c = 1) {
EdgeNum++;
G[f, t] = Math.Min(G[f, t], c);
if (IsNonDir)
G[t, f] = Math.Min(G[t, f], c);
}
public virtual void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i]);
}
public virtual void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void Run() {
for (int i = 0; i < VertexNum + 1; ++i)
for (int j = 0; j < VertexNum + 1; ++j)
for (int k = 0; k < VertexNum + 1; ++k)
G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]);
}
public long MinCost(int f, int t) => G[f, t];
}
class SimpleIO {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
public SimpleIO() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
if (st != null)
_nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
else
st = "";
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void Flush() => Out.Flush();
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
class Simple {
int H, W;
int[,] c, A;
void Solve() {
// input
H = io.Int;
W = io.Int;
c = new int[10, 10];
A = new int[H, W];
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
c[i, j] = io.Int;
for (int i = 0; i < H; ++i)
for (int j = 0; j < W; ++j)
A[i, j] = io.Int;
// cal
var wf = new WarshallFloyd(10, false);
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
wf.AddPath(i, j, c[i, j]);
wf.Run();
var ans = 0L;
for (int i = 0; i < H; ++i)
for (int j = 0; j < W; ++j)
if (A[i, j] != -1)
ans += wf.MinCost(A[i, j], 1);
// ret
WriteLine(ans);
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) => new Simple().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class WarshallFloyd {
bool IsNonDir;
int VertexNum;
int EdgeNum;
long INF;
long[,] G;
public WarshallFloyd(int n, bool isNondir = true,
long inf = long.MaxValue / 2) {
IsNonDir = isNondir;
INF = inf;
Init(n);
}
public void Init(int n) {
VertexNum = n;
G = new long[VertexNum + 1, VertexNum + 1];
for (int i = 0; i < VertexNum + 1; ++i)
for (int j = 0; j < VertexNum + 1; ++j)
G[i, j] = INF;
}
public void AddPath(int f, int t, long c = 1) {
EdgeNum++;
G[f, t] = Math.Min(G[f, t], c);
if (IsNonDir)
G[t, f] = Math.Min(G[t, f], c);
}
public virtual void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i]);
}
public virtual void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void Run() {
for (int i = 0; i < VertexNum + 1; ++i)
for (int j = 0; j < VertexNum + 1; ++j)
for (int k = 0; k < VertexNum + 1; ++k)
G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]);
}
public long MinCost(int f, int t) => G[f, t];
}
class SimpleIO {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
public SimpleIO() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
if (st != null)
_nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
else
st = "";
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void Flush() => Out.Flush();
}
|
[["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 21], ["+", 0, 230, 3, 4, 0, 28, 0, 211, 0, 147]]
| 8
| 971
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() { return Array().Select(int.Parse).ToArray(); }
public long[] LongArray() { return Array().Select(long.Parse).ToArray(); }
}
class Program {
public void Solve() {
var sc = new Scanner();
char x = sc.Next()[0], y = sc.Next()[0];
if (x == y) {
Console.WriteLine("=");
}
if (x > y) {
Console.WriteLine(">");
} else {
Console.WriteLine("<");
}
}
static void Main(string[] args) { new Program().Solve(); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest {
class Scanner {
private string[] line = new string[0];
private int index = 0;
public string Next() {
if (line.Length <= index) {
line = Console.ReadLine().Split(' ');
index = 0;
}
var res = line[index];
index++;
return res;
}
public int NextInt() { return int.Parse(Next()); }
public long NextLong() { return long.Parse(Next()); }
public string[] Array() {
line = Console.ReadLine().Split(' ');
index = line.Length;
return line;
}
public int[] IntArray() { return Array().Select(int.Parse).ToArray(); }
public long[] LongArray() { return Array().Select(long.Parse).ToArray(); }
}
class Program {
public void Solve() {
var sc = new Scanner();
char x = sc.Next()[0], y = sc.Next()[0];
if (x == y) {
Console.WriteLine("=");
} else if (x > y) {
Console.WriteLine(">");
} else {
Console.WriteLine("<");
}
}
static void Main(string[] args) { new Program().Solve(); }
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 328
| 1
|
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var xy = Console.ReadLine();
string msg;
if (xy[0] > xy[1]) {
msg = ">";
} else if (xy[0] < xy[1]) {
msg = "<";
} else {
msg = "=";
}
Console.WriteLine(msg);
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class Calculation {}
static class ReadLib {
public static long ReadAsLong() { return long.Parse(Console.ReadLine()); }
public static int ReadAsInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadAsIntArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) + step)
.ToArray();
}
public static long[] ReadAsLongArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => long.Parse(s) + step)
.ToArray();
}
public static ulong[] ReadAsULongArray() {
return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
}
public static string[] ReadAsStringArray() {
return Console.ReadLine().Split(' ');
}
public static int[] ReadNTimesAsInt(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => int.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static int[][] ReadNTimesAsIntArray(int n, int step = 0) {
return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray();
}
public static string[] ReadNTimesAsString(int n) {
return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray();
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
///// <summary>nCr, 組み合わせ</summary>
// public static long Combination(int n, int r) {
// if (r == 0) {
// return 1;
// }
// // 分子
// var moleculeArr = Enumerable
// .Range(0, Math.Min(n - r, r))
// .Select(i => n - i)
// .ToArray();
// var moleculeArrLength = moleculeArr.Length;
// // 分母
// var denominatorArr = Enumerable
// .Range(1, Math.Max(n - r, r))
// .ToArray();
// for (var m = 0; m < moleculeArrLength; m++) {
// while (true) {
// var mVal = moleculeArr[m];
// var gcds = denominatorArr.Select(b => Gcd(mVal, b));
// var maxGcd = gcds.Max();
// var maxI = gcds.ToList().IndexOf(maxGcd);
// if (maxGcd == 1) {
// break;
// }
// denominatorArr[maxI] /= (int)maxGcd;
// moleculeArr[m] /= (int)maxGcd;
// }
// }
// return FullPower(moleculeArr);
//}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
long value = item1.Value + item2;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
long value = Math.BigMul(item1.Value, item2);
return new ModInt(value, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var xy = Console.ReadLine();
string msg;
if (xy[0] > xy[2]) {
msg = ">";
} else if (xy[0] < xy[2]) {
msg = "<";
} else {
msg = "=";
}
Console.WriteLine(msg);
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class Calculation {}
static class ReadLib {
public static long ReadAsLong() { return long.Parse(Console.ReadLine()); }
public static int ReadAsInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadAsIntArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) + step)
.ToArray();
}
public static long[] ReadAsLongArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => long.Parse(s) + step)
.ToArray();
}
public static ulong[] ReadAsULongArray() {
return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
}
public static string[] ReadAsStringArray() {
return Console.ReadLine().Split(' ');
}
public static int[] ReadNTimesAsInt(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => int.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static int[][] ReadNTimesAsIntArray(int n, int step = 0) {
return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray();
}
public static string[] ReadNTimesAsString(int n) {
return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray();
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
///// <summary>nCr, 組み合わせ</summary>
// public static long Combination(int n, int r) {
// if (r == 0) {
// return 1;
// }
// // 分子
// var moleculeArr = Enumerable
// .Range(0, Math.Min(n - r, r))
// .Select(i => n - i)
// .ToArray();
// var moleculeArrLength = moleculeArr.Length;
// // 分母
// var denominatorArr = Enumerable
// .Range(1, Math.Max(n - r, r))
// .ToArray();
// for (var m = 0; m < moleculeArrLength; m++) {
// while (true) {
// var mVal = moleculeArr[m];
// var gcds = denominatorArr.Select(b => Gcd(mVal, b));
// var maxGcd = gcds.Max();
// var maxI = gcds.ToList().IndexOf(maxGcd);
// if (maxGcd == 1) {
// break;
// }
// denominatorArr[maxI] /= (int)maxGcd;
// moleculeArr[m] /= (int)maxGcd;
// }
// }
// return FullPower(moleculeArr);
//}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
long value = item1.Value + item2;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
long value = Math.BigMul(item1.Value, item2);
return new ModInt(value, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
|
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 1,544
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine().Split(' ');
if (0 < str[0].CompareTo(str[1])) {
Console.WriteLine(">");
} else if (0 > str[0].CompareTo(str[2])) {
Console.WriteLine("<");
} else {
Console.WriteLine("=");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine().Split(' ');
if (0 < str[0].CompareTo(str[1])) {
Console.WriteLine(">");
} else if (0 > str[0].CompareTo(str[1])) {
Console.WriteLine("<");
} else {
Console.WriteLine("=");
}
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 124
| 2
|
using System;
using System.Linq;
class Program {
static void Main() {
char[] input = Array.ConvertAll(Console.ReadLine().Split(), char.Parse);
// int input=int.Parse(Console.ReadLine());
// string a = Console.ReadLine();
string ans;
if (input[0] < input[1]) {
ans = "<";
} else if (input[1] > input[0]) {
ans = "<";
} else {
ans = "=";
}
Console.WriteLine(ans);
Console.ReadLine();
}
}
|
using System;
using System.Linq;
class Program {
static void Main() {
char[] input = Array.ConvertAll(Console.ReadLine().Split(), char.Parse);
// int input=int.Parse(Console.ReadLine());
// string a = Console.ReadLine();
string ans;
if (input[0] < input[1]) {
ans = "<";
} else if (input[1] < input[0]) {
ans = ">";
} else {
ans = "=";
}
Console.WriteLine(ans);
Console.ReadLine();
}
}
|
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
| 8
| 111
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split();
int x = int.Parse(input[0]);
int y = int.Parse(input[1]);
int z = int.Parse(input[2]);
Console.WriteLine((x - 1) / (y + z));
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split();
int x = int.Parse(input[0]);
int y = int.Parse(input[1]);
int z = int.Parse(input[2]);
Console.WriteLine((x - z) / (y + z));
}
}
|
[["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22]]
| 8
| 101
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
//
int X;
int Y;
int Z;
Multi(out X, out Y, out Z);
var ans = (X + Z) / (Y + Z);
Console.WriteLine(ans);
//
Console.Out.Flush();
Console.ReadKey();
}
static void Solve() {}
static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public string GetStr() { return Console.ReadLine().Trim(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Split(' ').Select(char.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V>(out T a, out U b, out V c, out V d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<V>(ar[3]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
static class Program {
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
//
int X;
int Y;
int Z;
Multi(out X, out Y, out Z);
var ans = (X - Z) / (Y + Z);
Console.WriteLine(ans);
//
Console.Out.Flush();
Console.ReadKey();
}
static void Solve() {}
static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
static public string GetStr() { return Console.ReadLine().Trim(); }
static public int GetInt() { return int.Parse(Console.ReadLine()); }
static public long GetLong() { return long.Parse(Console.ReadLine()); }
static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
static public int[] GetIntArray() {
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Split(' ').Select(char.Parse).ToArray();
}
static public List<double> GetDoubleList() {
return Console.ReadLine().Split(' ').Select(double.Parse).ToList();
}
static public void WriteObjects<T>(IEnumerable<T> values) {
foreach (var o in values) {
Console.Write(o + " ");
}
}
static string yesno(this bool b) { return b ? "yes" : "no"; }
static string YesNo(this bool b) { return b ? "Yes" : "No"; }
static string YESNO(this bool b) { return b ? "YES" : "NO"; }
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V>(out T a, out U b, out V c, out V d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<V>(ar[3]);
}
}
}
|
[["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33]]
| 8
| 887
| 2
|
using System;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var XYZ = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
Console.WriteLine((XYZ[0] - 1) / (XYZ[1] + XYZ[2]));
}
}
}
|
using System;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var XYZ = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
Console.WriteLine((XYZ[0] - XYZ[2]) / (XYZ[1] + XYZ[2]));
}
}
}
|
[["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 85
| 5
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
return;
}
public void Solve(ConsoleInput cin) {
var X = cin.ReadInt;
var Y = cin.ReadInt;
var Z = cin.ReadInt;
var num = 0;
while (true) {
if (Y * num + Z * (num + 1) > X)
break;
else
num++;
}
WriteLine(num);
}
}
public static class Extensions {
public static string Reverse(this string sourse) {
char[] chrAry = sourse.ToCharArray();
Array.Reverse(chrAry);
return new string(chrAry);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
return;
}
public void Solve(ConsoleInput cin) {
var X = cin.ReadInt;
var Y = cin.ReadInt;
var Z = cin.ReadInt;
var num = 0;
while (true) {
if (Y * num + Z * (num + 1) > X)
break;
else
num++;
}
WriteLine(num - 1);
}
}
public static class Extensions {
public static string Reverse(this string sourse) {
char[] chrAry = sourse.ToCharArray();
Array.Reverse(chrAry);
return new string(chrAry);
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 527
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
int[] a = Read.ints();
Console.WriteLine((a[0] - a[1]) / (a[1] + a[2]));
}
public static long gcd(long a, long b) {
while (true) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
a -= b;
} else {
b -= a;
}
}
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static bool IsPrime(long n) {
if (n < 2)
return false;
if (n == 2)
return true;
for (long i = 2; i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
}
public static class Read {
public static void outl(string n = "") {
Console.WriteLine(n);
return;
}
public static long Long() { return long.Parse(Console.ReadLine()); }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
int[] a = Read.ints();
Console.WriteLine((a[0] - a[2]) / (a[1] + a[2]));
}
public static long gcd(long a, long b) {
while (true) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
a -= b;
} else {
b -= a;
}
}
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static bool IsPrime(long n) {
if (n < 2)
return false;
if (n == 2)
return true;
for (long i = 2; i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
}
public static class Read {
public static void outl(string n = "") {
Console.WriteLine(n);
return;
}
public static long Long() { return long.Parse(Console.ReadLine()); }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
[["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 392
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ACB75A {
class Program {
static void Main(string[] args) {
int a, b, c;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[0]);
c = int.Parse(word[0]);
if (b == c) {
Console.WriteLine(a);
} else if (a == c) {
Console.WriteLine(b);
} else if (a == b) {
Console.WriteLine(c);
}
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ACB75A {
class Program {
static void Main(string[] args) {
int a, b, c;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = int.Parse(word[2]);
if (b == c) {
Console.WriteLine(a);
} else if (a == c) {
Console.WriteLine(b);
} else if (a == b) {
Console.WriteLine(c);
}
Console.ReadKey();
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 158
| 4
|
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var a = ReadLine().Split(' ').Select(int.Parse).ToList();
WriteLine(a[0] == a[1] ? a[2] : (a[0] == a[2] ? a[1] : a[2]));
}
}
}
|
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var a = ReadLine().Split(' ').Select(int.Parse).ToList();
WriteLine(a[0] == a[1] ? a[2] : (a[0] == a[2] ? a[1] : a[0]));
}
}
}
|
[["-", 0, 41, 75, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 41, 75, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 105
| 2
|
using System;
using System.Linq;
namespace ABC075_A {
class Program {
static void Main(string[] args) {
var n = Console.ReadLine().Split().Select(int.Parse).ToArray();
Console.WriteLine(n[0] == n[1] ? n[2] : n[0] == n[2] ? n[1] : n[2]);
}
}
}
|
using System;
using System.Linq;
namespace ABC075_A {
class Program {
static void Main(string[] args) {
var n = Console.ReadLine().Split().Select(int.Parse).ToArray();
Console.WriteLine(n[0] == n[1] ? n[2] : n[0] == n[2] ? n[1] : n[0]);
}
}
}
|
[["-", 75, 41, 75, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 41, 75, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 91
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace atcoder {
class Program {
static void Main(string[] args) {
var allSet =
Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToList();
if (allSet[0] == allSet[1])
Console.WriteLine(allSet[2]);
if (allSet[2] == allSet[1])
Console.WriteLine(allSet[0]);
else
Console.WriteLine(allSet[1]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace atcoder {
class Program {
static void Main(string[] args) {
var allSet =
Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToList();
if (allSet[0] == allSet[1])
Console.WriteLine(allSet[2]);
else if (allSet[2] == allSet[1])
Console.WriteLine(allSet[0]);
else
Console.WriteLine(allSet[1]);
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 121
| 1
|
using System;
using CompLib.Util;
public class Program {
public void Solve() {
var sc = new Scanner();
int h = sc.NextInt();
int w = sc.NextInt();
char[][] s = new char [h][];
for (int i = 0; i < h; i++) {
s[i] = sc.Next().ToCharArray();
}
int[] dy = new int[8] { 1, 1, 1, 0, 0, -1, -1, -1 };
int[] dx = new int[8] { -1, 0, 1, -1, 1, -1, 0, 1 };
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
continue;
int cnt = 0;
for (int k = 0; k < 8; k++) {
int yy = i + dy[k];
int xx = i + dx[k];
if (yy < 0 || yy >= h)
continue;
if (xx < 0 || xx >= w)
continue;
if (s[yy][xx] == '#')
cnt++;
}
s[i][j] = (char)('0' + cnt);
}
}
for (int i = 0; i < h; i++) {
Console.WriteLine(new string(s[i]));
}
}
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 h = sc.NextInt();
int w = sc.NextInt();
char[][] s = new char [h][];
for (int i = 0; i < h; i++) {
s[i] = sc.Next().ToCharArray();
}
int[] dy = new int[8] { 1, 1, 1, 0, 0, -1, -1, -1 };
int[] dx = new int[8] { -1, 0, 1, -1, 1, -1, 0, 1 };
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '#')
continue;
int cnt = 0;
for (int k = 0; k < 8; k++) {
int yy = i + dy[k];
int xx = j + dx[k];
if (yy < 0 || yy >= h)
continue;
if (xx < 0 || xx >= w)
continue;
if (s[yy][xx] == '#')
cnt++;
}
s[i][j] = (char)('0' + cnt);
}
}
for (int i = 0; i < h; i++) {
Console.WriteLine(new string(s[i]));
}
}
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, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22]]
| 8
| 661
| 2
|
using System;
using System.Collections.Generic;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
int H = 0, W = 0;
string[] inputStr = Console.ReadLine().Split(' ');
H = int.Parse(inputStr[0]);
W = int.Parse(inputStr[1]);
char[,] HW = new char[H, W];
for (int i = 0; i < H; ++i) {
string str = Console.ReadLine();
for (int j = 0; j < W; ++j) {
HW[i, j] = str[j];
}
}
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
int counter = 0;
if (HW[i, j] != '#') {
if (i - 1 > 0 & j - 1 > 0 && HW[i - 1, j - 1] == '#') {
counter++;
}
if (i - 1 > 0 && HW[i - 1, j] == '#') {
counter++;
}
if (i - 1 > 0 & j + 1 < W && HW[i - 1, j + 1] == '#') {
counter++;
}
if (j - 1 > 0 && HW[i, j - 1] == '#') {
counter++;
}
if (j + 1 < W && HW[i, j + 1] == '#') {
counter++;
}
if (i + 1 < H & j - 1 > 0 && HW[i + 1, j - 1] == '#') {
counter++;
}
if (i + 1 < H && HW[i + 1, j] == '#') {
counter++;
}
if (i + 1 < H & j + 1 < W && HW[i + 1, j + 1] == '#') {
counter++;
}
HW[i, j] = char.Parse(counter.ToString());
}
}
}
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
Console.Write($"{HW[i,j]}");
}
Console.Write("\n");
}
}
}
}
|
using System;
using System.Collections.Generic;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
int H = 0, W = 0;
string[] inputStr = Console.ReadLine().Split(' ');
H = int.Parse(inputStr[0]);
W = int.Parse(inputStr[1]);
char[,] HW = new char[H, W];
for (int i = 0; i < H; ++i) {
string str = Console.ReadLine();
for (int j = 0; j < W; ++j) {
HW[i, j] = str[j];
}
}
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
int counter = 0;
if (HW[i, j] != '#') {
if (i - 1 >= 0 & j - 1 >= 0 && HW[i - 1, j - 1] == '#') {
counter++;
}
if (i - 1 >= 0 && HW[i - 1, j] == '#') {
counter++;
}
if (i - 1 >= 0 & j + 1 < W && HW[i - 1, j + 1] == '#') {
counter++;
}
if (j - 1 >= 0 && HW[i, j - 1] == '#') {
counter++;
}
if (j + 1 < W && HW[i, j + 1] == '#') {
counter++;
}
if (i + 1 < H & j - 1 >= 0 && HW[i + 1, j - 1] == '#') {
counter++;
}
if (i + 1 < H && HW[i + 1, j] == '#') {
counter++;
}
if (i + 1 < H & j + 1 < W && HW[i + 1, j + 1] == '#') {
counter++;
}
HW[i, j] = char.Parse(counter.ToString());
}
}
}
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
Console.Write($"{HW[i,j]}");
}
Console.Write("\n");
}
}
}
}
|
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 20], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 20], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 20]]
| 8
| 514
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA();
// SolveB();
// SolveC();
// SolveD();
}
private const long MOD = 1000000007;
static void SolveA() {
var o = ReadAndParseIntArr();
int h = o[0];
int w = o[1];
var s = new string[h];
for (int i = 0; i < h; ++i) {
s[i] = Console.ReadLine();
}
char[,] table = new char[h, w];
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
if (s[y][x] == '#') {
table[y, x] = '#';
} else {
int total = 0;
int sx = Math.Max(0, x - 1);
int ex = Math.Min(w - 1, x + 1);
int sy = Math.Max(0, y - 1);
int ey = Math.Min(h - 1, y + 1);
for (int j = sy; j <= ey; ++j) {
for (int i = sx; i <= ex; ++i) {
if (s[j][i] == '#') {
total++;
}
}
}
table[y, x] = (char)total;
}
}
}
for (int y = 0; y < h; ++y) {
var c = new char[w];
for (int x = 0; x < w; ++x) {
c[x] = table[y, x];
}
Console.WriteLine(new string(c));
}
}
#region よく使う便利関数
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 int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA();
// SolveB();
// SolveC();
// SolveD();
}
private const long MOD = 1000000007;
static void SolveA() {
var o = ReadAndParseIntArr();
int h = o[0];
int w = o[1];
var s = new string[h];
for (int i = 0; i < h; ++i) {
s[i] = Console.ReadLine();
}
char[,] table = new char[h, w];
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
if (s[y][x] == '#') {
table[y, x] = '#';
} else {
int total = 0;
int sx = Math.Max(0, x - 1);
int ex = Math.Min(w - 1, x + 1);
int sy = Math.Max(0, y - 1);
int ey = Math.Min(h - 1, y + 1);
for (int j = sy; j <= ey; ++j) {
for (int i = sx; i <= ex; ++i) {
if (s[j][i] == '#') {
total++;
}
}
}
table[y, x] = (char)('0' + total);
}
}
}
for (int y = 0; y < h; ++y) {
var c = new char[w];
for (int x = 0; x < w; ++x) {
c[x] = table[y, x];
}
Console.WriteLine(new string(c));
}
}
#region よく使う便利関数
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 int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
#endregion
}
}
|
[["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 24], ["+", 12, 74, 51, 23, 0, 16, 31, 252, 0, 104], ["+", 12, 74, 51, 23, 0, 16, 31, 252, 0, 253], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 25]]
| 8
| 688
| 6
|
using System;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
int h = int.Parse(input[0]);
int w = int.Parse(input[1]);
string result = "";
string[] masu = new string[h];
for (int i = 0; i < h; i++) {
masu[i] = Console.ReadLine();
}
for (int i = 0; i < h; i++) {
result = "";
for (int j = 0; j < w; j++) {
int k = 0;
for (int a = i - 1; a >= i + 1; a++) {
for (int b = j - 1; b >= j + 1; b++) {
if (a >= 0 && b >= 0 && a < h && b < w) {
if (masu[a][b] == '#')
k++;
}
}
}
if (masu[i][j] == '.')
result += k;
else
result += '#';
}
Console.WriteLine(result);
}
}
}
|
using System;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
int h = int.Parse(input[0]);
int w = int.Parse(input[1]);
string result = "";
string[] masu = new string[h];
for (int i = 0; i < h; i++) {
masu[i] = Console.ReadLine();
}
for (int i = 0; i < h; i++) {
result = "";
for (int j = 0; j < w; j++) {
int k = 0;
for (int a = i - 1; a <= i + 1; a++) {
for (int b = j - 1; b <= j + 1; b++) {
if (a >= 0 && b >= 0 && a < h && b < w) {
if (masu[a][b] == '#')
k++;
}
}
}
if (masu[i][j] == '.')
result += k;
else
result += '#';
}
Console.WriteLine(result);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 254
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
int[] n = ints();
char[,] a = new char[n[0], n[1]];
for (int i = 0; i < n[0]; i++) {
string s = Console.ReadLine();
for (int j = 0; j < n[1]; j++) {
a[i, j] = s[j];
}
}
var ans = new int[n[0], n[1]];
for (int i = 0; i < n[0]; i++) {
for (int j = 0; j < n[1]; j++) {
if (a[i, j] == '#') {
if (i != 0 && j != 0) {
ans[i - 1, j - 1]++;
}
if (i != 0) {
ans[i - 1, j]++;
}
if (i != 0 && j != n[1] - 1) {
ans[i - 1, j + 1]++;
}
if (j != 0) {
ans[i, j - 1]++;
}
if (j != n[1] - 1) {
ans[i, j + 1]++;
}
if (i != n[1] - 1 && j != 0) {
ans[i + 1, j - 1]++;
}
if (i != n[1] - 1) {
ans[i + 1, j]++;
}
if (i != n[1] - 1 && j != n[1] - 1) {
ans[i + 1, j + 1]++;
}
}
}
}
for (int i = 0; i < n[0]; i++) {
for (int j = 0; j < n[1]; j++) {
if (a[i, j] == '#') {
Console.Write("#");
} else {
Console.Write(ans[i, j]);
}
}
Console.WriteLine();
}
Console.ReadLine();
}
public static long gcd(long a, long b) {
while (true) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
a -= b;
} else {
b -= a;
}
}
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
int[] n = ints();
char[,] a = new char[n[0], n[1]];
for (int i = 0; i < n[0]; i++) {
string s = Console.ReadLine();
for (int j = 0; j < n[1]; j++) {
a[i, j] = s[j];
}
}
var ans = new int[n[0], n[1]];
for (int i = 0; i < n[0]; i++) {
for (int j = 0; j < n[1]; j++) {
if (a[i, j] == '#') {
if (i != 0 && j != 0) {
ans[i - 1, j - 1]++;
}
if (i != 0) {
ans[i - 1, j]++;
}
if (i != 0 && j != n[1] - 1) {
ans[i - 1, j + 1]++;
}
if (j != 0) {
ans[i, j - 1]++;
}
if (j != n[1] - 1) {
ans[i, j + 1]++;
}
if (i != n[0] - 1 && j != 0) {
ans[i + 1, j - 1]++;
}
if (i != n[0] - 1) {
ans[i + 1, j]++;
}
if (i != n[0] - 1 && j != n[1] - 1) {
ans[i + 1, j + 1]++;
}
}
}
}
for (int i = 0; i < n[0]; i++) {
for (int j = 0; j < n[1]; j++) {
if (a[i, j] == '#') {
Console.Write("#");
} else {
Console.Write(ans[i, j]);
}
}
Console.WriteLine();
}
Console.ReadLine();
}
public static long gcd(long a, long b) {
while (true) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a > b) {
a -= b;
} else {
b -= a;
}
}
}
public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
public static long[] longs() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static int Int() { return int.Parse(Console.ReadLine()); }
public static int[] ints() {
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
[["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 691
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static void Main(string[] args) {
#region C問題
// var data = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var t = data[0];
// var s = data[1];
// int[,] friens = new int[t, t];
// int tomo = 0;
// for (int i = 0; i < s; i++)
// {
// var friend = Array.ConvertAll(Console.ReadLine().Split(),
// int.Parse); friens[friend[0] - 1, friend[1] - 1] = 1;
// friens[friend[1] - 1, friend[0] - 1] = 1;
// }
// for (int i = 0; i < t; i++)
// {
// var x = new List<int>();
// var y = new List<int>();
// var a = new List<int>();
// for (int j = 0; j < t; j++)
// {
// if (friens[i, j] == 1)
// {
// x.Add(j);
// }
// }
// foreach (var z in x)
// {
// for (int l = 0; l < t; l++)
// {
// if (friens[z, l] == 1)
// {
// y.Add(l);
// }
// }
// foreach (var m in y)
// {
// if (m != i && friens[m, i] != 1)
// {
// a.Add(m);
// }
// }
// }
// Console.WriteLine(a.Distinct().Count());
// }
// var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var b = a[0];
// var c = a[1];
// int[] d = new int[b];
// int[] e = new int[b];
// int[] f = new int[b];
// int tmp = 0;
// int tokuten = 0;
// for (int i = 0; i < b; i++)
// {
// var g = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// d[i] = g[0];
// e[i] = g[1];
// f[i] = g[2];
// }
// for (int j = 1; j <= c; j++)
// {
// for (int k = 0; k < b; k++)
// {
// if (d[k] <= j && e[k] >= j)
// {
// }
// else
// {
// tmp += f[k];
// }
// }
// tokuten = Math.Max(tokuten ,tmp);
// tmp = 0;
// }
// Console.WriteLine(tokuten);
// var a = int.Parse(Console.ReadLine());
// var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// Dictionary<int,int> c = new Dictionary<int,int>();
// int d = 0;
// int cnt = 0;
////for (int i = 0; i < a; i++)
////{
//// c.Add(b[i], 1);
////}
// for (int i = 0; i < a; i++)
//{
// d = b[i];
// while (d % 2 == 0)
// {
// d /= 2;
// }
// if (c.ContainsKey(d))
// {
// }
// else
// {
// c.Add(d, 1);
// cnt++;
// }
//}
// Console.WriteLine(cnt);
// var one = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
// var N = one[0];
// var M = one[1];
// List<int[]> ID= new List<int[]>();
// List<string> Out = new List<string>();
// int cnt = 1;
// long now = -1;
// for (int i = 0; i < M; i++)
//{
// var morethanone = Array.ConvertAll(Console.ReadLine().Split(),
// int.Parse); ID.Add(morethanone);
//}
// var sortedID = ID.OrderBy(data => data[0]).ThenBy(data => data[1]);
// var Rank = new Dictionary<string, int>();
// foreach (var item in sortedID)
//{
// if (now != -1 && item[0] != now)
// {
// cnt = 1;
// }
// now = item[0];
// Rank.Add(item[0].ToString() + item[1].ToString(), cnt);
// cnt++;
//}
// for (int i = 0; i < M; i++)
//{
// var tmp = ID[i];
// string key = tmp[0].ToString() + tmp[1].ToString();
// string Output = tmp[0].ToString().PadLeft(6, '0') +
// Rank[key].ToString().PadLeft(6, '0'); Console.WriteLine(Output);
//}
// var N = int.Parse(Console.ReadLine());
// List<int[]> Z = new List<int[]>();
// List<int[]> dis = new List<int[]>();
// int X = 0;
// int Y = 0;
// int H = 0;
// for (int i = 0; i < N; i++)
//{
// var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// Z.Add(line);
//}
// row
// for (int i = 0; i < N; i++)
//{
// var linedata = Z[i];
// //height
// for (int j = 0; j < 201; j++)
// {
// //x
// for (int k = 0; k < 101; k++)
// {
// for (int l = 0; l < 101; l++)
// {
// if ((j + linedata[2]) - Math.Abs(k - linedata[0]) -
// Math.Abs(l - linedata[1]) == linedata[2])
// {
// X = k;
// Y = l;
// H = j;
// dis.Add(new {x = X,y =Y, h =H});
// }
// }
// }
// }
//}
// var a = dis.GroupBy(n => n)
// var b = a.OrderByDescending(n => n.cnt);
// var a = Console.ReadLine().ToCharArray();
// var b = Console.ReadLine().ToCharArray();
////char[] c = new char[a.Count()];
////char[] d = new char[a.Count()];
// var c = new Dictionary<char, char>();
// var d = new Dictionary<char, char>();
// for (int i = 0; i < a.Count(); i++)
//{
// if (!c.ContainsKey(a[i]))
// {
// c.Add(a[i], b[i]);
// }
// else if (c[a[i]] != b[i])
// {
// Console.WriteLine("No");
// return;
// }
//}
// for (int i = 0; i < b.Count(); i++)
//{
// if (!d.ContainsKey(b[i]))
// {
// d.Add(b[i], a[i]);
// }
// else if (d[b[i]] != a[i])
// {
// Console.WriteLine("No");
// return;
// }
//}
// Console.WriteLine("Yes");
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int min = int.MaxValue;
// int min2 = int.MaxValue;
// int amari = int.MaxValue;
// for (int i = 0; i < line1[0]; i++)
//{
// if (Math.Abs(line2[i]-line1[1]) <= min)
// {
// min2 = min;
// min = Math.Abs(line2[i] - line1[1]);
// }
// else if (Math.Abs(line2[i] - line1[1]) < min2)
// {
// min2 = Math.Abs(line2[i] - line1[1]);
// }
//}
// if (min2 != int.MaxValue)
//{
// while (amari != 0)
// {
// amari = min2 % min;
// min2 = min;
// min = amari;
// }
// Console.WriteLine(min2);
//}
// else
//{
// Console.WriteLine(min);
//}
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int N = line1[0];
// int K = line1[1];
// int Kgaguu = 0;
// int amari0 = 0;
// for (int i = 1; i <= N; i++)
//{
// if (i % K == 0)
// {
// amari0++;
// }
// else if (K % 2 == 0 && i % K == K /2)
// {
// Kgaguu++;
// }
//}
// Console.WriteLine(amari0 * amari0 * amari0 + Kgaguu * Kgaguu * Kgaguu);
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int N = line1[0];
// int K = line1[1];
// var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
// long mintmp = int.MaxValue;
// long min = int.MaxValue;
// for (int i = 0; i < N-K+1; i++)
//{
// var left = line2[i];
// var right = line2[i + K - 1];
// mintmp = Math.Min(Math.Min(Math.Abs(left) + Math.Abs(right - left),
// min), Math.Abs(right) + Math.Abs(left - right));
// min = Math.Min(mintmp, min);
//}
////for (int i = 0; i < N; i++)
////{
//// if (i != 0 || i != N-1)
//// {
//// var tmp = new node();
//// tmp._to1 = line2[i - 1];
//// tmp._to2 = line2[i + 1];
//// tmp.me = line2[i];
//// tmp.flg = false;
//// node.Add(tmp);
//// }
////}
// Console.WriteLine(min);
// var S = Console.ReadLine().ToCharArray();
// var K = decimal.Parse(Console.ReadLine());
// int cnt = 0;
// bool ren = false;
// int ans = 0;
// for (int i = 0; i < S.Count(); i++)
//{
// if (i == 0 && int.Parse(S[i].ToString()) == 1)
// {
// ren = true;
// cnt++;
// continue;
// }
// if (ren && int.Parse(S[i].ToString()) == 1)
// {
// ren = true;
// cnt++;
// continue;
// }
// if (int.Parse(S[i].ToString()) != 1)
// {
// ans = int.Parse(S[i].ToString());
// break;
// }
//}
// if (cnt >= K)
//{
// Console.WriteLine(1);
//}
// else
//{
// Console.WriteLine(ans);
//}
// Console.WriteLine(1 % -2);
// int input = int.Parse(Console.ReadLine());
// for (int i = 0; i < input; i++)
//{
// Console.WriteLine("Hello");
//}
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int N = line1[0];
// int M = line1[1];
// int[] tree = new int[N];
// int min = int.MaxValue;
// for (int i = 0; i < N; i++)
//{
// tree[i] = int.Parse(Console.ReadLine());
//}
// var sortedTree = tree.OrderBy(n => n).ToArray();
// for (int i = 0; i < N - K + 1; i++)
//{
// min = Math.Min(sortedTree[i + K -1] - sortedTree[i], min);
//}
// Console.WriteLine(min);
// var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
// int N = line1[0];
// int M = line1[1];
// var time1 = 1/Math.Pow(0.5, M);
// var time2 = 100 * (N - M) * time1;
// Console.WriteLine(time1 * 1900 * M + time2);
// var N = int.Parse(Console.ReadLine());
// var A = Array.ConvertAll(Console.ReadLine().Split(),
// long.Parse).OrderBy(n => n).ToArray(); var B =
// Array.ConvertAll(Console.ReadLine().Split(), long.Parse).OrderBy(n =>
// n).ToArray(); var C = Array.ConvertAll(Console.ReadLine().Split(),
// long.Parse).OrderBy(n => n).ToArray();
// long x = 0;
// for (int i = 0; i < N; i++)
//{
// var a = LowerBound(A, B[i]);
// var b = N - UpperBound(C, B[i]);
// x += a * b;
//}
// Console.WriteLine(x);
// var S = Console.ReadLine().ToCharArray().Reverse().ToArray();
// var T = Console.ReadLine().ToCharArray().Reverse().ToArray();
// var N = S.Length - 1;
// var K = T.Length - 1;
// int cnt;
// bool flg = false;
// for (int i = 0; i < N - K + 1; i++)
//{
// cnt = 0;
// for (int j = i; j <= i + K; j++)
// {
// if (S[j] == '?' || S[j] == T[j - i])
// {
// cnt++;
// }
// }
// if (cnt == K + 1)
// {
// for (int j = i; j <= i + K; j++)
// {
// S[j] = T[j - i];
// flg = true;
// }
// break;
// }
//}
// for (int i = 0; i < N + 1; i++)
//{
// if (S[i] == '?')
// {
// S[i] = 'a';
// }
//}
// if (flg)
//{
// var st = new string(S.Reverse().ToArray());
// Console.WriteLine(st);
//}
// else
//{
// Console.WriteLine("UNRESTORABLE");
//}
#endregion
var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
var N = line1[0];
var M = line1[1];
var a = new long[M];
var b = new long[M];
int bridge = 0;
int[,] dag = new int[N, N];
for (int i = 0; i < M; i++) {
var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
a[i] = line2[0] - 1;
b[i] = line2[1] - 1;
dag[a[i], b[i]] = 1;
dag[b[i], a[i]] = 1;
}
for (int i = 0; i < N; i++) {
bool[] visited = new bool[N];
dag[a[i], b[i]] = 0;
dag[b[i], a[i]] = 0;
DFS(0, visited, dag);
if (visited.Where(n => n == true).Count() != N) {
bridge++;
}
dag[a[i], b[i]] = 1;
dag[b[i], a[i]] = 1;
}
Console.WriteLine(bridge);
}
public static void DFS(int v, bool[] visited, int[,] dag) {
visited[v] = true;
for (int i = 0; i < visited.Length; i++) {
if (dag[v, i] == 0)
continue;
if (visited[i])
continue;
DFS(i, visited, dag);
}
}
public static long LowerBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long 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 long LowerBound<T>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static long UpperBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long 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 long UpperBound<T>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
var N = line1[0];
var M = line1[1];
var a = new long[M];
var b = new long[M];
int bridge = 0;
int[,] dag = new int[N, N];
for (int i = 0; i < M; i++) {
var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
a[i] = line2[0] - 1;
b[i] = line2[1] - 1;
dag[a[i], b[i]] = 1;
dag[b[i], a[i]] = 1;
}
for (int i = 0; i < M; i++) {
bool[] visited = new bool[N];
dag[a[i], b[i]] = 0;
dag[b[i], a[i]] = 0;
DFS(0, visited, dag);
if (visited.Where(n => n == true).Count() != N) {
bridge++;
}
dag[a[i], b[i]] = 1;
dag[b[i], a[i]] = 1;
}
Console.WriteLine(bridge);
}
public static void DFS(int v, bool[] visited, int[,] dag) {
visited[v] = true;
for (int i = 0; i < visited.Length; i++) {
if (dag[v, i] == 0)
continue;
if (visited[i])
continue;
DFS(i, visited, dag);
}
}
public static long LowerBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long 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 long LowerBound<T>(T[] arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
public static long UpperBound<T>(T[] arr, long start, long end, T value,
IComparer<T> comparer) {
long low = start;
long high = end;
long 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 long UpperBound<T>(T[] arr, T value) {
return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default);
}
}
}
|
[["-", 8, 201, 0, 235, 8, 201, 0, 195, 8, 196], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 333], ["-", 8, 201, 0, 195, 8, 196, 0, 333, 0, 334], ["-", 0, 195, 8, 196, 0, 333, 0, 334, 0, 169], ["-", 8, 196, 0, 333, 0, 334, 0, 169, 0, 169], ["-", 0, 333, 0, 334, 0, 169, 0, 169, 0, 169], ["-", 0, 334, 0, 169, 0, 169, 0, 169, 0, 169], ["-", 0, 169, 0, 169, 0, 169, 0, 169, 0, 169], ["-", 0, 169, 0, 169, 0, 169, 0, 169, 0, 335], ["-", 0, 169, 0, 169, 0, 169, 0, 335, 0, 197], ["-", 0, 169, 0, 169, 0, 335, 0, 197, 0, 198], ["-", 0, 169, 0, 335, 0, 197, 0, 198, 39, 216], ["-", 0, 335, 0, 197, 0, 198, 39, 216, 0, 200], ["-", 0, 197, 0, 198, 39, 216, 0, 200, 0, 197], ["-", 0, 198, 39, 216, 0, 200, 0, 197, 0, 198], ["-", 39, 216, 0, 200, 0, 197, 0, 198, 39, 216], ["-", 0, 200, 0, 197, 0, 198, 39, 216, 0, 200], ["-", 39, 216, 0, 200, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 197, 0, 198, 39, 199, 0, 200], ["-", 0, 197, 0, 198, 39, 199, 0, 200, 0, 197], ["-", 0, 198, 39, 199, 0, 200, 0, 197, 0, 198], ["-", 39, 199, 0, 200, 0, 197, 0, 198, 39, 224], ["-", 0, 200, 0, 197, 0, 198, 39, 224, 0, 200], ["-", 0, 197, 0, 198, 39, 224, 0, 200, 0, 7], ["-", 0, 198, 39, 224, 0, 200, 0, 7, 10, 198], ["-", 39, 224, 0, 200, 0, 7, 10, 198, 39, 199], ["-", 0, 200, 0, 7, 10, 198, 39, 199, 0, 200], ["-", 0, 7, 10, 198, 39, 199, 0, 200, 15, 16], ["-", 10, 198, 39, 199, 0, 200, 15, 16, 31, 22], ["-", 39, 199, 0, 200, 15, 16, 31, 22, 12, 22], ["-", 0, 200, 15, 16, 31, 22, 12, 22, 26, 223], ["-", 15, 16, 31, 22, 12, 22, 26, 223, 0, 22], ["-", 31, 22, 12, 22, 26, 223, 0, 22, 8, 196], ["-", 12, 22, 26, 223, 0, 22, 8, 196, 0, 197], ["-", 26, 223, 0, 22, 8, 196, 0, 197, 0, 1], ["-", 0, 22, 8, 196, 0, 197, 0, 1, 0, 1], ["-", 8, 196, 0, 197, 0, 1, 0, 1, 0, 1], ["-", 0, 197, 0, 1, 0, 1, 0, 1, 0, 1], ["-", 0, 1, 0, 1, 0, 1, 0, 1, 0, 7], ["-", 0, 1, 0, 1, 0, 1, 0, 7, 10, 198], ["-", 0, 1, 0, 1, 0, 7, 10, 198, 39, 199], ["-", 0, 1, 0, 7, 10, 198, 39, 199, 0, 200], ["-", 0, 197, 0, 1, 0, 1, 0, 1, 0, 57], ["-", 0, 1, 0, 1, 0, 1, 0, 57, 0, 1], ["-", 0, 1, 0, 1, 0, 57, 0, 1, 0, 1], ["-", 0, 1, 0, 57, 0, 1, 0, 1, 0, 1], ["-", 0, 57, 0, 1, 0, 1, 0, 1, 0, 213], ["-", 0, 1, 0, 1, 0, 1, 0, 213, 63, 214], ["-", 0, 1, 0, 1, 0, 213, 63, 214, 3, 4], ["-", 8, 201, 0, 195, 8, 196, 0, 333, 0, 336], ["-", 8, 201, 0, 195, 8, 196, 0, 335, 0, 337], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 1,085
| 7
|
using System;
namespace ABC075C {
class Program {
static int INFTY = 0x30000000;
static void Main(string[] args) {
string[] bufs = Console.ReadLine().Split(' ');
int N = int.Parse(bufs[0]);
int M = int.Parse(bufs[1]);
int[] a = new int[M];
int[] b = new int[M];
int[,] cost = new int[N, N];
for (int i = 0; i < M; i++) {
bufs = Console.ReadLine().Split(' ');
a[i] = int.Parse(bufs[0]) - 1;
b[i] = int.Parse(bufs[1]) - 1;
}
// END Initialize
int res = 0;
for (int cut = 0; cut < N; cut++) {
// Cost Reset
for (int i = 0; i < N; i++) {
cost[i, i] = 0;
for (int j = i + 1; j < N; j++) {
cost[i, j] = cost[j, i] = INFTY;
}
}
for (int m = 0; m < M; m++) {
if (m != cut) {
cost[a[m], b[m]] = cost[b[m], a[m]] = 1;
}
}
// END Cost Reset
// WF Method
for (int k = 0; k < N; ++k) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
int wc = cost[i, k] + cost[k, j];
if (wc < cost[i, j]) {
cost[i, j] = wc;
}
}
}
}
// Check
bool disconnected = false;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (cost[i, j] >= INFTY) {
disconnected = true;
}
}
}
if (disconnected) {
res++;
}
}
Console.WriteLine(res);
}
}
}
|
using System;
namespace ABC075C {
class Program {
static int INFTY = 0x30000000;
static void Main(string[] args) {
string[] bufs = Console.ReadLine().Split(' ');
int N = int.Parse(bufs[0]);
int M = int.Parse(bufs[1]);
int[] a = new int[M];
int[] b = new int[M];
int[,] cost = new int[N, N];
for (int i = 0; i < M; i++) {
bufs = Console.ReadLine().Split(' ');
a[i] = int.Parse(bufs[0]) - 1;
b[i] = int.Parse(bufs[1]) - 1;
}
// END Initialize
int res = 0;
for (int cut = 0; cut < M; cut++) {
// Cost Reset
for (int i = 0; i < N; i++) {
cost[i, i] = 0;
for (int j = i + 1; j < N; j++) {
cost[i, j] = cost[j, i] = INFTY;
}
}
for (int m = 0; m < M; m++) {
if (m != cut) {
cost[a[m], b[m]] = cost[b[m], a[m]] = 1;
}
}
// END Cost Reset
// WF Method
for (int k = 0; k < N; ++k) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
int wc = cost[i, k] + cost[k, j];
if (wc < cost[i, j]) {
cost[i, j] = wc;
}
}
}
}
// Check
bool disconnected = false;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (cost[i, j] >= INFTY) {
disconnected = true;
}
}
}
if (disconnected) {
res++;
}
}
Console.WriteLine(res);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 469
| 2
|
using System;
using System.Linq;
public class Problem_C {
public static void Main() {
var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int N = inputs[0], M = inputs[1];
var from = new int[N];
var to = new int[N];
var matrix = new int[N, N];
for (var i = 0; i < M; i++) {
var edge = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
from[i] = edge[0] - 1;
to[i] = edge[1] - 1;
matrix[from[i], to[i]] = matrix[to[i], from[i]] = 1;
}
var count = 0;
for (var i = 0; i < N; i++) {
// Check how it works when each edge is removed
matrix[from[i], to[i]] = matrix[to[i], from[i]] = 0;
var visited = new bool[N];
Dfs(N, 0, matrix, visited);
if (visited.Contains(false))
count++;
// Resume original state
matrix[from[i], to[i]] = matrix[to[i], from[i]] = 1;
}
Console.WriteLine($"{count}");
}
private static void Dfs(int nodeNum, int v, int[,] matrix, bool[] visited) {
visited[v] = true;
for (var i = 0; i < nodeNum; i++) {
if (matrix[v, i] == 0)
continue;
if (visited[i])
continue;
Dfs(nodeNum, i, matrix, visited);
}
}
}
|
using System;
using System.Linq;
public class Problem_C {
public static void Main() {
var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int N = inputs[0], M = inputs[1];
var from = new int[M];
var to = new int[M];
var matrix = new int[N, N];
for (var i = 0; i < M; i++) {
var edge = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
from[i] = edge[0] - 1;
to[i] = edge[1] - 1;
matrix[from[i], to[i]] = matrix[to[i], from[i]] = 1;
}
var count = 0;
for (var i = 0; i < M; i++) {
// Check how it works when each edge is removed
matrix[from[i], to[i]] = matrix[to[i], from[i]] = 0;
var visited = new bool[N];
Dfs(N, 0, matrix, visited);
if (visited.Contains(false))
count++;
// Resume original state
matrix[from[i], to[i]] = matrix[to[i], from[i]] = 1;
}
Console.WriteLine($"{count}");
}
private static void Dfs(int nodeNum, int v, int[,] matrix, bool[] visited) {
visited[v] = true;
for (var i = 0; i < nodeNum; i++) {
if (matrix[v, i] == 0)
continue;
if (visited[i])
continue;
Dfs(nodeNum, i, matrix, visited);
}
}
}
|
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 379
| 6
|
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 min = long.MaxValue;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
for (int k = j + 1; k < N; k++) {
for (int l = k + 1; l < N; l++) {
long w0 = new long[] { X[i], X[j], X[k], X[l] }.Min();
long w1 = new long[] { X[i], X[j], X[k], X[l] }.Max();
long h0 = new long[] { Y[i], Y[j], Y[k], Y[l] }.Min();
long h1 = new long[] { Y[i], Y[j], Y[k], Y[l] }.Max();
long ar = (w1 - w0) * (h1 - h0);
if (ar == 0)
continue; // 無いはず
int cnt = 0;
for (int m = 0; m < N; m++) {
if (InRange(X[m], w0, w1) && InRange(Y[m], h0, h1))
cnt++;
}
if (cnt >= K) {
min = Math.Min(min, ar);
}
}
}
}
}
Console.WriteLine(min);
}
bool InRange(long t, long l, long r) {
return l <= t && t <= r; // inclusive;
}
int N, K;
long[] X, Y;
public Sol() {
var d = ria();
N = d[0];
K = d[1];
X = new long[N];
Y = new long[N];
for (int i = 0; i < N; i++) {
d = ria();
X[i] = d[0];
Y[i] = d[1];
}
}
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 min = long.MaxValue;
for (int i = 0; i < N; i++) {
for (int j = i; j < N; j++) {
for (int k = j; k < N; k++) {
for (int l = k; l < N; l++) {
long w0 = new long[] { X[i], X[j], X[k], X[l] }.Min();
long w1 = new long[] { X[i], X[j], X[k], X[l] }.Max();
long h0 = new long[] { Y[i], Y[j], Y[k], Y[l] }.Min();
long h1 = new long[] { Y[i], Y[j], Y[k], Y[l] }.Max();
long ar = (w1 - w0) * (h1 - h0);
if (ar == 0)
continue; // 無いはず
int cnt = 0;
for (int m = 0; m < N; m++) {
if (InRange(X[m], w0, w1) && InRange(Y[m], h0, h1))
cnt++;
}
if (cnt >= K) {
min = Math.Min(min, ar);
}
}
}
}
}
Console.WriteLine(min);
}
bool InRange(long t, long l, long r) {
return l <= t && t <= r; // inclusive;
}
int N, K;
long[] X, Y;
public Sol() {
var d = ria();
N = d[0];
K = d[1];
X = new long[N];
Y = new long[N];
for (int i = 0; i < N; i++) {
d = ria();
X[i] = d[0];
Y[i] = d[1];
}
}
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));
}
}
|
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 712
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
string s = sc.Next();
string answer = s.Substring(0, s.Length - 7);
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();
string s = sc.Next();
string answer = s.Substring(0, s.Length - 8);
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, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 366
| 2
|
using System;
public class Hello {
public static void Main() {
var s = Console.ReadLine();
var l = s.LastIndexOf("FESTIVAL");
Console.WriteLine(s.Substring(0, l + 1));
}
}
|
using System;
public class Hello {
public static void Main() {
var s = Console.ReadLine();
var l = s.LastIndexOf("FESTIVAL");
Console.WriteLine(s.Substring(0, l));
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 53
| 2
|
using System;
class Program {
static void Main() {
var s = Console.ReadLine();
Console.WriteLine(s.Substring(0, s.IndexOf("FESTIVAL")));
}
}
|
using System;
class Program {
static void Main() {
var s = Console.ReadLine();
Console.WriteLine(s.Substring(0, s.LastIndexOf("FESTIVAL")));
}
}
|
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
| 8
| 44
| 2
|
using System;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
string str = args[0];
int len = str.Length;
Console.WriteLine(str.Substring(0, len - 8));
}
}
}
|
using System;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
int len = str.Length;
Console.WriteLine(str.Substring(0, len - 8));
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 53
| 9
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
string S = re.s();
for (int i = 0; i + 4 < S.Length; i++) {
sb.Append(S[i]);
}
sb.Append("\n");
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 1000000007; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
ReadData re;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
re = new ReadData();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
string S = re.s();
for (int i = 0; i + 8 < S.Length; i++) {
sb.Append(S[i]);
}
sb.Append("\n");
}
}
class ReadData {
string[] str;
int counter;
public ReadData() { counter = 0; }
public string s() {
if (counter == 0) {
str = Console.ReadLine().Split(' ');
counter = str.Length;
}
counter--;
return str[str.Length - counter - 1];
}
public int i() { return int.Parse(s()); }
public long l() { return long.Parse(s()); }
public double d() { return double.Parse(s()); }
public int[] ia(int N) {
int[] ans = new int[N];
for (int j = 0; j < N; j++) {
ans[j] = i();
}
return ans;
}
public int[] ia() {
str = Console.ReadLine().Split(' ');
counter = 0;
int[] ans = new int[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = int.Parse(str[j]);
}
return ans;
}
public long[] la(int N) {
long[] ans = new long[N];
for (int j = 0; j < N; j++) {
ans[j] = l();
}
return ans;
}
public long[] la() {
str = Console.ReadLine().Split(' ');
counter = 0;
long[] ans = new long[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = long.Parse(str[j]);
}
return ans;
}
public double[] da(int N) {
double[] ans = new double[N];
for (int j = 0; j < N; j++) {
ans[j] = d();
}
return ans;
}
public double[] da() {
str = Console.ReadLine().Split(' ');
counter = 0;
double[] ans = new double[str.Length];
for (int j = 0; j < str.Length; j++) {
ans[j] = double.Parse(str[j]);
}
return ans;
}
public List<int>[] g(int N, int[] f, int[] t) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < f.Length; j++) {
ans[f[j]].Add(t[j]);
ans[t[j]].Add(f[j]);
}
return ans;
}
public List<int>[] g(int N, int M) {
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
public List<int>[] g() {
int N = i();
int M = i();
List<int>[] ans = new List<int>[N];
for (int j = 0; j < N; j++) {
ans[j] = new List<int>();
}
for (int j = 0; j < M; j++) {
int f = i() - 1;
int t = i() - 1;
ans[f].Add(t);
ans[t].Add(f);
}
return ans;
}
}
public static class Define { public const long mod = 1000000007; }
public static class Debug {
public static void Print(double[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(double[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(double[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(long[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(long[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(long[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
public static void Print(int[,,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
for (int l = 0; l < k.GetLength(2); l++) {
Console.Write(k[i, j, l] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
}
public static void Print(int[,] k) {
for (int i = 0; i < k.GetLength(0); i++) {
for (int j = 0; j < k.GetLength(1); j++) {
Console.Write(k[i, j] + " ");
}
Console.WriteLine();
}
}
public static void Print(int[] k) {
for (int i = 0; i < k.Length; i++) {
Console.WriteLine(k[i]);
}
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 203]]
| 8
| 1,713
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
var n = long.Parse(Console.ReadLine());
long[] d = Console.ReadLine().Split().Select(long.Parse).ToArray();
var m = long.Parse(Console.ReadLine());
long[] t = Console.ReadLine().Split().Select(long.Parse).ToArray();
var dic = new Dictionary<long, long>();
for (int i = 0; i < n; i++) {
if (!dic.ContainsKey(d[i]))
dic.Add(d[i], 1);
else
dic[d[i]]++;
}
var ans = "Yes";
for (int i = 0; i < m; i++) {
if (!dic.ContainsKey(t[i])) {
ans = "No";
break;
} else {
if (dic[t[i]] > 0) {
dic[t[i]]--;
} else {
ans = "No";
break;
}
}
}
// 出力
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
var n = long.Parse(Console.ReadLine());
long[] d = Console.ReadLine().Split().Select(long.Parse).ToArray();
var m = long.Parse(Console.ReadLine());
long[] t = Console.ReadLine().Split().Select(long.Parse).ToArray();
var dic = new Dictionary<long, long>();
for (int i = 0; i < n; i++) {
if (!dic.ContainsKey(d[i]))
dic.Add(d[i], 1);
else
dic[d[i]]++;
}
var ans = "YES";
for (int i = 0; i < m; i++) {
if (!dic.ContainsKey(t[i])) {
ans = "NO";
break;
} else {
if (dic[t[i]] > 0) {
dic[t[i]]--;
} else {
ans = "NO";
break;
}
}
}
// 出力
Console.WriteLine(ans);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
| 8
| 277
| 6
|
using System.Collections.Generic;
using System;
public class Hello {
public static void Main() {
var d = new Dictionary<int, int>();
var d2 = new Dictionary<int, int>();
Console.ReadLine();
string[] line = Console.ReadLine().Trim().Split(' ');
setDict(d, line);
Console.ReadLine();
string[] line2 = Console.ReadLine().Trim().Split(' ');
setDict(d2, line2);
Console.WriteLine(compDict(d, d2) ? "YES" : "NO");
}
public static bool compDict(Dictionary<int, int> d, Dictionary<int, int> d2) {
foreach (var x in d2)
if (!d2.ContainsKey(x.Key))
return false;
else if (d[x.Key] < x.Value)
return false;
return true;
}
public static void setDict(Dictionary<int, int> d, string[] a) {
for (int i = 0; i < a.Length; i++) {
var w = int.Parse(a[i]);
if (d.ContainsKey(w))
d[w]++;
else
d[w] = 1;
}
}
}
|
using System.Collections.Generic;
using System;
public class Hello {
public static void Main() {
var d = new Dictionary<int, int>();
var d2 = new Dictionary<int, int>();
Console.ReadLine();
string[] line = Console.ReadLine().Trim().Split(' ');
setDict(d, line);
Console.ReadLine();
string[] line2 = Console.ReadLine().Trim().Split(' ');
setDict(d2, line2);
Console.WriteLine(compDict(d, d2) ? "YES" : "NO");
}
public static bool compDict(Dictionary<int, int> d, Dictionary<int, int> d2) {
foreach (var x in d2)
if (!d.ContainsKey(x.Key))
return false;
else if (d[x.Key] < x.Value)
return false;
return true;
}
public static void setDict(Dictionary<int, int> d, string[] a) {
for (int i = 0; i < a.Length; i++) {
var w = int.Parse(a[i]);
if (d.ContainsKey(w))
d[w]++;
else
d[w] = 1;
}
}
}
|
[["-", 8, 57, 15, 241, 0, 213, 63, 214, 205, 22], ["+", 8, 57, 15, 241, 0, 213, 63, 214, 205, 22]]
| 8
| 278
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace atcoder {
class Program {
static void Main(string[] args) {
var all = int.Parse(Console.ReadLine());
var allSet =
Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToList();
var need = int.Parse(Console.ReadLine());
var needSet =
Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToList();
allSet.Sort();
needSet.Sort();
int index = 0;
for (int j = 0; j < needSet.Count; j++) {
int now = needSet[j];
for (int i = index; i <= allSet.Count; i++) {
if (i == allSet.Count) {
Console.WriteLine("NO");
return;
}
if (now == allSet[i]) {
index = i + 1;
break;
}
}
Console.WriteLine("YES");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace atcoder {
class Program {
static void Main(string[] args) {
var all = int.Parse(Console.ReadLine());
var allSet =
Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToList();
var need = int.Parse(Console.ReadLine());
var needSet =
Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToList();
allSet.Sort();
needSet.Sort();
int index = 0;
for (int j = 0; j < needSet.Count; j++) {
int now = needSet[j];
for (int i = index; i <= allSet.Count; i++) {
if (i == allSet.Count) {
Console.WriteLine("NO");
return;
}
if (now == allSet[i]) {
index = i + 1;
break;
}
}
}
Console.WriteLine("YES");
}
}
}
|
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 236
| 2
|
using System;
class Program {
static void Main(string[] args) {
int n;
int sum = 100000;
n = int.Parse(Console.ReadLine());
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
string[] s = Console.ReadLine().Split(' ');
a[i] = int.Parse(s[0]);
b[i] = int.Parse(s[1]);
sum -= b[i] - a[i];
}
Console.WriteLine(sum);
}
}
|
using System;
class Program {
static void Main(string[] args) {
int n;
int sum = 0;
n = int.Parse(Console.ReadLine());
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
string[] s = Console.ReadLine().Split(' ');
a[i] = int.Parse(s[0]);
b[i] = int.Parse(s[1]);
sum += b[i] - a[i] + 1;
}
Console.WriteLine(sum);
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 144
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main() {
int a, b, c;
int hito = 0;
c = int.Parse(Console.ReadLine());
for (int i = 0; i < c; i++) {
string[] str =
Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得
a = int.Parse(str[0]); //数値で受け取りたい場合は変換する
b = int.Parse(str[1]);
if ((b - a) == 0) {
hito++;
} else {
hito += b - a;
}
}
Console.Write(hito);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main() {
int a, b, c;
int hito = 0;
c = int.Parse(Console.ReadLine());
for (int i = 0; i < c; i++) {
string[] str =
Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得
a = int.Parse(str[0]); //数値で受け取りたい場合は変換する
b = int.Parse(str[1]);
if ((b - a) == 0) {
hito++;
} else {
hito += b - a + 1;
}
}
Console.WriteLine(hito);
}
}
}
|
[["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
| 8
| 158
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC073_C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var A = new List<long>();
for (int i = 0; i < N; i++) {
A.Add(long.Parse(Console.ReadLine()));
}
A.Sort();
var count = 1;
var ansCount = 0;
for (int i = 0; i < N; i++) {
if (i == N - 2) {
if (A[i] == A[i + 1]) {
count++;
if (count % 2 == 0) {
break;
} else {
ansCount++;
}
}
if (count % 2 != 0) {
ansCount += 2;
break;
} else {
ansCount++;
break;
}
}
if (A[i] != A[i + 1]) {
if (count % 2 == 0) {
count = 1;
continue;
} else {
count = 1;
ansCount++;
continue;
}
} else {
count++;
continue;
}
}
Console.WriteLine(ansCount);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC073_C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var A = new List<long>();
for (int i = 0; i < N; i++) {
A.Add(long.Parse(Console.ReadLine()));
}
A.Sort();
var count = 1;
var ansCount = 0;
for (int i = 0; i < N; i++) {
if (i == N - 2) {
if (A[i] == A[i + 1]) {
count++;
if (count % 2 == 0) {
break;
} else {
ansCount++;
break;
}
}
if (count % 2 != 0) {
ansCount += 2;
break;
} else {
ansCount++;
break;
}
}
if (A[i] != A[i + 1]) {
if (count % 2 == 0) {
count = 1;
continue;
} else {
count = 1;
ansCount++;
continue;
}
} else {
count++;
continue;
}
}
Console.WriteLine(ansCount);
}
}
}
|
[["+", 64, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 75, 196, 0, 93, 0, 35]]
| 8
| 265
| 2
|
using System;
using System.Reflection;
using System.Linq.Expressions;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
public class Program {
static int[] getKeys(char delimiter) {
var Keys = Console.ReadLine().Split(' ');
int N = Keys.Length;
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Keys[i]);
}
return Ns;
}
static void Show<T>(T[,] map) {
int H = map.GetLength(0);
int W = map.GetLength(1);
Console.WriteLine("-------------------------");
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Console.Write(map[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine("-------------------------");
}
static void Show<T>(T[,] map, string delimiter) {
int H = map.GetLength(0);
int W = map.GetLength(1);
Console.WriteLine("-------------------------");
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Console.Write(map[i, j] + delimiter);
}
Console.WriteLine();
}
Console.WriteLine("-------------------------");
}
static void Show<T>(IEnumerable<T> ts) {
foreach (var item in ts) {
Console.Write(item + " ");
}
Console.WriteLine();
}
static void Show<T>(IEnumerable<T> ts, string delimiter) {
foreach (var item in ts) {
Console.Write(item + delimiter);
}
Console.WriteLine();
}
static void Main() {
int N = int.Parse(Console.ReadLine());
Dictionary<int, int> History = new Dictionary<int, int>();
int a;
for (int i = 0; i < N; i++) {
a = int.Parse(Console.ReadLine());
if (!History.ContainsKey(a)) {
History.Add(a, a);
}
if (History[a] == 0) {
History[a] = a;
} else {
History[a] = 0;
}
}
Console.WriteLine(History.Values.Sum());
}
}
}
|
using System;
using System.Reflection;
using System.Linq.Expressions;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
public class Program {
static int[] getKeys(char delimiter) {
var Keys = Console.ReadLine().Split(' ');
int N = Keys.Length;
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Keys[i]);
}
return Ns;
}
static void Show<T>(T[,] map) {
int H = map.GetLength(0);
int W = map.GetLength(1);
Console.WriteLine("-------------------------");
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Console.Write(map[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine("-------------------------");
}
static void Show<T>(T[,] map, string delimiter) {
int H = map.GetLength(0);
int W = map.GetLength(1);
Console.WriteLine("-------------------------");
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Console.Write(map[i, j] + delimiter);
}
Console.WriteLine();
}
Console.WriteLine("-------------------------");
}
static void Show<T>(IEnumerable<T> ts) {
foreach (var item in ts) {
Console.Write(item + " ");
}
Console.WriteLine();
}
static void Show<T>(IEnumerable<T> ts, string delimiter) {
foreach (var item in ts) {
Console.Write(item + delimiter);
}
Console.WriteLine();
}
static void Main() {
int N = int.Parse(Console.ReadLine());
Dictionary<int, int> History = new Dictionary<int, int>();
int a;
for (int i = 0; i < N; i++) {
a = int.Parse(Console.ReadLine());
if (!History.ContainsKey(a)) {
History.Add(a, 1);
continue;
}
if (History[a] == 0) {
History[a] = 1;
} else {
History[a] = 0;
}
}
Console.WriteLine(History.Values.Sum());
}
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 563
| 6
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication {
class Program {
static void Main() { new Solution().answer(); }
}
class Solution {
string N, M;
string[] M_split = new string[2];
int N1;
int T = 0;
public Solution() {
N = Console.ReadLine().ToString();
N1 = Convert.ToInt32(N);
string[] A = new string[N1];
int i;
List<string> result = new List<string>();
for (i = 1; i <= N1; i++) {
M = Console.ReadLine();
result.Add(M);
}
result.Sort();
int k = result.Count;
for (i = 0; i <= k - 1; i++) {
if (i + 1 <= k - 1) {
if (result[i] == result[i + 1]) {
i++;
} else {
T++;
}
}
}
}
public void answer() { Console.WriteLine(T.ToString()); }
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication {
class Program {
static void Main() { new Solution().answer(); }
}
class Solution {
string N, M;
string[] M_split = new string[2];
int N1;
int T = 0;
public Solution() {
N = Console.ReadLine().ToString();
N1 = Convert.ToInt32(N);
string[] A = new string[N1];
int i;
List<string> result = new List<string>();
for (i = 1; i <= N1; i++) {
M = Console.ReadLine();
result.Add(M);
}
result.Sort();
int k = result.Count;
for (i = 0; i <= k - 1; i++) {
if (i + 1 <= k - 1) {
if (result[i] == result[i + 1]) {
i++;
} else {
T++;
}
} else {
T++;
}
}
}
public void answer() { Console.WriteLine(T.ToString()); }
}
}
|
[["+", 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
| 259
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;
class MyUtil {
public static void AssertEquals<T>(T expected, T actual,
[CallerLineNumber] int lno = 0)
where T : IComparable {
if (expected.CompareTo(actual) != 0) {
WriteLine($"Assertion Error at line {lno}:");
WriteLine($"\texpected: {expected}");
WriteLine($"\t actual: {actual}");
Environment.Exit(1);
}
}
public static int Gcd(int a, int b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static void Swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
public static void WarshallFloyd(int[,] d, int v) {
for (int k = 0; k < v; k++)
for (int i = 0; i < v; i++)
for (int j = 0; j < v; j++)
d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
}
public static bool NextPermutation<T>(T[] a)
where T : IComparable {
if (a.Length <= 1)
return false;
for (int i = a.Length - 1; i > 0; i--) {
int k = i - 1;
if (a[k].CompareTo(a[i]) < 0) {
int j = a.Length - 1;
while (a[k].CompareTo(a[j]) >= 0) {
j--;
}
Swap(ref a[k], ref a[j]);
Array.Reverse(a, i, a.Length - i);
return true;
}
}
Array.Reverse(a);
return false;
}
public static int[] ReadIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
public static long[] ReadLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
}
class Program {
static int res;
static bool[] used;
static int R;
static int[] rs;
static int[,] d;
static void dfs(int c, int las, int dist) {
if (c == R) {
if (res > dist)
res = dist;
return;
}
for (int i = 0; i < R; i++) {
if (!used[i]) {
used[i] = true;
if (las == -1)
dfs(c + 1, i, 0);
else
dfs(c + 1, i, dist + d[rs[las], rs[i]]);
used[i] = false;
}
}
}
public static void Main() {
int inf = int.MaxValue;
var tmp = ReadIntArray();
int n = tmp[0], m = tmp[1], r = tmp[2];
rs = ReadIntArray();
for (int i = 0; i < r; i++)
rs[i]--;
Array.Sort(rs);
d = new int[n, n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i != j)
d[i, j] = inf;
for (int i = 0; i < m; i++) {
tmp = ReadIntArray();
int a = tmp[0], b = tmp[1], c = tmp[2];
a--;
b--;
if (d[a, b] > c) {
d[a, b] = c;
d[b, a] = c;
}
}
WarshallFloyd(d, n);
res = inf;
used = new bool[8];
R = r;
dfs(0, -1, 0);
WriteLine(res);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;
class MyUtil {
public static void AssertEquals<T>(T expected, T actual,
[CallerLineNumber] int lno = 0)
where T : IComparable {
if (expected.CompareTo(actual) != 0) {
WriteLine($"Assertion Error at line {lno}:");
WriteLine($"\texpected: {expected}");
WriteLine($"\t actual: {actual}");
Environment.Exit(1);
}
}
public static int Gcd(int a, int b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
var r = a % b;
a = b;
b = r;
}
return a;
}
public static void Swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
public static void WarshallFloyd(int[,] d, int v) {
for (int k = 0; k < v; k++)
for (int i = 0; i < v; i++)
for (int j = 0; j < v; j++)
d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
}
public static bool NextPermutation<T>(T[] a)
where T : IComparable {
if (a.Length <= 1)
return false;
for (int i = a.Length - 1; i > 0; i--) {
int k = i - 1;
if (a[k].CompareTo(a[i]) < 0) {
int j = a.Length - 1;
while (a[k].CompareTo(a[j]) >= 0) {
j--;
}
Swap(ref a[k], ref a[j]);
Array.Reverse(a, i, a.Length - i);
return true;
}
}
Array.Reverse(a);
return false;
}
public static int[] ReadIntArray() {
return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
public static long[] ReadLongArray() {
return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
}
class Program {
static int res;
static bool[] used;
static int R;
static int[] rs;
static int[,] d;
static void dfs(int c, int las, int dist) {
if (c == R) {
if (res > dist)
res = dist;
return;
}
for (int i = 0; i < R; i++) {
if (!used[i]) {
used[i] = true;
if (las == -1)
dfs(c + 1, i, 0);
else
dfs(c + 1, i, dist + d[rs[las], rs[i]]);
used[i] = false;
}
}
}
public static void Main() {
int inf = (1 << 29);
var tmp = ReadIntArray();
int n = tmp[0], m = tmp[1], r = tmp[2];
rs = ReadIntArray();
for (int i = 0; i < r; i++)
rs[i]--;
Array.Sort(rs);
d = new int[n, n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i != j)
d[i, j] = inf;
for (int i = 0; i < m; i++) {
tmp = ReadIntArray();
int a = tmp[0], b = tmp[1], c = tmp[2];
a--;
b--;
if (d[a, b] > c) {
d[a, b] = c;
d[b, a] = c;
}
}
WarshallFloyd(d, n);
res = inf;
used = new bool[8];
R = r;
dfs(0, -1, 0);
WriteLine(res);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 31, 203], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 17, 151], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 23, 0, 25]]
| 8
| 912
| 8
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static string[] input = Console.ReadLine().Split(' ');
static long n = long.Parse(input[0]);
static long m = long.Parse(input[1]);
static int r = int.Parse(input[2]);
static long[,] moveMatrix = new long[n, n];
static long[] nums =
Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
static List<int> numListOri =
Enumerable.Range(0, r).ToList(); // 0,1,...,n-1のn個入ったリスト。
static List<int> numListEnd =
new List<int>(); //生成用のリスト。最初から値が左側に入っていても良い。
static long answer = long.MaxValue;
static void Main() {
for (int i = 0; i < r; i++)
nums[i]--;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
moveMatrix[i, j] = 9999999999999;
moveMatrix[j, i] = 9999999999999;
}
}
for (long i = 0; i < m; i++) {
long[] numsSub = Array.ConvertAll(Console.ReadLine().Split(' '),
long.Parse); //1行ごとに受け取る
moveMatrix[numsSub[0] - 1, numsSub[1] - 1] = numsSub[2];
moveMatrix[numsSub[1] - 1, numsSub[0] - 1] = numsSub[2];
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (moveMatrix[i, j] > moveMatrix[i, k] + moveMatrix[k, j])
moveMatrix[i, j] = moveMatrix[i, k] + moveMatrix[k, j]; //距離の更新
}
}
}
Permutation(numListOri, numListEnd); //順列の生成関数
Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。
}
static void Permutation(List<int> numListOri,
List<int> numListEnd) //順列の生成関数
{
for (int i = 0; i < numListOri.Count();
i++) // numListOriの要素を全通り移していく。
{
int x = numListOri[i]; //移動する要素
numListEnd.Add(x);
numListOri.RemoveAt(i);
if (numListOri.Count() > 0)
Permutation(numListOri, numListEnd); //さらに移動
else {
long memo = 0;
for (int j = 0; j < numListEnd.Count() - 1; j++) {
memo += moveMatrix[nums[numListEnd[i]], nums[numListEnd[i + 1]]];
}
answer = Math.Min(memo, answer);
}
numListOri.Insert(i, x); // listOriginalに戻す
numListEnd.RemoveAt(numListEnd.Count() - 1);
}
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static string[] input = Console.ReadLine().Split(' ');
static long n = long.Parse(input[0]);
static long m = long.Parse(input[1]);
static int r = int.Parse(input[2]);
static long[,] moveMatrix = new long[n, n];
static long[] nums =
Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
static List<int> numListOri =
Enumerable.Range(0, r).ToList(); // 0,1,...,n-1のn個入ったリスト。
static List<int> numListEnd =
new List<int>(); //生成用のリスト。最初から値が左側に入っていても良い。
static long answer = long.MaxValue;
static void Main() {
for (int i = 0; i < r; i++)
nums[i]--;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
moveMatrix[i, j] = 9999999999999;
moveMatrix[j, i] = 9999999999999;
}
}
for (long i = 0; i < m; i++) {
long[] numsSub = Array.ConvertAll(Console.ReadLine().Split(' '),
long.Parse); //1行ごとに受け取る
moveMatrix[numsSub[0] - 1, numsSub[1] - 1] = numsSub[2];
moveMatrix[numsSub[1] - 1, numsSub[0] - 1] = numsSub[2];
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (moveMatrix[i, j] > moveMatrix[i, k] + moveMatrix[k, j])
moveMatrix[i, j] = moveMatrix[i, k] + moveMatrix[k, j]; //距離の更新
}
}
}
Permutation(numListOri, numListEnd); //順列の生成関数
Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。
}
static void Permutation(List<int> numListOri,
List<int> numListEnd) //順列の生成関数
{
for (int i = 0; i < numListOri.Count();
i++) // numListOriの要素を全通り移していく。
{
int x = numListOri[i]; //移動する要素
numListEnd.Add(x);
numListOri.RemoveAt(i);
if (numListOri.Count() > 0)
Permutation(numListOri, numListEnd); //さらに移動
else {
long memo = 0;
for (int j = 0; j < numListEnd.Count() - 1; j++) {
memo += moveMatrix[nums[numListEnd[j]], nums[numListEnd[j + 1]]];
}
// Console.WriteLine(memo+" "+nums[numListEnd[0]]+nums[numListEnd[1]]);
answer = Math.Min(memo, answer);
}
numListOri.Insert(i, x); // listOriginalに戻す
numListEnd.RemoveAt(numListEnd.Count() - 1);
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22]]
| 8
| 619
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
// using System.Numerics;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
Scanner cin = new Scanner();
Random rnd = new Random();
Stopwatch sw = new Stopwatch();
readonly int[] dd = { 0, 1, 0, -1, 0 };
readonly int mod = 1000000007;
readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int N, R;
long[,] D;
long ans = long.MaxValue;
int[] E;
void solve() {
N = cin.nextint;
int M = cin.nextint;
R = cin.nextint;
E = cin.scanint.Select(i => i - 1).ToArray();
D = new long[N, N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
D[i, j] = long.MaxValue;
}
}
for (int i = 0; i < M; i++) {
int a = cin.nextint - 1;
int b = cin.nextint - 1;
int c = cin.nextint;
D[a, b] = c;
D[b, a] = c;
}
for (int i = 0; i < N; i++) {
D[i, i] = 0;
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
D[i, j] = Math.Min(D[i, j], D[i, k] + D[k, j]);
}
}
}
calc(0, 0, -1);
WriteLine(ans);
}
void calc(int road, long sum, int before) {
// Write(before + " ");
if (road == (1 << R) - 1) {
ans = Math.Min(ans, sum);
return;
}
for (int i = 0; i < R; i++) {
if (before == -1) {
calc(road | 1 << i, 0, i);
} else {
if ((road >> i & 1) == 1)
continue;
// WriteLine(road);
calc(road | 1 << i, sum + D[E[i], E[before]], i);
}
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan {
get { return ReadLine().Split(); }
}
public int[] scanint {
get { return Array.ConvertAll(scan, int.Parse); }
}
public long[] scanlong {
get { return Array.ConvertAll(scan, long.Parse); }
}
public double[] scandouble {
get { return Array.ConvertAll(scan, double.Parse); }
}
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint {
get { return int.Parse(next); }
}
public long nextlong {
get { return long.Parse(next); }
}
public double nextdouble {
get { return double.Parse(next); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
// using System.Numerics;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
Scanner cin = new Scanner();
Random rnd = new Random();
Stopwatch sw = new Stopwatch();
readonly int[] dd = { 0, 1, 0, -1, 0 };
readonly int mod = 1000000007;
readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int N, R;
long[,] D;
long ans = long.MaxValue;
int[] E;
void solve() {
N = cin.nextint;
int M = cin.nextint;
R = cin.nextint;
E = cin.scanint.Select(i => i - 1).ToArray();
D = new long[N, N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
D[i, j] = long.MaxValue / 3;
}
}
for (int i = 0; i < M; i++) {
int a = cin.nextint - 1;
int b = cin.nextint - 1;
int c = cin.nextint;
D[a, b] = c;
D[b, a] = c;
}
for (int i = 0; i < N; i++) {
D[i, i] = 0;
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
D[i, j] = Math.Min(D[i, j], D[i, k] + D[k, j]);
}
}
}
// for (int i = 0; i < N; i++)
//{
// for (int j = 0; j < N; j++)
// {
// Write(" " + D[i, j]);
// }
// WriteLine();
//}
// var Q = new Queue<int>();
// var S = new Queue<long>();
// var B = new Queue<int>();
// while (Q.Any())
//{
//}
calc(0, 0, -1);
WriteLine(ans);
}
void calc(int road, long sum, int before) {
// WriteLine(int.Parse(Convert.ToString(road, 2)).ToString("D3"));
// Write(before + " ");
if (road == (1 << R) - 1) {
ans = Math.Min(ans, sum);
return;
}
for (int i = 0; i < R; i++) {
if (before == -1) {
calc(road | 1 << i, 0, i);
} else {
if ((road >> i & 1) == 1)
continue;
// WriteLine(road);
calc(road | 1 << i, sum + D[E[i], E[before]], i);
}
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan {
get { return ReadLine().Split(); }
}
public int[] scanint {
get { return Array.ConvertAll(scan, int.Parse); }
}
public long[] scanlong {
get { return Array.ConvertAll(scan, long.Parse); }
}
public double[] scandouble {
get { return Array.ConvertAll(scan, double.Parse); }
}
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint {
get { return int.Parse(next); }
}
public long nextlong {
get { return long.Parse(next); }
}
public double nextdouble {
get { return double.Parse(next); }
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 810
| 2
|
using System;
using System.Linq;
class Program {
static void Main() {
int[] input =
Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
// int a=int.Parse(Console.ReadLine());
// string a = Console.ReadLine();
Console.WriteLine(Math.Min(input[0] - input[1], 0));
Console.ReadLine();
}
}
|
using System;
using System.Linq;
class Program {
static void Main() {
int[] input =
Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
// int a=int.Parse(Console.ReadLine());
// string a = Console.ReadLine();
Console.WriteLine(Math.Max(input[0] - input[1], 0));
Console.ReadLine();
}
}
|
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
| 8
| 80
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
using static System.Math;
class Simple {
int X, t;
void Solve() {
// input
X = io.Int;
t = io.Int;
// cal
var ans = X - t;
// ret
WriteLine(ans);
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) => new Simple().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class SimpleIO {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
public SimpleIO() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
if (st != null)
_nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
else
st = "";
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void Flush() => Out.Flush();
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
using static System.Math;
class Simple {
int X, t;
void Solve() {
// input
X = io.Int;
t = io.Int;
// cal
var ans = Max(X - t, 0);
// ret
WriteLine(ans);
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) => new Simple().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class SimpleIO {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
public SimpleIO() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
if (st != null)
_nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
else
st = "";
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void Flush() => Out.Flush();
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 341
| 5
|
using System;
using System.Text;
namespace AtCorder {
class Program {
static void Main(string[] args) {
var s = "fukuokayamaguchi";
var length = s.Length;
var sb = new StringBuilder();
for (var i = 0; i < length; i++) {
if (i % 2 != 0) {
continue;
}
sb.Append(s[i]);
}
Console.WriteLine(sb.ToString());
}
}
}
|
using System;
using System.Text;
namespace AtCorder {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
var length = s.Length;
var sb = new StringBuilder();
for (var i = 0; i < length; i++) {
if (i % 2 != 0) {
continue;
}
sb.Append(s[i]);
}
Console.WriteLine(sb.ToString());
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 98
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
class s_Atcoder {
public static void Main() {
string s = Console.ReadLine();
char[] c = s.ToCharArray();
for (int i = 0; i < s.Length; i++) {
if (i % 2 == 1) {
Console.Write(c[i]);
}
}
Console.WriteLine("");
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
class s_Atcoder {
public static void Main() {
string s = Console.ReadLine();
char[] c = s.ToCharArray();
for (int i = 0; i < s.Length; i++) {
if (i % 2 == 0) {
Console.Write(c[i]);
}
}
Console.WriteLine("");
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 99
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass {
static void Main(string[] args) { Answer(); }
public static void Answer() {
var str = Console.ReadLine();
var ans3 = "";
for (int i = 1; i < str.Length; i += 2) {
ans3 += str[i - 1];
}
Console.WriteLine(ans3);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass {
static void Main(string[] args) { Answer(); }
public static void Answer() {
var str = Console.ReadLine();
var ans3 = "";
for (int i = 1; i <= str.Length; i += 2) {
ans3 += str[i - 1];
}
Console.WriteLine(ans3);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 115
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) { Question.Exec(); }
}
public static class Question {
public static void Exec() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var dict = new Dictionary<int, int>();
for (var i = 0; i < n; ++i) {
for (var j = -1; j <= 1; ++j) {
int b = a[i] + 1;
if (dict.ContainsKey(b)) {
++dict[b];
} else {
dict.Add(b, 1);
}
}
}
int max = dict.Values.Max();
Console.WriteLine($"{max}");
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
namespace AtCoder {
class Program {
static void Main(string[] args) { Question.Exec(); }
}
public static class Question {
public static void Exec() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var dict = new Dictionary<int, int>();
for (var i = 0; i < n; ++i) {
for (var j = -1; j <= 1; ++j) {
int b = a[i] + j;
if (dict.ContainsKey(b)) {
++dict[b];
} else {
dict.Add(b, 1);
}
}
}
int max = dict.Values.Max();
Console.WriteLine($"{max}");
Console.ReadKey();
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
| 8
| 237
| 2
|
using System;
using System.Linq;
namespace _072c {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int[] s = new int[a.Max() + 2];
foreach (int i in a) {
if (i != 0) {
s[i - 1]++;
s[i]++;
s[i + 1]++;
}
}
Console.WriteLine(s.Max());
}
}
}
|
using System;
using System.Linq;
namespace _072c {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int[] s = new int[a.Max() + 2];
foreach (int i in a) {
if (i != 0) {
s[i - 1]++;
}
s[i]++;
s[i + 1]++;
}
Console.WriteLine(s.Max());
}
}
}
|
[["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 132
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
namespace ConsoleApplication6 {
class Program {
static void Main(string[] args) {
var read = Console.ReadLine();
var split = read.Split(' ');
int a = int.Parse(split[0]);
int b = int.Parse(split[1]);
long answer = 0;
answer = (a - b) * 100;
answer += 1900 * b;
answer *= (long)Math.Pow(2, b);
;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
namespace ConsoleApplication6 {
class Program {
static void Main(string[] args) {
var read = Console.ReadLine();
var split = read.Split(' ');
int a = int.Parse(split[0]);
int b = int.Parse(split[1]);
long answer = 0;
answer = (a - b) * 100;
answer += 1900 * b;
answer *= (long)Math.Pow(2, b);
Console.WriteLine(answer);
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
| 8
| 117
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
// using System.Numerics;
using static System.Math;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
void solve() {
int N = cin.nextint;
var Z = cin.nextlong;
var W = cin.nextlong;
var A = cin.scanlong;
if (N == 1) {
WriteLine(Abs(W - A[0]));
return;
}
var MAX = new long[N];
var MIN = new long[N];
MAX[N - 1] = Abs(A[N - 1] - A[N - 2]);
MIN[N - 1] = Abs(A[N - 1] - A[N - 2]);
for (int j = N - 2; j > 0; j--) {
MAX[j] = Abs(A[j - 1] - A[N - 1]);
MIN[j] = Abs(A[j - 1] - A[N - 1]);
for (int i = j + 1; i < N; i++) {
MAX[j] = Max(MAX[j], MIN[i]);
MIN[j] = Min(MIN[j], MAX[i]);
}
}
long ans = Abs(W - A[N - 1]);
int id = N;
for (int i = 1; i < N; i++) {
if (ans < MAX[i]) {
id = i;
ans = MAX[i];
}
}
WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan {
get { return ReadLine().Split(); }
}
public int[] scanint {
get { return Array.ConvertAll(scan, int.Parse); }
}
public long[] scanlong {
get { return Array.ConvertAll(scan, long.Parse); }
}
public double[] scandouble {
get { return Array.ConvertAll(scan, double.Parse); }
}
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint {
get { return int.Parse(next); }
}
public long nextlong {
get { return long.Parse(next); }
}
public double nextdouble {
get { return double.Parse(next); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
// using System.Numerics;
using static System.Math;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().solve();
Out.Flush();
}
Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
readonly int mod = 1000000007;
void solve() {
int N = cin.nextint;
var Z = cin.nextlong;
var W = cin.nextlong;
var A = cin.scanlong;
if (N == 1) {
WriteLine(Abs(W - A[0]));
return;
}
var MAX = new long[N];
var MIN = new long[N];
MAX[N - 1] = Abs(A[N - 1] - A[N - 2]);
MIN[N - 1] = Abs(A[N - 1] - A[N - 2]);
for (int j = N - 2; j > 0; j--) {
MAX[j] = Abs(A[j - 1] - A[N - 1]);
MIN[j] = Abs(A[j - 1] - A[N - 1]);
for (int i = j + 1; i < N; i++) {
MAX[j] = Max(MAX[j], MIN[i]);
MIN[j] = Min(MIN[j], MAX[i]);
}
}
long ans = Abs(W - A[N - 1]);
int id = N;
for (int i = 1; i < N; i++) {
if (ans < MIN[i]) {
id = i;
ans = MIN[i];
}
}
WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] scan {
get { return ReadLine().Split(); }
}
public int[] scanint {
get { return Array.ConvertAll(scan, int.Parse); }
}
public long[] scanlong {
get { return Array.ConvertAll(scan, long.Parse); }
}
public double[] scandouble {
get { return Array.ConvertAll(scan, double.Parse); }
}
public string next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next;
}
}
public int nextint {
get { return int.Parse(next); }
}
public long nextlong {
get { return long.Parse(next); }
}
public double nextdouble {
get { return double.Parse(next); }
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22]]
| 8
| 652
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
List<string> s1 = Console.ReadLine().ToList().ConvertAll(x => x.ToString());
List<string> s2 = Console.ReadLine().ToList().ConvertAll(x => x.ToString());
// Console.WriteLine(string.Join(" ",s2));
s2.Reverse();
// Console.WriteLine(string.Join(" ",s2));
if (string.Join(" ", s1) == string.Join(" ", s2)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
List<string> s1 = Console.ReadLine().ToList().ConvertAll(x => x.ToString());
List<string> s2 = Console.ReadLine().ToList().ConvertAll(x => x.ToString());
// Console.WriteLine(string.Join(" ",s2));
s2.Reverse();
// Console.WriteLine(string.Join(" ",s2));
if (string.Join(" ", s1) == string.Join(" ", s2)) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 139
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Student {
class Program {
static void Main(string[] args) {
Test4();
Console.ReadKey();
}
private static void Test4() {
string str = Console.ReadLine();
string str2 = Console.ReadLine();
char[] ch = str.ToArray();
Array.Reverse(ch);
string str3 = new StringBuilder().Append(ch).ToString();
if (str2 == str3) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Student {
class Program {
static void Main(string[] args) {
Test4();
Console.ReadKey();
}
private static void Test4() {
string str = Console.ReadLine();
string str2 = Console.ReadLine();
char[] ch = str.ToArray();
Array.Reverse(ch);
string str3 = new StringBuilder().Append(ch).ToString();
if (str2 == str3) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 146
| 4
|
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var a = Console.ReadLine().Reverse();
var b = Console.ReadLine();
Console.WriteLine(a.SequenceEqual(b) ? "Yes" : "No");
}
}
}
|
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var a = Console.ReadLine().Reverse();
var b = Console.ReadLine();
Console.WriteLine(a.SequenceEqual(b) ? "YES" : "NO");
}
}
}
|
[["-", 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
| 93
| 4
|
using System;
using System.Linq;
namespace A___Rotation {
class Program {
static void Main(string[] args) {
var C1 = Console.ReadLine();
var C2 = Console.ReadLine();
Console.WriteLine(
string.Compare(C1, string.Join("", C2.Reverse())) == 0 ? "Yes" : "No");
}
}
}
|
using System;
using System.Linq;
namespace A___Rotation {
class Program {
static void Main(string[] args) {
var C1 = Console.ReadLine();
var C2 = Console.ReadLine();
Console.WriteLine(
string.Compare(C1, string.Join("", C2.Reverse())) == 0 ? "YES" : "NO");
}
}
}
|
[["-", 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
| 81
| 4
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int[] input = Console.ReadLine().Split().Select(i =>
// int.Parse(i)).ToArray(); string input= Console.ReadLine();
string[] input = new string[2];
for (int a = 0; a < 2; a++) {
input[a] = Console.ReadLine();
}
string f = "YES";
// int input =int.Parse(input[0]+""+input[3+1]+""+input[3*2+2]);
for (int a = 0; a < 3; a++) {
if (input[0][a] == input[1][2 - a])
f = "NO";
}
Console.WriteLine(f);
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int[] input = Console.ReadLine().Split().Select(i =>
// int.Parse(i)).ToArray(); string input= Console.ReadLine();
string[] input = new string[2];
for (int a = 0; a < 2; a++) {
input[a] = Console.ReadLine();
}
string f = "YES";
// int input =int.Parse(input[0]+""+input[3+1]+""+input[3*2+2]);
for (int a = 0; a < 3; a++) {
if (input[0][a] != input[1][2 - a])
f = "NO";
}
Console.WriteLine(f);
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79]]
| 8
| 142
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA();
// SolveB();
// SolveC();
// SolveD();
}
private const long MOD = 1000000007;
static void SolveA() {
string c0 = Console.ReadLine();
string c1 = Console.ReadLine();
bool ans = true;
if (c0[0] != c1[2] || c0[1] != c1[1] || c0[2] != c1[0]) {
ans = false;
}
string anss = ans ? "Yes" : "No";
Console.WriteLine(anss);
}
#region よく使う便利関数
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 int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) {
SolveA();
// SolveB();
// SolveC();
// SolveD();
}
private const long MOD = 1000000007;
static void SolveA() {
string c0 = Console.ReadLine();
string c1 = Console.ReadLine();
bool ans = true;
if (c0[0] != c1[2] || c0[1] != c1[1] || c0[2] != c1[0]) {
ans = false;
}
string anss = ans ? "YES" : "NO";
Console.WriteLine(anss);
}
#region よく使う便利関数
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 int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
#endregion
}
}
|
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
| 8
| 442
| 4
|
using System;
using System.Linq;
class prog {
static void Main() {
string s1 = Console.ReadLine();
string s2 = Console.ReadLine();
Console.WriteLine(
s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0] ? "Yes" : "No");
}
}
|
using System;
using System.Linq;
class prog {
static void Main() {
string s1 = Console.ReadLine();
string s2 = Console.ReadLine();
Console.WriteLine(
s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0] ? "YES" : "NO");
}
}
|
[["-", 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
| 80
| 4
|
using System;
public class Hello {
public static void Main() {
string A = Console.ReadLine();
string B = Console.ReadLine();
if ((A.Substring(0, 1) == B.Substring(2, 1)) &&
(A.Substring(1, 1) == B.Substring(1, 1)) &&
(A.Substring(2, 1) == B.Substring(0, 1))) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
using System;
public class Hello {
public static void Main() {
string A = Console.ReadLine();
string B = Console.ReadLine();
if ((A.Substring(0, 1) == B.Substring(2, 1)) &&
(A.Substring(1, 1) == B.Substring(1, 1)) &&
(A.Substring(2, 1) == B.Substring(0, 1))) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 119
| 4
|
using System;
public class Example {
public static void Main() {
string a = Console.ReadLine();
char[] c = Console.ReadLine().ToCharArray();
Array.Reverse(c);
if (a == new string(c))
System.Console.WriteLine("OK");
else
System.Console.WriteLine("NG");
}
}
|
using System;
public class Example {
public static void Main() {
string a = Console.ReadLine();
char[] c = Console.ReadLine().ToCharArray();
Array.Reverse(c);
if (a == new string(c))
System.Console.WriteLine("YES");
else
System.Console.WriteLine("NO");
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 80
| 4
|
using System;
class B {
static void Main() {
int N = int.Parse(Console.ReadLine());
int ans = 0;
for (int i = 0; i < 40000; i++) {
if (i * i == N)
ans = i;
}
Console.WriteLine(ans);
}
}
|
using System;
class B {
static void Main() {
int N = int.Parse(Console.ReadLine());
int ans = 0;
for (int i = 0; i < 40000; i++) {
if (i * i <= N)
ans = i * i;
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 48]]
| 8
| 68
| 4
|
using System;
using System.Linq;
using CompLib.Util;
public class Program {
public void Solve() {
var sc = new Scanner();
int n = sc.NextInt();
int i = 1;
for (; i * i < n; i++) {
}
Console.WriteLine((i - 1) * (i - 1));
}
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 System.Linq;
using CompLib.Util;
public class Program {
public void Solve() {
var sc = new Scanner();
int n = sc.NextInt();
int i = 1;
for (; i * i <= n; i++) {
}
Console.WriteLine((i - 1) * (i - 1));
}
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, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 406
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int n = sc.NextInt();
int answer = 0;
for (int i = 0; i * i < n; i++) {
if (i * i <= n) {
answer = i * i;
}
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int n = sc.NextInt();
int answer = 0;
for (int i = 0; i * i <= n; i++) {
if (i * i <= n) {
answer = i * i;
}
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 389
| 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;
public static void Main() {
// 方針
//
long n = rlong();
for (int i = 1; i < n; i++) {
if (i * i > n) {
WriteLine((i - 1) * (i - 1));
break;
}
}
}
static int binarysearchd(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] >= b) {
return 0;
} else if (a[leng - 1] < b) {
return leng;
} else {
if (a[max] < b) {
return max + 1;
}
return min + 1;
}
}
static int binarysearchu(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] > b) {
return leng;
} else if (a[leng - 1] <= b) {
return 0;
} else {
if (a[max] <= b) {
return leng - (max + 1);
}
return leng - (min + 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
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) {
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;
}
//各種読取
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); }
}
class UnionFind {
private int[] _unionfind;
private int[] _unionfind_size;
public UnionFind(int a) {
_unionfind = new int[a];
_unionfind_size = new int[a];
for (int i = 0; i < a; i++) {
_unionfind[i] = i;
_unionfind_size[i] = 1;
}
}
public int root(int x) {
if (_unionfind[x] == x)
return x;
return _unionfind[x] = root(_unionfind[x]);
}
public void unite(int a, int b) {
a = root(a);
b = root(b);
if (a == b)
return;
if (_unionfind_size[a] < _unionfind_size[b]) {
int temp = a;
a = b;
b = temp;
}
_unionfind[b] = a;
_unionfind_size[a] += _unionfind_size[b];
}
public bool same(int a, int b) { return root(a) == root(b); }
public int size(int x) { return _unionfind_size[root(x)]; }
}
class PriorityQueue {
private List<int> _priorityqueue;
public void Enqueue(int a) {
_priorityqueue.Add(a);
int num = _priorityqueue.Count - 1;
while (true) {
if (num == 0)
break;
if (_priorityqueue[(num - 1) / 2] <
_priorityqueue[num]) { //大小逆の時弄るとこ
int temp = _priorityqueue[(num - 1) / 2];
_priorityqueue[(num - 1) / 2] = _priorityqueue[num];
_priorityqueue[num] = temp;
num = (num - 1) / 2;
} else {
break;
}
}
}
public int Dequeue() {
int re = _priorityqueue[0];
int temp = _priorityqueue[0];
_priorityqueue[0] = _priorityqueue[_priorityqueue.Count - 1];
_priorityqueue[_priorityqueue.Count - 1] = temp;
_priorityqueue.Remove(_priorityqueue.Count - 1);
int num = 0;
while (true) {
int swapnum = -1;
if ((num + 1) * 2 < _priorityqueue.Count) {
if (_priorityqueue[num * 2 + 1] >
_priorityqueue[(num + 1) * 2]) { //大小逆の時弄るとこ
swapnum = num * 2 + 1;
} else {
swapnum = (num + 1) * 2;
}
} else if (num * 2 + 1 < _priorityqueue.Count) {
swapnum = num * 2 + 1;
}
if (swapnum == -1)
break;
if (_priorityqueue[swapnum] > _priorityqueue[num]) { //大小逆の時弄るとこ
temp = _priorityqueue[swapnum];
_priorityqueue[swapnum] = _priorityqueue[num];
_priorityqueue[num] = temp;
num = swapnum;
} else {
break;
}
}
return re;
}
public int Peek() { return _priorityqueue[0]; }
public int Count() { return _priorityqueue.Count; }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Dictionary hoge<string,int>
// hoge.ContainsKey(string) -> return boolean
// hoge[string] -> return int
// hoge[int] -> CE
// Dictionary hoge<int1,int2>
// hoge<int1,int2>: hoge[int1] -> return int2
// KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー -> 幅優先 ???
// var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue()
// スタック -> 深さ優先 ???
// var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek()
// stack.Count
// if (list?.Count > 0) リストが空でもnullでもない
// ソート
// list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート
// StringComparer.Ordinal とは
// Array.Sort(list1,list2);
// 出力
// foreach(var a int list){ WriteLine(a); } より
// WriteLine(string.Join("\n", list)); が速い
// var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
// Console.SetOut(sw);
// 出力部分
// Console.Out.Flush();
// 未知
// 最小費用流
// 二分探索の理解が浅い
|
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;
public static void Main() {
// 方針
//
long n = rlong();
for (int i = 1; true; i++) {
if (i * i > n) {
WriteLine((i - 1) * (i - 1));
break;
}
}
}
static int binarysearchd(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] >= b) {
return 0;
} else if (a[leng - 1] < b) {
return leng;
} else {
if (a[max] < b) {
return max + 1;
}
return min + 1;
}
}
static int binarysearchu(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] > b) {
return leng;
} else if (a[leng - 1] <= b) {
return 0;
} else {
if (a[max] <= b) {
return leng - (max + 1);
}
return leng - (min + 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
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) {
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;
}
//各種読取
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); }
}
class UnionFind {
private int[] _unionfind;
private int[] _unionfind_size;
public UnionFind(int a) {
_unionfind = new int[a];
_unionfind_size = new int[a];
for (int i = 0; i < a; i++) {
_unionfind[i] = i;
_unionfind_size[i] = 1;
}
}
public int root(int x) {
if (_unionfind[x] == x)
return x;
return _unionfind[x] = root(_unionfind[x]);
}
public void unite(int a, int b) {
a = root(a);
b = root(b);
if (a == b)
return;
if (_unionfind_size[a] < _unionfind_size[b]) {
int temp = a;
a = b;
b = temp;
}
_unionfind[b] = a;
_unionfind_size[a] += _unionfind_size[b];
}
public bool same(int a, int b) { return root(a) == root(b); }
public int size(int x) { return _unionfind_size[root(x)]; }
}
class PriorityQueue {
private List<int> _priorityqueue;
public void Enqueue(int a) {
_priorityqueue.Add(a);
int num = _priorityqueue.Count - 1;
while (true) {
if (num == 0)
break;
if (_priorityqueue[(num - 1) / 2] <
_priorityqueue[num]) { //大小逆の時弄るとこ
int temp = _priorityqueue[(num - 1) / 2];
_priorityqueue[(num - 1) / 2] = _priorityqueue[num];
_priorityqueue[num] = temp;
num = (num - 1) / 2;
} else {
break;
}
}
}
public int Dequeue() {
int re = _priorityqueue[0];
int temp = _priorityqueue[0];
_priorityqueue[0] = _priorityqueue[_priorityqueue.Count - 1];
_priorityqueue[_priorityqueue.Count - 1] = temp;
_priorityqueue.Remove(_priorityqueue.Count - 1);
int num = 0;
while (true) {
int swapnum = -1;
if ((num + 1) * 2 < _priorityqueue.Count) {
if (_priorityqueue[num * 2 + 1] >
_priorityqueue[(num + 1) * 2]) { //大小逆の時弄るとこ
swapnum = num * 2 + 1;
} else {
swapnum = (num + 1) * 2;
}
} else if (num * 2 + 1 < _priorityqueue.Count) {
swapnum = num * 2 + 1;
}
if (swapnum == -1)
break;
if (_priorityqueue[swapnum] > _priorityqueue[num]) { //大小逆の時弄るとこ
temp = _priorityqueue[swapnum];
_priorityqueue[swapnum] = _priorityqueue[num];
_priorityqueue[num] = temp;
num = swapnum;
} else {
break;
}
}
return re;
}
public int Peek() { return _priorityqueue[0]; }
public int Count() { return _priorityqueue.Count; }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Dictionary hoge<string,int>
// hoge.ContainsKey(string) -> return boolean
// hoge[string] -> return int
// hoge[int] -> CE
// Dictionary hoge<int1,int2>
// hoge<int1,int2>: hoge[int1] -> return int2
// KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー -> 幅優先 ???
// var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue()
// スタック -> 深さ優先 ???
// var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek()
// stack.Count
// if (list?.Count > 0) リストが空でもnullでもない
// ソート
// list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート
// StringComparer.Ordinal とは
// Array.Sort(list1,list2);
// 出力
// foreach(var a int list){ WriteLine(a); } より
// WriteLine(string.Join("\n", list)); が速い
// var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
// Console.SetOut(sw);
// 出力部分
// Console.Out.Flush();
// 未知
// 最小費用流
// 二分探索の理解が浅い
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 211, 0, 146]]
| 8
| 2,123
| 4
|
using System;
namespace ABC077_B {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
long m = 0;
for (long i = 1; i * i < N; i++)
m = i;
Console.WriteLine(m * m);
}
}
}
|
using System;
namespace ABC077_B {
class Program {
static void Main(string[] args) {
var N = long.Parse(Console.ReadLine());
long m = 0;
for (long i = 1; i * i <= N; i++)
m = i;
Console.WriteLine(m * m);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 70
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Program {
class MainClass {
////////////////////////////////////////////////////////////
string S, T;
void Solve() {
int N;
io.i(out N);
int ans = 0;
for (int i = 0; i * i < N; ++i) {
ans = i * i;
}
io.o(ans);
}
////////////////////////////////////////////////////////////
public static void Main() { new MainClass().Stream(); }
IO io = new IO();
Mat mat = new Mat();
void Stream() {
Solve();
io.writeFlush();
}
// void Stream() { Test(); io.writeFlush(); }
void Test() {}
#region MockMacro
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act) {
for (int i = a; i < b; ++i)
act(i);
}
void FORR(int a, int b, Action<int> act) {
for (int i = a - 1; i >= b; --i)
act(i);
}
#endregion
////////////////////////////////////////////////////////////
}
#region default
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public string[] arr => Console.ReadLine().Split(' ');
public char[] arrChar => Array.ConvertAll(arr, char.Parse);
public int[] arrInt => Array.ConvertAll(arr, int.Parse);
public long[] arrLong => Array.ConvertAll(arr, long.Parse);
public double[] arrDouble => Array.ConvertAll(arr, double.Parse);
public T i<T>() { return suitType<T>(String); }
public void i<T>(out T v) { v = suitType<T>(String); }
public void i<T, U>(out T v1, out U v2) {
i(out v1);
i(out v2);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
i(out v1);
i(out v2);
i(out v3);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
}
public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4,
out X v5) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
i(out v5);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = suitType<T>(String);
}
public void ini<T, U>(out T[] a, out U[] b, int n) {
a = new T[n];
b = new U[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<U>();
}
}
public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) {
a = new T[n];
b = new U[n];
c = new V[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<U>();
c[i] = i<V>();
}
}
public void ini<T, U>(out Tuple<T, U>[] t, int n) {
t = new Tuple<T, U>[n];
for (int j = 0; j < n; ++j) {
T i1;
U i2;
i(out i1);
i(out i2);
t[j] = Tuple.Create(i1, i2);
}
}
public void ini<T, U, V>(out Tuple<T, U, V>[] t, int n) {
t = new Tuple<T, U, V>[n];
for (int j = 0; j < n; ++j) {
T i1;
U i2;
V i3;
i(out i1);
i(out i2);
i(out i3);
t[j] = Tuple.Create(i1, i2, i3);
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
a[i, j] = i<T>();
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); }
public void o<T>(T[,] a) {
int a0 = a.GetLength(0), a1 = a.GetLength(1);
for (int i = 0; i < a0; ++i) {
for (int j = 0; j < a1 - 1; ++j)
Console.Write(a[i, j] + " ");
Console.WriteLine(a[i, a1 - 1]);
}
}
public void YN(bool f) { o(f ? "YES" : "NO"); }
public void Yn(bool f) { o(f ? "Yes" : "No"); }
public void yn(bool f) { o(f ? "yes" : "no"); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void or<T>(T a) { Console.Write(a); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
}
class PQueue<T>
where T : struct, IComparable<T> {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size;
private int type; // type=0->min
public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; }
public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) {
this.comparer = comparer;
}
public PQueue(Comparison<T> comparison) : this(16, comparison) {}
public PQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.comp = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (Compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
public bool Empty() { return !Any(); }
public bool Contains(T v) { return heap.Contains(v); }
private int Compare(T x, T y) {
return type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
}
class AssociativeArray<T> : IEnumerable {
public Dictionary<T, int> dic;
public AssociativeArray() { dic = new Dictionary<T, int>(); }
public AssociativeArray(params T[] a) {
dic = new Dictionary<T, int>();
Add(a);
}
public void Add(T a) {
if (!conK(a))
dic[a] = 0;
dic[a]++;
}
public void Add(params T[] a) {
a.Length.REP(i => {
if (!conK(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
});
}
public void Set(T k, int v) {
if (!dic.ContainsKey(k))
dic[k] = 0;
dic[k] = v;
}
public void Remove(params T[] a) {
a.Length.REP(i => {
if (conK(a[i]))
dic.Remove(a[i]);
});
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValSum => dic.Values.Sum();
public int KeyNum => dic.Keys.Count;
public int MaxVal => dic.Values.Max();
public int MinVal => dic.Values.Min();
public T MaxKey => MaxK();
public T MinKey => MinK();
public T MaxK() {
var maxV = MaxVal;
return dic.First(d => d.Value == maxV).Key;
}
public T MinK() {
var minV = MinVal;
return dic.First(d => d.Value == minV).Key;
}
public T[] MaxKeys() {
var maxV = MaxVal;
return dic.Where(kp => kp.Value == maxV)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public T[] MinKeys() {
var minV = MinVal;
return dic.Where(kp => kp.Value == minV)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public bool conK(T k) { return dic.ContainsKey(k); }
public bool anyK(params T[] k) { return k.Any(key => conK(key)); }
public bool allK(params T[] k) { return k.All(key => conK(key)); }
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
public T[] ValueSortedKey(bool inc = true) {
return (inc ? (dic.OrderBy(kp => kp.Value))
: (dic.OrderByDescending(kp => kp.Value)))
.ThenBy(kp => kp.Key)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public IEnumerator GetEnumerator() {
foreach (var kp in dic)
yield return kp;
}
//:sort->array
}
public struct edge : IComparable<edge> {
public int to;
public long cost;
public edge(int to, long cost) {
this.to = to;
this.cost = cost;
}
public int CompareTo(edge e) { return cost.CompareTo(e.cost); }
}
#endregion
#region test
// interface IField<T> { T Add(T that) ; T Subtract(T that); T
// Multiply(T that); T Devide(T that); }
#endregion
#region other
class Mat {
public long mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long ModC(long n, long r) {
if (r == 0 || n == r)
return 1;
if (n == 0)
return 0;
if (n < 0 || n < r)
throw new ArgumentException("n,r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long[,] C(int N) {
long[,] Co = new long[N + 1, N + 1];
(N + 1).REP(i => (i + 1).REP(j => Co[i, j] =
(j == 0 || j == i)
? 1L
: Co[i - 1, j - 1] + Co[i - 1, j]));
return Co;
}
public long DupC(long n, long r) { return ModC(n + r - 1, r); }
public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test
public bool isPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (long v = 3; v <= (long)Math.Sqrt(n); v += 2)
if (n % v == 0)
return false;
return true;
}
public long LCM(long a, long b) { return a * (b / GCD(a, b)); }
public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); }
public long GCD(long a, long b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public long GCD(params long[] array) {
return array.Aggregate((v, n) => GCD(v, n));
}
public T Max<T>(params T[] a) { return a.Max(); }
public T Min<T>(params T[] a) { return a.Min(); }
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public double Dis(double x1, double y1, double x2, double y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public int mDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public int[] DigArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long DigArr2Num(IEnumerable<int> enu) {
return enu.Aggregate((v, n) => v * 10 + n);
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public long Tousa(long a, long d, long n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, long n) {
return n * (2 * a + (n - 1) * d) / 2;
}
public long[] EnuDivsor(long N) {
var ret = new SortedSet<long>();
for (long i = 1; i * i <= N; i++)
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
return ret.ToArray();
}
public Dictionary<long, long> PrimeFactor(long n) {
var ret = new Dictionary<long, long>();
for (int i = 2; i * i <= n; ++i) {
if (!ret.ContainsKey(i))
ret[i] = 0;
while (n % i == 0) {
++ret[i];
n /= i;
}
}
return ret.Where(kp => kp.Value != 0)
.ToDictionary(kp => kp.Key, kp => kp.Value);
}
public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<List<int>>();
for (int i = Arr.Length - 1; i >= 0; i--)
s.Push(new List<int>() { i });
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use) {
var ret = new List<int>();
cur.ForEach(X => ret.Add(Arr[X]));
yield return ret.ToArray();
} else
for (int i = Arr.Length - 1; i >= 0; i--)
if (!cur.Contains(i))
s.Push(new List<int>(cur) { i });
}
}
public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<List<int>>();
Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] }));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use)
yield return cur.ToArray();
else
Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<string[]> enuPart(string str) {
var s = new Stack<Tuple<string, List<string>, int>>();
s.Push(Tuple.Create(str[0].ToString(), new List<string>(), 1));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item3 >= str.Length)
yield return (new List<string>(cur.Item2) { cur.Item1 }).ToArray();
else {
s.Push(Tuple.Create(cur.Item1 + str[cur.Item3],
new List<string>(cur.Item2), cur.Item3 + 1));
s.Push(Tuple.Create(str[cur.Item3].ToString(),
new List<string>(cur.Item2) { cur.Item1 },
cur.Item3 + 1));
}
}
}
//そのうちrefacter
public List<int[]> gRangedArr(int content, int rangeStart, int rangeEnd) {
var result = new List<int[]>();
_gRangedArr(content - 1, new int[content], result, rangeStart, rangeEnd);
return result;
}
private void _gRangedArr(int n, int[] Arr, List<int[]> result, int rs,
int re) {
if (n < 0) {
result.Add(Arr);
return;
}
for (int i = rs; i <= re; ++i) {
var newArr = Arr.ToArray();
newArr[n] = i;
_gRangedArr(n - 1, newArr, result, rs, re);
}
}
}
#endregion
#region Data
class TreeDis { // TODO:shortestPath
public List<Tuple<long, long>>[] g;
public long[] a2other;
private int type;
public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
g.Length.REP(i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], 1L));
g[b[i]].Add(Tuple.Create(a[i], 1L));
});
}
public void Run(long[] a, long[] b, long[] w) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public long[] a2iArr(long a) {
a2other = new long[g.Count()];
if (type == 0)
BFS(a);
else
DFS(a);
return a2other;
}
private void BFS(long a) {
var q = new Queue<Tuple<long, long>>();
q.Enqueue(Tuple.Create(a, -1L));
while (q.Count > 0) {
var c = q.Dequeue();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
q.Enqueue(Tuple.Create(v.Item1, c.Item1));
}
}
}
private void DFS(long a) {
var s = new Stack<Tuple<long, long>>();
s.Push(Tuple.Create(a, -1L));
while (s.Count > 0) {
var c = s.Pop();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
s.Push(Tuple.Create(v.Item1, c.Item1));
}
}
}
}
class ShortestPath {
protected int I = -1; //辺は1~N
protected int V; //頂点数
protected int E; //辺の数
protected bool isNonDir = true; //有向?
public long INF = (long)1e15; //初期化
public long[] cost; //重み
public List<edge>[] Adj; //隣接リスト
public void Init(int n) {
I = n + 1;
V = n;
Adj = new List<edge>[I];
for (int i = 0; i < I; ++i)
Adj[i] = new List<edge>();
}
public void AddPath(int f, int t, long c = 1) {
E++;
Adj[f].Add(new edge(t, c));
if (isNonDir)
Adj[t].Add(new edge(f, c));
}
public void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i]);
}
public bool PathExist(int t) { return cost[t] != INF; }
}
class Dijkstra : ShortestPath {
public Dijkstra(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
Run(f);
return cost[t];
}
public long MinCost(int t) { return cost[t]; }
public void Run(int f) {
cost = new long[I];
for (int i = 0; i < I; ++i)
cost[i] = INF;
cost[f] = 0;
var pq = new PQueue<edge>();
pq.Enqueue(new edge(f, 0L));
while (!pq.Empty()) {
var cur = pq.Dequeue();
if (cost[cur.to] < cur.cost)
continue;
for (int i = 0; i < Adj[cur.to].Count; ++i) {
var tmp = Adj[cur.to][i];
if (cost[tmp.to] > cur.cost + tmp.cost) {
cost[tmp.to] = cur.cost + tmp.cost;
pq.Enqueue(new edge(tmp.to, cost[tmp.to]));
}
}
}
}
}
class BellmanFord : ShortestPath {
private bool[] neg;
public BellmanFord(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
Run(f);
return cost[t];
}
public long MinCost(int t) { return cost[t]; }
public void Run(int f) {
cost = new long[I];
cost.Set(INF);
cost[f] = 0;
neg = new bool[I];
for (int i = 0; i < I - 1; i++)
for (int j = 0; j < I; ++j)
for (int k = 0; k < Adj[j].Count; ++k) {
var cur = Adj[j][k];
if (cost[cur.to] > cost[j] + cur.cost)
cost[cur.to] = cost[j] + cur.cost;
}
for (int i = 0; i < I; i++)
for (int j = 0; j < I; ++j)
for (int k = 0; k < Adj[j].Count; ++k) {
var cur = Adj[j][k];
if (cost[cur.to] > cost[j] + cur.cost) {
cost[cur.to] = cost[j] + cur.cost;
neg[cur.to] = true;
}
if (neg[j])
neg[cur.to] = true;
}
}
public bool loopExist() { return neg[I - 1]; }
}
class WF : ShortestPath {
public WF() {}
public WF(bool isNonDir) { this.isNonDir = isNonDir; }
public void Run() {}
}
class WarshallFloyd {
private int E;
private bool isNonDir;
public long INF = (long)1e15;
public long[,] BefG;
public long[,] G;
public WarshallFloyd(bool isNonDir = true) { this.isNonDir = isNonDir; }
public void Init(int n) {
E = n + 1;
G = new long[E, E];
BefG = new long[E, E];
for (int i = 0; i < E; ++i)
for (int j = 0; j < E; ++j) {
G[i, j] = INF;
BefG[i, j] = INF;
}
for (int i = 0; i < E; ++i) {
G[i, i] = 0;
BefG[i, i] = 0;
}
}
public void AddPath(int f, int t, long c = 1) {
if (isNonDir) {
G[f, t] = c;
G[t, f] = c;
BefG[f, t] = c;
BefG[t, f] = c;
} else {
G[f, t] = c;
BefG[f, t] = c;
}
}
public void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], 1);
}
public void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void Run() { G = MinCostArr(); }
public long[,] MinCostArr() {
for (int i = 0; i < E; ++i)
for (int j = 0; j < E; ++j)
for (int k = 0; k < E; ++k)
G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]);
return G;
}
//使う?使わない?
public int[] MinPath(int from, int to) {
var ret = new List<int>();
var cur = from;
while (cur != to) {
ret.Add(cur);
for (int i = 1; i < E; ++i) {
if (BefG[cur, i] + G[i, to] == G[cur, to]) {
if (i == cur)
continue;
cur = i;
break;
}
}
}
ret.Add(cur);
return ret.ToArray();
}
public bool isMinPath(int a, int b, long c) {
for (int i = 0; i < E; ++i)
if (G[i, a] + c == G[i, b])
return true;
return false;
}
//全地点間を繋ぐ最小コスト
public long MinCost() {
long orig = 0;
for (int i = 0; i < E; ++i)
for (int j = i + 1; j < E; ++j) {
bool isOrig = true;
for (int k = 0; k < E; ++k) {
if (k == i || k == j)
continue;
if (G[i, j] == G[i, k] + G[k, j]) {
isOrig = false;
break;
}
}
if (isOrig)
orig += G[i, j];
}
return orig;
}
}
class UnionFind {
int[] dat;
public void Init(int n) {
dat = new int[n + 1];
for (int i = 0; i <= n; ++i)
dat[i] = -1;
}
public void Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x == y)
return;
if (dat[y] < dat[x])
swap(ref x, ref y);
dat[x] += dat[y];
dat[y] = x;
}
public bool Find(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return dat[x] < 0 ? x : dat[x] = Root(dat[x]); }
public int Size(int x) { return -dat[Root(x)]; }
void swap(ref int a, ref int b) {
int tmp = b;
b = a;
a = tmp;
}
}
class Kruskal : ShortestPath {
public Kruskal(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long Run() {
var uf = new UnionFind();
var ret = 0L;
var L = new List<Tuple<int, int, long>>();
uf.Init(V);
for (int i = 0; i < I; ++i)
for (int j = 0; j < Adj[i].Count; ++i)
L.Add(Tuple.Create(i, Adj[i][j].to, Adj[i][j].cost));
L = L.OrderBy(t => t.Item3).ToList();
for (int i = 0; i < L.Count; ++i)
if (!uf.Find(L[i].Item1, L[i].Item2)) {
ret += L[i].Item3;
uf.Unite(L[i].Item1, L[i].Item2);
}
return ret;
}
}
#endregion
#region Ex
static class StringEX {
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) { return toInt(c.ToString()); }
public static int toInt(this char[] c) { return toInt(new string(c)); }
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0;
}
public static long toLong(this char c) { return toLong(c.ToString()); }
public static long toLong(this char[] c) { return toLong(new string(c)); }
public static string toString(this char[] c) { return new string(c); }
}
static class NumericEx {
public static string pad0<T>(this T v, int n) {
return v.ToString().PadLeft(n, '0');
}
public static double RoundOff(this double v, int n) {
return Math.Round(v, n - 1, MidpointRounding.AwayFromZero);
}
public static bool Odd(this int v) { return v % 2 != 0; }
public static bool Odd(this long v) { return v % 2 != 0; }
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Sort(a);
Array.Reverse(a);
return a;
}
public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
}
public static int[] toIntArr(this string[] a) {
return Array.ConvertAll(a, int.Parse);
}
public static long[] toLongArr(this string[] a) {
return Array.ConvertAll(a, long.Parse);
}
public static double[] toDoubleArr(this string[] a) {
return Array.ConvertAll(a, double.Parse);
}
public static char[] toCharArr(this string[] a) {
return Array.ConvertAll(a, char.Parse);
}
public static int LowerBound<T>(this T[] a, T x)
where T : IComparable {
Array.Sort(a);
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) >= 0)
ub = mid;
else
lb = mid;
}
return ub;
}
public static int UpperBound<T>(this T[] a, T x)
where T : IComparable {
Array.Sort(a);
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) > 0)
ub = mid;
else
lb = mid;
}
return ub;
}
}
static class BitEx {
public static bool Any(this BitArray b) {
foreach (bool f in b)
if (f)
return true;
return false;
}
public static bool All(this BitArray b) {
foreach (bool f in b)
if (!f)
return false;
return true;
}
public static bool None(this BitArray b) { return !Any(b); }
public static void Flip(this BitArray b, int index) {
b.Set(index, !b.Get(index));
}
}
static class IEnumerableEx {}
static class Test {
public static int add(this int a, int b) { return a + b; }
public static double add(this double a, int b) { return a + b; }
public static double add(this int a, double b) { return a + b; }
public static double add(this double a, double b) { return a + b; }
public static long add(this long a, int b) { return a + b; }
public static long add(this int a, long b) { return a + b; }
public static long add(this long a, long b) { return a + b; }
}
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Program {
class MainClass {
////////////////////////////////////////////////////////////
string S, T;
void Solve() {
int N;
io.i(out N);
int ans = 0;
for (int i = 0; i * i <= N; ++i) {
ans = i * i;
}
io.o(ans);
}
////////////////////////////////////////////////////////////
public static void Main() { new MainClass().Stream(); }
IO io = new IO();
Mat mat = new Mat();
void Stream() {
Solve();
io.writeFlush();
}
// void Stream() { Test(); io.writeFlush(); }
void Test() {}
#region MockMacro
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act) {
for (int i = a; i < b; ++i)
act(i);
}
void FORR(int a, int b, Action<int> act) {
for (int i = a - 1; i >= b; --i)
act(i);
}
#endregion
////////////////////////////////////////////////////////////
}
#region default
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public string[] arr => Console.ReadLine().Split(' ');
public char[] arrChar => Array.ConvertAll(arr, char.Parse);
public int[] arrInt => Array.ConvertAll(arr, int.Parse);
public long[] arrLong => Array.ConvertAll(arr, long.Parse);
public double[] arrDouble => Array.ConvertAll(arr, double.Parse);
public T i<T>() { return suitType<T>(String); }
public void i<T>(out T v) { v = suitType<T>(String); }
public void i<T, U>(out T v1, out U v2) {
i(out v1);
i(out v2);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
i(out v1);
i(out v2);
i(out v3);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
}
public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4,
out X v5) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
i(out v5);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = suitType<T>(String);
}
public void ini<T, U>(out T[] a, out U[] b, int n) {
a = new T[n];
b = new U[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<U>();
}
}
public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) {
a = new T[n];
b = new U[n];
c = new V[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<U>();
c[i] = i<V>();
}
}
public void ini<T, U>(out Tuple<T, U>[] t, int n) {
t = new Tuple<T, U>[n];
for (int j = 0; j < n; ++j) {
T i1;
U i2;
i(out i1);
i(out i2);
t[j] = Tuple.Create(i1, i2);
}
}
public void ini<T, U, V>(out Tuple<T, U, V>[] t, int n) {
t = new Tuple<T, U, V>[n];
for (int j = 0; j < n; ++j) {
T i1;
U i2;
V i3;
i(out i1);
i(out i2);
i(out i3);
t[j] = Tuple.Create(i1, i2, i3);
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
a[i, j] = i<T>();
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); }
public void o<T>(T[,] a) {
int a0 = a.GetLength(0), a1 = a.GetLength(1);
for (int i = 0; i < a0; ++i) {
for (int j = 0; j < a1 - 1; ++j)
Console.Write(a[i, j] + " ");
Console.WriteLine(a[i, a1 - 1]);
}
}
public void YN(bool f) { o(f ? "YES" : "NO"); }
public void Yn(bool f) { o(f ? "Yes" : "No"); }
public void yn(bool f) { o(f ? "yes" : "no"); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void or<T>(T a) { Console.Write(a); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
}
class PQueue<T>
where T : struct, IComparable<T> {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size;
private int type; // type=0->min
public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; }
public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) {
this.comparer = comparer;
}
public PQueue(Comparison<T> comparison) : this(16, comparison) {}
public PQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.comp = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (Compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
public bool Empty() { return !Any(); }
public bool Contains(T v) { return heap.Contains(v); }
private int Compare(T x, T y) {
return type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
}
class AssociativeArray<T> : IEnumerable {
public Dictionary<T, int> dic;
public AssociativeArray() { dic = new Dictionary<T, int>(); }
public AssociativeArray(params T[] a) {
dic = new Dictionary<T, int>();
Add(a);
}
public void Add(T a) {
if (!conK(a))
dic[a] = 0;
dic[a]++;
}
public void Add(params T[] a) {
a.Length.REP(i => {
if (!conK(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
});
}
public void Set(T k, int v) {
if (!dic.ContainsKey(k))
dic[k] = 0;
dic[k] = v;
}
public void Remove(params T[] a) {
a.Length.REP(i => {
if (conK(a[i]))
dic.Remove(a[i]);
});
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValSum => dic.Values.Sum();
public int KeyNum => dic.Keys.Count;
public int MaxVal => dic.Values.Max();
public int MinVal => dic.Values.Min();
public T MaxKey => MaxK();
public T MinKey => MinK();
public T MaxK() {
var maxV = MaxVal;
return dic.First(d => d.Value == maxV).Key;
}
public T MinK() {
var minV = MinVal;
return dic.First(d => d.Value == minV).Key;
}
public T[] MaxKeys() {
var maxV = MaxVal;
return dic.Where(kp => kp.Value == maxV)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public T[] MinKeys() {
var minV = MinVal;
return dic.Where(kp => kp.Value == minV)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public bool conK(T k) { return dic.ContainsKey(k); }
public bool anyK(params T[] k) { return k.Any(key => conK(key)); }
public bool allK(params T[] k) { return k.All(key => conK(key)); }
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
public T[] ValueSortedKey(bool inc = true) {
return (inc ? (dic.OrderBy(kp => kp.Value))
: (dic.OrderByDescending(kp => kp.Value)))
.ThenBy(kp => kp.Key)
.ToDictionary(kp => kp.Key, kp => kp.Value)
.Keys.ToArray();
}
public IEnumerator GetEnumerator() {
foreach (var kp in dic)
yield return kp;
}
//:sort->array
}
public struct edge : IComparable<edge> {
public int to;
public long cost;
public edge(int to, long cost) {
this.to = to;
this.cost = cost;
}
public int CompareTo(edge e) { return cost.CompareTo(e.cost); }
}
#endregion
#region test
// interface IField<T> { T Add(T that) ; T Subtract(T that); T
// Multiply(T that); T Devide(T that); }
#endregion
#region other
class Mat {
public long mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long ModC(long n, long r) {
if (r == 0 || n == r)
return 1;
if (n == 0)
return 0;
if (n < 0 || n < r)
throw new ArgumentException("n,r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long[,] C(int N) {
long[,] Co = new long[N + 1, N + 1];
(N + 1).REP(i => (i + 1).REP(j => Co[i, j] =
(j == 0 || j == i)
? 1L
: Co[i - 1, j - 1] + Co[i - 1, j]));
return Co;
}
public long DupC(long n, long r) { return ModC(n + r - 1, r); }
public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test
public bool isPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (long v = 3; v <= (long)Math.Sqrt(n); v += 2)
if (n % v == 0)
return false;
return true;
}
public long LCM(long a, long b) { return a * (b / GCD(a, b)); }
public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); }
public long GCD(long a, long b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public long GCD(params long[] array) {
return array.Aggregate((v, n) => GCD(v, n));
}
public T Max<T>(params T[] a) { return a.Max(); }
public T Min<T>(params T[] a) { return a.Min(); }
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public double Dis(double x1, double y1, double x2, double y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public int mDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public int[] DigArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long DigArr2Num(IEnumerable<int> enu) {
return enu.Aggregate((v, n) => v * 10 + n);
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public long Tousa(long a, long d, long n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, long n) {
return n * (2 * a + (n - 1) * d) / 2;
}
public long[] EnuDivsor(long N) {
var ret = new SortedSet<long>();
for (long i = 1; i * i <= N; i++)
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
return ret.ToArray();
}
public Dictionary<long, long> PrimeFactor(long n) {
var ret = new Dictionary<long, long>();
for (int i = 2; i * i <= n; ++i) {
if (!ret.ContainsKey(i))
ret[i] = 0;
while (n % i == 0) {
++ret[i];
n /= i;
}
}
return ret.Where(kp => kp.Value != 0)
.ToDictionary(kp => kp.Key, kp => kp.Value);
}
public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<List<int>>();
for (int i = Arr.Length - 1; i >= 0; i--)
s.Push(new List<int>() { i });
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use) {
var ret = new List<int>();
cur.ForEach(X => ret.Add(Arr[X]));
yield return ret.ToArray();
} else
for (int i = Arr.Length - 1; i >= 0; i--)
if (!cur.Contains(i))
s.Push(new List<int>(cur) { i });
}
}
public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<List<int>>();
Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] }));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use)
yield return cur.ToArray();
else
Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<string[]> enuPart(string str) {
var s = new Stack<Tuple<string, List<string>, int>>();
s.Push(Tuple.Create(str[0].ToString(), new List<string>(), 1));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item3 >= str.Length)
yield return (new List<string>(cur.Item2) { cur.Item1 }).ToArray();
else {
s.Push(Tuple.Create(cur.Item1 + str[cur.Item3],
new List<string>(cur.Item2), cur.Item3 + 1));
s.Push(Tuple.Create(str[cur.Item3].ToString(),
new List<string>(cur.Item2) { cur.Item1 },
cur.Item3 + 1));
}
}
}
//そのうちrefacter
public List<int[]> gRangedArr(int content, int rangeStart, int rangeEnd) {
var result = new List<int[]>();
_gRangedArr(content - 1, new int[content], result, rangeStart, rangeEnd);
return result;
}
private void _gRangedArr(int n, int[] Arr, List<int[]> result, int rs,
int re) {
if (n < 0) {
result.Add(Arr);
return;
}
for (int i = rs; i <= re; ++i) {
var newArr = Arr.ToArray();
newArr[n] = i;
_gRangedArr(n - 1, newArr, result, rs, re);
}
}
}
#endregion
#region Data
class TreeDis { // TODO:shortestPath
public List<Tuple<long, long>>[] g;
public long[] a2other;
private int type;
public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
g.Length.REP(i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], 1L));
g[b[i]].Add(Tuple.Create(a[i], 1L));
});
}
public void Run(long[] a, long[] b, long[] w) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public long[] a2iArr(long a) {
a2other = new long[g.Count()];
if (type == 0)
BFS(a);
else
DFS(a);
return a2other;
}
private void BFS(long a) {
var q = new Queue<Tuple<long, long>>();
q.Enqueue(Tuple.Create(a, -1L));
while (q.Count > 0) {
var c = q.Dequeue();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
q.Enqueue(Tuple.Create(v.Item1, c.Item1));
}
}
}
private void DFS(long a) {
var s = new Stack<Tuple<long, long>>();
s.Push(Tuple.Create(a, -1L));
while (s.Count > 0) {
var c = s.Pop();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
s.Push(Tuple.Create(v.Item1, c.Item1));
}
}
}
}
class ShortestPath {
protected int I = -1; //辺は1~N
protected int V; //頂点数
protected int E; //辺の数
protected bool isNonDir = true; //有向?
public long INF = (long)1e15; //初期化
public long[] cost; //重み
public List<edge>[] Adj; //隣接リスト
public void Init(int n) {
I = n + 1;
V = n;
Adj = new List<edge>[I];
for (int i = 0; i < I; ++i)
Adj[i] = new List<edge>();
}
public void AddPath(int f, int t, long c = 1) {
E++;
Adj[f].Add(new edge(t, c));
if (isNonDir)
Adj[t].Add(new edge(f, c));
}
public void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i]);
}
public bool PathExist(int t) { return cost[t] != INF; }
}
class Dijkstra : ShortestPath {
public Dijkstra(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
Run(f);
return cost[t];
}
public long MinCost(int t) { return cost[t]; }
public void Run(int f) {
cost = new long[I];
for (int i = 0; i < I; ++i)
cost[i] = INF;
cost[f] = 0;
var pq = new PQueue<edge>();
pq.Enqueue(new edge(f, 0L));
while (!pq.Empty()) {
var cur = pq.Dequeue();
if (cost[cur.to] < cur.cost)
continue;
for (int i = 0; i < Adj[cur.to].Count; ++i) {
var tmp = Adj[cur.to][i];
if (cost[tmp.to] > cur.cost + tmp.cost) {
cost[tmp.to] = cur.cost + tmp.cost;
pq.Enqueue(new edge(tmp.to, cost[tmp.to]));
}
}
}
}
}
class BellmanFord : ShortestPath {
private bool[] neg;
public BellmanFord(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
Run(f);
return cost[t];
}
public long MinCost(int t) { return cost[t]; }
public void Run(int f) {
cost = new long[I];
cost.Set(INF);
cost[f] = 0;
neg = new bool[I];
for (int i = 0; i < I - 1; i++)
for (int j = 0; j < I; ++j)
for (int k = 0; k < Adj[j].Count; ++k) {
var cur = Adj[j][k];
if (cost[cur.to] > cost[j] + cur.cost)
cost[cur.to] = cost[j] + cur.cost;
}
for (int i = 0; i < I; i++)
for (int j = 0; j < I; ++j)
for (int k = 0; k < Adj[j].Count; ++k) {
var cur = Adj[j][k];
if (cost[cur.to] > cost[j] + cur.cost) {
cost[cur.to] = cost[j] + cur.cost;
neg[cur.to] = true;
}
if (neg[j])
neg[cur.to] = true;
}
}
public bool loopExist() { return neg[I - 1]; }
}
class WF : ShortestPath {
public WF() {}
public WF(bool isNonDir) { this.isNonDir = isNonDir; }
public void Run() {}
}
class WarshallFloyd {
private int E;
private bool isNonDir;
public long INF = (long)1e15;
public long[,] BefG;
public long[,] G;
public WarshallFloyd(bool isNonDir = true) { this.isNonDir = isNonDir; }
public void Init(int n) {
E = n + 1;
G = new long[E, E];
BefG = new long[E, E];
for (int i = 0; i < E; ++i)
for (int j = 0; j < E; ++j) {
G[i, j] = INF;
BefG[i, j] = INF;
}
for (int i = 0; i < E; ++i) {
G[i, i] = 0;
BefG[i, i] = 0;
}
}
public void AddPath(int f, int t, long c = 1) {
if (isNonDir) {
G[f, t] = c;
G[t, f] = c;
BefG[f, t] = c;
BefG[t, f] = c;
} else {
G[f, t] = c;
BefG[f, t] = c;
}
}
public void AddPath(int[] f, int[] t) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], 1);
}
public void AddPath(int[] f, int[] t, long[] c) {
for (int i = 0; i < f.Length; ++i)
AddPath(f[i], t[i], c[i]);
}
public void Run() { G = MinCostArr(); }
public long[,] MinCostArr() {
for (int i = 0; i < E; ++i)
for (int j = 0; j < E; ++j)
for (int k = 0; k < E; ++k)
G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]);
return G;
}
//使う?使わない?
public int[] MinPath(int from, int to) {
var ret = new List<int>();
var cur = from;
while (cur != to) {
ret.Add(cur);
for (int i = 1; i < E; ++i) {
if (BefG[cur, i] + G[i, to] == G[cur, to]) {
if (i == cur)
continue;
cur = i;
break;
}
}
}
ret.Add(cur);
return ret.ToArray();
}
public bool isMinPath(int a, int b, long c) {
for (int i = 0; i < E; ++i)
if (G[i, a] + c == G[i, b])
return true;
return false;
}
//全地点間を繋ぐ最小コスト
public long MinCost() {
long orig = 0;
for (int i = 0; i < E; ++i)
for (int j = i + 1; j < E; ++j) {
bool isOrig = true;
for (int k = 0; k < E; ++k) {
if (k == i || k == j)
continue;
if (G[i, j] == G[i, k] + G[k, j]) {
isOrig = false;
break;
}
}
if (isOrig)
orig += G[i, j];
}
return orig;
}
}
class UnionFind {
int[] dat;
public void Init(int n) {
dat = new int[n + 1];
for (int i = 0; i <= n; ++i)
dat[i] = -1;
}
public void Unite(int x, int y) {
x = Root(x);
y = Root(y);
if (x == y)
return;
if (dat[y] < dat[x])
swap(ref x, ref y);
dat[x] += dat[y];
dat[y] = x;
}
public bool Find(int x, int y) { return Root(x) == Root(y); }
public int Root(int x) { return dat[x] < 0 ? x : dat[x] = Root(dat[x]); }
public int Size(int x) { return -dat[Root(x)]; }
void swap(ref int a, ref int b) {
int tmp = b;
b = a;
a = tmp;
}
}
class Kruskal : ShortestPath {
public Kruskal(bool isNonDir = true) { this.isNonDir = isNonDir; }
public long Run() {
var uf = new UnionFind();
var ret = 0L;
var L = new List<Tuple<int, int, long>>();
uf.Init(V);
for (int i = 0; i < I; ++i)
for (int j = 0; j < Adj[i].Count; ++i)
L.Add(Tuple.Create(i, Adj[i][j].to, Adj[i][j].cost));
L = L.OrderBy(t => t.Item3).ToList();
for (int i = 0; i < L.Count; ++i)
if (!uf.Find(L[i].Item1, L[i].Item2)) {
ret += L[i].Item3;
uf.Unite(L[i].Item1, L[i].Item2);
}
return ret;
}
}
#endregion
#region Ex
static class StringEX {
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) { return toInt(c.ToString()); }
public static int toInt(this char[] c) { return toInt(new string(c)); }
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0;
}
public static long toLong(this char c) { return toLong(c.ToString()); }
public static long toLong(this char[] c) { return toLong(new string(c)); }
public static string toString(this char[] c) { return new string(c); }
}
static class NumericEx {
public static string pad0<T>(this T v, int n) {
return v.ToString().PadLeft(n, '0');
}
public static double RoundOff(this double v, int n) {
return Math.Round(v, n - 1, MidpointRounding.AwayFromZero);
}
public static bool Odd(this int v) { return v % 2 != 0; }
public static bool Odd(this long v) { return v % 2 != 0; }
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Sort(a);
Array.Reverse(a);
return a;
}
public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
}
public static int[] toIntArr(this string[] a) {
return Array.ConvertAll(a, int.Parse);
}
public static long[] toLongArr(this string[] a) {
return Array.ConvertAll(a, long.Parse);
}
public static double[] toDoubleArr(this string[] a) {
return Array.ConvertAll(a, double.Parse);
}
public static char[] toCharArr(this string[] a) {
return Array.ConvertAll(a, char.Parse);
}
public static int LowerBound<T>(this T[] a, T x)
where T : IComparable {
Array.Sort(a);
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) >= 0)
ub = mid;
else
lb = mid;
}
return ub;
}
public static int UpperBound<T>(this T[] a, T x)
where T : IComparable {
Array.Sort(a);
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) > 0)
ub = mid;
else
lb = mid;
}
return ub;
}
}
static class BitEx {
public static bool Any(this BitArray b) {
foreach (bool f in b)
if (f)
return true;
return false;
}
public static bool All(this BitArray b) {
foreach (bool f in b)
if (!f)
return false;
return true;
}
public static bool None(this BitArray b) { return !Any(b); }
public static void Flip(this BitArray b, int index) {
b.Set(index, !b.Get(index));
}
}
static class IEnumerableEx {}
static class Test {
public static int add(this int a, int b) { return a + b; }
public static double add(this double a, int b) { return a + b; }
public static double add(this int a, double b) { return a + b; }
public static double add(this double a, double b) { return a + b; }
public static long add(this long a, int b) { return a + b; }
public static long add(this int a, long b) { return a + b; }
public static long add(this long a, long b) { return a + b; }
}
#endregion
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 9,044
| 2
|
using System;
public class Hello {
public static void Main() {
int N = int.Parse(Console.ReadLine());
int X = 1;
while (X * X < N) {
X++;
}
Console.WriteLine((X - 1) * (X - 1));
}
}
|
using System;
public class Hello {
public static void Main() {
long N = long.Parse(Console.ReadLine());
long X = 1;
while (X * X <= N) {
X++;
}
Console.WriteLine((X - 1) * (X - 1));
}
}
|
[["-", 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, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 65
| 8
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.