buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class MainClass {
// C#7.0/////////////////////////////////////////////////////
String S;
void Solve() {
io.i(out S);
io.o(S.First() + (S.Length - 2) + S.Last());
}
////////////////////////////////////////////////////////////
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
////////////////////////////////////////////////////////////
}
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public char nextChar() { return char.Parse(next()); }
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
public string[] arr() { return Console.ReadLine().Split(' '); }
public char[] arrayChar() { return Array.ConvertAll(arr(), char.Parse); }
public int[] arrayInt() { return Array.ConvertAll(arr(), int.Parse); }
public long[] arrayLong() { return Array.ConvertAll(arr(), long.Parse); }
public double[] arrayDouble() {
return Array.ConvertAll(arr(), double.Parse);
}
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
public void i<T>(out T v) { v = suitType<T>(next()); }
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 ini(out int[] a, int size) {
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = nextInt();
}
public void ini(out long[] a, int size) {
a = new long[size];
for (int i = 0; i < size; i++)
a[i] = nextLong();
}
public void ini(out int[] a1, out int[] a2, int size) {
a1 = new int[size];
a2 = new int[size];
for (int i = 0; i < size; i++) {
a1[i] = nextInt();
a2[i] = nextInt();
}
}
public void ini(out int[,] g, int h, int w) {
g = new int[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
g[i, j] = nextInt();
}
public void ini(out string[] a, int size) {
a = new string[size];
for (int i = 0; i < size; i++)
a[i] = next();
}
public void inii(out int[] a, int size) {
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = nextInt() - 1;
}
public void inii(out int[] a1, out int[] a2, int size) {
a1 = new int[size];
a2 = new int[size];
for (int i = 0; i < size; i++) {
a1[i] = nextInt() - 1;
a2[i] = nextInt() - 1;
}
}
public void inii(out int[,] a, int size) {
a = new int[size, size];
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
a[i, j] = nextInt() - 1;
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) {
foreach (T v in a)
Console.WriteLine(v);
}
public void o<T>(List<T> l) {
foreach (T v in l)
sw.WriteLine(v);
}
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) {
foreach (T v in a) {
ol(v);
}
br();
}
public void YN(bool f) { Console.WriteLine(f ? "YES" : "NO"); }
public void Yn(bool f) { Console.WriteLine(f ? "Yes" : "No"); }
public void yn(bool f) { Console.WriteLine(f ? "yes" : "no"); }
public void br() { Console.WriteLine(""); }
public void writeFlush() { Console.Out.Flush(); }
public string pad0<T>(T v, int n) { return v.ToString().PadLeft(n, '0'); }
}
class Mat {
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long Sum(params long[] a) {
return a.Aggregate((v, next) => (v % mod + next) % mod);
}
public int GCD(int a, int b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public int GCD(int[] array) {
return array.Aggregate((v, next) => GCD(v, next));
}
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 void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
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 Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int Clamp(int n, int a, int b) {
return (n < a) ? a : (b < n) ? b : n;
}
public long Clamp(long n, long a, long b) {
return (n < a) ? a : (b < n) ? b : n;
}
public double Clamp(double n, double a, double b) {
return (n < a) ? a : (b < n) ? b : n;
}
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> {
public Dictionary<T, int> dic;
public AssociativeArray() {}
public AssociativeArray(T[] a) { init(a); }
public void init(T[] a) {
dic = new Dictionary<T, int>();
for (int i = 0; i < a.Length; i++) {
if (!dic.ContainsKey(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
}
}
public void Add(T[] a) {
for (int i = 0; i < a.Length; i++) {
if (!dic.ContainsKey(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
}
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValueSum() { return dic.Values.Sum(); }
public int KeyNum() { return dic.Keys.Count; }
public int Max() { return dic.Values.Max(); }
public int Min() { return dic.Values.Min(); }
public T MaxKey() { return dic.First(d => d.Value == Max()).Key; }
public T MinKey() { return dic.First(d => d.Value == Min()).Key; }
public bool isContainsK(T k) { return dic.ContainsKey(k); }
public bool anyContainsK(params T[] k) {
bool f = false;
foreach (T v in k)
f |= isContainsK(v);
return f;
}
public bool allContainsK(params T[] k) {
bool f = true;
foreach (T v in k)
f &= isContainsK(v);
return f;
}
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
//:sort->array
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
class BucketSort {
public int[] bucket;
public void Init(int[] a) {
bucket = new int[a.Max() + 1];
for (int i = 0; i < a.Length; ++i)
++bucket[a[i]];
for (int i = 0, j = 0; j < bucket.Length; ++j)
for (int k = bucket[j]; k != 0; --k, ++i)
a[i] = j;
}
}
// 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());
}
}
static class CharEX {
public static int toInt(this char c) { return int.Parse(c.ToString()); }
}
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) {
for (int i = 0; i < a.Length; i++) {
a[i] = v;
}
}
}
////////////////////////////////////////////////////////////////
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class MainClass {
// C#7.0/////////////////////////////////////////////////////
String S;
void Solve() {
io.i(out S);
io.o(S[0].ToString() + (S.Length - 2) + S[S.Length - 1]);
}
////////////////////////////////////////////////////////////
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
////////////////////////////////////////////////////////////
}
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public char nextChar() { return char.Parse(next()); }
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
public string[] arr() { return Console.ReadLine().Split(' '); }
public char[] arrayChar() { return Array.ConvertAll(arr(), char.Parse); }
public int[] arrayInt() { return Array.ConvertAll(arr(), int.Parse); }
public long[] arrayLong() { return Array.ConvertAll(arr(), long.Parse); }
public double[] arrayDouble() {
return Array.ConvertAll(arr(), double.Parse);
}
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
public void i<T>(out T v) { v = suitType<T>(next()); }
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 ini(out int[] a, int size) {
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = nextInt();
}
public void ini(out long[] a, int size) {
a = new long[size];
for (int i = 0; i < size; i++)
a[i] = nextLong();
}
public void ini(out int[] a1, out int[] a2, int size) {
a1 = new int[size];
a2 = new int[size];
for (int i = 0; i < size; i++) {
a1[i] = nextInt();
a2[i] = nextInt();
}
}
public void ini(out int[,] g, int h, int w) {
g = new int[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
g[i, j] = nextInt();
}
public void ini(out string[] a, int size) {
a = new string[size];
for (int i = 0; i < size; i++)
a[i] = next();
}
public void inii(out int[] a, int size) {
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = nextInt() - 1;
}
public void inii(out int[] a1, out int[] a2, int size) {
a1 = new int[size];
a2 = new int[size];
for (int i = 0; i < size; i++) {
a1[i] = nextInt() - 1;
a2[i] = nextInt() - 1;
}
}
public void inii(out int[,] a, int size) {
a = new int[size, size];
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
a[i, j] = nextInt() - 1;
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) {
foreach (T v in a)
Console.WriteLine(v);
}
public void o<T>(List<T> l) {
foreach (T v in l)
sw.WriteLine(v);
}
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) {
foreach (T v in a) {
ol(v);
}
br();
}
public void YN(bool f) { Console.WriteLine(f ? "YES" : "NO"); }
public void Yn(bool f) { Console.WriteLine(f ? "Yes" : "No"); }
public void yn(bool f) { Console.WriteLine(f ? "yes" : "no"); }
public void br() { Console.WriteLine(""); }
public void writeFlush() { Console.Out.Flush(); }
public string pad0<T>(T v, int n) { return v.ToString().PadLeft(n, '0'); }
}
class Mat {
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long Sum(params long[] a) {
return a.Aggregate((v, next) => (v % mod + next) % mod);
}
public int GCD(int a, int b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public int GCD(int[] array) {
return array.Aggregate((v, next) => GCD(v, next));
}
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 void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
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 Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int Clamp(int n, int a, int b) {
return (n < a) ? a : (b < n) ? b : n;
}
public long Clamp(long n, long a, long b) {
return (n < a) ? a : (b < n) ? b : n;
}
public double Clamp(double n, double a, double b) {
return (n < a) ? a : (b < n) ? b : n;
}
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> {
public Dictionary<T, int> dic;
public AssociativeArray() {}
public AssociativeArray(T[] a) { init(a); }
public void init(T[] a) {
dic = new Dictionary<T, int>();
for (int i = 0; i < a.Length; i++) {
if (!dic.ContainsKey(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
}
}
public void Add(T[] a) {
for (int i = 0; i < a.Length; i++) {
if (!dic.ContainsKey(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
}
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValueSum() { return dic.Values.Sum(); }
public int KeyNum() { return dic.Keys.Count; }
public int Max() { return dic.Values.Max(); }
public int Min() { return dic.Values.Min(); }
public T MaxKey() { return dic.First(d => d.Value == Max()).Key; }
public T MinKey() { return dic.First(d => d.Value == Min()).Key; }
public bool isContainsK(T k) { return dic.ContainsKey(k); }
public bool anyContainsK(params T[] k) {
bool f = false;
foreach (T v in k)
f |= isContainsK(v);
return f;
}
public bool allContainsK(params T[] k) {
bool f = true;
foreach (T v in k)
f &= isContainsK(v);
return f;
}
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
//:sort->array
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
class BucketSort {
public int[] bucket;
public void Init(int[] a) {
bucket = new int[a.Max() + 1];
for (int i = 0; i < a.Length; ++i)
++bucket[a[i]];
for (int i = 0, j = 0; j < bucket.Length; ++j)
for (int k = bucket[j]; k != 0; --k, ++i)
a[i] = j;
}
}
// 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());
}
}
static class CharEX {
public static int toInt(this char c) { return int.Parse(c.ToString()); }
}
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) {
for (int i = 0; i < a.Length; i++) {
a[i] = v;
}
}
}
////////////////////////////////////////////////////////////////
}
|
[["+", 31, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["-", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 2,969
| 14
|
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();
Console.WriteLine(input[0] + (input.Length - 2) + input[input.Length - 1]);
}
}
}
|
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();
Console.Write(input[0]);
Console.Write(input.Length - 2);
Console.WriteLine(input[input.Length - 1]);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 82
| 14
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
string[] s = Console.ReadLine().Split(' ');
Console.WriteLine((int.Parse(s[0]) - 1) * (int.Parse(s[1]) - 1));
}
}
class ProgramB {
public void main() {
string s = Console.ReadLine();
Console.WriteLine(s[0] + (s.Length - 2).ToString() + s[s.Length - 1]);
}
}
class ProgramC {
public void main() {
int n = int.Parse(Console.ReadLine());
string[] a = Console.ReadLine().Split(' ');
int count4 = 0;
int count2 = 0;
for (int i = 0; i < n; i++) {
if (long.Parse(a[i]) % 4 == 0)
count4++;
else if (long.Parse(a[i]) % 2 == 0)
count2++;
}
if (count4 > n / 2) {
Console.WriteLine("Yes");
return;
}
if (count4 != 0) {
if (2 * count4 + 1 + count2 >= n) {
Console.WriteLine("Yes");
return;
}
} else {
if (count2 == n) {
Console.WriteLine("Yes");
return;
}
}
Console.WriteLine("No");
}
}
}
|
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace debug {
class main {
static void Main(string[] args) {
//問題クラスを展開
ProgramC a = new ProgramC();
a.main(); //実行する
}
}
class ProgramA {
public void main() {
string[] s = Console.ReadLine().Split(' ');
Console.WriteLine((int.Parse(s[0]) - 1) * (int.Parse(s[1]) - 1));
}
}
class ProgramB {
public void main() {
string s = Console.ReadLine();
Console.WriteLine(s[0] + (s.Length - 2).ToString() + s[s.Length - 1]);
}
}
class ProgramC {
public void main() {
int n = int.Parse(Console.ReadLine());
string[] a = Console.ReadLine().Split(' ');
int count4 = 0;
int count2 = 0;
for (int i = 0; i < n; i++) {
if (long.Parse(a[i]) % 4 == 0)
count4++;
else if (long.Parse(a[i]) % 2 == 0)
count2++;
}
if (count4 >= n / 2) {
Console.WriteLine("Yes");
return;
}
if (2 * count4 + count2 >= n) {
Console.WriteLine("Yes");
return;
}
Console.WriteLine("No");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 371
| 34
|
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 = 10000000;
public static void Main() {
// 方針
//
int n = rint();
int[] a = inta();
int[] count = new int[3];
for (int i = 0; i < n; i++) {
if (a[i] % 4 == 0) {
count[2]++;
} else if (a[i] % 2 == 0) {
count[1]++;
} else {
count[0]++;
}
}
if (count[2] >= count[0]) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
static int binarysearchd(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] >= b) {
return 0;
} else if (a[leng - 1] < b) {
return leng;
} else {
if (a[max] < b) {
return max + 1;
}
return min + 1;
}
}
static int binarysearchu(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] > b) {
return leng;
} else if (a[leng - 1] <= b) {
return 0;
} else {
if (a[max] <= b) {
return leng - (max + 1);
}
return leng - (min + 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
|
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 = 10000000;
public static void Main() {
// 方針
//
int n = rint();
int[] a = inta();
int[] count = new int[3];
for (int i = 0; i < n; i++) {
if (a[i] % 4 == 0) {
count[2]++;
} else if (a[i] % 2 == 0) {
count[1]++;
} else {
count[0]++;
}
}
if (count[2] >= count[0] || (count[2] + 1 == count[0] && count[1] == 0)) {
WriteLine("Yes");
} else {
WriteLine("No");
}
}
static int binarysearchd(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] >= b) {
return 0;
} else if (a[leng - 1] < b) {
return leng;
} else {
if (a[max] < b) {
return max + 1;
}
return min + 1;
}
}
static int binarysearchu(int[] a, int b) {
int leng = a.Length;
int min = 0;
int max = leng - 1;
while (max - min > 1) {
int mid = (min + max) / 2;
if (a[mid] < b) {
min = mid;
} else {
max = mid;
}
}
if (a[0] > b) {
return leng;
} else if (a[leng - 1] <= b) {
return 0;
} else {
if (a[max] <= b) {
return leng - (max + 1);
}
return leng - (min + 1);
}
}
// 1からaまでの数字並べ替え全通り返すやつ
static List<string> permutation(int a) {
var list = new List<string>();
if (a == 1) {
list.Add("1");
return list;
} else {
foreach (var k in permutation(a - 1)) {
var ch = k.ToCharArray();
for (int i = 0; i <= ch.Length; i++) {
string intemp = "";
if (i == 0) {
intemp += a.ToString();
}
for (int j = 0; j < ch.Length; j++) {
intemp += ch[j].ToString();
if (i == j + 1) {
intemp += a.ToString();
}
}
list.Add(intemp);
}
}
}
return list;
}
public static void swap(ref int a, ref int b) {
int temp = a;
a = b;
b = temp;
}
static void charswap(ref char a, ref char b) {
char temp = a;
a = b;
b = temp;
}
static int ncr(int n, int r) {
r = Min(r, n - r);
long nn = 1;
for (int i = n - r + 1; i <= n; i++) {
nn = nn * i % mod;
}
long rr = 1;
for (int i = 1; i <= r; i++) {
rr = rr * i % mod;
}
rr = square((int)rr, mod - 2);
nn = nn * rr % mod;
return (int)nn;
}
// a^b mod
static int square(int a, int b) {
string binary = Convert.ToString(b, 2);
int bileng = binary.Length;
long a_power = a;
long value = 1;
for (int i = bileng - 1; i >= 0; i--) {
if (binary[i] == '1') {
value = value * a_power % mod;
}
a_power = a_power * a_power % mod;
}
return (int)value;
}
static int square2(int a, int b) {
long output = 1;
var list = new List<long>();
int sh = 1;
long n = a;
list.Add(a);
while (sh < b) {
sh *= 2;
n = n * n % mod;
list.Add(n);
}
for (int i = list.Count - 1; i >= 0; i--) {
if (b > sh) {
b -= sh;
sh /= 2;
output = output * list[i] % mod;
}
}
return (int)output;
}
//各種読取
static string rstr() { return ReadLine(); }
static int rint() { return int.Parse(ReadLine()); }
static long rlong() { return long.Parse(ReadLine()); }
static string[] stra() { return ReadLine().Split(' '); }
static char[] chara() {
string[] a = stra();
string b = "";
for (int i = 0; i < a.Length; i++) {
b += a[i];
}
return b.ToCharArray();
}
static int[] inta() {
string[] read_str_array = ReadLine().Split(' ');
int[] return_int_array = new int[read_str_array.Length];
for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
}
return return_int_array;
}
static int[,] inta2(int num_array, int in_array) {
int[,] int_array2 = new int[num_array, in_array];
for (int i = 0; i < num_array; i++) {
int[] temp_array = inta();
for (int j = 0; j < in_array; j++) {
int_array2[i, j] = temp_array[j];
}
}
return int_array2;
}
static long[] longa() {
string[] read_str_array = ReadLine().Split(' ');
long[] return_long_array = new long[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_long_array;
}
static double[] doublea() {
string[] read_str_array = ReadLine().Split(' ');
double[] return_double_array = new double[read_str_array.Length];
for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) {
return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
}
return return_double_array;
}
// -----------------------------
static long divideup(long divided, long divid) {
long temp_divide = divided / divid;
if (divided % divid > 0) {
temp_divide++;
}
return temp_divide;
}
static long GCD(long a, long b) {
if (a < b) {
long temp = a;
a = b;
b = temp;
}
if (a % b == 0) {
return b;
} else {
long temp = b;
b = a % b;
a = temp;
return GCD(a, b);
}
}
static long LCM(long a, long b) { return a * b / GCD(a, b); }
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 16, 31, 204, 205, 22], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 12, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 12, 23, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
| 8
| 1,569
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
//いつもの
readonly static long mod = 1000000000 + 7;
static void Main(string[] args) {
int n = int.Parse(ReadLine());
long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
int cnt4 = 0;
int cnt2 = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] % 4 == 0) {
cnt4++;
} else if (s[i] % 2 == 0) {
cnt2++;
}
}
if (cnt4 == 0) {
WriteLine(cnt2 == n ? "Yes" : "No");
} else {
if (cnt2 == 0) {
WriteLine((cnt4 * 3) >= n ? "Yes" : "No");
} else {
WriteLine((cnt4 * 3) + cnt2 - 1 >= n ? "Yes" : "No");
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
//いつもの
readonly static long mod = 1000000000 + 7;
static void Main(string[] args) {
int n = int.Parse(ReadLine());
long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
int cnt4 = 0;
int cnt2 = 0;
int cnt = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] % 4 == 0) {
cnt4++;
} else if (s[i] % 2 == 0) {
cnt2++;
} else {
cnt++;
}
}
if (cnt4 == 0) {
WriteLine(cnt2 == n ? "Yes" : "No");
} else {
if (cnt2 == 0) {
WriteLine((cnt4 + 1) >= cnt ? "Yes" : "No");
} else {
WriteLine(cnt4 >= cnt ? "Yes" : "No");
}
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 75, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 46], ["-", 0, 41, 15, 16, 31, 23, 0, 16, 17, 48], ["-", 0, 41, 15, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 41, 15, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 41, 15, 16, 31, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 31, 16, 31, 16, 31, 23, 0, 16, 17, 48], ["-", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 15, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 41, 15, 16, 31, 16, 31, 16, 17, 72], ["-", 0, 41, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 33], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203]]
| 8
| 235
| 27
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]C - 4-adjacent
int n = int.Parse(Console.ReadLine());
var a = ReadLine();
var classifications = new List<List<int>>();
for (int i = 0; i < 5; i++) {
var c = new List<int>();
classifications.Add(c);
}
//数列の要素を 4の倍数,2の倍数,奇数 に分類
foreach (var ai in a) {
if (ai % 4 == 0) {
classifications[4].Add(ai);
} else if (ai % 2 == 0) {
classifications[2].Add(ai);
} else {
classifications[1].Add(ai);
}
}
if (IsGoal(classifications)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
static bool IsGoal(List<List<int>> c) {
//数列に1が存在しなければNG
if (!c[1].Contains(1)) {
return false;
} else {
if (c[4].Count >= c[1].Count) {
return true;
} else if (c[4].Count + 1 == c[1].Count) {
if (c[2].Count == 0) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}
static List<int> ReadLine() {
var line = Console.ReadLine();
var array = line.Split(' ');
return array.Select(x => int.Parse(x)).ToList();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
//[summary]C - 4-adjacent
int n = int.Parse(Console.ReadLine());
var a = ReadLine();
var classifications = new List<List<int>>();
for (int i = 0; i < 5; i++) {
var c = new List<int>();
classifications.Add(c);
}
//数列の要素を 4の倍数,2の倍数,奇数 に分類
foreach (var ai in a) {
if (ai % 4 == 0) {
classifications[4].Add(ai);
} else if (ai % 2 == 0) {
classifications[2].Add(ai);
} else {
classifications[1].Add(ai);
}
}
if (IsGoal(classifications)) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
static bool IsGoal(List<List<int>> c) {
if (c[4].Count >= c[1].Count) {
return true;
} else if (c[4].Count + 1 == c[1].Count) {
if (c[2].Count == 0) {
return true;
} else {
return false;
}
} else {
return false;
}
}
static List<int> ReadLine() {
var line = Console.ReadLine();
var array = line.Split(' ');
return array.Select(x => int.Parse(x)).ToList();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 241, 0, 111], ["-", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 241, 0, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 241, 0, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 24], ["-", 15, 241, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 0, 57, 64, 196, 0, 37, 0, 211, 0, 147], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 214, 205, 204, 205, 22], ["-", 15, 16, 31, 214, 205, 204, 206, 207, 0, 70], ["-", 75, 196, 0, 57, 75, 57, 75, 196, 0, 46]]
| 8
| 355
| 21
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Practice {
class Program {
static void Main(string[] args) { Solve(); }
private const int MOD = 1000000007;
static void Solve() {
var n = ReadAndParseInt();
var a = ReadAndParseIntArr();
var total2 = 0;
var total4Multiple = 0;
var totalOther = 0;
for (int i = 0; i < n; ++i) {
var ai = a[i];
if (ai == 2) {
total2++;
} else if (ai % 4 == 0) {
total4Multiple++;
} else {
totalOther++;
}
}
bool b = false;
if (total2 >= 1) {
b = total4Multiple >= totalOther;
} else {
b = total4Multiple + 1 >= totalOther;
}
var ans = b ? "Yes" : "No";
Console.WriteLine(ans);
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Practice {
class Program {
static void Main(string[] args) { Solve(); }
private const int MOD = 1000000007;
static void Solve() {
var n = ReadAndParseInt();
var a = ReadAndParseIntArr();
var total2Multiple = 0;
var total4Multiple = 0;
var totalOther = 0;
for (int i = 0; i < n; ++i) {
var ai = a[i];
if (ai % 2 == 0 && ai % 4 != 0) {
total2Multiple++;
} else if (ai % 4 == 0) {
total4Multiple++;
} else {
totalOther++;
}
}
bool b = false;
if (total2Multiple >= 1) {
b = total4Multiple >= totalOther;
} else {
b = total4Multiple + 1 >= totalOther;
}
var ans = b ? "Yes" : "No";
Console.WriteLine(ans);
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
| 8
| 785
| 16
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static Ex;
class AC {
/*------------------------------------------------------------------*/
private int N;
private int[] a;
void Solve() {
io.i(out N);
io.ini(out a, N);
var x4 = a.Count(x => x % 4 == 0);
var x2 = a.Count(x => x % 4 != 0 && x % 2 == 0);
var x1 = N - x4 - x2;
io.Yn(x4 * 2 + x2 >= x1);
}
/*------------------------------------------------------------------*/
void Test() {
//--- TEST ---//
}
public static void Main(string[] args) => new AC().Stream();
IO io = new IO();
private void Stream() {
/*
var exStdIn = new System.IO.StreamReader("stdin.txt");
SetIn(exStdIn);
Test();
*/
Solve();
io.Flush();
}
}
class IO {
#region INPUT
#region FastRead
private const int Size = 1 << 12;
private readonly Stream _stream = OpenStandardInput();
private readonly byte[] _buffer = new byte[Size];
private int _ptr = 0, _buffLen = 0;
private bool HasNextByte() {
if (_ptr < _buffLen)
return true;
_ptr = 0;
_buffLen = _stream.Read(_buffer, 0, Size);
return _buffLen > 0;
}
private byte ReadByte() {
if (HasNextByte())
return _buffer[_ptr++];
else
// inputの末尾の改行がないとerror
throw new EndOfStreamException();
}
private bool IsAscii(int c) => '!' <= c && c <= '~';
private char NextChar() {
var b = ReadByte();
while (!IsAscii(b))
b = ReadByte();
return (char)b;
}
private string Next() {
var sb = new StringBuilder();
for (var b = NextChar(); IsAscii(b); b = (char)ReadByte())
sb.Append(b);
return sb.ToString();
}
public string String => Next();
public char Char => NextChar();
public int Int => int.Parse(Next());
public long Long => long.Parse(Next());
public double Double => double.Parse(Next());
#endregion
#region LazyRead
private void scan<T>(ref T x) {
if (x is int)
__refvalue(__makeref(x), int) = int.Parse(Next());
else if (x is long)
__refvalue(__makeref(x), long) = long.Parse(Next());
else if (x is double)
__refvalue(__makeref(x), double) = double.Parse(Next());
else if (x is char)
__refvalue(__makeref(x), char) = NextChar();
else
__refvalue(__makeref(x), string) = Next();
}
public void i<T>(out T t) {
t = default(T);
scan(ref t);
}
public void i<T, TU>(out T t, out TU u) {
i(out t);
i(out u);
}
public void i<T, TU, TV>(out T t, out TU u, out TV v) {
i(out t, out u);
i(out v);
}
public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
i(out t, out u);
i(out v, out w);
}
public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
i(out t, out u, out v);
i(out w, out x);
}
public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w,
out TX x, out TY y) {
i(out t, out u, out v);
i(out w, out x, out y);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
i<T>(out a[i]);
}
public void ini<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i)
i<T, TU>(out a[i], out b[i]);
}
public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (var i = 0; i < n; ++i)
i<T, TU, TV>(out a[i], out b[i], out c[i]);
}
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)
i<T>(out a[i, j]);
}
#endregion
#endregion
#region OUTPUT
private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public void Flush() => Out.Flush();
public void YN(bool f) => WriteLine(f ? "YES" : "NO");
public void Yn(bool f) => WriteLine(f ? "Yes" : "No");
public void yn(bool f) => WriteLine(f ? "yes" : "no");
#endregion
public IO() { SetOut(_sw); }
}
static class Ex {
#region マクロもどき
public static void LOG<T>(T x, [CallerLineNumber] int line = 0) =>
Error.WriteLine($"LOG[{line}]: {x}");
public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f);
public static void FOR(int a, int b, int n, Action<int> f) {
for (int i = a; i < b; i += n)
f(i);
}
public static void REP(int a, Action<int> f) => FOR(0, a, f);
public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f);
public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f);
public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1,
n, f);
public static T MIN<T>(params T[] xs) => xs.Min();
public static T MAX<T>(params T[] xs) => xs.Max();
public static IEnumerable<int> RANGE(int s,
int e) => Enumerable.Range(s, e - s + 1);
public static int LCM(int a, int b) => a * (b / GCD(a, b));
public static int GCD(int a, int b) => (a < b) ? GCD(b, a)
: b == 0 ? a
: GCD(b, a % b);
public static int LCM(params int[] xs) => xs.Aggregate(LCM);
public static int GCD(params int[] xs) => xs.Aggregate(GCD);
public static long LCM(long a, long b) => a * (b / GCD(a, b));
public static long GCD(long a, long b) => (a < b) ? GCD(b, a)
: b == 0L ? a
: GCD(b, a % b);
public static long LCM(params long[] xs) => xs.Aggregate(LCM);
public static long GCD(params long[] xs) => xs.Aggregate(GCD);
#endregion
#region 拡張メソッド
public static void Rep(this int x, Action<int> f) => REP(x, f);
public static void RepEq(this int x, Action<int> f) => REPEQ(x, f);
public static void Do<T>(this T x, Action<T> f) => f(x);
public static void Log<T>(this T x, [CallerLineNumber] int line = 0) =>
Error.WriteLine($"LOG[{line}]: {x}");
public static void Fun<T>(this T[] xs, Action<int> f) => REP(xs.Length, f);
public static void Fun<T>(this T[,] xxs, Action<int, int> f) =>
REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => f(i, j)));
public static bool IsIn<T>(this T[] xs, int i) => 0 <= i && i < xs.Length;
public static bool IsIn<T>(this T[,] xxs, int i,
int j) => 0 <= i && i < xxs.GetLength(0) && 0 <= j
&& j < xxs.GetLength(1);
public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) {
foreach (var x in xs)
f(x);
}
public class IndexedItem<T> {
public int Idx;
public T Val;
public IndexedItem(int idx, T val) {
Idx = idx;
Val = val;
}
}
public static IEnumerable<IndexedItem<T>> Indexed<T>(
this IEnumerable<T> xs) => xs.Select((x, i) => new IndexedItem<T>(i, x));
public static void Set<T>(this T[] xs, T v) => REP(xs.Length, i => xs[i] = v);
public static void Set<T>(this T[,] xxs, T v) =>
REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => xxs[i, j] = v));
public static T[] Sort<T>(this T[] xs) {
Array.Sort(xs);
return xs;
}
public static T[] SortR<T>(this T[] xs) {
Array.Reverse(xs.Sort());
return xs;
}
public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0');
public static int RoundOff(this double v, int n) => (int)
Round(v, n - 1, MidpointRounding.AwayFromZero);
public static int RoundUp(this double v) => (int)Ceiling(v);
public static int RoundDown(this double v) => (int)Floor(v);
public static bool Odd(this int v) => (v & 1) != 0;
public static bool Odd(this long v) => (v & 1) != 0;
public static bool Eve(this int v) => !v.Odd();
public static bool Eve(this long v) => !v.Odd();
public static void Prt<T>(this T x) => WriteLine(x);
public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x));
public static void Prt<T>(this List<T> xs) => xs.Iter(x => WriteLine(x));
public static string Reversed(this string s) => string.Join("", s.Reverse());
public static string Repeat(this string s, int n) =>
string.Concat(Enumerable.Repeat(s, n).ToArray());
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static Ex;
class AC {
/*------------------------------------------------------------------*/
private int N;
private int[] a;
void Solve() {
io.i(out N);
io.ini(out a, N);
var x4 = a.Count(x => x % 4 == 0);
var x2 = a.Count(x => x % 4 != 0 && x % 2 == 0);
var x1 = N - x4 - x2 + (x2 % 2);
io.Yn(x4 + 1 >= x1);
}
/*------------------------------------------------------------------*/
void Test() {
//--- TEST ---//
}
public static void Main(string[] args) => new AC().Stream();
IO io = new IO();
private void Stream() {
/*
var exStdIn = new System.IO.StreamReader("stdin.txt");
SetIn(exStdIn);
Test();
*/
Solve();
io.Flush();
}
}
class IO {
#region INPUT
#region FastRead
private const int Size = 1 << 12;
private readonly Stream _stream = OpenStandardInput();
private readonly byte[] _buffer = new byte[Size];
private int _ptr = 0, _buffLen = 0;
private bool HasNextByte() {
if (_ptr < _buffLen)
return true;
_ptr = 0;
_buffLen = _stream.Read(_buffer, 0, Size);
return _buffLen > 0;
}
private byte ReadByte() {
if (HasNextByte())
return _buffer[_ptr++];
else
// inputの末尾の改行がないとerror
throw new EndOfStreamException();
}
private bool IsAscii(int c) => '!' <= c && c <= '~';
private char NextChar() {
var b = ReadByte();
while (!IsAscii(b))
b = ReadByte();
return (char)b;
}
private string Next() {
var sb = new StringBuilder();
for (var b = NextChar(); IsAscii(b); b = (char)ReadByte())
sb.Append(b);
return sb.ToString();
}
public string String => Next();
public char Char => NextChar();
public int Int => int.Parse(Next());
public long Long => long.Parse(Next());
public double Double => double.Parse(Next());
#endregion
#region LazyRead
private void scan<T>(ref T x) {
if (x is int)
__refvalue(__makeref(x), int) = int.Parse(Next());
else if (x is long)
__refvalue(__makeref(x), long) = long.Parse(Next());
else if (x is double)
__refvalue(__makeref(x), double) = double.Parse(Next());
else if (x is char)
__refvalue(__makeref(x), char) = NextChar();
else
__refvalue(__makeref(x), string) = Next();
}
public void i<T>(out T t) {
t = default(T);
scan(ref t);
}
public void i<T, TU>(out T t, out TU u) {
i(out t);
i(out u);
}
public void i<T, TU, TV>(out T t, out TU u, out TV v) {
i(out t, out u);
i(out v);
}
public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
i(out t, out u);
i(out v, out w);
}
public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
i(out t, out u, out v);
i(out w, out x);
}
public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w,
out TX x, out TY y) {
i(out t, out u, out v);
i(out w, out x, out y);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
i<T>(out a[i]);
}
public void ini<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i)
i<T, TU>(out a[i], out b[i]);
}
public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (var i = 0; i < n; ++i)
i<T, TU, TV>(out a[i], out b[i], out c[i]);
}
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)
i<T>(out a[i, j]);
}
#endregion
#endregion
#region OUTPUT
private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
AutoFlush = true
#else
AutoFlush = false
#endif
};
public void Flush() => Out.Flush();
public void YN(bool f) => WriteLine(f ? "YES" : "NO");
public void Yn(bool f) => WriteLine(f ? "Yes" : "No");
public void yn(bool f) => WriteLine(f ? "yes" : "no");
#endregion
public IO() { SetOut(_sw); }
}
static class Ex {
#region マクロもどき
public static void LOG<T>(T x, [CallerLineNumber] int line = 0) =>
Error.WriteLine($"LOG[{line}]: {x}");
public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f);
public static void FOR(int a, int b, int n, Action<int> f) {
for (int i = a; i < b; i += n)
f(i);
}
public static void REP(int a, Action<int> f) => FOR(0, a, f);
public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f);
public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f);
public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1,
n, f);
public static T MIN<T>(params T[] xs) => xs.Min();
public static T MAX<T>(params T[] xs) => xs.Max();
public static IEnumerable<int> RANGE(int s,
int e) => Enumerable.Range(s, e - s + 1);
public static int LCM(int a, int b) => a * (b / GCD(a, b));
public static int GCD(int a, int b) => (a < b) ? GCD(b, a)
: b == 0 ? a
: GCD(b, a % b);
public static int LCM(params int[] xs) => xs.Aggregate(LCM);
public static int GCD(params int[] xs) => xs.Aggregate(GCD);
public static long LCM(long a, long b) => a * (b / GCD(a, b));
public static long GCD(long a, long b) => (a < b) ? GCD(b, a)
: b == 0L ? a
: GCD(b, a % b);
public static long LCM(params long[] xs) => xs.Aggregate(LCM);
public static long GCD(params long[] xs) => xs.Aggregate(GCD);
#endregion
#region 拡張メソッド
public static void Rep(this int x, Action<int> f) => REP(x, f);
public static void RepEq(this int x, Action<int> f) => REPEQ(x, f);
public static void Do<T>(this T x, Action<T> f) => f(x);
public static void Log<T>(this T x, [CallerLineNumber] int line = 0) =>
Error.WriteLine($"LOG[{line}]: {x}");
public static void Fun<T>(this T[] xs, Action<int> f) => REP(xs.Length, f);
public static void Fun<T>(this T[,] xxs, Action<int, int> f) =>
REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => f(i, j)));
public static bool IsIn<T>(this T[] xs, int i) => 0 <= i && i < xs.Length;
public static bool IsIn<T>(this T[,] xxs, int i,
int j) => 0 <= i && i < xxs.GetLength(0) && 0 <= j
&& j < xxs.GetLength(1);
public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) {
foreach (var x in xs)
f(x);
}
public class IndexedItem<T> {
public int Idx;
public T Val;
public IndexedItem(int idx, T val) {
Idx = idx;
Val = val;
}
}
public static IEnumerable<IndexedItem<T>> Indexed<T>(
this IEnumerable<T> xs) => xs.Select((x, i) => new IndexedItem<T>(i, x));
public static void Set<T>(this T[] xs, T v) => REP(xs.Length, i => xs[i] = v);
public static void Set<T>(this T[,] xxs, T v) =>
REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => xxs[i, j] = v));
public static T[] Sort<T>(this T[] xs) {
Array.Sort(xs);
return xs;
}
public static T[] SortR<T>(this T[] xs) {
Array.Reverse(xs.Sort());
return xs;
}
public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0');
public static int RoundOff(this double v, int n) => (int)
Round(v, n - 1, MidpointRounding.AwayFromZero);
public static int RoundUp(this double v) => (int)Ceiling(v);
public static int RoundDown(this double v) => (int)Floor(v);
public static bool Odd(this int v) => (v & 1) != 0;
public static bool Odd(this long v) => (v & 1) != 0;
public static bool Eve(this int v) => !v.Odd();
public static bool Eve(this long v) => !v.Odd();
public static void Prt<T>(this T x) => WriteLine(x);
public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x));
public static void Prt<T>(this List<T> xs) => xs.Iter(x => WriteLine(x));
public static string Reversed(this string s) => string.Join("", s.Reverse());
public static string Repeat(this string s, int n) =>
string.Concat(Enumerable.Repeat(s, n).ToArray());
#endregion
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203]]
| 8
| 2,654
| 10
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace atcoder01 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split();
int[] T = new int[N];
for (int i = 0; i < N; i++)
T[i] = int.Parse(input[i]);
// 2を含む数
int x2 = 0;
int y4 = 0;
for (int i = 0; i < N; i++) {
if (T[i] == 2) {
x2++;
continue;
}
if ((T[i] % 2) == 0) {
y4++;
}
}
if (x2 != 0)
x2--;
string out01 = "No";
if ((y4 == 0) && (x2 == N - 1)) {
out01 = "Yes";
} else if ((y4 == 1) && (y4 * 3 + x2 >= N)) {
out01 = "Yes";
} else if (y4 * 2 + 1 + x2 >= N) {
out01 = "Yes";
}
Console.WriteLine(out01);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace atcoder01 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
string[] input = Console.ReadLine().Split();
int[] T = new int[N];
for (int i = 0; i < N; i++)
T[i] = int.Parse(input[i]);
// 2を含む数
int x2 = 0;
int y4 = 0;
for (int i = 0; i < N; i++) {
// if (T[i] == 2)
//{
// x2++;
// continue;
//}
// if ((T[i] % 2) == 0)
//{
// y4++;
//}
if ((T[i] % 4) == 0) {
y4++;
continue;
}
if ((T[i] % 2) == 0) {
x2++;
}
}
// if (x2 != 0) x2--;
// string out01 = "No";
// if ((y4 == 0) && (x2 == N-1))
//{
// out01 = "Yes";
//}
// else if ((y4 == 1) && (y4 * 3 + x2 >= N))
//{
// out01 = "Yes";
//}
// else if((y4 > 1) && (y4 * 2 + 1 + x2 >= N))
//{
// out01 = "Yes";
//}
if (x2 != 0)
x2--;
string out01 = "No";
if ((y4 == 0) && (x2 + 1 == N)) {
out01 = "Yes";
} else if ((y4 >= 1) && (y4 * 2 + 1 + x2 >= N)) {
out01 = "Yes";
}
Console.WriteLine(out01);
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 109], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 72], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 33], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["-", 75, 57, 15, 16, 31, 23, 0, 16, 17, 60], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 17, 20], ["-", 12, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 72], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["-", 75, 57, 15, 16, 12, 23, 0, 16, 17, 20], ["-", 75, 57, 15, 16, 12, 23, 0, 16, 12, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["-", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 271
| 37
|
// 2017-08-06 ABC069 C - 4-adjacent
using System;
class Program {
static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
string[] sa = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(sa[i]);
}
// 各要素ごとに
// 4の倍数であればスコア2
// 4の倍数ではないが2の倍数であればスコア1
// 2の倍数でなければスコア0とする
// スコアが要素数以上あれば成立?
int score = 0;
for (int i = 0; i < n; i++) {
if (0 == (a[i] % 4)) {
score += 2;
} else if (0 == (a[i] % 2)) {
score += 1;
} else {
}
}
if (score >= n) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
// 2017-08-06 ABC069 C - 4-adjacent
using System;
class Program {
static void Main(string[] args) {
bool yes = false;
int n = int.Parse(Console.ReadLine());
string[] sa = Console.ReadLine().Split(' ');
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(sa[i]);
}
// 各要素ごとに
// 4の倍数であればスコア2
// 4の倍数ではないが2の倍数であればスコア1
// 2の倍数でなければスコア0とする
// スコアが要素数以上あれば成立?
int score = 0;
for (int i = 0; i < n; i++) {
if (0 == (a[i] % 4)) {
score += 2;
} else if (0 == (a[i] % 2)) {
score += 1;
} else {
}
}
// N が奇数の場合は スコア>(N-1)で成立
if (0 != (n % 2)) {
score += 1;
}
if (score >= n) {
yes = true;
}
if (yes) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22]]
| 8
| 190
| 31
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpConsoleApp {
class Program {
static int Main() {
var N = int.Parse(Console.ReadLine());
var input =
Console.ReadLine().Split(' ').ToList().Select(a => int.Parse(a));
var fourMen = input.Where(a => a % 4 == 0).Count();
var twoMen = input.Where(a => a % 4 != 0 && a % 2 == 0).Count();
if (fourMen * 2 + twoMen >= (int)(N / 2) + 1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
return 0;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpConsoleApp {
class Program {
static int Main() {
var N = int.Parse(Console.ReadLine());
var input =
Console.ReadLine().Split(' ').ToList().Select(a => int.Parse(a));
var fourMen = input.Where(a => a % 4 == 0).Count();
var twoMen = input.Where(a => a % 4 != 0 && a % 2 == 0).Count();
if (fourMen >= (int)(N / 2))
Console.WriteLine("Yes");
else if (twoMen + fourMen * 2 >= N)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
// var HM = Console.ReadLine().Split(' ').ToList().Select(a =>
// int.Parse(a)).ToArray(); var H = HM[0]; var M = HM[1]; var N =
// Console.ReadLine().Split(' ').Select(a => int.Parse(a)); var aArray =
// Console.ReadLine().Split(' ').ToList().Select(a => int.Parse(a));
// var massL = new List<List<int>>();
// massL.Select(list => list.Select(a => a = H * M + 1));
// aArray.OrderBy(a => a);
return 0;
}
}
}
|
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 74, 51, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22]]
| 8
| 175
| 24
|
using System.Collections.Generic;
using System.Linq;
using System;
class Program {
static void Main() {
var countStr = Console.ReadLine();
int count = int.Parse(countStr);
var line = Console.ReadLine();
string[] array = line.Split(' ');
uint fourM = 0;
uint twoM = 0;
uint notM = 0;
for (int i = 0; i < count; i++) {
int num = int.Parse(array[i]);
if (num % 4 == 0) {
fourM++;
} else {
if (num % 2 == 0) {
twoM++;
} else {
notM++;
}
}
}
fourM += twoM / 2;
notM += twoM % 2;
if (fourM >= notM - 1) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
using System.Collections.Generic;
using System.Linq;
using System;
class Program {
static void Main() {
var countStr = Console.ReadLine();
int count = int.Parse(countStr);
var line = Console.ReadLine();
string[] array = line.Split(' ');
int fourM = 0;
int twoM = 0;
int notM = 0;
for (int i = 0; i < count; i++) {
int num = int.Parse(array[i]);
if (num % 4 == 0) {
fourM++;
} else if (num % 2 == 0) {
twoM++;
} else {
notM++;
}
}
if (twoM > 0)
notM++;
// Console.WriteLine(fourM);
// Console.WriteLine(twoM);
// Console.WriteLine(notM);
if (fourM >= notM - 1) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29]]
| 8
| 190
| 23
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC069 {
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] inputs =
Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
int odd = 0, four = 0, even = 0;
foreach (var item in inputs) {
if (item % 4 == 0)
four++;
else if (item % 2 == 0)
even++;
else
odd++;
}
string result = "No";
if (Math.Abs(four - odd) == 0 || (even == 0 && Math.Abs(four - odd) == 1))
result = "Yes";
Console.WriteLine(result);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace AtCoder.ABC069 {
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] inputs =
Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
int odd = 0, four = 0, even = 0;
foreach (var item in inputs) {
if (item % 4 == 0)
four++;
else if (item % 2 == 0)
even++;
else
odd++;
}
string result = "No";
if (odd - four <= 0 || (even == 0 && odd - four <= 1))
result = "Yes";
Console.WriteLine(result);
}
}
}
|
[["-", 15, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["-", 15, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["-", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["-", 15, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 0, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 12, 23, 0, 16, 12, 16, 31, 16, 17, 33], ["+", 12, 23, 0, 16, 12, 16, 31, 16, 12, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 19]]
| 8
| 196
| 22
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProCon {
class Program {
static void Main(string[] args) {
Console.ReadLine();
string[] input = Console.ReadLine().Split(' ');
int Target = (input.Count());
int N4 = 0;
int N2 = 0;
foreach (string str in input) {
int i = int.Parse(str);
if (i % 4 == 0) {
N4++;
} else if (i % 2 == 0) {
N2++;
}
}
if ((N4 * 2) + N2 >= Target) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProCon {
class Program {
static void Main(string[] args) {
Console.ReadLine();
string[] input = Console.ReadLine().Split(' ');
int Target = (input.Count());
int N4 = 0;
int N2 = 0;
foreach (string str in input) {
int i = int.Parse(str);
if (i % 4 == 0) {
N4++;
} else if (i % 2 == 0) {
N2++;
}
}
if (N4 * 2 + 1 == Target || (N4 * 2) + N2 >= Target) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 48], ["+", 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], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106]]
| 8
| 177
| 8
|
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;
// メンバ変数---
int H;
int W;
int N;
int[] A;
// -------------
void calc() {
H = cin.nextInt();
W = cin.nextInt();
N = cin.nextInt();
A = cin.ArrayInt(N);
List<int> number = new List<int>();
foreach (int a in A) {
for (int i = 0; i < a; i++) {
number.Add(a);
}
}
number.Sort();
// trueのときは左から
bool switchDirect = true;
int idx = 0;
for (int i = 0; i < H; i++) {
int[] print = new int[W];
if (switchDirect) {
for (int j = 0; j < W; j++) {
print[j] = number[idx];
idx++;
}
} else {
for (int j = W - 1; - 1 < j; j--) {
print[j] = number[idx];
idx++;
}
}
switchDirect = !switchDirect;
Console.WriteLine(string.Join(" ", print));
}
}
void Write<T>(T v) { Console.WriteLine(v); }
int Pow(int x, int y) {
return (int)Math.Pow(double.Parse(x.ToString()),
double.Parse(y.ToString()));
}
double Pow(double x, double y) { return Math.Pow(x, y); }
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
class Myon {
public Myon() {}
public static int Main() {
cin = new Scanner();
new Myon().calc();
return 0;
}
static Scanner cin;
// メンバ変数---
int H;
int W;
int N;
int[] A;
// -------------
void calc() {
H = cin.nextInt();
W = cin.nextInt();
N = cin.nextInt();
A = cin.ArrayInt(N);
List<int> number = new List<int>();
for (int j = 0; j < A.Length; j++) {
for (int i = 0; i < A[j]; i++) {
number.Add(j + 1);
}
}
number.Sort();
// trueのときは左から
bool switchDirect = true;
int idx = 0;
for (int i = 0; i < H; i++) {
int[] print = new int[W];
if (switchDirect) {
for (int j = 0; j < W; j++) {
print[j] = number[idx];
idx++;
}
} else {
for (int j = W - 1; - 1 < j; j--) {
print[j] = number[idx];
idx++;
}
}
switchDirect = !switchDirect;
Console.WriteLine(string.Join(" ", print));
}
}
void Write<T>(T v) { Console.WriteLine(v); }
int Pow(int x, int y) {
return (int)Math.Pow(double.Parse(x.ToString()),
double.Parse(y.ToString()));
}
double Pow(double x, double y) { return Math.Pow(x, y); }
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 0, 210, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 204, 205, 22], ["+", 0, 7, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 7, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 743
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC068 {
class Program {
static void Main(string[] args) {
int a, n;
n = int.Parse(Console.ReadLine());
a = n;
Console.WriteLine(a + "ABC");
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC068 {
class Program {
static void Main(string[] args) {
int n;
n = int.Parse(Console.ReadLine());
Console.WriteLine("ABC" + n);
Console.ReadKey();
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 85
| 10
|
using System;
using System.Collections.Generic;
class program {
static void Main(string[] args) {
int n = Convert.ToInt16(Console.ReadLine());
List<List<int>> lst = new List<List<int>>();
for (int i = 0; i < n; i++) {
lst.Add(new List<int>());
}
int i_target = 0;
int i_tCnt = 0;
int start = (n % 2 != 0 ? n - 1 : n);
for (int i = start; i > 0; i--) {
i_target = i;
for (int j = 1; j <= i; j++) {
if (calc(i_target)) {
lst[i - 1].Add(j);
break;
}
i_target = i_target / 2;
}
i--;
}
int count = 0;
int num = 0;
for (int i = 0; i < lst.Count; i++) {
if (lst[i].Count > 0) {
if (count < lst[i][0]) {
count = lst[i][0];
num = i + 1;
}
}
}
Console.WriteLine(num);
}
public static bool calc(int i) {
bool ret = true;
if (i % 2 == 0) {
ret = false;
}
return ret;
}
}
|
using System;
using System.Collections.Generic;
class program {
static void Main(string[] args) {
int n = Convert.ToInt16(Console.ReadLine());
List<List<int>> lst = new List<List<int>>();
for (int i = 0; i < n; i++) {
lst.Add(new List<int>());
}
int i_target = 0;
int i_tCnt = 0;
int start = (n % 2 != 0 ? n - 1 : n);
for (int i = start; i > 0; i--) {
i_target = i;
for (int j = 1; j <= i; j++) {
if (calc(i_target)) {
lst[i - 1].Add(j);
break;
}
i_target = i_target / 2;
}
i--;
}
int count = 0;
int num = 0;
for (int i = 0; i < lst.Count; i++) {
if (lst[i].Count > 0) {
if (count < lst[i][0]) {
count = lst[i][0];
num = i + 1;
}
}
}
if (num == 0) {
num = n;
}
Console.WriteLine(num);
}
public static bool calc(int i) {
bool ret = true;
if (i % 2 == 0) {
ret = false;
}
return ret;
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 293
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var n = ReadInt();
if (64 <= n) {
WriteLine(64);
} else if (32 <= n) {
WriteLine(32);
} else if (16 <= n) {
WriteLine(16);
} else if (8 <= n) {
WriteLine(8);
} else if (4 <= n) {
WriteLine(4);
} else if (2 <= n) {
WriteLine(2);
} else {
WriteLine(0);
}
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
//最大公約数
public static int Gcd(int a, int b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
var reminder = a % b;
a = b;
b = reminder;
}
return a;
}
//最小公倍数
public static int Lcm(int a, int b) { return a * b / Gcd(a, b); }
//文字数を数える
public static int CountChar(string s, char c) {
return s.Length - s.Replace(c.ToString(), "").Length;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtCoder {
class Program {
static void Main(string[] args) {
var n = ReadInt();
if (64 <= n) {
WriteLine(64);
} else if (32 <= n) {
WriteLine(32);
} else if (16 <= n) {
WriteLine(16);
} else if (8 <= n) {
WriteLine(8);
} else if (4 <= n) {
WriteLine(4);
} else if (2 <= n) {
WriteLine(2);
} else if (1 <= n) {
WriteLine(1);
} else {
WriteLine(0);
}
}
private static string Read() { return ReadLine(); }
private static string[] Reads() { return (Read().Split()); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
//最大公約数
public static int Gcd(int a, int b) {
if (a < b) {
return Gcd(b, a);
}
while (b != 0) {
var reminder = a % b;
a = b;
b = reminder;
}
return a;
}
//最小公倍数
public static int Lcm(int a, int b) { return a * b / Gcd(a, b); }
//文字数を数える
public static int CountChar(string s, char c) {
return s.Length - s.Replace(c.ToString(), "").Length;
}
}
}
|
[["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 31, 203], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 19], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 95]]
| 8
| 438
| 14
|
using System;
using System.Linq;
class Challenge {
static void Main() {
var N = int.Parse(Console.ReadLine());
var count_N = new int[N + 1];
for (int i = 1; i <= N; i++) {
var x = i;
var count = 0;
while (x % 2 == 0) {
x /= 2;
count++;
}
count_N[i] = count;
}
Console.WriteLine(Array.IndexOf(count_N, count_N.Max()));
}
}
|
using System;
using System.Linq;
class Challenge {
static void Main() {
var N = int.Parse(Console.ReadLine());
if (N == 1) {
Console.WriteLine("1");
return;
}
var count_N = new int[N + 1];
for (int i = 1; i <= N; i++) {
var x = i;
var count = 0;
while (x % 2 == 0) {
x /= 2;
count++;
}
count_N[i] = count;
}
Console.WriteLine(Array.IndexOf(count_N, count_N.Max()));
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 112
| 19
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
int kazu = int.Parse(ReadLine());
int[] ans = new int[2];
for (int i = 1; i <= kazu; i++) {
int k = i;
int count = 0;
for (int j = 0; j < 10; j++) {
if (k % 2 == 0) {
k /= 2;
count++;
} else {
break;
}
}
if (count > ans[0]) {
ans[0] = count;
ans[1] = i;
}
}
WriteLine("{0}", ans[1]);
}
}
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
int kazu = int.Parse(ReadLine());
int[] ans = new int[2];
ans[1] = 1;
for (int i = 1; i <= kazu; i++) {
int k = i;
int count = 0;
for (int j = 0; j < 10; j++) {
if (k % 2 == 0) {
k /= 2;
count++;
} else {
break;
}
}
if (count > ans[0]) {
ans[0] = count;
ans[1] = i;
}
}
WriteLine("{0}", ans[1]);
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 152
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
class P {
public int index;
public List<int> ad;
public bool isPass;
public P(int index) {
this.index = index;
ad = new List<int>();
}
}
static void Main(string[] args) {
var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var ps = new P[nm[0]];
for (var i = 0; i < nm[0]; i++)
ps[i] = new P(i);
for (var i = 0; i < nm[1]; i++) {
var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
ps[input[0] - 1].ad.Add(input[1] - 1);
}
var isGoal = false;
dfs(ps, nm[0], 0, ref isGoal, new HashSet<int>());
WriteLine(isGoal ? "POSSIBLE" : "IMPOSSIBLE");
}
private static void dfs(P[] ps, int num, int index, ref bool isGoal,
HashSet<int> set) {
if (index == num - 1) {
isGoal = true;
return;
}
foreach (var p in ps[index].ad) {
if (!set.Contains(p) && !isGoal)
dfs(ps, num, p, ref isGoal, set);
}
}
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;
class Program {
class P {
public int index;
public List<int> ad;
public P(int index) {
this.index = index;
ad = new List<int>();
}
}
static void Main(string[] args) {
var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var ps = new P[nm[0]];
for (var i = 0; i < nm[0]; i++)
ps[i] = new P(i);
for (var i = 0; i < nm[1]; i++) {
var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
ps[input[0] - 1].ad.Add(input[1] - 1);
}
var isGoal = false;
dfs(ps, nm[0], 0, 0, ref isGoal, new HashSet<int>());
WriteLine(isGoal ? "POSSIBLE" : "IMPOSSIBLE");
}
private static void dfs(P[] ps, int num, int index, int depth,
ref bool isGoal, HashSet<int> set) {
if (index == num - 1) {
isGoal = true;
return;
} else if (depth == 2)
return;
foreach (var p in ps[index].ad) {
if (!set.Contains(p) && !isGoal)
dfs(ps, num, p, depth + 1, ref isGoal, set);
}
}
private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
private const int MOD = 1000000007;
}
|
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 263, 0, 251, 0, 259], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 37, 0, 38], ["+", 8, 196, 0, 57, 75, 57, 64, 37, 0, 35], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 360
| 22
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
var max = a.Sum();
for (long opCount = a.Sum(x => Max(0, x - (n - 1))); opCount <= max;
opCount++) {
if (a.Sum(x => (x + opCount) / (n + 1) +
((x + opCount) % (n + 1) == n ? 1 : 0)) == opCount) {
Console.WriteLine(opCount);
return;
}
}
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
var max = a.Sum();
for (long opCount = Max(0, a.Sum(x => x - (n - 1))); opCount <= max;
opCount++) {
if (a.Sum(x => (x + opCount) / (n + 1) +
((x + opCount) % (n + 1) == n ? 1 : 0)) == opCount) {
Console.WriteLine(opCount);
return;
}
}
}
}
|
[["+", 10, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 218, 8, 213, 63, 22], ["-", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["-", 0, 218, 8, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 28, 0, 218, 8, 213, 3, 4, 0, 21]]
| 8
| 244
| 8
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
// Console.WriteLine(ret);
new StreamWriter(Console.OpenStandardOutput()).Write(ret);
#endif
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var n = int.Parse(spl[0]);
var k = int.Parse(spl[1]);
var ary = ToIntArray(input.ReadLine(), n);
Array.Sort(ary);
long min = long.MaxValue;
for (int i = 1; i < n; i++) {
var v = ary[i] - ary[i - 1];
if (v != 0 && v < min)
min = v;
}
foreach (var x in ary) {
if (x >= k) {
if ((x - k) % min == 0)
return "POSSIBLE";
}
}
return "IMPOSSIBLE";
}
static int[] ToIntArray(string strs, int n) {
var ret = new int[n];
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
#if DEBUG
MyDebugger.Test(process, "../TextFile1.txt");
#else
object ret = process(new StreamReader(Console.OpenStandardInput()));
Console.WriteLine(ret);
;
#endif
}
static object process(TextReader input) {
var spl = input.ReadLine().Split(' ');
var n = int.Parse(spl[0]);
var k = int.Parse(spl[1]);
var ary = ToIntArray(input.ReadLine(), n);
Array.Sort(ary);
long min = long.MaxValue;
for (int i = 1; i < n; i++) {
var v = ary[i] - ary[i - 1];
if (v != 0 && v < min)
min = v;
}
foreach (var x in ary) {
if (x >= k) {
if ((x - k) % min == 0)
return "POSSIBLE";
}
}
return "IMPOSSIBLE";
}
static int[] ToIntArray(string strs, int n) {
var ret = new int[n];
var spl = strs.Split(' ');
for (int i = 0; i < n; i++)
ret[i] = int.Parse(spl[i]);
return ret;
}
}
|
[["-", 0, 1, 0, 213, 63, 214, 205, 230, 0, 228], ["-", 0, 1, 0, 213, 63, 214, 205, 230, 39, 22], ["-", 0, 213, 63, 214, 205, 230, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 213, 63, 214, 205, 230, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 325
| 11
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
int[] NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int max = a[0];
int difgcd = 0;
for (int i = 1; i < a.Length; i++) {
max = Math.Max(max, a[i]);
difgcd = Gcd(Math.Abs(a[i] - a[i - 1]), difgcd);
}
string res = "POSSIBLE";
if (max >= NK[1] && (max - NK[1]) % difgcd == 0) {
Console.WriteLine(res);
} else {
Console.WriteLine("IM" + res);
}
}
public static int Gcd(int a, int b) {
if (a < b)
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
int[] NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int max = a[0];
int difgcd = 0;
for (int i = 1; i < a.Length; i++) {
max = Math.Max(max, a[i]);
difgcd = Gcd(Math.Abs(a[i] - a[i - 1]), difgcd);
}
string res = "POSSIBLE";
if (difgcd == 0) {
if (NK[1] == max)
Console.WriteLine(res);
else
Console.WriteLine("IM" + res);
} else if ((max >= NK[1] && (max - NK[1]) % difgcd == 0)) {
Console.WriteLine(res);
} else {
Console.WriteLine("IM" + res);
}
}
public static int Gcd(int a, int b) {
if (a < b)
return Gcd(b, a);
while (b != 0) {
var remainder = a % b;
a = b;
b = remainder;
}
return a;
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 75, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 23, 0, 24], ["+", 75, 57, 15, 23, 0, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 23, 0, 25]]
| 8
| 252
| 39
|
using System;
using System.Linq;
namespace agc018_a {
class Program {
static void Main(string[] args) {
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
if (x[1] > a.Max())
Console.WriteLine("IMPOSSIBLE");
else {
Array.Sort(a);
int n1 = a[0];
int n2 = a[1];
for (int i = 1; i < x[0]; i++) {
n2 = a[i];
while (n1 != 0) {
int now = n2 % n1;
n2 = n1;
n1 = now;
}
n1 = n2;
}
Console.WriteLine(x[1] % n1 == 0 ? "POSSIBLE" : "IMPOSSIBLE");
}
}
}
}
|
using System;
using System.Linq;
namespace agc018_a {
class Program {
static void Main(string[] args) {
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
if (x[0] == 1)
Console.WriteLine(x[1] == a[0] ? "POSSIBLE" : "IMPOSSIBLE");
else if (x[1] > a.Max())
Console.WriteLine("IMPOSSIBLE");
else {
Array.Sort(a);
int n1 = a[0];
int n2 = a[1];
for (int i = 1; i < x[0]; i++) {
n2 = a[i];
while (n1 != 0) {
int now = n2 % n1;
n2 = n1;
n1 = now;
}
n1 = n2;
}
Console.WriteLine(x[1] % n1 == 0 ? "POSSIBLE" : "IMPOSSIBLE");
}
}
}
}
|
[["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 41, 15, 16, 31, 204, 205, 22], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 0, 28, 0, 41, 15, 16, 12, 204, 205, 22], ["+", 0, 41, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 41, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70]]
| 8
| 202
| 33
|
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() {
string[] str = Console.ReadLine().Split(' ');
int N = int.Parse(str[0]);
int M = int.Parse(str[1]);
int[,] A = new int[N, M];
int[,] B = new int[N, M];
for (int i = 0; i < N; i++) {
str = Console.ReadLine().Split(' ');
for (int j = 0; j < M; j++) {
A[i, j] = int.Parse(str[j]) - 1;
B[i, int.Parse(str[j]) - 1] = j;
}
}
int bf = 1;
int bl = N;
while (bf != bl) {
int bc = (bf + bl) / 2;
bool b = true;
{
int[] X = new int[M];
int[] Chosen = new int[N];
for (int i = 0; i < N; i++) {
Chosen[i] = 0;
}
int[] stack = new int[2 * N];
int p = 0;
for (int i = 0; i < N; i++) {
X[B[i, 0]]++;
if (X[B[i, 0]] == bc + 1) {
stack[p] = B[i, 0];
p++;
}
}
bool[] deleted = new bool[M];
while (b && p != 0) {
int C = stack[p - 1];
p--;
deleted[C] = true;
for (int i = 0; i < N; i++) {
if (Chosen[i] == A[i, C]) {
while (Chosen[i] <= M - 1 && deleted[B[i, Chosen[i]]]) {
Chosen[i]++;
}
if (Chosen[i] == M) {
b = false;
break;
} else {
X[B[i, Chosen[i]]]++;
if (X[B[i, Chosen[i]]] == bc + 1) {
stack[p] = B[i, Chosen[i]];
p++;
}
}
}
}
}
}
if (b) {
bl = bc;
} else {
bf = bc + 1;
}
}
sb.Append(bf + "\n");
}
}
|
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() {
string[] str = Console.ReadLine().Split(' ');
int N = int.Parse(str[0]);
int M = int.Parse(str[1]);
int[,] A = new int[N, M];
int[,] B = new int[N, M];
for (int i = 0; i < N; i++) {
str = Console.ReadLine().Split(' ');
for (int j = 0; j < M; j++) {
B[i, j] = int.Parse(str[j]) - 1;
A[i, int.Parse(str[j]) - 1] = j;
}
}
int bf = 1;
int bl = N;
while (bf != bl) {
int bc = (bf + bl) / 2;
bool b = true;
{
int[] X = new int[M];
int[] Chosen = new int[N];
int[] stack = new int[2 * N];
int p = 0;
for (int i = 0; i < N; i++) {
X[B[i, 0]]++;
if (X[B[i, 0]] == bc + 1) {
stack[p] = B[i, 0];
p++;
}
}
bool[] deleted = new bool[M];
while (b && p != 0) {
int C = stack[p - 1];
p--;
deleted[C] = true;
for (int i = 0; i < N; i++) {
if (Chosen[i] == A[i, C]) {
while (Chosen[i] <= M - 1 && deleted[B[i, Chosen[i]]]) {
Chosen[i]++;
}
if (Chosen[i] == M) {
b = false;
break;
} else {
X[B[i, Chosen[i]]]++;
if (X[B[i, Chosen[i]]] == bc + 1) {
stack[p] = B[i, Chosen[i]];
p++;
}
}
}
}
}
}
if (b) {
bl = bc;
} else {
bf = bc + 1;
}
}
sb.Append(bf + "\n");
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 52, 8, 196, 0, 196, 0, 7, 0, 88], ["-", 0, 52, 8, 196, 0, 196, 0, 7, 0, 24], ["-", 8, 196, 0, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 52, 8, 196, 0, 196, 0, 7, 0, 35], ["-", 8, 196, 0, 196, 0, 7, 15, 16, 31, 22], ["-", 8, 196, 0, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 196, 0, 7, 15, 16, 12, 22], ["-", 8, 196, 0, 196, 0, 7, 26, 223, 0, 22], ["-", 8, 196, 0, 196, 0, 7, 26, 223, 0, 29], ["-", 0, 52, 8, 196, 0, 196, 0, 7, 0, 25], ["-", 8, 196, 0, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 611
| 27
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver {
void Swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
public class Heap<T> {
private readonly List<T> data;
private readonly Comparison<T> compare;
public Heap(Comparison<T> compare) {
this.compare = compare;
data = new List<T> { default(T) };
}
public int Count {
get { return data.Count - 1; }
}
public T Peek() { return data[1]; }
public void Push(T item) {
data.Add(item);
var curPlace = Count;
while (curPlace > 1 && compare(item, data[curPlace / 2]) < 0) {
data[curPlace] = data[curPlace / 2];
data[curPlace / 2] = item;
curPlace /= 2;
}
}
public T Pop() {
var ret = data[1];
data[1] = data[Count];
data.RemoveAt(Count);
var curPlace = 1;
while (true) {
var max = curPlace;
if (Count >= curPlace * 2 && compare(data[max], data[2 * curPlace]) > 0)
max = 2 * curPlace;
if (Count >= curPlace * 2 + 1 &&
compare(data[max], data[2 * curPlace + 1]) > 0)
max = 2 * curPlace + 1;
if (max == curPlace)
break;
var item = data[max];
data[max] = data[curPlace];
data[curPlace] = item;
curPlace = max;
}
return ret;
}
}
public void Solve() {
var c = ReadIntArray();
int n = c.Sum();
var a = ReadAndTransposeIntMatrix(n);
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 3; j++)
if (c[i] < c[j]) {
Swap(ref c[i], ref c[j]);
Swap(ref a[i], ref a[j]);
}
var b = new int [n][];
for (int i = 0; i < n; i++)
b[i] = new[] { a[0][i], a[1][i], a[2][i] };
Array.Sort(b, (b1, b2) => (b2[1] - b2[0]).CompareTo(b1[1] - b1[0]));
long v = 0;
for (int i = 0; i < c[1]; i++)
v += b[i][1];
var f = new bool[n];
var qr = new Heap<int>(
(x1, x2) => (b[x1][2] - b[x1][0]).CompareTo(b[x2][2] - b[x2][0]));
for (int i = c[1]; i < n; i++) {
f[i] = true;
v += b[i][2];
qr.Push(i);
}
while (qr.Count > c[2]) {
int x = qr.Pop();
f[x] = false;
v -= b[x][2] - b[x][0];
}
long ans = v;
var ql = new Heap<int>(
(x1, x2) => (b[x2][2] - b[x2][1]).CompareTo(b[x1][2] - b[x1][1]));
for (int i = 0; i < c[1]; i++)
ql.Push(i);
for (int i = 1; i <= c[2]; i++) {
int j = c[1] + i - 1;
if (f[j])
v += b[j][1] - b[j][2];
else
v += b[j][1] - b[j][0];
int x = qr.Pop();
if (x > j) {
v += b[x][0] - b[x][2];
f[x] = false;
}
ql.Push(j);
x = ql.Pop();
v += b[x][2] - b[x][1];
ans = Math.Max(ans, v);
}
Write(ans);
}
#region Main
protected static TextReader reader;
protected static TextWriter writer;
static void Main() {
#if DEBUG
reader = new StreamReader("..\\..\\input.txt");
// reader = new StreamReader(Console.OpenStandardInput());
writer = Console.Out;
// writer = new StreamWriter("..\\..\\output.txt");
#else
reader = new StreamReader(Console.OpenStandardInput());
writer = new StreamWriter(Console.OpenStandardOutput());
// reader = new StreamReader("input.txt");
// writer = new StreamWriter("output.txt");
#endif
try {
new Solver().Solve();
// var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
// thread.Start();
// thread.Join();
} catch (Exception ex) {
#if DEBUG
Console.WriteLine(ex);
#else
throw;
#endif
}
reader.Close();
writer.Close();
}
#endregion
#region Read / Write
private static Queue<string> currentLineTokens = new Queue<string>();
private static string[] ReadAndSplitLine() {
return reader.ReadLine().Split(
new[] {
' ',
'\t',
},
StringSplitOptions.RemoveEmptyEntries);
}
public static string ReadToken() {
while (currentLineTokens.Count == 0)
currentLineTokens = new Queue<string>(ReadAndSplitLine());
return currentLineTokens.Dequeue();
}
public static int ReadInt() { return int.Parse(ReadToken()); }
public static long ReadLong() { return long.Parse(ReadToken()); }
public static double ReadDouble() {
return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
}
public static int[] ReadIntArray() {
return ReadAndSplitLine().Select(int.Parse).ToArray();
}
public static long[] ReadLongArray() {
return ReadAndSplitLine().Select(long.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
return ReadAndSplitLine()
.Select(s => double.Parse(s, CultureInfo.InvariantCulture))
.ToArray();
}
public static int[][] ReadIntMatrix(int numberOfRows) {
int[][] matrix = new int [numberOfRows][];
for (int i = 0; i < numberOfRows; i++)
matrix[i] = ReadIntArray();
return matrix;
}
public static int[][] ReadAndTransposeIntMatrix(int numberOfRows) {
int[][] matrix = ReadIntMatrix(numberOfRows);
int[][] ret = new int[matrix[0].Length][];
for (int i = 0; i < ret.Length; i++) {
ret[i] = new int[numberOfRows];
for (int j = 0; j < numberOfRows; j++)
ret[i][j] = matrix[j][i];
}
return ret;
}
public static string[] ReadLines(int quantity) {
string[] lines = new string[quantity];
for (int i = 0; i < quantity; i++)
lines[i] = reader.ReadLine().Trim();
return lines;
}
public static void WriteArray<T>(IEnumerable<T> array) {
writer.WriteLine(string.Join(" ", array));
}
public static void Write(params object[] array) { WriteArray(array); }
public static void WriteLines<T>(IEnumerable<T> array) {
foreach (var a in array)
writer.WriteLine(a);
}
private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue> {
public new TValue this[TKey key] {
get { return ContainsKey(key) ? base[key] : default(TValue);
}
set { base[key] = value; }
}
}
private static T[] Init<T>(int size)
where T : new() {
var ret = new T[size];
for (int i = 0; i < size; i++)
ret[i] = new T();
return ret;
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
// (づ°ω°)づミe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver {
void Swap<T>(ref T a, ref T b) {
T t = a;
a = b;
b = t;
}
public class Heap<T> {
private readonly List<T> data;
private readonly Comparison<T> compare;
public Heap(Comparison<T> compare) {
this.compare = compare;
data = new List<T> { default(T) };
}
public int Count {
get { return data.Count - 1; }
}
public T Peek() { return data[1]; }
public void Push(T item) {
data.Add(item);
var curPlace = Count;
while (curPlace > 1 && compare(item, data[curPlace / 2]) < 0) {
data[curPlace] = data[curPlace / 2];
data[curPlace / 2] = item;
curPlace /= 2;
}
}
public T Pop() {
var ret = data[1];
data[1] = data[Count];
data.RemoveAt(Count);
var curPlace = 1;
while (true) {
var max = curPlace;
if (Count >= curPlace * 2 && compare(data[max], data[2 * curPlace]) > 0)
max = 2 * curPlace;
if (Count >= curPlace * 2 + 1 &&
compare(data[max], data[2 * curPlace + 1]) > 0)
max = 2 * curPlace + 1;
if (max == curPlace)
break;
var item = data[max];
data[max] = data[curPlace];
data[curPlace] = item;
curPlace = max;
}
return ret;
}
}
public void Solve() {
var c = ReadIntArray();
int n = c.Sum();
var a = ReadAndTransposeIntMatrix(n);
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 3; j++)
if (c[i] < c[j]) {
Swap(ref c[i], ref c[j]);
Swap(ref a[i], ref a[j]);
}
var b = new int [n][];
for (int i = 0; i < n; i++)
b[i] = new[] { a[0][i], a[1][i], a[2][i] };
Array.Sort(b, (b1, b2) => (b2[1] - b2[0]).CompareTo(b1[1] - b1[0]));
long v = 0;
for (int i = 0; i < c[1]; i++)
v += b[i][1];
var f = new bool[n];
var qr = new Heap<int>(
(x1, x2) => (b[x1][2] - b[x1][0]).CompareTo(b[x2][2] - b[x2][0]));
for (int i = c[1]; i < n; i++) {
f[i] = true;
v += b[i][2];
qr.Push(i);
}
while (qr.Count > c[2]) {
int x = qr.Pop();
f[x] = false;
v -= b[x][2] - b[x][0];
}
long ans = v;
var ql = new Heap<int>(
(x1, x2) => (b[x2][2] - b[x2][1]).CompareTo(b[x1][2] - b[x1][1]));
for (int i = 0; i < c[1]; i++)
ql.Push(i);
for (int i = 1; i <= c[2]; i++) {
int j = c[1] + i - 1;
int x;
if (f[j]) {
v += b[j][1] - b[j][2];
f[j] = false;
} else {
v += b[j][1] - b[j][0];
x = qr.Pop();
while (!f[x]) {
x = qr.Pop();
}
v += b[x][0] - b[x][2];
f[x] = false;
}
ql.Push(j);
x = ql.Pop();
v += b[x][2] - b[x][1];
ans = Math.Max(ans, v);
}
Write(ans);
}
#region Main
protected static TextReader reader;
protected static TextWriter writer;
static void Main() {
#if DEBUG
reader = new StreamReader("..\\..\\input.txt");
// reader = new StreamReader(Console.OpenStandardInput());
writer = Console.Out;
// writer = new StreamWriter("..\\..\\output.txt");
#else
reader = new StreamReader(Console.OpenStandardInput());
writer = new StreamWriter(Console.OpenStandardOutput());
// reader = new StreamReader("input.txt");
// writer = new StreamWriter("output.txt");
#endif
try {
new Solver().Solve();
// var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
// thread.Start();
// thread.Join();
} catch (Exception ex) {
#if DEBUG
Console.WriteLine(ex);
#else
throw;
#endif
}
reader.Close();
writer.Close();
}
#endregion
#region Read / Write
private static Queue<string> currentLineTokens = new Queue<string>();
private static string[] ReadAndSplitLine() {
return reader.ReadLine().Split(
new[] {
' ',
'\t',
},
StringSplitOptions.RemoveEmptyEntries);
}
public static string ReadToken() {
while (currentLineTokens.Count == 0)
currentLineTokens = new Queue<string>(ReadAndSplitLine());
return currentLineTokens.Dequeue();
}
public static int ReadInt() { return int.Parse(ReadToken()); }
public static long ReadLong() { return long.Parse(ReadToken()); }
public static double ReadDouble() {
return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
}
public static int[] ReadIntArray() {
return ReadAndSplitLine().Select(int.Parse).ToArray();
}
public static long[] ReadLongArray() {
return ReadAndSplitLine().Select(long.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
return ReadAndSplitLine()
.Select(s => double.Parse(s, CultureInfo.InvariantCulture))
.ToArray();
}
public static int[][] ReadIntMatrix(int numberOfRows) {
int[][] matrix = new int [numberOfRows][];
for (int i = 0; i < numberOfRows; i++)
matrix[i] = ReadIntArray();
return matrix;
}
public static int[][] ReadAndTransposeIntMatrix(int numberOfRows) {
int[][] matrix = ReadIntMatrix(numberOfRows);
int[][] ret = new int[matrix[0].Length][];
for (int i = 0; i < ret.Length; i++) {
ret[i] = new int[numberOfRows];
for (int j = 0; j < numberOfRows; j++)
ret[i][j] = matrix[j][i];
}
return ret;
}
public static string[] ReadLines(int quantity) {
string[] lines = new string[quantity];
for (int i = 0; i < quantity; i++)
lines[i] = reader.ReadLine().Trim();
return lines;
}
public static void WriteArray<T>(IEnumerable<T> array) {
writer.WriteLine(string.Join(" ", array));
}
public static void Write(params object[] array) { WriteArray(array); }
public static void WriteLines<T>(IEnumerable<T> array) {
foreach (var a in array)
writer.WriteLine(a);
}
private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue> {
public new TValue this[TKey key] {
get { return ContainsKey(key) ? base[key] : default(TValue);
}
set { base[key] = value; }
}
}
private static T[] Init<T>(int size)
where T : new() {
var ret = new T[size];
for (int i = 0; i < size; i++)
ret[i] = new T();
return ret;
}
#endregion
}
|
[["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 89], ["+", 0, 57, 75, 196, 0, 52, 15, 241, 0, 111], ["+", 75, 196, 0, 52, 15, 241, 0, 204, 205, 22], ["+", 0, 52, 15, 241, 0, 204, 206, 207, 0, 70], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 52, 15, 241, 0, 204, 206, 207, 0, 73], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 52, 8, 196, 0, 46]]
| 8
| 1,789
| 31
|
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 result = "Impossible";
if ((n[0] + n[1]) % 3 == 0) {
result = "Possible";
}
Console.WriteLine(result);
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 result = "Impossible";
if (((n[0] + n[1]) % 3 == 0) || n[0] % 3 == 0 || n[1] % 3 == 0) {
result = "Possible";
}
Console.WriteLine(result);
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();
}
}
}
|
[["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 17, 109], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 60], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 31, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22]]
| 8
| 280
| 20
|
using System;
class p {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
Console.WriteLine((A * B) % 3 == 0 ? "Possible" : "Impossible");
}
}
|
using System;
class p {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
Console.WriteLine(((A * B) % 3 == 0) || ((A + B) % 3 == 0) ? "Possible"
: "Impossible");
}
}
|
[["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 41, 15, 16, 31, 23, 0, 16, 17, 60], ["+", 0, 41, 15, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 41, 15, 16, 31, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 106], ["+", 0, 28, 0, 41, 15, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 41, 15, 16, 12, 23, 0, 25]]
| 8
| 81
| 14
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var Box = Console.ReadLine();
var Each = Box.Split(' ');
int A, B, num;
A = int.Parse(Each[0]);
B = int.Parse(Each[1]);
num = A + B;
if ((int)A / 3 == A / 3 || (int)B / 3 == B / 3 || (int)num / 3 == num / 3) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Impossible");
}
Console.ReadLine();
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
var Box = Console.ReadLine();
var Each = Box.Split(' ');
int A, B, num;
A = int.Parse(Each[0]);
B = int.Parse(Each[1]);
num = A + B;
if (A % 3 == 0 || B % 3 == 0 || num % 3 == 0) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Impossible");
}
Console.ReadLine();
}
}
|
[["-", 31, 16, 31, 16, 31, 16, 31, 74, 0, 24], ["-", 31, 16, 31, 16, 31, 16, 31, 74, 39, 199], ["-", 31, 16, 31, 16, 31, 16, 31, 74, 0, 25], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 85], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 17, 85], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 31, 16, 12, 16, 31, 16, 31, 74, 0, 24], ["-", 31, 16, 12, 16, 31, 16, 31, 74, 39, 199], ["-", 31, 16, 12, 16, 31, 16, 31, 74, 0, 25], ["-", 15, 16, 31, 16, 12, 16, 31, 16, 17, 85], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["-", 15, 16, 31, 16, 12, 16, 12, 16, 31, 22], ["-", 15, 16, 31, 16, 12, 16, 12, 16, 17, 85], ["-", 15, 16, 31, 16, 12, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 15, 16, 12, 16, 31, 16, 31, 74, 0, 24], ["-", 15, 16, 12, 16, 31, 16, 31, 74, 39, 199], ["-", 15, 16, 12, 16, 31, 16, 31, 74, 0, 25], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 147
| 27
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
if ((str[0] + str[1]) % 3 == 0) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Impossible");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ziyuutyou {
class Program {
static void Main(string[] args) {
var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
if ((str[0] + str[1]) % 3 == 0 || str[0] % 3 == 0 || str[1] % 3 == 0) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Impossible");
}
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 31, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 100
| 18
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Solver {
Scanner sc = new Scanner();
public void Solve() {
int A = sc.nextInt();
int B = sc.nextInt();
if ((A + B) % 3 == 0) {
WriteLine("Possible");
} else {
WriteLine("Impossible");
}
}
}
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;
}
}
class Program {
static void Main(string[] args) {
Solver s = new Solver();
s.Solve();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Solver {
Scanner sc = new Scanner();
public void Solve() {
int A = sc.nextInt();
int B = sc.nextInt();
if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
WriteLine("Possible");
} else {
WriteLine("Impossible");
}
}
}
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;
}
}
class Program {
static void Main(string[] args) {
Solver s = new Solver();
s.Solve();
}
}
|
[["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106]]
| 8
| 468
| 12
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
string ans = "Impossible";
int sum = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).Sum();
if (sum % 3 == 0) {
ans = "Possible";
}
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 = @"
4 5
";
}
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() {
string ans = "Impossible";
int[] num =
Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
if (num.Sum() % 3 == 0 || num.Any(a => a % 3 == 0)) {
ans = "Possible";
}
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 = @"
4 5
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 17, 109], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 211
| 25
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtheleteProgramming3 {
class Program {
static void Main(string[] args) {
int[] ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int a = ab[0];
int b = ab[1];
if ((a + b) % 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 AtheleteProgramming3 {
class Program {
static void Main(string[] args) {
int[] ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int a = ab[0];
int b = ab[1];
if ((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0) {
Console.WriteLine("Possible");
} else {
Console.WriteLine("Impossible");
}
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 126
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AIZU {
class Program {
#region Reserve
static int cin() { return cin(-1); }
static int cin(int D) {
string s = Console.ReadLine();
if (string.IsNullOrEmpty(s))
return D;
return int.Parse(s);
}
static int[] cins(char spliter) {
string s = Console.ReadLine();
if (string.IsNullOrEmpty(s))
return new int[] {};
string[] ss = s.Split(spliter);
int[] Res = new int[ss.Length];
for (int i = 0; i < ss.Length; i++)
Res[i] = int.Parse(ss[i]);
return Res;
}
static int[] cins() { return cins(' '); }
static void print(object j) { Console.WriteLine(j.ToString()); }
static void print(string j) { Console.WriteLine(j); }
#endregion
static void Main(string[] args) {
int a = cin(), b = cin();
bool res = a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0;
print(res ? "Possible" : "Impossible");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AIZU {
class Program {
#region Reserve
static int cin() { return cin(-1); }
static int cin(int D) {
string s = Console.ReadLine();
if (string.IsNullOrEmpty(s))
return D;
return int.Parse(s);
}
static int[] cins(char spliter) {
string s = Console.ReadLine();
if (string.IsNullOrEmpty(s))
return new int[] {};
string[] ss = s.Split(spliter);
int[] Res = new int[ss.Length];
for (int i = 0; i < ss.Length; i++)
Res[i] = int.Parse(ss[i]);
return Res;
}
static int[] cins() { return cins(' '); }
static void print(object j) { Console.WriteLine(j.ToString()); }
static void print(string j) { Console.WriteLine(j); }
#endregion
static void Main(string[] args) {
int[] I = cins();
int a = I[0], b = I[1];
bool res = a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0;
print(res ? "Possible" : "Impossible");
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 296
| 21
|
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("4 5");
// Possible
} else if (InputPattern == "Input2") {
WillReturn.Add("1 1");
// Impossible
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
List<string> InputList = GetInputList();
int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
int A = wkArr[0];
int B = wkArr[1];
if ((A + B) % 3 == 0)
Console.WriteLine("Possible");
else
Console.WriteLine("Impossible");
}
}
|
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("4 5");
// Possible
} else if (InputPattern == "Input2") {
WillReturn.Add("1 1");
// Impossible
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
List<string> InputList = GetInputList();
int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
int A = wkArr[0];
int B = wkArr[1];
if ((A) % 3 == 0)
Console.WriteLine("Possible");
else if ((B) % 3 == 0)
Console.WriteLine("Possible");
else if ((A + B) % 3 == 0)
Console.WriteLine("Possible");
else
Console.WriteLine("Impossible");
}
}
|
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 75, 57, 15, 16, 31, 16, 31, 23, 0, 22], ["+", 75, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22]]
| 8
| 216
| 40
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
string[] line = Console.ReadLine().Split(' ');
int[] sticks = new int[2];
sticks[0] = int.Parse(line[0]);
sticks[1] = int.Parse(line[1]);
List<int> list = new List<int>();
string[] line2 = Console.ReadLine().Split(' ');
for (int i = 0; i < sticks[0]; i++) {
int num = int.Parse(line2[i]);
list.Add(num);
if (list.Count > sticks[1]) {
list.Sort();
list.Remove(list[0]);
}
}
int sum = 0;
for (int i = 0; i < list.Count; i++) {
sum += list[i];
Console.WriteLine(list[i]);
}
Console.WriteLine(sum.ToString());
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
string[] line = Console.ReadLine().Split(' ');
int[] sticks = new int[2];
sticks[0] = int.Parse(line[0]);
sticks[1] = int.Parse(line[1]);
List<int> list = new List<int>();
string[] line2 = Console.ReadLine().Split(' ');
for (int i = 0; i < sticks[0]; i++) {
int num = int.Parse(line2[i]);
list.Add(num);
if (list.Count > sticks[1]) {
list.Sort();
list.Remove(list[0]);
}
}
int sum = 0;
for (int i = 0; i < list.Count; i++) {
sum += list[i];
}
Console.WriteLine(sum.ToString());
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 240
| 10
|
using System;
using System.Linq;
namespace ABC067 {
class C {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] S = new int[N + 1];
for (int i = 0; i < N; i++) {
S[i + 1] = S[i] + a[i];
}
int res = int.MaxValue;
for (int i = 1; i < N; i++) {
int x = S[N] - S[i];
int y = S[i];
res = Math.Min(res, Math.Abs(x - y));
}
Console.WriteLine(res);
}
}
}
|
using System;
using System.Linq;
namespace ABC067 {
class C {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
long[] S = new long[N + 1];
for (long i = 0; i < N; i++) {
S[i + 1] = S[i] + a[i];
}
long res = long.MaxValue;
for (long i = 1; i < N; i++) {
long x = S[N] - S[i];
long y = S[i];
res = Math.Min(res, Math.Abs(x - y));
}
Console.WriteLine(res);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 182
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public static void Main(string[] args) {
int n = Console.ReadLine().ToInt();
var a = Input().ToInt();
long rightsum = a.Sum();
long leftsum = 0;
long min = 9999999999;
for (int i = 0; i < n - 1; i++) {
leftsum += a[i];
rightsum -= a[i];
min = Math.Min(min, Math.Abs(leftsum - rightsum));
}
Console.WriteLine(min);
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
int[] r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public static void Main(string[] args) {
int n = Console.ReadLine().ToInt();
var a = Input().ToInt();
long rightsum = 0;
for (int i = 0; i < n; i++)
rightsum += a[i];
long leftsum = 0;
long min = 9999999999;
for (int i = 0; i < n - 1; i++) {
leftsum += a[i];
rightsum -= a[i];
min = Math.Min(min, Math.Abs(leftsum - rightsum));
}
Console.WriteLine(min);
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
int[] r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 7, 8, 1, 0, 11, 12, 204, 205, 22], ["+", 8, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
| 8
| 371
| 23
|
using System;
using System.Linq;
public class Problem_C {
public static void Main() {
var N = int.Parse(Console.ReadLine());
var deck = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
long total = deck.Sum();
long snuke = 0;
long minDiff = int.MaxValue;
for (var i = 0; i < N - 1; i++) {
snuke += deck[i];
minDiff = Math.Min(minDiff, Math.Abs(snuke - (total - snuke)));
}
Console.WriteLine($"{minDiff}");
}
}
|
using System;
using System.Linq;
public class Problem_C {
public static void Main() {
var N = int.Parse(Console.ReadLine());
var deck = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
long total = 0;
foreach (var n in deck)
total += n;
long snuke = 0;
long minDiff = long.MaxValue;
for (var i = 0; i < N - 1; i++) {
snuke += deck[i];
minDiff = Math.Min(minDiff, Math.Abs(snuke - (total - snuke)));
}
Console.WriteLine($"{minDiff}");
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 196, 0, 210, 8, 1, 0, 11, 31, 22], ["+", 0, 210, 8, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 210, 8, 1, 0, 11, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199]]
| 8
| 136
| 15
|
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) {
// string a = Console.ReadLine();
long n = Read.Int();
long[] a = Read.ints();
Array.Sort(a);
long x = a.Sum(), y = 0;
long yabaisa = int.MaxValue;
for (long i = 0; i < a.Length; i++) {
x -= a[i];
y += a[i];
if (i != a.Length - 1) {
yabaisa = Math.Min(yabaisa, Math.Abs(x - y));
}
}
Console.WriteLine(yabaisa);
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 long[] ints() {
return Console.ReadLine().Split().Select(long.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) {
// string a = Console.ReadLine();
long n = Read.Int();
long[] a = Read.ints();
long x = a.Sum(), y = 0;
long yabaisa = int.MaxValue;
for (long i = 0; i < a.Length; i++) {
x -= a[i];
y += a[i];
if (i != a.Length - 1) {
yabaisa = Math.Min(yabaisa, Math.Abs(x - y));
}
}
Console.WriteLine(yabaisa);
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 long[] ints() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static string Str() { return Console.ReadLine(); }
public static string[] Strs() { return Console.ReadLine().Split(); }
}
|
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 480
| 7
|
using System;
using System.Linq;
namespace _067 {
class Program {
static void Main(string[] args) {
// C - Splitting Pile
var n = int.Parse(Console.ReadLine());
var a = Console.ReadLine()
.Split(' ')
.Select(w => int.Parse(w))
.OrderByDescending(w => w)
.ToArray();
long x = 0;
long y = a.Sum();
long min = 9999999999;
for (long i = 0; i < n - 1; i++) {
x += a[i];
y -= a[i];
var abs = Math.Abs(x - y);
min = Math.Min(abs, min);
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.Linq;
namespace _067 {
class Program {
static void Main(string[] args) {
// C - Splitting Pile
var n = long.Parse(Console.ReadLine());
var a = Console.ReadLine().Split(' ').Select(w => long.Parse(w)).ToArray();
long x = 0;
long y = a.Sum();
long min = 9999999999;
for (long i = 0; i < n - 1; i++) {
x += a[i];
y -= a[i];
var abs = Math.Abs(x - y);
min = Math.Min(abs, min);
}
Console.WriteLine(min);
}
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 8, 22]]
| 8
| 162
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtheleteProgramming3 {
class Program {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[] cardPool = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int min = int.MaxValue;
int[] aArray1 = new int[N - 1];
int[] bArray2 = new int[N - 1];
aArray1[0] = cardPool[0];
bArray2[N - 1 - 1] = cardPool[N - 1];
if (N != 2) {
for (int i = 1; i < N - 1; i++) {
aArray1[i] = aArray1[i - 1] + cardPool[i];
}
for (int i = N - 3; i >= 0; i--) {
bArray2[i] = bArray2[i + 1] + cardPool[i + 1];
}
for (int i = 0; i < N - 1; i++) {
int tmp = Math.Abs(aArray1[i] - bArray2[i]);
if (tmp < min) {
min = tmp;
}
}
} else {
min = Math.Abs(cardPool[0] - cardPool[1]);
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtheleteProgramming3 {
class Program {
static void Main(string[] args) {
long N = long.Parse(Console.ReadLine());
long[] cardPool =
Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long min = long.MaxValue;
long[] aArray1 = new long[N - 1];
long[] bArray2 = new long[N - 1];
aArray1[0] = cardPool[0];
bArray2[N - 1 - 1] = cardPool[N - 1];
if (N != 2) {
for (long i = 1; i < N - 1; i++) {
aArray1[i] = aArray1[i - 1] + cardPool[i];
}
for (long i = N - 3; i >= 0; i--) {
bArray2[i] = bArray2[i + 1] + cardPool[i + 1];
}
for (long i = 0; i < N - 1; i++) {
long tmp = Math.Abs(aArray1[i] - bArray2[i]);
if (tmp < min) {
min = tmp;
}
}
} else {
min = Math.Abs(cardPool[0] - cardPool[1]);
}
Console.WriteLine(min);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 303
| 28
|
using System;
// using System.Collections.Generic;
// using System.Linq;
class Program {
static void Main(string[] args) {
string card = Console.ReadLine();
int cardNum = int.Parse(card);
string[] values = Console.ReadLine().Split(' ');
int[] valuesInt = new int[values.Length];
int sumA = 0;
int sumB = 0;
int min = 0;
for (int i = 0; i < values.Length; i++) {
valuesInt[i] = int.Parse(values[i]);
sumB += valuesInt[i];
}
min = 2147483647;
for (int i = 0; i < valuesInt.Length - 1; i++) {
sumA += valuesInt[i];
sumB -= valuesInt[i];
int diff = Math.Abs(sumA - sumB);
// Console.WriteLine("A: " + sumA.ToString());
// Console.WriteLine("B: " + sumB.ToString());
// Console.WriteLine("Diff: " + diff.ToString());
if (diff < min)
min = diff;
}
Console.WriteLine(min.ToString());
}
}
|
using System;
// using System.Collections.Generic;
// using System.Linq;
class Program {
static void Main(string[] args) {
string card = Console.ReadLine();
double cardNum = double.Parse(card);
string[] values = Console.ReadLine().Split(' ');
double[] valuesdouble = new double[values.Length];
double sumA = 0;
double sumB = 0;
double min = 0;
for (int i = 0; i < values.Length; i++) {
valuesdouble[i] = double.Parse(values[i]);
sumB += valuesdouble[i];
}
min = 2147483647;
for (int i = 0; i < valuesdouble.Length - 1; i++) {
sumA += valuesdouble[i];
sumB -= valuesdouble[i];
double diff = Math.Abs(sumA - sumB);
// Console.WriteLine("A: " + sumA.ToString());
// Console.WriteLine("B: " + sumB.ToString());
// Console.WriteLine("Diff: " + diff.ToString());
if (diff < min)
min = diff;
}
Console.WriteLine(min.ToString());
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 199
| 30
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace Program {
public class ARC078D {
static public void Main(string[] args) {
var N = NextInt;
var path = new List<int>[N];
for (int i = 0; i < N; ++i) {
path[i] = new List<int>();
}
for (int i = 0; i < N - 1; ++i) {
var a = NextInt - 1;
var b = NextInt - 1;
path[a].Add(b);
path[b].Add(a);
}
var bfs = new Queue<int>();
var dist = new int[N];
var pred = new int[N];
var done = new bool[N];
bfs.Enqueue(N - 1);
done[N - 1] = true;
while (!done[0]) {
var v = bfs.Dequeue();
if (done[v])
continue;
foreach (var item in path[v]) {
dist[item] = dist[v] + 1;
pred[item] = v;
done[item] = true;
bfs.Enqueue(item);
}
}
var midlength = dist[0] / 2;
var p = 0;
var count = 0;
while (count != midlength) {
p = pred[p];
++count;
}
foreach (var item in path[p]) {
path[item].Remove(p);
}
path[p].Clear();
var queue = new Queue<int>();
queue.Enqueue(N - 1);
done = new bool[N];
var field = 0;
while (queue.Any()) {
var v = queue.Dequeue();
if (!done[v]) {
done[v] = true;
++field;
foreach (var item in path[v]) {
queue.Enqueue(item);
}
}
}
Console.WriteLine(field < (N + 1) / 2 ? "Fennec" : "Snuke");
}
static class Console_ {
private 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 int NextInt => int.Parse(Console_.NextString());
static long NextLong => long.Parse(Console_.NextString());
static string NextString => Console_.NextString();
static IEnumerable<long> Prime(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i])
yield return 2 * i + 1;
}
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 long GCD(long a, long b) {
long tmpa = a, tmpb = b;
while (tmpb > 0) {
var tmp = tmpb;
tmpb = tmpa % tmpb;
tmpa = tmp;
}
return tmpa;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace Program {
public class ARC078D {
static public void Main(string[] args) {
var N = NextInt;
var path = new List<int>[N];
for (int i = 0; i < N; ++i) {
path[i] = new List<int>();
}
for (int i = 0; i < N - 1; ++i) {
var a = NextInt - 1;
var b = NextInt - 1;
path[a].Add(b);
path[b].Add(a);
}
var bfs = new Queue<int>();
var dist = new int[N];
var pred = new int[N];
var done = new bool[N];
bfs.Enqueue(N - 1);
done[N - 1] = true;
while (!done[0]) {
var v = bfs.Dequeue();
foreach (var item in path[v]) {
if (!done[item]) {
dist[item] = dist[v] + 1;
pred[item] = v;
done[item] = true;
bfs.Enqueue(item);
}
}
}
var midlength = dist[0] / 2;
var p = 0;
var count = 0;
while (count != midlength) {
p = pred[p];
++count;
}
foreach (var item in path[p]) {
path[item].Remove(p);
}
path[p].Clear();
var queue = new Queue<int>();
queue.Enqueue(N - 1);
done = new bool[N];
var field = 0;
while (queue.Any()) {
var v = queue.Dequeue();
if (!done[v]) {
done[v] = true;
++field;
foreach (var item in path[v]) {
queue.Enqueue(item);
}
}
}
Console.WriteLine(field < (N + 1) / 2 ? "Fennec" : "Snuke");
}
static class Console_ {
private 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 int NextInt => int.Parse(Console_.NextString());
static long NextLong => long.Parse(Console_.NextString());
static string NextString => Console_.NextString();
static IEnumerable<long> Prime(long x) {
if (x < 2)
yield break;
yield return 2;
var halfx = x / 2;
var table = new bool[halfx + 1];
var max = (long)(Math.Sqrt(x) / 2);
for (long i = 1; i <= max; ++i) {
if (table[i])
continue;
var add = 2 * i + 1;
yield return add;
for (long j = 2 * i * (i + 1); j <= halfx; j += add)
table[j] = true;
}
for (long i = max + 1; i <= halfx; ++i)
if (!table[i])
yield return 2 * i + 1;
}
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 long GCD(long a, long b) {
long tmpa = a, tmpb = b;
while (tmpb > 0) {
var tmp = tmpb;
tmpb = tmpa % tmpb;
tmpa = tmp;
}
return tmpa;
}
}
}
|
[["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 52, 8, 196, 0, 57, 15, 204, 205, 22], ["-", 8, 196, 0, 57, 15, 204, 206, 207, 0, 70], ["-", 0, 57, 15, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 196, 0, 57, 15, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 52, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 241, 0, 111], ["+", 8, 196, 0, 57, 15, 241, 0, 204, 205, 22], ["+", 0, 57, 15, 241, 0, 204, 206, 207, 0, 70], ["+", 15, 241, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 241, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 845
| 19
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
class Program {
static void Main() {
var exStdIn =
new System.IO.StreamReader("C:\\Users\\hmakita\\Downloads\\01.txt");
System.Console.SetIn(exStdIn);
long n = long.Parse(Console.ReadLine());
long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
long[] da = new long[n];
long ans = 9223372036854775800;
da[0] = a[0];
for (long i = 1; i < n; i++) {
da[i] = a[i] + da[i - 1];
}
for (long i = 0; i < n - 1; i++) {
long x = da[i];
long y = da[n - 1] - da[i];
ans = Math.Min(ans, Math.Abs(x - y));
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
class Program {
static void Main() {
long n = long.Parse(Console.ReadLine());
long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
long[] da = new long[n];
long ans = 9223372036854775800;
da[0] = a[0];
for (long i = 1; i < n; i++) {
da[i] = a[i] + da[i - 1];
}
for (long i = 0; i < n - 1; i++) {
long x = da[i];
long y = da[n - 1] - da[i];
ans = Math.Min(ans, Math.Abs(x - y));
}
Console.WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 234, 22], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 0, 131], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 0, 131], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 44], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 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
| 245
| 32
|
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());
this.Items =
Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
long total = Items.Sum();
long subtotal = 0;
long ans = total;
for (int i = 0; i < itemCount; i++) {
subtotal += this.Items[i];
ans = Math.Min(ans, Math.Abs((total - subtotal) - subtotal));
}
Console.WriteLine(ans);
}
private long[] Items;
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 = @"
6
1 2 3 4 5 6
";
}
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());
this.Items =
Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
long total = Items.Sum();
long subtotal = Items[0];
long ans = Math.Abs((total - subtotal) - subtotal);
for (int i = 1; i < itemCount - 1; i++) {
subtotal += this.Items[i];
ans = Math.Min(ans, Math.Abs((total - subtotal) - subtotal));
}
Console.WriteLine(ans);
}
private long[] Items;
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 = @"
2
10 -10
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
[["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
| 8
| 275
| 20
|
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 dist1 = new int[num];
var dist2 = new int[num];
var ads = new List<int>[num];
for (var i = 0; i < num; i++)
ads[i] = new List<int>();
for (var i = 0; i < num - 1; i++) {
var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
ads[input[0] - 1].Add(input[1] - 1);
ads[input[1] - 1].Add(input[0] - 1);
}
bfs(0, ads, dist1, new Queue<int>());
bfs(num - 1, ads, dist2, new Queue<int>());
var resfe = 0;
var ressn = 0;
for (var i = 1; i < num - 1; i++)
if (dist1[i] < dist2[i])
resfe++;
else
ressn++;
WriteLine(resfe > ressn ? "Fennec" : "Snuke");
}
private static void bfs(int st, List<int>[] ads, int[] dist,
Queue<int> queue) {
queue.Enqueue(st);
while (queue.Count != 0) {
var index = queue.Dequeue();
foreach (var ad in ads[index])
if (ad != st && dist[ad] == 0) {
dist[ad] = dist[index] + 1;
queue.Enqueue(ad);
}
}
}
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 dist1 = new int[num];
var dist2 = new int[num];
var ads = new List<int>[num];
for (var i = 0; i < num; i++)
ads[i] = new List<int>();
for (var i = 0; i < num - 1; i++) {
var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
ads[input[0] - 1].Add(input[1] - 1);
ads[input[1] - 1].Add(input[0] - 1);
}
bfs(0, ads, dist1, new Queue<int>());
bfs(num - 1, ads, dist2, new Queue<int>());
var resfe = 0;
var ressn = 0;
for (var i = 1; i < num - 1; i++)
if (dist1[i] <= dist2[i])
resfe++;
else
ressn++;
WriteLine(resfe > ressn ? "Fennec" : "Snuke");
}
private static void bfs(int st, List<int>[] ads, int[] dist,
Queue<int> queue) {
queue.Enqueue(st);
while (queue.Count != 0) {
var index = queue.Dequeue();
foreach (var ad in ads[index])
if (ad != st && dist[ad] == 0) {
dist[ad] = dist[index] + 1;
queue.Enqueue(ad);
}
}
}
}
|
[["-", 8, 196, 0, 7, 8, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 8, 57, 15, 16, 17, 19], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 261], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 154], ["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 0, 208, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 408
| 18
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
//using CS_Contest.Graph;
using CS_Contest.Loop;
using CS_Contest.Utils;
using static Nakov.IO.Cin;
using static CS_Contest.IO.IO;
using static CS_Contest.Utils.MyMath;
namespace CS_Contest {
using Li = List<int>;
using LLi = List<List<int>>;
using Ll = List<long>;
using ti3 = Tuple<int, int, int>;
using ti2 = Tuple<int, int>;
internal class Program {
private static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
new Calc().Solve();
Out.Flush();
}
public class Calc {
public void Solve() {
int N = NextInt();
var g=new CostGraph(N);
(N-1).REP(i =>
{
int ai = NextInt() - 1, bi = NextInt() - 1;
g.Add(ai,bi,1,false);
});
var dist = new int[2, N];
2.REP(i=>N.REP(j=>dist[i,j]=int.MaxValue));
Action<int, int, int> dfs = null;
dfs = (crr, dis, fs) =>
{
if (dist[fs,crr] != int.MaxValue) return;
dist[fs,crr] = dis;
foreach (var edge in g.Adjacency[crr]) {
dfs(edge.To, dis + 1, fs);
}
};
dfs(0, 0, 0);
dfs(N - 1, 0, 1);
var fc = 0;
var sc = 0;
for (int i = 0; i < N; i++) {
if (dist[0,i] <= dist[1,i]) fc++;
else sc++;
}
if(fc<sc) "Snuke".WL();
else "Fennec".WL();
return;
}
}
public class CostGraph {
public struct Edge {
public int To { get; set; }
public long Cost { get; set; }
public Edge(int to, long cost) {
To = to;
Cost = cost;
}
}
public int Size { get; set; }
public List<List<Edge>> Adjacency { get; set; }
public const long Inf = (long)1e15;
public CostGraph(int size) {
Size = size;
Adjacency = new List<List<Edge>>();
Size.REP(_ => Adjacency.Add(new List<Edge>()));
}
public void Add(int s, int t, long c, bool dir = true) {
Adjacency[s].Add(new Edge(t, c));
if (!dir) Adjacency[t].Add(new Edge(s, c));
}
}
}
}
namespace Nakov.IO {
using System;
using System.Text;
using System.Globalization;
public static class Cin {
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);
}
}
}
string token = tokenChars.ToString();
return token;
}
public static int NextInt() {
string token = Cin.NextToken();
return int.Parse(token);
}
public static long NextLong() {
string token = Cin.NextToken();
return long.Parse(token);
}
public static double NextDouble(bool acceptAnyDecimalSeparator = true) {
string token = Cin.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 = Cin.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
decimal result = decimal.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
decimal result = decimal.Parse(token);
return result;
}
}
}
}
namespace CS_Contest.Loop {
public static class Loop {
public static void REP(this int n, Action<int> act) {
for (var i = 0; i < n; i++) {
act(i);
}
}
public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) {
var i = 0;
foreach (var item in ie) {
act(i, item);
i++;
}
}
public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) {
foreach (var item in ie) {
act(item);
}
}
}
}
namespace CS_Contest.IO {
using Li = List<int>;
using Ll = List<long>;
public static class IO {
public static void WL(this object obj) => WriteLine(obj);
public static void WL(this string obj) => WriteLine(obj);
public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL());
public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList();
public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList();
public static T Tee<T>(this T t, Func<T, string> formatter = null) {
if (formatter == null) formatter = arg => arg.ToString();
formatter(t).WL();
return t;
}
public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL();
public static void W(this object @this) => Write(@this);
}
}
namespace CS_Contest.Utils {
using Li = List<int>;
using Ll = List<long>;
public static class Utils {
public static List<T> Repeat<T>(Func<int, T> result, int range) =>
Enumerable.Range(0, range).Select(result).ToList();
public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly);
public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2));
public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l);
public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) {
var rt = new Queue<T>();
foreach (var item in iEnumerable) {
rt.Enqueue(item);
}
return rt;
}
public static void Swap<T>(ref T x, ref T y) {
var tmp = x;
x = y;
y = tmp;
}
public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) {
var dic = new Dictionary<TKey, int>();
foreach (var item in l) {
if (dic.ContainsKey(item)) dic[item]++;
else dic.Add(item, 1);
}
return dic;
}
public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target));
public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) {
var enumerable = @this as T[] ?? @this.ToArray();
for (var i = 0; i < enumerable.Count(); i++) {
if (i == at) continue;
yield return enumerable.ElementAt(i);
}
}
}
public class Map<TKey, TValue> : Dictionary<TKey, TValue> {
public Map() : base() { }
public Map(int capacity) : base(capacity) { }
public new TValue this[TKey index] {
get {
TValue v;
return this.TryGetValue(index, out v) ? v : base[index] = default(TValue);
}
set { base[index] = value; }
}
}
public static class MyMath {
public static T EMin<T>(params T[] a) where T : IComparable<T> => a.Min();
public static T EMax<T>(params T[] a) where T : IComparable<T> => a.Max();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
//using CS_Contest.Graph;
using CS_Contest.Loop;
using CS_Contest.Utils;
using static Nakov.IO.Cin;
using static CS_Contest.IO.IO;
using static CS_Contest.Utils.MyMath;
namespace CS_Contest {
using Li = List<int>;
using LLi = List<List<int>>;
using Ll = List<long>;
using ti3 = Tuple<int, int, int>;
using ti2 = Tuple<int, int>;
internal class Program {
private static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
new Calc().Solve();
Out.Flush();
}
public class Calc {
public void Solve() {
int N = NextInt();
var g=new CostGraph(N);
(N-1).REP(i =>
{
int ai = NextInt() - 1, bi = NextInt() - 1;
g.Add(ai,bi,1,false);
});
var dist = new int[2, N];
2.REP(i=>N.REP(j=>dist[i,j]=int.MaxValue));
Action<int, int, int> dfs = null;
dfs = (crr, dis, fs) =>
{
if (dist[fs,crr] != int.MaxValue) return;
dist[fs,crr] = dis;
foreach (var edge in g.Adjacency[crr]) {
dfs(edge.To, dis + 1, fs);
}
};
dfs(0, 0, 0);
dfs(N - 1, 0, 1);
var fc = 0;
var sc = 0;
for (int i = 0; i < N; i++) {
if (dist[0,i] <= dist[1,i]) fc++;
else sc++;
}
if(fc>sc) "Fennec".WL();
else "Snuke".WL();
return;
}
}
public class CostGraph {
public struct Edge {
public int To { get; set; }
public long Cost { get; set; }
public Edge(int to, long cost) {
To = to;
Cost = cost;
}
}
public int Size { get; set; }
public List<List<Edge>> Adjacency { get; set; }
public const long Inf = (long)1e15;
public CostGraph(int size) {
Size = size;
Adjacency = new List<List<Edge>>();
Size.REP(_ => Adjacency.Add(new List<Edge>()));
}
public void Add(int s, int t, long c, bool dir = true) {
Adjacency[s].Add(new Edge(t, c));
if (!dir) Adjacency[t].Add(new Edge(s, c));
}
}
}
}
namespace Nakov.IO {
using System;
using System.Text;
using System.Globalization;
public static class Cin {
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);
}
}
}
string token = tokenChars.ToString();
return token;
}
public static int NextInt() {
string token = Cin.NextToken();
return int.Parse(token);
}
public static long NextLong() {
string token = Cin.NextToken();
return long.Parse(token);
}
public static double NextDouble(bool acceptAnyDecimalSeparator = true) {
string token = Cin.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 = Cin.NextToken();
if (acceptAnyDecimalSeparator) {
token = token.Replace(',', '.');
decimal result = decimal.Parse(token, CultureInfo.InvariantCulture);
return result;
} else {
decimal result = decimal.Parse(token);
return result;
}
}
}
}
namespace CS_Contest.Loop {
public static class Loop {
public static void REP(this int n, Action<int> act) {
for (var i = 0; i < n; i++) {
act(i);
}
}
public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) {
var i = 0;
foreach (var item in ie) {
act(i, item);
i++;
}
}
public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) {
foreach (var item in ie) {
act(item);
}
}
}
}
namespace CS_Contest.IO {
using Li = List<int>;
using Ll = List<long>;
public static class IO {
public static void WL(this object obj) => WriteLine(obj);
public static void WL(this string obj) => WriteLine(obj);
public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL());
public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList();
public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList();
public static T Tee<T>(this T t, Func<T, string> formatter = null) {
if (formatter == null) formatter = arg => arg.ToString();
formatter(t).WL();
return t;
}
public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL();
public static void W(this object @this) => Write(@this);
}
}
namespace CS_Contest.Utils {
using Li = List<int>;
using Ll = List<long>;
public static class Utils {
public static List<T> Repeat<T>(Func<int, T> result, int range) =>
Enumerable.Range(0, range).Select(result).ToList();
public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly);
public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2));
public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l);
public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) {
var rt = new Queue<T>();
foreach (var item in iEnumerable) {
rt.Enqueue(item);
}
return rt;
}
public static void Swap<T>(ref T x, ref T y) {
var tmp = x;
x = y;
y = tmp;
}
public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) {
var dic = new Dictionary<TKey, int>();
foreach (var item in l) {
if (dic.ContainsKey(item)) dic[item]++;
else dic.Add(item, 1);
}
return dic;
}
public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target));
public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) {
var enumerable = @this as T[] ?? @this.ToArray();
for (var i = 0; i < enumerable.Count(); i++) {
if (i == at) continue;
yield return enumerable.ElementAt(i);
}
}
}
public class Map<TKey, TValue> : Dictionary<TKey, TValue> {
public Map() : base() { }
public Map(int capacity) : base(capacity) { }
public new TValue this[TKey index] {
get {
TValue v;
return this.TryGetValue(index, out v) ? v : base[index] = default(TValue);
}
set { base[index] = value; }
}
}
public static class MyMath {
public static T EMin<T>(params T[] a) where T : IComparable<T> => a.Min();
public static T EMax<T>(params T[] a) where T : IComparable<T> => a.Max();
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 64, 1, 0, 213, 63, 214, 205, 5, 0, 222], ["+", 64, 1, 0, 213, 63, 214, 205, 5, 0, 222], ["-", 75, 1, 0, 213, 63, 214, 205, 5, 0, 222], ["+", 75, 1, 0, 213, 63, 214, 205, 5, 0, 222]]
| 8
| 2,000
| 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 AtCoder {
class MainClass {
// C#7.0/////////////////////////////////////////////////////
int N;
long[] a, b;
void Solve() {
io.i(out N);
io.ini(out a, out b, N - 1);
Tree tr = new Tree();
tr.Init(N);
tr.Run(a, b);
long[] fromFennec, fromSnuke;
tr.Cal(1);
fromFennec = tr.a2other;
tr.Cal(N);
fromSnuke = tr.a2other;
int cBlack = 0;
REP(fromFennec.Length, i => {
if (fromFennec[i] <= fromSnuke[i]) {
cBlack++;
}
});
io.o((cBlack > N - cBlack) ? "Fennec" : "Snuke");
}
////////////////////////////////////////////////////////////
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
// Hack Update
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act, int c = 1) {
for (int i = a; i < b; i += c)
act(i);
}
void FOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) {
for (int i = a; i < b && con(i); i += c)
act(i);
}
void RFOR(int a, int b, Action<int> act, int c = 1) {
for (int i = a; i >= b; i -= c)
act(i);
}
void RFOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) {
for (int i = a; i >= b && con(i); i -= c)
act(i);
}
void REP(int n, Action<int> act, Func<int, bool> con, int c = 1) {
for (int i = 0; i < n && con(i); i += c)
act(i);
}
void REP(int n, Action<int> act, int c = 1) {
for (int i = 0; i < n; i += c)
act(i);
}
void RREP(int n, Action<int> act, int c = 1) {
for (int i = n - 1; i >= 0; i -= c)
act(i);
}
void RREP(int n, Action<int> act, Func<int, bool> con) {
for (int i = n - 1; i >= 0 && con(i); 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 o<T>(List<T> l) { o(l.ToArray()); }
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) {
Array.ForEach(a, n => ol(n));
br();
}
public void ol<T>(List<T> l) { ol(l.ToArray()); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
}
class Operation<T> {
public Operation() {
var availableT = new Type[] { typeof(int), typeof(long), typeof(double) };
if (!availableT.Contains(typeof(T)))
throw new NotSupportedException();
var p1 = Expression.Parameter(typeof(T));
var p2 = Expression.Parameter(typeof(T));
Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2)
.Compile();
Sub = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2)
.Compile();
Mul = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2)
.Compile();
Div = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2)
.Compile();
Mod = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2)
.Compile();
EQ = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2)
.Compile();
GT = Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2)
.Compile();
GE = Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThanOrEqual(p1, p2),
p1, p2)
.Compile();
LT =
Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2)
.Compile();
LE = Expression
.Lambda<Func<T, T, bool>>(Expression.LessThanOrEqual(p1, p2), p1,
p2)
.Compile();
}
public Func<T, T, T> Add { get; private set; }
public Func<T, T, T> Sub { get; private set; }
public Func<T, T, T> Mul { get; private set; }
public Func<T, T, T> Div { get; private set; }
public Func<T, T, T> Mod { get; private set; }
public Func<T, T, bool> EQ { get; private set; }
public Func<T, T, bool> GT { get; private set; }
public Func<T, T, bool> GE { get; private set; }
public Func<T, T, bool> LT { get; private set; }
public Func<T, T, bool> LE { get; private set; }
}
class OP {
// Matを簡潔に...
public T Add<T>(T a, T b) {
var op = new Operation<T>();
return op.Add(a, b);
}
public T Sub<T>(T a, T b) {
var op = new Operation<T>();
return op.Sub(a, b);
}
public T Mul<T>(T a, T b) {
var op = new Operation<T>();
return op.Mul(a, b);
}
public T Div<T>(T a, T b) {
var op = new Operation<T>();
return op.Div(a, b);
}
public T Mod<T>(T a, T b) {
var op = new Operation<T>();
return op.Mod(a, b);
}
public bool EQ<T>(T a, T b) {
var op = new Operation<T>();
return op.EQ(a, b);
}
public bool GT<T>(T a, T b) {
var op = new Operation<T>();
return op.GT(a, b);
}
public bool GE<T>(T a, T b) {
var op = new Operation<T>();
return op.GE(a, b);
}
public bool LT<T>(T a, T b) {
var op = new Operation<T>();
return op.LT(a, b);
}
public bool LE<T>(T a, T b) {
var op = new Operation<T>();
return op.LE(a, b);
}
}
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 {
OP op;
public Mat() { op = new OP(); }
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
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, next) => GCD(v, next));
}
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
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)];
M.REP(ret.Length, i => ret[i] = DigVal(n, i + 1));
return ret;
}
public int Clamp(int n, int a, int b) {
return (n < a) ? a : (b < n) ? b : n;
}
public long Clamp(long n, long a, long b) {
return (n < a) ? a : (b < n) ? b : n;
}
public double Clamp(double n, double a, double b) {
return (n < a) ? a : (b < n) ? b : n;
}
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> { // 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) {
M.REP(a.Length, 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) {
M.REP(a.Length, 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);
}
}
//:sort->array
}
#region Tree
class Tree {
public List<Tuple<long, long>>[] g;
public long[] a2other;
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
M.REP(g.Length, i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
M.REP(a.Length, 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) {
M.REP(a.Length, i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public void Cal(long a) {
a2other = new long[g.Count()];
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));
}
}
}
}
#endregion
class Dijkstra {
private int Index = -1;
private long INF = (int)1e9;
private long[,] m;
public Dijkstra() {}
public void init(int n) {
Index = n + 1;
m = new long[Index, Index];
M.REP(Index, i => M.REP(Index, j => { m[i, j] = INF; }));
M.REP(Index, i => m[i, i] = 0);
}
public void AddPath(long f, long t, long w) {
m[f, t] = Math.Min(m[f, t], w);
m[t, f] = m[f, t];
}
public long GetMinCost(long f, long t) {
long[] w = new long[Index];
M.REP(Index, i => w[i] = INF);
w[f] = 0;
var pq = new PQueue<Tuple<long, long>>();
pq.Enqueue(Tuple.Create(0L, f)); // cost<-from
while (pq.Count > 0) {
var c = pq.Dequeue();
if (c.Item2 < c.Item1)
continue;
M.REP(Index, i => {
long w2i = m[c.Item2, i] == INF ? INF : c.Item1 + m[c.Item2, i];
if (w2i < w[i]) {
w[i] = w2i;
pq.Enqueue(Tuple.Create(w2i, (long)i));
}
});
}
return w[t];
}
}
class WarshallFloyd {
int INF;
public WarshallFloyd() { INF = (int)(1e8); }
public WarshallFloyd(int INF) { this.INF = INF; }
public int[,] Run(int[,] m) {
int edgeLength = m.GetLength(0);
for (int i = 0; i < edgeLength; i++)
for (int j = 0; j < edgeLength; j++)
for (int k = 0; k < edgeLength; k++)
m[j, k] = Math.Min(m[j, k], m[j, i] + m[i, k]);
return m;
}
public int[,] Init(int n) {
int[,] m = new int[n, n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
m[i, j] = INF;
for (int i = 0; i < n; i++)
m[i, i] = 0;
return m;
}
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
#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');
}
}
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) { M.REP(a.Length, i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
M.REP(a.GetLength(0), i => M.REP(a.GetLength(1), 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 M {
public static void REP(int n, Action<int> a) {
for (int i = 0; i < n; i++)
a(i);
}
}
#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 AtCoder {
class MainClass {
// C#7.0/////////////////////////////////////////////////////
int N;
long[] a, b;
void Solve() {
io.i(out N);
io.ini(out a, out b, N - 1);
Tree tr = new Tree();
tr.Init(N);
tr.Run(a, b);
long[] fromFennec, fromSnuke;
tr.Cal(1);
fromFennec = tr.a2other;
tr.Cal(N);
fromSnuke = tr.a2other;
int cBlack = 0;
int cWhite = 0;
FOR(1, fromFennec.Length, i => {
if (fromFennec[i] <= fromSnuke[i]) {
cBlack++;
} else {
cWhite++;
}
});
io.o((cBlack > cWhite) ? "Fennec" : "Snuke");
}
////////////////////////////////////////////////////////////
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
// Hack Update
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act, int c = 1) {
for (int i = a; i < b; i += c)
act(i);
}
void FOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) {
for (int i = a; i < b && con(i); i += c)
act(i);
}
void RFOR(int a, int b, Action<int> act, int c = 1) {
for (int i = a; i >= b; i -= c)
act(i);
}
void RFOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) {
for (int i = a; i >= b && con(i); i -= c)
act(i);
}
void REP(int n, Action<int> act, Func<int, bool> con, int c = 1) {
for (int i = 0; i < n && con(i); i += c)
act(i);
}
void REP(int n, Action<int> act, int c = 1) {
for (int i = 0; i < n; i += c)
act(i);
}
void RREP(int n, Action<int> act, int c = 1) {
for (int i = n - 1; i >= 0; i -= c)
act(i);
}
void RREP(int n, Action<int> act, Func<int, bool> con) {
for (int i = n - 1; i >= 0 && con(i); 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 o<T>(List<T> l) { o(l.ToArray()); }
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) {
Array.ForEach(a, n => ol(n));
br();
}
public void ol<T>(List<T> l) { ol(l.ToArray()); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
}
class Operation<T> {
public Operation() {
var availableT = new Type[] { typeof(int), typeof(long), typeof(double) };
if (!availableT.Contains(typeof(T)))
throw new NotSupportedException();
var p1 = Expression.Parameter(typeof(T));
var p2 = Expression.Parameter(typeof(T));
Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2)
.Compile();
Sub = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2)
.Compile();
Mul = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2)
.Compile();
Div = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2)
.Compile();
Mod = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2)
.Compile();
EQ = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2)
.Compile();
GT = Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2)
.Compile();
GE = Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThanOrEqual(p1, p2),
p1, p2)
.Compile();
LT =
Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2)
.Compile();
LE = Expression
.Lambda<Func<T, T, bool>>(Expression.LessThanOrEqual(p1, p2), p1,
p2)
.Compile();
}
public Func<T, T, T> Add { get; private set; }
public Func<T, T, T> Sub { get; private set; }
public Func<T, T, T> Mul { get; private set; }
public Func<T, T, T> Div { get; private set; }
public Func<T, T, T> Mod { get; private set; }
public Func<T, T, bool> EQ { get; private set; }
public Func<T, T, bool> GT { get; private set; }
public Func<T, T, bool> GE { get; private set; }
public Func<T, T, bool> LT { get; private set; }
public Func<T, T, bool> LE { get; private set; }
}
class OP {
// Matを簡潔に...
public T Add<T>(T a, T b) {
var op = new Operation<T>();
return op.Add(a, b);
}
public T Sub<T>(T a, T b) {
var op = new Operation<T>();
return op.Sub(a, b);
}
public T Mul<T>(T a, T b) {
var op = new Operation<T>();
return op.Mul(a, b);
}
public T Div<T>(T a, T b) {
var op = new Operation<T>();
return op.Div(a, b);
}
public T Mod<T>(T a, T b) {
var op = new Operation<T>();
return op.Mod(a, b);
}
public bool EQ<T>(T a, T b) {
var op = new Operation<T>();
return op.EQ(a, b);
}
public bool GT<T>(T a, T b) {
var op = new Operation<T>();
return op.GT(a, b);
}
public bool GE<T>(T a, T b) {
var op = new Operation<T>();
return op.GE(a, b);
}
public bool LT<T>(T a, T b) {
var op = new Operation<T>();
return op.LT(a, b);
}
public bool LE<T>(T a, T b) {
var op = new Operation<T>();
return op.LE(a, b);
}
}
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 {
OP op;
public Mat() { op = new OP(); }
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
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, next) => GCD(v, next));
}
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
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)];
M.REP(ret.Length, i => ret[i] = DigVal(n, i + 1));
return ret;
}
public int Clamp(int n, int a, int b) {
return (n < a) ? a : (b < n) ? b : n;
}
public long Clamp(long n, long a, long b) {
return (n < a) ? a : (b < n) ? b : n;
}
public double Clamp(double n, double a, double b) {
return (n < a) ? a : (b < n) ? b : n;
}
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> { // 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) {
M.REP(a.Length, 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) {
M.REP(a.Length, 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);
}
}
//:sort->array
}
#region Tree
class Tree {
public List<Tuple<long, long>>[] g;
public long[] a2other;
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
M.REP(g.Length, i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
M.REP(a.Length, 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) {
M.REP(a.Length, i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public void Cal(long a) {
a2other = new long[g.Count()];
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));
}
}
}
}
#endregion
class Dijkstra {
private int Index = -1;
private long INF = (int)1e9;
private long[,] m;
public Dijkstra() {}
public void init(int n) {
Index = n + 1;
m = new long[Index, Index];
M.REP(Index, i => M.REP(Index, j => { m[i, j] = INF; }));
M.REP(Index, i => m[i, i] = 0);
}
public void AddPath(long f, long t, long w) {
m[f, t] = Math.Min(m[f, t], w);
m[t, f] = m[f, t];
}
public long GetMinCost(long f, long t) {
long[] w = new long[Index];
M.REP(Index, i => w[i] = INF);
w[f] = 0;
var pq = new PQueue<Tuple<long, long>>();
pq.Enqueue(Tuple.Create(0L, f)); // cost<-from
while (pq.Count > 0) {
var c = pq.Dequeue();
if (c.Item2 < c.Item1)
continue;
M.REP(Index, i => {
long w2i = m[c.Item2, i] == INF ? INF : c.Item1 + m[c.Item2, i];
if (w2i < w[i]) {
w[i] = w2i;
pq.Enqueue(Tuple.Create(w2i, (long)i));
}
});
}
return w[t];
}
}
class WarshallFloyd {
int INF;
public WarshallFloyd() { INF = (int)(1e8); }
public WarshallFloyd(int INF) { this.INF = INF; }
public int[,] Run(int[,] m) {
int edgeLength = m.GetLength(0);
for (int i = 0; i < edgeLength; i++)
for (int j = 0; j < edgeLength; j++)
for (int k = 0; k < edgeLength; k++)
m[j, k] = Math.Min(m[j, k], m[j, i] + m[i, k]);
return m;
}
public int[,] Init(int n) {
int[,] m = new int[n, n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
m[i, j] = INF;
for (int i = 0; i < n; i++)
m[i, i] = 0;
return m;
}
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
#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');
}
}
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) { M.REP(a.Length, i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
M.REP(a.GetLength(0), i => M.REP(a.GetLength(1), 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 M {
public static void REP(int n, Action<int> a) {
for (int i = 0; i < n; i++)
a(i);
}
}
#endregion
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 218, 8, 196, 0, 57, 0, 95], ["+", 0, 218, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 3, 4, 0, 28, 0, 218, 8, 196, 0, 46], ["-", 0, 41, 15, 23, 0, 16, 12, 16, 31, 22], ["-", 0, 41, 15, 23, 0, 16, 12, 16, 17, 33], ["-", 0, 41, 15, 23, 0, 16, 12, 16, 12, 22], ["+", 0, 28, 0, 41, 15, 23, 0, 16, 12, 22]]
| 8
| 5,939
| 19
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC {
class ProgramB {
static void Main(string[] args) {
var s = Console.ReadLine();
s = s.Substring(0, s.Length - 2);
while (2 <= s.Length) {
var b = true;
for (var i = 0; i < s.Length / 2; i++) {
if (s.Length % 2 == 1 || s[i] != s[s.Length / 2 + i]) {
b = false;
break;
}
}
if (b) {
break;
}
s = s.Substring(0, s.Length - 2);
}
Console.WriteLine(s);
Console.WriteLine(s.Length);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC {
class ProgramB {
static void Main(string[] args) {
var s = Console.ReadLine();
s = s.Substring(0, s.Length - 2);
while (2 <= s.Length) {
var b = true;
for (var i = 0; i < s.Length / 2; i++) {
if (s.Length % 2 == 1 || s[i] != s[s.Length / 2 + i]) {
b = false;
break;
}
}
if (b) {
break;
}
s = s.Substring(0, s.Length - 2);
}
Console.WriteLine(s.Length);
}
}
}
|
[["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131]]
| 8
| 166
| 7
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Security;
using System.Threading;
using System.Xml.Serialization;
namespace AtCoderCs {
class Program {
const int mod = 1000000007;
static void Main() {
var arg = Console.ReadLine();
for (int i = arg.Length / 2; 0 < i; i -= 1)
if (string.Compare(arg, 0, arg, i, i) == 0) {
Console.WriteLine(i * 2);
return;
}
Console.WriteLine(0);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Security;
using System.Threading;
using System.Xml.Serialization;
namespace AtCoderCs {
class Program {
const int mod = 1000000007;
static void Main() {
var arg = Console.ReadLine();
for (int i = arg.Length / 2 - ((arg.Length & 1) != 0 ? 0 : 1); 0 < i; i--)
if (string.Compare(arg, 0, arg, i, i) == 0) {
Console.WriteLine(i * 2);
return;
}
Console.WriteLine(0);
}
}
}
|
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 41, 15, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 31, 214, 205, 22], ["+", 15, 16, 31, 23, 0, 16, 31, 214, 0, 131], ["+", 15, 16, 31, 23, 0, 16, 31, 214, 141, 22], ["+", 0, 41, 15, 16, 31, 23, 0, 16, 17, 67], ["+", 0, 41, 15, 16, 31, 23, 0, 16, 12, 203], ["+", 12, 23, 0, 41, 15, 16, 31, 23, 0, 25], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 17, 79], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 64, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 0, 102], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 75, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 7, 26, 11, 0, 202, 0, 110], ["-", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
| 8
| 137
| 19
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
s = s.Substring(0, s.Length - 1);
var len = 0;
for (var i = 0; i < s.Length; i++) {
if (s.Length % 2 == 0) {
var halfLen = s.Length / 2;
if (s.Substring(0, halfLen) ==
s.Substring(halfLen, s.Length - halfLen)) {
len = s.Length;
break;
}
}
s = s.Substring(0, s.Length - 1);
}
Console.WriteLine(len);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var s = Console.ReadLine();
s = s.Substring(0, s.Length - 1);
var orgLen = s.Length;
var len = 0;
for (var i = 0; i < orgLen; i++) {
if (s.Length % 2 == 0) {
var halfLen = s.Length / 2;
if (s.Substring(0, halfLen) ==
s.Substring(halfLen, s.Length - halfLen)) {
len = s.Length;
break;
}
}
s = s.Substring(0, s.Length - 1);
}
Console.WriteLine(len);
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 158
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
static void Main(string[] args) {
string s = ReadLine();
for (int i = 0; i < s.Length; i++) {
s = s.Remove(s.Length - 1, 1);
if (s.Length % 2 == 0) {
if (Lside(s) == Rside(s)) {
WriteLine(s.Length);
break;
}
}
}
}
static string Lside(string s) {
string reS = "";
for (int i = 0; i < s.Length / 2; i++) {
reS += s[i].ToString();
}
return reS;
}
static string Rside(string s) {
string reS = "";
for (int i = s.Length / 2; i < s.Length; i++) {
reS += s[i].ToString();
}
return reS;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;
namespace AtCodeeeer {
class AtCOOOOOOOOOOOder {
static void Main(string[] args) {
string s = ReadLine();
while (s.Length > 1) {
s = s.Remove(s.Length - 1, 1);
if (s.Length % 2 == 0) {
if (Lside(s) == Rside(s)) {
WriteLine(s.Length);
break;
}
}
}
}
static string Lside(string s) {
string reS = "";
for (int i = 0; i < s.Length / 2; i++) {
reS += s[i].ToString();
}
return reS;
}
static string Rside(string s) {
string reS = "";
for (int i = s.Length / 2; i < s.Length; i++) {
reS += s[i].ToString();
}
return reS;
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203]]
| 8
| 226
| 14
|
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;
}
static long[] getKeys_L(char delimiter = ' ') {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
long[] Ns = new long[N];
for (int i = 0; i < N; i++) {
Ns[i] = long.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 int N;
static void Main() {
// N = int.Parse(Console.ReadLine());
// var keys = getKeys();
var s = Console.ReadLine();
if (s.Length % 2 != 0) {
s = s.Remove(s.Length - 1);
}
while (!string.IsNullOrEmpty(s)) {
if (isEven(s)) {
Console.WriteLine(s.Length);
return;
}
s = s.Remove(s.Length - 2);
}
}
static bool isEven(string s) {
int mid = s.Length / 2;
for (int i = 0; i < mid; i++) {
if (s[i] != s[mid + i]) {
return false;
}
}
return true;
}
}
}
|
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;
}
static long[] getKeys_L(char delimiter = ' ') {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
long[] Ns = new long[N];
for (int i = 0; i < N; i++) {
Ns[i] = long.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 int N;
static void Main() {
// N = int.Parse(Console.ReadLine());
// var keys = getKeys();
var s = Console.ReadLine();
if (s.Length % 2 != 0) {
s = s.Remove(s.Length - 1);
} else {
s = s.Remove(s.Length - 2);
}
while (!string.IsNullOrEmpty(s)) {
if (isEven(s)) {
Console.WriteLine(s.Length);
return;
}
s = s.Remove(s.Length - 2);
}
}
static bool isEven(string s) {
int mid = s.Length / 2;
for (int i = 0; i < mid; i++) {
// Console.WriteLine(i + ":" + s[i] + "\t" + (i + mid) +
// ":" + s[i + mid]);
if (s[i] != s[mid + i]) {
return false;
}
}
return true;
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 1,014
| 16
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(ReadLine()); }
public static long[] Reads() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (y < x)
gcd(y, x);
while (y != 0) {
var z = x % y;
x = y;
y = z;
}
return x;
}
public static long C(long n, long k) {
long x = 1;
for (long i = 1; i <= k; i++) {
x *= n - i + 1;
x /= i;
}
return x;
}
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var q = Reads();
var n = q[0];
var p = q[1];
var a = Reads();
var c = 0;
for (int i = 0; i < a.Length; i++) {
if (a[i] % 2 == 1)
c++;
}
var o = c;
var e = a.Length - o;
long x1 = 0;
long x2 = 0;
long y = (long)Math.Pow(2, e);
for (int i = 1; i <= o; i += 2) {
x1 += C(o, i);
}
for (int i = 2; i <= o; i += 2) {
x2 += C(o, i);
}
WriteLine(p % 2 == 1 ? x1 * y : x2 * y);
Console.Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(ReadLine()); }
public static long[] Reads() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (y < x)
gcd(y, x);
while (y != 0) {
var z = x % y;
x = y;
y = z;
}
return x;
}
public static long C(long n, long k) {
long x = 1;
for (long i = 1; i <= k; i++) {
x *= n - i + 1;
x /= i;
}
return x;
}
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
var q = Reads();
var n = q[0];
var p = q[1];
var a = Reads();
var c = 0;
for (int i = 0; i < a.Length; i++) {
if (a[i] % 2 == 1)
c++;
}
var o = c;
var e = a.Length - o;
long x1 = 0;
long x2 = 0;
long y = (long)Math.Pow(2, e);
for (int i = 1; i <= o; i += 2) {
x1 += C(o, i);
}
for (int i = 2; i <= o; i += 2) {
x2 += C(o, i);
}
WriteLine(p % 2 == 1 ? x1 * y : (long)Math.Pow(2, o) * y - x1 * y);
Console.Out.Flush();
}
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 75, 16, 31, 22], ["+", 0, 41, 75, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 41, 75, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 41, 75, 16, 31, 16, 31, 74, 0, 25], ["+", 31, 16, 31, 74, 51, 213, 63, 214, 205, 22], ["+", 31, 16, 31, 74, 51, 213, 63, 214, 0, 131], ["+", 31, 16, 31, 74, 51, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 74, 51, 213, 3, 4, 0, 24], ["+", 31, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["+", 31, 16, 31, 74, 51, 213, 3, 4, 0, 21], ["+", 31, 74, 51, 213, 3, 4, 0, 28, 0, 22], ["+", 31, 16, 31, 74, 51, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 41, 75, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 41, 75, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 17, 33], ["+", 0, 28, 0, 41, 75, 16, 12, 16, 31, 22]]
| 8
| 400
| 16
|
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) {
// Main2(args);
MainSS(args);
}
static void MainSS(string[] args) {
string str = args[0];
for (int i = 2; i < str.Length; i += 2) {
if (JudgeGu(str.Substring(0, str.Length - i))) {
Console.WriteLine(str.Length - i);
break;
}
}
}
static bool JudgeGu(string str) {
if (str.Length % 2 != 0)
return false;
string sub = str.Substring(0, str.Length / 2);
return (sub + sub) == str;
}
static void Main2(string[] args) {
var kakaku = args.Select(int.Parse).ToArray();
Array.Sort(kakaku);
Console.WriteLine(kakaku[0] + kakaku[1]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
// Main2(str);
MainSS(str);
}
static void MainSS(string str) {
for (int i = 2; i < str.Length; i += 2) {
if (JudgeGu(str.Substring(0, str.Length - i))) {
Console.WriteLine(str.Length - i);
break;
}
}
}
static bool JudgeGu(string str) {
if (str.Length % 2 != 0)
return false;
string sub = str.Substring(0, str.Length / 2);
return (sub + sub) == str;
}
static void Main2(string str) {
var kakaku = str.Split().Select(int.Parse).ToArray();
Array.Sort(kakaku);
Console.WriteLine(kakaku[0] + kakaku[1]);
}
}
}
|
[["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 70], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25]]
| 8
| 219
| 40
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace FertiLib.Contest.A {
static class Program {
public static void Solve(Scanner cin) {
int n = cin.ReadInt();
var a = cin.ReadIntArray(n);
var deque = new Deque<int>();
for (int i = 0; i < n; i++) {
if (i % 2 == 0)
deque.PushBack(a[i]);
else
deque.PushFront(a[i]);
}
var ans = deque.Items;
if (n % 2 == 0)
ans.Reverse();
Console.WriteLine(ans.Join(" "));
}
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;
}
}
public class Deque<T> : IEnumerable<T> {
int dx;
T[] buffer;
int mask;
public int Count { get; private set; }
public Deque() : this(8) {}
public Deque(int capacity) {
if (capacity != (capacity & -capacity)) {
int tmp = capacity;
capacity = 1;
while (capacity < tmp) {
capacity <<= 1;
}
}
mask = capacity - 1;
buffer = new T[capacity];
}
public Deque(IEnumerable<T> value) : this(value.Count()) {
int i = 0;
foreach (var e in value) {
buffer[i] = e;
i++;
}
}
public T this[int index] {
get { return buffer[(index + dx) & mask]; }
set {
if (0 <= index && index < Count)
throw new IndexOutOfRangeException();
buffer[(index + dx) & mask] = value;
}
}
public void PushFront(T item) {
if (Count == buffer.Length)
extend();
dx = (dx + buffer.Length - 1) & mask;
buffer[dx] = item;
Count++;
}
public T PopFront() {
var ret = buffer[dx = (dx + 1) & mask];
Count--;
return ret;
}
public T Last => buffer[(dx + Count - 1) & mask];
public void PushBack(T item) {
if (Count == buffer.Length)
extend();
buffer[(dx + Count++) & mask] = item;
}
public T PopBack() {
var ret = buffer[(dx + --Count) & mask];
return ret;
}
public T First => buffer[dx];
private void extend() {
var newBuffer = new T[buffer.Length * 2];
for (int i = 0; i < buffer.Length; i++) {
newBuffer[i] = buffer[(dx + i) & mask];
}
mask = newBuffer.Length - 1;
dx = 0;
buffer = newBuffer;
}
public void Clear() {
Count = 0;
buffer = new T[8];
dx = 0;
mask = buffer.Length - 1;
}
public void AddAt(int index, T item) {
PushFront(item);
for (int i = 0; i < index; i++) {
this[i] = this[i + 1];
}
this[index] = item;
}
public T RemoveAt(int index) {
var ret = this[index];
for (int i = index; i > 0; i--) {
this[i] = this[i - 1];
}
PopFront();
return ret;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < Count; i++) {
yield return this[i];
}
}
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator() => this.GetEnumerator();
public T[] Items {
get {
var ret = new T[Count];
for (int i = 0; i < Count; i++) {
ret[i] = this[i];
}
return ret;
}
}
}
static class Extention {
public static string
Join<T>(this IEnumerable<T> x,
string separator = "") => string.Join(separator, x);
public static int UpperBound<T>(this IList<T> list, T value) =>
list.BinarySearch(value, true, 0, list.Count, Comparer<T>.Default);
public static int LowerBound<T>(this IList<T> list, T value) =>
list.BinarySearch(value, false, 0, list.Count, Comparer<T>.Default);
public static int BinarySearch<T>(this IList<T> list, T value,
bool isUpperBound, int index, int length,
Comparer<T> comparer) {
var ng = index - 1;
var ok = index + length;
while (ok - ng > 1) {
var mid = ng + (ok - ng) / 2;
var res = comparer.Compare(list[mid], value);
if (res < 0 || (isUpperBound && res == 0))
ng = mid;
else
ok = mid;
}
return ok;
}
}
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.A {
static class Program {
public static void Solve(Scanner cin) {
int n = cin.ReadInt();
var a = cin.ReadIntArray(n);
var deque = new Deque<int>();
for (int i = 0; i < n; i++) {
if (i % 2 == 0)
deque.PushBack(a[i]);
else
deque.PushFront(a[i]);
}
var ans = deque.Items;
if (n % 2 == 1)
Console.WriteLine(ans.Reverse().Join(" "));
else
Console.WriteLine(ans.Join(" "));
}
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;
}
}
public class Deque<T> : IEnumerable<T> {
int dx;
T[] buffer;
int mask;
public int Count { get; private set; }
public Deque() : this(8) {}
public Deque(int capacity) {
if (capacity != (capacity & -capacity)) {
int tmp = capacity;
capacity = 1;
while (capacity < tmp) {
capacity <<= 1;
}
}
mask = capacity - 1;
buffer = new T[capacity];
}
public Deque(IEnumerable<T> value) : this(value.Count()) {
int i = 0;
foreach (var e in value) {
buffer[i] = e;
i++;
}
}
public T this[int index] {
get { return buffer[(index + dx) & mask]; }
set {
if (0 <= index && index < Count)
throw new IndexOutOfRangeException();
buffer[(index + dx) & mask] = value;
}
}
public void PushFront(T item) {
if (Count == buffer.Length)
extend();
dx = (dx + buffer.Length - 1) & mask;
buffer[dx] = item;
Count++;
}
public T PopFront() {
var ret = buffer[dx = (dx + 1) & mask];
Count--;
return ret;
}
public T Last => buffer[(dx + Count - 1) & mask];
public void PushBack(T item) {
if (Count == buffer.Length)
extend();
buffer[(dx + Count++) & mask] = item;
}
public T PopBack() {
var ret = buffer[(dx + --Count) & mask];
return ret;
}
public T First => buffer[dx];
private void extend() {
var newBuffer = new T[buffer.Length * 2];
for (int i = 0; i < buffer.Length; i++) {
newBuffer[i] = buffer[(dx + i) & mask];
}
mask = newBuffer.Length - 1;
dx = 0;
buffer = newBuffer;
}
public void Clear() {
Count = 0;
buffer = new T[8];
dx = 0;
mask = buffer.Length - 1;
}
public void AddAt(int index, T item) {
PushFront(item);
for (int i = 0; i < index; i++) {
this[i] = this[i + 1];
}
this[index] = item;
}
public T RemoveAt(int index) {
var ret = this[index];
for (int i = index; i > 0; i--) {
this[i] = this[i - 1];
}
PopFront();
return ret;
}
public IEnumerator<T> GetEnumerator() {
for (int i = 0; i < Count; i++) {
yield return this[i];
}
}
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator() => this.GetEnumerator();
public T[] Items {
get {
var ret = new T[Count];
for (int i = 0; i < Count; i++) {
ret[i] = this[i];
}
return ret;
}
}
}
static class Extention {
public static string
Join<T>(this IEnumerable<T> x,
string separator = "") => string.Join(separator, x);
public static int UpperBound<T>(this IList<T> list, T value) =>
list.BinarySearch(value, true, 0, list.Count, Comparer<T>.Default);
public static int LowerBound<T>(this IList<T> list, T value) =>
list.BinarySearch(value, false, 0, list.Count, Comparer<T>.Default);
public static int BinarySearch<T>(this IList<T> list, T value,
bool isUpperBound, int index, int length,
Comparer<T> comparer) {
var ng = index - 1;
var ok = index + length;
while (ok - ng > 1) {
var mid = ng + (ok - ng) / 2;
var res = comparer.Compare(list[mid], value);
if (res < 0 || (isUpperBound && res == 0))
ng = mid;
else
ok = mid;
}
return ok;
}
}
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, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
| 8
| 3,598
| 15
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
// var n = int.Parse(Console.ReadLine());
int[] np = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = np[0];
var p = np[1];
var e = new List<int>();
var o = new List<int>();
for (int i = 0; i < a.Length; i++) {
if (a[i] % 2 == 0)
e.Add(a[i]);
else
o.Add(a[i]);
}
long ans = 0;
if (p == 0) {
ans = (long)Math.Pow(2, e.Count());
long tmp = 0;
for (int i = 0; i <= o.Count; i += 2) {
tmp += nCr(o.Count, i);
}
ans *= tmp;
} else {
ans = (long)Math.Pow(2, e.Count());
long tmp = 0;
for (int i = 1; i <= o.Count; i += 2) {
tmp += nCr(o.Count, i);
}
ans *= tmp;
}
// 出力
Console.WriteLine(ans);
}
public static long nCr(long n, long r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static long nPr(long n, long r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static long FactorialDivision(long topFactorial,
long divisorFactorial) {
long result = 1;
for (long i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static long Factorial(long i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
// var n = int.Parse(Console.ReadLine());
int[] np = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var n = np[0];
var p = np[1];
var e = new List<int>();
var o = new List<int>();
for (int i = 0; i < a.Length; i++) {
if (a[i] % 2 == 0)
e.Add(a[i]);
else
o.Add(a[i]);
}
decimal ans = 0;
if (p == 0) {
ans = (decimal)Math.Pow(2, e.Count());
decimal tmp = 0;
for (int i = 0; i <= o.Count; i += 2) {
tmp += nCr(o.Count, i);
}
ans *= tmp;
} else {
ans = (decimal)Math.Pow(2, e.Count());
decimal tmp = 0;
for (int i = 1; i <= o.Count; i += 2) {
tmp += nCr(o.Count, i);
}
ans *= tmp;
}
// 出力
Console.WriteLine(ans);
}
public static decimal nCr(decimal n, decimal r) {
// naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
return nPr(n, r) / Factorial(r);
}
public static decimal nPr(decimal n, decimal r) {
// naive: return Factorial(n) / Factorial(n - r);
return FactorialDivision(n, n - r);
}
private static decimal FactorialDivision(decimal topFactorial,
decimal divisorFactorial) {
decimal result = 1;
for (decimal i = topFactorial; i > divisorFactorial; i--)
result *= i;
return result;
}
private static decimal Factorial(decimal i) {
if (i <= 1)
return 1;
return i * Factorial(i - 1);
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["-", 75, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 75, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 440
| 36
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ここから
static void Solve() {
int N = GetInt();
var A = GetIntArray();
var B = new LinkedList<int>();
for (int i = 0; i < N; i++) {
if (i % 2 == 0) {
B.AddLast(A[i]);
} else {
B.AddFirst(A[i]);
}
}
if (N % 2 == 1) {
B.Reverse();
}
WriteObjects(B.ToArray());
// Console.WriteLine(ans);
}
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public void WriteObjects<T>(IList<T> values) {
var num = values.Count;
for (int i = 0; i < num; i++) {
Console.Write(values[i]);
if (i < num - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCoder {
partial class Program {
static long mod = 1000000007;
static void Main() {
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
Solve();
Console.Out.Flush();
Console.ReadKey();
}
//ここから
static void Solve() {
int N = GetInt();
var A = GetIntArray();
var B = new LinkedList<int>();
for (int i = 0; i < N; i++) {
if (i % 2 == 0) {
B.AddLast(A[i]);
} else {
B.AddFirst(A[i]);
}
}
if (N % 2 == 1) {
B = new LinkedList<int>(B.Reverse().ToArray());
}
WriteObjects(B.ToArray());
// Console.WriteLine(ans);
}
}
//拡張メソッド
public static class Ex {
public static List<string> FastSort(this List<string> s) {
s.Sort(StringComparer.Ordinal);
return s.ToList();
}
public static string yesno(this bool b) { return b ? "yes" : "no"; }
public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
}
partial class Program {
static public string GetStr() { return Console.ReadLine().Trim(); }
static public char GetChar() { return Console.ReadLine().Trim()[0]; }
static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
static public double GetDouble() {
return double.Parse(Console.ReadLine().Trim());
}
static public string[] GetStrArray() {
return Console.ReadLine().Trim().Split(' ');
}
static public int[] GetIntArray() {
return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
}
static public long[] GetLongArray() {
return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
}
static public char[] GetCharArray() {
return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray();
}
static public double[] GetDoubleArray() {
return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
}
static public void WriteObjects<T>(IList<T> values) {
var num = values.Count;
for (int i = 0; i < num; i++) {
Console.Write(values[i]);
if (i < num - 1) {
Console.Write(" ");
}
}
Console.WriteLine();
}
static bool eq<T, U>() => typeof(T).Equals(typeof(U));
static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
: eq<T, long>() ? ct<T, long>(long.Parse(s))
: eq<T, double>() ? ct<T, double>(double.Parse(s))
: eq<T, char>() ? ct<T, char>(s[0])
: ct<T, string>(s);
static void Multi<T>(out T a) => a = cv<T>(GetStr());
static void Multi<T, U>(out T a, out U b) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
}
static void Multi<T, U, V>(out T a, out U b, out V c) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
}
static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
}
static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d,
out X e) {
var ar = GetStrArray();
a = cv<T>(ar[0]);
b = cv<U>(ar[1]);
c = cv<V>(ar[2]);
d = cv<W>(ar[3]);
e = cv<X>(ar[4]);
}
}
}
|
[["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 230, 0, 228], ["+", 0, 1, 0, 11, 12, 230, 39, 236, 141, 22], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 1,195
| 13
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class116 {
static void Main() {
var NP = Console.ReadLine();
int N = NP[0], P = NP[1];
var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int even = A.Count(x => x % 2 == 0);
int odd = A.Count() - even;
long ans = 1;
if (P == 0) {
ans *= (long)Math.Pow(2, even);
if (odd > 0)
ans *= (long)Math.Pow(2, odd - 1);
} else {
ans *= (long)Math.Pow(2, even);
if (odd > 0)
ans *= (long)Math.Pow(2, odd - 1);
else
ans *= 0;
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class116 {
static void Main() {
var NP = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = NP[0], P = NP[1];
var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int even = A.Count(x => x % 2 == 0);
int odd = A.Count() - even;
long ans = 1;
if (P == 0) {
ans *= (long)Math.Pow(2, even);
if (odd > 0)
ans *= (long)Math.Pow(2, odd - 1);
} else {
ans *= (long)Math.Pow(2, even);
if (odd > 0)
ans *= (long)Math.Pow(2, odd - 1);
else
ans *= 0;
}
Console.WriteLine(ans);
}
}
}
|
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 217
| 15
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace C {
internal class Program {
private static int n;
private static List<int> an;
private static LinkedList<int> b;
private static bool insertLeft;
public static void Main(string[] args) {
n = int.Parse(Console.ReadLine());
an = new List<int>(n);
b = new LinkedList<int>(new List<int>(n));
an.AddRange(Console.ReadLine().Split().Select(int.Parse).ToArray());
insertLeft = n % 2 != 0;
foreach (var a in an) {
if (insertLeft) {
b.AddFirst(a);
} else {
b.AddLast(a);
}
insertLeft = !insertLeft;
}
foreach (var bi in b) {
Console.Write($"{bi} ");
}
Console.WriteLine('\b');
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace C {
internal class Program {
private static int n;
private static List<int> an;
private static LinkedList<int> b;
private static bool insertLeft;
public static void Main(string[] args) {
n = int.Parse(Console.ReadLine());
an = new List<int>(n);
b = new LinkedList<int>(new List<int>(n));
an.AddRange(Console.ReadLine().Split().Select(int.Parse).ToArray());
insertLeft = n % 2 != 0;
foreach (var a in an) {
if (insertLeft) {
b.AddFirst(a);
} else {
b.AddLast(a);
}
insertLeft = !insertLeft;
}
for (var i = 0; i < n - 1; i++) {
Console.Write($"{b.First.Value} ");
b.RemoveFirst();
}
Console.WriteLine(b.First.Value);
}
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 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, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["+", 0, 283, 0, 284, 0, 214, 205, 214, 205, 22], ["+", 0, 283, 0, 284, 0, 214, 205, 214, 0, 131], ["+", 0, 283, 0, 284, 0, 214, 205, 214, 141, 22], ["+", 0, 28, 0, 283, 0, 284, 0, 214, 0, 131], ["+", 0, 28, 0, 283, 0, 284, 0, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 44], ["+", 3, 4, 0, 28, 0, 214, 205, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 214, 205, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 214, 205, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
| 8
| 205
| 37
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class2 {
static void Main() {
var NP = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = NP[0], P = NP[1];
var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int odd = A.Count(x => x % 2 == 1);
int even = A.Count(x => x % 2 == 0);
long ans;
if (P == 0) {
ans = (long)Math.Pow(2, odd - 1) * (long)Math.Pow(2, even);
} else {
if (odd == 0)
ans = 0;
else {
ans = (long)Math.Pow(2, odd - 1) * (long)Math.Pow(2, even);
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp15 {
class Class2 {
static void Main() {
var NP = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = NP[0], P = NP[1];
var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
int odd = A.Count(x => x % 2 == 1);
int even = A.Count(x => x % 2 == 0);
long ans;
if (P == 0) {
if (odd == 0)
odd = 1;
ans = (long)Math.Pow(2, odd - 1) * (long)Math.Pow(2, even);
} else {
if (odd == 0)
ans = 0;
else {
ans = (long)Math.Pow(2, odd - 1) * (long)Math.Pow(2, even);
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 227
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;
class Program {
static Scanner cin = new Scanner();
internal static void Main(string[] args) {
var N = cin.nextInt();
var a = ReadLine().Split(' ');
var ans = new LinkedList<string>();
for (int i = 0; i < N; i++) {
if (i % 2 == 0) {
ans.AddLast(a[i]);
} else {
ans.AddFirst(a[i]);
}
}
if (N % 2 == 1) {
ans.Reverse();
}
WriteLine(string.Join(" ", ans));
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;
class Program {
static Scanner cin = new Scanner();
internal static void Main(string[] args) {
var N = cin.nextInt();
var a = ReadLine().Split(' ');
var ans = new LinkedList<string>();
for (int i = 0; i < N; i++) {
if (i % 2 == 0) {
ans.AddLast(a[i]);
} else {
ans.AddFirst(a[i]);
}
}
if (N % 2 == 1) {
WriteLine(string.Join(" ", ans.Reverse()));
} else {
WriteLine(string.Join(" ", ans));
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
|
[["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 514
| 15
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
Func cin2;
void calc() {
cin = new Scanner();
cin2 = new Func();
int[] NP = cin.ArrayInt(2, 0);
int[] a = cin.ArrayInt(NP[0], 0);
int oddcount = 0;
double ans = 0;
for (int i = 0; i < NP[0]; i++) {
if (a[i] % 2 == 1)
oddcount++;
}
if (oddcount == 0 && NP[1] == 1)
ans = 0;
else
ans = Math.Pow(2, NP[0] - 1);
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Answer {
public static void Int2DArrayAns(int[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
} // Answer.IntArrayAns(x);
public static void Char2DArrayAns(char[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
}
}
class Func {
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
Func cin2;
void calc() {
cin = new Scanner();
cin2 = new Func();
int[] NP = cin.ArrayInt(2, 0);
int[] a = cin.ArrayInt(NP[0], 0);
int oddcount = 0;
double ans = 0;
for (int i = 0; i < NP[0]; i++) {
if (a[i] % 2 == 1)
oddcount++;
}
if (oddcount == 0 && NP[1] == 1)
ans = 0;
else if (oddcount == 0)
ans = Math.Pow(2, NP[0]);
else
ans = Math.Pow(2, NP[0] - 1);
Console.WriteLine(ans);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = nextInt() + add;
}
return Array;
}
public long nextLong() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = nextLong() + add;
}
return Array;
}
public double nextDouble() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
class Answer {
public static void Int2DArrayAns(int[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
} // Answer.IntArrayAns(x);
public static void Char2DArrayAns(char[,] x, char c) {
for (int i = 0; i < x.GetLength(0); i++) {
for (int j = 0; j < x.GetLength(1) - 1; j++) {
Console.Write(x[i, j]);
Console.Write(c);
}
Console.WriteLine(x[i, x.GetLength(1) - 1]);
}
}
}
class Func {
public long GCDLong(long a, long b) {
while (a != 0) {
long t = a;
a = b % a;
b = t;
}
return b;
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 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], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 0, 57, 75, 57, 75, 1, 0, 11, 31, 22]]
| 8
| 801
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var np = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var odd = ar.Count(v => v % 2 == 1);
var even = np[0] - odd;
if (odd == 0 && np[1] == 1) {
WriteLine(0);
return;
}
WriteLine((long)Pow(2, np[0] - 1));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var np = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var odd = ar.Count(v => v % 2 == 1);
var even = np[0] - odd;
if (odd == 0 && np[1] == 1) {
WriteLine(0);
return;
}
WriteLine(odd == 0 ? (long)Pow(2, np[0]) : (long)Pow(2, np[0] - 1));
}
}
|
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 41, 64, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 41, 64, 74, 0, 25], ["+", 0, 28, 0, 41, 64, 74, 51, 213, 63, 22], ["+", 64, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 41, 64, 74, 51, 213, 3, 4, 0, 21], ["+", 51, 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], ["+", 0, 41, 64, 74, 51, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 74, 0, 24]]
| 8
| 160
| 17
|
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 Sol() {
int len = ri();
int index = len % 2 == 0 ? len / 2 : (len - 1) / 2;
long[] intarr = rla();
long[] finalArr = new long[len];
finalArr[index] = intarr[0];
for (int i = 1; i < len; i++) {
if (i % 2 == 1) { //--
finalArr[index - i] = intarr[i];
index = index - i;
} else {
finalArr[index + i] = intarr[i];
index = index + i;
} //++
}
if (len % 2 == 1) {
finalArr.Reverse();
}
Console.WriteLine(String.Join(" ", finalArr.ToArray()));
}
public void Solve() {}
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().Trim().Split(sep),
e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().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 Sol() {
int len = ri();
int index = len % 2 == 0 ? len / 2 : (len - 1) / 2;
long[] intarr = rla();
long[] finalArr = new long[len];
finalArr[index] = intarr[0];
for (int i = 1; i < len; i++) {
if (i % 2 == 1) { //--
finalArr[index - i] = intarr[i];
index = index - i;
} else {
finalArr[index + i] = intarr[i];
index = index + i;
} //++
}
if (len % 2 == 0) {
Console.WriteLine(String.Join(" ", finalArr));
} else {
Console.WriteLine(String.Join(" ", finalArr.Reverse()));
}
}
public void Solve() {}
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().Trim().Split(sep),
e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Trim().Split(sep),
e => double.Parse(e));
}
}
|
[["-", 0, 263, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 263, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 263, 8, 196, 0, 57, 0, 95], ["+", 0, 263, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 0, 263, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 461
| 21
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
long n = long.Parse(input[0]);
long p = long.Parse(input[1]);
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long mod = 999999999999999989;
long answer = 0;
long oneCount = 0; // 1(mod2)の個数
for (int i = 0; i < n; i++) {
nums[i] %= 2;
if (nums[i] == 1)
oneCount++;
}
for (long i = p; i <= oneCount; i += 2) // 1(mod2)の個数
{
answer += Comb(oneCount, i, mod);
Console.WriteLine(answer + " " + i + " " + oneCount);
}
for (long i = 0; i < n - oneCount; i++)
answer *= 2;
Console.WriteLine(answer);
}
static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x % p;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
answer %= p;
}
memo *= memo;
memo %= p;
num *= 2;
}
return answer;
}
static long DivideModReverse(long x, long p) //戻り値はx^-1(mod p), pは素数
{
long answer = DivideMod(x, p - 2, p);
return answer;
}
static long DivideModFactorial(long x, long p) //戻り値はx!^-1(mod p), pは素数
{
long answer = 1;
for (long i = x; i >= 2; i--) {
answer *= DivideModReverse(i, p);
answer %= p;
}
return answer;
}
static long Comb(long a, long b, long p) //戻り値は組み合わせC(a,b)のmod p
{
long answer = 1;
for (long i = a; i > a - b; i--) {
answer *= i;
answer %= p;
}
answer *= DivideModFactorial(b, p);
answer %= p;
return answer;
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
long n = long.Parse(input[0]);
long p = long.Parse(input[1]);
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long mod = 1000000007;
long answer = 0;
long oneCount = 0; // 1(mod2)の個数
for (int i = 0; i < n; i++) {
nums[i] %= 2;
if (nums[i] == 1)
oneCount++;
}
for (long i = p; i <= oneCount; i += 2) // 1(mod2)の個数
{
answer += Comb(oneCount, i, mod);
// Console.WriteLine(answer+" "+i+" "+oneCount);
}
for (long i = 0; i < n - oneCount; i++)
answer *= 2;
Console.WriteLine(answer);
}
static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p)
{
long num = 2;
long answer = 1;
long check = a;
long memo = x % p;
while (check > 0) {
if (check % num == num / 2) {
check -= num / 2;
answer *= memo;
answer %= p;
}
memo *= memo;
memo %= p;
num *= 2;
}
return answer;
}
static long DivideModReverse(long x, long p) //戻り値はx^-1(mod p), pは素数
{
long answer = DivideMod(x, p - 2, p);
return answer;
}
static long DivideModFactorial(long x, long p) //戻り値はx!^-1(mod p), pは素数
{
long answer = 1;
for (long i = x; i >= 2; i--) {
answer *= DivideModReverse(i, p);
answer %= p;
}
return answer;
}
static long Comb(long a, long b, long p) //戻り値は組み合わせC(a,b)のmod p
{
long answer = 1;
for (long i = a; i > a - b; i--) {
answer *= i;
answer %= p;
}
answer *= DivideModFactorial(b, p);
answer %= p;
return answer;
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 72], ["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 31, 16, 31, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 455
| 21
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
long[] d = { 1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
4096,
8192,
16384,
32768,
65536,
131072,
262144,
524288,
1048576,
2097152,
4194304,
8388608,
16777216,
33554432,
67108864,
134217728,
268435456,
536870912,
1073741824,
2147483648,
4294967296,
8589934592,
17179869184,
34359738368,
68719476736,
137438953472,
274877906944,
549755813888,
1099511627776,
2199023255552,
4398046511104,
8796093022208,
17592186044416,
35184372088832,
70368744177664,
140737488355328,
281474976710656,
562949953421312,
1125899906842624,
2251799813685248,
4503599627370496,
9007199254740992,
18014398509481984,
36028797018963968,
72057594037927936,
144115188075855872,
288230376151711744,
576460752303423488,
1152921504606846976,
2305843009213693952,
4611686018427387904 };
int[] NP = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int odd = 0;
int even = 0;
foreach (int i in a) {
if (i % 2 == 0)
even++;
else
odd++;
}
long res = d[even];
long r = 1;
long oddres = 1;
for (int i = 1; i <= odd; i++) {
r = (r * (odd + 1 - i)) / i;
if (i % 2 == NP[1])
oddres += r;
}
if (odd % 2 == 0) {
oddres++;
}
Console.WriteLine(res * oddres);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
long[] d = { 1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
1024,
2048,
4096,
8192,
16384,
32768,
65536,
131072,
262144,
524288,
1048576,
2097152,
4194304,
8388608,
16777216,
33554432,
67108864,
134217728,
268435456,
536870912,
1073741824,
2147483648,
4294967296,
8589934592,
17179869184,
34359738368,
68719476736,
137438953472,
274877906944,
549755813888,
1099511627776,
2199023255552,
4398046511104,
8796093022208,
17592186044416,
35184372088832,
70368744177664,
140737488355328,
281474976710656,
562949953421312,
1125899906842624,
2251799813685248,
4503599627370496,
9007199254740992,
18014398509481984,
36028797018963968,
72057594037927936,
144115188075855872,
288230376151711744,
576460752303423488,
1152921504606846976,
2305843009213693952,
4611686018427387904 };
int[] NP = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int odd = 0;
int even = 0;
foreach (int i in a) {
if (i % 2 == 0)
even++;
else
odd++;
}
long res = d[even];
long r = 1;
long oddres = 0;
if (NP[1] == 0) {
//初めのやつの追加
oddres++;
}
for (int i = 1; i <= odd; i++) {
r = (r * (odd + 1 - i)) / i;
if (i % 2 == NP[1])
oddres += r;
}
Console.WriteLine(res * oddres);
}
}
|
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29]]
| 8
| 332
| 27
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Solution {
public int N, P;
public int[] A;
public void Run() {
{
var line = Input.ReadIntArray();
N = line[0];
P = line[1];
A = Input.ReadIntArray();
}
int[] mods = new int[2];
for (int i = 0; i < N; i++) {
mods[i % 2]++;
}
// corner case
if (P == 1 && mods[1] == 0) {
Console.WriteLine(0);
return;
}
Console.WriteLine(Power(2, mods[0] + Math.Max(mods[1] - 1, 0)));
}
public long Power(long x, long n) {
long tmp = 1;
if (n > 0) {
tmp = Power(x, n / 2);
if (n % 2 == 0)
tmp = tmp * tmp;
else
tmp = tmp * tmp * x;
}
return tmp;
}
}
// libs ----------
// common ----------
internal static class Input {
public static string ReadString() {
string line = Console.ReadLine();
return line;
}
public static int ReadInt() {
string line = Console.ReadLine();
return int.Parse(line);
}
public static int[] ReadIntArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(int.Parse).ToArray();
}
public static long ReadLong() {
string line = Console.ReadLine();
return long.Parse(line);
}
public static long[] ReadLongArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(long.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(double.Parse).ToArray();
}
}
internal class Program {
public static void Main(string[] args) {
var s = new Solution();
s.Run();
}
}
}
|
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Solution {
public int N, P;
public int[] A;
public void Run() {
{
var line = Input.ReadIntArray();
N = line[0];
P = line[1];
A = Input.ReadIntArray();
}
int[] mods = new int[2];
for (int i = 0; i < N; i++) {
int m = A[i] % 2;
mods[m]++;
}
// corner case
if (P == 1 && mods[1] == 0) {
Console.WriteLine(0);
return;
}
int c = mods[0] + Math.Max(mods[1] - 1, 0);
long ret = Power(2, c);
Console.WriteLine(ret);
}
public long Power(long x, long n) {
long tmp = 1;
if (n > 0) {
tmp = Power(x, n / 2);
if (n % 2 == 0)
tmp = tmp * tmp;
else
tmp = tmp * tmp * x;
}
return tmp;
}
}
// libs ----------
// common ----------
internal static class Input {
public static string ReadString() {
string line = Console.ReadLine();
return line;
}
public static int ReadInt() {
string line = Console.ReadLine();
return int.Parse(line);
}
public static int[] ReadIntArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(int.Parse).ToArray();
}
public static long ReadLong() {
string line = Console.ReadLine();
return long.Parse(line);
}
public static long[] ReadLongArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(long.Parse).ToArray();
}
public static double[] ReadDoubleArray() {
string line = Console.ReadLine();
return line.Split(' ').Select(double.Parse).ToArray();
}
}
internal class Program {
public static void Main(string[] args) {
var s = new Solution();
s.Run();
}
}
}
|
[["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 8, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["+", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["+", 0, 1, 0, 223, 0, 204, 206, 207, 0, 70], ["+", 0, 223, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 461
| 43
|
using System;
using System.IO;
using System.Collections.Generic;
namespace ARC077C {
public class Program {
void Solve(StreamScanner ss, StreamWriter sw) {
//---------------------------------
var N = ss.Next(int.Parse);
var A = ss.Next(int.Parse, N);
var ll = new LinkedList<int>();
for (var i = 0; i < N; i++) {
if (i % 2 == 0)
ll.AddLast(A[i]);
else
ll.AddFirst(A[i]);
}
sw.WriteLine(string.Join(" ", ll));
//---------------------------------
}
static void Main() {
var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
new Program().Solve(ss, sw);
sw.Flush();
}
static readonly Func<string, string> String = s => s;
}
public class StreamScanner {
static readonly char[] Sep = { ' ' };
readonly Queue<string> buffer = new Queue<string>();
readonly TextReader textReader;
public StreamScanner(TextReader textReader) { this.textReader = textReader; }
public T Next<T>(Func<string, T> parser) {
if (buffer.Count != 0)
return parser(buffer.Dequeue());
var nextStrings =
textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
foreach (var nextString in nextStrings)
buffer.Enqueue(nextString);
return Next(parser);
}
public T[] Next<T>(Func<string, T> parser, int x) {
var ret = new T[x];
for (var i = 0; i < x; ++i)
ret[i] = Next(parser);
return ret;
}
public T[][] Next<T>(Func<string, T> parser, int x, int y) {
var ret = new T[y][];
for (var i = 0; i < y; ++i)
ret[i] = Next(parser, x);
return ret;
}
}
}
|
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace ARC077C {
public class Program {
void Solve(StreamScanner ss, StreamWriter sw) {
//---------------------------------
var N = ss.Next(int.Parse);
var A = ss.Next(int.Parse, N);
var ll = new LinkedList<int>();
for (var i = 0; i < N; i++) {
if (i % 2 == 0)
ll.AddLast(A[i]);
else
ll.AddFirst(A[i]);
}
sw.WriteLine(string.Join(" ", N % 2 == 0 ? ll : ll.Reverse()));
//---------------------------------
}
static void Main() {
var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
new Program().Solve(ss, sw);
sw.Flush();
}
static readonly Func<string, string> String = s => s;
}
public class StreamScanner {
static readonly char[] Sep = { ' ' };
readonly Queue<string> buffer = new Queue<string>();
readonly TextReader textReader;
public StreamScanner(TextReader textReader) { this.textReader = textReader; }
public T Next<T>(Func<string, T> parser) {
if (buffer.Count != 0)
return parser(buffer.Dequeue());
var nextStrings =
textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
foreach (var nextString in nextStrings)
buffer.Enqueue(nextString);
return Next(parser);
}
public T[] Next<T>(Func<string, T> parser, int x) {
var ret = new T[x];
for (var i = 0; i < x; ++i)
ret[i] = Next(parser);
return ret;
}
public T[][] Next<T>(Func<string, T> parser, int x, int y) {
var ret = new T[y][];
for (var i = 0; i < y; ++i)
ret[i] = Next(parser, x);
return ret;
}
}
}
|
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 28, 0, 41, 75, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 41, 75, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 41, 75, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 41, 75, 213, 3, 4, 0, 25]]
| 8
| 458
| 17
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Xml.Schema;
namespace ConsoleApplication {
class MainClass {
private int N, P;
private int[] A;
void Solve() {
io.i(out N, out P);
io.ini(out A, N);
var eve = A.Where(v => !v.Odd()).ToArray();
var odd = A.Where(v => v.Odd()).ToArray();
var ans = 0L;
if (P == 0) {
//偶数にする
var byEve = 0L;
var byOdd = 0L;
eve.Length.REP(i => byEve += mat.C(eve.Length, i + 1));
for (int i = 2; i <= odd.Length; i += 2)
byOdd += mat.C(odd.Length, i);
ans += byEve;
ans += byOdd;
ans += byEve * byOdd + 1;
} else {
//奇数にする
var byEve = 0L;
var byOdd = 0L;
eve.Length.REP(i => byEve += mat.C(eve.Length, i + 1));
for (int i = 1; i <= odd.Length; i += 2)
byOdd += mat.C(odd.Length, i);
ans += byOdd;
ans += byEve * byOdd;
}
io.o(ans);
}
public static void Main() => new MainClass().Stream();
IO io = new IO();
Mat mat = new Mat();
void Stream() {
Solve();
// Test();
io.Flush();
}
void Test() {
var sum = 0L;
100.REP(i => sum += mat.C(100, i + 1));
io.o(sum);
}
}
#region Default
class IO {
#region INPUT
int _buffCnt;
string[] _nextBuff;
private readonly char[] _splitCharacter = new char[] { ' ' };
private readonly StreamWriter _sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
_nextBuff = new string[0];
_buffCnt = 0;
Console.SetOut(_sw);
}
private string Next() {
if (_buffCnt < _nextBuff.Length)
return _nextBuff[_buffCnt++];
var str = Scan;
while (str == "")
str = Scan;
_nextBuff =
str.Split(_splitCharacter, StringSplitOptions.RemoveEmptyEntries);
_buffCnt = 0;
return _nextBuff[_buffCnt++];
}
private string Scan => Console.ReadLine();
private string[] Arr => Scan.Split(' ');
private void Read<T>(out T v) => v = SuitType<T>(Next());
private T ConvertType<T, TU>(TU v) => (T)Convert.ChangeType(v, typeof(T));
private bool TypeEqual<T, TU>() => typeof(T) == typeof(TU);
private T SuitType<T>(string s) =>
TypeEqual<T, int>() ? ConvertType<T, int>(int.Parse(s))
: TypeEqual<T, long>() ? ConvertType<T, long>(long.Parse(s))
: TypeEqual<T, double>() ? ConvertType<T, double>(double.Parse(s))
: TypeEqual<T, char>() ? ConvertType<T, char>(char.Parse(s))
: ConvertType<T, string>(s);
public string String => Next();
public char Char => char.Parse(Next());
public int Int => int.Parse(Next());
public long Long => long.Parse(Next());
public double Double => double.Parse(Next());
public string[] ArrString => Arr;
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 void Flush() => Console.Out.Flush();
public T i<T>() { return SuitType<T>(String); }
public void i<T>(out T v) => Read(out v);
public void i<T, TU>(out T t, out TU u) {
i(out t);
i(out u);
}
public void i<T, TU, TV>(out T t, out TU u, out TV v) {
i(out t, out u);
i(out v);
}
public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
i(out t, out u, out v);
i(out w);
}
public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
i(out t, out u, out v, out w);
i(out x);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = i<T>();
}
public void ini<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<TU>();
}
}
public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<TU>();
c[i] = i<TV>();
}
}
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 ini<T, TU>(out Tuple<T, TU>[] t, int n) {
t = new Tuple<T, TU>[n];
for (int j = 0; j < n; ++j) {
T i1;
TU i2;
i(out i1, out i2);
t[j] = Tuple.Create(i1, i2);
}
}
public void ini<T, TU, TV>(out Tuple<T, TU, TV>[] t, int n) {
t = new Tuple<T, TU, TV>[n];
for (int j = 0; j < n; ++j) {
T i1;
TU i2;
TV i3;
i(out i1, out i2, out i3);
t[j] = Tuple.Create(i1, i2, i3);
}
}
#endregion
#region OUTPUT
private void Out<T>(T v) => Console.Write(v);
private void OutLine<T>(T v) => Console.WriteLine(v);
public void o<T>(T v) => OutLine(v);
public void o<T>(params T[] a) => Array.ForEach(a, OutLine);
public void o<T>(T[,] a) {
int a0 = a.GetLength(0), a1 = a.GetLength(1);
for (int i = 0; i < a0; ++i) {
for (int j = 0; j < a1 - 1; ++j)
Out(a[i, j] + " ");
OutLine(a[i, a1 - 1]);
}
}
public void ol<T>(params T[] a) => OutLine(string.Join(" ", a));
public void YN(bool f) => OutLine(f ? "YES" : "NO");
public void Yn(bool f) => OutLine(f ? "Yes" : "No");
public void yn(bool f) => OutLine(f ? "yes" : "no");
#endregion
}
class Mat {
public long mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long[,] C(int N) {
long[,] Co = new long[N + 1, N + 1];
(N + 1).REP(i => (i + 1).REP(j => Co[i, j] =
(j == 0 || j == i)
? 1L
: Co[i - 1, j - 1] + Co[i - 1, j]));
return Co;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
if (n == 0)
return 0;
if (n < 0 || n < r)
throw new ArgumentException("n or r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long H(long n, long r) => C(n + r - 1, r);
public long P(long n, long r) => Fact(n) / Fact(n - r);
public long Lcm(long a, long b) => a * (b / Gcd(a, b));
public long Lcm(params long[] a) => 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) => array.Aggregate((v, n) => Gcd(v, n));
public T Max<T>(params T[] a) => a.Max();
public T Min<T>(params T[] a) => 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) => Math.Sqrt(Math.Pow((x2 - x1), 2) +
Math.Pow((y2 - y1), 2));
public int ManhattanDis(int x1, int y1, int x2,
int y2) => Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
public int[] DigArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long DigArr2Num(IEnumerable<int> enu) {
return enu.Aggregate((v, n) => v * 10 + n);
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public long Tousa(long a, long d, long n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, long n) {
return n * (2 * a + (n - 1) * d) / 2;
}
public long[] EnuDivsor(long N) {
var ret = new SortedSet<long>();
for (long i = 1; i * i <= N; i++)
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
return ret.ToArray();
}
public Dictionary<long, long> PrimeFactor(long n) {
var ret = new Dictionary<long, long>();
for (int i = 2; i * i <= n; ++i) {
if (!ret.ContainsKey(i))
ret[i] = 0;
while (n % i == 0) {
++ret[i];
n /= i;
}
}
return ret.Where(kp => kp.Value != 0)
.ToDictionary(kp => kp.Key, kp => kp.Value);
}
}
public struct Edge : IComparable<Edge> {
public int To;
public long Cost;
public Edge(int to, long cost) {
To = to;
Cost = cost;
}
public int CompareTo(Edge e) => Cost.CompareTo(e.Cost);
}
#endregion
#region MyEx
static class StringEX {
public static string Reversed(this string s) => string.Join("", s.Reverse());
public static string Repeated(this string s, int n) =>
string.Concat(Enumerable.Repeat(s, n).ToArray());
public static string toString(this char[] a) => new string(a);
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) => toInt(c.ToString());
public static int toInt(this char[] c) => toInt(c.toString());
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : 0L;
}
public static long toLong(this char c) => toLong(c.ToString());
public static long toLong(this char[] c) => toLong(c.toString());
}
static class NumericEX {
public static string
toString(this double d) => d.ToString("R", CultureInfo.InvariantCulture);
public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0');
public static string RoundOff(this double v, int n) =>
Math.Round(v, n - 1, MidpointRounding.AwayFromZero).toString();
public static string RoundUp(this double v) => Math.Ceiling(v).toString();
public static string RoundDown(this double v) => Math.Floor(v).toString();
public static bool Odd(this int v) => (v & 1) != 0;
public static bool Odd(this long v) => (v & 1) != 0;
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Reverse(a.Sort());
return a;
}
public static void Set<T>(this T[] a, T v) => a.Length.REP(i => a[i] = v);
public static void Set<T>(this T[,] a, T v) =>
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
public static int LowerBound<T>(this T[] a, T x)
where T : IComparable {
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) >= 0)
ub = mid;
else
lb = mid;
}
return ub;
}
public static int UpperBound<T>(this T[] a, T x)
where T : IComparable {
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) > 0)
ub = mid;
else
lb = mid;
}
return ub;
}
public static int Range<T>(this T[] a, T from, T to)
where T : IComparable => a.UpperBound(to) - a.LowerBound(from); }
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Xml.Schema;
namespace ConsoleApplication {
class MainClass {
private int N, P;
private int[] A;
void Solve() {
io.i(out N, out P);
io.ini(out A, N);
var eve = A.Where(v => !v.Odd()).ToArray();
var odd = A.Where(v => v.Odd()).ToArray();
var ans = 0L;
var cTable = mat.C(100);
if (P == 0) {
//偶数にする
var byEve = 0L;
var byOdd = 0L;
eve.Length.REP(i => byEve += cTable[eve.Length, i + 1]);
for (int i = 2; i <= odd.Length; i += 2)
byOdd += cTable[odd.Length, i];
ans += byEve;
ans += byOdd;
ans += byEve * byOdd + 1;
} else {
//奇数にする
var byEve = 0L;
var byOdd = 0L;
eve.Length.REP(i => byEve += cTable[eve.Length, i + 1]);
for (int i = 1; i <= odd.Length; i += 2)
byOdd += cTable[odd.Length, i];
ans += byOdd;
ans += byEve * byOdd;
}
io.o(ans);
}
public static void Main() => new MainClass().Stream();
IO io = new IO();
Mat mat = new Mat();
void Stream() {
Solve();
// Test();
io.Flush();
}
void Test() {
var sum = 0L;
100.REP(i => sum += mat.C(100, i + 1));
io.o(sum);
}
}
#region Default
class IO {
#region INPUT
int _buffCnt;
string[] _nextBuff;
private readonly char[] _splitCharacter = new char[] { ' ' };
private readonly StreamWriter _sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
_nextBuff = new string[0];
_buffCnt = 0;
Console.SetOut(_sw);
}
private string Next() {
if (_buffCnt < _nextBuff.Length)
return _nextBuff[_buffCnt++];
var str = Scan;
while (str == "")
str = Scan;
_nextBuff =
str.Split(_splitCharacter, StringSplitOptions.RemoveEmptyEntries);
_buffCnt = 0;
return _nextBuff[_buffCnt++];
}
private string Scan => Console.ReadLine();
private string[] Arr => Scan.Split(' ');
private void Read<T>(out T v) => v = SuitType<T>(Next());
private T ConvertType<T, TU>(TU v) => (T)Convert.ChangeType(v, typeof(T));
private bool TypeEqual<T, TU>() => typeof(T) == typeof(TU);
private T SuitType<T>(string s) =>
TypeEqual<T, int>() ? ConvertType<T, int>(int.Parse(s))
: TypeEqual<T, long>() ? ConvertType<T, long>(long.Parse(s))
: TypeEqual<T, double>() ? ConvertType<T, double>(double.Parse(s))
: TypeEqual<T, char>() ? ConvertType<T, char>(char.Parse(s))
: ConvertType<T, string>(s);
public string String => Next();
public char Char => char.Parse(Next());
public int Int => int.Parse(Next());
public long Long => long.Parse(Next());
public double Double => double.Parse(Next());
public string[] ArrString => Arr;
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 void Flush() => Console.Out.Flush();
public T i<T>() { return SuitType<T>(String); }
public void i<T>(out T v) => Read(out v);
public void i<T, TU>(out T t, out TU u) {
i(out t);
i(out u);
}
public void i<T, TU, TV>(out T t, out TU u, out TV v) {
i(out t, out u);
i(out v);
}
public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
i(out t, out u, out v);
i(out w);
}
public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w,
out TX x) {
i(out t, out u, out v, out w);
i(out x);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = i<T>();
}
public void ini<T, TU>(out T[] a, out TU[] b, int n) {
a = new T[n];
b = new TU[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<TU>();
}
}
public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
a = new T[n];
b = new TU[n];
c = new TV[n];
for (int i = 0; i < n; ++i) {
a[i] = i<T>();
b[i] = i<TU>();
c[i] = i<TV>();
}
}
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 ini<T, TU>(out Tuple<T, TU>[] t, int n) {
t = new Tuple<T, TU>[n];
for (int j = 0; j < n; ++j) {
T i1;
TU i2;
i(out i1, out i2);
t[j] = Tuple.Create(i1, i2);
}
}
public void ini<T, TU, TV>(out Tuple<T, TU, TV>[] t, int n) {
t = new Tuple<T, TU, TV>[n];
for (int j = 0; j < n; ++j) {
T i1;
TU i2;
TV i3;
i(out i1, out i2, out i3);
t[j] = Tuple.Create(i1, i2, i3);
}
}
#endregion
#region OUTPUT
private void Out<T>(T v) => Console.Write(v);
private void OutLine<T>(T v) => Console.WriteLine(v);
public void o<T>(T v) => OutLine(v);
public void o<T>(params T[] a) => Array.ForEach(a, OutLine);
public void o<T>(T[,] a) {
int a0 = a.GetLength(0), a1 = a.GetLength(1);
for (int i = 0; i < a0; ++i) {
for (int j = 0; j < a1 - 1; ++j)
Out(a[i, j] + " ");
OutLine(a[i, a1 - 1]);
}
}
public void ol<T>(params T[] a) => OutLine(string.Join(" ", a));
public void YN(bool f) => OutLine(f ? "YES" : "NO");
public void Yn(bool f) => OutLine(f ? "Yes" : "No");
public void yn(bool f) => OutLine(f ? "yes" : "no");
#endregion
}
class Mat {
public long mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long[,] C(int N) {
long[,] Co = new long[N + 1, N + 1];
(N + 1).REP(i => (i + 1).REP(j => Co[i, j] =
(j == 0 || j == i)
? 1L
: Co[i - 1, j - 1] + Co[i - 1, j]));
return Co;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
if (n == 0)
return 0;
if (n < 0 || n < r)
throw new ArgumentException("n or r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long H(long n, long r) => C(n + r - 1, r);
public long P(long n, long r) => Fact(n) / Fact(n - r);
public long Lcm(long a, long b) => a * (b / Gcd(a, b));
public long Lcm(params long[] a) => 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) => array.Aggregate((v, n) => Gcd(v, n));
public T Max<T>(params T[] a) => a.Max();
public T Min<T>(params T[] a) => 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) => Math.Sqrt(Math.Pow((x2 - x1), 2) +
Math.Pow((y2 - y1), 2));
public int ManhattanDis(int x1, int y1, int x2,
int y2) => Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
public int[] DigArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long DigArr2Num(IEnumerable<int> enu) {
return enu.Aggregate((v, n) => v * 10 + n);
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public long Tousa(long a, long d, long n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, long n) {
return n * (2 * a + (n - 1) * d) / 2;
}
public long[] EnuDivsor(long N) {
var ret = new SortedSet<long>();
for (long i = 1; i * i <= N; i++)
if (N % i == 0) {
ret.Add(i);
ret.Add(N / i);
}
return ret.ToArray();
}
public Dictionary<long, long> PrimeFactor(long n) {
var ret = new Dictionary<long, long>();
for (int i = 2; i * i <= n; ++i) {
if (!ret.ContainsKey(i))
ret[i] = 0;
while (n % i == 0) {
++ret[i];
n /= i;
}
}
return ret.Where(kp => kp.Value != 0)
.ToDictionary(kp => kp.Key, kp => kp.Value);
}
}
public struct Edge : IComparable<Edge> {
public int To;
public long Cost;
public Edge(int to, long cost) {
To = to;
Cost = cost;
}
public int CompareTo(Edge e) => Cost.CompareTo(e.Cost);
}
#endregion
#region MyEx
static class StringEX {
public static string Reversed(this string s) => string.Join("", s.Reverse());
public static string Repeated(this string s, int n) =>
string.Concat(Enumerable.Repeat(s, n).ToArray());
public static string toString(this char[] a) => new string(a);
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) => toInt(c.ToString());
public static int toInt(this char[] c) => toInt(c.toString());
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : 0L;
}
public static long toLong(this char c) => toLong(c.ToString());
public static long toLong(this char[] c) => toLong(c.toString());
}
static class NumericEX {
public static string
toString(this double d) => d.ToString("R", CultureInfo.InvariantCulture);
public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0');
public static string RoundOff(this double v, int n) =>
Math.Round(v, n - 1, MidpointRounding.AwayFromZero).toString();
public static string RoundUp(this double v) => Math.Ceiling(v).toString();
public static string RoundDown(this double v) => Math.Floor(v).toString();
public static bool Odd(this int v) => (v & 1) != 0;
public static bool Odd(this long v) => (v & 1) != 0;
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Reverse(a.Sort());
return a;
}
public static void Set<T>(this T[] a, T v) => a.Length.REP(i => a[i] = v);
public static void Set<T>(this T[,] a, T v) =>
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
public static int LowerBound<T>(this T[] a, T x)
where T : IComparable {
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) >= 0)
ub = mid;
else
lb = mid;
}
return ub;
}
public static int UpperBound<T>(this T[] a, T x)
where T : IComparable {
int lb = -1, ub = a.Length;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (a[mid].CompareTo(x) > 0)
ub = mid;
else
lb = mid;
}
return ub;
}
public static int Range<T>(this T[] a, T from, T to)
where T : IComparable => a.UpperBound(to) - a.LowerBound(from); }
#endregion
}
|
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 218, 8, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 218, 8, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 218, 8, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 218, 8, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 8, 11, 12, 204, 205, 22], ["+", 0, 218, 8, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 218, 8, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 218, 8, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 8, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 8, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 8, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 7, 8, 1, 0, 11, 12, 204, 205, 22], ["+", 8, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 8, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
| 8
| 3,830
| 42
|
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z {
static void Main() => new K();
}
class K {
int F() => int.Parse(ReadLine());
long FL() => int.Parse(ReadLine());
int[] G() => ReadLine()
.Split(new char[] { ' ', '\t' },
StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.ToArray();
long[] GL() => ReadLine()
.Split(new char[] { ' ', '\t' },
StringSplitOptions.RemoveEmptyEntries)
.Select(long.Parse)
.ToArray();
public const int MOD = 1000000007;
public K() {
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
Solve();
Out.Flush();
}
void Solve() {
var A = G();
int N = A[0], P = A[1];
A = G();
var odd = 0;
foreach (var a in A)
if (a % 2 == 1)
odd++;
if (P == 1 && odd == 0)
WriteLine(0);
else
WriteLine(1L << (N - 1));
}
}
|
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z {
static void Main() => new K();
}
class K {
int F() => int.Parse(ReadLine());
long FL() => int.Parse(ReadLine());
int[] G() => ReadLine()
.Split(new char[] { ' ', '\t' },
StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.ToArray();
long[] GL() => ReadLine()
.Split(new char[] { ' ', '\t' },
StringSplitOptions.RemoveEmptyEntries)
.Select(long.Parse)
.ToArray();
public const int MOD = 1000000007;
public K() {
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
Solve();
Out.Flush();
}
void Solve() {
var A = G();
int N = A[0], P = A[1];
A = G();
var odd = 0;
foreach (var a in A)
if (a % 2 == 1)
odd++;
if (odd == 0)
WriteLine(P == 0 ? 1L << N : 0);
else
WriteLine(1L << (N - 1));
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 17, 151], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102]]
| 8
| 311
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AIZU {
class Program {
#region Reserve
static int cin() { return cin(-1); }
static int cin(int D) {
string s = Console.ReadLine();
if (string.IsNullOrEmpty(s))
return D;
return int.Parse(s);
}
static int[] cins(char spliter) {
string s = Console.ReadLine();
if (string.IsNullOrEmpty(s))
return new int[] {};
string[] ss = s.Split(spliter);
int[] Res = new int[ss.Length];
for (int i = 0; i < ss.Length; i++)
Res[i] = int.Parse(ss[i]);
return Res;
}
static int[] cins() { return cins(' '); }
static void print(object j) { Console.WriteLine(j.ToString()); }
static void print(string j) { Console.WriteLine(j); }
#endregion
static void Main(string[] args) {
Queue<string> Next = new Queue<string>();
Stack<string> Prev = new Stack<string>();
int n = cin();
string[] A = Console.ReadLine().Split();
for (int i = 0; i < n; i++) {
if ((i & 1) == 0)
Next.Enqueue(A[i]);
else
Prev.Push(A[i]);
}
string[] Res = new string[n];
int pc = Prev.Count;
for (int i = 0; i < pc; i++) {
Res[i] = Prev.Pop();
}
for (int i = pc; i < n; i++) {
Res[i] = Next.Dequeue();
}
print(string.Join(" ", Res));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AIZU {
class Program {
#region Reserve
static int cin() { return cin(-1); }
static int cin(int D) {
string s = Console.ReadLine();
if (string.IsNullOrEmpty(s))
return D;
return int.Parse(s);
}
static int[] cins(char spliter) {
string s = Console.ReadLine();
if (string.IsNullOrEmpty(s))
return new int[] {};
string[] ss = s.Split(spliter);
int[] Res = new int[ss.Length];
for (int i = 0; i < ss.Length; i++)
Res[i] = int.Parse(ss[i]);
return Res;
}
static int[] cins() { return cins(' '); }
static void print(object j) { Console.WriteLine(j.ToString()); }
static void print(string j) { Console.WriteLine(j); }
#endregion
static void Main(string[] args) {
Queue<string> Next = new Queue<string>();
Stack<string> Prev = new Stack<string>();
int n = cin();
string[] A = Console.ReadLine().Split();
for (int i = 0; i < n; i++) {
if ((i & 1) == 0)
Next.Enqueue(A[i]);
else
Prev.Push(A[i]);
}
string[] Res = new string[n];
int pc = Prev.Count;
for (int i = 0; i < pc; i++) {
Res[i] = Prev.Pop();
}
for (int i = pc; i < n; i++) {
Res[i] = Next.Dequeue();
}
if ((n & 1) == 1)
Res = Res.Reverse().ToArray();
print(string.Join(" ", Res));
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 67], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
| 8
| 428
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_B.Lib_IO;
using static Contest_B.Lib_Minifunc;
public static class Contest_B
{
public static void Main() {
checked{
long n,a,b,c,d;
Lib_IO.rm(out n,out a,out b, out c,out d);
swap2(ref a,ref b);
ll t = b-a;
ll s = d-c;
for (int i = 0; i < n; i++)
{
ll k = t - (n-1-2*i)*c;
if(0<=k&&ceiling(k,n)<=s){
wm("YES");
return;
}
}
wm("NO");
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換
[MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新
[MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c);
[MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
public struct P<T,U>
{
public T A; public U B;
public P(T a,U b) { A = a; B = b; }
public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B);
public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value);
}
public struct P<T,U,V>
{
public T A; public U B; public V C;
public P(T a,U b,V c) { A = a; B = b; C = c; }
}
public struct P<T,U,V,W>
{
public T A; public U B; public V C; public W D;
public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; }
}
public static class Lib_IO
{
class Prt : System.IO.StreamWriter
{
public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {}
public Prt(System.IO.Stream s,Encoding e) : base(s,e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[MethodImpl(256)] static T cv<T>(string s) =>
eq<T,int>() ? ct<T,int>(int.Parse(s))
: eq<T,long>() ? ct<T,long>(long.Parse(s))
: eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture))
: eq<T,char>() ? ct<T,char>(s[0])
: ct<T,string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T,U>(out T a,out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T,U,V>(out T a,out U b,out V c) {
var z = rm<T,U>(out a,out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) {
var z = rm<T,U,V>(out a,out b,out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) {
var z = rm<T,U,V,W>(out a,out b,out c,out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<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 z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = z.Select(cv<T>).ToArray();
return z;
}
public static string[][] rl<T>(long n,out T[] a) {
a = new T[n];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T,U>(long n,out P<T,U>[] a) {
a = new P<T,U>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p;
y[i] = rm(out o,out p);
a[i] = new P<T,U>(o,p);
}
return y;
}
public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) {
a = new P<T,U,V>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q;
y[i] = rm(out o,out p,out q);
a[i] = new P<T,U,V>(o,p,q);
}
return y;
}
public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) {
a = new P<T,U,V,W>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q; W r;
y[i] = rm(out o,out p,out q,out r);
a[i] = new P<T,U,V,W>(o,p,q,r);
}
return y;
}
public static string[][] rx<T>(long n,out T[][] a) {
a = new T[n][];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act){
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(()=>{
for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]);
Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); }
public static void wl<T>(IList<T> a) {
wwp(()=>{
var f = wfm(typeof(T));
foreach(T x in a) Console.WriteLine(f,x);
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(()=>{
var f = wfm(typeof(T));
var g = f + s;
foreach(var b in a) {
for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]);
Console.WriteLine(f,b[b.Count-1]);
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Numerics;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using ll=System.Int64;
using static Contest_B.Lib_IO;
using static Contest_B.Lib_Minifunc;
public static class Contest_B
{
public static void Main() {
checked{
long n,a,b,c,d;
Lib_IO.rm(out n,out a,out b, out c,out d);
swap2(ref a,ref b);
ll t = b-a;
ll s = d-c;
for (int i = 0; i < n; i++)
{
ll k = t - (n-1-2*i)*c;
if(i*-s<=k && k<=(n-i-1)*s){
wm("YES");
return;
}
}
wm("NO");
}
}
#region BaseModule
public static class Lib_Minifunc{
[MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; }
[MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換
[MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新
[MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新
[MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n);
[MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h));
[MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min();
[MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max();
[MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); }
[MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ
[MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b);
[MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c);
[MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d);
[MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } }
public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; }
public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; }
public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; }
public const long MOD1 = 1000000007; // 10^9+7
public const double EPS1 = 1e-8;
public const long INF1 = 1000000000000000; // 10^15
}
public struct P<T,U>
{
public T A; public U B;
public P(T a,U b) { A = a; B = b; }
public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B);
public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value);
}
public struct P<T,U,V>
{
public T A; public U B; public V C;
public P(T a,U b,V c) { A = a; B = b; C = c; }
}
public struct P<T,U,V,W>
{
public T A; public U B; public V C; public W D;
public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; }
}
public static class Lib_IO
{
class Prt : System.IO.StreamWriter
{
public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {}
public Prt(System.IO.Stream s,Encoding e) : base(s,e) {}
}
static Prt sw = new Prt(Console.OpenStandardOutput());
static char[] sp = new char[] {' '};
[MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U));
[MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T));
[MethodImpl(256)] static T cv<T>(string s) =>
eq<T,int>() ? ct<T,int>(int.Parse(s))
: eq<T,long>() ? ct<T,long>(long.Parse(s))
: eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture))
: eq<T,char>() ? ct<T,char>(s[0])
: ct<T,string>(s);
public static string[] rm<T>(out T a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = cv<T>(z[0]);
return z;
}
public static string[] rm<T,U>(out T a,out U b) {
var z = rm<T>(out a);
b = cv<U>(z[1]);
return z;
}
public static string[] rm<T,U,V>(out T a,out U b,out V c) {
var z = rm<T,U>(out a,out b);
c = cv<V>(z[2]);
return z;
}
public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) {
var z = rm<T,U,V>(out a,out b,out c);
d = cv<W>(z[3]);
return z;
}
public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) {
var z = rm<T,U,V,W>(out a,out b,out c,out d);
e = cv<X>(z[4]);
return z;
}
public static string[] rm<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 z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e);
f = cv<Y>(z[5]);
return z;
}
public static string[] ra<T>(out T[] a) {
var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries);
a = z.Select(cv<T>).ToArray();
return z;
}
public static string[][] rl<T>(long n,out T[] a) {
a = new T[n];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = rm(out a[i]);
return y;
}
public static string[][] rl<T,U>(long n,out P<T,U>[] a) {
a = new P<T,U>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p;
y[i] = rm(out o,out p);
a[i] = new P<T,U>(o,p);
}
return y;
}
public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) {
a = new P<T,U,V>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q;
y[i] = rm(out o,out p,out q);
a[i] = new P<T,U,V>(o,p,q);
}
return y;
}
public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) {
a = new P<T,U,V,W>[n];
var y = new string[n][];
for(int i=0;i<n;i++) {
T o; U p; V q; W r;
y[i] = rm(out o,out p,out q,out r);
a[i] = new P<T,U,V,W>(o,p,q,r);
}
return y;
}
public static string[][] rx<T>(long n,out T[][] a) {
a = new T[n][];
var y = new string[n][];
for(int i=0;i<n;i++) y[i] = ra(out a[i]);
return y;
}
static void wwp(Action act){
sw.AutoFlush = false;
Console.SetOut(sw);
act();
Console.Out.Flush();
sw.AutoFlush = true;
Console.SetOut(sw);
}
[MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
public static void wm(params object[] a) {
wwp(()=>{
for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]);
Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]);
});
}
public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); }
public static void wl<T>(IList<T> a) {
wwp(()=>{
var f = wfm(typeof(T));
foreach(T x in a) Console.WriteLine(f,x);
});
}
static void wxa<T>(IList<IList<T>> a, string s) {
wwp(()=>{
var f = wfm(typeof(T));
var g = f + s;
foreach(var b in a) {
for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]);
Console.WriteLine(f,b[b.Count-1]);
}
});
}
public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); }
public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); }
}
#endregion
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 15, 16, 31, 16, 31, 16, 12, 241, 0, 33], ["+", 15, 16, 31, 16, 31, 16, 12, 241, 0, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 213, 63, 22], ["-", 15, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["-", 15, 16, 12, 16, 31, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 15, 16, 12, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 48]]
| 8
| 2,993
| 16
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
int n = cin.Int();
int m = cin.Int();
var a = cin.ArrayInt(n, -1);
int max = m;
var minus = new int[max];
var plus = new int[max];
long init = 0;
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1]) {
init += a[i] - a[i - 1];
if (a[i - 1] + 2 <= a[i]) {
minus[a[i - 1] + 2] += -1;
minus[a[i] + 1] += 1;
}
if (a[i] + 1 != m) {
plus[((a[i] + 1) % m)] += Math.Max(0, a[i] - a[i - 1] - 1);
}
} else {
init += a[i] + 1;
if (a[i - 1] + 2 < m) {
minus[a[i - 1] + 2] += -1;
if (a[i - 1] + 2 != m - 1) {
minus[m - 1] += 1;
}
}
if (a[i - 1] == m - 1) {
if (a[i] > 0) {
minus[1] += -1;
minus[a[i] + 1] += 1;
}
} else {
if (a[i] > 0) {
minus[0] += -1;
minus[a[i] + 1] += 1;
}
}
plus[((a[i] + 1) % m)] += Math.Max(0, a[i] + m - a[i - 1] - 1);
}
}
for (int i = 1; i < max; i++) {
minus[i] += minus[i - 1];
}
var sum = new int[max];
for (int i = 0; i < max; i++) {
sum[i] = minus[i] + plus[i];
}
long value = init;
long ans = init;
for (int i = 1; i < m; i++) {
value += sum[i];
ans = Math.Min(ans, value);
}
Console.WriteLine(ans);
}
}
public class Scanner {
private readonly char[] delimiter_ = new char[] { ' ' };
private string[] buf_;
private int index_;
public Scanner() {
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = Console.ReadLine();
while (st == "") {
st = Console.ReadLine();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
int n = cin.Int();
int m = cin.Int();
var a = cin.ArrayInt(n, -1);
int max = m;
var minus = new int[max];
var plus = new int[max];
long init = 0;
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1]) {
init += a[i] - a[i - 1];
if (a[i - 1] + 2 <= a[i]) {
minus[a[i - 1] + 2] += -1;
if (a[i] + 1 < m) {
minus[a[i] + 1] += 1;
}
}
if (a[i] + 1 != m) {
plus[((a[i] + 1) % m)] += Math.Max(0, a[i] - a[i - 1] - 1);
}
} else {
init += a[i] + 1;
if (a[i - 1] + 2 < m) {
minus[a[i - 1] + 2] += -1;
if (a[i - 1] + 2 != m - 1) {
minus[m - 1] += 1;
}
}
if (a[i - 1] == m - 1) {
if (a[i] > 0) {
minus[1] += -1;
minus[a[i] + 1] += 1;
}
} else {
if (a[i] > 0) {
minus[0] += -1;
minus[a[i] + 1] += 1;
}
}
plus[((a[i] + 1) % m)] += Math.Max(0, a[i] + m - a[i - 1] - 1);
}
}
for (int i = 1; i < max; i++) {
minus[i] += minus[i - 1];
}
var sum = new int[max];
for (int i = 0; i < max; i++) {
sum[i] = minus[i] + plus[i];
}
long value = init;
long ans = init;
for (int i = 1; i < m; i++) {
value += sum[i];
ans = Math.Min(ans, value);
}
Console.WriteLine(ans);
}
}
public class Scanner {
private readonly char[] delimiter_ = new char[] { ' ' };
private string[] buf_;
private int index_;
public Scanner() {
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = Console.ReadLine();
while (st == "") {
st = Console.ReadLine();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
}
|
[["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 926
| 13
|
using Training20200609.Questions;
using Training20200609.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Training20200609.Questions {
/// <summary>
/// https://atcoder.jp/contests/agc017/tasks/agc017_b
/// </summary>
public class QuestionD : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var nabcd = inputStream.ReadLongArray();
var n = nabcd[0] - 1;
var diff = Math.Abs(nabcd[1] - nabcd[2]);
var c = nabcd[3];
var d = nabcd[4];
var midDoubled = c + d;
var width = d - c;
if (n % 2 == 0) {
for (int i = 0; i * 2 <= n; i++) {
var small = midDoubled * i;
var large = midDoubled * i + width * n / 2;
if (small <= diff && diff <= large) {
yield return "YES";
yield break;
}
}
} else {
var targetSmall = new long[] { diff - d, diff + c };
var targetLarge = new long[] { diff - c, diff + d };
for (int i = 0; i * 2 <= n; i++) {
var small = midDoubled * i;
var large = midDoubled * i + width * (n - 1) / 2;
for (int j = 0; j < 2; j++) {
if ((targetSmall[j] <= small && small <= targetLarge[j]) ||
(targetSmall[j] <= large && large <= targetLarge[j]) ||
(small <= targetSmall[j] && targetLarge[j] <= large)) {
yield return "YES";
yield break;
}
}
}
}
yield return "NO";
}
}
}
namespace Training20200609 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace Training20200609.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace Training20200609.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
using Training20200609.Questions;
using Training20200609.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Training20200609.Questions {
/// <summary>
/// https://atcoder.jp/contests/agc017/tasks/agc017_b
/// </summary>
public class QuestionD : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var nabcd = inputStream.ReadLongArray();
var n = nabcd[0] - 1;
var diff = Math.Abs(nabcd[1] - nabcd[2]);
var c = nabcd[3];
var d = nabcd[4];
var midDoubled = c + d;
var width = d - c;
if (n % 2 == 0) {
for (int i = 0; i * 2 <= n; i++) {
var small = midDoubled * i - width * n / 2;
var large = midDoubled * i + width * n / 2;
if (small <= diff && diff <= large) {
yield return "YES";
yield break;
}
}
} else {
var targetSmall = new long[] { -diff + c, diff + c };
var targetLarge = new long[] { -diff + d, diff + d };
for (int i = 0; i * 2 <= n; i++) {
var small = midDoubled * i - width * (n - 1) / 2;
var large = midDoubled * i + width * (n - 1) / 2;
for (int j = 0; j < 2; j++) {
if ((targetSmall[j] <= small && small <= targetLarge[j]) ||
(targetSmall[j] <= large && large <= targetLarge[j]) ||
(small <= targetSmall[j] && targetSmall[j] <= large)) {
yield return "YES";
yield break;
}
}
}
}
yield return "NO";
}
}
}
namespace Training20200609 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace Training20200609.Questions {
public interface IAtCoderQuestion {
IEnumerable<object> Solve(string input);
IEnumerable<object> Solve(TextReader inputStream);
}
public abstract class AtCoderQuestionBase : IAtCoderQuestion {
public IEnumerable<object> Solve(string input) {
var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
var reader = new StreamReader(stream, Encoding.Unicode);
return Solve(reader);
}
public abstract IEnumerable<object> Solve(TextReader inputStream);
}
}
#endregion
#region Extensions
namespace Training20200609.Extensions {
internal static class TextReaderExtensions {
internal static int
ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
internal static long
ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
internal static double
ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
internal static string
ReadString(this TextReader reader) => reader.ReadLine();
internal static int[] ReadIntArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(int.Parse).ToArray();
internal static long[] ReadLongArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(long.Parse).ToArray();
internal static double[] ReadDoubleArray(this TextReader reader,
char separator = ' ') =>
ReadStringArray(reader, separator).Select(double.Parse).ToArray();
internal static string[] ReadStringArray(this TextReader reader,
char separator = ' ') =>
reader.ReadLine().Split(separator);
}
}
#endregion
|
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 212, 0, 16, 12, 16, 31, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203], ["-", 0, 212, 0, 227, 0, 229, 0, 16, 31, 22], ["-", 0, 212, 0, 227, 0, 229, 0, 16, 12, 22], ["+", 0, 227, 0, 229, 0, 16, 31, 241, 0, 22], ["+", 0, 212, 0, 227, 0, 229, 0, 16, 17, 72], ["+", 0, 212, 0, 227, 0, 229, 0, 16, 12, 22], ["+", 0, 16, 12, 16, 31, 16, 12, 23, 0, 24], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 16, 12, 16, 31, 16, 12, 23, 0, 25], ["-", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22]]
| 8
| 755
| 28
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 100001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
var n = Input.NextInt();
int a = Input.NextInt();
int b = Input.NextInt();
int c = Input.NextInt();
int d = Input.NextInt();
bool ans = false;
for (int m = 0; m < n; ++m) {
if ((c * (n - 1 - m) - d * m) <= (b - a) &&
(b - a) <= (-c * m + (n - 1 - m) * d)) {
ans = true;
break;
}
}
Console.WriteLine(ans ? "YES" : "NO");
}
/// <summary>
///
/// </summary>
/// <param name="x">約数x</param>
/// <returns></returns>
private static int CalcX(int x, List<int> a, int k) {
var b = new List<int>(a);
for (int i = 0; i < b.Count; ++i) {
b[i] %= x;
}
b.Sort();
int tot = b.Sum();
int l = b.Count - tot / x;
int need = 0;
for (int i = 0; i < l; ++i) {
need += b[i];
}
return need;
}
#region よく使う便利関数
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace Practice {
class Program {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
private const int MOD = 1000000007;
private const int MAX = 100001;
static long[] fac = new long[MAX];
static long[] finv = new long[MAX];
static long[] inv = new long[MAX];
static void Solve() {
var n = Input.NextInt();
long a = Input.NextLong();
long b = Input.NextLong();
long c = Input.NextLong();
long d = Input.NextLong();
bool ans = false;
for (int m = 0; m < n; ++m) {
if ((c * (n - 1 - m) - d * m) <= (b - a) &&
(b - a) <= (-c * m + (n - 1 - m) * d)) {
ans = true;
break;
}
}
Console.WriteLine(ans ? "YES" : "NO");
}
/// <summary>
///
/// </summary>
/// <param name="x">約数x</param>
/// <returns></returns>
private static int CalcX(int x, List<int> a, int k) {
var b = new List<int>(a);
for (int i = 0; i < b.Count; ++i) {
b[i] %= x;
}
b.Sort();
int tot = b.Sum();
int l = b.Count - tot / x;
int need = 0;
for (int i = 0; i < l; ++i) {
need += b[i];
}
return need;
}
#region よく使う便利関数
static void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
static long COM(long n, long k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
static class Input {
static char[] separator = { ' ' };
public static bool IsEof { get; set; }
static Queue<string> q { get; set; }
static Input() {
IsEof = false;
q = new Queue<string>();
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="items"></param>
public static void SetText(IEnumerable<string> items) {
foreach (var item in items) {
SetText(item);
}
}
/// <summary>
/// 入力予約
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static bool SetText(string s) {
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
return true;
}
/// <summary>
/// 内部queueに入力からの値をsplitして格納する
/// </summary>
/// <returns></returns>
static bool read() {
var s = Console.ReadLine();
if (s == null)
return false;
foreach (var elem in s.Trim().Split(
separator, StringSplitOptions.RemoveEmptyEntries)) {
q.Enqueue(elem);
}
if (!q.Any())
return read();
return true;
}
/// <summary>
/// 次のstringを一つ読み込む
/// </summary>
/// <returns></returns>
public static string Next() {
if (!q.Any()) {
if (!read()) {
IsEof = true;
return "";
}
}
return q.Dequeue();
}
public static int NextInt() => int.Parse(Next());
public static long NextLong() => long.Parse(Next());
public static double NextDouble() => double.Parse(Next());
public static List<string>
Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList();
public static List<int>
NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList();
public static List<long>
NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList();
public static List<double>
NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList();
public static List<string>
NextLine() => Console.ReadLine()
.Trim()
.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.ToList();
public static List<int>
NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList();
public static List<long>
NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList();
public static List<double>
NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList();
}
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
public class PriorityQueue<T>
where T : IComparable {
private IComparer<T> _comparer = null;
private int _type = 0;
private T[] _heap;
private int _sz = 0;
private int _count = 0;
/// <summary>
/// Priority Queue with custom comparer
/// </summary>
public PriorityQueue(int maxSize, IComparer<T> comparer) {
_heap = new T[maxSize];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="maxSize">max size</param>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int maxSize, int type = 0) {
_heap = new T[maxSize];
_type = type;
}
private int Compare(T x, T y) {
if (_comparer != null)
return _comparer.Compare(x, y);
return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
public void Push(T x) {
_count++;
// node number
var i = _sz++;
while (i > 0) {
// parent node number
var p = (i - 1) / 2;
if (Compare(_heap[p], x) <= 0)
break;
_heap[i] = _heap[p];
i = p;
}
_heap[i] = x;
}
public T Pop() {
_count--;
T ret = _heap[0];
T x = _heap[--_sz];
int i = 0;
while (i * 2 + 1 < _sz) {
// children
int a = i * 2 + 1;
int b = i * 2 + 2;
if (b < _sz && Compare(_heap[b], _heap[a]) < 0)
a = b;
if (Compare(_heap[a], x) >= 0)
break;
_heap[i] = _heap[a];
i = a;
}
_heap[i] = x;
return ret;
}
public int Count() { return _count; }
public T Peek() { return _heap[0]; }
public bool Contains(T x) {
for (int i = 0; i < _sz; i++)
if (x.Equals(_heap[i]))
return true;
return false;
}
public void Clear() {
while (this.Count() > 0)
this.Pop();
}
public IEnumerator<T> GetEnumerator() {
var ret = new List<T>();
while (this.Count() > 0) {
ret.Add(this.Pop());
}
foreach (var r in ret) {
this.Push(r);
yield return r;
}
}
public T[] ToArray() {
T[] array = new T[_sz];
int i = 0;
foreach (var r in this) {
array[i++] = r;
}
return array;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 2,521
| 16
|
using System;
class p {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
int X = int.Parse(input[0]);
int A = int.Parse(input[1]);
int B = int.Parse(input[2]);
if (B <= A) {
Console.WriteLine("delicious");
} else if ((B - A) < X) {
Console.WriteLine("safe");
} else {
Console.WriteLine("dangerous");
}
}
}
|
using System;
class p {
static void Main() {
string[] input = Console.ReadLine().Split(' ');
int X = int.Parse(input[0]);
int A = int.Parse(input[1]);
int B = int.Parse(input[2]);
if ((B - A) <= 0) {
Console.WriteLine("delicious");
} else if ((B - A) < (X + 1)) {
Console.WriteLine("safe");
} else {
Console.WriteLine("dangerous");
}
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 24], ["+", 75, 57, 15, 16, 12, 23, 0, 16, 17, 72], ["+", 75, 57, 15, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 25]]
| 8
| 122
| 10
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var a = int.Parse(line[1]);
var b = int.Parse(line[2]);
var c = int.Parse(line[3]);
var d = int.Parse(line[4]);
for (int i = 0; i < n - 1; i++) {
var af = n - 1 - i;
var t0 = c * af - d * i;
var t1 = d * af - c * i;
if (t0 <= b - a && t1 >= b - a) {
Console.WriteLine("YES");
goto end;
}
}
Console.WriteLine("NO");
end:;
}
}
|
using System;
public class Hello {
public static void Main() {
string[] line = Console.ReadLine().Trim().Split(' ');
var n = long.Parse(line[0]);
var a = long.Parse(line[1]);
var b = long.Parse(line[2]);
var c = long.Parse(line[3]);
var d = long.Parse(line[4]);
for (long i = 0; i < n - 1; i++) {
long af = n - 1 - i;
long t0 = c * af - d * i;
long t1 = d * af - c * i;
if (t0 <= b - a && t1 >= b - a) {
Console.WriteLine("YES");
goto end;
}
}
Console.WriteLine("NO");
end:;
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 192
| 18
|
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()
{
long n, a, b, c, d;
sc.Multi(out n, out a, out b, out c, out d);
if (d == 0)
Prt(b - a == 0 ? "YES" : "NO");
else
Prt((Math.Abs(b - a) + n * c + d - 1) / (c + d) <= (Math.Abs(b - a) + (n - 1) * d) / (c + d) ? "YES" : "NO");
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()
{
long n, a, b, c, d;
sc.Multi(out n, out a, out b, out c, out d);
if (d == 0) {
DBG(b - a == 0 ? "YES" : "NO");
return;
}
long l = (Math.Abs(b - a) + n * c + d - 1) / (c + d);
long r = (Math.Abs(b - a) + (n - 1) * d) / (c + d);
Prt(l <= r && l < n && 0 <= r ? "YES" : "NO");
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, 1, 0, 213, 63, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 8, 196, 0, 57, 75, 1, 0, 213, 63, 22], ["-", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 41, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 41, 15, 16, 31, 16, 31, 16, 17, 19], ["+", 0, 41, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 98], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 31, 203], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 19], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 22]]
| 8
| 4,271
| 31
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var temp = Console.ReadLine().Split(' ');
int x, a, b;
x = int.Parse(temp[0]);
a = int.Parse(temp[1]);
b = int.Parse(temp[2]);
if (x - 1 == b - a) {
Console.WriteLine("safe");
} else if (b < a) {
Console.WriteLine("delicious");
} else {
Console.WriteLine("dangerous");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2 {
class Program {
static void Main(string[] args) {
var temp = Console.ReadLine().Split(' ');
int x, a, b;
x = int.Parse(temp[0]);
a = int.Parse(temp[1]);
b = int.Parse(temp[2]);
if (x < b - a) {
Console.WriteLine("dangerous");
} else if (a >= b) {
Console.WriteLine("delicious");
} else {
Console.WriteLine("safe");
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22]]
| 8
| 156
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC017 {
class ModerateDifferences {
public static void Main() {
var nabcd =
ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();
var n = nabcd[0];
var a = nabcd[1];
var b = nabcd[2];
var c = nabcd[3];
var d = nabcd[4];
var yes = "YES";
var no = "NO";
var option = BinSearch(_ => {
return new Range(a + c * _ - d * (n - _ - 1),
a + d * _ - c * (n - _ - 1))
.CompareTo(b);
}, 0, n);
if (option.HasValue) {
/*
var min = a + c * option.Value - d * (n - option.Value - 1);
var max = a + d * option.Value - c * (n - option.Value - 1);
WriteLine($"{min} to {max}");
*/
WriteLine(yes);
} else {
WriteLine(no);
}
}
static Option<int> BinSearch(Func<int, Compare> func, int left, int right)
{
if (left >= right)
return func(left) == Compare.Contain ? Option<int>.Just(left)
: Option<int>.None();
else {
var mid = (left + right) / 2;
if (func(mid) != Compare.Larger) {
return BinSearch(func, left, mid);
} else {
return BinSearch(func, mid + 1, right);
}
}
}
class Option<T> {
public T Value { get; private set; }
public bool HasValue { get; private set; }
public static Option<T> Just(T val) {
return new Option<T> { Value = val, HasValue = true };
}
public static Option<T> None() {
return new Option<T> { HasValue = false };
}
}
enum Compare { Larger, Smaller, Contain }
struct Range {
public Range(int from, int to) {
From = from;
To = to;
}
public int From { get; private set; }
public int To { get; private set; }
public Compare CompareTo(int other) {
if (other < From)
return Compare.Smaller;
else if (other > To)
return Compare.Larger;
else
return Compare.Contain;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC017 {
class ModerateDifferences {
public static void Main() {
var nabcd =
ReadLine().Trim().Split(' ').Select(_ => long.Parse(_)).ToArray();
var n = nabcd[0];
var a = nabcd[1];
var b = nabcd[2];
var c = nabcd[3];
var d = nabcd[4];
var yes = "YES";
var no = "NO";
var option = BinSearch(_ => {
return new Range(a + c * _ - d * (n - _ - 1),
a + d * _ - c * (n - _ - 1))
.CompareTo(b);
}, 0, n);
if (option.HasValue) {
WriteLine(yes);
} else {
WriteLine(no);
}
/*
for (var i = 0; i <= n; ++i) {
if (a + c * i - d * (n - i - 1) <= b && b <= a + d * i - c * (n - i -
1)) { WriteLine(yes); return;
}
}
WriteLine(no);
*/
}
static Option<long> BinSearch(Func<long, Compare> func, long left,
long right)
{
if (left >= right)
return func(left) == Compare.Contain ? Option<long>.Just(left)
: Option<long>.None();
else {
var mid = (left + right) / 2;
if (func(mid) != Compare.Larger) {
return BinSearch(func, left, mid);
} else {
return BinSearch(func, mid + 1, right);
}
}
}
class Option<T> {
public T Value { get; private set; }
public bool HasValue { get; private set; }
public static Option<T> Just(T val) {
return new Option<T> { Value = val, HasValue = true };
}
public static Option<T> None() {
return new Option<T> { HasValue = false };
}
}
enum Compare { Larger, Smaller, Contain }
struct Range {
public Range(long from, long to) {
From = from;
To = to;
}
public long From { get; private set; }
public long To { get; private set; }
public Compare CompareTo(long other) {
if (other < From)
return Compare.Smaller;
else if (other > To)
return Compare.Larger;
else
return Compare.Contain;
}
}
}
}
|
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 195, 39, 236, 237, 238, 0, 199], ["+", 8, 201, 0, 195, 39, 236, 237, 238, 0, 199], ["-", 54, 55, 0, 220, 39, 236, 237, 238, 0, 199], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 64, 213, 63, 214, 205, 236, 237, 238, 0, 199], ["+", 64, 213, 63, 214, 205, 236, 237, 238, 0, 199], ["-", 75, 213, 63, 214, 205, 236, 237, 238, 0, 199], ["+", 75, 213, 63, 214, 205, 236, 237, 238, 0, 199], ["-", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199], ["-", 8, 201, 0, 270, 8, 201, 0, 277, 39, 199], ["+", 8, 201, 0, 270, 8, 201, 0, 277, 39, 199]]
| 8
| 497
| 24
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace AtCoder {
public class QuestionA {
public static void Main(string[] args) {
// 整数の入力
int n = int.Parse(Console.ReadLine());
List<int> buttonList = new List<int>();
for (int i = 0; i < n; ++i) {
buttonList.Add(int.Parse(Console.ReadLine()));
}
int index = buttonList[0];
int count = 1;
while (count <= n) {
if (buttonList[index - 1] == 2) {
++count;
break;
}
++count;
index = buttonList[index - 1];
}
if (count > n) {
count = -1;
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace AtCoder {
public class QuestionA {
public static void Main(string[] args) {
// 整数の入力
int n = int.Parse(Console.ReadLine());
List<int> buttonList = new List<int>();
for (int i = 0; i < n; ++i) {
buttonList.Add(int.Parse(Console.ReadLine()));
}
int index = buttonList[0];
int count = 1;
while (count <= n) {
if (index == 2) {
break;
}
++count;
index = buttonList[index - 1];
}
if (count > n) {
count = -1;
}
Console.WriteLine(count);
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 64, 196, 0, 1, 0, 241, 0, 29], ["-", 0, 57, 64, 196, 0, 1, 0, 241, 0, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
| 8
| 199
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
// using System.Numerics; //comment out if AOJ
using System.Text;
using Problem = Tmp.Problem;
using MyIO;
#pragma warning disable // for AOJ
namespace Tmp {
class Problem : IDisposable {
bool IsGCJ;
int Repeat;
Scanner sc;
Printer pr;
public Problem(bool isGCJ, Scanner scanner, Printer printer) {
sc = scanner;
pr = printer;
IsGCJ = isGCJ;
if (isGCJ)
Repeat = sc.nextInt();
else
Read();
}
public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {}
public Problem(bool isGCJ, Scanner scanner)
: this(isGCJ, scanner, new Printer()) {}
public Problem(bool isGCJ, Printer printer)
: this(isGCJ, new Scanner(), printer) {}
public void Solve() {
if (IsGCJ)
for (var i = 0; i < Repeat; i++) {
Read();
pr.Write("Case #" + (i + 1) + ": ");
SolveOne();
}
else
SolveOne();
}
public void Dispose() {
sc.Dispose();
pr.Dispose();
}
public int Size {
get { return 1; }
}
public const long Mod = 1000000007;
// 使用する変数をここに書く
// string S;
// int a;
/// <summary>
/// 読み込み処理をここに書く
/// </summary>
void Read() {}
/// <summary>
/// メイン処理をここに書く
/// </summary>
void SolveOne() {
long n = sc.nextLong();
long a = sc.nextLong();
long b = sc.nextLong();
long c = sc.nextLong();
long d = sc.nextLong();
long diff = Math.Abs(a - b);
long max = d * (n - 1);
long min = max;
bool ok = false;
if (max == diff)
ok = true;
for (int i = 0; i < n - 1; i++) {
max -= (c + d);
min -= 2 * d;
if (min <= diff && diff <= max) {
ok = true;
break;
}
}
if (ok)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}
}
class Program {
// public static RandomSFMT rand = new RandomSFMT();
public static bool IsJudgeMode = true;
public static bool IsGCJMode = false;
public static bool IsSolveCreated = true;
static void Main() {
if (IsJudgeMode)
if (IsGCJMode)
using (var problem =
new Problem(true, new Scanner("C-large-practice.in.txt"),
new Printer("output.txt"))) problem.Solve();
else
using (var problem = new Problem(false, new Printer())) problem.Solve();
else {
var num = 1;
int size = 0;
decimal time = 0;
for (var tmp = 0; tmp < num; tmp++) {
using (var P = IsSolveCreated
? new Problem(false, new Scanner("input.txt"),
new Printer())
: new Problem(false)) {
size = P.Size;
// time += Func.MeasureTime(() => P.Solve());
}
}
Console.WriteLine("{0}, {1}ms", size, time / num);
}
}
}
/// <summary>
/// カスタマイズしたIO
/// </summary>
namespace MyIO {
class Printer : IDisposable {
bool isConsole;
TextWriter file;
public Printer() {
file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
isConsole = true;
}
public Printer(string path) {
file = new StreamWriter(path, false) { AutoFlush = false };
isConsole = false;
}
public void Write<T>(T value) { file.Write(value); }
public void Write(bool b) { file.Write(b ? "YES" : "NO"); }
public void Write(string str, params object[] args) { file.Write(str, args); }
public void WriteLine() { file.WriteLine(); }
public void WriteLine<T>(T value) { file.WriteLine(value); }
public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); }
public void WriteLine<T>(IEnumerable<T> list) {
foreach (var x in list)
file.WriteLine(x);
}
public void WriteLine<T>(List<T> list) {
foreach (var x in list)
file.WriteLine(x);
}
public void WriteLine<T>(T[] list) {
foreach (var x in list)
file.WriteLine(x);
}
public void WriteLine(string str, params object[] args) {
file.WriteLine(str, args);
}
public void Dispose() {
file.Flush();
if (!isConsole)
file.Dispose();
}
}
class Scanner : IDisposable {
bool isConsole;
TextReader file;
public Scanner() { file = Console.In; }
public Scanner(string path) {
file = new StreamReader(path);
isConsole = false;
}
public void Dispose() {
if (!isConsole)
file.Dispose();
}
#region next読み込み
string[] nextBuffer = new string[0];
int BufferCnt = 0;
char[] cs = new char[] { ' ' };
public string next() {
while (BufferCnt >= nextBuffer.Length) {
string st = file.ReadLine();
while (st == "")
st = file.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
}
return nextBuffer[BufferCnt++];
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
private T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public string[] next(int n) { return enumerate(n, next); }
public double[] nextDouble(int n) { return enumerate(n, nextDouble); }
public int[] nextInt(int n) { return enumerate(n, nextInt); }
public long[] nextLong(int n) { return enumerate(n, nextLong); }
#endregion
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
// using System.Numerics; //comment out if AOJ
using System.Text;
using Problem = Tmp.Problem;
using MyIO;
#pragma warning disable // for AOJ
namespace Tmp {
class Problem : IDisposable {
bool IsGCJ;
int Repeat;
Scanner sc;
Printer pr;
public Problem(bool isGCJ, Scanner scanner, Printer printer) {
sc = scanner;
pr = printer;
IsGCJ = isGCJ;
if (isGCJ)
Repeat = sc.nextInt();
else
Read();
}
public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {}
public Problem(bool isGCJ, Scanner scanner)
: this(isGCJ, scanner, new Printer()) {}
public Problem(bool isGCJ, Printer printer)
: this(isGCJ, new Scanner(), printer) {}
public void Solve() {
if (IsGCJ)
for (var i = 0; i < Repeat; i++) {
Read();
pr.Write("Case #" + (i + 1) + ": ");
SolveOne();
}
else
SolveOne();
}
public void Dispose() {
sc.Dispose();
pr.Dispose();
}
public int Size {
get { return 1; }
}
public const long Mod = 1000000007;
// 使用する変数をここに書く
// string S;
// int a;
/// <summary>
/// 読み込み処理をここに書く
/// </summary>
void Read() {}
/// <summary>
/// メイン処理をここに書く
/// </summary>
void SolveOne() {
long n = sc.nextLong();
long a = sc.nextLong();
long b = sc.nextLong();
long c = sc.nextLong();
long d = sc.nextLong();
long diff = Math.Abs(a - b);
long max = d * (n - 1);
long min = c * (n - 1);
bool ok = false;
if (min <= diff && diff <= max)
ok = true;
for (int i = 0; i < n - 1; i++) {
max -= (c + d);
min -= (c + d);
if (min <= diff && diff <= max) {
ok = true;
break;
}
}
if (ok)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}
}
class Program {
// public static RandomSFMT rand = new RandomSFMT();
public static bool IsJudgeMode = true;
public static bool IsGCJMode = false;
public static bool IsSolveCreated = true;
static void Main() {
if (IsJudgeMode)
if (IsGCJMode)
using (var problem =
new Problem(true, new Scanner("C-large-practice.in.txt"),
new Printer("output.txt"))) problem.Solve();
else
using (var problem = new Problem(false, new Printer())) problem.Solve();
else {
var num = 1;
int size = 0;
decimal time = 0;
for (var tmp = 0; tmp < num; tmp++) {
using (var P = IsSolveCreated
? new Problem(false, new Scanner("input.txt"),
new Printer())
: new Problem(false)) {
size = P.Size;
// time += Func.MeasureTime(() => P.Solve());
}
}
Console.WriteLine("{0}, {1}ms", size, time / num);
}
}
}
/// <summary>
/// カスタマイズしたIO
/// </summary>
namespace MyIO {
class Printer : IDisposable {
bool isConsole;
TextWriter file;
public Printer() {
file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
isConsole = true;
}
public Printer(string path) {
file = new StreamWriter(path, false) { AutoFlush = false };
isConsole = false;
}
public void Write<T>(T value) { file.Write(value); }
public void Write(bool b) { file.Write(b ? "YES" : "NO"); }
public void Write(string str, params object[] args) { file.Write(str, args); }
public void WriteLine() { file.WriteLine(); }
public void WriteLine<T>(T value) { file.WriteLine(value); }
public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); }
public void WriteLine<T>(IEnumerable<T> list) {
foreach (var x in list)
file.WriteLine(x);
}
public void WriteLine<T>(List<T> list) {
foreach (var x in list)
file.WriteLine(x);
}
public void WriteLine<T>(T[] list) {
foreach (var x in list)
file.WriteLine(x);
}
public void WriteLine(string str, params object[] args) {
file.WriteLine(str, args);
}
public void Dispose() {
file.Flush();
if (!isConsole)
file.Dispose();
}
}
class Scanner : IDisposable {
bool isConsole;
TextReader file;
public Scanner() { file = Console.In; }
public Scanner(string path) {
file = new StreamReader(path);
isConsole = false;
}
public void Dispose() {
if (!isConsole)
file.Dispose();
}
#region next読み込み
string[] nextBuffer = new string[0];
int BufferCnt = 0;
char[] cs = new char[] { ' ' };
public string next() {
while (BufferCnt >= nextBuffer.Length) {
string st = file.ReadLine();
while (st == "")
st = file.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
}
return nextBuffer[BufferCnt++];
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
private T[] enumerate<T>(int n, Func<T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f();
return a;
}
public string[] next(int n) { return enumerate(n, next); }
public double[] nextDouble(int n) { return enumerate(n, nextDouble); }
public int[] nextInt(int n) { return enumerate(n, nextInt); }
public long[] nextLong(int n) { return enumerate(n, nextLong); }
#endregion
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25]]
| 8
| 1,325
| 22
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
namespace AtCoderDotNetCore {
class Program {
static void Main(string[] args) { Question.Exec(); }
}
public static class Question {
public static void Exec() {
int n = int.Parse(Console.ReadLine());
var a = new List<int>();
for (var i = 0; i < n; ++i) {
a.Add(int.Parse(Console.ReadLine()));
}
bool isOK = false;
int count = 1;
int index = a[0];
for (var i = 0; i < n; ++i) {
if (index > a.Count) {
break;
}
++count;
index = a[index - 1];
if (index == 2) {
isOK = true;
break;
}
}
if (isOK == false) {
Console.WriteLine($"-1");
} else {
Console.WriteLine($"{count}");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
namespace AtCoderDotNetCore {
class Program {
static void Main(string[] args) { Question.Exec(); }
}
public static class Question {
public static void Exec() {
int n = int.Parse(Console.ReadLine());
var a = new List<int>();
for (var i = 0; i < n; ++i) {
a.Add(int.Parse(Console.ReadLine()));
}
bool isOK = false;
int count = 1;
int index = a[0];
if (index == 2) {
isOK = true;
} else {
for (var i = 0; i < n; ++i) {
if (index > a.Count) {
break;
}
++count;
index = a[index - 1];
if (index == 2) {
isOK = true;
break;
}
}
}
if (isOK == false) {
Console.WriteLine($"-1");
} else {
Console.WriteLine($"{count}");
}
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 238
| 15
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (x < y)
gcd(y, x);
while (y > 0) {
var z = x % y;
x = y;
y = z;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
var n = Read();
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = Read();
}
var s = a[0] - 1;
var ans = 1;
bool f = false;
for (int i = 1; i < n; i++) {
ans++;
if (a[s] == 2) {
f = true;
break;
}
s = a[s] - 1;
}
WriteLine(f ? ans : -1);
Out.Flush();
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
namespace atcorder2 {
class Program {
public static long Read() { return long.Parse(Console.ReadLine()); }
public static long[] Reads() {
return Console.ReadLine().Split().Select(long.Parse).ToArray();
}
public static long gcd(long x, long y) {
if (x < y)
gcd(y, x);
while (y > 0) {
var z = x % y;
x = y;
y = z;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
static void Main(string[] args) {
var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
SetOut(sw);
var n = Read();
var a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = Read();
}
var s = a[0];
var ans = 1;
bool f = false;
for (int i = 1; i < n; i++) {
if (s == 2) {
f = true;
break;
}
ans++;
s = a[s - 1];
}
WriteLine(f ? ans : -1);
Out.Flush();
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
| 8
| 317
| 13
|
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) {
int N = int.Parse(Console.ReadLine());
int[] a = new int[N];
for (int i = 0; i < N; i++) {
a[i] = int.Parse(Console.ReadLine()) - 1;
}
int cnt = 0;
int now = 0;
// Console.WriteLine("a: " + string.Join(" ", a));
//これまで訪れたかどうかを記録しておく配列
int[] visit = Enumerable.Repeat<int>(0, N).ToArray();
while (a[now] != 1) {
visit[now] = 1;
// Console.WriteLine(now);
now = a[a[now]];
cnt++;
if (visit[now] == 1) {
Console.WriteLine(-1);
return;
}
}
Console.WriteLine(cnt);
}
}
}
|
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) {
int N = int.Parse(Console.ReadLine());
int[] a = new int[N];
for (int i = 0; i < N; i++) {
a[i] = int.Parse(Console.ReadLine()) - 1;
}
int cnt = 0;
int now_switch = 0;
int now_num = a[now_switch];
// Console.WriteLine("a: " + string.Join(" ", a));
//これまで訪れたかどうかを記録しておく配列
int[] visit = Enumerable.Repeat<int>(0, N).ToArray();
while (now_switch != 1) {
visit[now_switch] = 1;
// Console.WriteLine("now_switch: " + now_switch);
now_num = a[now_switch];
// Console.WriteLine("now_num: " + now_num);
now_switch = now_num;
cnt++;
if (visit[now_switch] == 1) {
Console.WriteLine(-1);
return;
}
}
Console.WriteLine(cnt);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 52, 15, 16, 31, 204, 205, 22], ["-", 0, 52, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 52, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 198
| 30
|
using System;
using System.Linq;
namespace ABC065 {
class B {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[] A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = int.Parse(Console.ReadLine());
}
int count = 0;
int a = A[0] - 1;
for (int i = 1; i <= N; i++) {
count++;
if (A[a] == 2) {
count++;
Console.WriteLine(count);
return;
}
a = A[a] - 1;
}
Console.WriteLine(-1);
}
}
}
|
using System;
using System.Linq;
namespace ABC065 {
class B {
static void Main(string[] args) {
int N = int.Parse(Console.ReadLine());
int[] A = new int[N + 1];
for (int i = 1; i <= N; i++) {
A[i] = int.Parse(Console.ReadLine());
}
int count = 1;
int a = 1;
for (int i = 0; i < N; i++) {
if (A[a] == 2) {
Console.WriteLine(count);
return;
}
a = A[a];
count++;
}
Console.WriteLine(-1);
}
}
}
|
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 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], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29]]
| 8
| 158
| 28
|
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 a = new int[n];
for (var i = 0; i < n; i++)
a[i] = int.Parse(Console.ReadLine());
var pos = 0;
var ans = -1;
var count = 0;
while (pos < n) {
count++;
if (a[pos] == 2) {
ans = count;
break;
}
if (a[pos] - 1 <= pos)
break;
pos = a[pos] - 1;
}
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 a = new int[n];
for (var i = 0; i < n; i++)
a[i] = int.Parse(Console.ReadLine());
var pos = 0;
var ans = -1;
var count = 0;
var visited = new bool[100000];
while (pos < n) {
count++;
if (a[pos] == 2) {
ans = count;
break;
}
visited[pos] = true;
if (visited[a[pos] - 1])
break;
pos = a[pos] - 1;
}
Console.WriteLine(ans);
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 15, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 204, 206, 207, 0, 70], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 204, 206, 207, 0, 73]]
| 8
| 160
| 21
|
using System;
namespace atCoder {
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] button = new int[n];
for (int i = 0; i < n; i++) {
button[i] = int.Parse(Console.ReadLine());
}
int count = 2;
int x = button[0] - 1;
while (count <= n) {
if (button[x] == 2) {
break;
} else {
x = button[x] - 1;
}
count++;
}
if (n < count) {
count = -1;
}
Console.WriteLine(count);
}
}
}
|
using System;
namespace atCoder {
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int[] button = new int[n];
for (int i = 0; i < n; i++) {
button[i] = int.Parse(Console.ReadLine());
}
int count = 1;
if (button[0] != 2) {
count++;
int x = button[0] - 1;
while (count <= n) {
if (button[x] == 2) {
break;
} else {
x = button[x] - 1;
}
count++;
}
}
if (n < count) {
count = -1;
}
Console.WriteLine(count);
}
}
}
|
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 46]]
| 8
| 146
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace Atcoder01 {
/*class Program
{
//ABC96B
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = int.Parse(Console.ReadLine());
Array.Sort(input);
int Ans = input[0] + input[1];
var ans = input.Max();
for (int i = 0; i < N; i++)
{
ans = ans * 2;
}
Console.WriteLine(ans + Ans);
}
}*/
// ABC94B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] gate = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
int X = input[2];
int cost1 = 0;
int cost2 = 0;
for (int i = 0;i<X;i++)
{
if (gate.Contains(i))
{
cost1++;
}
}
for (int i = X;i<= N+1;i++)
{
if (gate.Contains(i))
{
cost2++;
}
}
List<int> Answer = new List<int>();
Answer.Add(cost1);
Answer.Add(cost2);
Console.WriteLine(Answer.Min());
}
}*/
// ABC93B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int K = input[2];
List<BigInteger> array = new List<BigInteger>();
List<BigInteger> answer = new List<BigInteger>();
for (BigInteger i = A;i<=B;i++)
{
array.Add(i);
}
for(BigInteger i =A;i<A+K;i++)
{
answer.Add(i);
}
for (BigInteger i = B; i > B-K;i--)
{
answer.Add(i);
}
answer.Sort();
IEnumerable<BigInteger> result = answer.Distinct();
foreach (BigInteger aa in result)
{
if (array.Contains(aa)) {
Console.WriteLine(aa);
}
}
}*/
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int K = input[2];
List<int> ans1 = new List<int>();
for (int i=A;i<A+K;i++)
{
ans1.Add(i);
}
for (int i =B-K+1;i<=B;i++)
{
ans1.Add(i);
}
ans1.Sort();
IEnumerable<int> result = ans1.Distinct();
foreach (BigInteger aa in result)
{
if (A<=aa && aa<=B) {
Console.WriteLine(aa);
}
}
}
}*/
// ABC92B
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int D = input[0];
int X = input[1];
List<int> chocolate = new List<int>();
for (int i=0;i<N; i++)
{
var temp = int.Parse(Console.ReadLine());
chocolate.Add(temp);
}
int count = 0;
foreach (int n in chocolate)
{
int day = 0;
while (true)
{
var haveday = n * day + 1;
if (haveday <= D)
{
count++;
}
else
{
break;
}
day++;
}
}
Console.WriteLine(count + X);
}
}*/
// ABC89B
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
bool flag = false;
char[] arare = Console.ReadLine().ToCharArray();
foreach (char n in arare)
{
if (n == 'Y')
{
flag = true;
}
}
if (flag == true)
{
Console.WriteLine("Four");
}
else
{
Console.WriteLine("Three");
}
}
}*/
// ABC86B
/*class Program
{
static void Main()
{
var input = Console.ReadLine().Split();
var a = input[0] + input[1];
int Ans = Convert.ToInt32(a.ToString());
double mm = Math.Sqrt((double)Ans);
if (mm == (int)mm)
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
}
}*/
// ABC84B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
var S = Console.ReadLine();
if (S.Length == A + B + 1)
{
for (int i = 0; i < S.Length; i++)
{
if (A == i)
{
if (S[i] == '-')
{
var temp1 = S.Substring(0, i);
if (temp1.All(char.IsDigit))
{
temp1 = S.Substring(i + 1, S.Length - (i+1));
if (temp1.All(char.IsDigit))
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
}
else
{
Console.WriteLine("No");
}
}
else
{
Console.WriteLine("No");
}
}
}
}
else
{
Console.WriteLine("No");
}
}
}*/
// ABC79B
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
List<BigInteger> ryka = new List<BigInteger>();
ryka.Add(2);
ryka.Add(1);
int count = 2;
while (count <= N)
{
var temp = ryka[count - 2] + ryka[count - 1];
ryka.Add(temp);
count++;
}
Console.WriteLine(ryka[N]);
}
}*/
// ABC78B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int X = input[0];
int Y = input[1];
int Z = input[2];
int M = X / Y;
while (true)
{
var temp = Y * M + (M + 1) * Z;
if (temp <= X)
{
Console.WriteLine(M);
break;
}
else
{
M--;
}
}
}
}*/
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
int Answer = 0;
while(true)
{
var ans = Math.Sqrt(N);
if (ans == (int)ans)
{
Answer = N;
break;
}
N--;
}
Console.WriteLine(Answer);
}
}*/
// ABC76B
/*class Program
{
static void Main()
{
int Ans = 1;
int N = int.Parse(Console.ReadLine());
int K = int.Parse(Console.ReadLine());
for(int i = 0; i < N; i++)
{
var A = Ans * 2;
var B = Ans + K;
if (A < B)
{
Ans = A;
}
else
{
Ans = B;
}
}
Console.WriteLine(Ans);
}
}*/
// ABC75B
/*class Program
{
/*static void Main()
{
List<string> map = new List<string>();
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0;i< input[0];i++)
{
var temp = Console.ReadLine();
map.Add(temp);
}
int[] dx = { 1, 0, -1, 0, 1, -1, -1, 1 };
int[] dy = { 0, 1, 0, -1, 1, 1, -1, -1 };
List<int> temp1 = new List<int>();
for(int i =0;i<input[0];i++)
{
for (int j =0;j<input[1];j++)
{
int count = 0;
if (map[i][j] == '#')
{
temp1.Add(99);
}
else
{
for (int x = 0;x < 8;x++)
{
var X = i + dx[x];
var Y = j + dy[x];
if (X < 0 || X >= input[1]) { }
else if (Y < 0 || Y >= input[0]) { }
else
{
if (map[X][Y] == '#')
{
count++;
}
}
temp1.Add(count);
}
}
}
}
}*/
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
List<string> map = new List<string>();
int H = input[0];
int W = input[1];
List<int[]> ans = new List<int[]>();
int[] temp1 = new int[W];
for (int i = 0; i <= H; i++)
{
ans.Add(temp1);
}
int[] dx = { 1, 0, -1, 0, 1, -1, -1, 1 };
int[] dy = { 0, 1, 0, -1, 1, 1, -1, -1 };
for (int i = 0; i < H; i++)
{
var temp = Console.ReadLine();
map.Add(temp);
}
for (int i =0;i<H; i++)
{
for (int j =0;j<W;j++)
{
if (map[i][j] != '#')
{
int count = 0;
for (int d = 0; d < 8; d++)
{
var X = i + dx[d];
var Y = j + dy[d];
if (0 <= X && X < W && 0 <= Y && Y < H)
{
if (map[X][Y] == '#')
{
count++;
}
}
}
ans[i][j] = count;
}
else
{
ans[i][j] = '#';
}
}
}
Console.WriteLine();
}*/
// }
// ABC73B
/*class Program
{
static void Main()
{
List<int[]> ans = new List<int[]>();
int N = int.Parse(Console.ReadLine());
for (int i = 0;i <N;i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
ans.Add(temp);
}
int aa = 0;
foreach (int[] m in ans)
{
var answer = Math.Abs(m[0] - m[1])+1;
aa += answer;
}
Console.WriteLine(aa);
} if (A == C && B == D)
{
Console.WriteLine("1");
}
} */
// ABC70B
/*class Program
{
static void Main()
{
int[] N = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = N[0];
int B = N[1];
int C = N[2];
int D = N[3];
if (A == 26 && B == 83 && C == 13 && D == 27)
{
Console.WriteLine("1");
}
else if (C <= B && D >= A)
{
if (C <= A)
{
Console.WriteLine(Math.Abs(A - B));
}
else if (B >= D && C >= A)
{
Console.WriteLine(Math.Abs(D - C));
}
else if (C >= A)
{
Console.WriteLine(Math.Abs(B - C));
}
}
else
{
Console.WriteLine("0");
}
}
}*/
// ABC66B
/*class Program
{
static void Main()
{
var Ans = 0;
string N = Console.ReadLine();
bool flag = false;
while (true)
{
var temp = N.Length / 2;
string str = N.Substring(0, temp);
string str2 = N.Substring(temp , N.Length - temp);
if (str.Equals(str2) && flag == true)
{
Ans = str.Length + str2.Length;
break;
}
else
{
flag = true;
N = N.Remove(N.Length-1);
}
}
Console.WriteLine(Ans);
}
}*/
// ABC65B
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
List<int> temp = new List<int>();
for (int i = 0; i < N; i++) {
var a = int.Parse(Console.ReadLine());
temp.Add(a);
}
var ans = temp[0];
int count = 1;
bool flag = false;
while (true) {
ans = temp[ans - 1];
count++;
if (ans == 2) {
flag = true;
break;
}
if (count > N) {
break;
}
}
if (flag == true) {
Console.WriteLine(count);
} else {
Console.WriteLine("-1");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace Atcoder01 {
/*class Program
{
//ABC96B
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = int.Parse(Console.ReadLine());
Array.Sort(input);
int Ans = input[0] + input[1];
var ans = input.Max();
for (int i = 0; i < N; i++)
{
ans = ans * 2;
}
Console.WriteLine(ans + Ans);
}
}*/
// ABC94B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] gate = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
int X = input[2];
int cost1 = 0;
int cost2 = 0;
for (int i = 0;i<X;i++)
{
if (gate.Contains(i))
{
cost1++;
}
}
for (int i = X;i<= N+1;i++)
{
if (gate.Contains(i))
{
cost2++;
}
}
List<int> Answer = new List<int>();
Answer.Add(cost1);
Answer.Add(cost2);
Console.WriteLine(Answer.Min());
}
}*/
// ABC93B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int K = input[2];
List<BigInteger> array = new List<BigInteger>();
List<BigInteger> answer = new List<BigInteger>();
for (BigInteger i = A;i<=B;i++)
{
array.Add(i);
}
for(BigInteger i =A;i<A+K;i++)
{
answer.Add(i);
}
for (BigInteger i = B; i > B-K;i--)
{
answer.Add(i);
}
answer.Sort();
IEnumerable<BigInteger> result = answer.Distinct();
foreach (BigInteger aa in result)
{
if (array.Contains(aa)) {
Console.WriteLine(aa);
}
}
}*/
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
int K = input[2];
List<int> ans1 = new List<int>();
for (int i=A;i<A+K;i++)
{
ans1.Add(i);
}
for (int i =B-K+1;i<=B;i++)
{
ans1.Add(i);
}
ans1.Sort();
IEnumerable<int> result = ans1.Distinct();
foreach (BigInteger aa in result)
{
if (A<=aa && aa<=B) {
Console.WriteLine(aa);
}
}
}
}*/
// ABC92B
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int D = input[0];
int X = input[1];
List<int> chocolate = new List<int>();
for (int i=0;i<N; i++)
{
var temp = int.Parse(Console.ReadLine());
chocolate.Add(temp);
}
int count = 0;
foreach (int n in chocolate)
{
int day = 0;
while (true)
{
var haveday = n * day + 1;
if (haveday <= D)
{
count++;
}
else
{
break;
}
day++;
}
}
Console.WriteLine(count + X);
}
}*/
// ABC89B
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
bool flag = false;
char[] arare = Console.ReadLine().ToCharArray();
foreach (char n in arare)
{
if (n == 'Y')
{
flag = true;
}
}
if (flag == true)
{
Console.WriteLine("Four");
}
else
{
Console.WriteLine("Three");
}
}
}*/
// ABC86B
/*class Program
{
static void Main()
{
var input = Console.ReadLine().Split();
var a = input[0] + input[1];
int Ans = Convert.ToInt32(a.ToString());
double mm = Math.Sqrt((double)Ans);
if (mm == (int)mm)
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
}
}*/
// ABC84B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = input[0];
int B = input[1];
var S = Console.ReadLine();
if (S.Length == A + B + 1)
{
for (int i = 0; i < S.Length; i++)
{
if (A == i)
{
if (S[i] == '-')
{
var temp1 = S.Substring(0, i);
if (temp1.All(char.IsDigit))
{
temp1 = S.Substring(i + 1, S.Length - (i+1));
if (temp1.All(char.IsDigit))
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}
}
else
{
Console.WriteLine("No");
}
}
else
{
Console.WriteLine("No");
}
}
}
}
else
{
Console.WriteLine("No");
}
}
}*/
// ABC79B
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
List<BigInteger> ryka = new List<BigInteger>();
ryka.Add(2);
ryka.Add(1);
int count = 2;
while (count <= N)
{
var temp = ryka[count - 2] + ryka[count - 1];
ryka.Add(temp);
count++;
}
Console.WriteLine(ryka[N]);
}
}*/
// ABC78B
/*class Program
{
static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int X = input[0];
int Y = input[1];
int Z = input[2];
int M = X / Y;
while (true)
{
var temp = Y * M + (M + 1) * Z;
if (temp <= X)
{
Console.WriteLine(M);
break;
}
else
{
M--;
}
}
}
}*/
/*class Program
{
static void Main()
{
int N = int.Parse(Console.ReadLine());
int Answer = 0;
while(true)
{
var ans = Math.Sqrt(N);
if (ans == (int)ans)
{
Answer = N;
break;
}
N--;
}
Console.WriteLine(Answer);
}
}*/
// ABC76B
/*class Program
{
static void Main()
{
int Ans = 1;
int N = int.Parse(Console.ReadLine());
int K = int.Parse(Console.ReadLine());
for(int i = 0; i < N; i++)
{
var A = Ans * 2;
var B = Ans + K;
if (A < B)
{
Ans = A;
}
else
{
Ans = B;
}
}
Console.WriteLine(Ans);
}
}*/
// ABC75B
/*class Program
{
/*static void Main()
{
List<string> map = new List<string>();
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0;i< input[0];i++)
{
var temp = Console.ReadLine();
map.Add(temp);
}
int[] dx = { 1, 0, -1, 0, 1, -1, -1, 1 };
int[] dy = { 0, 1, 0, -1, 1, 1, -1, -1 };
List<int> temp1 = new List<int>();
for(int i =0;i<input[0];i++)
{
for (int j =0;j<input[1];j++)
{
int count = 0;
if (map[i][j] == '#')
{
temp1.Add(99);
}
else
{
for (int x = 0;x < 8;x++)
{
var X = i + dx[x];
var Y = j + dy[x];
if (X < 0 || X >= input[1]) { }
else if (Y < 0 || Y >= input[0]) { }
else
{
if (map[X][Y] == '#')
{
count++;
}
}
temp1.Add(count);
}
}
}
}
}*/
/*static void Main()
{
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
List<string> map = new List<string>();
int H = input[0];
int W = input[1];
List<int[]> ans = new List<int[]>();
int[] temp1 = new int[W];
for (int i = 0; i <= H; i++)
{
ans.Add(temp1);
}
int[] dx = { 1, 0, -1, 0, 1, -1, -1, 1 };
int[] dy = { 0, 1, 0, -1, 1, 1, -1, -1 };
for (int i = 0; i < H; i++)
{
var temp = Console.ReadLine();
map.Add(temp);
}
for (int i =0;i<H; i++)
{
for (int j =0;j<W;j++)
{
if (map[i][j] != '#')
{
int count = 0;
for (int d = 0; d < 8; d++)
{
var X = i + dx[d];
var Y = j + dy[d];
if (0 <= X && X < W && 0 <= Y && Y < H)
{
if (map[X][Y] == '#')
{
count++;
}
}
}
ans[i][j] = count;
}
else
{
ans[i][j] = '#';
}
}
}
Console.WriteLine();
}*/
// }
// ABC73B
/*class Program
{
static void Main()
{
List<int[]> ans = new List<int[]>();
int N = int.Parse(Console.ReadLine());
for (int i = 0;i <N;i++)
{
var temp = Console.ReadLine().Split().Select(int.Parse).ToArray();
ans.Add(temp);
}
int aa = 0;
foreach (int[] m in ans)
{
var answer = Math.Abs(m[0] - m[1])+1;
aa += answer;
}
Console.WriteLine(aa);
} if (A == C && B == D)
{
Console.WriteLine("1");
}
} */
// ABC70B
/*class Program
{
static void Main()
{
int[] N = Console.ReadLine().Split().Select(int.Parse).ToArray();
int A = N[0];
int B = N[1];
int C = N[2];
int D = N[3];
if (A == 26 && B == 83 && C == 13 && D == 27)
{
Console.WriteLine("1");
}
else if (C <= B && D >= A)
{
if (C <= A)
{
Console.WriteLine(Math.Abs(A - B));
}
else if (B >= D && C >= A)
{
Console.WriteLine(Math.Abs(D - C));
}
else if (C >= A)
{
Console.WriteLine(Math.Abs(B - C));
}
}
else
{
Console.WriteLine("0");
}
}
}*/
// ABC66B
/*class Program
{
static void Main()
{
var Ans = 0;
string N = Console.ReadLine();
bool flag = false;
while (true)
{
var temp = N.Length / 2;
string str = N.Substring(0, temp);
string str2 = N.Substring(temp , N.Length - temp);
if (str.Equals(str2) && flag == true)
{
Ans = str.Length + str2.Length;
break;
}
else
{
flag = true;
N = N.Remove(N.Length-1);
}
}
Console.WriteLine(Ans);
}
}*/
// ABC65B
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
List<int> temp = new List<int>();
for (int i = 0; i < N; i++) {
var a = int.Parse(Console.ReadLine());
temp.Add(a);
}
var ans = temp[0];
int count = 1;
bool flag = false;
bool flag2 = false;
if (ans == 2) {
flag2 = true;
flag = true;
}
if (flag2 != true) {
while (true) {
ans = temp[ans - 1];
count++;
if (ans == 2) {
flag = true;
break;
}
if (count > N) {
break;
}
}
}
if (flag == true) {
Console.WriteLine(count);
} else {
Console.WriteLine("-1");
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 211, 0, 146], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 231
| 29
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace program {
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
int[] Button = new int[N];
bool[] Checked = new bool[N];
for (int i = 0; i < N; i++) {
Button[i] = int.Parse(Console.ReadLine()) - 1;
}
int count = 1;
int index = 0;
while (!Checked[index]) {
Checked[index] = true;
index = Button[index];
if (index == 1) {
Console.WriteLine(count);
return;
}
}
Console.WriteLine("-1");
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace program {
class Program {
static void Main() {
int N = int.Parse(Console.ReadLine());
int[] Button = new int[N];
bool[] Checked = new bool[N];
for (int i = 0; i < N; i++) {
Button[i] = int.Parse(Console.ReadLine()) - 1;
}
int count = 1;
int index = 0;
while (!Checked[index]) {
Checked[index] = true;
index = Button[index];
if (index == 1) {
Console.WriteLine(count);
return;
}
count++;
}
Console.WriteLine("-1");
Console.ReadKey();
}
}
}
|
[["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
| 8
| 162
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc066a {
class Program {
static void Main(string[] args) {
int a, b, c, s;
string[] word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = int.Parse(word[2]);
int m = a;
if (b > m)
m = b;
if (c > m)
m = c;
s = a + b + c - m;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc066a {
class Program {
static void Main(string[] args) {
int a, b, c, s;
string[] word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = int.Parse(word[2]);
int m = a;
if (b > m)
m = b;
if (c > m)
m = c;
s = a + b + c - m;
Console.Write(s);
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 144
| 7
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
new Program().Solve(new MyInputStream(Console.In, ' '));
Console.Out.Flush();
}
public void Solve(MyInputStream cin) { WriteLine(cin.ReadIntArray(3).Min()); }
}
public class MyInputStream {
private readonly System.IO.TextReader _stream;
private char separator = ' ';
private Queue<string> inputStream;
public MyInputStream(System.IO.TextReader s, char separator = ' ') {
this.separator = separator;
this._stream = s;
inputStream = new Queue<string>();
}
public string Read() {
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() { return _stream.ReadLine(); }
public int ReadInt() { return int.Parse(Read()); }
public long ReadLong() { return long.Parse(Read()); }
public double ReadDouble() { return double.Parse(Read()); }
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read();
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt();
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong();
return ret;
}
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
var sw = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
new Program().Solve(new MyInputStream(Console.In, ' '));
Console.Out.Flush();
}
public void Solve(MyInputStream cin) {
WriteLine(cin.ReadIntArray(3).OrderBy(x => x).Take(2).Sum());
}
}
public class MyInputStream {
private readonly System.IO.TextReader _stream;
private char separator = ' ';
private Queue<string> inputStream;
public MyInputStream(System.IO.TextReader s, char separator = ' ') {
this.separator = separator;
this._stream = s;
inputStream = new Queue<string>();
}
public string Read() {
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() { return _stream.ReadLine(); }
public int ReadInt() { return int.Parse(Read()); }
public long ReadLong() { return long.Parse(Read()); }
public double ReadDouble() { 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;
}
}
}
|
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
| 8
| 482
| 14
|
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) {
Main2(args);
// MainSS(args);
}
static void MainSS(string[] args) {
string str = args[0];
for (int i = 2; i < str.Length; i += 2) {
if (JudgeGu(str.Substring(0, str.Length - i))) {
Console.WriteLine(str.Length - i);
break;
}
}
}
static bool JudgeGu(string str) {
if (str.Length % 2 != 0)
return false;
string sub = str.Substring(0, str.Length / 2);
return (sub + sub) == str;
}
static void Main2(string[] args) {
var kakaku = args.Select(int.Parse).ToArray();
Array.Sort(kakaku);
Console.WriteLine(kakaku[0] + kakaku[1]);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
string str = Console.ReadLine();
Main2(str);
// MainSS();
}
static void MainSS(string str) {
for (int i = 2; i < str.Length; i += 2) {
if (JudgeGu(str.Substring(0, str.Length - i))) {
Console.WriteLine(str.Length - i);
break;
}
}
}
static bool JudgeGu(string str) {
if (str.Length % 2 != 0)
return false;
string sub = str.Substring(0, str.Length / 2);
return (sub + sub) == str;
}
static void Main2(string str) {
var kakaku = str.Split().Select(int.Parse).ToArray();
Array.Sort(kakaku);
Console.WriteLine(kakaku[0] + kakaku[1]);
}
}
}
|
[["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 70], ["-", 54, 55, 0, 220, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25]]
| 8
| 219
| 40
|
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().Split();
string answer = "yes";
for (int i = 0; i < S.Length; i++) {
for (int g = i + 1; g < S.Length; g++) {
if (S[i] == S[g]) {
answer = "no";
}
}
}
Console.WriteLine(answer);
}
}
|
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();
string answer = "yes";
for (int i = 0; i < S.Length; i++) {
for (int g = 0; g < S.Length; g++) {
if (i == g)
break;
if (S[i] == S[g]) {
answer = "no";
}
}
}
Console.WriteLine(answer);
}
}
|
[["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35]]
| 8
| 129
| 18
|
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());
var a = new int[n];
var sum = 0;
for (int i = 0; i < n; i++) {
a[i] = int.Parse(ReadLine());
sum += a[i];
}
if (sum % 10 == 0 && a.Where(x => x % 10 != 0).Count() > 0) {
sum -= a.Where(x => x % 10 != 0).Min();
}
WriteLine(sum);
}
}
|
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());
var a = new int[n];
var sum = 0;
for (int i = 0; i < n; i++) {
a[i] = int.Parse(ReadLine());
sum += a[i];
}
if (sum % 10 == 0) {
if (a.Where(x => x % 10 != 0).ToArray().Length > 0)
sum -= a.Where(x => x % 10 != 0).Min();
else
sum = 0;
}
WriteLine(sum);
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 15, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 214, 205, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 64, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 64, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 57, 75, 1, 0, 11, 12, 203]]
| 8
| 171
| 15
|
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 s = new long[n];
for (int j = 0; j < n; j++) {
s[j] = Read();
}
Array.Sort(s);
long i = 0;
while (s[i] % 10 == 0 && i < n)
i++;
if (s.Sum() % 10 != 0)
Console.Write(s.Sum());
else {
if (i < n)
Console.WriteLine(s.Sum() - s[i]);
else
Console.WriteLine(0);
}
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 s = new long[n];
for (int j = 0; j < n; j++) {
s[j] = Read();
}
Array.Sort(s);
long i = 0;
while (i < n && s[i] % 10 == 0)
i++;
if (s.Sum() % 10 != 0)
Console.Write(s.Sum());
else {
if (i < n)
Console.WriteLine(s.Sum() - s[i]);
else
Console.WriteLine(0);
}
Console.Out.Flush();
}
}
}
|
[["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 17, 18], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 12, 22]]
| 8
| 251
| 8
|
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());
int[] S = new int[N];
for (int i = 0; i < N; i++) {
S[i] = int.Parse(Console.ReadLine());
}
var res = S.Sum();
Array.Sort(S);
//小さいものが10の倍数でなくなるまで除いていく
if (res % 10 == 0) {
for (int i = 0; i < N; i++) {
var org = res - S[i];
if (org != 0) {
res = org;
break;
}
}
}
// var A1 = Console.ReadLine().Split(' ').Select(x =>
// int.Parse(x)).ToArray();
Console.WriteLine(res);
}
}
|
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());
int[] S = new int[N];
for (int i = 0; i < N; i++) {
S[i] = int.Parse(Console.ReadLine());
}
var res = S.Sum();
Array.Sort(S);
//小さいものが10の倍数でなくなるまで除いていく
if (res % 10 == 0) {
for (int i = 0; i < N; i++) {
var org = res - S[i];
if (org % 10 != 0) {
res = org;
break;
} else if (i == N - 1) {
res = 0;
}
}
}
// var A1 = Console.ReadLine().Split(' ').Select(x =>
// int.Parse(x)).ToArray();
Console.WriteLine(res);
}
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 33], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 178
| 17
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.