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.Generic;
using System.Linq;
using Console = System.Console;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var r = Console.ReadLine()
.Split()
.Select(long.Parse)
.OrderByDescending(x => x)
.ToArray();
var ret = new List<long>();
for (int i = 0; i < N - 1; i++) {
if (r[i] == r[i + 1]) {
ret.Add(r[i]);
i += 2;
if (ret.Count == 2) {
Console.WriteLine(ret[0] * ret[1]);
return;
}
}
}
Console.WriteLine(0);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using Console = System.Console;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var r = Console.ReadLine()
.Split()
.Select(long.Parse)
.OrderByDescending(x => x)
.ToArray();
var ret = new List<long>();
for (int i = 0; i < N - 1; i++) {
if (r[i] == r[i + 1]) {
ret.Add(r[i]);
i++;
if (ret.Count == 2) {
Console.WriteLine(ret[0] * ret[1]);
return;
}
}
}
Console.WriteLine(0);
}
}
}
|
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29]]
| 8
| 179
| 3
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static AtCoderTemplate.MyExtensions;
using static AtCoderTemplate.MyInputOutputs;
using static AtCoderTemplate.MyNumericFunctions;
using static AtCoderTemplate.MyAlgorithm;
namespace AtCoderTemplate {
public class Program {
public static void Main(string[] args) {
var N = ReadInt();
var A = ReadLongs();
var edges = A.OrderByDescending(x => x)
.GroupBy(x => x)
.Where(group => group.Count() > 1)
.ToList();
Print2DArray(edges);
if (edges.Count == 0) {
Print(0);
} else if (edges.Count == 1) {
if (edges[0].Count() < 4) {
Print(0);
} else {
var max = edges[0].Key;
Print(max * max);
}
} else {
if (edges[0].Count() < 4) {
var max1 = edges[0].Key;
var max2 = edges[1].Key;
Print(max1 * max2);
} else {
var max = edges[0].Key;
Print(max * max);
}
}
}
}
static class MyInputOutputs {
/* Input & Output*/
public static int ReadInt() { return int.Parse(Console.ReadLine()); }
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<int> ReadInts() {
return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList();
}
public static List<List<int>> ReadIntColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static List<List<long>> ReadLongColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static void Print<T>(T item) { Console.WriteLine(item); }
public static void PrintIf<T1, T2>(bool condition, T1 trueResult,
T2 falseResult) {
if (condition) {
Console.WriteLine(trueResult);
} else {
Console.WriteLine(falseResult);
}
}
public static void PrintRow<T>(IEnumerable<T> list) {
/* 横ベクトルで表示
A B C D ...
*/
if (!list.IsEmpty()) {
Console.Write(list.First());
foreach (var item in list.Skip(1)) {
Console.Write($" {item}");
}
}
Console.Write("\n");
}
public static void PrintColomn<T>(IEnumerable<T> list) {
/* 縦ベクトルで表示
A
B
C
D
...
*/
foreach (var item in list) {
Console.WriteLine(item);
}
}
public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) {
foreach (var row in sources) {
PrintRow(row);
}
}
}
static class MyNumericFunctions {
public static bool isEven(int a) { return a % 2 == 0; }
public static bool isEven(long a) { return a % 2 == 0; }
public static bool isOdd(int a) { return !isEven(a); }
public static bool isOdd(long a) { return !isEven(a); }
public static long nPk(int n, int k) {
if (k > n) {
return 0;
} else {
return Enumerable.Range(n - k + 1, k)
.Aggregate((long)1, ((i, m) => i * m));
}
}
public static long Fact(int n) { return nPk(n, n); }
public static long nCk(int n, int k) {
if (k > n) {
return 0;
} else {
return nPk(n, k) / Fact(k);
}
}
// 最大公約数
public static long GCD(long m, long n) {
if (m < n) {
return GCD(n, m);
} else if (n == 0) {
return m;
} else {
return GCD(n, m % n);
}
}
// 最小公倍数
public static long LCM(long m, long n) {
if (m < n) {
return LCM(n, m);
} else {
return (m * n) / GCD(m, n);
}
}
}
static class MyAlgorithm {
/// <summary>
/// 二分探索法
/// O(log N)
/// </summary>
/// <param name="list">探索するリスト</param>
/// <param name="predicate">条件の述語関数</param>
/// <param name="ng">条件を満たさない既知のindex</param>
/// <param name="ok">条件を満たす既知のindex</param>
/// <typeparam name="T">順序関係を持つ型(IComparableを実装する)</typeparam>
/// <returns>条件を満たすindexの内、境界に最も近いものを返す</returns>
public static int BinarySearch<T>(IList<T> list, Func<T, bool> predicate,
int ng, int ok)
where T : IComparable<T> {
while (Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (predicate(list[mid])) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
/// <summary>
/// 辺の集まりを操作するオブジェクト
/// </summary>
public class Edge {
long[,] edge;
public int NodeNum { get; }
public Edge(int nodeNum, long overDistance) {
var edge = new long[nodeNum, nodeNum];
foreach (var i in Enumerable.Range(0, nodeNum)) {
foreach (var j in Enumerable.Range(0, nodeNum)) {
if (i != j) {
edge[i, j] = overDistance;
} else {
edge[i, j] = 0;
}
}
}
this.edge = edge;
this.NodeNum = nodeNum;
}
public Edge(Edge edge) {
this.edge = new long[edge.NodeNum, edge.NodeNum];
foreach (var i in Enumerable.Range(0, edge.NodeNum)) {
foreach (var j in Enumerable.Range(0, edge.NodeNum)) {
this.edge[i, j] = edge.GetLength(i, j);
}
}
this.NodeNum = edge.NodeNum;
}
public List<List<long>> ToList() {
return Enumerable.Range(0, NodeNum)
.Select(
i =>
Enumerable.Range(0, NodeNum).Select(j => edge[i, j]).ToList())
.ToList();
}
public void Add(int node1, int node2, long distance) {
edge[node1, node2] = distance;
}
public long GetLength(int node1, int node2) { return edge[node1, node2]; }
}
/// <summary>
/// ワーシャルフロイド法
/// O(N^3)
/// </summary>
/// <param name="edge">Edgeオブジェクト</param>
/// <param name="nodeNum">ノードの数</param>
/// <returns>各ノード間の最短距離を辺として持つEdgeオブジェクト</returns>
public static Edge WarshallFloyd(Edge edge) {
var res = new Edge(edge);
foreach (var b in Enumerable.Range(0, edge.NodeNum)) {
foreach (var a in Enumerable.Range(0, edge.NodeNum)) {
foreach (var c in Enumerable.Range(0, edge.NodeNum)) {
res.Add(a, c,
Min(res.GetLength(a, c),
res.GetLength(a, b) + res.GetLength(b, c)));
}
}
}
return res;
}
}
static class MyExtensions {
// AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2
// はそれに対応して仕様はあるが、実装がない
public static IEnumerable<T> Append<T>(this IEnumerable<T> source,
T element) {
return source.Concat(Enumerable.Repeat(element, 1));
}
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source,
T element) {
return Enumerable.Repeat(element, 1).Concat(source);
}
// TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2
// はそれに対応していない
public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source,
int count) {
return source.Skip(source.Count() - count);
}
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source,
int count) {
return source.Take(source.Count() - count);
}
public static bool IsEmpty<T>(this IEnumerable<T> source) {
return !source.Any();
}
/// <summary>
/// インデックスiの位置の要素からk個取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source,
int i, int count) {
return source.Take(i).Concat(source.Skip(i + count));
}
/// <summary>
/// インデックスiの位置の要素を取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source,
int i) {
return source.TakeAwayRange(i, 1);
}
/// <summary>
/// インデックスiの位置にシーケンスを挿入する
/// O(N + K)
/// </summary>
public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source,
int i, IEnumerable<T> inserted) {
return source.Take(i).Concat(inserted).Concat(source.Skip(i));
}
/// <summary>
/// 順列を得る
/// O(N!)
/// </summary>
public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source,
int n) {
if (n == 0 || source.IsEmpty() || source.Count() < n) {
return Enumerable.Empty<IEnumerable<T>>();
} else if (n == 1) {
return source.Select(i => new List<T> { i });
} else {
var nexts = source.Select(
(x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)),
selected = source.Take(i + 1).Last() });
return nexts.SelectMany(
next => Perm(next.next, n - 1)
.Select(item => item.Prepend(next.selected)));
}
}
/// <summary>
/// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る
/// </summary>
/// <para>O(N)</para>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数</param>
/// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example>
public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source,
Func<T1, T1, TR> func) {
var list = source.ToList();
return Enumerable.Range(1, list.Count - 1)
.Select(i => func(list[i], list[i - 1]));
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、first)
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <param name="first">func(first, source[0])のための初項</param>
/// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2),
/// f(f(f(0,1),2),3)]</example>
public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source,
TR first, Func<TR, T, TR> func) {
var list = source.ToList();
var result = new List<TR> { first };
foreach (var i in Enumerable.Range(0, source.Count())) {
result.Add(func(result[i], list[i]));
}
return result;
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、source.First())
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example>
public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source,
Func<T, T, T> func) {
var list = source.ToList();
var result = new List<T> { list[0] };
foreach (var i in Enumerable.Range(1, source.Count() - 1)) {
result.Add(func(result[i - 1], list[i]));
}
return result;
}
/// <summary>
/// 昇順にソートしたインデックスを得る
/// </summary>
/// <para>O(N * log N)</para>
public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) {
return source.Select((item, i) => new { Item = item, Index = i })
.OrderBy(x => x.Item)
.Select(x => x.Index);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static AtCoderTemplate.MyExtensions;
using static AtCoderTemplate.MyInputOutputs;
using static AtCoderTemplate.MyNumericFunctions;
using static AtCoderTemplate.MyAlgorithm;
namespace AtCoderTemplate {
public class Program {
public static void Main(string[] args) {
var N = ReadInt();
var A = ReadLongs();
var edges = A.OrderByDescending(x => x)
.GroupBy(x => x)
.Where(group => group.Count() > 1)
.ToList();
// Print2DArray (edges);
if (edges.Count == 0) {
Print(0);
} else if (edges.Count == 1) {
if (edges[0].Count() < 4) {
Print(0);
} else {
var max = edges[0].Key;
Print(max * max);
}
} else {
if (edges[0].Count() < 4) {
var max1 = edges[0].Key;
var max2 = edges[1].Key;
Print(max1 * max2);
} else {
var max = edges[0].Key;
Print(max * max);
}
}
}
}
static class MyInputOutputs {
/* Input & Output*/
public static int ReadInt() { return int.Parse(Console.ReadLine()); }
public static long ReadLong() { return long.Parse(Console.ReadLine()); }
public static List<int> ReadInts() {
return Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
}
public static List<long> ReadLongs() {
return Console.ReadLine().Split(' ').Select(c => long.Parse(c)).ToList();
}
public static List<List<int>> ReadIntColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadInts()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static List<List<long>> ReadLongColumns(int n) {
/*
入力例
A1 B1
A2 B2
...
An Bn
出力例
[[A1,A2,...,An], [B1,B2,...,Bn]]
*/
var rows = Enumerable.Range(0, n).Select(i => ReadLongs()).ToList();
var m = rows.FirstOrDefault()?.Count() ?? 0;
return Enumerable.Range(0, m)
.Select(i => rows.Select(items => items[i]).ToList())
.ToList();
}
public static void Print<T>(T item) { Console.WriteLine(item); }
public static void PrintIf<T1, T2>(bool condition, T1 trueResult,
T2 falseResult) {
if (condition) {
Console.WriteLine(trueResult);
} else {
Console.WriteLine(falseResult);
}
}
public static void PrintRow<T>(IEnumerable<T> list) {
/* 横ベクトルで表示
A B C D ...
*/
if (!list.IsEmpty()) {
Console.Write(list.First());
foreach (var item in list.Skip(1)) {
Console.Write($" {item}");
}
}
Console.Write("\n");
}
public static void PrintColomn<T>(IEnumerable<T> list) {
/* 縦ベクトルで表示
A
B
C
D
...
*/
foreach (var item in list) {
Console.WriteLine(item);
}
}
public static void Print2DArray<T>(IEnumerable<IEnumerable<T>> sources) {
foreach (var row in sources) {
PrintRow(row);
}
}
}
static class MyNumericFunctions {
public static bool isEven(int a) { return a % 2 == 0; }
public static bool isEven(long a) { return a % 2 == 0; }
public static bool isOdd(int a) { return !isEven(a); }
public static bool isOdd(long a) { return !isEven(a); }
public static long nPk(int n, int k) {
if (k > n) {
return 0;
} else {
return Enumerable.Range(n - k + 1, k)
.Aggregate((long)1, ((i, m) => i * m));
}
}
public static long Fact(int n) { return nPk(n, n); }
public static long nCk(int n, int k) {
if (k > n) {
return 0;
} else {
return nPk(n, k) / Fact(k);
}
}
// 最大公約数
public static long GCD(long m, long n) {
if (m < n) {
return GCD(n, m);
} else if (n == 0) {
return m;
} else {
return GCD(n, m % n);
}
}
// 最小公倍数
public static long LCM(long m, long n) {
if (m < n) {
return LCM(n, m);
} else {
return (m * n) / GCD(m, n);
}
}
}
static class MyAlgorithm {
/// <summary>
/// 二分探索法
/// O(log N)
/// </summary>
/// <param name="list">探索するリスト</param>
/// <param name="predicate">条件の述語関数</param>
/// <param name="ng">条件を満たさない既知のindex</param>
/// <param name="ok">条件を満たす既知のindex</param>
/// <typeparam name="T">順序関係を持つ型(IComparableを実装する)</typeparam>
/// <returns>条件を満たすindexの内、境界に最も近いものを返す</returns>
public static int BinarySearch<T>(IList<T> list, Func<T, bool> predicate,
int ng, int ok)
where T : IComparable<T> {
while (Abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (predicate(list[mid])) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
}
/// <summary>
/// 辺の集まりを操作するオブジェクト
/// </summary>
public class Edge {
long[,] edge;
public int NodeNum { get; }
public Edge(int nodeNum, long overDistance) {
var edge = new long[nodeNum, nodeNum];
foreach (var i in Enumerable.Range(0, nodeNum)) {
foreach (var j in Enumerable.Range(0, nodeNum)) {
if (i != j) {
edge[i, j] = overDistance;
} else {
edge[i, j] = 0;
}
}
}
this.edge = edge;
this.NodeNum = nodeNum;
}
public Edge(Edge edge) {
this.edge = new long[edge.NodeNum, edge.NodeNum];
foreach (var i in Enumerable.Range(0, edge.NodeNum)) {
foreach (var j in Enumerable.Range(0, edge.NodeNum)) {
this.edge[i, j] = edge.GetLength(i, j);
}
}
this.NodeNum = edge.NodeNum;
}
public List<List<long>> ToList() {
return Enumerable.Range(0, NodeNum)
.Select(
i =>
Enumerable.Range(0, NodeNum).Select(j => edge[i, j]).ToList())
.ToList();
}
public void Add(int node1, int node2, long distance) {
edge[node1, node2] = distance;
}
public long GetLength(int node1, int node2) { return edge[node1, node2]; }
}
/// <summary>
/// ワーシャルフロイド法
/// O(N^3)
/// </summary>
/// <param name="edge">Edgeオブジェクト</param>
/// <param name="nodeNum">ノードの数</param>
/// <returns>各ノード間の最短距離を辺として持つEdgeオブジェクト</returns>
public static Edge WarshallFloyd(Edge edge) {
var res = new Edge(edge);
foreach (var b in Enumerable.Range(0, edge.NodeNum)) {
foreach (var a in Enumerable.Range(0, edge.NodeNum)) {
foreach (var c in Enumerable.Range(0, edge.NodeNum)) {
res.Add(a, c,
Min(res.GetLength(a, c),
res.GetLength(a, b) + res.GetLength(b, c)));
}
}
}
return res;
}
}
static class MyExtensions {
// AppendとPrependが、.NET Standard 1.6からの追加で、Mono 4.6.2
// はそれに対応して仕様はあるが、実装がない
public static IEnumerable<T> Append<T>(this IEnumerable<T> source,
T element) {
return source.Concat(Enumerable.Repeat(element, 1));
}
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source,
T element) {
return Enumerable.Repeat(element, 1).Concat(source);
}
// TakeLastとSkipLastが、.Net Standard 2.1からの追加で、Mono 4.6.2
// はそれに対応していない
public static IEnumerable<T> TakeLast<T>(this IEnumerable<T> source,
int count) {
return source.Skip(source.Count() - count);
}
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source,
int count) {
return source.Take(source.Count() - count);
}
public static bool IsEmpty<T>(this IEnumerable<T> source) {
return !source.Any();
}
/// <summary>
/// インデックスiの位置の要素からk個取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayRange<T>(this IEnumerable<T> source,
int i, int count) {
return source.Take(i).Concat(source.Skip(i + count));
}
/// <summary>
/// インデックスiの位置の要素を取り除く
/// O(N)
/// </summary>
public static IEnumerable<T> TakeAwayAt<T>(this IEnumerable<T> source,
int i) {
return source.TakeAwayRange(i, 1);
}
/// <summary>
/// インデックスiの位置にシーケンスを挿入する
/// O(N + K)
/// </summary>
public static IEnumerable<T> InsertEnumAt<T>(this IEnumerable<T> source,
int i, IEnumerable<T> inserted) {
return source.Take(i).Concat(inserted).Concat(source.Skip(i));
}
/// <summary>
/// 順列を得る
/// O(N!)
/// </summary>
public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> source,
int n) {
if (n == 0 || source.IsEmpty() || source.Count() < n) {
return Enumerable.Empty<IEnumerable<T>>();
} else if (n == 1) {
return source.Select(i => new List<T> { i });
} else {
var nexts = source.Select(
(x, i) => new { next = source.Take(i).Concat(source.Skip(i + 1)),
selected = source.Take(i + 1).Last() });
return nexts.SelectMany(
next => Perm(next.next, n - 1)
.Select(item => item.Prepend(next.selected)));
}
}
/// <summary>
/// シーケンスの隣り合う要素を2引数の関数に適用したシーケンスを得る
/// </summary>
/// <para>O(N)</para>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数</param>
/// <example>[1,2,3,4].MapAdjacent(f) => [f(1,2), f(2,3), f(3,4)]</example>
public static IEnumerable<TR> MapAdjacent<T1, TR>(this IEnumerable<T1> source,
Func<T1, T1, TR> func) {
var list = source.ToList();
return Enumerable.Range(1, list.Count - 1)
.Select(i => func(list[i], list[i - 1]));
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、first)
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <param name="first">func(first, source[0])のための初項</param>
/// <example> [1,2,3].Scanl1(f,0) => [0, f(0,1), f(f(0,1),2),
/// f(f(f(0,1),2),3)]</example>
public static IEnumerable<TR> Scanl<T, TR>(this IEnumerable<T> source,
TR first, Func<TR, T, TR> func) {
var list = source.ToList();
var result = new List<TR> { first };
foreach (var i in Enumerable.Range(0, source.Count())) {
result.Add(func(result[i], list[i]));
}
return result;
}
/// <summary>
/// 累積項を要素にもつシーケンスを得る(初項は、source.First())
/// <para>O(N)</para>
/// </summary>
/// <param name="source">元のシーケンス</param>
/// <param name="func">2引数関数f</param>
/// <example> [1,2,3].Scanl1(f) => [1, f(1,2), f(f(1,2),3)]</example>
public static IEnumerable<T> Scanl1<T>(this IEnumerable<T> source,
Func<T, T, T> func) {
var list = source.ToList();
var result = new List<T> { list[0] };
foreach (var i in Enumerable.Range(1, source.Count() - 1)) {
result.Add(func(result[i - 1], list[i]));
}
return result;
}
/// <summary>
/// 昇順にソートしたインデックスを得る
/// </summary>
/// <para>O(N * log N)</para>
public static IEnumerable<int> SortIndex<T>(this IEnumerable<T> source) {
return source.Select((item, i) => new { Item = item, Index = i })
.OrderBy(x => x.Item)
.Select(x => x.Index);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 2,457
| 5
|
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 N;
int[] A;
void Solve() {
// input
N = io.Int;
A = new int[N];
for (int i = 0; i < N; ++i)
A[i] = io.Int;
var dic = new Dictionary<int, int>();
foreach (var v in A) {
if (!dic.ContainsKey(v))
dic[v] = 0;
dic[v]++;
}
var twoOrMore = dic.Where(kp => kp.Value >= 2)
.Select(kp => kp.Key)
.OrderByDescending(v => v)
.ToArray();
var fourOrMore = dic.Where(kp => kp.Value >= 4)
.Select(kp => kp.Key)
.OrderByDescending(v => v)
.ToArray();
var ans = 0L;
if (twoOrMore.Length >= 2 && fourOrMore.Length >= 1) {
ans = Max((long)twoOrMore[0] * twoOrMore[1],
(long)fourOrMore[0] + fourOrMore[0]);
} else if (twoOrMore.Length >= 2) {
ans = (long)twoOrMore[0] * twoOrMore[1];
} else if (fourOrMore.Length >= 1) {
ans = (long)fourOrMore[0] + fourOrMore[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();
}
|
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 N;
int[] A;
void Solve() {
// input
N = io.Int;
A = new int[N];
for (int i = 0; i < N; ++i)
A[i] = io.Int;
var dic = new Dictionary<int, int>();
foreach (var v in A) {
if (!dic.ContainsKey(v))
dic[v] = 0;
dic[v]++;
}
var twoOrMore = dic.Where(kp => kp.Value >= 2)
.Select(kp => kp.Key)
.OrderByDescending(v => v)
.ToArray();
var fourOrMore = dic.Where(kp => kp.Value >= 4)
.Select(kp => kp.Key)
.OrderByDescending(v => v)
.ToArray();
var ans = 0L;
if (twoOrMore.Length >= 2 && fourOrMore.Length >= 1) {
ans = Max((long)twoOrMore[0] * twoOrMore[1],
(long)fourOrMore[0] * fourOrMore[0]);
} else if (twoOrMore.Length >= 2) {
ans = (long)twoOrMore[0] * twoOrMore[1];
} else if (fourOrMore.Length >= 1) {
ans = (long)fourOrMore[0] * fourOrMore[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();
}
|
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48]]
| 8
| 594
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static string InputPattern = "InputX";
static List<string> GetInputList() {
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("6");
WillReturn.Add("3 1 2 4 2 1");
// 2
} else if (InputPattern == "Input2") {
WillReturn.Add("4");
WillReturn.Add("1 2 3 4");
// 0
} else if (InputPattern == "Input3") {
WillReturn.Add("10");
WillReturn.Add("3 3 3 3 4 4 4 5 5 5");
// 20
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
checked {
List<string> InputList = GetInputList();
long[] AArr =
InputList[1].Split(' ').Select(X => long.Parse(X)).ToArray();
var Query = AArr.GroupBy(A => A).OrderByDescending(A => A.Key);
var HenList = new List<long>();
foreach (var EachItem in Query) {
if (EachItem.Count() >= 4) {
HenList.Add(EachItem.Key);
HenList.Add(EachItem.Key);
} else if (EachItem.Count() >= 2) {
HenList.Add(EachItem.Key);
}
if (HenList.Count == 2)
break;
}
if (HenList.Count == 2) {
Console.WriteLine(HenList[0] * HenList[1]);
} else
Console.WriteLine(0);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static string InputPattern = "InputX";
static List<string> GetInputList() {
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("6");
WillReturn.Add("3 1 2 4 2 1");
// 2
} else if (InputPattern == "Input2") {
WillReturn.Add("4");
WillReturn.Add("1 2 3 4");
// 0
} else if (InputPattern == "Input3") {
WillReturn.Add("10");
WillReturn.Add("3 3 3 3 4 4 4 5 5 5");
// 20
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
checked {
List<string> InputList = GetInputList();
long[] AArr =
InputList[1].Split(' ').Select(X => long.Parse(X)).ToArray();
var Query = AArr.GroupBy(A => A).OrderByDescending(A => A.Key);
var HenList = new List<long>();
foreach (var EachItem in Query) {
if (EachItem.Count() >= 4) {
HenList.Add(EachItem.Key);
HenList.Add(EachItem.Key);
} else if (EachItem.Count() >= 2) {
HenList.Add(EachItem.Key);
}
if (HenList.Count >= 2)
break;
}
if (HenList.Count >= 2) {
Console.WriteLine(HenList[0] * HenList[1]);
} else
Console.WriteLine(0);
}
}
}
|
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 287, 0, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 287, 0, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 356
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[] A = Array.ConvertAll(Console.ReadLine().Split(' '),
new Converter<string, int>(x => int.Parse(x)));
Array.Sort(A);
A.Reverse();
long rect_upper = 0;
long rect = 0;
for (int i = 1; i < A.Length; i++) {
if (rect_upper == 0) {
if (A[i - 1] == A[i]) {
rect_upper = A[i];
i++;
}
} else {
if (A[i - 1] == A[i]) {
rect = A[i] * rect_upper;
}
}
}
Console.WriteLine(rect);
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[] A = Array.ConvertAll(Console.ReadLine().Split(' '),
new Converter<string, int>(x => int.Parse(x)));
Array.Sort(A);
Array.Reverse(A);
long rect_upper = 0;
long rect = 0;
for (int i = 1; i < A.Length; i++) {
if (rect_upper == 0) {
if (A[i - 1] == A[i]) {
rect_upper = A[i];
i++;
}
} else {
if (A[i - 1] == A[i]) {
rect = A[i] * rect_upper;
break;
}
}
}
Console.WriteLine(rect);
Console.ReadLine();
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
| 8
| 210
| 5
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
// var HW = Console.ReadLine().Split().Select(a =>
// long.Parse(a)).ToArray();
var N = int.Parse(Console.ReadLine());
var S1 = Console.ReadLine();
var S2 = Console.ReadLine();
long ans = 1L;
var i = 0;
var flag = true;
if (S2[0] == S1[0]) {
ans = 3;
i = 1;
flag = true;
} else {
ans = 6;
i = 2;
flag = false;
}
for (; i < N; i++) {
// Console.WriteLine(i);
if (S2[i] == S1[i]) {
if (flag) {
ans *= 2;
ans %= 1000000007;
} else {
ans *= 1;
ans %= 1000000007;
}
flag = true;
} else {
if (flag) {
ans *= 3;
ans %= 1000000007;
} else {
ans *= 2;
ans %= 1000000007;
}
i++;
flag = false;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
// var HW = Console.ReadLine().Split().Select(a =>
// long.Parse(a)).ToArray();
var N = int.Parse(Console.ReadLine());
var S1 = Console.ReadLine();
var S2 = Console.ReadLine();
long ans = 1L;
var i = 0;
var flag = true;
if (S2[0] == S1[0]) {
ans = 3;
i = 1;
flag = true;
} else {
ans = 6;
i = 2;
flag = false;
}
for (; i < N; i++) {
// Console.WriteLine(i);
if (S2[i] == S1[i]) {
if (flag) {
ans *= 2;
ans %= 1000000007;
} else {
ans *= 1;
ans %= 1000000007;
}
flag = true;
} else {
if (flag) {
ans *= 2;
ans %= 1000000007;
} else {
ans *= 3;
ans %= 1000000007;
}
i++;
flag = false;
}
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 223
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class MakeARectangle {
static void Main(string[] args) {
// var sw = new System.Diagnostics.Stopwatch();
// sw.Start();
Console.ReadLine(); // 扱うデータの個数 LINQに関係なし
var stick =
Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToList();
ulong largest = 0, larger = 0;
// var unique = new List<ulong>();
stick.Sort();
int xx = stick.Count();
while (0 < xx--) {
if (stick[xx] == stick[xx - 1]) {
if (largest > 0) {
larger = stick[xx];
break;
} else {
largest = stick[xx];
}
xx--;
}
}
// foreach (var x in stick)
//{
// if (larger < x)
// {
// if (unique.Remove(x))
// { // 2個目が見つかる
// larger = x;
// if (largest < larger)
// {
// larger ^= largest;
// largest ^= larger;
// larger ^= largest;
// }
// }
// else
// {
// unique.Add(x);
// }
// }
//}
Console.WriteLine(
$"{ umulh(larger, largest).ToString("#") }{larger * largest}");
// sw.Stop();
// Console.WriteLine($" {sw.ElapsedMilliseconds}ミリ秒");
}
// ulongの積の上位64bitを取得
// 参考 (http://d.hatena.ne.jp/n7shi/20100630/1277983197)
static public ulong umulh(ulong x, ulong y) {
ulong xh = x >> 32, xl = x & 0xffffffff;
ulong yh = y >> 32, yl = y & 0xffffffff;
ulong a = xh * yl, ah = a >> 32, al = a & 0xffffffff;
ulong b = xl * yh, bh = b >> 32, bl = b & 0xffffffff;
return ((((xl * yl) >> 32) + al + bl) >> 32) + ah + bh + xh * yh;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class MakeARectangle {
static void Main(string[] args) {
// var sw = new System.Diagnostics.Stopwatch();
// sw.Start();
Console.ReadLine(); // 扱うデータの個数 LINQに関係なし
var stick =
Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToList();
ulong largest = 0, larger = 0;
// var unique = new List<ulong>();
stick.Sort();
int xx = stick.Count();
while (1 < xx--) {
if (stick[xx] == stick[xx - 1]) {
if (largest > 0) {
larger = stick[xx];
break;
} else {
largest = stick[xx];
}
xx--;
}
}
// foreach (var x in stick)
//{
// if (larger < x)
// {
// if (unique.Remove(x))
// { // 2個目が見つかる
// larger = x;
// if (largest < larger)
// {
// larger ^= largest;
// largest ^= larger;
// larger ^= largest;
// }
// }
// else
// {
// unique.Add(x);
// }
// }
//}
Console.WriteLine(
$"{ umulh(larger, largest).ToString("#") }{larger * largest}");
// sw.Stop();
// Console.WriteLine($" {sw.ElapsedMilliseconds}ミリ秒");
}
// ulongの積の上位64bitを取得
// 参考 (http://d.hatena.ne.jp/n7shi/20100630/1277983197)
static public ulong umulh(ulong x, ulong y) {
ulong xh = x >> 32, xl = x & 0xffffffff;
ulong yh = y >> 32, yl = y & 0xffffffff;
ulong a = xh * yl, ah = a >> 32, al = a & 0xffffffff;
ulong b = xl * yh, bh = b >> 32, bl = b & 0xffffffff;
return ((((xl * yl) >> 32) + al + bl) >> 32) + ah + bh + xh * yh;
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 31, 203], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 203]]
| 8
| 321
| 2
|
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Extensions;
using DSA;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
int n = Cin;
string s1 = Cin, s2 = Cin;
var dominos = new List<bool>();
for (int i = 0; i < n; i++) {
if (s1[i] == s2[i])
dominos.Add(false);
else {
dominos.Add(true);
i++;
}
}
ModInt.Mod = 1000000007;
ModInt ans = dominos[0] ? 6 : 3;
for (var i = 1; i < dominos.Count; i++) {
if (dominos[i]) {
if (dominos[i - 1]) {
ans *= 3;
} else {
ans *= 1;
}
} else {
if (dominos[i - 1]) {
ans *= 2;
} else {
ans *= 2;
}
}
}
Coutln(ans);
}
}
// Other Classes Here
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
namespace DSA {
public class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count => _list.Count;
public PriorityQueue() {}
public void Push(T item, int priority) {
_list.Add(Tuple.Create(priority, item));
int itemIndex = Count - 1, parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > _list[parentIndex].Item1) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return Tuple.Create(item1, item2);
}
public T Pop() {
if (Count <= 0)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = _list[Count - 1];
_list.RemoveAt(Count - 1);
int index = 0;
Tuple<int, int> childrenIndex = GetChildrenIndex(index);
while (childrenIndex.Item1 < Count || childrenIndex.Item2 < Count) {
if (childrenIndex.Item2 >= Count ||
_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) {
if (_list[childrenIndex.Item1].Item1 <= _list[index].Item1)
return item;
Swap(index, childrenIndex.Item1);
index = childrenIndex.Item1;
} else {
if (_list[childrenIndex.Item2].Item1 <= _list[index].Item1)
return item;
Swap(index, childrenIndex.Item2);
index = childrenIndex.Item2;
}
childrenIndex = GetChildrenIndex(index);
}
return item;
}
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
public class UnionFind {
private readonly int[] _array;
public UnionFind(int size) {
_array = new int[size];
for (int i = 0; i < size; i++) {
_array[i] = i;
}
}
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
public bool IsRoot(int n) => _array[n] == n;
}
public delegate T SegTreeCombiner<T>(T item1, T item2);
public class SegTree<T> {
private readonly T _defaultItem;
private readonly SegTreeCombiner<T> _func;
private T[] List;
private int size;
public SegTree(T[] list, T defaultItem, SegTreeCombiner<T> func) {
_defaultItem = defaultItem;
_func = func;
size = 1;
while (size < list.Length)
size <<= 1;
List = new T[2 * size - 1];
for (int i = 0; i < list.Length; i++)
List[i + size - 1] = list[i];
for (int i = list.Length; i < size; i++)
List[i + size - 1] = defaultItem;
for (int i = size - 1 - 1; i >= 0; i--) {
List[i] = _func(List[2 * i + 1], List[2 * i + 2]);
}
}
public void Update(int index, T value) {
index += size - 1;
List[index] = value;
while (index > 0) {
index = (index - 1) >> 1;
List[index] = _func(List[2 * index + 1], List[2 * index + 2]);
}
}
public T Query(int a, int b) { return Query(a, b, 0, 0, size); }
private T Query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return _defaultItem;
if (a <= l && r <= b)
return List[k];
return _func(Query(a, b, k * 2 + 1, l, (l + r) >> 1),
Query(a, b, k * 2 + 2, (l + r) >> 1, r));
}
}
public static class BinarySearch {
public delegate bool Terms<T>(T i);
public static int UpperBound(int initLeft, int initRight, Terms<int> term) {
// TODO:範囲内に条件を満たす区間が存在しない場合に対応する
int left = initLeft - 1, right = initRight;
while (right - left > 1) {
int mid = (left + right) >> 1;
if (mid != initLeft - 1 && term(mid))
left = mid;
else
right = mid;
}
return left;
}
public static long UpperBound(long initLeft, long initRight,
Terms<long> term) {
long left = initLeft - 1, right = initRight;
while (right - left > 1) {
long mid = (left + right) >> 1;
if (mid != initLeft - 1 && term(mid))
left = mid;
else
right = mid;
}
return left;
}
public static int LowerBound(int initLeft, int initRight, Terms<int> term) {
int left = initLeft - 1, right = initRight;
while (right - left > 1) {
int mid = (left + right) >> 1;
if (mid != initRight && term(mid))
right = mid;
else
left = mid;
}
return right;
}
public static long LowerBound(long initLeft, long initRight,
Terms<long> term) {
long left = initLeft - 1, right = initRight;
while (right - left > 1) {
long mid = (left + right) >> 1;
if (term(mid))
right = mid;
else
left = mid;
}
return right;
}
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static implicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
if (b == 0)
return a;
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
if (b == 0)
return a;
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Extensions;
using DSA;
using static System.Math;
using static Extensions.MathExtension;
using static Extensions.ConsoleInputExtension;
using static Extensions.ConsoleOutputExtension;
class Solver {
public void Solve() {
// Solve Code Here
int n = Cin;
string s1 = Cin, s2 = Cin;
var dominos = new List<bool>();
for (int i = 0; i < n; i++) {
if (s1[i] == s2[i])
dominos.Add(false);
else {
dominos.Add(true);
i++;
}
}
ModInt.Mod = 1000000007;
ModInt ans = dominos[0] ? 6 : 3;
for (var i = 1; i < dominos.Count; i++) {
if (dominos[i - 1]) {
if (dominos[i]) {
ans *= 3;
} else {
ans *= 1;
}
} else {
if (dominos[i]) {
ans *= 2;
} else {
ans *= 2;
}
}
}
Coutln(ans);
}
}
// Other Classes Here
#if !DEBUG
class EntryPoint {
static void Main(string[] args) {
new Solver().Solve();
Flush();
}
}
#endif
namespace DSA {
public class PriorityQueue<T> {
private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>();
public int Count => _list.Count;
public PriorityQueue() {}
public void Push(T item, int priority) {
_list.Add(Tuple.Create(priority, item));
int itemIndex = Count - 1, parentIndex;
while ((parentIndex = GetParentIndex(itemIndex)) != -1 &&
priority > _list[parentIndex].Item1) {
Swap(itemIndex, parentIndex);
itemIndex = parentIndex;
}
}
private int GetParentIndex(int index) {
if (index == 0)
return -1;
return ((index + 1) >> 1) - 1;
}
private Tuple<int, int> GetChildrenIndex(int index) {
var item2 = (index + 1) << 1;
var item1 = item2 - 1;
return Tuple.Create(item1, item2);
}
public T Pop() {
if (Count <= 0)
throw new IndexOutOfRangeException();
var item = _list[0].Item2;
_list[0] = _list[Count - 1];
_list.RemoveAt(Count - 1);
int index = 0;
Tuple<int, int> childrenIndex = GetChildrenIndex(index);
while (childrenIndex.Item1 < Count || childrenIndex.Item2 < Count) {
if (childrenIndex.Item2 >= Count ||
_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) {
if (_list[childrenIndex.Item1].Item1 <= _list[index].Item1)
return item;
Swap(index, childrenIndex.Item1);
index = childrenIndex.Item1;
} else {
if (_list[childrenIndex.Item2].Item1 <= _list[index].Item1)
return item;
Swap(index, childrenIndex.Item2);
index = childrenIndex.Item2;
}
childrenIndex = GetChildrenIndex(index);
}
return item;
}
public T Peek() { return _list[0].Item2; }
private void Swap(int index1, int index2) {
var tmp = _list[index1];
_list[index1] = _list[index2];
_list[index2] = tmp;
}
}
public class UnionFind {
private readonly int[] _array;
public UnionFind(int size) {
_array = new int[size];
for (int i = 0; i < size; i++) {
_array[i] = i;
}
}
public int GetRootNode(int n) {
if (_array[n] == n)
return n;
return _array[n] = GetRootNode(_array[n]);
}
public void UnionGroup(int a, int b) {
var rootA = GetRootNode(a);
var rootB = GetRootNode(b);
if (rootA == rootB)
return;
_array[rootA] = rootB;
}
public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);
public bool IsRoot(int n) => _array[n] == n;
}
public delegate T SegTreeCombiner<T>(T item1, T item2);
public class SegTree<T> {
private readonly T _defaultItem;
private readonly SegTreeCombiner<T> _func;
private T[] List;
private int size;
public SegTree(T[] list, T defaultItem, SegTreeCombiner<T> func) {
_defaultItem = defaultItem;
_func = func;
size = 1;
while (size < list.Length)
size <<= 1;
List = new T[2 * size - 1];
for (int i = 0; i < list.Length; i++)
List[i + size - 1] = list[i];
for (int i = list.Length; i < size; i++)
List[i + size - 1] = defaultItem;
for (int i = size - 1 - 1; i >= 0; i--) {
List[i] = _func(List[2 * i + 1], List[2 * i + 2]);
}
}
public void Update(int index, T value) {
index += size - 1;
List[index] = value;
while (index > 0) {
index = (index - 1) >> 1;
List[index] = _func(List[2 * index + 1], List[2 * index + 2]);
}
}
public T Query(int a, int b) { return Query(a, b, 0, 0, size); }
private T Query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return _defaultItem;
if (a <= l && r <= b)
return List[k];
return _func(Query(a, b, k * 2 + 1, l, (l + r) >> 1),
Query(a, b, k * 2 + 2, (l + r) >> 1, r));
}
}
public static class BinarySearch {
public delegate bool Terms<T>(T i);
public static int UpperBound(int initLeft, int initRight, Terms<int> term) {
// TODO:範囲内に条件を満たす区間が存在しない場合に対応する
int left = initLeft - 1, right = initRight;
while (right - left > 1) {
int mid = (left + right) >> 1;
if (mid != initLeft - 1 && term(mid))
left = mid;
else
right = mid;
}
return left;
}
public static long UpperBound(long initLeft, long initRight,
Terms<long> term) {
long left = initLeft - 1, right = initRight;
while (right - left > 1) {
long mid = (left + right) >> 1;
if (mid != initLeft - 1 && term(mid))
left = mid;
else
right = mid;
}
return left;
}
public static int LowerBound(int initLeft, int initRight, Terms<int> term) {
int left = initLeft - 1, right = initRight;
while (right - left > 1) {
int mid = (left + right) >> 1;
if (mid != initRight && term(mid))
right = mid;
else
left = mid;
}
return right;
}
public static long LowerBound(long initLeft, long initRight,
Terms<long> term) {
long left = initLeft - 1, right = initRight;
while (right - left > 1) {
long mid = (left + right) >> 1;
if (term(mid))
right = mid;
else
left = mid;
}
return right;
}
}
}
struct ModInt {
public long Value { get; }
public static long Mod { get; set; } = 1000000000L + 7;
public ModInt(long l) {
long value = l % Mod;
while (value < 0)
value += Mod;
Value = value % Mod;
}
public static implicit operator long(ModInt m) { return m.Value; }
public static implicit operator ModInt(long l) { return new ModInt(l); }
public static ModInt operator +(ModInt a, ModInt b) {
return new ModInt(a.Value + b.Value);
}
public static ModInt operator -(ModInt a, ModInt b) {
return new ModInt(a.Value - b.Value);
}
public static ModInt operator *(ModInt a, ModInt b) {
return new ModInt(a.Value * b.Value);
}
public static ModInt operator /(ModInt a, ModInt b) {
return new ModInt(a * b.Inverse());
}
public override string ToString() { return Value.ToString(); }
}
static class ModIntMath {
public static ModInt Pow(this ModInt a, ModInt b) {
var pow = b.Value;
var m = a;
ModInt ans = new ModInt(1);
while (pow != 0) {
if ((pow & 1) == 1) {
ans *= m;
}
pow >>= 1;
m *= m;
}
return ans;
}
public static ModInt Inverse(this ModInt m) {
return m.Pow((ModInt)(ModInt.Mod - 2));
}
}
namespace Extensions {
public class ConsoleInputExtension {
private static readonly ConsoleInputExtension _cin =
new ConsoleInputExtension();
public static ConsoleInputExtension Cin => _cin;
private static readonly Queue<string> _inputQueue = new Queue<string>();
private ConsoleInputExtension() {}
public static implicit operator string(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return _inputQueue.Dequeue();
}
public static implicit operator int(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return int.Parse(_inputQueue.Dequeue());
}
public static implicit operator long(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return long.Parse(_inputQueue.Dequeue());
}
public static implicit operator float(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return float.Parse(_inputQueue.Dequeue());
}
public static implicit operator double(ConsoleInputExtension _) {
if (_inputQueue.Count == 0)
Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val));
return double.Parse(_inputQueue.Dequeue());
}
}
public static class ConsoleOutputExtension {
private static StringBuilder _builder = new StringBuilder();
public static void Cout(object o) { _builder.Append(o); }
public static void CoutF(object o) {
_builder.Append(o);
Flush();
}
public static void Coutln(object o) {
_builder.Append(o);
_builder.Append('\n');
}
public static void Coutln() { _builder.Append('\n'); }
public static void CoutlnF(object o) {
_builder.Append(o);
_builder.Append('\n');
Flush();
}
public static void Flush() {
Console.Write(_builder.ToString());
_builder.Clear();
}
}
public static class MathExtension {
//最小公倍数
public static int LCM(int num1, int num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
public static long LCM(long num1, long num2) {
var gcd = GCD(num1, num2);
return num1 * (num2 / gcd);
}
//最大公約数
public static int GCD(int num1, int num2) {
int a = Math.Max(num1, num2);
int b = Math.Min(num1, num2);
if (b == 0)
return a;
int mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
public static long GCD(long num1, long num2) {
long a = Math.Max(num1, num2);
long b = Math.Min(num1, num2);
if (b == 0)
return a;
long mod;
while ((mod = a % b) != 0) {
a = b;
b = mod;
}
return b;
}
}
public static class EnumerableExtension {
public delegate void Function<in T>(T val);
public static void ForEach<T>(this IEnumerable<T> enumerable,
Function<T> function) {
foreach (var x in enumerable) {
function(x);
}
}
}
}
|
[["+", 15, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 15, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 15, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 15, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 2,702
| 6
|
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 {
// C#Lover///////////////////////////////////////////////////
int N;
string S1, S2;
void Solve() {
io.i(out N);
io.i(out S1, out S2);
Mat mat = new Mat();
//
int index = 0;
long ans = 1;
if (S1[0] == S2[0]) {
ans = 3;
} else {
ans = 12;
index = 1;
}
for (int i = 1 + index; i < S1.Length; i++) {
if (S1[i] != S2[i]) {
if (S1[i - 1] != S2[i - 1]) {
ans = (ans * 3) % mat.mod;
} else {
ans = (ans * 2) % mat.mod;
}
i++;
} else {
if (S1[i - 1] != S2[i - 1]) {
//
} else {
ans = (ans * 2) % mat.mod;
}
}
}
io.o(ans);
}
////////////////////////////////////////////////////////////
public static void Main(string[] args) { 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 REP(int n, Action<int> act) { for (int i = 0; i < n; i++) act(i); }
#endregion
}
#region default
class IO {
TYPE tp;
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);
tp = new TYPE();
}
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 tp.suitType<T>(String); }
public void i<T>(out T v) { v = tp.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] = tp.suitType<T>(String);
}
public void ini<T>(out T[] a, out T[] b, int n) {
a = new T[n];
b = new T[n];
for (int i = 0; i < n; i++) {
a[i] = i<T>();
b[i] = i<T>();
}
}
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 ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
}
class TYPE {
public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
public T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
public 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 : IComparable {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size = 0;
private int type;
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);
}
}
#endregion
#region other
class Mat {
public int mod = 1000000007; // 10^9+7
public long MulMod(long a, long b) { return (a % mod) * (b % mod) % mod; }
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 Comb(long n, long r) {
if (r == 0 || n == r)
return 1;
else if (n == 0)
return 0;
else 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 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 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 int[] DigValArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long Tousa(long a, long d, int n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, int n) {
return n * (2 * a + (n - 1) * d) / 2;
}
}
class AssociativeArray<T> : IEnumerable { // hack:配列時要初期化
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(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 => dic.First(d => d.Value == MaxVal).Key;
public T MinKey => dic.First(d => d.Value == MinVal).Key;
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 IEnumerator GetEnumerator() {
foreach (var kp in dic)
yield return kp;
}
// KeyValuePairの利用に制限がかかる
//:sort->array
}
class UnionFind {
public int[] parent;
public int[] depth;
public void Init(int n) {
parent = new int[n];
depth = new int[n];
n.REP(i => parent[i] = i);
}
public int Find(int x) {
return (parent[x] == x) ? x : parent[x] = Find(parent[x]);
}
public void Unite(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y)
return;
if (depth[x] < depth[y])
parent[x] = y;
else {
parent[y] = x;
if (depth[x] == depth[y])
depth[x]++;
}
}
public bool Same(int a, int b) { return Find(a) == Find(b); }
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
#endregion
#region Graph
class Index {
public int[] Comp(int[] bef) {
int[] aft = new int[bef.Length];
var tmp = bef.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
aft = bef.Select(v => tmp[v]).ToArray();
return aft;
}
}
class BasicGraph { //まとめよう
public List<Tuple<int, long>>[] G;
public void Init(int n) {
G = new List<Tuple<int, long>>[n + 1];
G.Length.REP(i => G[i] = new List<Tuple<int, long>>());
}
public void Dir(int[] f, int[] t) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], 1L)));
}
public void Dir(int[] f, int[] t, long[] c) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], c[i])));
}
public void NonDir(int[] f, int[] t) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], 1L));
G[t[i]].Add(Tuple.Create(f[i], 1L));
});
}
public void NonDir(int[] f, int[] t, long[] c) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], c[i]));
G[t[i]].Add(Tuple.Create(f[i], c[i]));
});
}
}
class TreeDis { // test
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;
protected long INF = (int)1e9;
public List<Tuple<int, long>>[] Adj;
public void Init(int n) {
I = n + 1;
Adj = new List<Tuple<int, long>>[I];
I.REP(i => Adj[i] = new List<Tuple<int, long>>());
}
public void AddPath(int f, int t, long c) {
Adj[f].Add(Tuple.Create(t, c));
Adj[t].Add(Tuple.Create(f, c));
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
}
class Dijkstra : ShortestPath { //隣接対応後未検証
public long MinCost(int f, int t) {
long[] cost = new long[I];
cost.Set(INF);
cost[f] = 0;
var pq = new PQueue<Tuple<int, long>>();
pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost)
while (pq.Count > 0) {
var cur = pq.Dequeue();
if (cost[cur.Item1] < cur.Item2)
continue;
Adj[cur.Item1].Count.REP(i => {
var tmp = Adj[cur.Item1][i];
if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) {
cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2;
pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1]));
}
});
}
return cost[t];
}
}
class BellmanFord : ShortestPath {
public long MinCost(int f, int t) {
long[] cost = new long[I];
cost.Set(INF);
cost[f] = 0;
bool isUpdate = true;
while (isUpdate) {
isUpdate = false;
I.REP(i => Adj[i].Count.REP(j => {
var cur = Adj[i][j];
if (cost[cur.Item1] > cost[i] + cur.Item2) {
cost[cur.Item1] = cost[i] + cur.Item2;
isUpdate = true;
}
}));
}
return cost[t];
}
}
class WarshallFloyd { //要チェック
private int E;
private int INF = (int)1e9;
public long[,] G;
public void Init(int n) {
E = n + 1;
G = new long[E, E];
G.Set(INF);
E.REP(i => G[i, i] = 0);
}
public void AddPath(int f, int t, long c) {
G[f, t] = c;
G[t, f] = c;
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
public long[,] MinCostArr() {
E.REP(i => E.REP(
j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]))));
return G;
}
}
#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 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 isOdd(this int v) { return v % 2 != 0; }
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; i++)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(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));
}
}
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 TestEx {}
#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 {
// C#Lover///////////////////////////////////////////////////
int N;
string S1, S2;
void Solve() {
io.i(out N);
io.i(out S1, out S2);
Mat mat = new Mat();
//
int index = 0;
long ans = 1;
if (S1[0] == S2[0]) {
ans = 3;
} else {
ans = 6;
index = 1;
}
for (int i = 1 + index; i < S1.Length; i++) {
if (S1[i] != S2[i]) {
if (S1[i - 1] != S2[i - 1]) {
ans = (ans * 3) % mat.mod;
} else {
ans = (ans * 2) % mat.mod;
}
i++;
} else {
if (S1[i - 1] != S2[i - 1]) {
//
} else {
ans = (ans * 2) % mat.mod;
}
}
}
io.o(ans);
}
////////////////////////////////////////////////////////////
public static void Main(string[] args) { 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 REP(int n, Action<int> act) { for (int i = 0; i < n; i++) act(i); }
#endregion
}
#region default
class IO {
TYPE tp;
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);
tp = new TYPE();
}
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 tp.suitType<T>(String); }
public void i<T>(out T v) { v = tp.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] = tp.suitType<T>(String);
}
public void ini<T>(out T[] a, out T[] b, int n) {
a = new T[n];
b = new T[n];
for (int i = 0; i < n; i++) {
a[i] = i<T>();
b[i] = i<T>();
}
}
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 ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
}
class TYPE {
public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
public T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
public 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 : IComparable {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size = 0;
private int type;
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);
}
}
#endregion
#region other
class Mat {
public int mod = 1000000007; // 10^9+7
public long MulMod(long a, long b) { return (a % mod) * (b % mod) % mod; }
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 Comb(long n, long r) {
if (r == 0 || n == r)
return 1;
else if (n == 0)
return 0;
else 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 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 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 int[] DigValArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long Tousa(long a, long d, int n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, int n) {
return n * (2 * a + (n - 1) * d) / 2;
}
}
class AssociativeArray<T> : IEnumerable { // hack:配列時要初期化
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(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 => dic.First(d => d.Value == MaxVal).Key;
public T MinKey => dic.First(d => d.Value == MinVal).Key;
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 IEnumerator GetEnumerator() {
foreach (var kp in dic)
yield return kp;
}
// KeyValuePairの利用に制限がかかる
//:sort->array
}
class UnionFind {
public int[] parent;
public int[] depth;
public void Init(int n) {
parent = new int[n];
depth = new int[n];
n.REP(i => parent[i] = i);
}
public int Find(int x) {
return (parent[x] == x) ? x : parent[x] = Find(parent[x]);
}
public void Unite(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y)
return;
if (depth[x] < depth[y])
parent[x] = y;
else {
parent[y] = x;
if (depth[x] == depth[y])
depth[x]++;
}
}
public bool Same(int a, int b) { return Find(a) == Find(b); }
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
#endregion
#region Graph
class Index {
public int[] Comp(int[] bef) {
int[] aft = new int[bef.Length];
var tmp = bef.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
aft = bef.Select(v => tmp[v]).ToArray();
return aft;
}
}
class BasicGraph { //まとめよう
public List<Tuple<int, long>>[] G;
public void Init(int n) {
G = new List<Tuple<int, long>>[n + 1];
G.Length.REP(i => G[i] = new List<Tuple<int, long>>());
}
public void Dir(int[] f, int[] t) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], 1L)));
}
public void Dir(int[] f, int[] t, long[] c) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], c[i])));
}
public void NonDir(int[] f, int[] t) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], 1L));
G[t[i]].Add(Tuple.Create(f[i], 1L));
});
}
public void NonDir(int[] f, int[] t, long[] c) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], c[i]));
G[t[i]].Add(Tuple.Create(f[i], c[i]));
});
}
}
class TreeDis { // test
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;
protected long INF = (int)1e9;
public List<Tuple<int, long>>[] Adj;
public void Init(int n) {
I = n + 1;
Adj = new List<Tuple<int, long>>[I];
I.REP(i => Adj[i] = new List<Tuple<int, long>>());
}
public void AddPath(int f, int t, long c) {
Adj[f].Add(Tuple.Create(t, c));
Adj[t].Add(Tuple.Create(f, c));
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
}
class Dijkstra : ShortestPath { //隣接対応後未検証
public long MinCost(int f, int t) {
long[] cost = new long[I];
cost.Set(INF);
cost[f] = 0;
var pq = new PQueue<Tuple<int, long>>();
pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost)
while (pq.Count > 0) {
var cur = pq.Dequeue();
if (cost[cur.Item1] < cur.Item2)
continue;
Adj[cur.Item1].Count.REP(i => {
var tmp = Adj[cur.Item1][i];
if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) {
cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2;
pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1]));
}
});
}
return cost[t];
}
}
class BellmanFord : ShortestPath {
public long MinCost(int f, int t) {
long[] cost = new long[I];
cost.Set(INF);
cost[f] = 0;
bool isUpdate = true;
while (isUpdate) {
isUpdate = false;
I.REP(i => Adj[i].Count.REP(j => {
var cur = Adj[i][j];
if (cost[cur.Item1] > cost[i] + cur.Item2) {
cost[cur.Item1] = cost[i] + cur.Item2;
isUpdate = true;
}
}));
}
return cost[t];
}
}
class WarshallFloyd { //要チェック
private int E;
private int INF = (int)1e9;
public long[,] G;
public void Init(int n) {
E = n + 1;
G = new long[E, E];
G.Set(INF);
E.REP(i => G[i, i] = 0);
}
public void AddPath(int f, int t, long c) {
G[f, t] = c;
G[t, f] = c;
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
public long[,] MinCostArr() {
E.REP(i => E.REP(
j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]))));
return G;
}
}
#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 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 isOdd(this int v) { return v % 2 != 0; }
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; i++)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(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));
}
}
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 TestEx {}
#endregion
}
|
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 5,645
| 2
|
using System;
using System.Linq;
class GFG {
public static void Main() {
// var input = Console.ReadLine().Split(' ');
// var x = int.Parse(input[0]);
// var a = int.Parse(input[1]);
// var b = int.Parse(input[2]);
// var n = int.Parse(Console.ReadLine());
// var ss = str.ToCharArray().OrderBy(x => x).ToArray();
var s1 = Console.ReadLine();
// var s2 = Console.ReadLine();
Pallindrom(s1);
}
static void Pallindrom(string n) {
int l = 0;
int r = n.Length - 1;
while (l >= r) {
if (n[l] != n[r]) {
Console.Write("No");
return;
}
l++;
r--;
}
Console.Write("Yes");
}
}
|
using System;
using System.Linq;
class GFG {
public static void Main() {
// var input = Console.ReadLine().Split(' ');
// var x = int.Parse(input[0]);
// var a = int.Parse(input[1]);
// var b = int.Parse(input[2]);
// var n = int.Parse(Console.ReadLine());
// var ss = str.ToCharArray().OrderBy(x => x).ToArray();
var s1 = Console.ReadLine();
// var s2 = Console.ReadLine();
Pallindrom(s1);
}
static void Pallindrom(string n) {
int l = 0;
int r = n.Length - 1;
while (l <= r) {
if (n[l] != n[r]) {
Console.Write("No");
return;
}
l++;
r--;
}
Console.Write("Yes");
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 112
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Myon {
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
void calc() {
var N = cin.next();
var A = N[0];
var B = N[1];
var C = N[2];
var ret = "No";
if (A == C && B != A) {
ret = "Yes";
}
Console.WriteLine(ret);
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Myon {
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
void calc() {
var N = cin.next();
var A = N[0];
var B = N[1];
var C = N[2];
var ret = "No";
if (A == C) {
ret = "Yes";
}
Console.WriteLine(ret);
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 497
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApp3 {
class Program {
static void Main(string[] args) {
string input = Console.ReadLine();
for (int i = 0; i < input.Length / 2; i++) {
if (input[i] != input[input.Length - i]) {
Console.WriteLine("No");
return;
}
}
Console.Write("Yes");
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApp3 {
class Program {
static void Main(string[] args) {
string input = Console.ReadLine();
for (int i = 0; i < (input.Length / 2); i++) {
if (input[i] != input[input.Length - (i + 1)]) {
Console.WriteLine("No");
return;
}
}
Console.Write("Yes");
return;
}
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 7, 15, 16, 12, 23, 0, 25], ["+", 206, 207, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 16, 12, 23, 0, 25]]
| 8
| 120
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string input = Console.ReadLine();
string revers = "";
for (int i = input.Length - 1; i <= 0; i--) {
revers += input[i];
}
if (revers == input) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string input = Console.ReadLine();
string revers = "";
for (int i = input.Length - 1; i >= 0; i--) {
revers += input[i];
}
if (revers == input) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20]]
| 8
| 117
| 2
|
using System;
namespace ABC070 {
class MainClass {
public static void Main(string[] args) {
string N = Console.ReadLine();
for (int i = 0; 2 * i < N.Length; i++) {
if (N[i] != N[N.Length - 1 - i]) {
Console.WriteLine("No");
break;
}
}
Console.WriteLine("Yes");
}
}
}
|
using System;
namespace ABC070 {
class MainClass {
public static void Main(string[] args) {
string N = Console.ReadLine();
for (int i = 0; 2 * i < N.Length; i++) {
if (N[i] != N[N.Length - 1 - i]) {
Console.WriteLine("No");
return;
}
}
Console.WriteLine("Yes");
}
}
}
|
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 92
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split();
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int d = int.Parse(input[3]);
int ans = 0;
for (int i = 0; i <= 101; i++) {
if ((a <= i && i <= b) && (c <= i && i <= d)) {
ans += 1;
}
}
Console.WriteLine(ans - 1);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split();
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int d = int.Parse(input[3]);
int ans = 0;
for (int i = 0; i <= 101; i++) {
if ((a < i && i <= b) && (c < i && i <= d)) {
ans += 1;
}
}
Console.WriteLine(ans);
}
}
|
[["-", 15, 16, 31, 23, 0, 16, 31, 16, 17, 19], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 18], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 19], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 18], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 155
| 6
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace AtCoder.Contest.B {
static class Program {
public static void Solve(Scanner cin) {
var (a, b, c, d) = cin.ReadValue<int, int, int, int>();
Console.WriteLine(Math.Max(0, Math.Min(b, d) - Math.Min(a, c)));
}
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");
}
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 AtCoder.Contest.B {
static class Program {
public static void Solve(Scanner cin) {
var (a, b, c, d) = cin.ReadValue<int, int, int, int>();
Console.WriteLine(Math.Max(0, Math.Min(b, d) - Math.Max(a, c)));
}
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");
}
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, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22]]
| 8
| 2,548
| 2
|
using System;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var ABCD =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
var A = ABCD[0];
var B = ABCD[1];
var C = ABCD[2];
var D = ABCD[3];
var result = Math.Max(0, Math.Min(C, D) - Math.Max(A, B));
Console.WriteLine(result);
}
}
}
|
using System;
using System.Linq;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
var ABCD =
Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
var A = ABCD[0];
var B = ABCD[1];
var C = ABCD[2];
var D = ABCD[3];
var result = Math.Max(0, Math.Min(B, D) - Math.Max(A, C));
Console.WriteLine(result);
}
}
}
|
[["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 126
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
string[] sS = Console.ReadLine().Trim().Split(' ');
int iA = int.Parse(sS[0]);
int iB = int.Parse(sS[1]);
int iC = int.Parse(sS[2]);
int iD = int.Parse(sS[3]);
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// 解析
int iOut = 0; // 場合分け6パターン
if (iB <= iC) {
} // 重なりなし
if (iA <= iC && iC <= iB && iB <= iD) {
iOut = iB - iC;
} // 重なりあり
if (iA <= iC && iC <= iB && iA <= iD && iD <= iB) {
iOut = iD - iC;
} // 含有
if (iD <= iA) {
} // 重なりなし
if (iC <= iA && iA <= iD && iD <= iB) {
iOut = iD - iA;
} // 重なりあり
if (iC <= iA && iA <= iC && iC <= iB && iB <= iD) {
iOut = iB - iA;
} // 含有
//出力
Console.WriteLine("{0}", iOut.ToString().Trim());
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
string[] sS = Console.ReadLine().Trim().Split(' ');
int iA = int.Parse(sS[0]);
int iB = int.Parse(sS[1]);
int iC = int.Parse(sS[2]);
int iD = int.Parse(sS[3]);
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// 解析
int iOut = 0; // 場合分け6パターン
if (iB <= iC) {
} // 重なりなし
if (iA <= iC && iC <= iB && iB <= iD) {
iOut = iB - iC;
} // 重なりあり
if (iA <= iC && iC <= iB && iA <= iD && iD <= iB) {
iOut = iD - iC;
} // 含有
if (iD <= iA) {
} // 重なりなし
if (iC <= iA && iA <= iD && iD <= iB) {
iOut = iD - iA;
} // 重なりあり
if (iC <= iA && iA <= iD && iC <= iB && iB <= iD) {
iOut = iB - iA;
} // 含有
//出力
Console.WriteLine("{0}", iOut.ToString().Trim());
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
|
[["-", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22]]
| 8
| 326
| 2
|
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
class Program {
public static void Main() {
string[] inputSplit = ReadLine().Split(' ');
int A = int.Parse(inputSplit[0]);
int B = int.Parse(inputSplit[1]);
int C = int.Parse(inputSplit[2]);
int D = int.Parse(inputSplit[3]);
int downTimeBothSwitch = 0;
int upTimeBothSwitch = 0;
int result = 0;
if (B - C <= 0 || A - D <= 0)
WriteLine("0");
else {
if (A < C)
downTimeBothSwitch = C;
else
downTimeBothSwitch = A;
if (B <= D)
upTimeBothSwitch = B;
else
upTimeBothSwitch = D;
WriteLine(upTimeBothSwitch - downTimeBothSwitch);
}
}
}
|
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
class Program {
public static void Main() {
string[] inputSplit = ReadLine().Split(' ');
int A = int.Parse(inputSplit[0]);
int B = int.Parse(inputSplit[1]);
int C = int.Parse(inputSplit[2]);
int D = int.Parse(inputSplit[3]);
int downTimeBothSwitch = 0;
int upTimeBothSwitch = 0;
int result = 0;
if (B - C <= 0 || D - A <= 0)
WriteLine("0");
else {
if (A < C)
downTimeBothSwitch = C;
else
downTimeBothSwitch = A;
if (B <= D)
upTimeBothSwitch = B;
else
upTimeBothSwitch = D;
WriteLine(upTimeBothSwitch - downTimeBothSwitch);
}
}
}
|
[["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22]]
| 8
| 183
| 4
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCorder {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
var map = new int[3];
for (int i = 0; i < N; i++) {
var a = cin.ReadInt;
if (a % 4 == 0) {
map[0]++;
continue;
} else if (a % 2 != 0) {
map[1]++;
continue;
}
map[2]++;
}
if (map[0] < map[1]) {
if (map[2] == 0 && map[1] - map[0] == 1) {
WriteLine("Yes");
} else {
WriteLine("N0");
}
} else {
WriteLine("Yes");
}
}
/*public long C(long n, long r)
{
if (r == 0 || r == n) return 1L;
if (n < r) return 0L;
long[,] Pascal = new long[n + 1, n + 1];
Pascal[0, 0] = 1;
for (long i = 1; i <= n; i++)
{
Pascal[i, 0] = 1;
Pascal[i, i] = 1;
for (long j = 1; j < n; j++)
{
Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
}
}
return Pascal[n, r];
}*/
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 AtCorder {
class Program {
static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var N = cin.ReadInt;
var map = new int[3];
for (int i = 0; i < N; i++) {
var a = cin.ReadInt;
if (a % 4 == 0) {
map[0]++;
continue;
} else if (a % 2 != 0) {
map[1]++;
continue;
}
map[2]++;
}
if (map[0] < map[1]) {
if (map[2] == 0 && map[1] - map[0] == 1) {
WriteLine("Yes");
} else {
WriteLine("No");
}
} else {
WriteLine("Yes");
}
}
/*public long C(long n, long r)
{
if (r == 0 || r == n) return 1L;
if (n < r) return 0L;
long[,] Pascal = new long[n + 1, n + 1];
Pascal[0, 0] = 1;
for (long i = 1; i <= n; i++)
{
Pascal[i, 0] = 1;
Pascal[i, i] = 1;
for (long j = 1; j < n; j++)
{
Pascal[i, j] = Pascal[i - 1, j] + Pascal[i - 1, j - 1];
}
}
return Pascal[n, r];
}*/
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, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 569
| 2
|
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleTest {
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
int N = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int a4 = 0;
int a2 = 0;
for (var i = 0; i < N; i++) {
if (a[i] % 4 == 0) {
a4++;
} else if (a[i] % 2 == 0) {
a2++;
}
}
string ans = "No";
if (a4 * 3 >= a.Length || (a4 * 3 + a2 >= a.Length && a2 >= 2)) {
ans = "Yes";
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleTest {
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
int N = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int a4 = 0;
int a2 = 0;
for (var i = 0; i < N; i++) {
if (a[i] % 4 == 0) {
a4++;
} else if (a[i] % 2 == 0) {
a2++;
}
}
string ans = "No";
if (a4 * 2 + 1 >= a.Length || (a4 * 2 + a2 >= a.Length && a2 > 0)) {
ans = "Yes";
}
Console.WriteLine(ans);
Console.Out.Flush();
}
}
}
|
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 20], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 47], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203]]
| 8
| 234
| 10
|
using System;
using System.Linq;
namespace ABC069_C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var cntFour = 0;
var cntTwo = 0;
for (int i = 0; i < N; i++) {
if (a[i] % 4 == 0) {
cntFour++;
} else if (a[i] % 2 == 0) {
cntTwo++;
}
}
if (cntTwo % 2 == 1)
cntTwo--;
var achieve = N - 2 * cntFour - cntTwo < 1;
Console.WriteLine(achieve ? "Yes" : "No");
}
}
}
|
using System;
using System.Linq;
namespace ABC069_C {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var cntFour = 0;
var cntTwo = 0;
for (int i = 0; i < N; i++) {
if (a[i] % 4 == 0) {
cntFour++;
} else if (a[i] % 2 == 0) {
cntTwo++;
}
}
if (cntTwo % 2 == 1)
cntTwo--;
var achieve = N - 2 * cntFour - cntTwo <= 1;
Console.WriteLine(achieve ? "Yes" : "No");
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 18], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 19]]
| 8
| 163
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
Scanner cin = new Scanner();
int N = cin.Int();
int[] A = cin.ArrayInt(N);
int odd = 0, num = 0; // odd:奇数の個数,num:4の倍数の個数
foreach (var x in A) {
if (x % 2 != 0)
odd++;
else if (x % 4 == 0)
num++;
}
if (num + odd == A.Length)
Console.WriteLine(num - 1 >= odd ? "Yes" : "No");
else
Console.WriteLine(num >= odd ? "Yes" : "No");
Console.ReadLine();
}
}
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double Double() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
Scanner cin = new Scanner();
int N = cin.Int();
int[] A = cin.ArrayInt(N);
int odd = 0, num = 0; // odd:奇数の個数,num:4の倍数の個数
foreach (var x in A) {
if (x % 2 != 0)
odd++;
else if (x % 4 == 0)
num++;
}
if (num + odd == A.Length)
Console.WriteLine(num >= odd - 1 ? "Yes" : "No");
else
Console.WriteLine(num >= odd ? "Yes" : "No");
Console.ReadLine();
}
}
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double Double() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
|
[["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 33], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 33], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 203]]
| 8
| 513
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
Console.ReadLine();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int other = 0;
int multi2 = 0;
int multi4 = 0;
foreach (var i in a) {
if (i % 2 == 0) {
if (i % 4 == 0) {
multi4++;
} else {
multi2++;
}
} else {
other++;
}
}
if (other == multi4 || (other - 1 == multi4 && multi2 == 0)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
Console.ReadLine();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int other = 0;
int multi2 = 0;
int multi4 = 0;
foreach (var i in a) {
if (i % 2 == 0) {
if (i % 4 == 0) {
multi4++;
} else {
multi2++;
}
} else {
other++;
}
}
if (other <= multi4 || (other - 1 == multi4 && multi2 == 0)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19]]
| 8
| 158
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp11 {
class Class68 {
static void Main() {
int N = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count4 = a.Count(x => x % 4 == 0);
int count2 = a.Where(x => x % 4 != 0).Count(y => y % 2 == 0);
int test = count4 * 3 + count2;
Console.WriteLine(test >= N ? "Yes" : "No");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp11 {
class Class68 {
static void Main() {
int N = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int count4 = a.Count(x => x % 4 == 0);
int count2 = a.Where(x => x % 4 != 0).Count(y => y % 2 == 0);
int test = count4 + count2 / 2;
Console.WriteLine(test >= N / 2 ? "Yes" : "No");
}
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 85], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 203]]
| 8
| 149
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
// using static System.Globalization.CultureInfo;
class Program {
static void Main(string[] args) {
var num = ToInt32(ReadLine());
var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var pp = new int[num];
for (var i = 0; i < num; i++)
if (ar[i] % 4 == 0)
pp[i] = 2;
else if (ar[i] % 2 == 0)
pp[i] = 1;
var ct4 = pp.Count(v => v == 2);
var ct2 = pp.Count(v => v == 1);
var res = num - 2 * ct4 - ct2 - ct2 == 0 ? 1 : 0;
WriteLine(res <= 0 ? "Yes" : "No");
}
private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
private const int MOD = 1000000007;
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
// using static System.Globalization.CultureInfo;
class Program {
static void Main(string[] args) {
var num = ToInt32(ReadLine());
var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var pp = new int[num];
for (var i = 0; i < num; i++)
if (ar[i] % 4 == 0)
pp[i] = 2;
else if (ar[i] % 2 == 0)
pp[i] = 1;
var ct4 = pp.Count(v => v == 2);
var ct2 = pp.Count(v => v == 1);
var res = num - 2 * ct4 - ct2 - (ct2 == 0 ? 1 : 0);
WriteLine(res <= 0 ? "Yes" : "No");
}
private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
private const int MOD = 1000000007;
}
|
[["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
| 8
| 220
| 2
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
class Program {
static void Main() {
int n = C.NextInt();
int c4 = 0;
int c0 = 0;
for (int i = 0; i < n; i++) {
int m = C.NextInt();
if (m % 4 == 0)
c4++;
if (m % 2 != 0)
c0++;
}
bool f = (c0 + c4 != n && c0 <= c4) || (c0 + c4 == n && c0 < c4);
C.WriteLine(f ? "Yes" : "No");
}
}
//以下標準出入力用のクラス
static class C {
public static string NextToken() {
StringBuilder tokenChars = new StringBuilder();
bool tokenFinished = false;
bool skipWhiteSpaceMode = true;
while (!tokenFinished) {
int nextChar = Console.Read();
if (nextChar == -1)
tokenFinished = true;
else {
char ch = (char)nextChar;
if (char.IsWhiteSpace(ch)) {
if (!skipWhiteSpaceMode) {
tokenFinished = true;
if (ch == '\r' && (Environment.NewLine == "\r\n"))
Console.Read();
}
} else {
skipWhiteSpaceMode = false;
tokenChars.Append(ch);
}
}
}
return tokenChars.ToString();
}
public static int NextInt() {
string token = C.NextToken();
return int.Parse(token);
}
public static long NextLong() {
string token = C.NextToken();
return long.Parse(token);
}
public static double NextDouble(bool acceptAnyDecimalSeparator = true) {
string token = C.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
double result = double.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
double result = double.Parse(token);
return result;
}
}
public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) {
string token = C.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
decimal result = decimal.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
decimal result = decimal.Parse(token);
return result;
}
}
[System.Runtime.InteropServices.DllImport("msvcrt.dll")]
private static extern void printf(string s);
public static void Write(string s) { printf(s); }
public static void Write(char c) { printf(c.ToString()); }
public static void Write(long n) { printf(n.ToString()); }
public static void Write(int n) { printf(n.ToString()); }
public static void Write(double d) { printf(d.ToString()); }
public static void WriteLine() { printf("\n"); }
public static void WriteLine(string s) { printf(s + "\n"); }
public static void WriteLine(char c) { WriteLine(c.ToString()); }
public static void WriteLine(long n) { WriteLine(n.ToString()); }
public static void WriteLine(int n) { WriteLine(n.ToString()); }
public static void WriteLine(double d) { WriteLine(d.ToString()); }
public static void WriteLines(string[] s) {
foreach (var i in s)
WriteLine(i);
}
public static void WriteLines(char[] c) {
foreach (var i in c)
WriteLine(i);
}
public static void WriteLines(long[] c) {
foreach (var i in c)
WriteLine(i);
}
public static void WriteLines(int[] c) {
foreach (var i in c)
WriteLine(i);
}
public static void WriteLines(double[] d) {
foreach (var i in d)
WriteLine(i);
}
}
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
class Program {
static void Main() {
int n = C.NextInt();
int c4 = 0;
int c0 = 0;
for (int i = 0; i < n; i++) {
int m = C.NextInt();
if (m % 4 == 0)
c4++;
if (m % 2 != 0)
c0++;
}
bool f = (c0 + c4 != n && c0 <= c4) || (c0 + c4 == n && c0 - 1 <= c4);
C.WriteLine(f ? "Yes" : "No");
}
}
//以下標準出入力用のクラス
static class C {
public static string NextToken() {
StringBuilder tokenChars = new StringBuilder();
bool tokenFinished = false;
bool skipWhiteSpaceMode = true;
while (!tokenFinished) {
int nextChar = Console.Read();
if (nextChar == -1)
tokenFinished = true;
else {
char ch = (char)nextChar;
if (char.IsWhiteSpace(ch)) {
if (!skipWhiteSpaceMode) {
tokenFinished = true;
if (ch == '\r' && (Environment.NewLine == "\r\n"))
Console.Read();
}
} else {
skipWhiteSpaceMode = false;
tokenChars.Append(ch);
}
}
}
return tokenChars.ToString();
}
public static int NextInt() {
string token = C.NextToken();
return int.Parse(token);
}
public static long NextLong() {
string token = C.NextToken();
return long.Parse(token);
}
public static double NextDouble(bool acceptAnyDecimalSeparator = true) {
string token = C.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
double result = double.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
double result = double.Parse(token);
return result;
}
}
public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) {
string token = C.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
decimal result = decimal.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
decimal result = decimal.Parse(token);
return result;
}
}
[System.Runtime.InteropServices.DllImport("msvcrt.dll")]
private static extern void printf(string s);
public static void Write(string s) { printf(s); }
public static void Write(char c) { printf(c.ToString()); }
public static void Write(long n) { printf(n.ToString()); }
public static void Write(int n) { printf(n.ToString()); }
public static void Write(double d) { printf(d.ToString()); }
public static void WriteLine() { printf("\n"); }
public static void WriteLine(string s) { printf(s + "\n"); }
public static void WriteLine(char c) { WriteLine(c.ToString()); }
public static void WriteLine(long n) { WriteLine(n.ToString()); }
public static void WriteLine(int n) { WriteLine(n.ToString()); }
public static void WriteLine(double d) { WriteLine(d.ToString()); }
public static void WriteLines(string[] s) {
foreach (var i in s)
WriteLine(i);
}
public static void WriteLines(char[] c) {
foreach (var i in c)
WriteLine(i);
}
public static void WriteLines(long[] c) {
foreach (var i in c)
WriteLine(i);
}
public static void WriteLines(int[] c) {
foreach (var i in c)
WriteLine(i);
}
public static void WriteLines(double[] d) {
foreach (var i in d)
WriteLine(i);
}
}
|
[["-", 0, 16, 12, 23, 0, 16, 12, 16, 17, 18], ["+", 12, 23, 0, 16, 12, 16, 31, 16, 17, 33], ["+", 12, 23, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 17, 19]]
| 8
| 827
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
private int N;
private int[] A;
private void Scan() {
var l = Console.ReadLine().Split(' ');
N = int.Parse(l[0]);
l = Console.ReadLine().Split();
A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = int.Parse(l[i]);
}
}
public void Solve() {
Scan();
int one = 0, two = 0, four = 0;
foreach (int i in A) {
if (i % 4 == 0) {
four++;
} else if (i % 2 == 0) {
two++;
} else {
one++;
}
}
bool ans;
if (two == 0) {
ans = four >= one + 1;
if (four == 0) {
ans = false;
}
} else {
ans = four >= one;
}
Console.WriteLine(ans ? "Yes" : "No");
}
static void Main() { new Program().Solve(); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
private int N;
private int[] A;
private void Scan() {
var l = Console.ReadLine().Split(' ');
N = int.Parse(l[0]);
l = Console.ReadLine().Split();
A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = int.Parse(l[i]);
}
}
public void Solve() {
Scan();
int one = 0, two = 0, four = 0;
foreach (int i in A) {
if (i % 4 == 0) {
four++;
} else if (i % 2 == 0) {
two++;
} else {
one++;
}
}
bool ans;
if (two == 0) {
ans = four + 1 >= one;
if (four == 0) {
ans = false;
}
} else {
ans = four >= one;
}
Console.WriteLine(ans ? "Yes" : "No");
}
static void Main() { new Program().Solve(); }
}
|
[["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 20], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 20], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
| 8
| 257
| 4
|
using System;
public class AtCoderFourAdjacent {
public static void Main(String[] args) {
int n = int.Parse(Console.ReadLine());
int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int numDivisibleByFour = 0;
int numOdd = 0;
foreach (var e in arr) {
if (e % 2 != 0) {
numOdd++;
} else if (e % 4 == 0) {
numDivisibleByFour++;
}
}
if (numDivisibleByFour >= numOdd) {
Console.WriteLine("YES");
} else if (numDivisibleByFour == (numOdd - 1) &&
numDivisibleByFour + numOdd == n) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
|
using System;
public class AtCoderFourAdjacent {
public static void Main(String[] args) {
int n = int.Parse(Console.ReadLine());
int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int numDivisibleByFour = 0;
int numOdd = 0;
foreach (var e in arr) {
if (e % 2 != 0) {
numOdd++;
} else if (e % 4 == 0) {
numDivisibleByFour++;
}
}
if (numDivisibleByFour >= numOdd) {
Console.WriteLine("Yes");
} else if (numDivisibleByFour == (numOdd - 1) &&
numDivisibleByFour + numOdd == n) {
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
| 164
| 6
|
using System;
using System.Linq;
namespace arc080_a {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int nottwo = 0;
int two = 0;
int four = 0;
for (int i = 0; i < n; i++) {
if (x[i] % 2 != 0)
nottwo++;
else if (x[i] % 4 != 0)
two++;
else
four++;
}
two %= 2;
Console.WriteLine(four >= nottwo - two ? "Yes" : "No");
}
}
}
|
using System;
using System.Linq;
namespace arc080_a {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int nottwo = 0;
int two = 0;
int four = 0;
for (int i = 0; i < n; i++) {
if (x[i] % 2 != 0)
nottwo++;
else if (x[i] % 4 != 0)
two++;
else
four++;
}
two %= 2;
Console.WriteLine(four - two >= nottwo - 1 ? "Yes" : "No");
}
}
}
|
[["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 33], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 12, 22], ["-", 0, 28, 0, 41, 15, 16, 12, 16, 12, 22], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 203]]
| 8
| 154
| 4
|
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApplication1.CodeForces {
public class LowerBoundSortedSet<T> : SortedSet<T> {
private ComparerDecorator<T> _comparerDecorator;
private class ComparerDecorator<T> : IComparer<T> {
private IComparer<T> _comparer;
public T LowerBound { get; private set; }
public T UpperBound { get; private set; }
private bool _reset = true;
public void Reset() { _reset = true; }
public ComparerDecorator(IComparer<T> comparer) { _comparer = comparer; }
public int Compare(T x, T y) {
int num = _comparer.Compare(x, y);
if (_reset) {
LowerBound = y;
UpperBound = y;
}
if (num >= 0) {
LowerBound = y;
_reset = false;
}
if (num <= 0) {
UpperBound = y;
_reset = false;
}
return num;
}
}
public LowerBoundSortedSet() : this(Comparer<T>.Default) {}
public LowerBoundSortedSet(IComparer<T> comparer)
: base(new ComparerDecorator<T>(comparer)) {
_comparerDecorator = (ComparerDecorator<T>)this.Comparer;
}
public T FindLowerBound(T key) {
_comparerDecorator.Reset();
this.Contains<T>(key);
return _comparerDecorator.LowerBound;
}
public T FindUpperBound(T key) {
_comparerDecorator.Reset();
this.Contains<T>(key);
return _comparerDecorator.UpperBound;
}
}
public abstract class Heap<T> : IEnumerable<T> {
private const int InitialCapacity = 0;
private const int GrowFactor = 2;
private const int MinGrow = 1;
private int _capacity = InitialCapacity;
private T[] _heap = new T[InitialCapacity];
private int _tail = 0;
public int Count {
get { return _tail; }
}
public int Capacity {
get { return _capacity; }
}
protected Comparer<T> Comparer { get; private set; }
protected abstract bool Dominates(T x, T y);
protected Heap() : this(Comparer<T>.Default) {}
protected Heap(Comparer<T> comparer)
: this(Enumerable.Empty<T>(), comparer) {}
protected Heap(IEnumerable<T> collection)
: this(collection, Comparer<T>.Default) {}
protected Heap(IEnumerable<T> collection, Comparer<T> comparer) {
if (collection == null)
throw new ArgumentNullException("collection");
if (comparer == null)
throw new ArgumentNullException("comparer");
Comparer = comparer;
foreach (var item in collection) {
if (Count == Capacity)
Grow();
_heap[_tail++] = item;
}
for (int i = Parent(_tail - 1); i >= 0; i--)
BubbleDown(i);
}
public void Add(T item) {
if (Count == Capacity)
Grow();
_heap[_tail++] = item;
BubbleUp(_tail - 1);
}
private void BubbleUp(int i) {
if (i == 0 || Dominates(_heap[Parent(i)], _heap[i]))
return; // correct domination (or root)
Swap(i, Parent(i));
BubbleUp(Parent(i));
}
public T GetMin() {
if (Count == 0)
throw new InvalidOperationException("Heap is empty");
return _heap[0];
}
public T ExtractDominating() {
if (Count == 0)
throw new InvalidOperationException("Heap is empty");
T ret = _heap[0];
_tail--;
Swap(_tail, 0);
BubbleDown(0);
return ret;
}
private void BubbleDown(int i) {
int dominatingNode = Dominating(i);
if (dominatingNode == i)
return;
Swap(i, dominatingNode);
BubbleDown(dominatingNode);
}
private int Dominating(int i) {
int dominatingNode = i;
dominatingNode = GetDominating(YoungChild(i), dominatingNode);
dominatingNode = GetDominating(OldChild(i), dominatingNode);
return dominatingNode;
}
private int GetDominating(int newNode, int dominatingNode) {
if (newNode < _tail && !Dominates(_heap[dominatingNode], _heap[newNode]))
return newNode;
else
return dominatingNode;
}
private void Swap(int i, int j) {
T tmp = _heap[i];
_heap[i] = _heap[j];
_heap[j] = tmp;
}
private static int Parent(int i) { return (i + 1) / 2 - 1; }
private static int YoungChild(int i) { return (i + 1) * 2 - 1; }
private static int OldChild(int i) { return YoungChild(i) + 1; }
private void Grow() {
int newCapacity = _capacity * GrowFactor + MinGrow;
var newHeap = new T[newCapacity];
Array.Copy(_heap, newHeap, _capacity);
_heap = newHeap;
_capacity = newCapacity;
}
public IEnumerator<T> GetEnumerator() {
return _heap.Take(Count).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
public class MaxHeap<T> : Heap<T> {
public MaxHeap() : this(Comparer<T>.Default) {}
public MaxHeap(Comparer<T> comparer) : base(comparer) {}
public MaxHeap(IEnumerable<T> collection, Comparer<T> comparer)
: base(collection, comparer) {}
public MaxHeap(IEnumerable<T> collection) : base(collection) {}
protected override bool Dominates(T x, T y) {
return Comparer.Compare(x, y) >= 0;
}
}
public class MinHeap<T> : Heap<T> {
public MinHeap() : this(Comparer<T>.Default) {}
public MinHeap(Comparer<T> comparer) : base(comparer) {}
public MinHeap(IEnumerable<T> collection) : base(collection) {}
public MinHeap(IEnumerable<T> collection, Comparer<T> comparer)
: base(collection, comparer) {}
protected override bool Dominates(T x, T y) {
return Comparer.Compare(x, y) <= 0;
}
}
static class _4032123 {
private static int Next() {
int c;
int res = 0;
do {
c = reader.Read();
if (c == -1)
return res;
} while (c < '0' || c > '9');
res = c - '0';
while (true) {
c = reader.Read();
if (c < '0' || c > '9')
return res;
res *= 10;
res += c - '0';
}
}
private static readonly StreamReader reader = new StreamReader(
Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
private static readonly StreamWriter writer = new StreamWriter(
Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);
class Node {
public int Number { get; set; }
public char Letter { get; set; }
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
static void Main(String[] args) {
var N = int.Parse(Console.ReadLine().TrimEnd());
var data =
Console.ReadLine().TrimEnd().Split(' ').Select(long.Parse).ToList();
long divBy4 = data.Count(a => a % 4 == 0);
long divBy2NotBy4 = data.Count(a => a % 4 != 0 && a % 2 == 0);
bool canAdd = (divBy2NotBy4 / 3) >= 1;
long dist = (divBy2NotBy4 / 3) * 3;
divBy2NotBy4 -= (divBy2NotBy4 / 3) * 3;
if (canAdd) {
dist += divBy2NotBy4;
} else if (divBy2NotBy4 == 2) {
dist += divBy2NotBy4;
}
if (dist >= 0 && divBy4 >= 1) {
dist--;
}
dist += divBy4 * 3;
dist -= (divBy4 - 1);
if (dist >= N) {
writer.WriteLine("Yes");
} else {
writer.WriteLine("No");
}
writer.Flush();
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApplication1.CodeForces {
public class LowerBoundSortedSet<T> : SortedSet<T> {
private ComparerDecorator<T> _comparerDecorator;
private class ComparerDecorator<T> : IComparer<T> {
private IComparer<T> _comparer;
public T LowerBound { get; private set; }
public T UpperBound { get; private set; }
private bool _reset = true;
public void Reset() { _reset = true; }
public ComparerDecorator(IComparer<T> comparer) { _comparer = comparer; }
public int Compare(T x, T y) {
int num = _comparer.Compare(x, y);
if (_reset) {
LowerBound = y;
UpperBound = y;
}
if (num >= 0) {
LowerBound = y;
_reset = false;
}
if (num <= 0) {
UpperBound = y;
_reset = false;
}
return num;
}
}
public LowerBoundSortedSet() : this(Comparer<T>.Default) {}
public LowerBoundSortedSet(IComparer<T> comparer)
: base(new ComparerDecorator<T>(comparer)) {
_comparerDecorator = (ComparerDecorator<T>)this.Comparer;
}
public T FindLowerBound(T key) {
_comparerDecorator.Reset();
this.Contains<T>(key);
return _comparerDecorator.LowerBound;
}
public T FindUpperBound(T key) {
_comparerDecorator.Reset();
this.Contains<T>(key);
return _comparerDecorator.UpperBound;
}
}
public abstract class Heap<T> : IEnumerable<T> {
private const int InitialCapacity = 0;
private const int GrowFactor = 2;
private const int MinGrow = 1;
private int _capacity = InitialCapacity;
private T[] _heap = new T[InitialCapacity];
private int _tail = 0;
public int Count {
get { return _tail; }
}
public int Capacity {
get { return _capacity; }
}
protected Comparer<T> Comparer { get; private set; }
protected abstract bool Dominates(T x, T y);
protected Heap() : this(Comparer<T>.Default) {}
protected Heap(Comparer<T> comparer)
: this(Enumerable.Empty<T>(), comparer) {}
protected Heap(IEnumerable<T> collection)
: this(collection, Comparer<T>.Default) {}
protected Heap(IEnumerable<T> collection, Comparer<T> comparer) {
if (collection == null)
throw new ArgumentNullException("collection");
if (comparer == null)
throw new ArgumentNullException("comparer");
Comparer = comparer;
foreach (var item in collection) {
if (Count == Capacity)
Grow();
_heap[_tail++] = item;
}
for (int i = Parent(_tail - 1); i >= 0; i--)
BubbleDown(i);
}
public void Add(T item) {
if (Count == Capacity)
Grow();
_heap[_tail++] = item;
BubbleUp(_tail - 1);
}
private void BubbleUp(int i) {
if (i == 0 || Dominates(_heap[Parent(i)], _heap[i]))
return; // correct domination (or root)
Swap(i, Parent(i));
BubbleUp(Parent(i));
}
public T GetMin() {
if (Count == 0)
throw new InvalidOperationException("Heap is empty");
return _heap[0];
}
public T ExtractDominating() {
if (Count == 0)
throw new InvalidOperationException("Heap is empty");
T ret = _heap[0];
_tail--;
Swap(_tail, 0);
BubbleDown(0);
return ret;
}
private void BubbleDown(int i) {
int dominatingNode = Dominating(i);
if (dominatingNode == i)
return;
Swap(i, dominatingNode);
BubbleDown(dominatingNode);
}
private int Dominating(int i) {
int dominatingNode = i;
dominatingNode = GetDominating(YoungChild(i), dominatingNode);
dominatingNode = GetDominating(OldChild(i), dominatingNode);
return dominatingNode;
}
private int GetDominating(int newNode, int dominatingNode) {
if (newNode < _tail && !Dominates(_heap[dominatingNode], _heap[newNode]))
return newNode;
else
return dominatingNode;
}
private void Swap(int i, int j) {
T tmp = _heap[i];
_heap[i] = _heap[j];
_heap[j] = tmp;
}
private static int Parent(int i) { return (i + 1) / 2 - 1; }
private static int YoungChild(int i) { return (i + 1) * 2 - 1; }
private static int OldChild(int i) { return YoungChild(i) + 1; }
private void Grow() {
int newCapacity = _capacity * GrowFactor + MinGrow;
var newHeap = new T[newCapacity];
Array.Copy(_heap, newHeap, _capacity);
_heap = newHeap;
_capacity = newCapacity;
}
public IEnumerator<T> GetEnumerator() {
return _heap.Take(Count).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
public class MaxHeap<T> : Heap<T> {
public MaxHeap() : this(Comparer<T>.Default) {}
public MaxHeap(Comparer<T> comparer) : base(comparer) {}
public MaxHeap(IEnumerable<T> collection, Comparer<T> comparer)
: base(collection, comparer) {}
public MaxHeap(IEnumerable<T> collection) : base(collection) {}
protected override bool Dominates(T x, T y) {
return Comparer.Compare(x, y) >= 0;
}
}
public class MinHeap<T> : Heap<T> {
public MinHeap() : this(Comparer<T>.Default) {}
public MinHeap(Comparer<T> comparer) : base(comparer) {}
public MinHeap(IEnumerable<T> collection) : base(collection) {}
public MinHeap(IEnumerable<T> collection, Comparer<T> comparer)
: base(collection, comparer) {}
protected override bool Dominates(T x, T y) {
return Comparer.Compare(x, y) <= 0;
}
}
static class _4032123 {
private static int Next() {
int c;
int res = 0;
do {
c = reader.Read();
if (c == -1)
return res;
} while (c < '0' || c > '9');
res = c - '0';
while (true) {
c = reader.Read();
if (c < '0' || c > '9')
return res;
res *= 10;
res += c - '0';
}
}
private static readonly StreamReader reader = new StreamReader(
Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
private static readonly StreamWriter writer = new StreamWriter(
Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);
class Node {
public int Number { get; set; }
public char Letter { get; set; }
}
private static long Factorial(int i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
static void Main(String[] args) {
var N = int.Parse(Console.ReadLine().TrimEnd());
var data =
Console.ReadLine().TrimEnd().Split(' ').Select(long.Parse).ToList();
long divBy4 = data.Count(a => a % 4 == 0);
long divBy2NotBy4 = data.Count(a => a % 4 != 0 && a % 2 == 0);
bool canAdd = (divBy2NotBy4 / 3) >= 1;
long dist = (divBy2NotBy4 / 3) * 3;
divBy2NotBy4 -= (divBy2NotBy4 / 3) * 3;
if (canAdd) {
dist += divBy2NotBy4;
} else if (divBy2NotBy4 == 2) {
dist += divBy2NotBy4;
}
if (dist > 0 && divBy4 >= 1) {
dist--;
}
dist += divBy4 * 3;
dist -= (divBy4 - 1);
if (dist >= N) {
writer.WriteLine("Yes");
} else {
writer.WriteLine("No");
}
writer.Flush();
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47]]
| 8
| 1,698
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace ARC080B {
class Program {
static void Solve() {
var h = Input.NextInt();
var w = Input.NextInt();
var n = Input.NextInt();
var a = Input.NextInt(n);
var map = Enumerable.Repeat(0, h)
.Select(_ => Enumerable.Repeat(0, w).ToArray())
.ToArray();
int r = 0, c = 0;
int dir = 1;
for (int i = 0; i < a.Count(); i++) {
var m = a[i];
while (m-- > 0) {
map[r][c] = i;
c += dir;
if (c >= w) {
c = w - 1;
dir = -1;
r++;
} else if (c < 0) {
c = 0;
dir = 1;
r++;
}
}
}
for (int i = 0; i < h; i++) {
Console.WriteLine(string.Join(" ", map[i]));
}
}
#region Competitive Template
public static void Main(string[] args) {
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 仮想的に標準入力をセットする
// NextLine系を使っていると使えない
// Input.SetText("");
Solve();
Console.Out.Flush();
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
#endregion
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace ARC080B {
class Program {
static void Solve() {
var h = Input.NextInt();
var w = Input.NextInt();
var n = Input.NextInt();
var a = Input.NextInt(n);
var map = Enumerable.Repeat(0, h)
.Select(_ => Enumerable.Repeat(0, w).ToArray())
.ToArray();
int r = 0, c = 0;
int dir = 1;
for (int i = 0; i < a.Count(); i++) {
var m = a[i];
while (m-- > 0) {
map[r][c] = i + 1;
c += dir;
if (c >= w) {
c = w - 1;
dir = -1;
r++;
} else if (c < 0) {
c = 0;
dir = 1;
r++;
}
}
}
for (int i = 0; i < h; i++) {
Console.WriteLine(string.Join(" ", map[i]));
}
}
#region Competitive Template
public static void Main(string[] args) {
var needsFlushOutput = true;
if (needsFlushOutput) {
// 細かく出力しないようにする
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
// 仮想的に標準入力をセットする
// NextLine系を使っていると使えない
// Input.SetText("");
Solve();
Console.Out.Flush();
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
#endregion
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 903
| 2
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
int N = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
int[] X = new int[N];
for (int i = 0; i < N; i++) {
X[i] = int.Parse(str[i]);
}
List<int> Diff = new List<int>();
Diff.Add(X[0]);
Diff.Add(X[N - 1] + 1);
for (int i = 1; i < N; i++) {
if (X[i] != X[i - 1] + 1) {
Diff.Add(X[i]);
}
}
for (int i = 0; i < N - 1; i++) {
if (X[i] + 1 != X[i + 1]) {
Diff.Add(X[i] + 1);
}
}
int[] diff = Diff.ToArray();
int o = 0;
int e = 0;
for (int i = 0; i < diff.Length; i++) {
if (diff[i] % 2 == 0) {
e++;
} else {
o++;
}
}
int[] Odd = new int[o];
int[] Even = new int[e];
o = 0;
e = 0;
for (int i = 0; i < diff.Length; i++) {
if (diff[i] % 2 == 0) {
Even[e] = diff[i];
e++;
} else {
Odd[o] = diff[i];
o++;
}
}
List<int> f = new List<int>();
List<int> t = new List<int>();
List<long> capa = new List<long>();
int S = 0;
int Ef = 1;
int Of = e + 1;
int T = o + e + 1;
for (int i = 0; i < e; i++) {
f.Add(S);
t.Add(Ef + i);
capa.Add(1);
}
for (int i = 0; i < 0; i++) {
f.Add(Of + i);
t.Add(T);
capa.Add(1);
}
Generateprimenumber G = new Generateprimenumber(10000);
for (int i = 0; i < e; i++) {
for (int j = 0; j < o; j++) {
if (G.Prime(Math.Max(Even[i] - Odd[j], Odd[j] - Even[i]))) {
f.Add(Ef + i);
t.Add(Of + j);
capa.Add(1);
}
}
}
MaxFlow Flow = new MaxFlow(f.ToArray(), t.ToArray(), capa.ToArray(),
o + e + 2, 0, o + e + 1);
int flow = (int)Flow.flow;
int count = diff.Length - flow;
if (e % 2 != flow % 2) {
count++;
}
sb.Append(count + "\n");
}
}
class Edge {
public Vertex to;
public long capacity;
public Edge rev;
public Edge(Vertex v, long c) {
to = v;
capacity = c;
}
}
class Vertex {
public bool finished;
public List<Edge> edges;
public void AddEdge(Edge e) { edges.Add(e); }
public Vertex() {
edges = new List<Edge>();
finished = false;
}
}
class MaxFlow {
Vertex[] point;
Vertex S;
Vertex G;
public long flow;
int E;
const long INF = 1000000000000000;
public MaxFlow(int[] f, int[] t, long[] capacity, int n, int s, int g) {
point = new Vertex[n];
for (int i = 0; i < n; i++) {
point[i] = new Vertex();
}
E = f.Length;
for (int i = 0; i < E; i++) {
point[f[i]].AddEdge(new Edge(point[t[i]], capacity[i]));
point[t[i]].AddEdge(new Edge(point[f[i]], 0));
point[f[i]].edges[point[f[i]].edges.Count - 1].rev =
point[t[i]].edges[point[t[i]].edges.Count - 1];
point[t[i]].edges[point[t[i]].edges.Count - 1].rev =
point[f[i]].edges[point[f[i]].edges.Count - 1];
}
S = point[s];
G = point[g];
flow = 0;
while (true) {
long fl = dfs(S, INF);
flow += fl;
if (fl == 0) {
break;
}
for (int i = 0; i < n; i++) {
point[i].finished = false;
}
}
}
long dfs(Vertex v, long f) {
v.finished = true;
if (v == G) {
return f;
}
for (int i = 0; i < v.edges.Count; i++) {
Edge e = v.edges[i];
if (!e.to.finished && e.capacity > 0) {
long d = dfs(e.to, Math.Min(f, e.capacity));
if (d > 0) {
e.capacity -= d;
e.rev.capacity += d;
return d;
}
}
}
return 0;
}
}
class Generateprimenumber {
public int[] p;
public int length;
public Generateprimenumber(int n) {
bool[] a = new bool[n + 1];
List<int> pp = new List<int>();
int j = 2;
for (int i = 0; i < n + 1; i++) {
a[i] = true;
}
while (j <= n) {
if (a[j]) {
pp.Add(j);
for (int i = j; (long)i * (long)j <= n; i++) {
a[i * j] = false;
}
}
j++;
}
length = pp.Count;
p = pp.ToArray();
}
public bool Prime(int x) {
for (int i = 0; i < length; i++) {
if (p[i] == x) {
return true;
} else if (x % p[i] == 0) {
return false;
} else if (p[i] * p[i] > x) {
break;
}
}
return true;
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
public Solve() {}
StringBuilder sb;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
int N = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
int[] X = new int[N];
for (int i = 0; i < N; i++) {
X[i] = int.Parse(str[i]);
}
List<int> Diff = new List<int>();
Diff.Add(X[0]);
Diff.Add(X[N - 1] + 1);
for (int i = 1; i < N; i++) {
if (X[i] != X[i - 1] + 1) {
Diff.Add(X[i]);
}
}
for (int i = 0; i < N - 1; i++) {
if (X[i] + 1 != X[i + 1]) {
Diff.Add(X[i] + 1);
}
}
int[] diff = Diff.ToArray();
int o = 0;
int e = 0;
for (int i = 0; i < diff.Length; i++) {
if (diff[i] % 2 == 0) {
e++;
} else {
o++;
}
}
int[] Odd = new int[o];
int[] Even = new int[e];
o = 0;
e = 0;
for (int i = 0; i < diff.Length; i++) {
if (diff[i] % 2 == 0) {
Even[e] = diff[i];
e++;
} else {
Odd[o] = diff[i];
o++;
}
}
List<int> f = new List<int>();
List<int> t = new List<int>();
List<long> capa = new List<long>();
int S = 0;
int Ef = 1;
int Of = e + 1;
int T = o + e + 1;
for (int i = 0; i < e; i++) {
f.Add(S);
t.Add(Ef + i);
capa.Add(1);
}
for (int i = 0; i < o; i++) {
f.Add(Of + i);
t.Add(T);
capa.Add(1);
}
Generateprimenumber G = new Generateprimenumber(10000);
for (int i = 0; i < e; i++) {
for (int j = 0; j < o; j++) {
if (G.Prime(Math.Max(Even[i] - Odd[j], Odd[j] - Even[i]))) {
f.Add(Ef + i);
t.Add(Of + j);
capa.Add(1);
}
}
}
MaxFlow Flow = new MaxFlow(f.ToArray(), t.ToArray(), capa.ToArray(),
o + e + 2, 0, o + e + 1);
int flow = (int)Flow.flow;
int count = diff.Length - flow;
if (e % 2 != flow % 2) {
count++;
}
sb.Append(count + "\n");
}
}
class Edge {
public Vertex to;
public long capacity;
public Edge rev;
public Edge(Vertex v, long c) {
to = v;
capacity = c;
}
}
class Vertex {
public bool finished;
public List<Edge> edges;
public void AddEdge(Edge e) { edges.Add(e); }
public Vertex() {
edges = new List<Edge>();
finished = false;
}
}
class MaxFlow {
Vertex[] point;
Vertex S;
Vertex G;
public long flow;
int E;
const long INF = 1000000000000000;
public MaxFlow(int[] f, int[] t, long[] capacity, int n, int s, int g) {
point = new Vertex[n];
for (int i = 0; i < n; i++) {
point[i] = new Vertex();
}
E = f.Length;
for (int i = 0; i < E; i++) {
point[f[i]].AddEdge(new Edge(point[t[i]], capacity[i]));
point[t[i]].AddEdge(new Edge(point[f[i]], 0));
point[f[i]].edges[point[f[i]].edges.Count - 1].rev =
point[t[i]].edges[point[t[i]].edges.Count - 1];
point[t[i]].edges[point[t[i]].edges.Count - 1].rev =
point[f[i]].edges[point[f[i]].edges.Count - 1];
}
S = point[s];
G = point[g];
flow = 0;
while (true) {
long fl = dfs(S, INF);
flow += fl;
if (fl == 0) {
break;
}
for (int i = 0; i < n; i++) {
point[i].finished = false;
}
}
}
long dfs(Vertex v, long f) {
v.finished = true;
if (v == G) {
return f;
}
for (int i = 0; i < v.edges.Count; i++) {
Edge e = v.edges[i];
if (!e.to.finished && e.capacity > 0) {
long d = dfs(e.to, Math.Min(f, e.capacity));
if (d > 0) {
e.capacity -= d;
e.rev.capacity += d;
return d;
}
}
}
return 0;
}
}
class Generateprimenumber {
public int[] p;
public int length;
public Generateprimenumber(int n) {
bool[] a = new bool[n + 1];
List<int> pp = new List<int>();
int j = 2;
for (int i = 0; i < n + 1; i++) {
a[i] = true;
}
while (j <= n) {
if (a[j]) {
pp.Add(j);
for (int i = j; (long)i * (long)j <= n; i++) {
a[i * j] = false;
}
}
j++;
}
length = pp.Count;
p = pp.ToArray();
}
public bool Prime(int x) {
for (int i = 0; i < length; i++) {
if (p[i] == x) {
return true;
} else if (x % p[i] == 0) {
return false;
} else if (p[i] * p[i] > x) {
break;
}
}
return x != 1;
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 37, 0, 211, 0, 146], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 203]]
| 8
| 1,556
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
Console.WriteLine("Atcoder" + N);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
Console.WriteLine("ABC" + N);
}
}
}
|
[["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222]]
| 8
| 64
| 2
|
using System;
using System.Collections.Generic;
namespace ABC068 {
class Program {
static void Main(string[] args) {
// B
var N = int.Parse(Console.ReadLine());
Console.WriteLine(BreakNumber.DivisionNum(N));
}
}
public class BreakNumber {
public static int DivisionNum(int n) {
var list = new List<int>();
var result = 0;
for (int i = 1; i <= n; i++)
list.Add(i);
while (true) {
var isEvenNum = false;
for (var i = 0; i < list.Count; i++) {
if (list[i] % 2 == 0) {
isEvenNum = true;
list[i] = list[i] / 2;
result = i + 1;
}
}
if (isEvenNum == false)
break;
}
return result;
}
}
}
|
using System;
using System.Collections.Generic;
namespace ABC068 {
class Program {
static void Main(string[] args) {
// B
var N = int.Parse(Console.ReadLine());
Console.WriteLine(BreakNumber.DivisionNum(N));
}
}
public class BreakNumber {
public static int DivisionNum(int n) {
var list = new List<int>();
var result = 1;
for (int i = 1; i <= n; i++)
list.Add(i);
while (true) {
var isEvenNum = false;
for (var i = 0; i < list.Count; i++) {
if (list[i] % 2 == 0) {
isEvenNum = true;
list[i] = list[i] / 2;
result = i + 1;
}
}
if (isEvenNum == false)
break;
}
return result;
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 183
| 2
|
using System;
using System.Linq;
namespace ProgramingStydying {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var numMax = 0;
var ans = 0;
for (int m = 1; m <= n; m++) {
var k = m;
var num = 0;
while (k % 2 == 0) {
k = k / 2;
num++;
}
if (num > numMax) {
numMax = num;
ans = m;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
namespace ProgramingStydying {
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var numMax = 0;
var ans = 1;
for (int m = 1; m <= n; m++) {
var k = m;
var num = 0;
while (k % 2 == 0) {
k = k / 2;
num++;
}
if (num > numMax) {
numMax = num;
ans = m;
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 119
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;
class Program {
public static void Main() {
var n = int.Parse(ReadLine());
int i = 1;
for (; i <= n; i <<= 1)
;
WriteLine(i);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;
class Program {
public static void Main() {
var n = int.Parse(ReadLine());
int i = 1;
for (; i + i <= n; i <<= 1)
;
WriteLine(i);
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 22]]
| 8
| 89
| 2
|
using System;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var res = 1;
while (res < N)
res *= 2;
Console.WriteLine(res / 2);
}
}
|
using System;
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var res = 1;
while (res <= N)
res *= 2;
Console.WriteLine(res / 2);
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 56
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var now = 0;
var ans = 0;
for (int i = 1; i <= N; i++) {
var count = 0;
var x = i;
while (x % 2 == 0) {
x /= 2;
count++;
}
if (x == 1 && now < count)
ans = i;
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var N = sc.ReadInt();
var now = 0;
var ans = 1;
for (int i = 1; i <= N; i++) {
var count = 0;
var x = i;
while (x % 2 == 0) {
x /= 2;
count++;
}
if (x == 1 && now < count)
ans = i;
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 1,138
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
namespace AtCoder {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int loop = 1;
while (Math.Pow(2, loop) < N) {
loop++;
}
Console.WriteLine(Math.Pow(2, loop - 1));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
namespace AtCoder {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int loop = 1;
while (Math.Pow(2, loop) <= N) {
loop++;
}
Console.WriteLine(Math.Pow(2, loop - 1));
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 94
| 2
|
using System;
namespace AtCoder {
static class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
int res = 1;
for (int i = 0; i < N; i++) {
if (res * 2 < N)
res *= 2;
else
break;
}
Console.WriteLine(res);
}
}
}
|
using System;
namespace AtCoder {
static class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
int res = 1;
for (int i = 0; i < N; i++) {
if (res * 2 <= N)
res *= 2;
else
break;
}
Console.WriteLine(res);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 76
| 2
|
using System;
namespace ABC068B {
class Program {
static void Main(string[] args) {
int maxnum = 1;
int maxcount = 1;
int N = int.Parse(Console.ReadLine());
for (int i = 1; i <= N; i++) {
int count = 0;
int now = i;
while (now % 2 == 0) {
now /= 2;
count++;
}
if (maxcount < count) {
maxcount = count;
maxnum = i;
}
}
Console.WriteLine("{0}", maxnum);
}
}
}
|
using System;
namespace ABC068B {
class Program {
static void Main(string[] args) {
int maxnum = 1;
int maxcount = 0;
int N = int.Parse(Console.ReadLine());
for (int i = 1; i <= N; i++) {
int count = 0;
int now = i;
while (now % 2 == 0) {
now /= 2;
count++;
}
if (maxcount < count) {
maxcount = count;
maxnum = i;
}
}
Console.WriteLine("{0}", maxnum);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 116
| 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 = 1;
while (true) {
if (answer >= n) {
break;
}
answer *= 2;
}
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 = 1;
while (true) {
if (answer * 2 > n) {
break;
}
answer *= 2;
}
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, 52, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 375
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var max = 0;
var ans = 0;
for (var i = 1; i <= N; i++) {
var tmp = i;
var count = 0;
while (tmp % 2 == 0) {
tmp /= 2;
count++;
}
if (count > max) {
max = count;
ans = i;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var N = int.Parse(Console.ReadLine());
var max = 0;
var ans = 1;
for (var i = 1; i <= N; i++) {
var tmp = i;
var count = 0;
while (tmp % 2 == 0) {
tmp /= 2;
count++;
}
if (count > max) {
max = count;
ans = i;
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 124
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Program {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int d = 0;
for (d = 0; N != 0; d++)
N >>= 1;
Console.WriteLine($"{d-1}");
Console.ReadKey();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Program {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int d = 0;
for (d = 0; N != 0; d++)
N >>= 1;
Console.WriteLine($"{1 << (d-1)}");
Console.ReadKey();
}
}
}
|
[["+", 0, 28, 0, 283, 0, 284, 0, 16, 31, 203], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 17, 151], ["+", 0, 283, 0, 284, 0, 16, 12, 23, 0, 24], ["+", 0, 283, 0, 284, 0, 16, 12, 23, 0, 25]]
| 8
| 89
| 4
|
using System;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var x = 1;
while (x * 2 < n) {
x *= 2;
}
Console.WriteLine(x);
}
}
|
using System;
class Program {
static void Main(string[] args) {
var n = int.Parse(Console.ReadLine());
var x = 1;
while (x * 2 <= n) {
x *= 2;
}
Console.WriteLine(x);
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 58
| 2
|
using System;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int m = 0, a = 0;
for (int i = 1; i <= n; i++) {
int t = Cnt(i);
if (m < t) {
m = t;
a = i;
}
}
Console.WriteLine(a);
}
static int Cnt(int n) {
int cnt = 0;
while (n % 2 == 0) {
cnt++;
n /= 2;
}
return cnt;
}
}
|
using System;
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int m = 0, a = 1;
for (int i = 1; i <= n; i++) {
int t = Cnt(i);
if (m < t) {
m = t;
a = i;
}
}
Console.WriteLine(a);
}
static int Cnt(int n) {
int cnt = 0;
while (n % 2 == 0) {
cnt++;
n /= 2;
}
return cnt;
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 118
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
string sS = Console.ReadLine().Trim();
int iN = int.Parse(sS);
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// 解析
int iOut = 0;
List<int> lstMlt2 = new List<int>() {
64, 32, 16, 8, 4, 2,
};
for (int i = 0; i < lstMlt2.Count; i++) {
if (lstMlt2[i] <= iN) {
iOut = lstMlt2[i];
break;
}
}
//出力
Console.WriteLine("{0}", iOut.ToString().Trim());
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
string sS = Console.ReadLine().Trim();
int iN = int.Parse(sS);
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
// 解析
int iOut = 0;
List<int> lstMlt2 = new List<int>() { 64, 32, 16, 8, 4, 2, 1 };
for (int i = 0; i < lstMlt2.Count; i++) {
if (lstMlt2[i] <= iN) {
iOut = lstMlt2[i];
break;
}
}
//出力
Console.WriteLine("{0}", iOut.ToString().Trim());
sw.Stop();
#if DEBUG
Console.WriteLine();
Console.WriteLine("{0}", sw.Elapsed.ToString());
Console.WriteLine("続行するには何かキーを押してください...");
Console.ReadKey();
#endif
}
}
|
[["+", 0, 200, 0, 212, 0, 230, 10, 229, 0, 203]]
| 8
| 222
| 1
|
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;
void solve() {
N = cin.nextint;
int n = 1;
while (n < N)
n *= 2;
WriteLine(n);
}
}
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;
void solve() {
N = cin.nextint;
int n = 1;
while (n <= N)
n *= 2;
n /= 2;
WriteLine(n);
}
}
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); }
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 8, 196, 0, 52, 8, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 52, 8, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 90]]
| 8
| 421
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _068 {
class Program {
static void Main(string[] args) {
int num = int.Parse(Console.ReadLine());
int ans = 1;
int maxDivide2Cnt = 0;
for (int i = 1; i < num; i++) {
int divide2cnt = GetDivide2Cnt(i);
if (divide2cnt > maxDivide2Cnt) {
ans = i;
maxDivide2Cnt = divide2cnt;
}
}
Console.WriteLine(ans);
}
private static int GetDivide2Cnt(int n) {
int ret = 0;
if (n % 2 != 0) {
return ret;
}
return 1 + GetDivide2Cnt(n / 2);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _068 {
class Program {
static void Main(string[] args) {
int num = int.Parse(Console.ReadLine());
int ans = 1;
int maxDivide2Cnt = 0;
for (int i = 1; i <= num; i++) {
int divide2cnt = GetDivide2Cnt(i);
if (divide2cnt > maxDivide2Cnt) {
ans = i;
maxDivide2Cnt = divide2cnt;
}
}
Console.WriteLine(ans);
}
private static int GetDivide2Cnt(int n) {
int ret = 0;
if (n % 2 != 0) {
return ret;
}
return 1 + GetDivide2Cnt(n / 2);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 155
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BreakNumber {
class BreakNumber {
static void Main(string[] args) {
int intInputVal = int.Parse(Console.ReadLine()); // 標準入力
int[] intItems = { 2, 4, 8, 16, 32, 64 }; // 比較値
int intOutputVal = 0; // 出力結果
for (int i = 0; i < intItems.Length; i++) {
if (intItems[i] <= intInputVal) {
intOutputVal = intItems[i];
}
}
// 出力
Console.WriteLine(intOutputVal);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BreakNumber {
class BreakNumber {
static void Main(string[] args) {
int intInputVal = int.Parse(Console.ReadLine()); // 標準入力
int[] intItems = { 2, 4, 8, 16, 32, 64 }; // 比較値
int intOutputVal = 1; // 出力結果
for (int i = 0; i < intItems.Length; i++) {
if (intItems[i] <= intInputVal) {
intOutputVal = intItems[i];
}
}
// 出力
Console.WriteLine(intOutputVal);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 124
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int N = int.Parse(s);
int i = 2;
while (N > i) {
i *= 2;
}
Console.WriteLine((i / 2).ToString());
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int N = int.Parse(s);
int i = 2;
while (N >= i) {
i *= 2;
}
Console.WriteLine((i / 2).ToString());
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20]]
| 8
| 93
| 2
|
using System.Collections.Generic;
using System.Linq;
using System;
class Program {
static void Main() {
var line = Console.ReadLine();
int num = int.Parse(line);
int maxNum = 1;
while (maxNum * 2 < num) {
maxNum *= 2;
}
Console.WriteLine(maxNum);
}
}
|
using System.Collections.Generic;
using System.Linq;
using System;
class Program {
static void Main() {
var line = Console.ReadLine();
int num = int.Parse(line);
int maxNum = 1;
while (maxNum * 2 <= num) {
maxNum *= 2;
}
Console.WriteLine(maxNum);
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19]]
| 8
| 71
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
int a = Read.Int();
for (int i = 0;; i++) {
if (a <= Math.Pow(2, i)) {
Console.WriteLine(Math.Pow(2, Math.Max(i - 1, 0)));
break;
}
}
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 * b / gcd(a, 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;
using System.Text;
class Program {
public static bool f = false, t = true;
static void Main(string[] args) {
int a = Read.Int();
for (int i = 0;; i++) {
if (a < Math.Pow(2, i)) {
Console.WriteLine(Math.Pow(2, Math.Max(i - 1, 0)));
break;
}
}
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 * b / gcd(a, 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, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 425
| 2
|
using System;
namespace abc068_b {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int ret = 1;
while (n > ret)
ret *= 2;
Console.WriteLine(ret);
}
}
}
|
using System;
namespace abc068_b {
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int ret = 1;
while (n >= ret * 2)
ret *= 2;
Console.WriteLine(ret);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 17, 48], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 12, 203]]
| 8
| 58
| 4
|
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 Hello {
static public int mod = 1000000007;
public static void Main() {
// 方針
//
int[] n = inta();
var list1 = new List<int>();
var listn = new List<int>();
for (int i = 0; i < n[0]; i++) {
int[] temp = inta();
if (temp[0] == 1) {
list1.Add(temp[1]);
}
if (temp[1] == n[0]) {
listn.Add(temp[0]);
}
}
string ans = "IMPOSSIBLE";
int[] map = new int[300000];
foreach (var k in list1) {
map[k] = 1;
}
foreach (var k in listn) {
if (map[k] == 1) {
ans = "POSSIBLE";
break;
}
}
WriteLine(ans);
}
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(long a,long b,long m){var list = new List<int>();int
// temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp <
// b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b >
// 0){if(temp <= b){b -= temp;ret =
// ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取
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 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); }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Hashtable × Dictionary ○
// 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 とは
// 出力
// foreach(var a int list){ WriteLine(a); } より
// WriteLine(string.Join("\n", list)); が速い
// var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
// Console.SetOut(sw);
// foreach(var k in list[num-1]){
// WriteLine(k);
// }
// 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 Hello {
static public int mod = 1000000007;
public static void Main() {
// 方針
//
int[] n = inta();
var list1 = new List<int>();
var listn = new List<int>();
for (int i = 0; i < n[1]; i++) {
int[] temp = inta();
if (temp[0] == 1) {
list1.Add(temp[1]);
}
if (temp[1] == n[0]) {
listn.Add(temp[0]);
}
}
string ans = "IMPOSSIBLE";
int[] map = new int[300000];
foreach (var k in list1) {
map[k] = 1;
}
foreach (var k in listn) {
if (map[k] == 1) {
ans = "POSSIBLE";
break;
}
}
WriteLine(ans);
}
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(long a,long b,long m){var list = new List<int>();int
// temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp <
// b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b >
// 0){if(temp <= b){b -= temp;ret =
// ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取
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 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); }
}
//知見
// (string) hogestr -> (char[]) hoge
// char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
// string hoge = new string(hoge);
// Hashtable × Dictionary ○
// 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 とは
// 出力
// foreach(var a int list){ WriteLine(a); } より
// WriteLine(string.Join("\n", list)); が速い
// var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
// Console.SetOut(sw);
// foreach(var k in list[num-1]){
// WriteLine(k);
// }
// Console.Out.Flush();
|
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 981
| 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(new ConsoleInput(Console.In, ' ')); }
public static void Answer(ConsoleInput cin) {
const string STRPOS = "POSSIBLE";
const string STRIMP = "IMPOSSIBLE ";
int[] arr = cin.ReadIntArray(2);
var N = arr[0];
var M = arr[1];
var f = new int[M];
var t = new int[M];
for (int i = 0; i < M; i++) {
f[i] = cin.ReadInt;
t[i] = cin.ReadInt;
}
var bf = new bool[M];
var bt = new bool[M];
for (int i = 0; i < M; i++) {
if (f[i] == 1)
bt[t[i]] = true;
if (t[i] == N)
bf[f[i]] = true;
}
for (int i = 1; i <= N; i++) {
if (bf[i] && bt[i]) {
WriteLine(STRPOS);
return;
}
}
WriteLine(STRIMP);
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass {
static void Main(string[] args) { Answer(new ConsoleInput(Console.In, ' ')); }
public static void Answer(ConsoleInput cin) {
const string STRPOS = "POSSIBLE";
const string STRIMP = "IMPOSSIBLE ";
int[] arr = cin.ReadIntArray(2);
var N = arr[0];
var M = arr[1];
var f = new int[M];
var t = new int[M];
for (int i = 0; i < M; i++) {
f[i] = cin.ReadInt;
t[i] = cin.ReadInt;
}
var bf = new bool[200001];
var bt = new bool[200001];
for (int i = 0; i < M; i++) {
if (f[i] == 1)
bt[t[i]] = true;
if (t[i] == N)
bf[f[i]] = true;
}
for (int i = 1; i <= N; i++) {
if (bf[i] && bt[i]) {
WriteLine(STRPOS);
return;
}
}
WriteLine(STRIMP);
}
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, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
| 8
| 625
| 4
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var nm = Console.ReadLine().Split(' ');
var n = int.Parse(nm[0]);
var m = int.Parse(nm[1]);
var set = new HashSet<long>();
for (int i = 0; i < m; i++) {
var ab = Console.ReadLine().Split(' ');
var a = long.Parse(ab[0]);
var b = long.Parse(ab[1]);
set.Add((a << 32) + b);
}
for (long i = 2; i < n; i++) {
if (set.Contains((1 << 32) + i) && set.Contains((i << 32) + n)) {
Console.WriteLine("POSSIBLE");
return;
}
}
Console.WriteLine("IMPOSSIBLE");
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var nm = Console.ReadLine().Split(' ');
var n = int.Parse(nm[0]);
var m = int.Parse(nm[1]);
var set = new HashSet<long>();
for (int i = 0; i < m; i++) {
var ab = Console.ReadLine().Split(' ');
var a = long.Parse(ab[0]);
var b = long.Parse(ab[1]);
set.Add((a << 32) + b);
}
for (long i = 2; i < n; i++) {
if (set.Contains((1L << 32) + i) && set.Contains((i << 32) + n)) {
Console.WriteLine("POSSIBLE");
return;
}
}
Console.WriteLine("IMPOSSIBLE");
}
}
|
[["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 203], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 203]]
| 8
| 215
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
Scanner cin = new Scanner();
int N = cin.Int();
int M = cin.Int();
int[] a = new int[M];
int[] b = new int[M];
for (int i = 0; i < M; i++) {
a[i] = cin.Int();
b[i] = cin.Int();
}
var s = new bool[200002];
var t = new bool[200002];
for (int i = 1; i <= N; i++) {
if (a[i] == 1)
s[b[i]] = true;
if (b[i] == N)
t[a[i]] = true;
}
for (int i = 1; i <= N; i++) {
if (s[i] && t[i]) {
Console.WriteLine("POSSIBLE");
return;
}
}
Console.WriteLine("IMPOSSIBLE");
Console.ReadLine();
}
}
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double Double() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
Scanner cin = new Scanner();
int N = cin.Int();
int M = cin.Int();
int[] a = new int[M];
int[] b = new int[M];
for (int i = 0; i < M; i++) {
a[i] = cin.Int();
b[i] = cin.Int();
}
var s = new bool[200002];
var t = new bool[200002];
for (int i = 0; i < M; i++) {
if (a[i] == 1)
s[b[i]] = true;
if (b[i] == N)
t[a[i]] = true;
}
for (int i = 1; i <= N; i++) {
if (s[i] && t[i]) {
Console.WriteLine("POSSIBLE");
return;
}
}
Console.WriteLine("IMPOSSIBLE");
Console.ReadLine();
}
}
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double Double() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 603
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = Cin.Ni();
int m = Cin.Ni();
HashSet<int> startSet = new HashSet<int>();
HashSet<int> goalSet = new HashSet<int>();
for (int i = 0; i < n; i++) {
int a = Cin.Ni();
int b = Cin.Ni();
if (a == 1) {
startSet.Add(b);
}
if (b == n) {
goalSet.Add(a);
}
}
startSet.IntersectWith(goalSet);
Console.WriteLine(startSet.Any() ? "POSSIBLE" : "IMPOSSIBLE");
}
}
public class Cin {
private static string[] s = new string[0];
private static int i = 0;
private static char[] cs = new char[] { ' ' };
public static string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next();
}
public static int Ni() { return int.Parse(Next()); }
public static long NextLong() { return long.Parse(Next()); }
public static double NextDouble() { return double.Parse(Next()); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
int n = Cin.Ni();
int m = Cin.Ni();
HashSet<int> startSet = new HashSet<int>();
HashSet<int> goalSet = new HashSet<int>();
for (int i = 0; i < m; i++) {
int a = Cin.Ni();
int b = Cin.Ni();
if (a == 1) {
startSet.Add(b);
}
if (b == n) {
goalSet.Add(a);
}
}
startSet.IntersectWith(goalSet);
Console.WriteLine(startSet.Any() ? "POSSIBLE" : "IMPOSSIBLE");
}
}
public class Cin {
private static string[] s = new string[0];
private static int i = 0;
private static char[] cs = new char[] { ' ' };
public static string Next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next();
}
public static int Ni() { return int.Parse(Next()); }
public static long NextLong() { return long.Parse(Next()); }
public static double NextDouble() { return double.Parse(Next()); }
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 331
| 2
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace FertiLib.Contest.C {
static class Program {
public static void Solve(Scanner cin) {
var (n, m) = cin.ReadValue<int, int>();
var (a, b) = cin.ReadValueArray<int, int>(m);
var start = new List<int>();
var end = new List<int>();
for (int i = 0; i < n; i++) {
if (a[i] == 1)
start.Add(b[i]);
if (b[i] == n)
end.Add(a[i]);
}
start.Sort();
end.Sort();
bool ok = false;
for (int i = 0; i < end.Count; i++) {
if (start.UpperBound(end[i]) - start.LowerBound(end[i]) > 0)
ok = true;
}
Console.WriteLine(ok ? "POSSIBLE" : "IMPOSSIBLE");
}
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 BinarySearch {
public static int UpperBound<T>(T[] array, T value) =>
UpperBound(array, 0, array.Length - 1, value, Comparer<T>.Default);
public static int UpperBound<T>(T[] array, T value, Comparer<T> comparer) =>
UpperBound(array, 0, array.Length - 1, value, comparer);
public static int UpperBound<T>(T[] array, int index, int length,
T value) => UpperBound(array, index, length,
value,
Comparer<T>.Default);
public static int UpperBound<T>(T[] array, int index, int length, T value,
Comparer<T> comparer) {
var l = index - 1;
var r = index + length;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = comparer.Compare(array[mid], value);
if (res <= 0)
l = mid;
else
r = mid;
}
return r;
}
public static int UpperBound<T>(this List<T> list, T item) =>
list.UpperBound(0, list.Count, item, Comparer<T>.Default);
public static int UpperBound<T>(this List<T> list, T item,
Comparer<T> comparer) =>
list.UpperBound(0, list.Count, item, comparer);
public static int UpperBound<T>(this List<T> list, int index, int count,
T item, Comparer<T> comparer) {
var l = index - 1;
var r = index + count;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = comparer.Compare(list[mid], item);
if (res <= 0)
l = mid;
else
r = mid;
}
return r;
}
public static int LowerBound<T>(T[] array, T value) =>
LowerBound(array, 0, array.Length - 1, value, Comparer<T>.Default);
public static int LowerBound<T>(T[] array, T value, Comparer<T> comparer) =>
LowerBound(array, 0, array.Length - 1, value, comparer);
public static int LowerBound<T>(T[] array, int index, int length,
T value) => LowerBound(array, index, length,
value,
Comparer<T>.Default);
public static int LowerBound<T>(T[] array, int index, int length, T value,
Comparer<T> comparer) {
var l = index - 1;
var r = index + length;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = comparer.Compare(array[mid], value);
if (res == -1)
l = mid;
else
r = mid;
}
return r;
}
public static int LowerBound<T>(this List<T> list, T item) =>
list.LowerBound(0, list.Count, item, Comparer<T>.Default);
public static int LowerBound<T>(this List<T> list, T item,
Comparer<T> comparer) =>
list.LowerBound(0, list.Count, item, comparer);
public static int LowerBound<T>(this List<T> list, int index, int count,
T item, Comparer<T> comparer) {
var l = index - 1;
var r = index + count;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = comparer.Compare(list[mid], item);
if (res == -1)
l = mid;
else
r = mid;
}
return r;
}
}
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;
using System.Runtime.CompilerServices;
namespace FertiLib.Contest.C {
static class Program {
public static void Solve(Scanner cin) {
var (n, m) = cin.ReadValue<int, int>();
var (a, b) = cin.ReadValueArray<int, int>(m);
var start = new List<int>();
var end = new List<int>();
for (int i = 0; i < m; i++) {
if (a[i] == 1)
start.Add(b[i]);
if (b[i] == n)
end.Add(a[i]);
}
start.Sort();
end.Sort();
bool ok = false;
for (int i = 0; i < end.Count; i++) {
if (start.UpperBound(end[i]) - start.LowerBound(end[i]) > 0)
ok = true;
}
Console.WriteLine(ok ? "POSSIBLE" : "IMPOSSIBLE");
}
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 BinarySearch {
public static int UpperBound<T>(T[] array, T value) =>
UpperBound(array, 0, array.Length - 1, value, Comparer<T>.Default);
public static int UpperBound<T>(T[] array, T value, Comparer<T> comparer) =>
UpperBound(array, 0, array.Length - 1, value, comparer);
public static int UpperBound<T>(T[] array, int index, int length,
T value) => UpperBound(array, index, length,
value,
Comparer<T>.Default);
public static int UpperBound<T>(T[] array, int index, int length, T value,
Comparer<T> comparer) {
var l = index - 1;
var r = index + length;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = comparer.Compare(array[mid], value);
if (res <= 0)
l = mid;
else
r = mid;
}
return r;
}
public static int UpperBound<T>(this List<T> list, T item) =>
list.UpperBound(0, list.Count, item, Comparer<T>.Default);
public static int UpperBound<T>(this List<T> list, T item,
Comparer<T> comparer) =>
list.UpperBound(0, list.Count, item, comparer);
public static int UpperBound<T>(this List<T> list, int index, int count,
T item, Comparer<T> comparer) {
var l = index - 1;
var r = index + count;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = comparer.Compare(list[mid], item);
if (res <= 0)
l = mid;
else
r = mid;
}
return r;
}
public static int LowerBound<T>(T[] array, T value) =>
LowerBound(array, 0, array.Length - 1, value, Comparer<T>.Default);
public static int LowerBound<T>(T[] array, T value, Comparer<T> comparer) =>
LowerBound(array, 0, array.Length - 1, value, comparer);
public static int LowerBound<T>(T[] array, int index, int length,
T value) => LowerBound(array, index, length,
value,
Comparer<T>.Default);
public static int LowerBound<T>(T[] array, int index, int length, T value,
Comparer<T> comparer) {
var l = index - 1;
var r = index + length;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = comparer.Compare(array[mid], value);
if (res == -1)
l = mid;
else
r = mid;
}
return r;
}
public static int LowerBound<T>(this List<T> list, T item) =>
list.LowerBound(0, list.Count, item, Comparer<T>.Default);
public static int LowerBound<T>(this List<T> list, T item,
Comparer<T> comparer) =>
list.LowerBound(0, list.Count, item, comparer);
public static int LowerBound<T>(this List<T> list, int index, int count,
T item, Comparer<T> comparer) {
var l = index - 1;
var r = index + count;
while (r - l > 1) {
var mid = l + (r - l) / 2;
var res = comparer.Compare(list[mid], item);
if (res == -1)
l = mid;
else
r = mid;
}
return r;
}
}
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, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 3,625
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using static AtCoderer.Comfort;
using static AtCoderer.Math;
using static AtCoderer.Algorithm;
using static System.Math;
namespace AtCoderer {
public class App {
public static void Main(string[] args) {
Solve();
Console.ReadKey();
}
public static void Solve() {
int n, m;
ParseArray(out n, out m);
int[,] ab = new int[2, m];
List<int> l1 = new List<int>(), l2 = new List<int>();
for (int i = 0; i < m; i++) {
int t1, t2;
ParseArray(out t1, out t2);
if (t1 == 1)
l1.Add(t2);
if (t1 == n)
l2.Add(t1);
}
l1.Sort();
l2.Sort();
bool b = false;
foreach (var v in l1) {
if (l2.BinarySearch(v) >= 0)
b = true;
}
Console.WriteLine(b ? "POSSIBLE" : "IMPOSSIBLE");
}
public static int DivBy2(int a) {
int p = 0;
while (a % 2 != 1) {
a /= 2;
p++;
}
return p;
}
}
public static class Comfort {
//ソート
public static int[] OrderBy(this int[] IArr) {
int[] arr = new int[IArr.Length];
Array.Copy(IArr, arr, IArr.Length);
Array.Sort(arr);
return arr;
}
//ソート
public static char[] OrderBy(this string IArr) {
char[] arr = new char[IArr.Length];
Array.Copy(IArr.ToCharArray(), arr, IArr.Length);
Array.Sort(arr);
return arr;
}
// MinとMax
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
//整数入力
public static int Parse() { return int.Parse(Console.ReadLine()); }
//整数列入力
public static int[] ParseArray(this string s) {
return s.Split().Select(v => int.Parse(v)).ToArray();
}
//整数列入力
public static long[] ParseArrayL(this string s) {
return s.Split().Select(v => long.Parse(v)).ToArray();
}
//整数列入力
public static int[] ParseArray() {
return Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
}
//整数列入力
public static long[] ParseArrayL() {
return Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
}
// 2整数入力
public static void ParseArray(out int a, out int b) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
// 3整数入力
public static void ParseArray(out int a, out int b, out int c) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
// 4整数入力
public static void ParseArray(out int a, out int b, out int c, out int d) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
// 2整数入力
public static void ParseArray(out long a, out long b) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
// 3整数入力
public static void ParseArray(out long a, out long b, out long c) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
// 4整数入力
public static void ParseArray(out long a, out long b, out long c,
out long d) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
// char配列のstring化
public static string ToString(this IEnumerable<char> v) {
return string.Join("", v);
}
//配列のstring化
public static string Join<T>(this IEnumerable<T> v, char c) {
return string.Join(c.ToString(), v);
}
//配列のstring化
public static string Join<T>(this IEnumerable<T> v, string s) {
return string.Join(s, v);
}
}
public static class Math {
//自然数判定
public static bool IsNatural(this float v) => v - (int)v == 0;
public static bool IsNatural(this double v) => v - (int)v == 0;
//非重複順列
public static long nCm(long n, long m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * nCm(n - 1, m - 1) / m % 1000000007;
}
//素因数分解
public static IEnumerable<int> Factor(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
//最大公約数
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int x,
int y) => y == 0 ? x : GcdRecursive(y, x % y);
//最大公約数
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long x,
long y) => y == 0 ? x
: GcdRecursive(y, x % y);
//最小公倍数
public static long Lcm(int a, int b) => ((long)a) * b / Gcd(a, b);
}
public static class Algorithm {
// 2値タプル
public class Point {
public int a;
public int b;
public Point(int x, int y) {
a = x;
b = y;
}
}
// 3値タプル
public class Tri {
public int a;
public int b;
public int c;
public Tri(int x, int y, int z) {
a = x;
b = y;
c = z;
}
}
//全列挙のクラス
public class EnumAll {
bool Over = false;
int UpperValue;
int Dimension;
public int[] Current { private set; get; }
public EnumAll(int Value, int Dimension) {
this.Dimension = Dimension;
UpperValue = Value;
Current = new int[Dimension];
Current[0] = -1;
}
public bool Next() {
if (Over)
return false;
bool flag = false;
for (int i = 0; i < Dimension; i++) {
if (++Current[i] >= UpperValue)
Current[i] = 0;
else {
flag = true;
break;
}
}
if (!flag) {
Over = true;
return false;
}
return true;
}
public bool IsOver() { return Over; }
}
// Union-Find
public class UnionFind {
private int[] Parent;
private int GetRoot(int v) {
if (Parent[v] < 0)
return v;
else
return Parent[v] = GetRoot(Parent[v]);
}
public UnionFind(int size) {
Parent = new int[size];
for (int i = 0; i < size; i++)
Parent[i] = -1;
}
public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); }
public void Connect(int a, int b) {
a = GetRoot(a);
b = GetRoot(b);
if (a == b)
return;
if (Parent[b] < Parent[a]) {
Parent[b] += Parent[a];
Parent[a] = b;
} else {
Parent[a] += Parent[b];
Parent[b] = a;
}
}
public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; }
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static AtCoderer.Comfort;
using static AtCoderer.Math;
using static AtCoderer.Algorithm;
using static System.Math;
namespace AtCoderer {
public class App {
public static void Main(string[] args) {
Solve();
Console.ReadKey();
}
public static void Solve() {
int n, m;
ParseArray(out n, out m);
int[,] ab = new int[2, m];
List<int> l1 = new List<int>(), l2 = new List<int>();
for (int i = 0; i < m; i++) {
int t1, t2;
ParseArray(out t1, out t2);
if (t1 == 1)
l1.Add(t2);
if (t2 == n)
l2.Add(t1);
}
l1.Sort();
l2.Sort();
bool b = false;
foreach (var v in l1) {
if (l2.BinarySearch(v) >= 0)
b = true;
}
Console.WriteLine(b ? "POSSIBLE" : "IMPOSSIBLE");
}
public static int DivBy2(int a) {
int p = 0;
while (a % 2 != 1) {
a /= 2;
p++;
}
return p;
}
}
public static class Comfort {
//ソート
public static int[] OrderBy(this int[] IArr) {
int[] arr = new int[IArr.Length];
Array.Copy(IArr, arr, IArr.Length);
Array.Sort(arr);
return arr;
}
//ソート
public static char[] OrderBy(this string IArr) {
char[] arr = new char[IArr.Length];
Array.Copy(IArr.ToCharArray(), arr, IArr.Length);
Array.Sort(arr);
return arr;
}
// MinとMax
public static int Max(params int[] p) => p.Max();
public static long Max(params long[] p) => p.Max();
public static int Min(params int[] p) => p.Min();
public static long Min(params long[] p) => p.Min();
//整数入力
public static int Parse() { return int.Parse(Console.ReadLine()); }
//整数列入力
public static int[] ParseArray(this string s) {
return s.Split().Select(v => int.Parse(v)).ToArray();
}
//整数列入力
public static long[] ParseArrayL(this string s) {
return s.Split().Select(v => long.Parse(v)).ToArray();
}
//整数列入力
public static int[] ParseArray() {
return Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
}
//整数列入力
public static long[] ParseArrayL() {
return Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
}
// 2整数入力
public static void ParseArray(out int a, out int b) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
// 3整数入力
public static void ParseArray(out int a, out int b, out int c) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
// 4整数入力
public static void ParseArray(out int a, out int b, out int c, out int d) {
var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
// 2整数入力
public static void ParseArray(out long a, out long b) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
}
// 3整数入力
public static void ParseArray(out long a, out long b, out long c) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
}
// 4整数入力
public static void ParseArray(out long a, out long b, out long c,
out long d) {
var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray();
a = r[0];
b = r[1];
c = r[2];
d = r[3];
}
// char配列のstring化
public static string ToString(this IEnumerable<char> v) {
return string.Join("", v);
}
//配列のstring化
public static string Join<T>(this IEnumerable<T> v, char c) {
return string.Join(c.ToString(), v);
}
//配列のstring化
public static string Join<T>(this IEnumerable<T> v, string s) {
return string.Join(s, v);
}
}
public static class Math {
//自然数判定
public static bool IsNatural(this float v) => v - (int)v == 0;
public static bool IsNatural(this double v) => v - (int)v == 0;
//非重複順列
public static long nCm(long n, long m) {
if (m == 0)
return 1;
if (n == 0)
return 0;
return n * nCm(n - 1, m - 1) / m % 1000000007;
}
//素因数分解
public static IEnumerable<int> Factor(int n) {
int i = 2;
int tmp = n;
while (i * i <= n) {
if (tmp % i == 0) {
tmp /= i;
yield return i;
} else {
i++;
}
}
if (tmp != 1)
yield return tmp;
}
//最大公約数
public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static int GcdRecursive(int x,
int y) => y == 0 ? x : GcdRecursive(y, x % y);
//最大公約数
public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b)
: GcdRecursive(b, a);
private static long GcdRecursive(long x,
long y) => y == 0 ? x
: GcdRecursive(y, x % y);
//最小公倍数
public static long Lcm(int a, int b) => ((long)a) * b / Gcd(a, b);
}
public static class Algorithm {
// 2値タプル
public class Point {
public int a;
public int b;
public Point(int x, int y) {
a = x;
b = y;
}
}
// 3値タプル
public class Tri {
public int a;
public int b;
public int c;
public Tri(int x, int y, int z) {
a = x;
b = y;
c = z;
}
}
//全列挙のクラス
public class EnumAll {
bool Over = false;
int UpperValue;
int Dimension;
public int[] Current { private set; get; }
public EnumAll(int Value, int Dimension) {
this.Dimension = Dimension;
UpperValue = Value;
Current = new int[Dimension];
Current[0] = -1;
}
public bool Next() {
if (Over)
return false;
bool flag = false;
for (int i = 0; i < Dimension; i++) {
if (++Current[i] >= UpperValue)
Current[i] = 0;
else {
flag = true;
break;
}
}
if (!flag) {
Over = true;
return false;
}
return true;
}
public bool IsOver() { return Over; }
}
// Union-Find
public class UnionFind {
private int[] Parent;
private int GetRoot(int v) {
if (Parent[v] < 0)
return v;
else
return Parent[v] = GetRoot(Parent[v]);
}
public UnionFind(int size) {
Parent = new int[size];
for (int i = 0; i < size; i++)
Parent[i] = -1;
}
public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); }
public void Connect(int a, int b) {
a = GetRoot(a);
b = GetRoot(b);
if (a == b)
return;
if (Parent[b] < Parent[a]) {
Parent[b] += Parent[a];
Parent[a] = b;
} else {
Parent[a] += Parent[b];
Parent[b] = a;
}
}
public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; }
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22]]
| 8
| 1,903
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ARC79_C {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine().Split();
int n = int.Parse(s[0]);
int m = int.Parse(s[1]);
var a = new int [m][];
var c = new Dictionary<int, bool>();
var d = new Dictionary<int, bool>();
for (int i = 0; i < m; i++) {
c[i] = false;
d[i] = false;
}
for (int i = 0; i < m; i++) {
a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
if (a[i][0] == 1)
c[a[i][1]] = true;
if (a[i][1] == n)
d[a[i][0]] = true;
}
for (int i = 0; i < n; i++) {
if (c[i] && d[i]) {
Console.WriteLine("POSSIBLE");
return;
}
}
Console.WriteLine("IMPOSSIBLE");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ARC79_C {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine().Split();
int n = int.Parse(s[0]);
int m = int.Parse(s[1]);
var a = new int [m][];
var c = new Dictionary<int, bool>();
var d = new Dictionary<int, bool>();
for (int i = 0; i < n; i++) {
c[i] = false;
d[i] = false;
}
for (int i = 0; i < m; i++) {
a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
if (a[i][0] == 1)
c[a[i][1]] = true;
if (a[i][1] == n)
d[a[i][0]] = true;
}
for (int i = 0; i < n; i++) {
if (c[i] && d[i]) {
Console.WriteLine("POSSIBLE");
return;
}
}
Console.WriteLine("IMPOSSIBLE");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 294
| 2
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
int itemCount = int.Parse(Reader.ReadLine());
long[] tmp = Reader.ReadLine()
.Split(' ')
.Select(a => long.Parse(a))
.OrderByDescending(a => a)
.ToArray();
long ans = 0;
while (tmp[0] > itemCount - 1 && tmp[0] - tmp.Last() >= itemCount) {
long diff = tmp[0] - (tmp.Length - 1);
long div = diff / tmp.Length;
if (diff % tmp.Length > 0) {
div++;
}
tmp[0] -= (itemCount)*div;
for (int i = 1; i < itemCount; i++) {
tmp[i] += div;
}
ans += div;
tmp = tmp.OrderByDescending(a => a).ToArray();
}
if (tmp.Last() >= itemCount) {
long addAns = tmp.Last() - (itemCount - 1);
tmp = tmp.Select(a => a - addAns).ToArray();
ans += addAns;
}
while (tmp[0] > itemCount - 1) {
tmp = tmp.Select(a => a + 1).ToArray();
tmp[0] -= (itemCount + 1);
tmp = tmp.OrderByDescending(a => a).ToArray();
ans++;
}
Console.WriteLine(ans);
}
public class Reader {
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
10
1000 193 256 777 0 1 1192 1234567891011 48 425
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
int itemCount = int.Parse(Reader.ReadLine());
long[] tmp = Reader.ReadLine()
.Split(' ')
.Select(a => long.Parse(a))
.OrderByDescending(a => a)
.ToArray();
long ans = 0;
while (tmp[0] > itemCount - 1 && tmp[0] - tmp.Last() >= itemCount) {
long diff = tmp[0] - (tmp.Length - 1);
long div = diff / tmp.Length;
if (diff % tmp.Length > 0) {
div++;
}
tmp[0] -= (itemCount)*div;
for (int i = 1; i < itemCount; i++) {
tmp[i] += div;
}
ans += div;
tmp = tmp.OrderByDescending(a => a).ToArray();
}
if (tmp.Last() >= itemCount) {
long addAns = tmp.Last() - (itemCount - 1);
tmp = tmp.Select(a => a - addAns).ToArray();
ans += addAns * tmp.Length;
}
while (tmp[0] > itemCount - 1) {
tmp = tmp.Select(a => a + 1).ToArray();
tmp[0] -= (itemCount + 1);
tmp = tmp.OrderByDescending(a => a).ToArray();
ans++;
}
Console.WriteLine(ans);
}
public class Reader {
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
10
1000 193 256 777 0 1 1192 1234567891011 48 425
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 16, 12, 214, 141, 22], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
| 8
| 442
| 6
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
long[] A;
int N;
public Solve() {}
StringBuilder sb;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
N = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
A = new long[N];
for (int i = 0; i < N; i++) {
A[i] = long.Parse(str[i]);
}
long bf = 0;
long bl = 510000000000000000 / N;
while (bf != bl) {
long bc = (bf + bl) / 2;
if (check(bc * N)) {
bl = bc;
} else {
bf = bc + 1;
}
}
if (bf == 0) {
sb.Append("0\n");
return;
}
for (long bc = (bf - 3) * N + 1; bc <= bf * N; bc++) {
if (bc >= 0 && check(bc)) {
sb.Append(bc + "\n");
return;
}
}
}
bool check(long bc) {
long count = 0;
for (int i = 0; i < N; i++) {
long X = A[i] + bc;
if (X < N) {
continue;
}
if ((X - N + 1) % (N + 1) == 0) {
count += (X - N + 1) / (N + 1);
} else {
count += (X - N + 1) / (N + 1) + 1;
}
}
return count <= bc;
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve {
long[] A;
int N;
public Solve() {}
StringBuilder sb;
public static int Main() {
new Solve().Run();
return 0;
}
void Run() {
sb = new StringBuilder();
Calc();
Console.Write(sb.ToString());
}
void Calc() {
N = int.Parse(Console.ReadLine());
string[] str = Console.ReadLine().Split(' ');
A = new long[N];
for (int i = 0; i < N; i++) {
A[i] = long.Parse(str[i]);
}
long bf = 0;
long bl = 510000000000000000 / N;
while (bf != bl) {
long bc = (bf + bl) / 2;
if (check(bc * N)) {
bl = bc;
} else {
bf = bc + 1;
}
}
if (bf == 0) {
sb.Append("0\n");
return;
}
for (long bc = (bf - 1000) * N + 1; bc <= bf * N; bc++) {
if (bc >= 0 && check(bc)) {
sb.Append(bc + "\n");
return;
}
}
}
bool check(long bc) {
long count = 0;
for (int i = 0; i < N; i++) {
long X = A[i] + bc;
if (X < N) {
continue;
}
if ((X - N + 1) % (N + 1) == 0) {
count += (X - N + 1) / (N + 1);
} else {
count += (X - N + 1) / (N + 1) + 1;
}
}
return count <= bc;
}
}
|
[["-", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203]]
| 8
| 403
| 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() {
// •ûj
//
var n = inta();
var a = longa();
var gcd = a[0];
for (int i = 1; i < n[0]; i++) {
gcd = GCD(gcd, a[i]);
}
var tf = false;
for (int i = 0; i < n[0]; i++) {
var b = a[i] - n[1];
if (b <= 0)
continue;
if (b % gcd == 0) {
tf = true;
break;
}
}
if (tf) {
WriteLine("POSSIBLE");
} else {
WriteLine("IMPOSSIBLE");
}
}
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;
}
//Šeí“Çæ
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
public class Solve {
static public int mod = 1000000007;
public static void Main() {
// •ûj
//
var n = inta();
var a = longa();
var gcd = a[0];
for (int i = 1; i < n[0]; i++) {
gcd = GCD(gcd, a[i]);
}
var tf = false;
for (int i = 0; i < n[0]; i++) {
var b = a[i] - n[1];
if (b < 0)
continue;
if (b % gcd == 0) {
tf = true;
break;
}
}
if (tf) {
WriteLine("POSSIBLE");
} else {
WriteLine("IMPOSSIBLE");
}
}
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;
}
//Šeí“Çæ
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
static void WriteArray(int[,] a, int b, int c) {
for (int i = 0; i < b; i++) {
for (int j = 0; j < c; j++) {
if (j != 0)
Write(" ");
Write(a[i, j]);
}
WriteLine();
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 1,224
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var K = sc.ReadInt();
var A = sc.ReadIntArray(N);
var ok = true;
if (A.Max() < K) {
Console.WriteLine("IMPOSSIBLE");
return;
}
if (A.Contains(K)) {
Console.WriteLine("POSSIBLE");
return;
}
long gcd = A[0];
for (int i = 1; i < N; i++) {
gcd = Gcd(gcd, A[i]);
}
ok = gcd == 1;
Console.WriteLine(ok ? "POSSIBLE" : "IMPOSSIBLE");
}
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var K = sc.ReadInt();
var A = sc.ReadIntArray(N);
var ok = true;
if (A.Max() < K) {
Console.WriteLine("IMPOSSIBLE");
return;
}
if (A.Contains(K)) {
Console.WriteLine("POSSIBLE");
return;
}
long gcd = A[0];
for (int i = 1; i < N; i++) {
gcd = Gcd(gcd, A[i]);
}
ok = gcd == 1 || K % gcd == 0;
Console.WriteLine(ok ? "POSSIBLE" : "IMPOSSIBLE");
}
static long Gcd(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 106], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 17, 60], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 203]]
| 8
| 741
| 6
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program {
public static class AGC018A {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var K = NN;
var AList = NNList(N);
if (AList.Max() <= K) {
Console.WriteLine("IMPOSSIBLE");
return;
}
var gcd = AList.Aggregate((x, acc) => GCD(x, acc));
if (K % gcd == 0) {
Console.WriteLine("POSSIBLE");
} else {
Console.WriteLine("IMPOSSIBLE");
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static void RevSort<T>(T[] l)
where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); }
static void RevSort<T>(T[] l, Comparison<T> comp)
where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); }
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y);
static Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a.Mul(x);
x.Mul(x);
y >>= 1;
}
return a;
}
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
static List<T> LCS<T>(T[] s, T[] t)
where T : IEquatable<T> {
int sl = s.Length, tl = t.Length;
var dp = new int[sl + 1, tl + 1];
for (var i = 0; i < sl; i++)
for (var j = 0; j < tl; j++)
dp[i + 1, j + 1] =
s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]);
{
var r = new List<T>();
int i = sl, j = tl;
while (i > 0 && j > 0)
if (s[--i].Equals(t[--j]))
r.Add(s[i]);
else if (dp[i, j + 1] > dp[i + 1, j])
++j;
else
++i;
r.Reverse();
return r;
}
}
static long LIS<T>(T[] array, bool strict) {
var l = new List<T>();
foreach (var e in array) {
var i = l.BinarySearch(e);
if (i < 0)
i = ~i;
else if (!strict)
++i;
if (i == l.Count)
l.Add(e);
else
l[i] = e;
}
return l.Count;
}
class PQ<T>
where T : IComparable {
List<T> h;
Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV>
where TK : IComparable {
PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
long[] d;
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
public bool IsSame(long x, long y) => Root(x) == Root(y);
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
public long Count(long x) => -d[Root(x)];
}
struct Mod : IEquatable<Mod>, IEquatable<long> {
static public long _mod = 1000000007;
long v;
public Mod(long x) {
if (x < _mod && x >= 0)
v = x;
else if ((v = x % _mod) < 0)
v += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
static public implicit operator long(Mod x) => x.v;
public void Add(Mod x) {
if ((v += x.v) >= _mod)
v -= _mod;
}
public void Sub(Mod x) {
if ((v -= x.v) < 0)
v += _mod;
}
public void Mul(Mod x) => v = (v * x.v) % _mod;
public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
static public Mod operator +(Mod x, Mod y) {
var t = x.v + y.v;
return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t };
}
static public Mod operator -(Mod x, Mod y) {
var t = x.v - y.v;
return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t };
}
static public Mod operator *(Mod x, Mod y) => x.v * y.v;
static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
static public bool operator ==(Mod x, Mod y) => x.v == y.v;
static public bool operator !=(Mod x, Mod y) => x.v != y.v;
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
public bool Equals(Mod x) => v == x.v;
public bool Equals(long x) => v == x;
public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
public override int GetHashCode() => v.GetHashCode();
public override string ToString() => v.ToString();
static List<Mod> _fact = new List<Mod>() { 1 };
static void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
struct Mat<T> {
T[,] m;
public Mat(T[,] v) { m = (T[,])v.Clone(); }
static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v);
public T this[int r, int c] {
get { return m[r, c]; }
set { m[r, c] = value; }
}
static public Mat<T> operator +(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)x;
return tm;
}
static public Mat<T> operator +(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)b[r, c];
return tm;
}
static public Mat<T> operator -(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)x;
return tm;
}
static public Mat<T> operator -(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)b[r, c];
return tm;
}
static public Mat<T> operator *(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] *= (dynamic)x;
return tm;
}
static public Mat<T> operator *(Mat<T> a, Mat<T> b) {
var nr = a.m.GetLength(0);
var nc = b.m.GetLength(1);
var tm = new T[nr, nc];
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j)
tm[i, j] = (dynamic)0;
for (int r = 0; r < nr; ++r)
for (int c = 0; c < nc; ++c)
for (int i = 0; i < a.m.GetLength(1); ++i)
tm[r, c] += a[r, i] * (dynamic)b[i, c];
return tm;
}
static public Mat<T> Pow(Mat<T> x, long y) {
var n = x.m.GetLength(0);
var t = (Mat<T>)new T[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i, j] = (dynamic)(i == j ? 1 : 0);
while (y != 0) {
if ((y & 1) == 1)
t *= x;
x *= x;
y >>= 1;
}
return t;
}
}
class Tree {
long N;
int l;
List<long>[] p;
int[] d;
long[][] pr;
long r;
Tuple<long, long, int>[] e;
Tuple<long, long>[] b;
bool lca;
bool euler;
bool bfs;
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
public Tuple<long, long>[] BFSRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class Graph {
int n;
List<Tuple<int, int, long>> pathList;
Dictionary<int, long>[] vtxPath;
long INF = (long.MaxValue >> 1) - 1;
public Graph(long _n) {
n = (int)_n;
pathList = new List<Tuple<int, int, long>>();
vtxPath = Repeat(0, n).Select(_ => new Dictionary<int, long>()).ToArray();
}
public void AddPath(long a, long b, long c) {
pathList.Add(Tuple.Create((int)a, (int)b, c));
vtxPath[a][(int)b] =
vtxPath[a].ContainsKey((int)b) ? Min(vtxPath[a][(int)b], c) : c;
}
public long[,] WarshallFloyd() {
var ret = new long[n, n];
for (var i = 0; i < n; i++)
for (var j = 0; j < n; j++)
ret[i, j] = vtxPath[i].ContainsKey(j) ? vtxPath[i][j] : INF;
for (var k = 0; k < n; k++)
for (var i = 0; i < n; i++)
for (var j = 0; j < n; j++)
ret[i, j] = Min(ret[i, j], ret[i, k] + ret[k, j]);
return ret;
}
public Tuple<long[], int?[], bool[]> BellmanFord(long s) {
var dist = Repeat(INF, n).ToArray();
var pred = new int?[n];
var neg = new bool[n];
dist[s] = 0;
for (var i = 1; i < n; i++)
foreach (var path in pathList)
if (dist[path.Item2] >
(dist[path.Item1] == INF ? INF : dist[path.Item1] + path.Item3)) {
dist[path.Item2] = dist[path.Item1] + path.Item3;
pred[path.Item2] = path.Item1;
}
for (var i = 0; i < n; i++)
foreach (var path in pathList)
if (dist[path.Item2] > (dist[path.Item1] == INF
? INF
: dist[path.Item1] + path.Item3) ||
neg[path.Item1]) {
dist[path.Item2] = dist[path.Item1] + path.Item3;
neg[path.Item2] = true;
}
return Tuple.Create(dist, pred, neg);
}
public Tuple<long[], int?[]> Dijkstra(long s) {
var dist = Repeat(long.MaxValue >> 2, n).ToArray();
var pred = new int?[n];
dist[s] = 0;
var q = new PQ<long, int>();
q.Push(0, (int)s);
while (q.Count > 0) {
var u = q.Pop().Item2;
foreach (var path in vtxPath[u]) {
var v = path.Key;
var alt = dist[u] + path.Value;
if (dist[v] > alt) {
dist[v] = alt;
pred[v] = u;
q.Push(alt, v);
}
}
}
return Tuple.Create(dist, pred);
}
}
class BT<T>
where T : IComparable {
class Node {
public Node l;
public Node r;
public T v;
public bool b;
public int c;
}
Comparison<T> c;
Node r;
bool ch;
T lm;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
bool R(Node n) => n != null && !n.b;
bool B(Node n) => n != null && n.b;
long C(Node n) => n?.c ?? 0;
Node RtL(Node n) {
Node m = n.r, t = m.l;
m.l = n;
n.r = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtR(Node n) {
Node m = n.l, t = m.r;
m.r = n;
n.l = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtLR(Node n) {
n.l = RtL(n.l);
return RtR(n);
}
Node RtRL(Node n) {
n.r = RtR(n.r);
return RtL(n);
}
public void Add(T x) {
r = A(r, x);
r.b = true;
}
Node A(Node n, T x) {
if (n == null) {
ch = true;
return new Node() { v = x, c = 1 };
}
if (c(x, n.v) < 0)
n.l = A(n.l, x);
else
n.r = A(n.r, x);
n.c++;
return Bl(n);
}
Node Bl(Node n) {
if (!ch)
return n;
if (!B(n))
return n;
if (R(n.l) && R(n.l.l)) {
n = RtR(n);
n.l.b = true;
} else if (R(n.l) && R(n.l.r)) {
n = RtLR(n);
n.l.b = true;
} else if (R(n.r) && R(n.r.l)) {
n = RtRL(n);
n.r.b = true;
} else if (R(n.r) && R(n.r.r)) {
n = RtL(n);
n.r.b = true;
} else
ch = false;
return n;
}
public void Remove(T x) {
r = Rm(r, x);
if (r != null)
r.b = true;
}
Node Rm(Node n, T x) {
if (n == null) {
ch = false;
return n;
}
n.c--;
var r = c(x, n.v);
if (r < 0) {
n.l = Rm(n.l, x);
return BlL(n);
}
if (r > 0) {
n.r = Rm(n.r, x);
return BlR(n);
}
if (n.l == null) {
ch = n.b;
return n.r;
}
n.l = RmM(n.l);
n.v = lm;
return BlL(n);
}
Node RmM(Node n) {
n.c--;
if (n.r != null) {
n.r = RmM(n.r);
return BlR(n);
}
lm = n.v;
ch = n.b;
return n.l;
}
Node BlL(Node n) {
if (!ch)
return n;
if (B(n.r) && R(n.r.l)) {
var b = n.b;
n = RtRL(n);
n.b = b;
n.l.b = true;
ch = false;
} else if (B(n.r) && R(n.r.r)) {
var b = n.b;
n = RtL(n);
n.b = b;
n.r.b = true;
n.l.b = true;
ch = false;
} else if (B(n.r)) {
ch = n.b;
n.b = true;
n.r.b = false;
} else {
n = RtL(n);
n.b = true;
n.l.b = false;
n.l = BlL(n.l);
ch = false;
}
return n;
}
Node BlR(Node n) {
if (!ch)
return n;
if (B(n.l) && R(n.l.r)) {
var b = n.b;
n = RtLR(n);
n.b = b;
n.r.b = true;
ch = false;
} else if (B(n.l) && R(n.l.l)) {
var b = n.b;
n = RtR(n);
n.b = b;
n.l.b = true;
n.r.b = true;
ch = false;
} else if (B(n.l)) {
ch = n.b;
n.b = true;
n.l.b = false;
} else {
n = RtR(n);
n.b = true;
n.r.b = false;
n.r = BlR(n.r);
ch = false;
}
return n;
}
public T this[long i] {
get { return At(r, i); }
}
T At(Node n, long i) {
if (n == null)
return default(T);
if (n.l == null)
if (i == 0)
return n.v;
else
return At(n.r, i - 1);
if (n.l.c == i)
return n.v;
if (n.l.c > i)
return At(n.l, i);
return At(n.r, i - n.l.c - 1);
}
public bool Have(T x) {
var t = FindUpper(x);
return t < C(r) && At(r, t).CompareTo(x) == 0;
}
public long FindUpper(T x, bool allowSame = true) => allowSame
? FL(r, x) + 1
: FU(r, x);
long FU(Node n, T x) {
if (n == null)
return 0;
var r = c(x, n.v);
if (r < 0)
return FU(n.l, x);
return C(n.l) + 1 + FU(n.r, x);
}
public long FindLower(T x, bool allowSame = true) {
var t = FL(r, x);
if (allowSame)
return t + 1 < C(r) && At(r, t + 1).CompareTo(x) == 0 ? t + 1
: t < 0 ? C(r)
: t;
return t < 0 ? C(r) : t;
}
long FL(Node n, T x) {
if (n == null)
return -1;
var r = c(x, n.v);
if (r > 0)
return C(n.l) + 1 + FL(n.r, x);
return FL(n.l, x);
}
public T Min() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.l;
}
return p == null ? default(T) : p.v;
}
public T Max() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.r;
}
return p == null ? default(T) : p.v;
}
public bool Any() => r != null;
public long Count() => C(r);
public IEnumerable<T> List() => L(r);
IEnumerable<T> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.l))
yield return i;
yield return n.v;
foreach (var i in L(n.r))
yield return i;
}
}
class Dict<K, V> : Dictionary<K, V> {
Func<K, V> d;
public Dict(Func<K, V> _d) { d = _d; }
public Dict() : this(_ => default(V)) {}
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = d(i);
}
set { base[i] = value; }
}
}
class Deque<T> {
T[] b;
int o, c;
public int Count;
public T this[int i] {
get { return b[gi(i)]; }
set { b[gi(i)] = value; }
}
public Deque(int cap = 16) { b = new T[c = cap]; }
int gi(int i) {
if (i >= c)
throw new Exception();
var r = o + i;
return r >= c ? r - c : r;
}
public void PushFront(T x) {
if (Count == c)
e();
if (--o < 0)
o += b.Length;
b[o] = x;
++Count;
}
public T PopFront() {
if (Count-- == 0)
throw new Exception();
var r = b[o++];
if (o >= c)
o -= c;
return r;
}
public T Front => b[o];
public void PushBack(T x) {
if (Count == c)
e();
var i = o + Count++;
b[i >= c ? i - c : i] = x;
}
public T PopBack() {
if (Count == 0)
throw new Exception();
return b[gi(--Count)];
}
public T Back => b[gi(Count - 1)];
void e() {
T[] nb = new T[c << 1];
if (o > c - Count) {
var l = b.Length - o;
Array.Copy(b, o, nb, 0, l);
Array.Copy(b, 0, nb, l, Count - l);
} else
Array.Copy(b, o, nb, 0, Count);
b = nb;
o = 0;
c <<= 1;
}
public void Insert(int i, T x) {
if (i > Count)
throw new Exception();
this.PushFront(x);
for (int j = 0; j < i; j++)
this[j] = this[j + 1];
this[i] = x;
}
public T RemoveAt(int i) {
if (i < 0 || i >= Count)
throw new Exception();
var r = this[i];
for (int j = i; j > 0; j--)
this[j] = this[j - 1];
this.PopFront();
return r;
}
}
class SegTree<T> {
int n;
T ti;
Func<T, T, T> f;
T[] dat;
public SegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
while (n < _n)
n <<= 1;
ti = _ti;
f = _f;
dat = Repeat(ti, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public void Update(long i, T v) {
dat[i += n] = v;
while ((i >>= 1) > 0)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public T Query(long l, long r) {
var vl = ti;
var vr = ti;
for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, dat[li++]);
if ((ri & 1) == 1)
vr = f(dat[--ri], vr);
}
return f(vl, vr);
}
public T this[long idx] {
get { return dat[idx + n]; }
set { Update(idx, value); }
}
}
class LazySegTree<T, E> {
int n, height;
T ti;
E ei;
Func<T, T, T> f;
Func<T, E, T> g;
Func<E, E, E> h;
T[] dat;
E[] laz;
public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g,
Func<E, E, E> _h) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
ei = _ei;
f = _f;
g = _g;
h = _h;
dat = Repeat(ti, n << 1).ToArray();
laz = Repeat(ei, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f,
Func<T, E, T> _g, Func<E, E, E> _h)
: this(l.Count, _ti, _ei, _f, _g, _h) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
void Eval(long i) {
if (laz[i].Equals(ei))
return;
laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]);
laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]);
dat[i] = Reflect(i);
laz[i] = ei;
}
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
void Recalc(long i) {
while ((i >>= 1) > 0)
dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1));
}
public void Update(long l, long r, E v) {
Thrust(l += n);
Thrust(r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
laz[li] = h(laz[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
laz[ri] = h(laz[ri], v);
}
}
Recalc(l);
Recalc(r);
}
public T Query(long l, long r) {
Thrust(l += n);
Thrust(r += n - 1);
var vl = ti;
var vr = ti;
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, Reflect(li++));
if ((ri & 1) == 1)
vr = f(Reflect(--ri), vr);
}
return f(vl, vr);
}
public T this[long idx] {
get {
Thrust(idx += n);
return dat[idx] = Reflect(idx);
}
set {
Thrust(idx += n);
dat[idx] = value;
laz[idx] = ei;
Recalc(idx);
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
namespace Program {
public static class AGC018A {
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var K = NN;
var AList = NNList(N);
if (AList.Max() < K) {
Console.WriteLine("IMPOSSIBLE");
return;
}
var gcd = AList.Aggregate((x, acc) => GCD(x, acc));
if (K % gcd == 0) {
Console.WriteLine("POSSIBLE");
} else {
Console.WriteLine("IMPOSSIBLE");
}
}
static public void Main(string[] args) {
if (args.Length == 0) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
}
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
Console.Out.Flush();
}
static class Console_ {
static Queue<string> param = new Queue<string>();
public static string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
}
static long NN => long.Parse(Console_.NextString());
static double ND => double.Parse(Console_.NextString());
static string NS => Console_.NextString();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static IEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static void RevSort<T>(T[] l)
where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); }
static void RevSort<T>(T[] l, Comparison<T> comp)
where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); }
static IEnumerable<long> Primes(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i] && 2 * i + 1 <= x)
yield return 2 * i + 1;
}
static IEnumerable<long> Factors(long x) {
if (x < 2)
yield break;
while (x % 2 == 0) {
x /= 2;
yield return 2;
}
var max = (long)Math.Sqrt(x);
for (long i = 3; i <= max; i += 2)
while (x % i == 0) {
x /= i;
yield return i;
}
if (x != 1)
yield return x;
}
static IEnumerable<long> Divisor(long x) {
if (x < 1)
yield break;
var max = (long)Math.Sqrt(x);
for (long i = 1; i <= max; ++i) {
if (x % i != 0)
continue;
yield return i;
if (i != x / i)
yield return x / i;
}
}
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
static long GCD(long a, long b) {
while (b > 0) {
var tmp = b;
b = a % b;
a = tmp;
}
return a;
}
static long LCM(long a, long b) => a * b / GCD(a, b);
static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y);
static Mod Pow(Mod x, long y) {
Mod a = 1;
while (y != 0) {
if ((y & 1) == 1)
a.Mul(x);
x.Mul(x);
y >>= 1;
}
return a;
}
static long Pow(long x, long y) {
long a = 1;
while (y != 0) {
if ((y & 1) == 1)
a *= x;
x *= x;
y >>= 1;
}
return a;
}
static List<long> _fact = new List<long>() { 1 };
static void _B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static long Comb(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static long Perm(long n, long k) {
_B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) {
Func<TR> t = () => default(TR);
return t = () => f(t);
}
static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) {
Func<T1, TR> t = x1 => default(TR);
return t = x1 => f(x1, t);
}
static Func<T1, T2, TR>
Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) {
Func<T1, T2, TR> t = (x1, x2) => default(TR);
return t = (x1, x2) => f(x1, x2, t);
}
static Func<T1, T2, T3, TR>
Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) {
Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR);
return t = (x1, x2, x3) => f(x1, x2, x3, t);
}
static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>(
Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) {
Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR);
return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t);
}
static List<T> LCS<T>(T[] s, T[] t)
where T : IEquatable<T> {
int sl = s.Length, tl = t.Length;
var dp = new int[sl + 1, tl + 1];
for (var i = 0; i < sl; i++)
for (var j = 0; j < tl; j++)
dp[i + 1, j + 1] =
s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]);
{
var r = new List<T>();
int i = sl, j = tl;
while (i > 0 && j > 0)
if (s[--i].Equals(t[--j]))
r.Add(s[i]);
else if (dp[i, j + 1] > dp[i + 1, j])
++j;
else
++i;
r.Reverse();
return r;
}
}
static long LIS<T>(T[] array, bool strict) {
var l = new List<T>();
foreach (var e in array) {
var i = l.BinarySearch(e);
if (i < 0)
i = ~i;
else if (!strict)
++i;
if (i == l.Count)
l.Add(e);
else
l[i] = e;
}
return l.Count;
}
class PQ<T>
where T : IComparable {
List<T> h;
Comparison<T> c;
public T Peek => h[0];
public int Count => h.Count;
public PQ(int cap, Comparison<T> c, bool asc = true) {
h = new List<T>(cap);
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(Comparison<T> c, bool asc = true) {
h = new List<T>();
this.c = asc ? c : (x, y) => c(y, x);
}
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
public void Push(T v) {
var i = h.Count;
h.Add(v);
while (i > 0) {
var ni = (i - 1) / 2;
if (c(v, h[ni]) >= 0)
break;
h[i] = h[ni];
i = ni;
}
h[i] = v;
}
public T Pop() {
var r = h[0];
var v = h[h.Count - 1];
h.RemoveAt(h.Count - 1);
if (h.Count == 0)
return r;
var i = 0;
while (i * 2 + 1 < h.Count) {
var i1 = i * 2 + 1;
var i2 = i * 2 + 2;
if (i2 < h.Count && c(h[i1], h[i2]) > 0)
i1 = i2;
if (c(v, h[i1]) <= 0)
break;
h[i] = h[i1];
i = i1;
}
h[i] = v;
return r;
}
}
class PQ<TK, TV>
where TK : IComparable {
PQ<Tuple<TK, TV>> q;
public Tuple<TK, TV> Peek => q.Peek;
public int Count => q.Count;
public PQ(int cap, Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(Comparison<TK> c, bool asc = true) {
q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc);
}
public PQ(int cap, bool asc = true)
: this(cap, (x, y) => x.CompareTo(y), asc) {}
public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {}
public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v));
public Tuple<TK, TV> Pop() => q.Pop();
}
public class UF {
long[] d;
public UF(long s) { d = Repeat(-1L, s).ToArray(); }
public bool Unite(long x, long y) {
x = Root(x);
y = Root(y);
if (x != y) {
if (d[y] < d[x]) {
var t = y;
y = x;
x = t;
}
d[x] += d[y];
d[y] = x;
}
return x != y;
}
public bool IsSame(long x, long y) => Root(x) == Root(y);
public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]);
public long Count(long x) => -d[Root(x)];
}
struct Mod : IEquatable<Mod>, IEquatable<long> {
static public long _mod = 1000000007;
long v;
public Mod(long x) {
if (x < _mod && x >= 0)
v = x;
else if ((v = x % _mod) < 0)
v += _mod;
}
static public implicit operator Mod(long x) => new Mod(x);
static public implicit operator long(Mod x) => x.v;
public void Add(Mod x) {
if ((v += x.v) >= _mod)
v -= _mod;
}
public void Sub(Mod x) {
if ((v -= x.v) < 0)
v += _mod;
}
public void Mul(Mod x) => v = (v * x.v) % _mod;
public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod;
static public Mod operator +(Mod x, Mod y) {
var t = x.v + y.v;
return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t };
}
static public Mod operator -(Mod x, Mod y) {
var t = x.v - y.v;
return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t };
}
static public Mod operator *(Mod x, Mod y) => x.v * y.v;
static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v);
static public bool operator ==(Mod x, Mod y) => x.v == y.v;
static public bool operator !=(Mod x, Mod y) => x.v != y.v;
static public long Inverse(long x) {
long b = _mod, r = 1, u = 0, t = 0;
while (b > 0) {
var q = x / b;
t = u;
u = r - q * u;
r = t;
t = b;
b = x - q * b;
x = t;
}
return r < 0 ? r + _mod : r;
}
public bool Equals(Mod x) => v == x.v;
public bool Equals(long x) => v == x;
public override bool Equals(object x) => x == null ? false : Equals((Mod)x);
public override int GetHashCode() => v.GetHashCode();
public override string ToString() => v.ToString();
static List<Mod> _fact = new List<Mod>() { 1 };
static void B(long n) {
if (n >= _fact.Count)
for (int i = _fact.Count; i <= n; ++i)
_fact.Add(_fact[i - 1] * i);
}
static public Mod Comb(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k];
}
static public Mod Perm(long n, long k) {
B(n);
if (n == 0 && k == 0)
return 1;
if (n < k || n < 0)
return 0;
return _fact[(int)n] / _fact[(int)(n - k)];
}
}
struct Mat<T> {
T[,] m;
public Mat(T[,] v) { m = (T[,])v.Clone(); }
static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v);
public T this[int r, int c] {
get { return m[r, c]; }
set { m[r, c] = value; }
}
static public Mat<T> operator +(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)x;
return tm;
}
static public Mat<T> operator +(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] += (dynamic)b[r, c];
return tm;
}
static public Mat<T> operator -(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)x;
return tm;
}
static public Mat<T> operator -(Mat<T> a, Mat<T> b) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] -= (dynamic)b[r, c];
return tm;
}
static public Mat<T> operator *(Mat<T> a, T x) {
var tm = (T[,])a.m.Clone();
for (int r = 0; r < tm.GetLength(0); ++r)
for (int c = 0; c < tm.GetLength(1); ++c)
tm[r, c] *= (dynamic)x;
return tm;
}
static public Mat<T> operator *(Mat<T> a, Mat<T> b) {
var nr = a.m.GetLength(0);
var nc = b.m.GetLength(1);
var tm = new T[nr, nc];
for (int i = 0; i < nr; ++i)
for (int j = 0; j < nc; ++j)
tm[i, j] = (dynamic)0;
for (int r = 0; r < nr; ++r)
for (int c = 0; c < nc; ++c)
for (int i = 0; i < a.m.GetLength(1); ++i)
tm[r, c] += a[r, i] * (dynamic)b[i, c];
return tm;
}
static public Mat<T> Pow(Mat<T> x, long y) {
var n = x.m.GetLength(0);
var t = (Mat<T>)new T[n, n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i, j] = (dynamic)(i == j ? 1 : 0);
while (y != 0) {
if ((y & 1) == 1)
t *= x;
x *= x;
y >>= 1;
}
return t;
}
}
class Tree {
long N;
int l;
List<long>[] p;
int[] d;
long[][] pr;
long r;
Tuple<long, long, int>[] e;
Tuple<long, long>[] b;
bool lca;
bool euler;
bool bfs;
public Tree(List<long>[] p_, long r_) {
N = p_.Length;
p = p_;
r = r_;
lca = false;
euler = false;
}
public Tuple<long, long>[] BFSRoot() {
if (!bfs) {
var nb = new List<Tuple<long, long>>();
var q = new Queue<long>();
var d = new bool[N];
nb.Add(Tuple.Create(r, -1L));
d[r] = true;
q.Enqueue(r);
while (q.Count > 0) {
var w = q.Dequeue();
foreach (var i in p[w]) {
if (d[i])
continue;
d[i] = true;
q.Enqueue(i);
nb.Add(Tuple.Create(i, w));
}
}
b = nb.ToArray();
bfs = true;
}
return b;
}
public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray();
public Tuple<long, long, int>[] Euler() {
if (!euler) {
var ne = new List<Tuple<long, long, int>>();
var s = new Stack<Tuple<long, long>>();
var d = new bool[N];
d[r] = true;
s.Push(Tuple.Create(r, -1L));
while (s.Count > 0) {
var w = s.Peek();
var ad = true;
foreach (var i in p[w.Item1]) {
if (d[i])
continue;
d[i] = true;
ad = false;
s.Push(Tuple.Create(i, w.Item1));
}
if (!ad || p[w.Item1].Count == 1)
ne.Add(Tuple.Create(w.Item1, w.Item2, 1));
if (ad) {
s.Pop();
ne.Add(Tuple.Create(w.Item1, w.Item2, -1));
}
}
e = ne.ToArray();
euler = true;
}
return e;
}
public long LCA(long u, long v) {
if (!lca) {
l = 0;
while (N > (1 << l))
l++;
d = new int[N];
pr = Repeat(0, l).Select(_ => new long[N]).ToArray();
d[r] = 0;
pr[0][r] = -1;
var q = new Stack<long>();
q.Push(r);
while (q.Count > 0) {
var w = q.Pop();
foreach (var i in p[w]) {
if (i == pr[0][w])
continue;
q.Push(i);
d[i] = d[w] + 1;
pr[0][i] = w;
}
}
for (var k = 0; k + 1 < l; k++)
for (var w = 0; w < N; w++)
if (pr[k][w] < 0)
pr[k + 1][w] = -1;
else
pr[k + 1][w] = pr[k][pr[k][w]];
lca = true;
}
if (d[u] > d[v]) {
var t = u;
u = v;
v = t;
}
for (var k = 0; k < l; k++)
if ((((d[v] - d[u]) >> k) & 1) != 0)
v = pr[k][v];
if (u == v)
return u;
for (var k = l - 1; k >= 0; k--)
if (pr[k][u] != pr[k][v]) {
u = pr[k][u];
v = pr[k][v];
}
return pr[0][u];
}
}
class Graph {
int n;
List<Tuple<int, int, long>> pathList;
Dictionary<int, long>[] vtxPath;
long INF = (long.MaxValue >> 1) - 1;
public Graph(long _n) {
n = (int)_n;
pathList = new List<Tuple<int, int, long>>();
vtxPath = Repeat(0, n).Select(_ => new Dictionary<int, long>()).ToArray();
}
public void AddPath(long a, long b, long c) {
pathList.Add(Tuple.Create((int)a, (int)b, c));
vtxPath[a][(int)b] =
vtxPath[a].ContainsKey((int)b) ? Min(vtxPath[a][(int)b], c) : c;
}
public long[,] WarshallFloyd() {
var ret = new long[n, n];
for (var i = 0; i < n; i++)
for (var j = 0; j < n; j++)
ret[i, j] = vtxPath[i].ContainsKey(j) ? vtxPath[i][j] : INF;
for (var k = 0; k < n; k++)
for (var i = 0; i < n; i++)
for (var j = 0; j < n; j++)
ret[i, j] = Min(ret[i, j], ret[i, k] + ret[k, j]);
return ret;
}
public Tuple<long[], int?[], bool[]> BellmanFord(long s) {
var dist = Repeat(INF, n).ToArray();
var pred = new int?[n];
var neg = new bool[n];
dist[s] = 0;
for (var i = 1; i < n; i++)
foreach (var path in pathList)
if (dist[path.Item2] >
(dist[path.Item1] == INF ? INF : dist[path.Item1] + path.Item3)) {
dist[path.Item2] = dist[path.Item1] + path.Item3;
pred[path.Item2] = path.Item1;
}
for (var i = 0; i < n; i++)
foreach (var path in pathList)
if (dist[path.Item2] > (dist[path.Item1] == INF
? INF
: dist[path.Item1] + path.Item3) ||
neg[path.Item1]) {
dist[path.Item2] = dist[path.Item1] + path.Item3;
neg[path.Item2] = true;
}
return Tuple.Create(dist, pred, neg);
}
public Tuple<long[], int?[]> Dijkstra(long s) {
var dist = Repeat(long.MaxValue >> 2, n).ToArray();
var pred = new int?[n];
dist[s] = 0;
var q = new PQ<long, int>();
q.Push(0, (int)s);
while (q.Count > 0) {
var u = q.Pop().Item2;
foreach (var path in vtxPath[u]) {
var v = path.Key;
var alt = dist[u] + path.Value;
if (dist[v] > alt) {
dist[v] = alt;
pred[v] = u;
q.Push(alt, v);
}
}
}
return Tuple.Create(dist, pred);
}
}
class BT<T>
where T : IComparable {
class Node {
public Node l;
public Node r;
public T v;
public bool b;
public int c;
}
Comparison<T> c;
Node r;
bool ch;
T lm;
public BT(Comparison<T> _c) { c = _c; }
public BT() : this((x, y) => x.CompareTo(y)) {}
bool R(Node n) => n != null && !n.b;
bool B(Node n) => n != null && n.b;
long C(Node n) => n?.c ?? 0;
Node RtL(Node n) {
Node m = n.r, t = m.l;
m.l = n;
n.r = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtR(Node n) {
Node m = n.l, t = m.r;
m.r = n;
n.l = t;
n.c -= m.c - (t?.c ?? 0);
m.c += n.c - (t?.c ?? 0);
return m;
}
Node RtLR(Node n) {
n.l = RtL(n.l);
return RtR(n);
}
Node RtRL(Node n) {
n.r = RtR(n.r);
return RtL(n);
}
public void Add(T x) {
r = A(r, x);
r.b = true;
}
Node A(Node n, T x) {
if (n == null) {
ch = true;
return new Node() { v = x, c = 1 };
}
if (c(x, n.v) < 0)
n.l = A(n.l, x);
else
n.r = A(n.r, x);
n.c++;
return Bl(n);
}
Node Bl(Node n) {
if (!ch)
return n;
if (!B(n))
return n;
if (R(n.l) && R(n.l.l)) {
n = RtR(n);
n.l.b = true;
} else if (R(n.l) && R(n.l.r)) {
n = RtLR(n);
n.l.b = true;
} else if (R(n.r) && R(n.r.l)) {
n = RtRL(n);
n.r.b = true;
} else if (R(n.r) && R(n.r.r)) {
n = RtL(n);
n.r.b = true;
} else
ch = false;
return n;
}
public void Remove(T x) {
r = Rm(r, x);
if (r != null)
r.b = true;
}
Node Rm(Node n, T x) {
if (n == null) {
ch = false;
return n;
}
n.c--;
var r = c(x, n.v);
if (r < 0) {
n.l = Rm(n.l, x);
return BlL(n);
}
if (r > 0) {
n.r = Rm(n.r, x);
return BlR(n);
}
if (n.l == null) {
ch = n.b;
return n.r;
}
n.l = RmM(n.l);
n.v = lm;
return BlL(n);
}
Node RmM(Node n) {
n.c--;
if (n.r != null) {
n.r = RmM(n.r);
return BlR(n);
}
lm = n.v;
ch = n.b;
return n.l;
}
Node BlL(Node n) {
if (!ch)
return n;
if (B(n.r) && R(n.r.l)) {
var b = n.b;
n = RtRL(n);
n.b = b;
n.l.b = true;
ch = false;
} else if (B(n.r) && R(n.r.r)) {
var b = n.b;
n = RtL(n);
n.b = b;
n.r.b = true;
n.l.b = true;
ch = false;
} else if (B(n.r)) {
ch = n.b;
n.b = true;
n.r.b = false;
} else {
n = RtL(n);
n.b = true;
n.l.b = false;
n.l = BlL(n.l);
ch = false;
}
return n;
}
Node BlR(Node n) {
if (!ch)
return n;
if (B(n.l) && R(n.l.r)) {
var b = n.b;
n = RtLR(n);
n.b = b;
n.r.b = true;
ch = false;
} else if (B(n.l) && R(n.l.l)) {
var b = n.b;
n = RtR(n);
n.b = b;
n.l.b = true;
n.r.b = true;
ch = false;
} else if (B(n.l)) {
ch = n.b;
n.b = true;
n.l.b = false;
} else {
n = RtR(n);
n.b = true;
n.r.b = false;
n.r = BlR(n.r);
ch = false;
}
return n;
}
public T this[long i] {
get { return At(r, i); }
}
T At(Node n, long i) {
if (n == null)
return default(T);
if (n.l == null)
if (i == 0)
return n.v;
else
return At(n.r, i - 1);
if (n.l.c == i)
return n.v;
if (n.l.c > i)
return At(n.l, i);
return At(n.r, i - n.l.c - 1);
}
public bool Have(T x) {
var t = FindUpper(x);
return t < C(r) && At(r, t).CompareTo(x) == 0;
}
public long FindUpper(T x, bool allowSame = true) => allowSame
? FL(r, x) + 1
: FU(r, x);
long FU(Node n, T x) {
if (n == null)
return 0;
var r = c(x, n.v);
if (r < 0)
return FU(n.l, x);
return C(n.l) + 1 + FU(n.r, x);
}
public long FindLower(T x, bool allowSame = true) {
var t = FL(r, x);
if (allowSame)
return t + 1 < C(r) && At(r, t + 1).CompareTo(x) == 0 ? t + 1
: t < 0 ? C(r)
: t;
return t < 0 ? C(r) : t;
}
long FL(Node n, T x) {
if (n == null)
return -1;
var r = c(x, n.v);
if (r > 0)
return C(n.l) + 1 + FL(n.r, x);
return FL(n.l, x);
}
public T Min() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.l;
}
return p == null ? default(T) : p.v;
}
public T Max() {
Node n = r, p = null;
while (n != null) {
p = n;
n = n.r;
}
return p == null ? default(T) : p.v;
}
public bool Any() => r != null;
public long Count() => C(r);
public IEnumerable<T> List() => L(r);
IEnumerable<T> L(Node n) {
if (n == null)
yield break;
foreach (var i in L(n.l))
yield return i;
yield return n.v;
foreach (var i in L(n.r))
yield return i;
}
}
class Dict<K, V> : Dictionary<K, V> {
Func<K, V> d;
public Dict(Func<K, V> _d) { d = _d; }
public Dict() : this(_ => default(V)) {}
new public V this[K i] { get { V v;
return TryGetValue(i, out v) ? v : base[i] = d(i);
}
set { base[i] = value; }
}
}
class Deque<T> {
T[] b;
int o, c;
public int Count;
public T this[int i] {
get { return b[gi(i)]; }
set { b[gi(i)] = value; }
}
public Deque(int cap = 16) { b = new T[c = cap]; }
int gi(int i) {
if (i >= c)
throw new Exception();
var r = o + i;
return r >= c ? r - c : r;
}
public void PushFront(T x) {
if (Count == c)
e();
if (--o < 0)
o += b.Length;
b[o] = x;
++Count;
}
public T PopFront() {
if (Count-- == 0)
throw new Exception();
var r = b[o++];
if (o >= c)
o -= c;
return r;
}
public T Front => b[o];
public void PushBack(T x) {
if (Count == c)
e();
var i = o + Count++;
b[i >= c ? i - c : i] = x;
}
public T PopBack() {
if (Count == 0)
throw new Exception();
return b[gi(--Count)];
}
public T Back => b[gi(Count - 1)];
void e() {
T[] nb = new T[c << 1];
if (o > c - Count) {
var l = b.Length - o;
Array.Copy(b, o, nb, 0, l);
Array.Copy(b, 0, nb, l, Count - l);
} else
Array.Copy(b, o, nb, 0, Count);
b = nb;
o = 0;
c <<= 1;
}
public void Insert(int i, T x) {
if (i > Count)
throw new Exception();
this.PushFront(x);
for (int j = 0; j < i; j++)
this[j] = this[j + 1];
this[i] = x;
}
public T RemoveAt(int i) {
if (i < 0 || i >= Count)
throw new Exception();
var r = this[i];
for (int j = i; j > 0; j--)
this[j] = this[j - 1];
this.PopFront();
return r;
}
}
class SegTree<T> {
int n;
T ti;
Func<T, T, T> f;
T[] dat;
public SegTree(long _n, T _ti, Func<T, T, T> _f) {
n = 1;
while (n < _n)
n <<= 1;
ti = _ti;
f = _f;
dat = Repeat(ti, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public void Update(long i, T v) {
dat[i += n] = v;
while ((i >>= 1) > 0)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public T Query(long l, long r) {
var vl = ti;
var vr = ti;
for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, dat[li++]);
if ((ri & 1) == 1)
vr = f(dat[--ri], vr);
}
return f(vl, vr);
}
public T this[long idx] {
get { return dat[idx + n]; }
set { Update(idx, value); }
}
}
class LazySegTree<T, E> {
int n, height;
T ti;
E ei;
Func<T, T, T> f;
Func<T, E, T> g;
Func<E, E, E> h;
T[] dat;
E[] laz;
public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g,
Func<E, E, E> _h) {
n = 1;
height = 0;
while (n < _n) {
n <<= 1;
++height;
}
ti = _ti;
ei = _ei;
f = _f;
g = _g;
h = _h;
dat = Repeat(ti, n << 1).ToArray();
laz = Repeat(ei, n << 1).ToArray();
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f,
Func<T, E, T> _g, Func<E, E, E> _h)
: this(l.Count, _ti, _ei, _f, _g, _h) {
for (var i = 0; i < l.Count; i++)
dat[n + i] = l[i];
for (var i = n - 1; i > 0; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
}
T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]);
void Eval(long i) {
if (laz[i].Equals(ei))
return;
laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]);
laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]);
dat[i] = Reflect(i);
laz[i] = ei;
}
void Thrust(long i) {
for (var j = height; j > 0; j--)
Eval(i >> j);
}
void Recalc(long i) {
while ((i >>= 1) > 0)
dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1));
}
public void Update(long l, long r, E v) {
Thrust(l += n);
Thrust(r += n - 1);
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1) {
laz[li] = h(laz[li], v);
++li;
}
if ((ri & 1) == 1) {
--ri;
laz[ri] = h(laz[ri], v);
}
}
Recalc(l);
Recalc(r);
}
public T Query(long l, long r) {
Thrust(l += n);
Thrust(r += n - 1);
var vl = ti;
var vr = ti;
for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) {
if ((li & 1) == 1)
vl = f(vl, Reflect(li++));
if ((ri & 1) == 1)
vr = f(Reflect(--ri), vr);
}
return f(vl, vr);
}
public T this[long idx] {
get {
Thrust(idx += n);
return dat[idx] = Reflect(idx);
}
set {
Thrust(idx += n);
dat[idx] = value;
laz[idx] = ei;
Recalc(idx);
}
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
| 8
| 10,171
| 2
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
long n = long.Parse(input[0]);
long k = long.Parse(input[1]);
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long memo = nums[0];
long max = nums[0];
for (int i = 1; i < n; i++) {
memo = Gcd(memo, nums[i]);
max = Math.Max(max, nums[i]);
}
Console.WriteLine((k <= max && max - k % memo == 0) ? "POSSIBLE"
: "IMPOSSIBLE");
}
static long Gcd(long a, long b) { //引数a,bの最大公約数を返す
if (a < b)
return Gcd(b, a); //入れ替え
while (b != 0) {
long changeTo = a % b;
a = b;
b = changeTo;
}
return a;
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
long n = long.Parse(input[0]);
long k = long.Parse(input[1]);
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long memo = nums[0];
long max = nums[0];
for (int i = 1; i < n; i++) {
memo = Gcd(memo, nums[i]);
max = Math.Max(max, nums[i]);
// Console.WriteLine(memo+" "+max);
}
Console.WriteLine((k <= max && (max - k) % memo == 0) ? "POSSIBLE"
: "IMPOSSIBLE");
}
static long Gcd(long a, long b) { //引数a,bの最大公約数を返す
if (a < b)
return Gcd(b, a); //入れ替え
while (b != 0) {
long changeTo = a % b;
a = b;
b = changeTo;
}
return a;
}
}
|
[["+", 0, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 12, 16, 31, 16, 31, 23, 0, 25]]
| 8
| 244
| 2
|
using System;
using System.Linq;
class Program {
static int GCM(int n, int m) {
if (Math.Min(n, m) == 0)
return Math.Max(n, m);
if (Math.Max(n, m) % Math.Min(n, m) == 0)
return Math.Max(n, m);
return GCM(Math.Max(n, m) - Math.Min(n, m), Math.Min(n, m));
}
static void Main() {
int[] a;
int n, k;
a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
n = a[0];
k = a[1];
a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int m = a.Max();
int gcm = a[0];
for (int i = 0; i < n; i++)
gcm = GCM(gcm, a[i]);
if (k % gcm == 0 && k <= m) {
Console.WriteLine("POSSIBLE");
Environment.Exit(0);
}
Console.WriteLine("IMPOSSIBLE");
}
}
|
using System;
using System.Linq;
class Program {
static int GCM(int n, int m) {
if (Math.Min(n, m) == 0)
return Math.Max(n, m);
if (Math.Max(n, m) % Math.Min(n, m) == 0)
return Math.Min(n, m);
return GCM(Math.Max(n, m) - Math.Min(n, m), Math.Min(n, m));
}
static void Main() {
int[] a;
int n, k;
a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
n = a[0];
k = a[1];
a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
int m = a.Max();
int gcm = a[0];
for (int i = 0; i < n; i++)
gcm = GCM(gcm, a[i]);
if (k % gcm == 0 && k <= m) {
Console.WriteLine("POSSIBLE");
Environment.Exit(0);
}
Console.WriteLine("IMPOSSIBLE");
}
}
|
[["-", 0, 57, 64, 37, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 37, 0, 213, 63, 214, 141, 22]]
| 8
| 285
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression,
System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;
class Program
{
static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
const int M = 1000000007;
// const int M = 998244353;
const long LM = (long)1e18;
const double eps = 1e-11;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main()
{
int n, k;
sc.Multi(out n, out k);
var a = sc.IntArr;
if (n == 1) {
DBG(a[0] == k ? "POSSIBLE" : "IMPOSSIBLE");
}
var g = mymath.gcd(a[0], a[1]);
for (int i = 2; i < n; i++)
{
g = mymath.gcd(a[i], g);
}
Prt(k % g == 0 && a.Max() >= k ? "POSSIBLE" : "IMPOSSBILE");
sw.Flush();
}
static void DBG(string a) => Console.WriteLine(a);
static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
static void DBG(params object[] a) => DBG(string.Join(" ", a));
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
public T v1;
public U v2;
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
public override string ToString() => v1 + " " + v2;
}
static class util
{
public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]);
public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2);
public static T sqr<T>(T a) => Operator<T>.Multiply(a, a);
public static T Max<T>(params T[] a) => a.Max();
public static T Min<T>(params T[] a) => a.Min();
public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
public static T[] 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;
}
}
static class Operator<T>
{
static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
class Scan
{
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U>
{ T a; U b; Multi(out a, out b); return make_pair(a, b); }
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 []{' '}, System.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]); }
public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f)
{ var ar = 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]); f = cv<Y>(ar[5]); }
}
static class mymath
{
public static long Mod = 1000000007;
public static bool isprime(long a) {
if (a < 2) return false;
for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
return true;
}
public static bool[] sieve(int n) {
var p = new bool[n + 1];
for (int i = 2; i <= n; i++) p[i] = true;
for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
return p;
}
public static List<int> getprimes(int n) {
var prs = new List<int>();
var p = sieve(n);
for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
return prs;
}
public static long[][] E(int n) {
var ret = new long[n][];
for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
return ret;
}
public static double[][] dE(int n) {
var ret = new double[n][];
for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; }
return ret;
}
public static long[][] pow(long[][] A, long n) {
if (n == 0) return E(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double[][] pow(double[][] A, long n) {
if (n == 0) return dE(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0;
for (int i = 0; i < n; i++) ret += x[i] * y[i];
return ret;
}
public static double _dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0, r = 0;
for (int i = 0; i < n; i++) {
double s = ret + (x[i] * y[i] + r);
r = (x[i] * y[i] + r) - (s - ret);
ret = s;
}
return ret;
}
public static long dot(long[] x, long[] y) {
int n = x.Length;
long ret = 0;
for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
return ret;
}
public static T[][] trans<T>(T[][] A) {
int n = A[0].Length, m = A.Length;
var ret = new T[n][];
for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
return ret;
}
public static double[] mul(double a, double[] x) {
int n = x.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i];
return ret;
}
public static long[] mul(long a, long[] x) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod;
return ret;
}
public static double[] mul(double[][] A, double[] x) {
int n = A.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static long[] mul(long[][] A, long[] x) {
int n = A.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static double[][] mul(double a, double[][] A) {
int n = A.Length;
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static long[][] mul(long a, long[][] A) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static double[][] mul(double[][] A, double[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[][] mul(long[][] A, long[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[] add(long[] x, long[] y) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
return ret;
}
public static long[][] add(long[][] A, long[][] B) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
return ret;
}
public static long pow(long a, long b) {
if (a >= Mod) return pow(a % Mod, b);
if (a == 0) return 0;
if (b == 0) return 1;
var t = pow(a, b / 2);
if ((b & 1) == 0) return t * t % Mod;
return t * t % Mod * a % Mod;
}
public static long inv(long a) => pow(a, Mod - 2);
public static long gcd(long a, long b) {
while (b > 0) { var t = a % b; a = b; b = t; } return a;
}
// a x + b y = gcd(a, b)
public static long extgcd(long a, long b, out long x, out long y) {
long g = a; x = 1; y = 0;
if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
return g;
}
public static long lcm(long a, long b) => a / gcd(a, b) * b;
static long[] facts;
public static long[] setfacts(int n) {
facts = new long[n + 1];
facts[0] = 1;
for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod;
return facts;
}
public static long comb(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
if (n - r < r) r = n - r;
if (r == 0) return 1;
if (r == 1) return n;
if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod;
int[] numer = new int[r], denom = new int[r];
for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
for (int p = 2; p <= r; p++) {
int piv = denom[p - 1];
if (piv > 1) {
int ofst = (n - r) % p;
for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
}
}
long ret = 1;
for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
return ret;
}
public static long[][] getcombs(int n) {
var ret = new long[n + 1][];
for (int i = 0; i <= n; i++) {
ret[i] = new long[i + 1];
ret[i][0] = ret[i][i] = 1;
for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod;
}
return ret;
}
// nC0, nC2, ..., nCn
public static long[] getcomb(int n) {
var ret = new long[n + 1];
ret[0] = 1;
for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod;
return ret;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
using static util;
using P = pair<int, int>;
using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression,
System.Linq.Expressions.BinaryExpression>;
using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>;
class Program
{
static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
static Scan sc = new Scan();
const int M = 1000000007;
// const int M = 998244353;
const long LM = (long)1e18;
const double eps = 1e-11;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main()
{
int n, k;
sc.Multi(out n, out k);
var a = sc.IntArr;
if (n == 1) {
DBG(a[0] == k ? "POSSIBLE" : "IMPOSSIBLE");
return;
}
var g = mymath.gcd(a[0], a[1]);
for (int i = 2; i < n; i++)
{
g = mymath.gcd(a[i], g);
}
Prt(k % g == 0 && a.Max() >= k ? "POSSIBLE" : "IMPOSSIBLE");
sw.Flush();
}
static void DBG(string a) => Console.WriteLine(a);
static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a));
static void DBG(params object[] a) => DBG(string.Join(" ", a));
static void Prt(string a) => sw.WriteLine(a);
static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a));
static void Prt(params object[] a) => Prt(string.Join(" ", a));
}
class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
public T v1;
public U v2;
public pair(T v1, U v2) {
this.v1 = v1;
this.v2 = v2;
}
public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2);
public override string ToString() => v1 + " " + v2;
}
static class util
{
public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]);
public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2);
public static T sqr<T>(T a) => Operator<T>.Multiply(a, a);
public static T Max<T>(params T[] a) => a.Max();
public static T Min<T>(params T[] a) => a.Min();
public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; }
public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; }
public static T[] 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;
}
}
static class Operator<T>
{
static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x");
static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y");
public static readonly Func<T, T, T> Add = Lambda(Expression.Add);
public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract);
public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply);
public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide);
public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus);
public static readonly Func<T, T> Negate = Lambda(Expression.Negate);
public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
class Scan
{
public int Int => int.Parse(Str);
public long Long => long.Parse(Str);
public double Double => double.Parse(Str);
public string Str => Console.ReadLine().Trim();
public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U>
{ T a; U b; Multi(out a, out b); return make_pair(a, b); }
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 []{' '}, System.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]); }
public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f)
{ var ar = 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]); f = cv<Y>(ar[5]); }
}
static class mymath
{
public static long Mod = 1000000007;
public static bool isprime(long a) {
if (a < 2) return false;
for (long i = 2; i * i <= a; i++) if (a % i == 0) return false;
return true;
}
public static bool[] sieve(int n) {
var p = new bool[n + 1];
for (int i = 2; i <= n; i++) p[i] = true;
for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false;
return p;
}
public static List<int> getprimes(int n) {
var prs = new List<int>();
var p = sieve(n);
for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i);
return prs;
}
public static long[][] E(int n) {
var ret = new long[n][];
for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; }
return ret;
}
public static double[][] dE(int n) {
var ret = new double[n][];
for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; }
return ret;
}
public static long[][] pow(long[][] A, long n) {
if (n == 0) return E(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double[][] pow(double[][] A, long n) {
if (n == 0) return dE(A.Length);
var t = pow(A, n / 2);
if ((n & 1) == 0) return mul(t, t);
return mul(mul(t, t), A);
}
public static double dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0;
for (int i = 0; i < n; i++) ret += x[i] * y[i];
return ret;
}
public static double _dot(double[] x, double[] y) {
int n = x.Length;
double ret = 0, r = 0;
for (int i = 0; i < n; i++) {
double s = ret + (x[i] * y[i] + r);
r = (x[i] * y[i] + r) - (s - ret);
ret = s;
}
return ret;
}
public static long dot(long[] x, long[] y) {
int n = x.Length;
long ret = 0;
for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod;
return ret;
}
public static T[][] trans<T>(T[][] A) {
int n = A[0].Length, m = A.Length;
var ret = new T[n][];
for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; }
return ret;
}
public static double[] mul(double a, double[] x) {
int n = x.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i];
return ret;
}
public static long[] mul(long a, long[] x) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod;
return ret;
}
public static double[] mul(double[][] A, double[] x) {
int n = A.Length;
var ret = new double[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static long[] mul(long[][] A, long[] x) {
int n = A.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]);
return ret;
}
public static double[][] mul(double a, double[][] A) {
int n = A.Length;
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static long[][] mul(long a, long[][] A) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]);
return ret;
}
public static double[][] mul(double[][] A, double[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new double[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[][] mul(long[][] A, long[][] B) {
int n = A.Length;
var Bt = trans(B);
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]);
return ret;
}
public static long[] add(long[] x, long[] y) {
int n = x.Length;
var ret = new long[n];
for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod;
return ret;
}
public static long[][] add(long[][] A, long[][] B) {
int n = A.Length;
var ret = new long[n][];
for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]);
return ret;
}
public static long pow(long a, long b) {
if (a >= Mod) return pow(a % Mod, b);
if (a == 0) return 0;
if (b == 0) return 1;
var t = pow(a, b / 2);
if ((b & 1) == 0) return t * t % Mod;
return t * t % Mod * a % Mod;
}
public static long inv(long a) => pow(a, Mod - 2);
public static long gcd(long a, long b) {
while (b > 0) { var t = a % b; a = b; b = t; } return a;
}
// a x + b y = gcd(a, b)
public static long extgcd(long a, long b, out long x, out long y) {
long g = a; x = 1; y = 0;
if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; }
return g;
}
public static long lcm(long a, long b) => a / gcd(a, b) * b;
static long[] facts;
public static long[] setfacts(int n) {
facts = new long[n + 1];
facts[0] = 1;
for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod;
return facts;
}
public static long comb(int n, int r) {
if (n < 0 || r < 0 || r > n) return 0;
if (n - r < r) r = n - r;
if (r == 0) return 1;
if (r == 1) return n;
if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod;
int[] numer = new int[r], denom = new int[r];
for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; }
for (int p = 2; p <= r; p++) {
int piv = denom[p - 1];
if (piv > 1) {
int ofst = (n - r) % p;
for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; }
}
}
long ret = 1;
for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod;
return ret;
}
public static long[][] getcombs(int n) {
var ret = new long[n + 1][];
for (int i = 0; i <= n; i++) {
ret[i] = new long[i + 1];
ret[i][0] = ret[i][i] = 1;
for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod;
}
return ret;
}
// nC0, nC2, ..., nCn
public static long[] getcomb(int n) {
var ret = new long[n + 1];
ret[0] = 1;
for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod;
return ret;
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 4,277
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
// 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;
readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int N, M;
void solve() {
N = cin.nextint;
M = cin.nextint;
var A = new int [N][];
for (int i = 0; i < N; i++) {
A[i] = cin.scanint.Select(j => j - 1).ToArray();
}
int ans = int.MaxValue;
var H = new HashSet<int>();
for (int i = 0; i < M - 1; i++) {
var C = new int[M];
for (int j = 0; j < N; j++) {
for (int k = 0; k < M; k++) {
int d = A[j][k];
if (!H.Contains(d)) {
C[d]++;
break;
}
}
}
int idx = -1;
int max = 0;
// WriteLine(string.Join(" ", C));
for (int j = 0; j < M; j++) {
if (C[j] > max) {
max = C[j];
idx = j;
}
}
ans = Math.Min(max, ans);
H.Add(idx);
}
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 static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
// 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;
readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int N, M;
void solve() {
N = cin.nextint;
M = cin.nextint;
var A = new int [N][];
for (int i = 0; i < N; i++) {
A[i] = cin.scanint.Select(j => j - 1).ToArray();
}
int ans = int.MaxValue;
var H = new HashSet<int>();
for (int i = 0; i < M; i++) {
var C = new int[M];
for (int j = 0; j < N; j++) {
for (int k = 0; k < M; k++) {
int d = A[j][k];
if (!H.Contains(d)) {
C[d]++;
break;
}
}
}
int idx = -1;
int max = 0;
// WriteLine(string.Join(" ", C));
for (int j = 0; j < M; j++) {
if (C[j] > max) {
max = C[j];
idx = j;
}
}
ans = Math.Min(max, ans);
H.Add(idx);
}
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, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 614
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
class Program {
static void Main() { new Magatro().Solve(); }
}
class Magatro {
private int N, M;
private int[][] A;
private bool[] U;
private void Scan() {
var line = Console.ReadLine().Split(' ');
N = int.Parse(line[0]);
M = int.Parse(line[1]);
A = new int [N][];
for (int i = 0; i < N; i++) {
A[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
}
private int C(out int o) {
int[] a = new int[M + 1];
foreach (var i in A) {
foreach (int j in i) {
if (U[j]) {
a[j]++;
break;
}
}
}
int result = -1;
o = -1;
for (int i = 1; i <= M; i++) {
if (result < a[i]) {
result = a[i];
o = i;
}
}
return result;
}
public void Solve() {
Scan();
U = new bool[M + 1];
for (int i = 1; i <= M; i++) {
U[i] = true;
}
int ans = int.MaxValue;
for (int i = 0; i < M - 1; i++) {
int o;
ans = Math.Min(ans, C(out o));
U[o] = false;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
class Program {
static void Main() { new Magatro().Solve(); }
}
class Magatro {
private int N, M;
private int[][] A;
private bool[] U;
private void Scan() {
var line = Console.ReadLine().Split(' ');
N = int.Parse(line[0]);
M = int.Parse(line[1]);
A = new int [N][];
for (int i = 0; i < N; i++) {
A[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
}
private int C(out int o) {
int[] a = new int[M + 1];
foreach (var i in A) {
foreach (int j in i) {
if (U[j]) {
a[j]++;
break;
}
}
}
int result = -1;
o = -1;
for (int i = 1; i <= M; i++) {
if (result < a[i]) {
result = a[i];
o = i;
}
}
return result;
}
public void Solve() {
Scan();
U = new bool[M + 1];
for (int i = 1; i <= M; i++) {
U[i] = true;
}
int ans = int.MaxValue;
for (int i = 0; i < M; i++) {
int o;
ans = Math.Min(ans, C(out o));
U[o] = false;
}
Console.WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 401
| 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() {
Queue<int>[] Q = new Queue<int>[N];
for (int i = 0; i < N; i++) {
Q[i] = new Queue<int>();
for (int j = 0; j < M; j++)
Q[i].Enqueue(A[i][j]);
}
int min = M + 1;
HashSet<int> H = new HashSet<int>();
for (int i = 0; i < M; i++)
H.Add(i);
while (H.Count > 0) {
// for(int t=0;t<M;t++){
bool chk = true;
for (int i = 0; i < N; i++) {
while (Q[i].Count > 0 && !H.Contains(Q[i].Peek()))
Q[i].Dequeue();
if (Q[i].Count == 0)
chk = false;
}
if (!chk)
break;
int[] cnt = new int[M];
for (int i = 0; i < N; i++) {
var n = Q[i].Peek();
cnt[n]++;
}
int mx = 0;
for (int i = 0; i < M; i++)
mx = Math.Max(cnt[i], mx);
min = Math.Min(min, mx);
HashSet<int> hs = new HashSet<int>();
for (int j = 0; j < M; j++)
if (cnt[j] == mx)
hs.Add(j);
for (int i = 0; i < N; i++) {
if (hs.Contains(Q[i].Peek()))
Q[i].Dequeue();
}
for (int j = 0; j < M; j++) {
if (cnt[j] == mx)
H.Remove(j);
}
chk = true;
for (int i = 0; i < N; i++) {
while (Q[i].Count > 0 && !H.Contains(Q[i].Peek()))
Q[i].Dequeue();
if (Q[i].Count == 0)
chk = false;
}
if (!chk)
break;
// Console.WriteLine(String.Join(" ",H.ToArray()));
}
Console.WriteLine(min);
}
int N, M;
int[][] A;
public Sol() {
var d = ria();
N = d[0];
M = d[1];
A = new int [N][];
for (int i = 0; i < N; i++) {
A[i] = ria();
for (int j = 0; j < M; j++)
A[i][j]--;
}
}
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() {
Queue<int>[] Q = new Queue<int>[N];
for (int i = 0; i < N; i++) {
Q[i] = new Queue<int>();
for (int j = 0; j < M; j++)
Q[i].Enqueue(A[i][j]);
}
int min = N;
HashSet<int> H = new HashSet<int>();
for (int i = 0; i < M; i++)
H.Add(i);
while (H.Count > 0) {
// for(int t=0;t<M;t++){
bool chk = true;
for (int i = 0; i < N; i++) {
while (Q[i].Count > 0 && !H.Contains(Q[i].Peek()))
Q[i].Dequeue();
if (Q[i].Count == 0)
chk = false;
}
if (!chk)
break;
int[] cnt = new int[M];
for (int i = 0; i < N; i++) {
var n = Q[i].Peek();
cnt[n]++;
}
int mx = 0;
for (int i = 0; i < M; i++)
mx = Math.Max(cnt[i], mx);
min = Math.Min(min, mx);
HashSet<int> hs = new HashSet<int>();
for (int j = 0; j < M; j++)
if (cnt[j] == mx)
hs.Add(j);
for (int i = 0; i < N; i++) {
if (hs.Contains(Q[i].Peek()))
Q[i].Dequeue();
}
for (int j = 0; j < M; j++) {
if (cnt[j] == mx)
H.Remove(j);
}
chk = true;
for (int i = 0; i < N; i++) {
while (Q[i].Count > 0 && !H.Contains(Q[i].Peek()))
Q[i].Dequeue();
if (Q[i].Count == 0)
chk = false;
}
if (!chk)
break;
// Console.WriteLine(String.Join(" ",H.ToArray()));
}
Console.WriteLine(min);
}
int N, M;
int[][] A;
public Sol() {
var d = ria();
N = d[0];
M = d[1];
A = new int [N][];
for (int i = 0; i < N; i++) {
A[i] = ria();
for (int j = 0; j < M; j++)
A[i][j]--;
}
}
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, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
| 8
| 877
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var m = ri;
var k = ri;
var a = Enumerate(n + m + k, x => new long[] { rl, rl, rl })
.OrderBy(x => x[1] - x[2])
.ToArray();
var sum = a.Sum(x => x[0]);
var max = -INF;
var L = new long[n + m + k + 1];
{
var pq = new PriorityQueue<long>();
var u = 0L;
for (int i = 0; i < a.Length; i++) {
pq.Enqueue(a[i][2] - a[i][0]);
u += a[i][2] - a[i][0];
while (pq.Count > k) {
u -= pq.Dequeue();
}
L[i + 1] = u;
}
}
var R = new long[n + m + k + 1];
{
var pq = new PriorityQueue<long>();
var u = 0L;
for (int i = a.Length - 1; i >= 0; i--) {
pq.Enqueue(a[i][1] - a[i][0]);
u += a[i][1] - a[i][0];
while (pq.Count > m) {
u -= pq.Dequeue();
}
R[n + m + k - i] = u;
}
}
for (int i = 0; i < a.Length; i++) {
if (i >= m && n + m + k - i >= k)
max = Max(max, L[i] + R[n + m + k - i]);
}
Console.WriteLine(sum + max);
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < a.Length; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
/*
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
*/
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N) で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
namespace Program {
public class Solver {
Random rnd = new Random();
public void Solve() {
var n = ri;
var m = ri;
var k = ri;
var a = Enumerate(n + m + k, x => new long[] { rl, rl, rl })
.OrderBy(x => x[1] - x[2])
.ToArray();
var sum = a.Sum(x => x[0]);
var max = -INF;
var L = new long[n + m + k + 1];
{
var pq = new PriorityQueue<long>();
var u = 0L;
for (int i = 0; i < a.Length; i++) {
pq.Enqueue(a[i][2] - a[i][0]);
u += a[i][2] - a[i][0];
while (pq.Count > k) {
u -= pq.Dequeue();
}
L[i + 1] = u;
}
}
var R = new long[n + m + k + 1];
{
var pq = new PriorityQueue<long>();
var u = 0L;
for (int i = a.Length - 1; i >= 0; i--) {
pq.Enqueue(a[i][1] - a[i][0]);
u += a[i][1] - a[i][0];
while (pq.Count > m) {
u -= pq.Dequeue();
}
R[n + m + k - i] = u;
}
}
for (int i = 0; i < a.Length; i++) {
if (i >= k && n + m + k - i >= m)
max = Max(max, L[i] + R[n + m + k - i]);
}
Console.WriteLine(sum + max);
}
const long INF = 1L << 60;
static int[] dx = { -1, 0, 1, 0 };
static int[] dy = { 0, 1, 0, -1 };
int ri {
get { return sc.Integer(); }
}
long rl {
get { return sc.Long(); }
}
double rd {
get { return sc.Double(); }
}
string rs {
get { return sc.Scan(); }
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < a.Length; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
static public string AsString(this IEnumerable<char> ie) {
return new string(ie.ToArray());
}
static public string AsJoinedString<T>(this IEnumerable<T> ie,
string st = " ") {
return string.Join(st, ie);
}
static public void Main() {
Console.SetOut(new Program.IO.Printer(
Console.OpenStandardOutput()) { AutoFlush = true });
var solver = new Program.Solver();
/*
var t = new System.Threading.Thread(solver.Solve, 50000000);
t.Start();
t.Join();
*/
solver.Solve();
Console.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n' && b != 0; b = (char)read())
if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
public double Double() {
return isEof ? double.NaN
: double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
}
#endregion
#region PriorityQueue
/// <summary>
/// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します.
/// </summary>
/// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam>
/// <remarks>内部的にはバイナリヒープによって実装されています.</remarks>
public class PriorityQueue<T> {
readonly List<T> heap = new List<T>();
readonly Comparison<T> cmp;
/// <summary>
/// デフォルトの比較子を使用してインスタンスを初期化します.
/// </summary>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue() { cmp = Comparer<T>.Default.Compare; }
/// <summary>
/// デリゲートで表されるような比較関数を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparison"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(Comparison<T> comparison) { cmp = comparison; }
/// <summary>
/// 指定された比較子を使用してインスタンスを初期化します.
/// </summary>
/// <param name="comparer"></param>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; }
/// <summary>
/// 優先度付きキューに要素を追加します.
/// </summary>
/// <param name="item">優先度付きキューに追加される要素</param>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public void Enqueue(T item) {
var pos = heap.Count;
heap.Add(item);
while (pos > 0) {
var par = (pos - 1) / 2;
if (cmp(heap[par], item) <= 0)
break;
heap[pos] = heap[par];
pos = par;
}
heap[pos] = item;
}
/// <summary>
/// 優先度付きキューから最も価値が低い要素を削除し,返します.
/// </summary>
/// <returns>優先度付きキューから削除された要素.</returns>
/// <remarks>最悪計算量 O(log N) で実行されます.</remarks>
public T Dequeue() {
var ret = heap[0];
var pos = 0;
var x = heap[heap.Count - 1];
while (pos * 2 + 1 < heap.Count - 1) {
var lch = pos * 2 + 1;
var rch = pos * 2 + 2;
if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0)
lch = rch;
if (cmp(heap[lch], x) >= 0)
break;
heap[pos] = heap[lch];
pos = lch;
}
heap[pos] = x;
heap.RemoveAt(heap.Count - 1);
return ret;
}
/// <summary>
/// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します.
/// </summary>
/// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns>
/// <remarks>この操作は O(1) で実行されます.</remarks>
public T Peek() { return heap[0]; }
/// <summary>
/// 優先度付きキュー内の要素の数を取得します.
/// </summary>
/// <returns>優先度付キュー内にある要素の数</returns>
/// <remarks>最悪計算量 O(1) で実行されます.</remarks>
public int Count {
get { return heap.Count; }
}
/// <summary>
/// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します.
/// </summary>
/// <returns>優先度付キュー内にある要素が存在するならば
/// true,そうでなければ false.</returns> <remarks>この操作は O(1)
/// で実行されます.</remarks>
public bool Any() { return heap.Count > 0; }
/// <summary>
/// 優先度付きキューに含まれる要素を昇順に並べて返します.
/// </summary>
/// <remarks>この操作は計算量 O(N log N) で実行されます.</remarks>
public T[] Items {
get {
var ret = heap.ToArray();
Array.Sort(ret, cmp);
return ret;
}
}
}
#endregion
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 1,643
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split();
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
Console.WriteLine("Impossible");
} else {
Console.WriteLine("Possible");
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split();
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Impossible");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 118
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;
public class A {
public static void Main() {
int A = GetInt();
int B = GetInt();
Console.WriteLine((A % 3 == 0) || (B % 3 == 0) || ((A + B) % 3 == 0)
? "POSSIBLE"
: "IMPOSSIBLE");
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;
public class A {
public static void Main() {
int A = GetInt();
int B = GetInt();
Console.WriteLine((A % 3 == 0) || (B % 3 == 0) || ((A + B) % 3 == 0)
? "Possible"
: "Impossible");
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
[["-", 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
| 238
| 4
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int n = 100;
/*
long n = long.Parse(Console.ReadLine());
long[] input = new long[5];
for(int a = 0; a < 5; a++)
{
input[a]=long.Parse(Console.ReadLine());
}
*/
int[] input =
Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
Console.WriteLine(input[0] % 3 == 0 || input[1] % 3 == 0 ||
input[2] % 3 == 0
? "Possible"
: "Impossible");
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program {
static void Main() {
//入力
// int n = 100;
/*
long n = long.Parse(Console.ReadLine());
long[] input = new long[5];
for(int a = 0; a < 5; a++)
{
input[a]=long.Parse(Console.ReadLine());
}
*/
int[] input =
Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
Console.WriteLine(input[0] % 3 == 0 || input[1] % 3 == 0 ||
(input.Sum()) % 3 == 0
? "Possible"
: "Impossible");
/*
//処理速度計測
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
//解法
//処理速度表示
sw.Stop();
TimeSpan ts = sw.Elapsed;
Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
*/
Console.ReadLine();
}
}
|
[["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["-", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 16, 31, 23, 0, 213, 63, 214, 0, 131], ["+", 31, 16, 31, 23, 0, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 23, 0, 213, 3, 4, 0, 24], ["+", 31, 16, 31, 23, 0, 213, 3, 4, 0, 25], ["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 25]]
| 8
| 118
| 9
|
using System;
class Program {
static void Main(string[] args) {
var ab = Console.ReadLine().Split(' ');
var a = int.Parse(ab[0]);
var b = int.Parse(ab[1]);
if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Imossible");
}
}
}
|
using System;
class Program {
static void Main(string[] args) {
var ab = Console.ReadLine().Split(' ');
var a = int.Parse(ab[0]);
var b = int.Parse(ab[1]);
if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Impossible");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 107
| 2
|
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace AtCoder {
public class Program {
static int[] getKeys() {
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 int[] getKeys(char delimiter) {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Keys[i]);
}
return Ns;
}
public 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("-------------------------");
}
public 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("-------------------------");
}
public static void Show<T>(IEnumerable<T> ts) {
foreach (var item in ts) {
Console.Write(item + " ");
}
Console.WriteLine();
}
public static void Show<T>(IEnumerable<T> ts, string delimiter) {
foreach (var item in ts) {
Console.Write(item + delimiter);
}
Console.WriteLine();
}
public static void ShowDictionary<T1, T2>(Dictionary<T1, T2> dictionary) {
foreach (var item in dictionary) {
Console.WriteLine(item);
}
}
static T[] getUniform<T>(int length, T value) {
T[] Ts = new T[length];
for (int i = 0; i < length; i++) {
Ts[i] = value;
}
return Ts;
}
static void setUniform<T>(T[] ts, T value) {
int length = ts.Length;
for (int i = 0; i < length; i++) {
ts[i] = value;
}
}
static T[,] getUniform<T>(int row, int col, T value) {
T[,] Ts = new T[row, col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
Ts[j, i] = value;
}
}
return Ts;
}
static void setUniform<T>(T[,] ts, T value) {
int N = ts.GetLength(0);
int M = ts.GetLength(1);
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
ts[j, i] = value;
}
}
}
static void Main() {
var Key = getKeys();
if (Key[0] % 3 != 0 || Key[1] % 3 != 0 || Key.Sum() % 3 != 0) {
Console.WriteLine("Impossible");
} else {
Console.WriteLine("Possible");
}
}
}
}
|
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace AtCoder {
public class Program {
static int[] getKeys() {
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 int[] getKeys(char delimiter) {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Keys[i]);
}
return Ns;
}
public 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("-------------------------");
}
public 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("-------------------------");
}
public static void Show<T>(IEnumerable<T> ts) {
foreach (var item in ts) {
Console.Write(item + " ");
}
Console.WriteLine();
}
public static void Show<T>(IEnumerable<T> ts, string delimiter) {
foreach (var item in ts) {
Console.Write(item + delimiter);
}
Console.WriteLine();
}
public static void ShowDictionary<T1, T2>(Dictionary<T1, T2> dictionary) {
foreach (var item in dictionary) {
Console.WriteLine(item);
}
}
static T[] getUniform<T>(int length, T value) {
T[] Ts = new T[length];
for (int i = 0; i < length; i++) {
Ts[i] = value;
}
return Ts;
}
static void setUniform<T>(T[] ts, T value) {
int length = ts.Length;
for (int i = 0; i < length; i++) {
ts[i] = value;
}
}
static T[,] getUniform<T>(int row, int col, T value) {
T[,] Ts = new T[row, col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
Ts[j, i] = value;
}
}
return Ts;
}
static void setUniform<T>(T[,] ts, T value) {
int N = ts.GetLength(0);
int M = ts.GetLength(1);
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
ts[j, i] = value;
}
}
}
static void Main() {
var Key = getKeys();
if (Key[0] % 3 != 0 && Key[1] % 3 != 0 && Key.Sum() % 3 != 0) {
Console.WriteLine("Impossible");
} else {
Console.WriteLine("Possible");
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 852
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4 {
class Program {
static void Main(string[] args) {
// スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int b = int.Parse(input[0]);
int c = int.Parse(input[1]);
if (b % 3 == 0 || b % 3 == 0 || (b + c) % 3 == 0) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Impossible");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4 {
class Program {
static void Main(string[] args) {
// スペース区切りの整数の入力
string[] input = Console.ReadLine().Split(' ');
int b = int.Parse(input[0]);
int c = int.Parse(input[1]);
if (b % 3 == 0 || c % 3 == 0 || (b + c) % 3 == 0) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Impossible");
}
}
}
}
|
[["-", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22]]
| 8
| 138
| 2
|
using System;
using System.IO;
class Program {
static void Main(string[] args) {
string[] input = System.Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
if (a % 3 == 0 || b % 3 == 0 || (a * b) % 3 == 0) {
System.Console.WriteLine("Possible");
} else {
System.Console.WriteLine("Impossible");
}
}
}
|
using System;
using System.IO;
class Program {
static void Main(string[] args) {
string[] input = System.Console.ReadLine().Split(' ');
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
System.Console.WriteLine("Possible");
} else {
System.Console.WriteLine("Impossible");
}
}
}
|
[["-", 12, 16, 31, 16, 31, 23, 0, 16, 17, 48], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 17, 72]]
| 8
| 120
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
class Program {
public static void Main() {
var input = Console.ReadLine().Split();
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
var input2 = Console.ReadLine().Split();
var l = new int[n];
for (int i = 0; i < n; i++) {
l[i] = int.Parse(input[i]);
}
Array.Sort(l);
int ans = 0;
for (int i = n - 1; i > 0; i--) {
ans += l[i];
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
class Program {
public static void Main() {
var input = Console.ReadLine().Split();
int n = int.Parse(input[0]);
int k = int.Parse(input[1]);
var input2 = Console.ReadLine().Split();
var l = new int[n];
for (int i = 0; i < n; i++) {
l[i] = int.Parse(input2[i]);
}
Array.Sort(l);
int ans = 0;
for (int i = n - 1; i >= n - k; i--) {
ans += l[i];
}
Console.WriteLine(ans);
}
}
|
[["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22]]
| 8
| 169
| 8
|
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace AtCoder {
public class Program {
static int[] getKeys() {
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 int[] getKeys(char delimiter) {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Keys[i]);
}
return Ns;
}
public 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("-------------------------");
}
public 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("-------------------------");
}
public static void Show<T>(IEnumerable<T> ts) {
foreach (var item in ts) {
Console.Write(item + " ");
}
Console.WriteLine();
}
public static void Show<T>(IEnumerable<T> ts, string delimiter) {
foreach (var item in ts) {
Console.Write(item + delimiter);
}
Console.WriteLine();
}
public static void ShowDictionary<T1, T2>(Dictionary<T1, T2> dictionary) {
foreach (var item in dictionary) {
Console.WriteLine(item);
}
}
static T[] getUniform<T>(int length, T value) {
T[] Ts = new T[length];
for (int i = 0; i < length; i++) {
Ts[i] = value;
}
return Ts;
}
static void setUniform<T>(T[] ts, T value) {
int length = ts.Length;
for (int i = 0; i < length; i++) {
ts[i] = value;
}
}
static T[,] getUniform<T>(int row, int col, T value) {
T[,] Ts = new T[row, col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
Ts[j, i] = value;
}
}
return Ts;
}
static void setUniform<T>(T[,] ts, T value) {
int N = ts.GetLength(0);
int M = ts.GetLength(1);
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
ts[j, i] = value;
}
}
}
static void Main() {
var Key = getKeys();
int N = Key[0];
int K = Key[1];
Array.Sort(Key);
int answer = 0;
for (int i = 0; i < K; i++) {
answer += Key[N - 1 - i];
}
Console.WriteLine(answer);
}
}
}
|
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace AtCoder {
public class Program {
static int[] getKeys() {
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 int[] getKeys(char delimiter) {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Keys[i]);
}
return Ns;
}
public 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("-------------------------");
}
public 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("-------------------------");
}
public static void Show<T>(IEnumerable<T> ts) {
foreach (var item in ts) {
Console.Write(item + " ");
}
Console.WriteLine();
}
public static void Show<T>(IEnumerable<T> ts, string delimiter) {
foreach (var item in ts) {
Console.Write(item + delimiter);
}
Console.WriteLine();
}
public static void ShowDictionary<T1, T2>(Dictionary<T1, T2> dictionary) {
foreach (var item in dictionary) {
Console.WriteLine(item);
}
}
static T[] getUniform<T>(int length, T value) {
T[] Ts = new T[length];
for (int i = 0; i < length; i++) {
Ts[i] = value;
}
return Ts;
}
static void setUniform<T>(T[] ts, T value) {
int length = ts.Length;
for (int i = 0; i < length; i++) {
ts[i] = value;
}
}
static T[,] getUniform<T>(int row, int col, T value) {
T[,] Ts = new T[row, col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
Ts[j, i] = value;
}
}
return Ts;
}
static void setUniform<T>(T[,] ts, T value) {
int N = ts.GetLength(0);
int M = ts.GetLength(1);
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
ts[j, i] = value;
}
}
}
static void Main() {
var Key = getKeys();
int N = Key[0];
int K = Key[1];
Key = getKeys();
Array.Sort(Key);
int answer = 0;
for (int i = 0; i < K; i++) {
answer += Key[N - 1 - i];
}
Console.WriteLine(answer);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 861
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication32 {
class Program {
static void Main(string[] args) {
int[] a = new int[2];
a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] b = new int[a[0]];
b = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(b);
Array.Reverse(b);
int ans = 0;
for (int c = 0; c < a[1]; c++)
ans += b[0];
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication32 {
class Program {
static void Main(string[] args) {
int[] a = new int[2];
a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] b = new int[a[0]];
b = Console.ReadLine().Split().Select(int.Parse).ToArray();
Array.Sort(b);
Array.Reverse(b);
int ans = 0;
for (int c = 0; c < a[1]; c++)
ans += b[c];
Console.WriteLine(ans);
}
}
}
|
[["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 160
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var S = sc.ReadStr();
var ans = 0;
for (int i = 2; i < S.Length; i += 2) {
var len = (S.Length - i) / 2;
var s = S.Substring(0, len);
var t = S.Substring(len, len);
if (s == t)
ans = len * 2;
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var S = sc.ReadStr();
var ans = 0;
for (int i = 2; i < S.Length; i += 2) {
var len = (S.Length - i) / 2;
var s = S.Substring(0, len);
var t = S.Substring(len, len);
if (s == t) {
ans = len * 2;
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(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,139
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp69 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
int len = S.Length;
for (int i = 2; i <= len / 2; i += 2) {
// Console.WriteLine(S.Substring(0, len - i));
if (CheckGuumoji(S.Substring(0, len - i))) {
Console.WriteLine(len - i);
return;
}
}
}
static bool CheckGuumoji(string s) {
int length = s.Length;
for (int i = 0; i < length / 2; i++) {
if (s[i] != s[i + (length / 2)]) {
return false;
}
}
return true;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp69 {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
int len = S.Length;
for (int i = 2; i < len; i += 2) {
// Console.WriteLine(S.Substring(0, len - i));
if (CheckGuumoji(S.Substring(0, len - i))) {
Console.WriteLine(len - i);
return;
}
}
}
static bool CheckGuumoji(string s) {
int length = s.Length;
for (int i = 0; i < length / 2; i++) {
if (s[i] != s[i + (length / 2)]) {
return false;
}
}
return true;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 85], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 171
| 4
|
using System;
namespace B___ss {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
var count = 1;
var str = "";
for (var i = s.Length - 1; i > 1; i--) {
str = s.Remove(i, count);
if (str.Length % 2 == 0 &&
str.Substring(0, str.Length / 2) ==
str.Substring(str.Length / 2, str.Length / 2))
Console.WriteLine(str.Length);
count++;
}
}
}
}
|
using System;
namespace B___ss {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
var count = 1;
var str = "";
for (var i = s.Length - 1; i > 0; i--) {
str = s.Remove(i, count);
if (str.Length % 2 == 0 &&
str.Substring(0, str.Length / 2) ==
str.Substring(str.Length / 2, str.Length / 2)) {
Console.WriteLine(str.Length);
break;
}
count++;
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 125
| 6
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace program {
class Program {
static void Main() {
var s = Input.ScanStr();
for (int i = s.Length / 2; i >= 0; i--)
if (s.Substring(0, i) == s.Substring(i, i)) {
Out(i);
return;
}
}
static public void Out(object s) { Console.WriteLine(s); }
}
static class Input {
static public int ScanInt() { return int.Parse(Console.ReadLine()); }
static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
static public long ScanLong() { return long.Parse(Console.ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
static public int[] ScanIntArray() {
return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return Console.ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
}
static class MyMath {
public static int DistanceL1(int[] a, int[] b) {
if (a.Length != b.Length)
return -1;
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++)
c[i] = Math.Abs(a[i] - b[i]);
return c.Sum();
}
public static double DistanceL2(int[] a, int[] b) {
if (a.Length != b.Length)
return -1;
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++)
c[i] = (a[i] - b[i]) * (a[i] - b[i]);
return Math.Sqrt(c.Sum());
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong GCD(ulong a, ulong b) {
Func<ulong, ulong, ulong> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); }
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace program {
class Program {
static void Main() {
var s = Input.ScanStr();
for (int i = s.Length / 2 - 1; i >= 0; i--)
if (s.Substring(0, i) == s.Substring(i, i)) {
Out(i * 2);
return;
}
}
static public void Out(object s) { Console.WriteLine(s); }
}
static class Input {
static public int ScanInt() { return int.Parse(Console.ReadLine()); }
static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
static public long ScanLong() { return long.Parse(Console.ReadLine()); }
static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
static public int[] ScanIntArray() {
return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
}
static public uint[] ScanUintArray() {
return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray();
}
static public double[] ScanDoubleArray() {
return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray();
}
static public long[] ScanLongArray() {
return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
}
static public ulong[] ScanUlongArray() {
return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
}
static public string ScanStr() { return Console.ReadLine(); }
static public string[] ScanStrArray() { return ScanStr().Split(); }
}
static class MyMath {
public static int DistanceL1(int[] a, int[] b) {
if (a.Length != b.Length)
return -1;
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++)
c[i] = Math.Abs(a[i] - b[i]);
return c.Sum();
}
public static double DistanceL2(int[] a, int[] b) {
if (a.Length != b.Length)
return -1;
int[] c = new int[a.Length];
for (int i = 0; i < a.Length; i++)
c[i] = (a[i] - b[i]) * (a[i] - b[i]);
return Math.Sqrt(c.Sum());
}
public static int GCD(int a, int b) {
Func<int, int, int> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static ulong GCD(ulong a, ulong b) {
Func<ulong, ulong, ulong> gcd = null;
gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
return a > b ? gcd(a, b) : gcd(b, a);
}
public static int LCM(int a, int b) { return a * b / GCD(a, b); }
public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); }
}
}
|
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 804
| 4
|
using static System.Console;
class Program {
static void Main(string[] args) {
var str = ReadLine();
for (var i = 0; i <= str.Length / 2; i++) {
str = str.Substring(0, str.Length - 2);
var s = str.Substring(0, str.Length / 2);
if (s + s == str) {
WriteLine(str.Length);
break;
}
}
}
}
|
using static System.Console;
class Program {
static void Main(string[] args) {
var str = ReadLine();
for (var i = 0; i <= int.MaxValue; i++) {
str = str.Substring(0, str.Length - 2);
var s = str.Substring(0, str.Length / 2);
if (s + s == str) {
WriteLine(str.Length);
break;
}
}
}
}
|
[["-", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 199], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 141, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 85], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22]]
| 8
| 98
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC066B {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
int l = S.Length;
if (l % 2 == 0)
l -= 2;
else
l--;
for (; l > 0; l -= 2) {
string s = S.Substring(0, l);
string t = s.Substring(0, l / 2);
string u = s.Substring(l / 2, l / 2);
if (t == u) {
Console.WriteLine(l);
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC066B {
class Program {
static void Main(string[] args) {
string S = Console.ReadLine();
int l = S.Length;
if (l % 2 == 0)
l -= 2;
else
l--;
for (; l > 0; l -= 2) {
string s = S.Substring(0, l);
string t = s.Substring(0, l / 2);
string u = s.Substring(l / 2, l / 2);
if (t == u) {
Console.WriteLine(l);
break;
}
}
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35]]
| 8
| 148
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
var a = Reads();
var b = new long[(long)Math.Pow(10, 9)];
long left = (long)Math.Pow(10, 8) * 5;
long right = (long)Math.Pow(10, 8) * 5 + 1;
for (int i = 0; i < n; i++) {
if (n % 2 == (i + 1) % 2) {
b[left] = a[i];
left--;
} else {
b[right] = a[i];
right++;
}
}
for (long i = left + 1; i < right; i++) {
Console.Write("{0} ", b[i]);
}
Console.WriteLine();
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var n = Read();
var a = Reads();
var b = new long[(long)Math.Pow(10, 7)];
long left = (long)Math.Pow(10, 6) * 5;
long right = (long)Math.Pow(10, 6) * 5 + 1;
for (int i = 0; i < n; i++) {
if (n % 2 == (i + 1) % 2) {
b[left] = a[i];
left--;
} else {
b[right] = a[i];
right++;
}
}
for (long i = left + 1; i < right; i++) {
Console.Write("{0} ", b[i]);
}
Console.WriteLine();
Console.Out.Flush();
}
}
}
|
[["-", 0, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["-", 31, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["+", 31, 74, 51, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 292
| 6
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
//入力を受け取る
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var ans = new long[N];
if (N % 2 == 0) {
for (int i = 0; i < N; i++) {
if (i % 2 == 0) {
ans[N / 2 + i / 2] = A[i];
} else {
ans[N / 2 - 1 - i / 2] = A[i];
}
}
} else {
for (int i = 0; i < N; i++) {
if (i % 2 == 0) {
ans[N / 2 - i / 2] = A[i];
} else {
ans[N / 2 + i / 2 + 1] = A[i];
}
}
}
Console.WriteLine(String.Join("", ans));
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
class Program {
static void Main(string[] args) {
//入力を受け取る
var N = int.Parse(Console.ReadLine());
var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
var ans = new long[N];
if (N % 2 == 0) {
for (int i = 0; i < N; i++) {
if (i % 2 == 0) {
ans[N / 2 + i / 2] = A[i];
} else {
ans[N / 2 - 1 - i / 2] = A[i];
}
}
} else {
for (int i = 0; i < N; i++) {
if (i % 2 == 0) {
ans[N / 2 - i / 2] = A[i];
} else {
ans[N / 2 + i / 2 + 1] = A[i];
}
}
}
Console.WriteLine(String.Join(" ", ans));
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 254
| 1
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
static void Main(string[] args) {
try {
SetOut(sw);
Solve.Answer();
Out.Flush();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var n = IO.RInt;
var a = IO.RSInt;
var b = new int[n];
if (n % 2 == 0) {
for (int i = 0; i < n / 2; i++) {
b[i] = a[(n - 1) - 2 * i];
}
for (int i = 0; i < n / 2; i++) {
b[i + n / 2] = a[2 * i];
}
IO.OutJoinSpace(b);
} else {
for (int i = 0; i < n / 2 + 1; i++) {
b[i] = a[(n - 1) - 2 * i];
}
for (int i = 0; i < n / 2; i++) {
b[i + n / 2] = a[1 + 2 * i];
}
IO.OutJoinSpace(b);
}
}
}
public class IO {
#region Input
public static int RInt => int.Parse(ReadLine());
public static long RLong => long.Parse(ReadLine());
public static double RDouble => double.Parse(ReadLine());
public static string[] RSString => ReadLine().Split();
public static int[] RSInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToArray();
public static long[] RSLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToArray();
public static double[] RSDouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToArray();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES"
: "NO");
#endregion
}
public class Mod {
#region
private readonly static long M = 1000000007;
public static long Add(long a, long b) => (a * b) % M;
public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M
: (a - b) % M + M;
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;
namespace Atcoder {
class Program {
static StreamWriter sw =
new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
static void Main(string[] args) {
try {
SetOut(sw);
Solve.Answer();
Out.Flush();
} catch (Exception ex) {
WriteLine(ex.ToString());
}
}
}
public class Solve {
public static void Answer() {
var n = IO.RInt;
var a = IO.RSInt;
var b = new int[n];
if (n % 2 == 0) {
for (int i = 0; i < n / 2; i++) {
b[i] = a[(n - 1) - 2 * i];
}
for (int i = 0; i < n / 2; i++) {
b[i + n / 2] = a[2 * i];
}
IO.OutJoinSpace(b);
} else {
for (int i = 0; i < n / 2 + 1; i++) {
b[i] = a[(n - 1) - 2 * i];
}
for (int i = 0; i < n / 2; i++) {
b[i + n / 2 + 1] = a[1 + 2 * i];
}
IO.OutJoinSpace(b);
}
}
}
public class IO {
#region Input
public static int RInt => int.Parse(ReadLine());
public static long RLong => long.Parse(ReadLine());
public static double RDouble => double.Parse(ReadLine());
public static string[] RSString => ReadLine().Split();
public static int[] RSInt =>
ReadLine().Split().Select(s => int.Parse(s)).ToArray();
public static long[] RSLong =>
ReadLine().Split().Select(s => long.Parse(s)).ToArray();
public static double[] RSDouble =>
ReadLine().Split().Select(s => double.Parse(s)).ToArray();
#endregion
#region Output
public static void
OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes"
: "No");
public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES"
: "NO");
#endregion
}
public class Mod {
#region
private readonly static long M = 1000000007;
public static long Add(long a, long b) => (a * b) % M;
public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M
: (a - b) % M + M;
public static long Multi(long a, long b) => (a * b) % M;
#endregion
}
}
|
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 658
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main(string[] args) {
var i = int.Parse(ReadLine());
var ast = ReadLine().Split();
var a = new int[i];
for (var j = 0; j < i; j++) {
a[j] = int.Parse(ast[j]);
}
// var b = new List<int>();
for (var j = a.Length - 1; j > 0;) {
// b.Add(a[j]);
Write(a[j] + " ");
j -= 2;
}
for (var j = 0; j < a.Length - 2;) {
// b.Add(a[j]);
Write(a[j] + " ");
if (j == 0 && a.Length % 2 == 1) {
j++;
Write(a[j] + " ");
}
j += 2;
}
if (i != 1 && i != 3)
WriteLine(a[a.Length - 2]);
if (i == 1)
WriteLine(1);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
class Program {
static void Main(string[] args) {
var i = int.Parse(ReadLine());
var ast = ReadLine().Split();
var a = new int[i];
for (var j = 0; j < i; j++) {
a[j] = int.Parse(ast[j]);
}
// var b = new List<int>();
for (var j = a.Length - 1; j > 0;) {
// b.Add(a[j]);
Write(a[j] + " ");
j -= 2;
}
for (var j = 0; j < a.Length - 2;) {
// b.Add(a[j]);
Write(a[j] + " ");
if (j == 0 && a.Length % 2 == 1) {
j++;
Write(a[j] + " ");
}
j += 2;
}
if (i != 1 && i != 3)
WriteLine(a[a.Length - 2]);
if (i == 1)
WriteLine(a[0]);
}
}
|
[["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
| 8
| 234
| 5
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
#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 n = ReadLib.ReadAsInt();
var arr = ReadLib.ReadAsIntArray();
var oddList = new List<int>();
var evenList = new List<int>();
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
evenList.Add(arr[i]);
} else {
oddList.Add(arr[i]);
}
}
string msg;
if (n % 2 == 0) {
evenList.Reverse();
msg = string.Join(" ", evenList.Concat(oddList));
} else {
oddList.Reverse();
msg = string.Join(" ", oddList.Concat(evenList));
}
Console.WriteLine(msg);
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class Quick {
internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); }
private static void QuickSort(int[] ts, int p, int r) {
if (p < r) {
var q = Partition(ts, p, r);
QuickSort(ts, p, q - 1);
QuickSort(ts, q + 1, r);
}
}
public static int Partition(int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
}
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 WriteLib {
public static void Write<T>(IEnumerable<T> ts) {
ts.ToList().ForEach(s => Console.WriteLine(s));
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
public static ModCombination ModCombination(int maxN, int mod = 1000000007) {
return new ModCombination(maxN, mod);
}
/// <summary>a^n mod</summary>
public static int ModPow(int a, int n, int mod = 1000000007) {
var res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける
}
a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2
n >>= 1;
}
return res;
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>無向グラフ</summary>
class UndirectedGraph {
public Dictionary<int, List<int>> Graph { get; }
/// <param name="graphArr">point1 to point2</param>
/// <param name="n">グラフの全要素数</param>
public UndirectedGraph(int[][] graphArr, int n) {
Graph = new Dictionary<int, List<int>>();
for (int i = 1; i <= n; i++) {
Graph.Add(i, new List<int>());
}
foreach (var arr in graphArr) {
Graph[arr[0]].Add(arr[1]);
Graph[arr[1]].Add(arr[0]);
}
}
}
/// <summary>DeepCopyするクラス</summary>
class DeepCopier {
BinaryFormatter b = new BinaryFormatter();
public T DeepCopy<T>(T obj) {
T result;
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
static class MergeSort {
public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); }
// rightは+1されていることに注意
private static long[] Merge(long[] sArr, int left, int mid, int right) {
var n1 = mid - left;
var n2 = right - mid;
var lArr = new long[n1 + 1];
var rArr = new long[n2 + 1];
for (int i = 0; i < n1; i++) {
lArr[i] = sArr[left + i];
}
lArr[n1] = int.MaxValue;
for (int i = 0; i < n2; i++) {
rArr[i] = sArr[mid + i];
}
rArr[n2] = int.MaxValue;
int l = 0, r = 0;
for (int k = left; k < right; k++) {
if (lArr[l] <= rArr[r]) {
sArr[k] = lArr[l];
l++;
} else {
sArr[k] = rArr[r];
r++;
}
}
return sArr; // 要素数はright - left
}
private static long[] Sort(long[] sArr, int left, int right) {
if (left + 1 < right) {
var mid = (left + right) / 2;
sArr = Sort(sArr, left, mid);
sArr = Sort(sArr, mid, right);
sArr = Merge(sArr, left, mid, right);
}
return sArr;
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator -(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value - item2.Value;
if (value < 0) {
value += item1.Mod;
}
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
return item1 + new ModInt(item2, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
return item1 * new ModInt(item2, item1.Mod);
}
public static ModInt operator -(ModInt item1, int item2) {
return item1 - new ModInt(item2, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
/// <summary>組み合わせ</summary>
class ModCombination {
private int mod;
private int[] fac;
private int[] finv;
private int[] inv;
public ModCombination(int max, int mod = 1000000007) {
this.mod = mod;
fac = new int[max]; // modが法のn!の列
inv = new int[max]; // indexの逆元の列
finv = new int[max]; // modを法とした、invの累積の累積
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める
var s = Math.BigMul(inv[mod % i], mod / i) % mod;
inv[i] = (int)(mod - s);
// iに対する逆元を求める
finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod);
}
}
/// <summary>nCk</summary>
public int Calculation(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (int)(Math.BigMul(fac[n],
(int)(Math.BigMul(finv[k], finv[n - k]) % mod)) %
mod);
}
}
/// <summary>拡張メソッドs</summary>
static class Extention {
/// <summary>iとjを入れ替える</summary>
public static void Swap<T>(this T[] arr, int i, int j) {
var buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
}
/// <summary>
/// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。
/// </summary>
/// <param name="sArr"></param>
/// <param name="p">partitionの先頭の添字</param>
/// <param name="r">partitionの末尾の添字</param>
/// <returns>partitionの基準が存在する添字</returns>
public static int Partition(this int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
/// <summary>深いコピーをする</summary>
public static T DeepCopy<T>(this T obj) {
T result;
var b = new BinaryFormatter();
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
#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 n = ReadLib.ReadAsInt();
var arr = ReadLib.ReadAsIntArray();
var oddList = new List<int>();
var evenList = new List<int>();
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
evenList.Add(arr[i]);
} else {
oddList.Add(arr[i]);
}
}
string msg;
if (n % 2 == 1) {
evenList.Reverse();
msg = string.Join(" ", evenList.Concat(oddList));
} else {
oddList.Reverse();
msg = string.Join(" ", oddList.Concat(evenList));
}
Console.WriteLine(msg);
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
static class Quick {
internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); }
private static void QuickSort(int[] ts, int p, int r) {
if (p < r) {
var q = Partition(ts, p, r);
QuickSort(ts, p, q - 1);
QuickSort(ts, q + 1, r);
}
}
public static int Partition(int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
}
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 WriteLib {
public static void Write<T>(IEnumerable<T> ts) {
ts.ToList().ForEach(s => Console.WriteLine(s));
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
public static ModCombination ModCombination(int maxN, int mod = 1000000007) {
return new ModCombination(maxN, mod);
}
/// <summary>a^n mod</summary>
public static int ModPow(int a, int n, int mod = 1000000007) {
var res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける
}
a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2
n >>= 1;
}
return res;
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>無向グラフ</summary>
class UndirectedGraph {
public Dictionary<int, List<int>> Graph { get; }
/// <param name="graphArr">point1 to point2</param>
/// <param name="n">グラフの全要素数</param>
public UndirectedGraph(int[][] graphArr, int n) {
Graph = new Dictionary<int, List<int>>();
for (int i = 1; i <= n; i++) {
Graph.Add(i, new List<int>());
}
foreach (var arr in graphArr) {
Graph[arr[0]].Add(arr[1]);
Graph[arr[1]].Add(arr[0]);
}
}
}
/// <summary>DeepCopyするクラス</summary>
class DeepCopier {
BinaryFormatter b = new BinaryFormatter();
public T DeepCopy<T>(T obj) {
T result;
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
static class MergeSort {
public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); }
// rightは+1されていることに注意
private static long[] Merge(long[] sArr, int left, int mid, int right) {
var n1 = mid - left;
var n2 = right - mid;
var lArr = new long[n1 + 1];
var rArr = new long[n2 + 1];
for (int i = 0; i < n1; i++) {
lArr[i] = sArr[left + i];
}
lArr[n1] = int.MaxValue;
for (int i = 0; i < n2; i++) {
rArr[i] = sArr[mid + i];
}
rArr[n2] = int.MaxValue;
int l = 0, r = 0;
for (int k = left; k < right; k++) {
if (lArr[l] <= rArr[r]) {
sArr[k] = lArr[l];
l++;
} else {
sArr[k] = rArr[r];
r++;
}
}
return sArr; // 要素数はright - left
}
private static long[] Sort(long[] sArr, int left, int right) {
if (left + 1 < right) {
var mid = (left + right) / 2;
sArr = Sort(sArr, left, mid);
sArr = Sort(sArr, mid, right);
sArr = Merge(sArr, left, mid, right);
}
return sArr;
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator -(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value - item2.Value;
if (value < 0) {
value += item1.Mod;
}
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
return item1 + new ModInt(item2, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
return item1 * new ModInt(item2, item1.Mod);
}
public static ModInt operator -(ModInt item1, int item2) {
return item1 - new ModInt(item2, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
/// <summary>組み合わせ</summary>
class ModCombination {
private int mod;
private int[] fac;
private int[] finv;
private int[] inv;
public ModCombination(int max, int mod = 1000000007) {
this.mod = mod;
fac = new int[max]; // modが法のn!の列
inv = new int[max]; // indexの逆元の列
finv = new int[max]; // modを法とした、invの累積の累積
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める
var s = Math.BigMul(inv[mod % i], mod / i) % mod;
inv[i] = (int)(mod - s);
// iに対する逆元を求める
finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod);
}
}
/// <summary>nCk</summary>
public int Calculation(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (int)(Math.BigMul(fac[n],
(int)(Math.BigMul(finv[k], finv[n - k]) % mod)) %
mod);
}
}
/// <summary>拡張メソッドs</summary>
static class Extention {
/// <summary>iとjを入れ替える</summary>
public static void Swap<T>(this T[] arr, int i, int j) {
var buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
}
/// <summary>
/// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。
/// </summary>
/// <param name="sArr"></param>
/// <param name="p">partitionの先頭の添字</param>
/// <param name="r">partitionの末尾の添字</param>
/// <returns>partitionの基準が存在する添字</returns>
public static int Partition(this int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
/// <summary>深いコピーをする</summary>
public static T DeepCopy<T>(this T obj) {
T result;
var b = new BinaryFormatter();
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 3,047
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
class Program {
static void Main() { new Magatro().Solve(); }
}
class Magatro {
private const int Mod = (int)1e9 + 7;
private int[] F;
private int N = int.Parse(Console.ReadLine());
private int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
private int Not;
private void CalcF() {
F = new int[N + 2];
for (int i = 0; i <= N + 1; i++) {
if (i == 0) {
F[i] = 1;
} else {
F[i] = (F[i - 1] * i) % Mod;
}
}
}
private void Search() {
var map = (new int[N + 1]).Select(i => -1).ToArray();
for (int i = 0; i < N + 1; i++) {
if (map[A[i]] == -1) {
map[A[i]] = i;
} else {
Not = N + map[A[i]] - i;
break;
}
}
}
private long Pow(long a, long b, long mod) {
long result = 1;
while (b > 0) {
if (b % 2 == 1) {
result *= a;
result %= mod;
}
a *= a;
a %= mod;
b /= 2;
}
return result;
}
private long C(long n, long m, long mod) {
if (n < m) {
return 0;
}
long numerator = F[n];
long denominator = Pow((F[m] * F[n - m]) % mod, mod - 2, mod);
return (numerator * denominator) % mod;
}
public void Solve() {
CalcF();
Search();
var sb = new StringBuilder();
for (int i = 1; i <= N + 1; i++) {
long ans = C(N + 1, i, Mod) - C(Not, i - 1, Mod);
while (ans < 0) {
ans += Mod;
}
sb.AppendLine(ans.ToString());
}
Console.Write(sb.ToString());
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
class Program {
static void Main() { new Magatro().Solve(); }
}
class Magatro {
private const int Mod = (int)1e9 + 7;
private long[] F;
private int N = int.Parse(Console.ReadLine());
private int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
private int Not;
private void CalcF() {
F = new long[N + 2];
for (int i = 0; i <= N + 1; i++) {
if (i == 0) {
F[i] = 1;
} else {
F[i] = (F[i - 1] * i) % Mod;
}
}
}
private void Search() {
var map = (new int[N + 1]).Select(i => -1).ToArray();
for (int i = 0; i < N + 1; i++) {
if (map[A[i]] == -1) {
map[A[i]] = i;
} else {
Not = N + map[A[i]] - i;
break;
}
}
}
private long Pow(long a, long b, long mod) {
long result = 1;
while (b > 0) {
if (b % 2 == 1) {
result *= a;
result %= mod;
}
a *= a;
a %= mod;
b /= 2;
}
return result;
}
private long C(long n, long m, long mod) {
if (n < m) {
return 0;
}
long numerator = F[n];
long denominator = Pow((F[m] * F[n - m]) % mod, mod - 2, mod);
return (numerator * denominator) % mod;
}
public void Solve() {
CalcF();
Search();
var sb = new StringBuilder();
for (int i = 1; i <= N + 1; i++) {
long ans = C(N + 1, i, Mod) - C(Not, i - 1, Mod);
while (ans < 0) {
ans += Mod;
}
sb.AppendLine(ans.ToString());
}
Console.Write(sb.ToString());
}
}
|
[["-", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["+", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199]]
| 8
| 532
| 4
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var s = sc.Ia;
var a = sc.Ia;
var imos = new Imos(s[1] + 1, 2);
long p = 0, g = 0;
for (int i = 1; i < s[0]; i++) {
if (a[i] > a[i - 1]) {
imos.Add1(a[i - 1] + 1, a[i], 0, 1);
p += a[i] - a[i - 1];
} else {
imos.Add1(a[i - 1] + 1, s[1], 0, 1);
imos.Add1(1, a[i], s[1] - a[i - 1], 1);
p += s[1] + a[i] - a[i - 1];
}
}
imos.Go();
for (int i = 0; i < s[1]; i++) {
g = Max(g, imos[i]);
}
Console.WriteLine("{0}", p - g);
}
}
public class Imos {
private const int mod = (int)1e9 + 7;
private long[] a, h, c, ra;
private int o, n;
public Imos(int n, int o) {
this.o = o;
this.n = n;
a = new long[n + o];
h = new long[n + o];
c = new long[o];
ra = new long[n + o];
ra[0] = ra[1] = 1;
for (int i = 2; i < ra.Length; i++) {
ra[i] = ra[i - 1] * i;
if (i > o) {
ra[i] /= i - o + 1;
}
}
for (int i = 0; i < ((o + 1) >> 1); i++) {
ra[o - i - 1] = ra[i] *= ra[o - i - 1];
}
}
public void Add1(int l, int r, long a, long b) {
h[l] += a;
h[l + 1] -= a - b;
h[r + 1] -= a + (r - l + 1) * b;
h[r + 2] += a + (r - l) * b;
}
public void Add2(int l, int r, long b) {
h[l] += b;
h[l + 1] += b;
h[r + 1] -= (r - l + 2) * (r - l + 2) * b;
h[r + 2] += ((r - l + 1) * (r - l + 1) * 2 + (r - l + 1) * 2 - 1) * b;
h[r + 3] -= (r - l + 1) * (r - l + 1) * b;
}
public void Addc(int l, int r, long b) {
int p = r - l;
h[l] += b;
long f = ra[p + o] * b;
for (int i = 1; i <= o; i++) {
h[r + i] += f / ra[i - 1] * ((i & 1) == 1 ? -1 : 1);
f *= p + i;
f /= p + i + 1;
}
}
public void Addt(int l, int r, long b) {
int p = r - l;
h[l] += b;
h[r + 1] -= (p + 2) * (p + 3) / 2 * b;
h[r + 2] += (p + 1) * (p + 3) * b;
h[r + 3] -= (p + 1) * (p + 2) / 2 * b;
}
public void Go() {
for (int i = 1; i < n; i++) {
c[0] += h[i];
for (int j = 1; j < o; j++) {
c[j] += c[j - 1];
}
a[i] = c[o - 1];
}
}
public long this[int i] {
get { return a[i]; }
}
public override string ToString() => string.Join(" ", a);
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse);
}
public int[] Ia3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse);
}
public long[] La3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program {
const int mod = (int)1e9 + 7;
const double eps = 1e-11;
static void Main() {
Sc sc = new Sc();
var s = sc.Ia;
var a = sc.Ia;
var imos = new Imos(s[1] + 1, 2);
long p = 0, g = 0;
for (int i = 1; i < s[0]; i++) {
if (a[i] > a[i - 1]) {
imos.Add1(a[i - 1] + 1, a[i], 0, 1);
p += a[i] - a[i - 1];
} else {
imos.Add1(a[i - 1] + 1, s[1], 0, 1);
imos.Add1(1, a[i], s[1] - a[i - 1], 1);
p += s[1] + a[i] - a[i - 1];
}
}
imos.Go();
for (int i = 1; i <= s[1]; i++) {
g = Max(g, imos[i]);
}
Console.WriteLine("{0}", p - g);
}
}
public class Imos {
private const int mod = (int)1e9 + 7;
private long[] a, h, c, ra;
private int o, n;
public Imos(int n, int o) {
this.o = o;
this.n = n;
a = new long[n + o];
h = new long[n + o];
c = new long[o];
ra = new long[n + o];
ra[0] = ra[1] = 1;
for (int i = 2; i < ra.Length; i++) {
ra[i] = ra[i - 1] * i;
if (i > o) {
ra[i] /= i - o + 1;
}
}
for (int i = 0; i < ((o + 1) >> 1); i++) {
ra[o - i - 1] = ra[i] *= ra[o - i - 1];
}
}
public void Add1(int l, int r, long a, long b) {
h[l] += a;
h[l + 1] -= a - b;
h[r + 1] -= a + (r - l + 1) * b;
h[r + 2] += a + (r - l) * b;
}
public void Add2(int l, int r, long b) {
h[l] += b;
h[l + 1] += b;
h[r + 1] -= (r - l + 2) * (r - l + 2) * b;
h[r + 2] += ((r - l + 1) * (r - l + 1) * 2 + (r - l + 1) * 2 - 1) * b;
h[r + 3] -= (r - l + 1) * (r - l + 1) * b;
}
public void Addc(int l, int r, long b) {
int p = r - l;
h[l] += b;
long f = ra[p + o] * b;
for (int i = 1; i <= o; i++) {
h[r + i] += f / ra[i - 1] * ((i & 1) == 1 ? -1 : 1);
f *= p + i;
f /= p + i + 1;
}
}
public void Addt(int l, int r, long b) {
int p = r - l;
h[l] += b;
h[r + 1] -= (p + 2) * (p + 3) / 2 * b;
h[r + 2] += (p + 1) * (p + 3) * b;
h[r + 3] -= (p + 1) * (p + 2) / 2 * b;
}
public void Go() {
for (int i = 1; i < n; i++) {
c[0] += h[i];
for (int j = 1; j < o; j++) {
c[j] += c[j - 1];
}
a[i] = c[o - 1];
}
}
public long this[int i] {
get { return a[i]; }
}
public override string ToString() => string.Join(" ", a);
}
public class Sc {
public int I {
get { return int.Parse(Console.ReadLine()); }
}
public long L {
get { return long.Parse(Console.ReadLine()); }
}
public double D {
get { return double.Parse(Console.ReadLine()); }
}
public string S {
get { return Console.ReadLine(); }
}
public int[] Ia {
get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
}
public long[] La {
get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); }
}
public double[] Da {
get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); }
}
public string[] Sa {
get { return Console.ReadLine().Split(); }
}
public object[] Oa {
get { return Console.ReadLine().Split(); }
}
public int[] Ia2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
int.Parse);
}
}
public int[] Ia3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse);
}
public int[] Ia3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
int.Parse);
}
public long[] La2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
long.Parse);
}
}
public long[] La3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse);
}
public long[] La3(int a) {
return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(),
long.Parse);
}
public double[] Da2 {
get {
return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(),
double.Parse);
}
}
public double[] Da3(string a, string b) {
return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.Parse);
}
public T[] Arr<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f();
}
return a;
}
public T[] Arr<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i);
}
return a;
}
public T[] Arr<T>(int n, Func<string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(Console.ReadLine().Split());
}
return a;
}
public T[] Arr<T>(int n, Func<int, string[], T> f) {
var a = new T[n];
for (int i = 0; i < n; i++) {
a[i] = f(i, Console.ReadLine().Split());
}
return a;
}
}
|
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
| 8
| 1,828
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample {
class Sample {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int X = int.Parse(str[0]);
int A = int.Parse(str[1]);
int B = int.Parse(str[2]);
if (B < A) {
Console.WriteLine("delicious");
} else if ((B - A) <= X) {
Console.WriteLine("safe");
} else {
Console.WriteLine("dangerous");
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample {
class Sample {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int X = int.Parse(str[0]);
int A = int.Parse(str[1]);
int B = int.Parse(str[2]);
if (B <= A) {
Console.WriteLine("delicious");
} else if ((B - A) <= X) {
Console.WriteLine("safe");
} else {
Console.WriteLine("dangerous");
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
| 8
| 142
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A {
class Program {
public static void Main(string[] args) {
var n = ReadLineIntSpilit();
var re = "safe";
if (n[1] > n[2]) {
re = "delicious";
} else if (n[1] - n[2] <= n[0]) {
re = "dangerous";
}
Console.WriteLine(re);
ReadLine();
}
/// <summary>
/// stringを一文字ずつintにキャストして配列に変換します。
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static int[] StringCharArrayIntArray(string str) {
List<int> b = new List<int>();
for (int i = 0; i < str.Length; i++) {
b.Add(int.Parse(str[i].ToString()));
}
return b.ToArray();
}
public static string ReadLine() { return Console.ReadLine(); }
public static int ReadLineInt() { return int.Parse(Console.ReadLine()); }
public static string[] ReadLineStringSplit(char a = ' ') {
return ReadLine().Split(a).ToArray();
}
public static int[] ReadLineIntSpilit(char a = ' ') {
return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace A {
class Program {
public static void Main(string[] args) {
var n = ReadLineIntSpilit();
var re = "safe";
if (n[1] - n[2] >= 0) {
re = "delicious";
} else if (n[2] - n[1] > n[0]) {
re = "dangerous";
}
Console.WriteLine(re);
ReadLine();
}
/// <summary>
/// stringを一文字ずつintにキャストして配列に変換します。
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static int[] StringCharArrayIntArray(string str) {
List<int> b = new List<int>();
for (int i = 0; i < str.Length; i++) {
b.Add(int.Parse(str[i].ToString()));
}
return b.ToArray();
}
public static string ReadLine() { return Console.ReadLine(); }
public static int ReadLineInt() { return int.Parse(Console.ReadLine()); }
public static string[] ReadLineStringSplit(char a = ' ') {
return ReadLine().Split(a).ToArray();
}
public static int[] ReadLineIntSpilit(char a = ' ') {
return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47]]
| 8
| 300
| 10
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.