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.Linq;
namespace ABC054 {
class C {
static bool[,] graph;
static void Main(string[] args) {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
graph = new bool[N, N];
for (int i = 0; i < N; i++) {
input = Console.ReadLine().Split().Select(int.Parse).ToArray();
graph[input[0] - 1, input[1] - 1] = true;
graph[input[1] - 1, input[0] - 1] = true;
}
bool[] visited = new bool[N];
visited[0] = true;
Console.WriteLine(DFS(0, N, visited));
}
static int DFS(int v, int N, bool[] visited) {
bool all_visited = true;
for (int i = 0; i < N; i++) {
if (visited[i] == false)
all_visited = false;
}
if (all_visited)
return 1;
int res = 0;
for (int i = 0; i < N; i++) {
if (graph[v, i] == false)
continue;
if (visited[i])
continue;
visited[i] = true;
res += DFS(i, N, visited);
visited[i] = false;
}
return res;
}
}
}
|
using System;
using System.Linq;
namespace ABC054 {
class C {
static bool[,] graph;
static void Main(string[] args) {
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int M = input[1];
graph = new bool[N, N];
for (int i = 0; i < M; i++) {
input = Console.ReadLine().Split().Select(int.Parse).ToArray();
graph[input[0] - 1, input[1] - 1] = true;
graph[input[1] - 1, input[0] - 1] = true;
}
bool[] visited = new bool[N];
visited[0] = true;
Console.WriteLine(DFS(0, N, visited));
}
static int DFS(int v, int N, bool[] visited) {
bool all_visited = true;
for (int i = 0; i < N; i++) {
if (visited[i] == false)
all_visited = false;
}
if (all_visited)
return 1;
int res = 0;
for (int i = 0; i < N; i++) {
if (graph[v, i] == false)
continue;
if (visited[i])
continue;
visited[i] = true;
res += DFS(i, N, visited);
visited[i] = false;
}
return res;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 324
| 2
|
using System;
using System.Linq;
namespace ABC054_C_CS_ {
class Program {
static int N, M;
static bool[,] graph; //隣接行列
static bool[] visited; //一度訪れたかどうか
static int Dfs(int v, int N, bool[] visited) {
bool allVisited = true; //すべての頂点に訪れたかどうかのフラグ
for (var i = 0; i < N; i++) { // 1津でも訪ねてないとfalseを返す
if (!visited[i]) {
allVisited = false;
}
}
if (allVisited) { //全部訪れたら1を返す
return 1;
}
int ret = 0;
//全ての遷移先のついて調べる!!!!!!!!
for (var i = 0; i < N; i++) {
//頂点iが今いる場所とつながってない、あるいはすでに訪ねていたらi + 1に移る
if (!graph[v, i])
continue;
if (visited[i])
continue;
visited[i] = true; // iに移動する
ret += Dfs(i, N, visited); // iからの遷移を試す
visited[i] = false; //フラグを取り消す
}
return ret;
}
static void Main(string[] args) {
var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
N = s[0];
M = s[1];
graph = new bool[N, N];
visited = new bool[N];
for (var i = 0; i < M; i++) {
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
graph[input[0] - 1, input[1] - 1] = graph[input[0] - 1, input[1] - 1] =
true;
}
visited[0] = true;
Console.WriteLine(Dfs(0, N, visited));
}
}
}
|
using System;
using System.Linq;
namespace ABC054_C_CS_ {
class Program {
static int N, M;
static bool[,] graph; //隣接行列
static bool[] visited; //一度訪れたかどうか
static int Dfs(int v, int N, bool[] visited) {
bool allVisited = true; //すべての頂点に訪れたかどうかのフラグ
for (var i = 0; i < N; i++) { // 1津でも訪ねてないとfalseを返す
if (!visited[i]) {
allVisited = false;
}
}
if (allVisited) { //全部訪れたら1を返す
return 1;
}
int ret = 0;
//全ての遷移先のついて調べる!!!!!!!!
for (var i = 0; i < N; i++) {
//頂点iが今いる場所とつながってない、あるいはすでに訪ねていたらi + 1に移る
if (!graph[v, i])
continue;
if (visited[i])
continue;
visited[i] = true; // iに移動する
ret += Dfs(i, N, visited); // iからの遷移を試す
visited[i] = false; //フラグを取り消す
}
return ret;
}
static void Main(string[] args) {
var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
N = s[0];
M = s[1];
graph = new bool[N, N];
visited = new bool[N];
for (var i = 0; i < M; i++) {
var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
graph[input[0] - 1, input[1] - 1] = graph[input[1] - 1, input[0] - 1] =
true;
}
visited[0] = true;
Console.WriteLine(Dfs(0, N, visited));
}
}
}
|
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 346
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static void Main(string[] args) {
int[] NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
Node[] nodes = new Node[NM[0]];
for (int i = 0; i < NM[1]; i++) {
nodes[i] = new Node();
}
for (int i = 0; i < NM[1]; i++) {
int[] edge = Console.ReadLine()
.Split(' ')
.Select(int.Parse)
.Select(x => x - 1)
.ToArray();
nodes[edge[0]].number = edge[0];
nodes[edge[0]].next.Add(edge[1]);
nodes[edge[1]].number = edge[1];
nodes[edge[1]].next.Add(edge[0]);
}
Person person = new Person(0, NM[0]);
person.history[0] = true;
Queue<Person> people = new Queue<Person>();
people.Enqueue(person);
int output = 0;
while (people.Count > 0) {
Person tuginokata = people.Dequeue();
bool isFinished = true;
for (int i = 0; i < tuginokata.history.Length; i++) {
isFinished = isFinished && tuginokata.history[i];
}
if (isFinished)
output++;
else {
List<int> next_choice = nodes[tuginokata.You_are_here].next;
for (int i = 0; i < next_choice.Count; i++) {
Person next_generation = tuginokata.Clone();
if (next_generation.history[next_choice[i]] == false) {
//行ったことがなければ
next_generation.history[next_choice[i]] = true;
//次行くところに足跡をつけて
next_generation.You_are_here = next_choice[i];
//移動して
people.Enqueue(next_generation);
//後ろに並ぶ
}
}
}
};
Console.WriteLine(output);
}
}
class Node {
public int number;
public List<int> next;
public Node(int number) {
this.number = number;
this.next = new List<int>();
}
public Node() {
this.number = 0;
this.next = new List<int>();
}
}
class Person {
public int You_are_here;
public bool[] history;
public Person(int place, int N) {
this.You_are_here = place;
this.history = new bool[N];
}
public Person Clone() {
Person output = new Person(0, this.history.Length);
output.You_are_here = this.You_are_here;
output.history = (bool[])this.history.Clone();
return output;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Atcoder {
class Program {
static void Main(string[] args) {
int[] NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
Node[] nodes = new Node[NM[0]];
for (int i = 0; i < NM[0]; i++) {
nodes[i] = new Node();
}
for (int i = 0; i < NM[1]; i++) {
int[] edge = Console.ReadLine()
.Split(' ')
.Select(int.Parse)
.Select(x => x - 1)
.ToArray();
nodes[edge[0]].number = edge[0];
nodes[edge[0]].next.Add(edge[1]);
nodes[edge[1]].number = edge[1];
nodes[edge[1]].next.Add(edge[0]);
}
Person person = new Person(0, NM[0]);
person.history[0] = true;
Queue<Person> people = new Queue<Person>();
people.Enqueue(person);
int output = 0;
while (people.Count > 0) {
Person tuginokata = people.Dequeue();
bool isFinished = true;
for (int i = 0; i < tuginokata.history.Length; i++) {
isFinished = isFinished && tuginokata.history[i];
}
if (isFinished)
output++;
else {
List<int> next_choice = nodes[tuginokata.You_are_here].next;
for (int i = 0; i < next_choice.Count; i++) {
Person next_generation = tuginokata.Clone();
if (next_generation.history[next_choice[i]] == false) {
//行ったことがなければ
next_generation.history[next_choice[i]] = true;
//次行くところに足跡をつけて
next_generation.You_are_here = next_choice[i];
//移動して
people.Enqueue(next_generation);
//後ろに並ぶ
}
}
}
};
Console.WriteLine(output);
}
}
class Node {
public int number;
public List<int> next;
public Node(int number) {
this.number = number;
this.next = new List<int>();
}
public Node() {
this.number = 0;
this.next = new List<int>();
}
}
class Person {
public int You_are_here;
public bool[] history;
public Person(int place, int N) {
this.You_are_here = place;
this.history = new bool[N];
}
public Person Clone() {
Person output = new Person(0, this.history.Length);
output.You_are_here = this.You_are_here;
output.history = (bool[])this.history.Clone();
return output;
}
}
}
|
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 609
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
int N, M;
// int[] a, b;
bool[,] G;
void Solve() {
// input
N = io.Int;
M = io.Int;
G = new bool[N, N];
for (int i = 0; i < M; ++i) {
var a = io.Int - 1;
var b = io.Int - 1;
G[a, b] = G[b, a] = true;
}
// cal
bool[] visited = new bool[N];
visited[0] = true;
int ans = dfs(visited, 0);
// res
Console.WriteLine(ans);
}
int dfs(bool[] vis, int cur) {
if (vis.All(f => f))
return 1;
int ret = 0;
for (int i = 0; i < M; ++i) {
if (G[cur, i] && !vis[i]) {
vis[i] = true;
ret += dfs(vis, i);
vis[i] = false;
}
}
return ret;
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) { new Simple().Stream(); }
void Stream() {
Solve();
io.writeFlush();
}
}
class SimpleIO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public SimpleIO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void writeFlush() { Console.Out.Flush(); }
}
|
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;
class Simple {
int N, M;
// int[] a, b;
bool[,] G;
void Solve() {
// input
N = io.Int;
M = io.Int;
G = new bool[N, N];
for (int i = 0; i < M; ++i) {
var a = io.Int - 1;
var b = io.Int - 1;
G[a, b] = G[b, a] = true;
}
// cal
bool[] visited = new bool[N];
visited[0] = true;
int ans = dfs(visited, 0);
// res
Console.WriteLine(ans);
}
int dfs(bool[] vis, int cur) {
if (vis.All(f => f))
return 1;
int ret = 0;
for (int i = 0; i < N; ++i) {
if (G[cur, i] && !vis[i]) {
vis[i] = true;
ret += dfs(vis, i);
vis[i] = false;
}
}
return ret;
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) { new Simple().Stream(); }
void Stream() {
Solve();
io.writeFlush();
}
}
class SimpleIO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public SimpleIO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void writeFlush() { Console.Out.Flush(); }
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 517
| 2
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC054D {
class Program {
static void Main(string[] args) {
int N = RInt;
int Ma = RInt;
int Mb = RInt;
List<int> canda = new List<int>();
List<int> candb = new List<int>();
int sa = Ma;
int sb = Mb;
while (sa <= 200 && sb <= 200) {
canda.Add(sa);
candb.Add(sb);
sa += Ma;
sb += Mb;
}
Med[] meds = new Med[N];
for (int i = 0; i < N; i++) {
int a = RInt;
int b = RInt;
int c = RInt;
meds[i] = new Med { a = a, b = b, c = c };
}
// 半分全列挙
int count = N / 2;
if (N > 30)
count = N / 2;
var first = meds.Take(count).ToArray();
var last = meds.Skip(count).ToArray();
int[,] min = new int[201, 201];
for (int i = 0; i < 201; i++) {
for (int j = 0; j < 201; j++) {
min[i, j] = int.MaxValue / 2;
}
}
int n = first.Length;
for (int bit = 0; bit < (1 << n); ++bit) {
int suma = 0;
int sumb = 0;
int sumc = 0;
for (int i = 0; i < n; i++) {
if ((bit & (1 << i)) != 0) {
suma += last[i].a;
sumb += last[i].b;
sumc += last[i].c;
}
}
min[suma, sumb] = Math.Min(min[suma, sumb], sumc);
}
int ans = int.MaxValue / 2;
n = last.Length;
for (int bit = 0; bit < (1 << n); ++bit) {
int suma = 0;
int sumb = 0;
int sumc = 0;
for (int i = 0; i < n; i++) {
if ((bit & (1 << i)) != 0) {
suma += last[i].a;
sumb += last[i].b;
sumc += last[i].c;
}
}
for (int i = 0; i < canda.Count; i++) {
int rema = canda[i] - suma;
int remb = candb[i] - sumb;
if (rema < 0 || remb < 0)
continue;
if (min[rema, remb] == int.MaxValue / 2)
continue;
int cand = sumc + min[rema, remb];
ans = Math.Min(ans, cand);
}
}
if (ans == int.MaxValue / 2)
ans = -1;
Console.WriteLine(ans);
}
public static int[][] BitSearch(int n) {
int[][] ret = new int [1 << n][];
for (int bit = 0; bit < (1 << n); ++bit) {
List<int> S = new List<int>();
for (int i = 0; i < n; i++) {
if ((bit & (1 << i)) != 0) {
S.Add(i);
}
}
ret[bit] = S.ToArray();
}
return ret;
}
struct Med {
public int a;
public int b;
public int c;
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() {
_v = n >= mod || n < 0 ? (n % mod + mod) % mod : n;
}
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
public static void Draw<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
static public void Draw<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC054D {
class Program {
static void Main(string[] args) {
int N = RInt;
int Ma = RInt;
int Mb = RInt;
List<int> canda = new List<int>();
List<int> candb = new List<int>();
int sa = Ma;
int sb = Mb;
while (sa <= 200 && sb <= 200) {
canda.Add(sa);
candb.Add(sb);
sa += Ma;
sb += Mb;
}
Med[] meds = new Med[N];
for (int i = 0; i < N; i++) {
int a = RInt;
int b = RInt;
int c = RInt;
meds[i] = new Med { a = a, b = b, c = c };
}
// 半分全列挙
int count = N / 2;
if (N > 30)
count = N / 2 + 2;
var first = meds.Take(count).ToArray();
var last = meds.Skip(count).ToArray();
int[,] min = new int[201, 201];
for (int i = 0; i < 201; i++) {
for (int j = 0; j < 201; j++) {
min[i, j] = int.MaxValue / 2;
}
}
int n = first.Length;
for (int bit = 0; bit < (1 << n); ++bit) {
int suma = 0;
int sumb = 0;
int sumc = 0;
for (int i = 0; i < n; i++) {
if ((bit & (1 << i)) != 0) {
suma += first[i].a;
sumb += first[i].b;
sumc += first[i].c;
}
}
min[suma, sumb] = Math.Min(min[suma, sumb], sumc);
}
int ans = int.MaxValue / 2;
n = last.Length;
for (int bit = 0; bit < (1 << n); ++bit) {
int suma = 0;
int sumb = 0;
int sumc = 0;
for (int i = 0; i < n; i++) {
if ((bit & (1 << i)) != 0) {
suma += last[i].a;
sumb += last[i].b;
sumc += last[i].c;
}
}
for (int i = 0; i < canda.Count; i++) {
int rema = canda[i] - suma;
int remb = candb[i] - sumb;
if (rema < 0 || remb < 0)
continue;
if (min[rema, remb] == int.MaxValue / 2)
continue;
int cand = sumc + min[rema, remb];
ans = Math.Min(ans, cand);
}
}
if (ans == int.MaxValue / 2)
ans = -1;
Console.WriteLine(ans);
}
public static int[][] BitSearch(int n) {
int[][] ret = new int [1 << n][];
for (int bit = 0; bit < (1 << n); ++bit) {
List<int> S = new List<int>();
for (int i = 0; i < n; i++) {
if ((bit & (1 << i)) != 0) {
S.Add(i);
}
}
ret[bit] = S.ToArray();
}
return ret;
}
struct Med {
public int a;
public int b;
public int c;
}
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() {
_v = n >= mod || n < 0 ? (n % mod + mod) % mod : n;
}
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
public static void Draw<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
static public void Draw<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
}
}
|
[["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 214, 205, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 214, 205, 204, 205, 22]]
| 8
| 1,853
| 8
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static long Mod = (long)1e9 + 7;
static void Main(string[] args) {
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
Solve();
Out.Flush();
Read();
}
static void Solve() {
var NAB = Sarray();
var N = NAB[0];
var MA = NAB[1];
var MB = NAB[2];
long[] Ai = new long[N], Bi = new long[N], Ci = new long[N];
for (var i = 0; i < N; ++i) {
var abc = Sarray();
Ai[i] = abc[0];
Bi[i] = abc[1];
Ci[i] = abc[2];
}
var NONE = long.MaxValue / 2;
var NMAX = 41;
var AMAX = 420;
var BMAX = 420;
var dp = new long[NMAX, AMAX, BMAX];
for (var n = 0; n < NMAX; ++n)
for (var a = 0; a < AMAX; ++a)
for (var b = 0; b < BMAX; ++b)
dp[n, a, b] = NONE;
dp[0, 0, 0] = 0;
long asum = Ai.Sum(), bsum = Bi.Sum();
for (var p = 0; p < N; ++p) {
for (var a = 0; a <= asum; ++a)
for (var b = 0; b <= bsum; ++b) {
if (dp[p, a, b] == NONE)
continue;
dp[p + 1, a, b] = Min(dp[p + 1, a, b], dp[p, a, b]);
dp[p + 1, a + Ai[p], b + Bi[p]] =
Min(dp[p + 1, a + Ai[p], b + Bi[p]], dp[p + 1, a, b] + Ci[p]);
}
}
var ans = NONE;
for (var n = 1;; ++n) {
if (asum < n * MA || bsum < n * MB)
break;
ans = Min(ans, dp[N, n * MA, n * MB]);
}
if (ans == NONE)
WriteLine(-1);
else
WriteLine(ans);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
namespace AtCoder {
class Program {
static public long[] Sarray() {
return ReadLine().Split().Select(long.Parse).ToArray();
}
static public List<long> Slist() {
return ReadLine().Split().Select(long.Parse).ToList();
}
static long Mod = (long)1e9 + 7;
static void Main(string[] args) {
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
Solve();
Out.Flush();
Read();
}
static void Solve() {
var NAB = Sarray();
var N = NAB[0];
var MA = NAB[1];
var MB = NAB[2];
long[] Ai = new long[N], Bi = new long[N], Ci = new long[N];
for (var i = 0; i < N; ++i) {
var abc = Sarray();
Ai[i] = abc[0];
Bi[i] = abc[1];
Ci[i] = abc[2];
}
var NONE = long.MaxValue / 2;
var NMAX = 41;
var AMAX = 420;
var BMAX = 420;
var dp = new long[NMAX, AMAX, BMAX];
for (var n = 0; n < NMAX; ++n)
for (var a = 0; a < AMAX; ++a)
for (var b = 0; b < BMAX; ++b)
dp[n, a, b] = NONE;
dp[0, 0, 0] = 0;
long asum = Ai.Sum(), bsum = Bi.Sum();
for (var p = 0; p < N; ++p) {
for (var a = 0; a <= asum; ++a)
for (var b = 0; b <= bsum; ++b) {
if (dp[p, a, b] == NONE)
continue;
dp[p + 1, a, b] = Min(dp[p + 1, a, b], dp[p, a, b]);
dp[p + 1, a + Ai[p], b + Bi[p]] =
Min(dp[p + 1, a + Ai[p], b + Bi[p]], dp[p, a, b] + Ci[p]);
}
}
var ans = NONE;
for (var n = 1;; ++n) {
if (asum < n * MA || bsum < n * MB)
break;
ans = Min(ans, dp[N, n * MA, n * MB]);
}
if (ans == NONE)
WriteLine(-1);
else
WriteLine(ans);
}
}
}
|
[["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 627
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var abc = new int[nm[0]][];
for (var i = 0; i < nm[0]; i++)
abc[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var dp = new long[nm[0] + 1, 401, 401];
for (var i = 0; i <= nm[0]; i++) {
for (var j = 0; j < 401; j++) {
for (var h = 0; h < 401; h++)
dp[i, j, h] = int.MaxValue;
}
}
dp[0, 0, 0] = 0;
for (var i = 0; i < nm[0]; i++) {
for (var j = 0; j < 401; j++) {
for (var h = 0; h < 401; h++) {
dp[i + 1, j, h] = Min(dp[i, j, h], dp[i + 1, j, h]);
if (j + abc[i][0] <= 400 && h + abc[i][1] <= 400)
dp[i + 1, j + abc[i][0], h + abc[i][1]] =
Min(dp[i, j + abc[i][0], abc[i][1]], abc[i][2] + dp[i, j, h]);
}
}
}
long res = int.MaxValue;
for (var i = 0; i < 401; i++) {
for (var j = 0; j < 401; j++) {
if (i == 0 && j == 0)
continue;
if (i * nm[2] == j * nm[1])
res = Min(res, dp[nm[0], i, j]);
}
}
WriteLine(res == int.MaxValue ? -1 : res);
}
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 {
static void Main(string[] args) {
var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var abc = new int[nm[0]][];
for (var i = 0; i < nm[0]; i++)
abc[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var dp = new long[nm[0] + 1, 401, 401];
for (var i = 0; i <= nm[0]; i++) {
for (var j = 0; j < 401; j++) {
for (var h = 0; h < 401; h++)
dp[i, j, h] = int.MaxValue;
}
}
dp[0, 0, 0] = 0;
for (var i = 0; i < nm[0]; i++) {
for (var j = 0; j < 401; j++) {
for (var h = 0; h < 401; h++) {
dp[i + 1, j, h] = Min(dp[i, j, h], dp[i + 1, j, h]);
if (j + abc[i][0] <= 400 && h + abc[i][1] <= 400)
dp[i + 1, j + abc[i][0], h + abc[i][1]] = Min(
dp[i, j + abc[i][0], h + abc[i][1]], abc[i][2] + dp[i, j, h]);
}
}
}
long res = int.MaxValue;
for (var i = 0; i < 401; i++) {
for (var j = 0; j < 401; j++) {
if (i == 0 && j == 0)
continue;
if (i * nm[2] == j * nm[1])
res = Min(res, dp[nm[0], i, j]);
}
}
WriteLine(res == int.MaxValue ? -1 : res);
}
private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
private const int MOD = 1000000007;
}
|
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72]]
| 8
| 515
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AGC010a {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long sum = a.Sum();
if (sum % 2 == 0) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AGC010a {
class Program {
static void Main(string[] args) {
long n = long.Parse(Console.ReadLine());
long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long sum = a.Sum();
if (sum % 2 == 0) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 129
| 4
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class AAddtion {
public static void Main(string[] args) {
new AAddtion().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
// 解答はココに書く
var n = cin.ReadInt;
var aList = cin.ReadIntArray(n);
var ans = (aList.Count(x => x % 2 != 0)) % 2 == 0 ? "Yes" : "No";
WriteLine(ans);
}
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
namespace AtCoder {
public class AAddtion {
public static void Main(string[] args) {
new AAddtion().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
// 解答はココに書く
var n = cin.ReadInt;
var aList = cin.ReadIntArray(n);
var ans = (aList.Count(x => x % 2 != 0)) % 2 == 0 ? "YES" : "NO";
WriteLine(ans);
}
}
}
public class ConsoleInput {
private readonly System.IO.TextReader _stream;
private char _separator = ' ';
private Queue<string> inputStream;
public ConsoleInput(System.IO.TextReader stream, char separator = ' ') {
this._separator = separator;
this._stream = stream;
inputStream = new Queue<string>();
}
public string Read {
get {
if (inputStream.Count != 0)
return inputStream.Dequeue();
string[] tmp = _stream.ReadLine().Split(_separator);
for (int i = 0; i < tmp.Length; ++i)
inputStream.Enqueue(tmp[i]);
return inputStream.Dequeue();
}
}
public string ReadLine {
get { return _stream.ReadLine(); }
}
public int ReadInt {
get { return int.Parse(Read); }
}
public long ReadLong {
get { return long.Parse(Read); }
}
public double ReadDouble {
get { return double.Parse(Read); }
}
public string[] ReadStrArray(long N) {
var ret = new string[N];
for (long i = 0; i < N; ++i)
ret[i] = Read;
return ret;
}
public int[] ReadIntArray(long N) {
var ret = new int[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadInt;
return ret;
}
public long[] ReadLongArray(long N) {
var ret = new long[N];
for (long i = 0; i < N; ++i)
ret[i] = ReadLong;
return ret;
}
}
|
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
| 8
| 477
| 4
|
using System;
using System.Linq;
// using th
// using if(from==0){};
namespace agc010_a {
class Program {
static void Main(string[] args) {
long kinokosuu = 0;
long gunokosu = 0;
// long kiwomatomeyou=0;
long s = Int64.Parse(Console.ReadLine());
long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
for (long i = 0; i < s; i++) {
if (a[i] % 2 == 0) {
gunokosu++;
} else {
kinokosuu++;
}
}
if (kinokosuu % 2 == 0) {
// if (gunokosu % 2 == 0) { Console.WriteLine("Yes"); }
Console.WriteLine("Yes");
}
else {
Console.WriteLine("No");
}
//{ kiwomatomeyou = kinokosuu / 2; } else { kiwomatomeyou =( kinokosuu/2)+1;
//}
// if ((kiwomatomeyou + gunokosu )%2== 0)
/* { Console.WriteLine("Yes"); }
{Console.WriteLine("No"); }
Console.ReadLine();
*/
}
}
}
|
using System;
using System.Linq;
// using th
// using if(from==0){};
namespace agc010_a {
class Program {
static void Main(string[] args) {
long kinokosuu = 0;
long gunokosu = 0;
// long kiwomatomeyou=0;
long s = Int64.Parse(Console.ReadLine());
long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
for (long i = 0; i < s; i++) {
if (a[i] % 2 == 0) {
gunokosu++;
} else {
kinokosuu++;
}
}
if (kinokosuu % 2 == 0) {
// if (gunokosu % 2 == 0) { Console.WriteLine("Yes"); }
Console.WriteLine("YES");
}
else {
Console.WriteLine("NO");
}
//{ kiwomatomeyou = kinokosuu / 2; } else { kiwomatomeyou =( kinokosuu/2)+1;
//}
// if ((kiwomatomeyou + gunokosu )%2== 0)
/* { Console.WriteLine("Yes"); }
{Console.WriteLine("No"); }
Console.ReadLine();
*/
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 154
| 4
|
using System;
using System.Linq;
namespace AGC010_B___Boxes {
class Program {
static void Main(string[] args) {
Console.WriteLine(solver() ? "YES" : "NO");
}
static bool solver() {
var N = long.Parse(Console.ReadLine());
var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var difference = new long[N];
difference[0] = A[0] - A[N - 1];
for (int i = 1; i < N; i++)
difference[i] = A[i] - A[i - 1];
if ((A.Sum() % (N * (N + 1 / 2)) != 0))
return false;
var opCount = A.Sum() / (N * (N + 1) / 2);
for (int i = 0; i < N; i++) {
var check = (difference[i] - opCount) * -1;
if (check < 0 || check % N != 0)
return false;
}
return true;
}
}
}
|
using System;
using System.Linq;
namespace AGC010_B___Boxes {
class Program {
static void Main(string[] args) {
Console.WriteLine(solver() ? "YES" : "NO");
}
static bool solver() {
var N = long.Parse(Console.ReadLine());
var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
var difference = new long[N];
difference[0] = A[0] - A[N - 1];
for (int i = 1; i < N; i++)
difference[i] = A[i] - A[i - 1];
if ((A.Sum() % (N * (N + 1) / 2) != 0))
return false;
var opCount = A.Sum() / (N * (N + 1) / 2);
for (int i = 0; i < N; i++) {
var check = (difference[i] - opCount) * -1;
if (check < 0 || check % N != 0)
return false;
}
return true;
}
}
}
|
[["+", 12, 23, 0, 16, 31, 16, 12, 23, 0, 25], ["-", 31, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
| 8
| 244
| 2
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static System.Console;
using static System.Math;
//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() {
var N = NextLong();
var A = NextLongList().ToArray();
var sum = A.Sum();
var sub = (N * (N + 1)) / 2;
long k = sum / sub;
if (k != 0) {
"NO".WL();
return;
}
var list = new long[N];
for (int i = 0; i < N; i++) {
list[i] = A[(i + 1) % N] - A[i] - k;
}
var cnt = 0L;
foreach (var item in list) {
if (Abs(item) % N != 0 || item > 0) {
"NO".WL();
return;
}
if(item==0) continue;
cnt += Abs(item) / N;
}
(k == cnt ? "YES" : "NO").WL();
}
}
}
}
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 {
[DebuggerStepThrough]
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);
}
}
}
public class Generate
{
public static IEnumerable<int> Seq(int s, int e) => Seq(s, e, 1);
public static IEnumerable<int> Seq(int s, int e, int a) {
while (s != e) {
yield return s;
s += a;
}
}
public static List<T> Repeat<T>(Func<int, T> result, int range) =>
Enumerable.Range(0, range).Select(result).ToList();
}
}
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>;
[DebuggerStepThrough]
public static class Utils {
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.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static System.Console;
using static System.Math;
//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() {
var N = NextLong();
var A = NextLongList().ToArray();
var sum = A.Sum();
var sub = (N * (N + 1)) / 2;
long k = sum / sub;
if (sum%sub!=0) {
"NO".WL();
return;
}
var list = new long[N];
for (int i = 0; i < N; i++) {
list[i] = A[(i + 1) % N] - A[i] - k;
}
var cnt = 0L;
foreach (var item in list) {
if (Abs(item) % N != 0 || item > 0) {
"NO".WL();
return;
}
if(item==0) continue;
cnt += Abs(item) / N;
}
(k == cnt ? "YES" : "NO").WL();
}
}
}
}
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 {
[DebuggerStepThrough]
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);
}
}
}
public class Generate
{
public static IEnumerable<int> Seq(int s, int e) => Seq(s, e, 1);
public static IEnumerable<int> Seq(int s, int e, int a) {
while (s != e) {
yield return s;
s += a;
}
}
public static List<T> Repeat<T>(Func<int, T> result, int range) =>
Enumerable.Range(0, range).Select(result).ToList();
}
}
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>;
[DebuggerStepThrough]
public static class Utils {
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, 31, 22], ["+", 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, 22]]
| 8
| 1,793
| 4
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
Console.WriteLine(Answer(nums) ? "First" : "Second");
}
static bool Answer(long[] nums) {
int n = nums.Length;
int evenCount = 0;
int oddNum = 0;
long oddMemo = 0;
for (int i = 0; i < n; i++) {
if (nums[i] % 2 == 0)
evenCount++;
else {
oddNum = i;
oddMemo = nums[i];
}
}
if (evenCount % 2 == 1)
return true;
else if (evenCount != n - 1 && oddMemo > 1)
return false;
else {
nums[oddNum] = oddMemo - 1;
long gcd = nums[0];
for (int i = 1; i < n; i++) {
gcd = Gcd(gcd, nums[i]);
}
for (int i = 1; i < n; i++) {
nums[i] /= gcd;
}
return !Answer(nums);
}
}
static long Gcd(long a, long b) { //引数a,bの最大公約数を返す
if (a < b)
return Gcd(b, a); //入れ替え
while (b != 0) {
long changeTo = a % b;
a = b;
b = changeTo;
}
return a;
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
Console.WriteLine(Answer(nums) ? "First" : "Second");
}
static bool Answer(long[] nums) {
int n = nums.Length;
int evenCount = 0;
int oddNum = 0;
long oddMemo = 0;
for (int i = 0; i < n; i++) {
if (nums[i] % 2 == 0)
evenCount++;
else {
oddNum = i;
oddMemo = nums[i];
}
}
if (evenCount % 2 == 1)
return true;
else if (evenCount != n - 1 || oddMemo == 1)
return false;
else {
nums[oddNum] = oddMemo - 1;
long gcd = nums[0];
for (int i = 1; i < n; i++) {
gcd = Gcd(gcd, nums[i]);
}
for (int i = 0; i < n; i++) {
nums[i] /= gcd;
}
return !Answer(nums);
}
}
static long Gcd(long a, long b) { //引数a,bの最大公約数を返す
if (a < b)
return Gcd(b, a); //入れ替え
while (b != 0) {
long changeTo = a % b;
a = b;
b = changeTo;
}
return a;
}
}
|
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 106], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 47], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 328
| 6
|
using System;
namespace ConsoleApplication1 {
public class Runes {
static int Main(string[] args) {
string s = Console.ReadLine();
int i = Convert.ToInt32(s);
if (i < 1000)
Console.WriteLine("ABC");
else
Console.WriteLine("ARC");
return 0;
}
}
}
|
using System;
namespace ConsoleApplication1 {
public class Runes {
static int Main(string[] args) {
string s = Console.ReadLine();
int i = Convert.ToInt32(s);
if (i < 1200)
Console.WriteLine("ABC");
else
Console.WriteLine("ARC");
return 0;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 70
| 2
|
using System;
public class Hello {
public static void Main() {
string s = Console.ReadLine();
int slen = s.Length;
int A = 0;
int Z = 0;
for (int i = 0; i < slen; i++) {
if (s[i] == 'A' && A == 0) {
A = i;
} else if (s[i] == 'Z') {
Z = i;
} else {
//特に何もしない
}
}
System.Console.WriteLine(Z - A + 1);
}
}
|
using System;
public class Hello {
public static void Main() {
string s = Console.ReadLine();
int slen = s.Length;
int A = -1;
int Z = 0;
for (int i = 0; i < slen; i++) {
if (s[i] == 'A' && A == -1) {
A = i;
} else if (s[i] == 'Z') {
Z = i;
} else {
//特に何もしない
}
}
System.Console.WriteLine(Z - A + 1);
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 203]]
| 8
| 114
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int aIdx = s.IndexOf('A');
int zIdx = s.IndexOf('Z');
Console.WriteLine(zIdx - aIdx + 1);
}
}
static class MathUtil {
static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
static class ConsoleUtil {
public static string[] StrArrayReadLine(char sepalator) {
string str = Console.ReadLine();
return str.Split(sepalator).ToArray();
}
public static string[] StrArrayReadLine() {
string str = Console.ReadLine();
if (str.Contains(',')) {
return str.Split(',').ToArray();
}
{ return str.Split(' ').ToArray(); }
}
public static int[] IntArrayReadLine() {
return StrArrayReadLine().Select(s => int.Parse(s)).ToArray();
}
public static int[] IntArrayReadLine(char sepalator) {
return StrArrayReadLine(sepalator).Select(s => int.Parse(s)).ToArray();
}
public static int IntReadLine() => int.Parse(Console.ReadLine());
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int aIdx = s.IndexOf('A');
int zIdx = s.LastIndexOf('Z');
Console.WriteLine(zIdx - aIdx + 1);
}
}
static class MathUtil {
static IEnumerable<int> EnumeratePrimeNumbers() {
List<int> primes = new List<int>() { 2 };
yield return 2;
for (int i = 3; i < int.MaxValue; i++) {
bool isPrime = true;
int Sqrt = (int)Math.Sqrt(i) + 1;
foreach (var prime in primes) {
if (prime > Sqrt) {
break;
}
if (i % prime == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.Add(i);
yield return i;
}
}
}
}
static class ConsoleUtil {
public static string[] StrArrayReadLine(char sepalator) {
string str = Console.ReadLine();
return str.Split(sepalator).ToArray();
}
public static string[] StrArrayReadLine() {
string str = Console.ReadLine();
if (str.Contains(',')) {
return str.Split(',').ToArray();
}
{ return str.Split(' ').ToArray(); }
}
public static int[] IntArrayReadLine() {
return StrArrayReadLine().Select(s => int.Parse(s)).ToArray();
}
public static int[] IntArrayReadLine(char sepalator) {
return StrArrayReadLine(sepalator).Select(s => int.Parse(s)).ToArray();
}
public static int IntReadLine() => int.Parse(Console.ReadLine());
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
| 8
| 395
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace hogeeeee {
class hogehoge {
static void Main(string[] args) {
string s = Console.ReadLine();
int APlace = 0;
int ZPlace = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] == 'A' && APlace == 0) {
APlace = i;
}
if (s[i] == 'Z') {
ZPlace = i;
}
}
Console.WriteLine(ZPlace - APlace + 1);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
namespace hogeeeee {
class hogehoge {
static void Main(string[] args) {
string s = Console.ReadLine();
int APlace = -1;
int ZPlace = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] == 'A' && APlace == -1) {
APlace = i;
}
if (s[i] == 'Z') {
ZPlace = i;
}
}
Console.WriteLine(ZPlace - APlace + 1);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 203]]
| 8
| 126
| 6
|
using System;
using System.Linq;
public class Program {
public static void Main() {
string s = Console.ReadLine();
int firstA = 0, lastZ = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] == 'Z')
lastZ = i;
}
for (int i = s.Length - 1; i > 0; i--) {
if (s[i] == 'A')
firstA = i;
}
Console.WriteLine(lastZ - firstA + 1);
}
}
|
using System;
using System.Linq;
public class Program {
public static void Main() {
string s = Console.ReadLine();
int firstA = 0, lastZ = 0;
for (int i = 0; i < s.Length; i++) {
if (s[i] == 'Z')
lastZ = i;
}
for (int i = s.Length - 1; i >= 0; i--) {
if (s[i] == 'A')
firstA = i;
}
Console.WriteLine(lastZ - firstA + 1);
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20]]
| 8
| 118
| 2
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
string input = ReadLine();
int a = 0;
int b = 0;
for (int i = 0; i < input.Length; ++i) {
if (input[i] == 'A' && a == 0) {
a = i;
}
if (input[i] == 'Z') {
b = i;
}
}
WriteLine(b - a + 1);
}
}
|
using System;
using static System.Console;
using static System.Math;
public class Hello {
public static void Main() {
string input = ReadLine();
int a = -1;
int b = 0;
for (int i = 0; i < input.Length; ++i) {
if (input[i] == 'A' && a == -1) {
a = i;
}
if (input[i] == 'Z') {
b = i;
}
}
WriteLine(b - a + 1);
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 203]]
| 8
| 110
| 6
|
using System;
namespace Sample101 {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int start = 0, end = 0;
for (int i = 0; i < s.Length; ++i) {
if (start == 0 && s[i] == 'A') {
start = i;
}
if (s[i] == 'Z') {
end = i;
}
}
Console.WriteLine(end - start + 1);
}
}
}
|
using System;
namespace Sample101 {
class Program {
static void Main(string[] args) {
string s = Console.ReadLine();
int start = -1, end = 0;
for (int i = 0; i < s.Length; ++i) {
if (start == -1 && s[i] == 'A') {
start = i;
}
if (s[i] == 'Z') {
end = i;
}
}
Console.WriteLine(end - start + 1);
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 241, 0, 203]]
| 8
| 107
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace yukicode001 {
class Program {
static void Main() {
Program pg = new Program();
string word = Console.ReadLine();
int a = word.Select((content, index) =>
new { Index = index, Content = content })
.Where(x => x.Content == 'a')
.Select(x => x.Index)
.First();
int z = word.Select((content, index) =>
new { Index = index, Content = content })
.Where(x => x.Content == 'z')
.Select(x => x.Index)
.Last();
var new_word = word.Skip(a).Take(z - a + 1).Count();
Console.WriteLine(new_word);
// Console.WriteLine(z);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace yukicode001 {
class Program {
static void Main() {
Program pg = new Program();
string word = Console.ReadLine();
int a = word.Select((content, index) =>
new { Index = index, Content = content })
.Where(x => x.Content == 'A')
.Select(x => x.Index)
.First();
int z = word.Select((content, index) =>
new { Index = index, Content = content })
.Where(x => x.Content == 'Z')
.Select(x => x.Index)
.Last();
var new_word = word.Skip(a).Take(z - a + 1).Count();
Console.WriteLine(new_word);
// Console.WriteLine(z);
}
}
}
|
[["-", 0, 28, 0, 218, 8, 16, 12, 252, 0, 253], ["+", 0, 28, 0, 218, 8, 16, 12, 252, 0, 253]]
| 8
| 192
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long x = sc.NextLong();
long answer = 0;
answer += x / 11 * 2;
long mod = x % 11;
if (mod > 0) {
answer += mod > 5 ? 2 : 1;
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long x = sc.NextLong();
long answer = 0;
answer += x / 11 * 2;
long mod = x % 11;
if (mod > 0) {
answer += mod > 6 ? 2 : 1;
}
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203]]
| 8
| 388
| 2
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
var x = decimal.Parse(Console.ReadLine());
decimal ans = Math.Ceiling(x / 11) * 2;
if (x % 11 < 6 && x % 11 != 0) {
ans -= 1;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
var x = decimal.Parse(Console.ReadLine());
decimal ans = Math.Ceiling(x / 11) * 2;
if (x % 11 < 7 && x % 11 != 0) {
ans -= 1;
}
Console.WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 96
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp110 {
class Program {
static void Main(string[] args) {
long x = long.Parse(Console.ReadLine());
long katamari_11 = 0;
katamari_11 = (long)Math.Ceiling((double)x / 11);
// 11の塊を最後まで足した和
long fullSum = 11 * katamari_11;
if (fullSum - 6 < x) {
Console.WriteLine(katamari_11 * 2);
} else {
Console.WriteLine(katamari_11 * 2 - 1);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp110 {
class Program {
static void Main(string[] args) {
long x = long.Parse(Console.ReadLine());
long katamari_11 = 0;
katamari_11 = (long)Math.Ceiling((double)x / 11);
// 11の塊を最後まで足した和
long fullSum = 11 * katamari_11;
if (fullSum - 5 < x) {
Console.WriteLine(katamari_11 * 2);
} else {
Console.WriteLine(katamari_11 * 2 - 1);
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 123
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass {
static void Main(string[] args) { Answer(); }
public static void Answer() {
var x = long.Parse(Console.ReadLine());
double a = (x / 11) * 2;
double b = x % 11;
if (b < 7) {
a += 1;
} else if (7 <= b) {
a += 2;
}
Console.WriteLine(a);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass {
static void Main(string[] args) { Answer(); }
public static void Answer() {
var x = long.Parse(Console.ReadLine());
double a = (x / 11) * 2;
double b = x % 11;
if (b < 7) {
if (b != 0)
a += 1;
} else if (7 <= b) {
a += 2;
}
Console.WriteLine(a);
}
}
|
[["+", 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, 79], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25]]
| 8
| 129
| 6
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;
public class C {
public static void Main() {
long x = GetLong();
long q = x / 11;
long rest = x - 11 * q;
Console.WriteLine(2 * q + (rest + 4) / 5);
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;
public class C {
public static void Main() {
long x = GetLong();
long q = x / 11;
long rest = x - 11 * q;
Console.WriteLine(2 * q + (rest + 5) / 6);
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
[["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203]]
| 8
| 223
| 4
|
using System;
class P {
static void Main() {
long a = long.Parse(Console.ReadLine()), b = a / 11, c = a % 11;
Console.WriteLine(b * 2 + (c > 6 ? 2 : 1));
}
}
|
using System;
class P {
static void Main() {
long a = long.Parse(Console.ReadLine()), b = a / 11, c = a % 11;
Console.WriteLine(b * 2 + (c == 0 ? 0 : c > 6 ? 2 : 1));
}
}
|
[["+", 0, 16, 12, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 64, 203], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 0, 102], ["+", 12, 23, 0, 41, 75, 41, 15, 16, 31, 22]]
| 8
| 59
| 6
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;
class Solver {
Scanner sc = new Scanner();
public void Solve() {
long x = sc.nextLong();
long div = x / 11;
long mod = x % 11;
long ans = div * 2;
if (mod == 0) {
} else if (mod <= 5) {
ans += 1;
} else {
ans += 2;
}
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 Program {
static void Main(string[] args) {
Solver s = new Solver();
s.Solve();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;
class Solver {
Scanner sc = new Scanner();
public void Solve() {
long x = sc.nextLong();
long div = x / 11;
long mod = x % 11;
long ans = div * 2;
if (mod == 0) {
} else if (mod <= 6) {
ans += 1;
} else {
ans += 2;
}
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 Program {
static void Main(string[] args) {
Solver s = new Solver();
s.Solve();
}
}
|
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203]]
| 8
| 487
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
long n = long.Parse(Console.ReadLine());
Console.WriteLine((n / 11) * 2 + (n % 11 == 0 ? 0 : (n % 11 <= 5 ? 1 : 2)));
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
long n = long.Parse(Console.ReadLine());
Console.WriteLine((n / 11) * 2 + (n % 11 == 0 ? 0 : (n % 11 <= 6 ? 1 : 2)));
}
}
|
[["-", 0, 41, 75, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 41, 75, 23, 0, 41, 15, 16, 12, 203]]
| 8
| 75
| 2
|
using System;
class ajinori {
static void Main() {
var x = double.Parse(Console.ReadLine());
var a = (int)x / 11 * 2;
if (x % 11 > 0)
a++;
if (x % 11 > 6)
a++;
Console.WriteLine(a + "\n");
}
}
|
using System;
class ajinori {
static void Main() {
var x = long.Parse(Console.ReadLine());
var a = x / 11 * 2;
if (x % 11 > 0)
a++;
if (x % 11 > 6)
a++;
Console.WriteLine(a + "\n");
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 212, 0, 16, 31, 16, 31, 74, 0, 24], ["-", 0, 212, 0, 16, 31, 16, 31, 74, 39, 199], ["-", 0, 212, 0, 16, 31, 16, 31, 74, 0, 25]]
| 8
| 73
| 5
|
using System;
using System.Collections.Generic;
class Program {
static string InputPattern = "InputX";
static List<string> GetInputList() {
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("7");
// 2
} else if (InputPattern == "Input2") {
WillReturn.Add("149696127901");
// 27217477801
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
List<string> InputList = GetInputList();
long x = long.Parse(InputList[0]);
long Answer = 0;
long Syou = x / 11;
Answer += Syou * 2;
long ModVal = x % 11;
if (1 <= ModVal && ModVal <= 5)
Answer++;
if (6 <= ModVal && ModVal <= 10)
Answer += 2;
Console.WriteLine(Answer);
}
}
|
using System;
using System.Collections.Generic;
class Program {
static string InputPattern = "InputX";
static List<string> GetInputList() {
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("7");
// 2
} else if (InputPattern == "Input2") {
WillReturn.Add("149696127901");
// 27217477801
} else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null)
WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main() {
List<string> InputList = GetInputList();
long x = long.Parse(InputList[0]);
long Answer = 0;
long Syou = x / 11;
Answer += Syou * 2;
long ModVal = x % 11;
if (1 <= ModVal && ModVal <= 6)
Answer++;
if (7 <= ModVal && ModVal <= 10)
Answer += 2;
Console.WriteLine(Answer);
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 203]]
| 8
| 203
| 4
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace ABC053 {
public class Don {
public Don() {}
private Reader r = new Reader();
public void Solve() {
long N = r.nextLong();
int mod = (int)N % 11;
long ret = (N - mod) / 11;
ret *= 2;
if (mod != 0) {
if (mod <= 6)
ret++;
else
ret += 2;
}
Console.WriteLine(ret);
}
public static void Main(string[] args) { new Don().Solve(); }
}
class Reader {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Reader() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
var input = Console.ReadLine();
while (input == "")
input = Console.ReadLine();
s = input.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace ABC053 {
public class Don {
public Don() {}
private Reader r = new Reader();
public void Solve() {
long N = r.nextLong();
long mod = N % 11;
long ret = (N - mod) / 11;
ret *= 2;
if (mod != 0) {
if (mod <= 6)
ret++;
else
ret += 2;
}
Console.WriteLine(ret);
}
public static void Main(string[] args) { new Don().Solve(); }
}
class Reader {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Reader() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
var input = Console.ReadLine();
while (input == "")
input = Console.ReadLine();
s = input.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return next();
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
}
|
[["-", 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, 16, 31, 74, 0, 24], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25]]
| 8
| 309
| 5
|
using System;
public class XYADG {
public static void Main() {
string read = Console.ReadLine();
long x = long.Parse(read);
long rotate = (x / 11) * 2;
if (x % 11 <= 6) {
if (x != 0) {
rotate++;
}
} else {
rotate += 2;
}
Console.WriteLine(rotate);
}
}
|
using System;
public class XYADG {
public static void Main() {
string read = Console.ReadLine();
long x = long.Parse(read);
long rotate = (x / 11) * 2;
if (x % 11 <= 6) {
if (x % 11 != 0) {
rotate++;
}
} else {
rotate += 2;
}
Console.WriteLine(rotate);
}
}
|
[["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 81
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
long[] a = sc.LongArray();
Dictionary<long, long> dic = new Dictionary<long, long>();
foreach (var num in a) {
if (dic.ContainsKey(num)) {
dic[num]++;
} else {
dic.Add(num, 1);
}
}
long eat = 0;
long even = 0;
foreach (var item in dic) {
var count = item.Value;
if (item.Value >= 2) {
var num = (count - 1) / 2;
eat += num;
count -= num;
if (count == 2) {
even++;
}
}
}
eat += (even + 1) / 2;
long answer = n - eat * 2;
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
long n = sc.NextLong();
long[] a = sc.LongArray();
Dictionary<long, long> dic = new Dictionary<long, long>();
foreach (var num in a) {
if (dic.ContainsKey(num)) {
dic[num]++;
} else {
dic.Add(num, 1);
}
}
long eat = 0;
long even = 0;
foreach (var item in dic) {
var count = item.Value;
if (item.Value >= 2) {
var num = (count - 1) / 2;
eat += num;
count -= num * 2;
if (count == 2) {
even++;
}
}
}
eat += (even + 1) / 2;
long answer = n - eat * 2;
Console.WriteLine(answer);
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 502
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const int INF = 1 << 30;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner sc = new Scaner();
write wr = new write();
Math2 mmath = new Math2();
//ここから
int N = sc.Int1;
var A = sc.IntArr;
var AA = A.Distinct();
int uni = AA.ToArray().Length;
wr.wri(uni % 2 == 0 ? uni : uni - 1);
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = 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; }
}
class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = powMOD(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
public long nCrMod(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
public long powMOD(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
static long GCD(long x, long y) {
if (y == 0)
return x;
return GCD(y, x % y);
}
static long LCM(long x, long y) { return x * y / GCD(x, y); }
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrArr => Str.Split(' ');
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public char[] CharArr => Str.ToArray();
public long Long1 => LongArr[0];
public int Int1 => IntArr[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
const int MOD = 1000000007;
const int INF = 1 << 30;
static void Main(string[] args) { Solve(); }
static void Solve() {
Scaner sc = new Scaner();
write wr = new write();
Math2 mmath = new Math2();
//ここから
int N = sc.Int1;
var A = sc.IntArr;
var AA = A.Distinct();
int uni = AA.ToArray().Length;
wr.wri(uni % 2 == 0 ? uni - 1 : uni);
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = 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; }
}
class Math2 {
public long[] Fact; // Nまでの階乗
public long[] invFact; //階乗の逆元
public void FactoricalModSet(long N, long MOD = 1000000007) {
Fact = new long[N + 1];
invFact = new long[N + 1];
Fact[0] = 1;
for (long i = 1; i <= N; ++i) {
Fact[i] = Fact[i - 1] * i % MOD;
}
invFact[N] = powMOD(Fact[N], MOD - 2);
for (long i = N; i > 0; --i) {
invFact[i - 1] = invFact[i] * i % MOD;
}
}
public long nCrMod(long n, long r, long MOD = 1000000007) {
return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
}
public long powMOD(long x, long n, long MOD = 1000000007) {
long res = 1;
while (n > 0) {
if ((n & 1) != 0)
res = res * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return res;
}
static long GCD(long x, long y) {
if (y == 0)
return x;
return GCD(y, x % y);
}
static long LCM(long x, long y) { return x * y / GCD(x, y); }
}
class Scaner {
public string Str => Console.ReadLine();
public string[] StrArr => Str.Split(' ');
public long[] LongArr => StrArr.Select(long.Parse).ToArray();
public int[] IntArr => StrArr.Select(int.Parse).ToArray();
public char[] CharArr => Str.ToArray();
public long Long1 => LongArr[0];
public int Int1 => IntArr[0];
}
class write {
public void wri<T>(T x) { Console.WriteLine(x); }
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["-", 3, 4, 0, 28, 0, 41, 75, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
| 8
| 939
| 4
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtTest.D_Challenge {
class ABC_053 {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
int n = ReadInt();
int[] array = ReadInts();
Array.Sort(array);
var cntList = new List<int>();
cntList.Add(array[0]);
bool requirePair = false;
for (int i = 1; i < n; i++) {
if (array[i] == array[i - 1]) {
cntList[cntList.Count - 1]++;
} else {
if (cntList[cntList.Count - 1] % 2 == 0) {
requirePair = !requirePair;
}
cntList.Add(1);
}
}
if (cntList[cntList.Count - 1] % 2 == 0) {
requirePair = !requirePair;
}
if (requirePair) {
Console.WriteLine(cntList.Count - 1);
} else {
Console.WriteLine(cntList.Count);
}
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtTest.D_Challenge {
class ABC_053 {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
int n = ReadInt();
int[] array = ReadInts();
Array.Sort(array);
var cntList = new List<int>();
cntList.Add(1);
bool requirePair = false;
for (int i = 1; i < n; i++) {
if (array[i] == array[i - 1]) {
cntList[cntList.Count - 1]++;
} else {
if (cntList[cntList.Count - 1] % 2 == 0) {
requirePair = !requirePair;
}
cntList.Add(1);
}
}
if (cntList[cntList.Count - 1] % 2 == 0) {
requirePair = !requirePair;
}
if (requirePair) {
Console.WriteLine(cntList.Count - 1);
} else {
Console.WriteLine(cntList.Count);
}
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
| 8
| 385
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeginnerContest053 {
class Program {
static void Main(string[] args) {
// var input = Console.ReadLine();
// Console.WriteLine(int.Parse(input) < 1200 ? "ABC" : "ARC");
// var first = input.IndexOf("A");
// var last = input.LastIndexOf("Z");
// Console.WriteLine(last - first +1);
// var max = long.Parse(input);
// if (max <= 6)
//{
// Console.WriteLine(1);
//}
// else if (max < 11)
//{
// Console.WriteLine(2);
//}
// else
//{
// var result = max / 11;
// result *= 2;
// if (max%11 != 0)
// {
// result += 1;
// var mod = max % 11 ;
// if (mod > 6)
// result += 1;
// }
// Console.WriteLine(result);
//}
var length = int.Parse(Console.ReadLine());
var data = new List<string>(Console.ReadLine().Split(' '));
var dict = new Dictionary<int, int>();
foreach (var value in data) {
if (!dict.ContainsKey(int.Parse(value))) {
dict.Add(int.Parse(value), 0);
}
dict[int.Parse(value)] += 1;
}
var count = 0;
foreach (var i in dict) {
count += 1;
}
if (count % 2 != 0)
count -= 1;
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BeginnerContest053 {
class Program {
static void Main(string[] args) {
// var input = Console.ReadLine();
// Console.WriteLine(int.Parse(input) < 1200 ? "ABC" : "ARC");
// var first = input.IndexOf("A");
// var last = input.LastIndexOf("Z");
// Console.WriteLine(last - first +1);
// var max = long.Parse(input);
// if (max <= 6)
//{
// Console.WriteLine(1);
//}
// else if (max < 11)
//{
// Console.WriteLine(2);
//}
// else
//{
// var result = max / 11;
// result *= 2;
// if (max%11 != 0)
// {
// result += 1;
// var mod = max % 11 ;
// if (mod > 6)
// result += 1;
// }
// Console.WriteLine(result);
//}
var length = int.Parse(Console.ReadLine());
var data = new List<string>(Console.ReadLine().Split(' '));
var dict = new Dictionary<int, int>();
foreach (var value in data) {
if (!dict.ContainsKey(int.Parse(value))) {
dict.Add(int.Parse(value), 0);
}
dict[int.Parse(value)] += 1;
}
var count = 0;
foreach (var i in dict) {
count += 1;
}
if (count % 2 == 0)
count -= 1;
Console.WriteLine(count);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60]]
| 8
| 212
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
class Prog {
public Prog() {}
public static int Main() {
new Prog().calc();
return 0;
}
Scanner cin;
public void calc() {
cin = new Scanner();
int N = cin.nextInt();
int[] arr = new int[100001];
for (int i = 0; i < N; i++) {
int a = cin.nextInt();
arr[a]++;
}
int ans = 0;
int even_cnt = 0;
for (int i = 0; i < arr.Length; i++) {
if (arr[i] == 0)
continue;
ans++;
if (arr[i] % 2 == 0)
even_cnt++;
}
if (even_cnt == 1)
ans--;
Console.WriteLine(ans);
}
}
/*
public void calc()
{
cin = new Scanner();
int N = cin.nextInt();
int[] arr = new int[100001];
for (int i = 0; i < N; i++)
{
int a = cin.nextInt();
arr[a]++;
}
int ans = 0;
int min = -1;
int max = -1;
for(int i = 0;i<arr.Length;i++)
{
if (arr[i] == 0) continue;
if (min == -1) min = i;
max = i;
ans++;
}
//両端のうち片方が偶数で、かつ真ん中がすべて奇数なら1を引く
bool between_all_odd = true;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == 0) continue;
if (i == min || i == max) continue;
if (arr[i] % 2 == 0) between_all_odd = false;
}
if (((arr[min] % 2) != (arr[max] % 2)) && between_all_odd) ans--;
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);
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
class Prog {
public Prog() {}
public static int Main() {
new Prog().calc();
return 0;
}
Scanner cin;
public void calc() {
cin = new Scanner();
int N = cin.nextInt();
int[] arr = new int[100001];
for (int i = 0; i < N; i++) {
int a = cin.nextInt();
arr[a]++;
}
int ans = 0;
int even_cnt = 0;
for (int i = 0; i < arr.Length; i++) {
if (arr[i] == 0)
continue;
ans++;
if (arr[i] % 2 == 0)
even_cnt++;
}
if (even_cnt % 2 == 1)
ans--;
Console.WriteLine(ans);
}
}
/*
public void calc()
{
cin = new Scanner();
int N = cin.nextInt();
int[] arr = new int[100001];
for (int i = 0; i < N; i++)
{
int a = cin.nextInt();
arr[a]++;
}
int ans = 0;
int min = -1;
int max = -1;
for(int i = 0;i<arr.Length;i++)
{
if (arr[i] == 0) continue;
if (min == -1) min = i;
max = i;
ans++;
}
//両端のうち片方が偶数で、かつ真ん中がすべて奇数なら1を引く
bool between_all_odd = true;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == 0) continue;
if (i == min || i == max) continue;
if (arr[i] % 2 == 0) between_all_odd = false;
}
if (((arr[min] % 2) != (arr[max] % 2)) && between_all_odd) ans--;
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);
i = 0;
return s[i++];
}
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
}
|
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
| 8
| 367
| 2
|
using Yorukatsu028.Questions;
using Yorukatsu028.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Yorukatsu028.Questions {
/// <summary>
/// ARC068 C
/// </summary>
public class QuestionC : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var x = inputStream.ReadLong();
var elevenCount = x / 11;
x -= 11 * elevenCount;
long count = 2 * elevenCount;
if (x == 0) {
yield return count;
} else if (x <= 5) {
yield return count + 1;
} else {
yield return count + 2;
}
}
}
}
namespace Yorukatsu028 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionC(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace Yorukatsu028.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 Yorukatsu028.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 Yorukatsu028.Questions;
using Yorukatsu028.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Yorukatsu028.Questions {
/// <summary>
/// ARC068 C
/// </summary>
public class QuestionC : AtCoderQuestionBase {
public override IEnumerable<object> Solve(TextReader inputStream) {
var x = inputStream.ReadLong();
var elevenCount = x / 11;
x -= 11 * elevenCount;
long count = 2 * elevenCount;
if (x == 0) {
yield return count;
} else if (x <= 6) {
yield return count + 1;
} else {
yield return count + 2;
}
}
}
}
namespace Yorukatsu028 {
class Program {
static void Main(string[] args) {
IAtCoderQuestion question = new QuestionC(); // 問題に合わせて書き換え
var answers = question.Solve(Console.In);
foreach (var answer in answers) {
Console.WriteLine(answer);
}
}
}
}
#region Base Classes
namespace Yorukatsu028.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 Yorukatsu028.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
|
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203]]
| 8
| 522
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
var X = sc.ReadLong();
var ans = X / 11 * 2;
var rem = X % 11;
if (rem > 0)
ans++;
if (rem > 5)
ans++;
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
checked {
var X = sc.ReadLong();
var ans = X / 11 * 2;
var rem = X % 11;
if (rem > 0)
ans++;
if (rem > 6)
ans++;
Console.WriteLine(ans);
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 287, 0, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46]]
| 8
| 1,100
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
class Progaram {
static void Main(string[] args) {
var x = long.Parse(Console.ReadLine());
long ans;
long y = x / 11 * 2;
long f = 11 % 2;
if (f == 0)
ans = y;
else if (f > 6)
ans = y + 2;
else
ans = y + 1;
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Progaram {
static void Main(string[] args) {
var x = long.Parse(Console.ReadLine());
long ans;
long y = x / 11 * 2;
long f = x % 11;
if (f == 0)
ans = y;
else if (f > 6)
ans = y + 2;
else
ans = y + 1;
Console.WriteLine(ans);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 100
| 4
|
using System;
using System.Linq;
namespace ARC068 {
class C {
static void Main(string[] args) {
long x = long.Parse(Console.ReadLine());
long a = x / 11;
long b = x % 11;
if (a == 0 && b <= 6) {
Console.WriteLine(1);
return;
} else if (a == 0 && 6 < b) {
Console.WriteLine(2);
return;
}
if (0 < a && 0 < b) {
if (0 < b && b <= 6) {
Console.WriteLine(2 * a + 1);
return;
} else if (6 < b) {
Console.WriteLine(2 * a + 2);
return;
} else if (b == 0) {
Console.WriteLine(2 * a);
return;
}
}
}
}
}
|
using System;
using System.Linq;
namespace ARC068 {
class C {
static void Main(string[] args) {
long x = long.Parse(Console.ReadLine());
long a = x / 11;
long b = x % 11;
if (a == 0 && b <= 6) {
Console.WriteLine(1);
return;
} else if (a == 0 && 6 < b) {
Console.WriteLine(2);
return;
}
if (0 < a && 0 <= b) {
if (0 < b && b <= 6) {
Console.WriteLine(2 * a + 1);
return;
} else if (6 < b) {
Console.WriteLine(2 * a + 2);
return;
} else if (b == 0) {
Console.WriteLine(2 * a);
return;
}
}
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
| 8
| 177
| 2
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var x = ReadLib.ReadAsLong();
Console.WriteLine(Calculation.Calc(x).ToString("D"));
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
internal class Calculation {
internal static long Calc(long x) {
if (x <= 5) {
return 1;
} else if (5 < x && x <= 11) {
return 2;
}
var score = (x / 11) * 2;
var mod = x % 11;
if (mod == 0) {
return score;
} else if (1 <= mod && mod <= 5) {
return score + 1;
} else {
return score + 2;
}
}
}
static class Quick {
internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); }
private static void QuickSort(int[] ts, int p, int r) {
if (p < r) {
var q = Partition(ts, p, r);
QuickSort(ts, p, q - 1);
QuickSort(ts, q + 1, r);
}
}
public static int Partition(int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
}
static class ReadLib {
public static long ReadAsLong() { return long.Parse(Console.ReadLine()); }
public static int ReadAsInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadAsIntArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) + step)
.ToArray();
}
public static long[] ReadAsLongArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => long.Parse(s) + step)
.ToArray();
}
public static ulong[] ReadAsULongArray() {
return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
}
public static string[] ReadAsStringArray() {
return Console.ReadLine().Split(' ');
}
public static int[] ReadNTimesAsInt(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => int.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static int[][] ReadNTimesAsIntArray(int n, int step = 0) {
return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray();
}
public static string[] ReadNTimesAsString(int n) {
return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray();
}
}
static class WriteLib {
public static void Write<T>(IEnumerable<T> ts) {
ts.ToList().ForEach(s => Console.WriteLine(s));
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
public static ModCombination ModCombination(int maxN, int mod = 1000000007) {
return new ModCombination(maxN, mod);
}
/// <summary>a^n mod</summary>
public static int ModPow(int a, int n, int mod = 1000000007) {
var res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける
}
a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2
n >>= 1;
}
return res;
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>無向グラフ</summary>
class UndirectedGraph {
public Dictionary<int, List<int>> Graph { get; }
/// <param name="graphArr">point1 to point2</param>
/// <param name="n">グラフの全要素数</param>
public UndirectedGraph(int[][] graphArr, int n) {
Graph = new Dictionary<int, List<int>>();
for (int i = 1; i <= n; i++) {
Graph.Add(i, new List<int>());
}
foreach (var arr in graphArr) {
Graph[arr[0]].Add(arr[1]);
Graph[arr[1]].Add(arr[0]);
}
}
}
/// <summary>DeepCopyするクラス</summary>
class DeepCopier {
BinaryFormatter b = new BinaryFormatter();
public T DeepCopy<T>(T obj) {
T result;
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
static class MergeSort {
public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); }
// rightは+1されていることに注意
private static long[] Merge(long[] sArr, int left, int mid, int right) {
var n1 = mid - left;
var n2 = right - mid;
var lArr = new long[n1 + 1];
var rArr = new long[n2 + 1];
for (int i = 0; i < n1; i++) {
lArr[i] = sArr[left + i];
}
lArr[n1] = int.MaxValue;
for (int i = 0; i < n2; i++) {
rArr[i] = sArr[mid + i];
}
rArr[n2] = int.MaxValue;
int l = 0, r = 0;
for (int k = left; k < right; k++) {
if (lArr[l] <= rArr[r]) {
sArr[k] = lArr[l];
l++;
} else {
sArr[k] = rArr[r];
r++;
}
}
return sArr; // 要素数はright - left
}
private static long[] Sort(long[] sArr, int left, int right) {
if (left + 1 < right) {
var mid = (left + right) / 2;
sArr = Sort(sArr, left, mid);
sArr = Sort(sArr, mid, right);
sArr = Merge(sArr, left, mid, right);
}
return sArr;
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator -(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value - item2.Value;
if (value < 0) {
value += item1.Mod;
}
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
return item1 + new ModInt(item2, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
return item1 * new ModInt(item2, item1.Mod);
}
public static ModInt operator -(ModInt item1, int item2) {
return item1 - new ModInt(item2, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
/// <summary>組み合わせ</summary>
class ModCombination {
private int mod;
private int[] fac;
private int[] finv;
private int[] inv;
public ModCombination(int max, int mod = 1000000007) {
this.mod = mod;
fac = new int[max]; // modが法のn!の列
inv = new int[max]; // indexの逆元の列
finv = new int[max]; // modを法とした、invの累積の累積
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める
var s = Math.BigMul(inv[mod % i], mod / i) % mod;
inv[i] = (int)(mod - s);
// iに対する逆元を求める
finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod);
}
}
/// <summary>nCk</summary>
public int Calculation(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (int)(Math.BigMul(fac[n],
(int)(Math.BigMul(finv[k], finv[n - k]) % mod)) %
mod);
}
}
/// <summary>拡張メソッドs</summary>
static class Extention {
/// <summary>iとjを入れ替える</summary>
public static void Swap<T>(this T[] arr, int i, int j) {
var buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
}
/// <summary>
/// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。
/// </summary>
/// <param name="sArr"></param>
/// <param name="p">partitionの先頭の添字</param>
/// <param name="r">partitionの末尾の添字</param>
/// <returns>partitionの基準が存在する添字</returns>
public static int Partition(this int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
/// <summary>深いコピーをする</summary>
public static T DeepCopy<T>(this T obj) {
T result;
var b = new BinaryFormatter();
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
#if !DEBUG
using System.IO;
#endif
public class Program {
public static void Main() {
#region SetAutoFlushIsFalse
#if !DEBUG
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
#endif
#endregion
var x = ReadLib.ReadAsLong();
Console.WriteLine(Calculation.Calc(x).ToString("D"));
#region Flush
#if !DEBUG
Console.Out.Flush();
sw.Close();
#endif
#endregion
}
}
internal class Calculation {
internal static long Calc(long x) {
if (x <= 6) {
return 1;
} else if (6 < x && x <= 11) {
return 2;
}
var score = (x / 11) * 2;
var mod = x % 11;
if (mod == 0) {
return score;
} else if (1 <= mod && mod <= 6) {
return score + 1;
} else {
return score + 2;
}
}
}
static class Quick {
internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); }
private static void QuickSort(int[] ts, int p, int r) {
if (p < r) {
var q = Partition(ts, p, r);
QuickSort(ts, p, q - 1);
QuickSort(ts, q + 1, r);
}
}
public static int Partition(int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
}
static class ReadLib {
public static long ReadAsLong() { return long.Parse(Console.ReadLine()); }
public static int ReadAsInt() { return int.Parse(Console.ReadLine()); }
public static int[] ReadAsIntArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => int.Parse(s) + step)
.ToArray();
}
public static long[] ReadAsLongArray(int step = 0) {
return Console.ReadLine()
.Split(' ')
.Select(s => long.Parse(s) + step)
.ToArray();
}
public static ulong[] ReadAsULongArray() {
return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray();
}
public static string[] ReadAsStringArray() {
return Console.ReadLine().Split(' ');
}
public static int[] ReadNTimesAsInt(int n, int step = 0) {
return Enumerable.Range(1, n)
.Select(s => int.Parse(Console.ReadLine()) + step)
.ToArray();
}
public static int[][] ReadNTimesAsIntArray(int n, int step = 0) {
return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray();
}
public static string[] ReadNTimesAsString(int n) {
return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray();
}
}
static class WriteLib {
public static void Write<T>(IEnumerable<T> ts) {
ts.ToList().ForEach(s => Console.WriteLine(s));
}
}
static class MyMath {
/// <summary>階乗</summary>
public static long Factorial(int n) {
if (n == 0) {
return 1;
}
return Permutation(n, 0);
}
public static long Permutation(int n, int k) {
return Enumerable.Range(0, n - k)
.Select(i => n - i)
.Aggregate(1, (b, i) => b * i);
}
#region FullPower
/// <summary>総乗、π</summary>
public static long FullPower(IEnumerable<long> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
public static long FullPower(IEnumerable<int> vs) {
return vs.Aggregate(1L, (a, b) => a * b);
}
#endregion
/// <summary>最大公約数</summary>
public static long Gcd(long item1, long item2) {
var a = Math.Max(item1, item2);
var b = Math.Min(item1, item2);
while (true) {
long mod;
Math.DivRem(a, b, out mod);
if (mod == 0) {
break;
}
a = b;
b = mod;
}
return b;
}
/// <summary>約分。最大公約数で割ったものを返す。</summary>
public static Tuple<long, long> DeviedByGcd(long item1, long item2) {
var gcd = Gcd(item1, item2);
return new Tuple<long, long>(item1 / gcd, item2 / gcd);
}
public static long Lcm(int item1, int item2) {
return Math.BigMul(item1, item2) / Gcd(item1, item2);
}
public static ModCombination ModCombination(int maxN, int mod = 1000000007) {
return new ModCombination(maxN, mod);
}
/// <summary>a^n mod</summary>
public static int ModPow(int a, int n, int mod = 1000000007) {
var res = 1;
while (n > 0) {
if ((n & 1) == 1) {
res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける
}
a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2
n >>= 1;
}
return res;
}
}
static class MyMethod {
/// <summary>数え上げて、key, 出現回数に変換</summary>
public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) {
return str.GroupBy(c => c)
.Select(g => new KeyValuePair<T, int>(g.Key, g.Count()))
.ToDictionary(e => e.Key, e => e.Value);
}
}
/// <summary>無向グラフ</summary>
class UndirectedGraph {
public Dictionary<int, List<int>> Graph { get; }
/// <param name="graphArr">point1 to point2</param>
/// <param name="n">グラフの全要素数</param>
public UndirectedGraph(int[][] graphArr, int n) {
Graph = new Dictionary<int, List<int>>();
for (int i = 1; i <= n; i++) {
Graph.Add(i, new List<int>());
}
foreach (var arr in graphArr) {
Graph[arr[0]].Add(arr[1]);
Graph[arr[1]].Add(arr[0]);
}
}
}
/// <summary>DeepCopyするクラス</summary>
class DeepCopier {
BinaryFormatter b = new BinaryFormatter();
public T DeepCopy<T>(T obj) {
T result;
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
static class MergeSort {
public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); }
// rightは+1されていることに注意
private static long[] Merge(long[] sArr, int left, int mid, int right) {
var n1 = mid - left;
var n2 = right - mid;
var lArr = new long[n1 + 1];
var rArr = new long[n2 + 1];
for (int i = 0; i < n1; i++) {
lArr[i] = sArr[left + i];
}
lArr[n1] = int.MaxValue;
for (int i = 0; i < n2; i++) {
rArr[i] = sArr[mid + i];
}
rArr[n2] = int.MaxValue;
int l = 0, r = 0;
for (int k = left; k < right; k++) {
if (lArr[l] <= rArr[r]) {
sArr[k] = lArr[l];
l++;
} else {
sArr[k] = rArr[r];
r++;
}
}
return sArr; // 要素数はright - left
}
private static long[] Sort(long[] sArr, int left, int right) {
if (left + 1 < right) {
var mid = (left + right) / 2;
sArr = Sort(sArr, left, mid);
sArr = Sort(sArr, mid, right);
sArr = Merge(sArr, left, mid, right);
}
return sArr;
}
}
/// <summary>あまりを計算するためのintのラッパー</summary>
struct ModInt {
int Value { get; }
int Mod { get; }
public override string ToString() { return Value.ToString(); }
public static explicit operator ModInt(long value) {
return new ModInt(value);
}
public ModInt(long value, int mod = 1000000007) {
this.Value = (int)(value % mod);
this.Mod = mod;
}
public static explicit operator int(ModInt modInt) { return modInt.Value; }
private static void CheckNotEqualMod(ModInt item1, ModInt item2) {
if (item1.Mod != item2.Mod) {
throw new Exception("mod not equal");
}
}
public static ModInt operator +(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value + item2.Value;
return new ModInt(value, item1.Mod);
}
public static ModInt operator *(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = Math.BigMul(item1.Value, item2.Value);
return new ModInt(value, item1.Mod);
}
public static ModInt operator -(ModInt item1, ModInt item2) {
CheckNotEqualMod(item1, item2);
long value = item1.Value - item2.Value;
if (value < 0) {
value += item1.Mod;
}
return new ModInt(value, item1.Mod);
}
public static ModInt operator +(ModInt item1, int item2) {
return item1 + new ModInt(item2, item1.Mod);
}
public static ModInt operator *(ModInt item1, int item2) {
return item1 * new ModInt(item2, item1.Mod);
}
public static ModInt operator -(ModInt item1, int item2) {
return item1 - new ModInt(item2, item1.Mod);
}
public override int GetHashCode() { return this.Value; }
public override bool Equals(object obj) {
if (obj == null || this.GetType() != obj.GetType()) {
return false;
}
var modIntObj = (ModInt)obj;
return modIntObj.Value == this.Value;
}
public static bool operator ==(ModInt item1, ModInt item2) {
return item1.Value == item2.Value;
}
public static bool operator !=(ModInt item1, ModInt item2) {
return !(item1 == item2);
}
public static bool operator ==(ModInt item1, int item2) {
return item1.Value == item2;
}
public static bool operator !=(ModInt item1, int item2) {
return !(item1.Value == item2);
}
public static bool operator >=(ModInt item1, ModInt item2) {
return item1.Value >= item2.Value;
}
public static bool operator <=(ModInt item1, ModInt item2) {
return item1.Value <= item2.Value;
}
public static bool operator >=(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator <=(ModInt item1, int item2) {
return item1.Value <= item2;
}
public static bool operator>(ModInt item1, ModInt item2) {
return item1.Value > item2.Value;
}
public static bool operator<(ModInt item1, ModInt item2) {
return item1.Value < item2.Value;
}
public static bool operator>(ModInt item1, int item2) {
return item1.Value >= item2;
}
public static bool operator<(ModInt item1, int item2) {
return item1.Value <= item2;
}
}
/// <summary>組み合わせ</summary>
class ModCombination {
private int mod;
private int[] fac;
private int[] finv;
private int[] inv;
public ModCombination(int max, int mod = 1000000007) {
this.mod = mod;
fac = new int[max]; // modが法のn!の列
inv = new int[max]; // indexの逆元の列
finv = new int[max]; // modを法とした、invの累積の累積
fac[0] = 1;
fac[1] = 1;
finv[0] = 1;
finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める
var s = Math.BigMul(inv[mod % i], mod / i) % mod;
inv[i] = (int)(mod - s);
// iに対する逆元を求める
finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod);
}
}
/// <summary>nCk</summary>
public int Calculation(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (int)(Math.BigMul(fac[n],
(int)(Math.BigMul(finv[k], finv[n - k]) % mod)) %
mod);
}
}
/// <summary>拡張メソッドs</summary>
static class Extention {
/// <summary>iとjを入れ替える</summary>
public static void Swap<T>(this T[] arr, int i, int j) {
var buf = arr[i];
arr[i] = arr[j];
arr[j] = buf;
}
/// <summary>
/// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。
/// </summary>
/// <param name="sArr"></param>
/// <param name="p">partitionの先頭の添字</param>
/// <param name="r">partitionの末尾の添字</param>
/// <returns>partitionの基準が存在する添字</returns>
public static int Partition(this int[] sArr, int p, int r) {
var x = sArr[r];
var i = p - 1;
for (int j = p; j < r; j++) {
if (sArr[j] <= x) {
i++;
sArr.Swap(i, j);
}
}
sArr.Swap(i + 1, r);
return i + 1;
}
/// <summary>深いコピーをする</summary>
public static T DeepCopy<T>(this T obj) {
T result;
var b = new BinaryFormatter();
using (var mem = new MemoryStream()) {
b.Serialize(mem,
obj); // binaryFormatterによりobjをmemにserial化して書き出す
mem.Position = 0; // memのpotisionを先頭に戻す
result = (T)b.Deserialize(mem); // memの内容を読み取る。
}
return result;
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 31, 203], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 203], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203]]
| 8
| 3,012
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
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();
// static Scan sc = new ScanCHK();
const int M = 1000000007;
const double eps = 1e-9;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main() {
long n = sc.Long;
Prt(n / 11 * 2 + (n + 5) / 6);
sw.Flush();
}
static void swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
static T Max<T>(params T[] a) { return a.Max(); }
static T Min<T>(params T[] a) { return a.Min(); }
static void DBG(string a) { Console.WriteLine(a); }
static void DBG<T>(IEnumerable<T> a) {
Console.WriteLine(string.Join(" ", a));
}
static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); }
static void Prt(string a) { sw.WriteLine(a); }
static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); }
static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); }
}
static class ex {
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) {
return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
}
public static Func<T, T> Lambda(Unary op) {
return Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
}
class ScanCHK : Scan {
public new string Str { get { var s = Console.ReadLine();
if (s != s.Trim())
throw new Exception();
return s;
}
}
}
class Scan {
public int Int {
get { return int.Parse(Str); }
}
public long Long {
get { return long.Parse(Str); }
}
public double Double {
get { return double.Parse(Str); }
}
public string Str {
get { return Console.ReadLine().Trim(); }
}
public int[] IntArr {
get { return StrArr.Select(int.Parse).ToArray(); }
}
public long[] LongArr {
get { return StrArr.Select(long.Parse).ToArray(); }
}
public double[] DoubleArr {
get { return StrArr.Select(double.Parse).ToArray(); }
}
public string[] StrArr {
get { return Str.Split(); }
}
bool eq<T, U>() { return typeof(T).Equals(typeof(U)); }
T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); }
T cv<T>(string s) {
return 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]);
}
}
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 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 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 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 = 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 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) { return 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) { return a / gcd(a, b) * b; }
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;
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;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
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();
// static Scan sc = new ScanCHK();
const int M = 1000000007;
const double eps = 1e-9;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main() {
long n = sc.Long;
Prt(n / 11 * 2 + (n % 11 + 5) / 6);
sw.Flush();
}
static void swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
static T Max<T>(params T[] a) { return a.Max(); }
static T Min<T>(params T[] a) { return a.Min(); }
static void DBG(string a) { Console.WriteLine(a); }
static void DBG<T>(IEnumerable<T> a) {
Console.WriteLine(string.Join(" ", a));
}
static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); }
static void Prt(string a) { sw.WriteLine(a); }
static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); }
static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); }
}
static class ex {
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) {
return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
}
public static Func<T, T> Lambda(Unary op) {
return Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
}
class ScanCHK : Scan {
public new string Str { get { var s = Console.ReadLine();
if (s != s.Trim())
throw new Exception();
return s;
}
}
}
class Scan {
public int Int {
get { return int.Parse(Str); }
}
public long Long {
get { return long.Parse(Str); }
}
public double Double {
get { return double.Parse(Str); }
}
public string Str {
get { return Console.ReadLine().Trim(); }
}
public int[] IntArr {
get { return StrArr.Select(int.Parse).ToArray(); }
}
public long[] LongArr {
get { return StrArr.Select(long.Parse).ToArray(); }
}
public double[] DoubleArr {
get { return StrArr.Select(double.Parse).ToArray(); }
}
public string[] StrArr {
get { return Str.Split(); }
}
bool eq<T, U>() { return typeof(T).Equals(typeof(U)); }
T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); }
T cv<T>(string s) {
return 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]);
}
}
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 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 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 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 = 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 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) { return 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) { return a / gcd(a, b) * b; }
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;
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;
}
}
|
[["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 109], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 203]]
| 8
| 2,934
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
class Program {
static void Main() {
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().Solve();
Out.Flush();
}
Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 };
readonly int mod = 1000000007;
readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
void Solve() {
var x = cin.Nextlong;
long sum = 2 * (x / 11);
if (0 < x % 11) {
sum++;
}
if (5 < x % 11) {
sum++;
}
WriteLine(sum);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] Scan {
get { return ReadLine().Split(); }
}
public int[] Scanint {
get { return Array.ConvertAll(Scan, int.Parse); }
}
public long[] Scanlong {
get { return Array.ConvertAll(Scan, long.Parse); }
}
public double[] Scandouble {
get { return Array.ConvertAll(Scan, double.Parse); }
}
public string Next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next;
}
}
public int Nextint {
get { return int.Parse(Next); }
}
public long Nextlong {
get { return long.Parse(Next); }
}
public double Nextdouble {
get { return double.Parse(Next); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
class Program {
static void Main() {
SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().Solve();
Out.Flush();
}
Scanner cin = new Scanner();
readonly int[] dd = { 0, 1, 0, -1, 0 };
readonly int mod = 1000000007;
readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
void Solve() {
var x = cin.Nextlong;
long sum = 2 * (x / 11);
if (0 < x % 11) {
sum++;
}
if (6 < x % 11) {
sum++;
}
WriteLine(sum);
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] Scan {
get { return ReadLine().Split(); }
}
public int[] Scanint {
get { return Array.ConvertAll(Scan, int.Parse); }
}
public long[] Scanlong {
get { return Array.ConvertAll(Scan, long.Parse); }
}
public double[] Scandouble {
get { return Array.ConvertAll(Scan, double.Parse); }
}
public string Next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next;
}
}
public int Nextint {
get { return int.Parse(Next); }
}
public long Nextlong {
get { return long.Parse(Next); }
}
public double Nextdouble {
get { return double.Parse(Next); }
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 203]]
| 8
| 431
| 2
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program {
public void Proc() {
Reader.IsDebug = false;
long inpt = long.Parse(Reader.ReadLine());
long ans = (inpt / 11) * 2;
if (inpt % 11 > 6) {
ans++;
} else if (inpt % 11 > 0) {
ans++;
}
Console.WriteLine(ans);
}
public class Reader {
public static bool IsDebug = true;
private static String PlainInput = @"
149696127901
";
private static System.IO.StringReader Sr = null;
public static string ReadLine() {
if (IsDebug) {
if (Sr == null) {
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
} else {
return Console.ReadLine();
}
}
}
static void Main() {
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program {
public void Proc() {
Reader.IsDebug = false;
long inpt = long.Parse(Reader.ReadLine());
long ans = (inpt / 11) * 2;
if (inpt % 11 > 6) {
ans += 2;
} else if (inpt % 11 > 0) {
ans++;
}
Console.WriteLine(ans);
}
public class Reader {
public static bool IsDebug = true;
private static String PlainInput = @"
149696127901
";
private static System.IO.StringReader Sr = null;
public static string ReadLine() {
if (IsDebug) {
if (Sr == null) {
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
} else {
return Console.ReadLine();
}
}
}
static void Main() {
Program prg = new Program();
prg.Proc();
}
}
|
[["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
| 8
| 202
| 3
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long ans = N / 11 * 2;
long left = ans % 11;
if (left != 0) {
if (left <= 6)
ans++;
else
ans += 2;
}
Console.WriteLine(ans);
}
long N;
public Sol() { N = rl(); }
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long ans = N / 11 * 2;
long left = N % 11;
if (left != 0) {
if (left <= 6)
ans++;
else
ans += 2;
}
Console.WriteLine(ans);
}
long N;
public Sol() { N = rl(); }
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22]]
| 8
| 342
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
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();
// static Scan sc = new ScanCHK();
const int M = 1000000007;
const double eps = 1e-9;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main() {
int n = sc.Int;
var a = sc.IntArr;
int c = a.Distinct().Count();
Prt(c - c % 2);
sw.Flush();
}
static void swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
static T Max<T>(params T[] a) { return a.Max(); }
static T Min<T>(params T[] a) { return a.Min(); }
static void DBG(string a) { Console.WriteLine(a); }
static void DBG<T>(IEnumerable<T> a) {
Console.WriteLine(string.Join(" ", a));
}
static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); }
static void Prt(string a) { sw.WriteLine(a); }
static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); }
static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); }
}
static class ex {
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) {
return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
}
public static Func<T, T> Lambda(Unary op) {
return Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
}
class ScanCHK : Scan {
public new string Str { get { var s = Console.ReadLine();
if (s != s.Trim())
throw new Exception();
return s;
}
}
}
class Scan {
public int Int {
get { return int.Parse(Str); }
}
public long Long {
get { return long.Parse(Str); }
}
public double Double {
get { return double.Parse(Str); }
}
public string Str {
get { return Console.ReadLine().Trim(); }
}
public int[] IntArr {
get { return StrArr.Select(int.Parse).ToArray(); }
}
public long[] LongArr {
get { return StrArr.Select(long.Parse).ToArray(); }
}
public double[] DoubleArr {
get { return StrArr.Select(double.Parse).ToArray(); }
}
public string[] StrArr {
get { return Str.Split(); }
}
bool eq<T, U>() { return typeof(T).Equals(typeof(U)); }
T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); }
T cv<T>(string s) {
return 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]);
}
}
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 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 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 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 = 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 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) { return 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) { return a / gcd(a, b) * b; }
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;
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;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;
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();
// static Scan sc = new ScanCHK();
const int M = 1000000007;
const double eps = 1e-9;
static readonly int[] dd = { 0, 1, 0, -1, 0 };
static void Main() {
int n = sc.Int;
var a = sc.IntArr;
int c = a.Distinct().Count();
Prt(c - (c + 1) % 2);
sw.Flush();
}
static void swap<T>(ref T a, ref T b) {
var t = a;
a = b;
b = t;
}
static T Max<T>(params T[] a) { return a.Max(); }
static T Min<T>(params T[] a) { return a.Min(); }
static void DBG(string a) { Console.WriteLine(a); }
static void DBG<T>(IEnumerable<T> a) {
Console.WriteLine(string.Join(" ", a));
}
static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); }
static void Prt(string a) { sw.WriteLine(a); }
static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); }
static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); }
}
static class ex {
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) {
return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile();
}
public static Func<T, T> Lambda(Unary op) {
return Expression.Lambda<Func<T, T>>(op(x), x).Compile();
}
}
class ScanCHK : Scan {
public new string Str { get { var s = Console.ReadLine();
if (s != s.Trim())
throw new Exception();
return s;
}
}
}
class Scan {
public int Int {
get { return int.Parse(Str); }
}
public long Long {
get { return long.Parse(Str); }
}
public double Double {
get { return double.Parse(Str); }
}
public string Str {
get { return Console.ReadLine().Trim(); }
}
public int[] IntArr {
get { return StrArr.Select(int.Parse).ToArray(); }
}
public long[] LongArr {
get { return StrArr.Select(long.Parse).ToArray(); }
}
public double[] DoubleArr {
get { return StrArr.Select(double.Parse).ToArray(); }
}
public string[] StrArr {
get { return Str.Split(); }
}
bool eq<T, U>() { return typeof(T).Equals(typeof(U)); }
T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); }
T cv<T>(string s) {
return 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]);
}
}
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 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 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 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 = 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 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) { return 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) { return a / gcd(a, b) * b; }
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;
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;
}
}
|
[["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 24], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 25]]
| 8
| 2,946
| 4
|
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();
var a = Input.NextInt(n);
var dic = new Dictionary<int, int>();
foreach (var ai in a) {
if (!dic.ContainsKey(ai)) {
dic.Add(ai, 0);
}
dic[ai]++;
}
var list = dic.ToArray();
for (int i = 0; i < list.Length; ++i) {
var kv = list[i];
if (kv.Value >= 3) {
int total = kv.Value % 2 == 0 ? 2 : 1;
list[i] = new KeyValuePair<int, int>(kv.Key, total);
}
}
var ans = 0;
foreach (var kv in list) {
ans += kv.Value;
}
int cntEven = 0;
foreach (var kv in list) {
if (kv.Value == 2) {
cntEven++;
}
}
if (cntEven % 2 == 0) {
ans -= cntEven;
} else {
ans -= (cntEven + 2);
}
Console.WriteLine(ans);
}
#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();
var a = Input.NextInt(n);
var dic = new Dictionary<int, int>();
foreach (var ai in a) {
if (!dic.ContainsKey(ai)) {
dic.Add(ai, 0);
}
dic[ai]++;
}
var list = dic.ToArray();
for (int i = 0; i < list.Length; ++i) {
var kv = list[i];
if (kv.Value >= 3) {
int total = kv.Value % 2 == 0 ? 2 : 1;
list[i] = new KeyValuePair<int, int>(kv.Key, total);
}
}
var ans = 0;
foreach (var kv in list) {
ans += kv.Value;
}
int cntEven = 0;
foreach (var kv in list) {
if (kv.Value == 2) {
cntEven++;
}
}
if (cntEven % 2 == 0) {
ans -= cntEven;
} else {
ans -= (cntEven + 1);
}
Console.WriteLine(ans);
}
#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, 1, 0, 11, 12, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 12, 203]]
| 8
| 2,494
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
Dictionary<int, int> di = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
if (di.ContainsKey(A[i]) == false)
di.Add(A[i], 0);
di[A[i]]++;
}
int tot = 0;
foreach (var k in di.Keys) {
if (di[k] > 1)
tot += di[k] - 1;
}
int ans = tot / 2;
if (tot % 2 == 1)
ans++;
Console.WriteLine(ans);
}
int N;
int[] A;
public Sol() {
N = ri();
A = ria();
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
Dictionary<int, int> di = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
if (di.ContainsKey(A[i]) == false)
di.Add(A[i], 0);
di[A[i]]++;
}
int tot = 0;
foreach (var k in di.Keys) {
if (di[k] > 1)
tot += di[k] - 1;
}
int ans = tot / 2;
if (tot % 2 == 1)
ans++;
Console.WriteLine(N - 2 * ans);
}
int N;
int[] A;
public Sol() {
N = ri();
A = ria();
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48]]
| 8
| 436
| 4
|
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 (x < y)
gcd(y, x);
while (y != 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
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 n = Read();
long ans = 0;
var a = new long[n];
var b = new long[n];
for (int i = 0; i < n; i++) {
var q = Reads();
a[i] = q[0];
b[i] = q[1];
}
for (long i = n - 1; i > 0; i--) {
a[i] += ans;
if (a[i] % b[i] != 0)
ans += b[i] - a[i] % b[i];
}
WriteLine(ans);
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 (x < y)
gcd(y, x);
while (y != 0) {
var z = x;
x = y;
y = z % y;
}
return x;
}
public static long lcm(long x, long y) { return x * y / gcd(x, y); }
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 n = Read();
long ans = 0;
var a = new long[n];
var b = new long[n];
for (int i = 0; i < n; i++) {
var q = Reads();
a[i] = q[0];
b[i] = q[1];
}
for (long i = n - 1; i >= 0; i--) {
a[i] += ans;
if (a[i] % b[i] != 0)
ans += b[i] - a[i] % b[i];
}
WriteLine(ans);
Console.Out.Flush();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20]]
| 8
| 384
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var AB = sc.ReadTupLongArray(N);
long ans = 0;
for (int i = N - 1; i >= 0; i--) {
var a = AB[i].Item1;
var b = AB[i].Item2;
a += ans;
if (b > 1 && a > 0 && b % a > 0) {
ans += b - (a % b);
}
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var AB = sc.ReadTupLongArray(N);
long ans = 0;
for (int i = N - 1; i >= 0; i--) {
var a = AB[i].Item1;
var b = AB[i].Item2;
a += ans;
if (b > 1 && a > 0 && a % b > 0) {
ans += b - (a % b);
}
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public Tuple<int, int> ReadTup(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add);
}
public Tuple<long, long> ReadTupLong(int add = 0) {
return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add);
}
public Tuple<int, int, int> ReadTup3(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add);
}
public Tuple<int, int, int, int> ReadTup4(int add = 0) {
return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add,
this.ReadInt() + add, this.ReadInt() + add);
}
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) {
var array = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTupLong(add);
}
return array;
}
public Tuple<int, int>[] ReadTupArray(int n, int add = 0) {
var array = new Tuple<int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup(add);
}
return array;
}
public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) {
var array = new Tuple<int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup3(add);
}
return array;
}
public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) {
var array = new Tuple<int, int, int, int>[n];
for (int i = 0; i < n; i++) {
array[i] = this.ReadTup4(add);
}
return array;
}
}
|
[["-", 0, 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, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22]]
| 8
| 1,102
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Solution {
public int N;
public List<List<int>> D;
public void Run() {
// Input
N = Input.ReadInt();
D = new List<List<int>>();
for (int i = 0; i < N; i++) {
D.Add(new List<int>());
}
for (int i = 1; i < N; i++) {
var w = Input.ReadInt() - 1;
int l = i;
D[w].Add(l);
}
int ret = 0; // Depth(0);
Console.WriteLine(ret);
}
public int Depth(int i) {
int c = D[i].Count;
if (c == 0)
return 0;
if (c == 1)
return Depth(D[i][0]) + 1;
int[] depths = new int[c];
for (int j = 0; j < c; j++) {
depths[j] = Depth(D[i][j]);
}
Array.Sort(depths);
for (int d = 0; d < c; d++) {
depths[d] += (c - d);
}
int ret = 0;
for (int d = 0; d < c; d++) {
ret = Math.Max(ret, depths[d]);
}
return ret;
}
}
// 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.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
internal class Solution {
public int N;
public List<List<int>> D;
public void Run() {
// Input
N = Input.ReadInt();
D = new List<List<int>>();
for (int i = 0; i < N; i++) {
D.Add(new List<int>());
}
for (int i = 1; i < N; i++) {
var w = Input.ReadInt() - 1;
int l = i;
D[w].Add(l);
}
int ret = Depth(0);
Console.WriteLine(ret);
}
public int Depth(int i) {
int c = D[i].Count;
if (c == 0)
return 0;
if (c == 1)
return Depth(D[i][0]) + 1;
int[] depths = new int[c];
for (int j = 0; j < c; j++) {
depths[j] = Depth(D[i][j]);
}
Array.Sort(depths);
for (int d = 0; d < c; d++) {
depths[d] += (c - d);
}
int ret = 0;
for (int d = 0; d < c; d++) {
ret = Math.Max(ret, depths[d]);
}
return ret;
}
}
// 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, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 547
| 3
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var abcd = ReadIntArray();
Console.WriteLine(Math.Max(abcd[0] + abcd[1], abcd[2] * abcd[3]));
}
private static readonly Func<string> Read = () => Console.ReadLine();
private static readonly Func<string[]> ReadStringArray = () =>
Console.ReadLine().Split();
private static readonly Func<int> ReadInt = () =>
int.Parse(Console.ReadLine());
private static readonly Func<long> ReadLong = () =>
long.Parse(Console.ReadLine());
private static readonly Func<int[]> ReadIntArray = () =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
private static readonly Func<long[]> ReadLongArray = () =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
private static readonly Action<string> Cw = str => Console.WriteLine(str);
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;
namespace Atcoder {
class Program {
static void Main(string[] args) {
var abcd = ReadIntArray();
Console.WriteLine(Math.Max(abcd[0] * abcd[1], abcd[2] * abcd[3]));
}
private static readonly Func<string> Read = () => Console.ReadLine();
private static readonly Func<string[]> ReadStringArray = () =>
Console.ReadLine().Split();
private static readonly Func<int> ReadInt = () =>
int.Parse(Console.ReadLine());
private static readonly Func<long> ReadLong = () =>
long.Parse(Console.ReadLine());
private static readonly Func<int[]> ReadIntArray = () =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
private static readonly Func<long[]> ReadLongArray = () =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
private static readonly Action<string> Cw = str => Console.WriteLine(str);
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48]]
| 8
| 264
| 2
|
using System;
public class Program {
public static void Main(string[] args) {
var sArray = Console.ReadLine().Split(' ');
var a = int.Parse(sArray[0]);
var b = int.Parse(sArray[1]);
var c = int.Parse(sArray[2]);
var d = int.Parse(sArray[3]);
if (a * b > c * d || a * b == c * d) {
Console.WriteLine(a * b);
} else if (a * b < c * d) {
Console.WriteLine(b * c);
}
}
}
|
using System;
public class Program {
public static void Main(string[] args) {
var sArray = Console.ReadLine().Split(' ');
var a = int.Parse(sArray[0]);
var b = int.Parse(sArray[1]);
var c = int.Parse(sArray[2]);
var d = int.Parse(sArray[3]);
if (a * b > c * d || a * b == c * d) {
Console.WriteLine(a * b);
} else if (a * b < c * d) {
Console.WriteLine(c * d);
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 139
| 4
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
String input = Console.ReadLine();
String[] nums = input.Split(' ');
int[] a = new int[4];
for (int i = 0; i < 4; i++) {
a[i] = int.Parse(nums[i]);
}
int rect1 = a[0] * a[1];
int rect2 = a[2] * a[2];
if (rect1 > rect2) {
Console.WriteLine(rect1);
} else {
Console.WriteLine(rect2);
}
}
}
}
|
using System;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
String input = Console.ReadLine();
String[] nums = input.Split(' ');
int[] a = new int[4];
for (int i = 0; i < 4; i++) {
a[i] = int.Parse(nums[i]);
}
int rect1 = a[0] * a[1];
int rect2 = a[2] * a[3];
if (rect1 > rect2) {
Console.WriteLine(rect1);
} else {
Console.WriteLine(rect2);
}
}
}
}
|
[["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 138
| 2
|
using System;
public class TR {
public static void Main() {
string[] read = new string[4];
read = Console.ReadLine().Split(' ');
int A = int.Parse(read[0]);
int B = int.Parse(read[1]);
int C = int.Parse(read[0]);
int D = int.Parse(read[1]);
int S1 = A * B;
int S2 = C * D;
if (S1 >= S2) {
Console.WriteLine(S1);
} else {
Console.WriteLine(S2);
}
}
}
|
using System;
public class TR {
public static void Main() {
string[] read = new string[4];
read = Console.ReadLine().Split(' ');
int A = int.Parse(read[0]);
int B = int.Parse(read[1]);
int C = int.Parse(read[2]);
int D = int.Parse(read[3]);
int S1 = A * B;
int S2 = C * D;
if (S1 >= S2) {
Console.WriteLine(S1);
} else {
Console.WriteLine(S2);
}
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 133
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var S = sc.ReadStr();
var x = 0;
var ans = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'I')
x++;
else
x--;
ans = Math.Max(ans, x);
}
Console.WriteLine(x);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var S = sc.ReadStr();
var x = 0;
var ans = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'I')
x++;
else
x--;
ans = Math.Max(ans, x);
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
|
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 623
| 2
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
public class Program {
public void Proc() {
Reader.IsDebug = false;
string[] inpt = Reader.ReadLine().Split(' ');
long ans = 0;
if (inpt[1].Equals("+")) {
ans = long.Parse(inpt[0]) + long.Parse(inpt[1]);
} else {
ans = long.Parse(inpt[0]) - long.Parse(inpt[1]);
}
Console.WriteLine(ans);
}
public class Reader {
public static bool IsDebug = true;
private static System.IO.StringReader SReader;
private static string InitText = @"
";
public static string ReadLine() {
if (IsDebug) {
if (SReader == null) {
SReader = new System.IO.StringReader(InitText.Trim());
}
return SReader.ReadLine();
} else {
return Console.ReadLine();
}
}
}
public static void Main(string[] args) {
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
public class Program {
public void Proc() {
Reader.IsDebug = false;
string[] inpt = Reader.ReadLine().Split(' ');
long ans = 0;
if (inpt[1].Equals("+")) {
ans = long.Parse(inpt[0]) + long.Parse(inpt[2]);
} else {
ans = long.Parse(inpt[0]) - long.Parse(inpt[2]);
}
Console.WriteLine(ans);
}
public class Reader {
public static bool IsDebug = true;
private static System.IO.StringReader SReader;
private static string InitText = @"
";
public static string ReadLine() {
if (IsDebug) {
if (SReader == null) {
SReader = new System.IO.StringReader(InitText.Trim());
}
return SReader.ReadLine();
} else {
return Console.ReadLine();
}
}
}
public static void Main(string[] args) {
Program prg = new Program();
prg.Proc();
}
}
|
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 247
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
static Dictionary<int, List<int>> nodes;
public static void Main() {
Console.ReadLine();
var tArr =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var m = int.Parse(Console.ReadLine());
var allScore = tArr.Sum();
for (int i = 0; i < m; i++) {
var drink =
Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
var score = allScore - tArr[drink[0]] + drink[1];
Console.WriteLine(score);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
public class Program {
static Dictionary<int, List<int>> nodes;
public static void Main() {
Console.ReadLine();
var tArr =
Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
var m = int.Parse(Console.ReadLine());
var allScore = tArr.Sum();
for (int i = 0; i < m; i++) {
var drink =
Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
var score = allScore - tArr[drink[0] - 1] + drink[1];
Console.WriteLine(score);
}
}
}
|
[["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 174
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
Console.ReadLine();
string[] arrStrOriginalTime = Console.ReadLine().Split(' ');
int intDrinkCount = int.Parse(Console.ReadLine());
List<string> lstStrProlemAndChangeTime = new List<string>();
for (int i = 0; i < intDrinkCount; i++) {
lstStrProlemAndChangeTime.Add(Console.ReadLine());
}
int intSumTime = 0;
for (int i = 0; i < arrStrOriginalTime.Length; i++) {
intSumTime += int.Parse(arrStrOriginalTime[i]);
}
for (int i = 0; i < intDrinkCount; i++) {
int intProblemNumber =
int.Parse(lstStrProlemAndChangeTime[i].Split(' ')[0]);
int intChangeTime = int.Parse(lstStrProlemAndChangeTime[i].Split(' ')[1]);
int intOutputTime = intSumTime +
int.Parse(arrStrOriginalTime[intProblemNumber]) -
intChangeTime;
Console.WriteLine(intOutputTime.ToString());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
Console.ReadLine();
string[] arrStrOriginalTime = Console.ReadLine().Split(' ');
int intDrinkCount = int.Parse(Console.ReadLine());
List<string> lstStrProlemAndChangeTime = new List<string>();
for (int i = 0; i < intDrinkCount; i++) {
lstStrProlemAndChangeTime.Add(Console.ReadLine());
}
int intSumTime = 0;
for (int i = 0; i < arrStrOriginalTime.Length; i++) {
intSumTime += int.Parse(arrStrOriginalTime[i]);
}
for (int i = 0; i < intDrinkCount; i++) {
int intProblemNumber =
int.Parse(lstStrProlemAndChangeTime[i].Split(' ')[0]);
int intChangeTime = int.Parse(lstStrProlemAndChangeTime[i].Split(' ')[1]);
int intOutputTime = intSumTime -
int.Parse(arrStrOriginalTime[intProblemNumber - 1]) +
intChangeTime;
Console.WriteLine(intOutputTime.ToString());
}
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72]]
| 8
| 242
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC049A {
class Program {
static void Main(string[] args) {
var c = Console.ReadLine();
var a = new string[] { "a", "e", "i", "o", "u" };
for (var i = 0; i < 5; i++) {
if (a[i] == c)
Console.WriteLine("vowel");
return;
}
Console.WriteLine("consonant");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC049A {
class Program {
static void Main(string[] args) {
var c = Console.ReadLine();
var a = new string[] { "a", "e", "i", "o", "u" };
for (var i = 0; i < 5; i++) {
if (a[i] == c) {
Console.WriteLine("vowel");
return;
}
}
Console.WriteLine("consonant");
}
}
}
|
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 129
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
class Program {
static void Main(string[] args) {
var c = sc.ReadStr()[0];
if (c == 'a' || c == 'i' || c == 'e' || c == 'u' || c == '0') {
Console.WriteLine("vowel");
} else {
Console.WriteLine("consonant");
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
class Program {
static void Main(string[] args) {
var c = sc.ReadStr()[0];
if (c == 'a' || c == 'i' || c == 'e' || c == 'u' || c == 'o') {
Console.WriteLine("vowel");
} else {
Console.WriteLine("consonant");
}
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
|
[["-", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253]]
| 8
| 617
| 2
|
using System;
using System.Linq;
class p {
static void Main() {
string s = Console.ReadLine();
Console.WriteLine(s == "a" || s == "i" || s == "u" || s == "e" || s == "o"
? "Yes"
: "No");
}
}
|
using System;
using System.Linq;
class p {
static void Main() {
string s = Console.ReadLine();
Console.WriteLine(s == "a" || s == "i" || s == "u" || s == "e" || s == "o"
? "vowel"
: "consonant");
}
}
|
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 71
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using static ConsoleApplication.Utils;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var c = ReadLine().First();
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
WriteLine("vowel");
break;
default:
WriteLine("consonant");
break;
}
}
}
public static class Utils
{
#region Extensions for IO
public static int ReadInt()
=> ReadLine().ToInt();
public static IEnumerable<int> ReadInts()
=> ReadStrings().Select(int.Parse);
public static IEnumerable<int> ReadInts(int count)
=> ReadLines(count).Select(int.Parse);
public static long ReadLong()
=> ReadLine().ToLong();
public static IEnumerable<long> ReadLongs()
=> ReadStrings().Select(long.Parse);
public static ulong ReadUlong()
=> ReadLine().ToUlong();
public static IEnumerable<ulong> ReadUlongs()
=> ReadStrings().Select(ulong.Parse);
public static IEnumerable<string> ReadStrings()
=> ReadLine().Split(' ');
public static IEnumerable<string> ReadLines(int n)
{
foreach (var i in Enumerable.Range(0, n))
{
yield return ReadLine();
}
}
#endregion
#region Extensions of int
public static bool IsOdd(this int n)
=> !n.IsEven();
public static bool IsEven(this int n)
=> n % 2 == 0;
public static bool CanDivideWith(this int n, int divisor)
=> n % divisor == 0;
#endregion
#region Extensions of string
public static int ToInt(this string str)
=> int.Parse(str);
public static long ToLong(this string str)
=> long.Parse(str);
public static ulong ToUlong(this string str)
=> ulong.Parse(str);
public static double ToDouble(this string str)
=> double.Parse(str);
public static bool IsNullOrEmpty(this string str)
=> string.IsNullOrEmpty(str);
#endregion
public static TSource Min<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
where TKey : IComparable
=> source.OrderBy(keySelector).First();
public static TSource Max<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
where TKey : IComparable
=> source.OrderByDescending(keySelector).First();
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var item in source)
{
action(item);
}
}
public static IEnumerable<T> Peek<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var item in source)
{
action(item);
}
return source;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using static ConsoleApplication.Utils;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var c = ReadLine().First();
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
WriteLine("vowel");
break;
default:
WriteLine("consonant");
break;
}
}
}
public static class Utils
{
#region Extensions for IO
public static int ReadInt()
=> ReadLine().ToInt();
public static IEnumerable<int> ReadInts()
=> ReadStrings().Select(int.Parse);
public static IEnumerable<int> ReadInts(int count)
=> ReadLines(count).Select(int.Parse);
public static long ReadLong()
=> ReadLine().ToLong();
public static IEnumerable<long> ReadLongs()
=> ReadStrings().Select(long.Parse);
public static ulong ReadUlong()
=> ReadLine().ToUlong();
public static IEnumerable<ulong> ReadUlongs()
=> ReadStrings().Select(ulong.Parse);
public static IEnumerable<string> ReadStrings()
=> ReadLine().Split(' ');
public static IEnumerable<string> ReadLines(int n)
{
foreach (var i in Enumerable.Range(0, n))
{
yield return ReadLine();
}
}
#endregion
#region Extensions of int
public static bool IsOdd(this int n)
=> !n.IsEven();
public static bool IsEven(this int n)
=> n % 2 == 0;
public static bool CanDivideWith(this int n, int divisor)
=> n % divisor == 0;
#endregion
#region Extensions of string
public static int ToInt(this string str)
=> int.Parse(str);
public static long ToLong(this string str)
=> long.Parse(str);
public static ulong ToUlong(this string str)
=> ulong.Parse(str);
public static double ToDouble(this string str)
=> double.Parse(str);
public static bool IsNullOrEmpty(this string str)
=> string.IsNullOrEmpty(str);
#endregion
public static TSource Min<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
where TKey : IComparable
=> source.OrderBy(keySelector).First();
public static TSource Max<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
where TKey : IComparable
=> source.OrderByDescending(keySelector).First();
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var item in source)
{
action(item);
}
}
public static IEnumerable<T> Peek<T>(this IEnumerable<T> source, Action<T> action)
{
foreach (var item in source)
{
action(item);
}
return source;
}
}
}
|
[["+", 0, 99, 8, 254, 0, 239, 0, 264, 0, 173], ["+", 8, 254, 0, 239, 0, 264, 0, 252, 0, 104], ["+", 8, 254, 0, 239, 0, 264, 0, 252, 0, 253], ["+", 0, 99, 8, 254, 0, 239, 0, 264, 0, 102]]
| 8
| 619
| 5
|
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;
namespace AtCoder {
class Program {
static void Main() {
var hw = ReadString();
var h = hw[0];
for (int i = 0; i < h; i++) {
var c = ReadString();
Console.WriteLine(c);
Console.WriteLine(c);
}
}
}
public static class Io {
public static string ReadString() => Console.ReadLine();
public static string[] ReadStringArray() => ReadString().Split(' ');
public static int ReadInt() => int.Parse(ReadString());
public static long ReadLong() => long.Parse(ReadString());
public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
public static long[] ReadLongArray() =>
ReadStringArray().ParseLong().ToArray();
public static IEnumerable<int>
ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
public static IEnumerable<long>
ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;
namespace AtCoder {
class Program {
static void Main() {
var hw = ReadIntArray();
var h = hw[0];
for (int i = 0; i < h; i++) {
var c = ReadString();
Console.WriteLine(c);
Console.WriteLine(c);
}
}
}
public static class Io {
public static string ReadString() => Console.ReadLine();
public static string[] ReadStringArray() => ReadString().Split(' ');
public static int ReadInt() => int.Parse(ReadString());
public static long ReadLong() => long.Parse(ReadString());
public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
public static long[] ReadLongArray() =>
ReadStringArray().ParseLong().ToArray();
public static IEnumerable<int>
ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
public static IEnumerable<long>
ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22]]
| 8
| 251
| 2
|
using System;
using System.Linq;
public class Hello {
public static void Main() {
int[] x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int H = x[0];
int W = x[1];
for (int i = 0; i < W; i++) {
string str = Console.ReadLine();
Console.WriteLine(str);
Console.WriteLine(str);
}
}
}
|
using System;
using System.Linq;
public class Hello {
public static void Main() {
int[] x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int H = x[0];
int W = x[1];
for (int i = 0; i < H; i++) {
string str = Console.ReadLine();
Console.WriteLine(str);
Console.WriteLine(str);
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 105
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) { Solve(); }
private const long MOD = 1000000007;
static void Solve() {
var o = ReadAndParseIntArr();
int h = o[0];
int w = o[1];
var c = new string[h];
for (int i = 0; i < h; ++i) {
c[i] = Console.ReadLine();
}
for (int i = 0; i < 2 * h; ++i) {
string s = c[(i + 1) / 2];
Console.WriteLine(s);
}
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
#endregion
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Practice {
class Program {
static void Main(string[] args) { Solve(); }
private const long MOD = 1000000007;
static void Solve() {
var o = ReadAndParseIntArr();
int h = o[0];
int w = o[1];
var c = new string[h];
for (int i = 0; i < h; ++i) {
c[i] = Console.ReadLine();
}
for (int i = 0; i < 2 * h; ++i) {
string s = c[i / 2];
Console.WriteLine(s);
}
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
#endregion
}
}
|
[["-", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 206, 207, 0, 28, 0, 16, 31, 23, 0, 25]]
| 8
| 456
| 4
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
public class Hello {
public static void Main() {
//出力を早くする
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var wh = Console.ReadLine().Split().Select(int.Parse).ToArray();
int w = wh[0];
int h = wh[1];
for (int i = 0; i < h; i++) {
string line = Console.ReadLine();
for (int n = 0; n < 2; n++) {
Console.WriteLine(line);
}
}
Console.Out.Flush();
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
public class Hello {
public static void Main() {
//出力を早くする
Console.SetOut(
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
int h = hw[0];
int w = hw[1];
for (int i = 0; i < h; i++) {
string line = Console.ReadLine();
for (int n = 0; n < 2; n++) {
Console.WriteLine(line);
}
}
Console.Out.Flush();
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22]]
| 8
| 150
| 10
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
public class Program {
public void Proc() {
int[] inpt =
Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int rowCount = inpt[0];
StringBuilder ans = new StringBuilder();
for (int i = 0; i < rowCount; i++) {
string text = Reader.ReadLine();
ans.AppendLine(text);
ans.AppendLine(text);
}
Console.Write(ans.ToString());
}
public class Reader {
public static bool IsDebug = true;
private static System.IO.StringReader SReader;
private static string InitText = @"
2 2
*.
.*
";
public static string ReadLine() {
if (IsDebug) {
if (SReader == null) {
SReader = new System.IO.StringReader(InitText.Trim());
}
return SReader.ReadLine();
} else {
return Console.ReadLine();
}
}
}
public static void Main(string[] args) {
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
public class Program {
public void Proc() {
Reader.IsDebug = false;
int[] inpt =
Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int rowCount = inpt[0];
StringBuilder ans = new StringBuilder();
for (int i = 0; i < rowCount; i++) {
string text = Reader.ReadLine();
ans.AppendLine(text);
ans.AppendLine(text);
}
Console.Write(ans.ToString());
}
public class Reader {
public static bool IsDebug = true;
private static System.IO.StringReader SReader;
private static string InitText = @"
2 2
*.
.*
";
public static string ReadLine() {
if (IsDebug) {
if (SReader == null) {
SReader = new System.IO.StringReader(InitText.Trim());
}
return SReader.ReadLine();
} else {
return Console.ReadLine();
}
}
}
public static void Main(string[] args) {
Program prg = new Program();
prg.Proc();
}
}
|
[["+", 8, 196, 0, 1, 0, 11, 31, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 11, 31, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 248
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Threading.Tasks;
namespace B {
class Program {
static void Main(string[] args) {
int[] input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
for (int i = 0; i < input[1]; ++i) {
string str = Console.ReadLine();
Console.Write("{0}\n{0}\n", str);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Threading.Tasks;
namespace B {
class Program {
static void Main(string[] args) {
int[] input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
for (int i = 0; i < input[0]; ++i) {
string str = Console.ReadLine();
Console.Write("{0}\n{0}\n", str);
}
}
}
}
|
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 116
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Threading.Tasks;
namespace B {
class Program {
static void Main(string[] args) {
int[] input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
for (int i = 0; i < input[1]; ++i) {
string str = Console.ReadLine();
Console.Write("{0}\n{0}\n", str);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// using System.Threading.Tasks;
namespace B {
class Program {
static void Main(string[] args) {
int[] input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
string str;
for (int i = 0; i < input[0]; ++i) {
str = Console.ReadLine();
Console.Write("{0}\n{0}\n", str);
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 116
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace AIZUproject07 {
class Program {
// static string T;
/*static void Main()
{
int count = 0;
bool flag = false;
string In = Console.ReadLine();
string[] s = Console.ReadLine().Split();
int[] aa = s.Select(int.Parse).ToArray();
while (true)
{
for (int i = 0; i < aa.Length; i++)
{
if (aa[i] % 2 != 0)
{
flag = true;
}
}
aa = aa.Select(n => n / 2).ToArray();
if (flag == true) break;
count++;
}
Console.WriteLine(count);
}*/
/*static void Main()
{
int sum = 0;
int count = 0;
string A = Console.ReadLine();
string B = Console.ReadLine();
string C = Console.ReadLine();
string D = Console.ReadLine();
int AA = int.Parse(A);
int BB = int.Parse(B);
int CC = int.Parse(C);
int DD = int.Parse(D);
for(int i = 0;i<=AA;i++)
{
for (int j=0;j<=BB;j++)
{
for (int k =0;k<=CC;k++)
{
sum = i * 500 + j * 100 + k * 50;
if (sum == DD) count++;
}
}
}
Console.WriteLine(count);
}*/
/*static void Main()
{
int ans1 = 0;
int ans2 = 0;
string[] s = Console.ReadLine().Split();
int[] intArray = s.Select(int.Parse).ToArray();
for (int i = 1;i<=intArray[0];i++)
{
ans1 = 0;
if (i >= 10 && i <100)
{
var aaa = i % 10;
var bbb = i / 10;
ans1 = aaa + bbb;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
if (i >= 100 && i<1000)
{
var aaa = i % 10;
var bbb = i / 10;
var ccc = bbb % 10;
var ddd = bbb / 10;
ans1 = aaa + ccc + ddd;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
if (i >= 1000 && i <10000)
{
var aaa = i % 10;//4
var bbb = i / 10;
var ccc = bbb % 10;//3
var ddd = bbb / 10;
var eee = ddd % 10;//2
var fff = ddd / 10;//1
ans1 = aaa + ccc + eee + fff;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
if (i == 10000)
{
ans1 = 1;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
if (i < 10)
{
ans1 = i;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
}
Console.WriteLine(ans2);
}*/
/*static void Main()
{
int sum = 0;
bool test = false;
string[] aa = Console.ReadLine().Split();
int N = int.Parse(aa[0]);
int Y = int.Parse(aa[1]);
int Yukichi = Y / 10000;
int Ichiyo = Y / 5000;
int Hideyo = Y / 1000;
int x = 0;
int y = 0;
int z = 0;
for (int i = 0;i<=Yukichi;i++)
{
for (int j =0;j<=Ichiyo;j++)
{
for (int k =0;k<=Hideyo;k++)
{
sum = 10000 * i + 5000 * j + 1000 * k;
if (sum == Y && i+j+k < N)
{
x = i;
y = j;
z = k;
//Console.WriteLine(i + " " + j + " " + k);
test = true;
}
}
}
}
if (test == true)
{
Console.WriteLine(x + " " + y + " " + z);
}
if (test == false)
{
Console.WriteLine("-1 -1 -1");
}
}*/
/*static void Main()
{
string[] aa = Console.ReadLine().Split();
int N = int.Parse(aa[0]);
int Y = int.Parse(aa[1]);
int X = 0;
int Z = 0;
int b = 0;
int d = 0;
X = Y / 10000;
var a = Y - (X*10000);
if (a != 0 || Y < 10000)
{
b = a / 5000;
var cc = a - (b * 5000);
if (cc != 0 || a < 5000)
{
d = cc / 1000;
var gg = cc - (d * 1000);
if (gg != 0 || cc<1000)
{
Console.WriteLine("-1 -1 -1");
}
else if (X + b + d <= N)
{
Console.WriteLine(X + " " + b + " " + d);
}
else if (X + b + d > N)
{
Console.WriteLine("-1 -1 -1");
}
}
else if (X + b <= N)
{
Console.WriteLine(X +" "+ b +" "+"0");
}
else if (X + b > N)
{
Console.WriteLine("-1 -1 -1");
}
}
else if (X <= N)
{
Console.WriteLine(X +" "+0+" "+0);
}
else if (X>N)
{
Console.WriteLine("-1 -1 -1");
}
}*/
/*static void Main()
{
string s = Console.ReadLine();
var Ans = s.Replace("eraser", "").Replace("dreamer",
"").Replace("dreamer", "").Replace("erase", "").ToString(); if (Ans == null)
Console.WriteLine("YES"); else Console.WriteLine("NO");*/
// List<string> str = new List<string>(); || s.Substring(5, 1) == ""
// string NN = new string(s); || s.Substring(5,1) == ""
/*while (true) {
while (true)
{
if (s.StartsWith("dream") && (s.Substring(5,2) != "er" ))
{
count++;
var f = s.Remove(0, 5);
s = f;
break;
}
if (s.StartsWith("dreamer"))
{
var n = s.Remove(0, 7);
s = n;
break;
}
if (s.StartsWith("erase") || (s.Substring(5,1) != "r" ))
{
count2++;
var f1 = s.Remove(0, 5);
s = f1;
break;
}
if (s.StartsWith("eraser"))
{
var f2 = s.Remove(0, 6);
s = f2;
break;
}
else
{
tt = true;
break;
}
}
if (s.Length == 0)
{
Console.WriteLine("YES");
break;
}
if (tt)
{
Console.WriteLine("NO");
break;
}
}*/
// Console.WriteLine(count+","+count2);
//}
// 86C
/*static void Main()
{
/*string aa = Console.ReadLine();
List<int[]> nn = new List<int[]>();
for (int i = 0;i<aa.Length;i++)
{
string[] str = Console.ReadLine().Split();
int[] intstr = str.Select(int.Parse).ToArray();
nn.Add(intstr);
}
var a1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
var num = a1[0];
var list = new List<int[]>(num);
for (int i=0;i<num;i++)
{
}
}*/
/*static void Main(string[] args)
{
var input = Console.ReadLine().Split(' ');
var array = input.Select(int.Parse).ToArray();
int num = array[0] * 100 + array[1] * 10 + array[2] * 1;
if (num % 4 == 0)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
/*static void Main()
{
var input = Console.ReadLine();
var a = Console.ReadLine();
int N = int.Parse(input);
int A = int.Parse(a);
bool flag = false;
for (int i = 0;i <= A;i++ )
{
var Ans = N - i;
if (Ans % 500 == 0)
{
Console.WriteLine("Yes");
flag = true;
break;
}
}
if (flag == false)
{
Console.WriteLine("No");
}
}*/
/*static void Main()
{
var a = Console.ReadLine().Split();
double[] integer = a.Select(double.Parse).ToArray();
double ans = (integer[0] + integer[1]) / 2;
Console.WriteLine(Math.Ceiling(ans));
}*/
/*static void Main()
{
int count = 0;
string str = Console.ReadLine();
//var cross = str.Select(n => n != '×');
//var circle = str.Select(n => n != 'o');
//Console.WriteLine(cross);
//Console.WriteLine(circle);
/*Console.WriteLine(str.Length);
while (true)
{
Match match1 = Regex.Match(str, "o");
if (match1 != null)
{
count++;
}
str = str.Substring(match1.Index+1, str.Length);
if (match1.Index == str.Length)
{
break;
}
}
var Ans = 700 + count * 100;
Console.WriteLine(Ans);*/
// Console.WriteLine(match.Value);
/*or (int i =0;i<str.Length;i++)
{
if (Regex.Match(str[i], "o"))
{
}
}
count = str.Length - str.Replace("o", "").Length;
var Ans = 700 + count * 100;
Console.WriteLine(Ans);
}*/
/*static void Main()
{
var str = Console.ReadLine();
var Ans = str.Replace("2017","2018");
Console.WriteLine(Ans);
}*/
/*static void Main()
{
var str = Console.ReadLine();
//str.Substring(0, 1) +
Console.WriteLine(str.Substring(0, 1) + (str.Length-2) +
str.Substring(str.Length-1));
}*/
// 82B
/*static void Main()
{
var s = Console.ReadLine();
var t = Console.ReadLine();
char[] S = s.ToArray();
char[] T = t.ToArray();
Array.Sort(S);
Array.Sort(T);Array.Reverse(T);
string ss = new string(S);
string ts = new string(T);
if (ss.CompareTo(ts) < 0)
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}*/
// sに関してソート
/*for (int i = 0; i < s.Length; i++)
{
}*/
// var hoge = s.OrderByDescending((x) => x.Value);
/*List<int> array = new List<int>();
int[] rank = new int[s.Length];
for (int i = 0; i < s.Length; i++)
{
rank[i] = 0;
}
for (int i = 0; i < s.Length; i++)
{
for (int j = 0; j < s.Length; j++)
{
if (s[i] > s[j])
{
rank[i]++;
}
}
}
for (int i=0;i<s.Length;i++)
{
for (int j =0;j<s.Length;j++)
{
if (i == rank[j])
{
array.Add(s[i]);
}
}
}
for (int i = 0; i < s.Length; i++)
{
Console.Write(array[i]);
}
}*/
/*static void Main()
{
int count;
int temp = 0;
var N = int.Parse(Console.ReadLine());
List<int> aa = new List<int>();
for (int i = 1; i <= N; i++)
{
count = 0;
temp = i;
while (true)
{
var Ans = temp / 2;
var Ans2 = temp % 2;
if (Ans2 == 0)
{
count++;
temp = Ans;
}
else
{
break;
}
}
aa.Add(count);
}
//Program program = new Program();
//program.Max(aa, temp);
var max = aa.IndexOf(aa.Max());
Console.WriteLine(max+1);
}
public void Max(List<int> array,int num)
{
var Ans3 = array.Max();
}*/
/*static void Main()
{
List<int> array = new List<int>();
var N = Console.ReadLine();
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0;i<A.Length;i++)
{
for (int j = 0; j< A.Length; j++)
{
var ans = A[i] - A[j];
if (ans < 0)
{
ans = Math.Abs(ans);
}
//Console.Write(ans);
array.Add(ans);
}
//Console.WriteLine();
}
Console.WriteLine(array.Max());
}*/
/*static void Main()
{
var N = Console.ReadLine();
int[] temperture = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] height = Console.ReadLine().Split().Select(int.Parse).ToArray();
int T = temperture[0];
int A = temperture[1];
List<double> aa = new List<double>();
List<double> bb = new List<double>();
for (int i = 0;i<height.Length;i++)
{
var temp = T - height[i] * 0.006;
aa.Add(temp);
}
for (int i =0;i<height.Length;i++)
{
var temp = A - aa[i];
if (temp < 0)
{
temp = Math.Abs(temp);
}
bb.Add(temp);
}
Console.WriteLine(bb.IndexOf(bb.Min())+1);
}*/
/*static void Main()
{
string a = Console.ReadLine();
char[] charArray = a.ToArray();
List<char> aa = new List<char>();
for (int i = 0;i<charArray.Length;i++)
{
if ((i+1)%2 == 1)
{
aa.Add(charArray[i]);
}
}
var str = string.Join("",aa);
Console.WriteLine(str);
}*/
// 053B
/*static void Main()
{
var str = Console.ReadLine();
var start = str.IndexOf("A");
var goal = str.IndexOf("Z",start);
string temp = new string(str.Substring(goal).ToArray());
int goalpoint = 0;
List<int> kk = new List<int>();
while (true)
{
if (temp.Contains("Z"))
{
goalpoint = temp.IndexOf("Z") +1;
temp = temp.Replace("Z", "");
}
if (temp.Contains("Z") == false)
{
break;
}
if(temp.Contains("Z"))
{
Console.WriteLine();
}
}
for (int i = 0;i<temp.Length;i++)
{
if (temp[i] == 'Z')
{
goalpoint = i;
}
}
var ans = str.Substring(start, goal-start).Length + 1 + goalpoint;
Console.WriteLine(ans);
}*/
// 095B
/*static void Main()
{
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = a[0];
int X = a[1];
List<int> listarray = new List<int>();
int Ans = 0;
for (int i =0;i < N;i++)
{
var temp = Console.ReadLine();
int temp1 = int.Parse(temp);
listarray.Add(temp1);
}
for (int i =0;i< N;i++)
{
X = X - listarray[i];
if (X >= 0)
{
Ans++;
}
}
if (X > 0)
{
while (true)
{
X = X - listarray.Min();
if (X < 0)
{
break;
}
Ans++;
}
}
Console.WriteLine(Ans);
}*/
// 105B
/*static void Main()
{
int dunats = 7;
int cake = 4;
int sum = 0;
bool flag = false;
int N = int.Parse(Console.ReadLine());
if (N > 3)
{
for (int i = 0; i <= N / cake; i++)
{
for (int j=0; j<=N/dunats;j++)
{
sum = dunats * j + cake * i;
if (sum == N) {
flag = true;
}
if (flag == true)
{
break;
}
}
if (flag == true)
{
break;
}
}
}
if (flag == true) { Console.WriteLine("Yes"); }
else { Console.WriteLine("No"); }
}*/
// 004A
/*static void Main()
{
List<double> Ans = new List<double>();
List<int[]> array = new List<int[]>();
int N = int.Parse(Console.ReadLine());
for (int i = 0; i < N; i++)
{
int[] aa = Console.ReadLine().Split().Select(int.Parse).ToArray();
array.Add(aa);
}
for (int i=0;i<N;i++)
{
for (int j = 0;j<N;j++)
{
var X = array[i][0] - array[j][0];
var Y = array[i][1] - array[j][1];
var resultX = Math.Pow(X, 2);
var resultY = Math.Pow(Y, 2);
var ans = Math.Sqrt(resultX + resultY);
Ans.Add(ans);
}
}
var finalresult = Ans.Max();
Console.WriteLine(finalresult);
}*/
// 51B
static void Main() {
int count = 0;
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int K = input[0];
int S = input[1];
for (int x = 0; x <= K; x++) {
for (int y = 0; y <= K; y++) {
/*for (int z = 0; z <= K; z++)
{
var ans = x + y + z;
if (ans == S)
{
count++;
}
}*/
var z = S - x - y;
if (0 <= z || z <= K) {
count++;
}
}
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace AIZUproject07 {
class Program {
// static string T;
/*static void Main()
{
int count = 0;
bool flag = false;
string In = Console.ReadLine();
string[] s = Console.ReadLine().Split();
int[] aa = s.Select(int.Parse).ToArray();
while (true)
{
for (int i = 0; i < aa.Length; i++)
{
if (aa[i] % 2 != 0)
{
flag = true;
}
}
aa = aa.Select(n => n / 2).ToArray();
if (flag == true) break;
count++;
}
Console.WriteLine(count);
}*/
/*static void Main()
{
int sum = 0;
int count = 0;
string A = Console.ReadLine();
string B = Console.ReadLine();
string C = Console.ReadLine();
string D = Console.ReadLine();
int AA = int.Parse(A);
int BB = int.Parse(B);
int CC = int.Parse(C);
int DD = int.Parse(D);
for(int i = 0;i<=AA;i++)
{
for (int j=0;j<=BB;j++)
{
for (int k =0;k<=CC;k++)
{
sum = i * 500 + j * 100 + k * 50;
if (sum == DD) count++;
}
}
}
Console.WriteLine(count);
}*/
/*static void Main()
{
int ans1 = 0;
int ans2 = 0;
string[] s = Console.ReadLine().Split();
int[] intArray = s.Select(int.Parse).ToArray();
for (int i = 1;i<=intArray[0];i++)
{
ans1 = 0;
if (i >= 10 && i <100)
{
var aaa = i % 10;
var bbb = i / 10;
ans1 = aaa + bbb;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
if (i >= 100 && i<1000)
{
var aaa = i % 10;
var bbb = i / 10;
var ccc = bbb % 10;
var ddd = bbb / 10;
ans1 = aaa + ccc + ddd;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
if (i >= 1000 && i <10000)
{
var aaa = i % 10;//4
var bbb = i / 10;
var ccc = bbb % 10;//3
var ddd = bbb / 10;
var eee = ddd % 10;//2
var fff = ddd / 10;//1
ans1 = aaa + ccc + eee + fff;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
if (i == 10000)
{
ans1 = 1;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
if (i < 10)
{
ans1 = i;
if (intArray[1] <= ans1 && ans1 <= intArray[2])
{
ans2 += i;
}
}
}
Console.WriteLine(ans2);
}*/
/*static void Main()
{
int sum = 0;
bool test = false;
string[] aa = Console.ReadLine().Split();
int N = int.Parse(aa[0]);
int Y = int.Parse(aa[1]);
int Yukichi = Y / 10000;
int Ichiyo = Y / 5000;
int Hideyo = Y / 1000;
int x = 0;
int y = 0;
int z = 0;
for (int i = 0;i<=Yukichi;i++)
{
for (int j =0;j<=Ichiyo;j++)
{
for (int k =0;k<=Hideyo;k++)
{
sum = 10000 * i + 5000 * j + 1000 * k;
if (sum == Y && i+j+k < N)
{
x = i;
y = j;
z = k;
//Console.WriteLine(i + " " + j + " " + k);
test = true;
}
}
}
}
if (test == true)
{
Console.WriteLine(x + " " + y + " " + z);
}
if (test == false)
{
Console.WriteLine("-1 -1 -1");
}
}*/
/*static void Main()
{
string[] aa = Console.ReadLine().Split();
int N = int.Parse(aa[0]);
int Y = int.Parse(aa[1]);
int X = 0;
int Z = 0;
int b = 0;
int d = 0;
X = Y / 10000;
var a = Y - (X*10000);
if (a != 0 || Y < 10000)
{
b = a / 5000;
var cc = a - (b * 5000);
if (cc != 0 || a < 5000)
{
d = cc / 1000;
var gg = cc - (d * 1000);
if (gg != 0 || cc<1000)
{
Console.WriteLine("-1 -1 -1");
}
else if (X + b + d <= N)
{
Console.WriteLine(X + " " + b + " " + d);
}
else if (X + b + d > N)
{
Console.WriteLine("-1 -1 -1");
}
}
else if (X + b <= N)
{
Console.WriteLine(X +" "+ b +" "+"0");
}
else if (X + b > N)
{
Console.WriteLine("-1 -1 -1");
}
}
else if (X <= N)
{
Console.WriteLine(X +" "+0+" "+0);
}
else if (X>N)
{
Console.WriteLine("-1 -1 -1");
}
}*/
/*static void Main()
{
string s = Console.ReadLine();
var Ans = s.Replace("eraser", "").Replace("dreamer",
"").Replace("dreamer", "").Replace("erase", "").ToString(); if (Ans == null)
Console.WriteLine("YES"); else Console.WriteLine("NO");*/
// List<string> str = new List<string>(); || s.Substring(5, 1) == ""
// string NN = new string(s); || s.Substring(5,1) == ""
/*while (true) {
while (true)
{
if (s.StartsWith("dream") && (s.Substring(5,2) != "er" ))
{
count++;
var f = s.Remove(0, 5);
s = f;
break;
}
if (s.StartsWith("dreamer"))
{
var n = s.Remove(0, 7);
s = n;
break;
}
if (s.StartsWith("erase") || (s.Substring(5,1) != "r" ))
{
count2++;
var f1 = s.Remove(0, 5);
s = f1;
break;
}
if (s.StartsWith("eraser"))
{
var f2 = s.Remove(0, 6);
s = f2;
break;
}
else
{
tt = true;
break;
}
}
if (s.Length == 0)
{
Console.WriteLine("YES");
break;
}
if (tt)
{
Console.WriteLine("NO");
break;
}
}*/
// Console.WriteLine(count+","+count2);
//}
// 86C
/*static void Main()
{
/*string aa = Console.ReadLine();
List<int[]> nn = new List<int[]>();
for (int i = 0;i<aa.Length;i++)
{
string[] str = Console.ReadLine().Split();
int[] intstr = str.Select(int.Parse).ToArray();
nn.Add(intstr);
}
var a1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
var num = a1[0];
var list = new List<int[]>(num);
for (int i=0;i<num;i++)
{
}
}*/
/*static void Main(string[] args)
{
var input = Console.ReadLine().Split(' ');
var array = input.Select(int.Parse).ToArray();
int num = array[0] * 100 + array[1] * 10 + array[2] * 1;
if (num % 4 == 0)
{
Console.WriteLine("YES");
}
else
{
Console.WriteLine("NO");
}
}*/
/*static void Main()
{
var input = Console.ReadLine();
var a = Console.ReadLine();
int N = int.Parse(input);
int A = int.Parse(a);
bool flag = false;
for (int i = 0;i <= A;i++ )
{
var Ans = N - i;
if (Ans % 500 == 0)
{
Console.WriteLine("Yes");
flag = true;
break;
}
}
if (flag == false)
{
Console.WriteLine("No");
}
}*/
/*static void Main()
{
var a = Console.ReadLine().Split();
double[] integer = a.Select(double.Parse).ToArray();
double ans = (integer[0] + integer[1]) / 2;
Console.WriteLine(Math.Ceiling(ans));
}*/
/*static void Main()
{
int count = 0;
string str = Console.ReadLine();
//var cross = str.Select(n => n != '×');
//var circle = str.Select(n => n != 'o');
//Console.WriteLine(cross);
//Console.WriteLine(circle);
/*Console.WriteLine(str.Length);
while (true)
{
Match match1 = Regex.Match(str, "o");
if (match1 != null)
{
count++;
}
str = str.Substring(match1.Index+1, str.Length);
if (match1.Index == str.Length)
{
break;
}
}
var Ans = 700 + count * 100;
Console.WriteLine(Ans);*/
// Console.WriteLine(match.Value);
/*or (int i =0;i<str.Length;i++)
{
if (Regex.Match(str[i], "o"))
{
}
}
count = str.Length - str.Replace("o", "").Length;
var Ans = 700 + count * 100;
Console.WriteLine(Ans);
}*/
/*static void Main()
{
var str = Console.ReadLine();
var Ans = str.Replace("2017","2018");
Console.WriteLine(Ans);
}*/
/*static void Main()
{
var str = Console.ReadLine();
//str.Substring(0, 1) +
Console.WriteLine(str.Substring(0, 1) + (str.Length-2) +
str.Substring(str.Length-1));
}*/
// 82B
/*static void Main()
{
var s = Console.ReadLine();
var t = Console.ReadLine();
char[] S = s.ToArray();
char[] T = t.ToArray();
Array.Sort(S);
Array.Sort(T);Array.Reverse(T);
string ss = new string(S);
string ts = new string(T);
if (ss.CompareTo(ts) < 0)
{
Console.WriteLine("Yes");
}
else
{
Console.WriteLine("No");
}*/
// sに関してソート
/*for (int i = 0; i < s.Length; i++)
{
}*/
// var hoge = s.OrderByDescending((x) => x.Value);
/*List<int> array = new List<int>();
int[] rank = new int[s.Length];
for (int i = 0; i < s.Length; i++)
{
rank[i] = 0;
}
for (int i = 0; i < s.Length; i++)
{
for (int j = 0; j < s.Length; j++)
{
if (s[i] > s[j])
{
rank[i]++;
}
}
}
for (int i=0;i<s.Length;i++)
{
for (int j =0;j<s.Length;j++)
{
if (i == rank[j])
{
array.Add(s[i]);
}
}
}
for (int i = 0; i < s.Length; i++)
{
Console.Write(array[i]);
}
}*/
/*static void Main()
{
int count;
int temp = 0;
var N = int.Parse(Console.ReadLine());
List<int> aa = new List<int>();
for (int i = 1; i <= N; i++)
{
count = 0;
temp = i;
while (true)
{
var Ans = temp / 2;
var Ans2 = temp % 2;
if (Ans2 == 0)
{
count++;
temp = Ans;
}
else
{
break;
}
}
aa.Add(count);
}
//Program program = new Program();
//program.Max(aa, temp);
var max = aa.IndexOf(aa.Max());
Console.WriteLine(max+1);
}
public void Max(List<int> array,int num)
{
var Ans3 = array.Max();
}*/
/*static void Main()
{
List<int> array = new List<int>();
var N = Console.ReadLine();
int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
for (int i = 0;i<A.Length;i++)
{
for (int j = 0; j< A.Length; j++)
{
var ans = A[i] - A[j];
if (ans < 0)
{
ans = Math.Abs(ans);
}
//Console.Write(ans);
array.Add(ans);
}
//Console.WriteLine();
}
Console.WriteLine(array.Max());
}*/
/*static void Main()
{
var N = Console.ReadLine();
int[] temperture = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] height = Console.ReadLine().Split().Select(int.Parse).ToArray();
int T = temperture[0];
int A = temperture[1];
List<double> aa = new List<double>();
List<double> bb = new List<double>();
for (int i = 0;i<height.Length;i++)
{
var temp = T - height[i] * 0.006;
aa.Add(temp);
}
for (int i =0;i<height.Length;i++)
{
var temp = A - aa[i];
if (temp < 0)
{
temp = Math.Abs(temp);
}
bb.Add(temp);
}
Console.WriteLine(bb.IndexOf(bb.Min())+1);
}*/
/*static void Main()
{
string a = Console.ReadLine();
char[] charArray = a.ToArray();
List<char> aa = new List<char>();
for (int i = 0;i<charArray.Length;i++)
{
if ((i+1)%2 == 1)
{
aa.Add(charArray[i]);
}
}
var str = string.Join("",aa);
Console.WriteLine(str);
}*/
// 053B
/*static void Main()
{
var str = Console.ReadLine();
var start = str.IndexOf("A");
var goal = str.IndexOf("Z",start);
string temp = new string(str.Substring(goal).ToArray());
int goalpoint = 0;
List<int> kk = new List<int>();
while (true)
{
if (temp.Contains("Z"))
{
goalpoint = temp.IndexOf("Z") +1;
temp = temp.Replace("Z", "");
}
if (temp.Contains("Z") == false)
{
break;
}
if(temp.Contains("Z"))
{
Console.WriteLine();
}
}
for (int i = 0;i<temp.Length;i++)
{
if (temp[i] == 'Z')
{
goalpoint = i;
}
}
var ans = str.Substring(start, goal-start).Length + 1 + goalpoint;
Console.WriteLine(ans);
}*/
// 095B
/*static void Main()
{
var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = a[0];
int X = a[1];
List<int> listarray = new List<int>();
int Ans = 0;
for (int i =0;i < N;i++)
{
var temp = Console.ReadLine();
int temp1 = int.Parse(temp);
listarray.Add(temp1);
}
for (int i =0;i< N;i++)
{
X = X - listarray[i];
if (X >= 0)
{
Ans++;
}
}
if (X > 0)
{
while (true)
{
X = X - listarray.Min();
if (X < 0)
{
break;
}
Ans++;
}
}
Console.WriteLine(Ans);
}*/
// 105B
/*static void Main()
{
int dunats = 7;
int cake = 4;
int sum = 0;
bool flag = false;
int N = int.Parse(Console.ReadLine());
if (N > 3)
{
for (int i = 0; i <= N / cake; i++)
{
for (int j=0; j<=N/dunats;j++)
{
sum = dunats * j + cake * i;
if (sum == N) {
flag = true;
}
if (flag == true)
{
break;
}
}
if (flag == true)
{
break;
}
}
}
if (flag == true) { Console.WriteLine("Yes"); }
else { Console.WriteLine("No"); }
}*/
// 004A
/*static void Main()
{
List<double> Ans = new List<double>();
List<int[]> array = new List<int[]>();
int N = int.Parse(Console.ReadLine());
for (int i = 0; i < N; i++)
{
int[] aa = Console.ReadLine().Split().Select(int.Parse).ToArray();
array.Add(aa);
}
for (int i=0;i<N;i++)
{
for (int j = 0;j<N;j++)
{
var X = array[i][0] - array[j][0];
var Y = array[i][1] - array[j][1];
var resultX = Math.Pow(X, 2);
var resultY = Math.Pow(Y, 2);
var ans = Math.Sqrt(resultX + resultY);
Ans.Add(ans);
}
}
var finalresult = Ans.Max();
Console.WriteLine(finalresult);
}*/
// 51B
static void Main() {
int count = 0;
int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int K = input[0];
int S = input[1];
for (int x = 0; x <= K; x++) {
for (int y = 0; y <= K; y++) {
/*for (int z = 0; z <= K; z++)
{
var ans = x + y + z;
if (ans == S)
{
count++;
}
}*/
var z = S - x - y;
if (0 <= z && z <= K) {
count++;
}
}
}
Console.WriteLine(count);
}
}
}
|
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 201
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
// 0<=x,y,z<=K
// X+Y+Z=S
var Array = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int K = Array[0];
int S = Array[1];
int Count = 0;
int z = 0;
for (int x = 0; x <= K; x++) {
for (int y = 0; y <= K; y++) {
z = K - (x + y);
if (0 <= z && z <= K)
Count++;
}
}
Console.WriteLine(Count);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
// 0<=x,y,z<=K
// X+Y+Z=S
var Array = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
int K = Array[0];
int S = Array[1];
int Count = 0;
int z = 0;
for (int x = 0; x <= K; x++) {
for (int y = 0; y <= K; y++) {
z = S - (x + y);
if (0 <= z && z <= K)
Count++;
}
}
Console.WriteLine(Count);
}
}
|
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22]]
| 8
| 149
| 2
|
using System;
using System.Collections.Generic;
// using System.Linq;
class Program {
// static List<string> list;
static void Main(string[] args) {
// 入力フェーズ
string[] input = Console.ReadLine().Split(' ');
int K = int.Parse(input[0]);
int S = int.Parse(input[1]);
long pattern = 0;
for (int x = 0; x <= Math.Min(S, K); x++) {
// x = ?の場合、Y+Z=S-x
if (S - x - K > K)
continue; // 組が作れない
// x = ?の場合、Y+Z=Tを作りたいとして、min(T,K)から1になるまで...
int T = S - x;
if (T <= K) {
// T通り作れる
pattern += T;
} else {
// (T-K) + K → T-2K + 0までのうち、左側の項 <= Kのだけ作れる
pattern += Math.Max(2 * K - T + 1, 0); // 0未満だと作れない
}
}
// 出力
Console.WriteLine(pattern);
}
class myClass { //自作クラス
public int ID { set; get; }
public long Point { set; get; }
}
}
|
using System;
using System.Collections.Generic;
// using System.Linq;
class Program {
// static List<string> list;
static void Main(string[] args) {
// 入力フェーズ
string[] input = Console.ReadLine().Split(' ');
int K = int.Parse(input[0]);
int S = int.Parse(input[1]);
long pattern = 0;
for (int x = 0; x <= Math.Min(S, K); x++) {
// x = ?の場合、Y+Z=S-x
if (S - x - K > K)
continue; // 組が作れない
// x = ?の場合、Y+Z=Tを作りたいとして、min(T,K)から0になるまで...
int T = S - x;
if (T <= K) {
// T通り作れる
pattern += T + 1;
} else {
// (T-K) + K → T-2K + 0までのうち、左側の項 <= Kのだけ作れる
pattern += Math.Max(2 * K - T + 1, 0); // 0未満だと作れない
}
}
// 出力
Console.WriteLine(pattern);
}
class myClass { //自作クラス
public int ID { set; get; }
public long Point { set; get; }
}
}
|
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
| 8
| 188
| 2
|
using System;
namespace AtCoder {
class B_SumofThreeIntegers_051 {
public static void Main() {
string[] input = Console.ReadLine().Split(' ');
var K = int.Parse(input[0]);
var S = int.Parse(input[1]);
var count = 0;
for (var x = 0; x <= K; ++x) {
if (S < x) {
break;
}
for (var y = 0; y <= K; ++y) {
if (S < x + y) {
break;
}
var z = S - x - y;
if (z <= 0 && z <= K) {
++count;
}
}
}
Console.WriteLine(count);
}
}
}
|
using System;
namespace AtCoder {
class B_SumofThreeIntegers_051 {
public static void Main() {
string[] input = Console.ReadLine().Split(' ');
var K = int.Parse(input[0]);
var S = int.Parse(input[1]);
var count = 0;
for (var x = 0; x <= K; ++x) {
if (S < x) {
break;
}
for (var y = 0; y <= K; ++y) {
if (S < x + y) {
break;
}
var z = S - x - y;
if (0 <= z && z <= K) {
++count;
}
}
}
Console.WriteLine(count);
}
}
}
|
[["-", 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, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22]]
| 8
| 153
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
var input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var counter = 0;
for (int i = 0; i <= input[0]; i++) {
for (int j = 0; j <= input[0]; j++) {
var z = input[1] - i - j;
if (0 <= z && z <= input[1])
counter++;
}
}
Console.WriteLine(counter);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4 {
class Program {
static void Main(string[] args) {
var input =
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
var counter = 0;
for (int i = 0; i <= input[0]; i++) {
for (int j = 0; j <= input[0]; j++) {
var z = input[1] - i - j;
if (0 <= z && z <= input[0])
counter++;
}
}
Console.WriteLine(counter);
}
}
}
|
[["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 156
| 2
|
using System;
using System.Linq;
public class Program {
public static void Main() {
var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var K = list[0];
var S = list[1];
var ans = 0;
for (int x = 0; x <= K; x++) {
for (int y = 0; y <= K; y++) {
int z = S - x - y;
if (z <= 0 && z <= K)
ans++;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
public class Program {
public static void Main() {
var list = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
var K = list[0];
var S = list[1];
var ans = 0;
for (int x = 0; x <= K; x++) {
for (int y = 0; y <= K; y++) {
int z = S - x - y;
if (0 <= z && z <= K)
ans++;
}
}
Console.WriteLine(ans);
}
}
|
[["-", 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, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22]]
| 8
| 135
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
// using Point = System.Numerics.Complex;
using Number = System.Int64;
namespace Program {
public class Solver {
public void Solve() {
var k = sc.Integer();
var s = sc.Integer();
var ans = 0;
for (int i = 0; i <= k; i++)
for (int j = 0; j <= k; j++)
if (i + j <= s && i + j + k <= s)
ans++;
IO.Printer.Out.WriteLine(ans);
}
ModInteger f(long k) {
var mat = new Matrix(2, 2);
mat[0, 0] = mat[0, 1] = 1;
mat[1, 0] = 1;
var ret = Matrix.Pow(mat, k);
return ret[0, 0] + ret[0, 1];
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
// static public string AsString(this IEnumerable<char> ie) { return new
// string(System.Linq.Enumerable.ToArray(ie)); } static public string
// AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return
// string.Join(st, ie); }
static public void Main() {
var solver = new Program.Solver();
solver.Solve();
Program.IO.Printer.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
static Printer() {
Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
}
public static Printer Out { get; set; }
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture)
: double.NaN;
}
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 char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
}
#endregion
#region Matrix
public class Matrix {
int row, col;
public Number[] mat;
public Number this[int r, int c] {
get { return mat[r * col + c]; }
set { mat[r * col + c] = value; }
}
public Matrix(int r, int c) {
row = r;
col = c;
mat = new Number[row * col];
}
public static Matrix operator +(Matrix l, Matrix r) {
check(l, r);
var ret = new Matrix(l.row, l.col);
for (int i = 0; i < l.row; i++)
for (int j = 0; j < l.col; j++)
ret.mat[i * ret.col + j] = l.mat[i * l.col + j] + r.mat[i * r.col + j];
return ret;
}
public static Matrix operator *(Matrix l, Matrix r) {
checkMul(l, r);
var ret = new Matrix(l.row, r.col);
for (int i = 0; i < l.row; i++)
for (int k = 0; k < l.col; k++)
for (int j = 0; j < r.col; j++)
ret.mat[i * r.col + j] =
(ret.mat[i * r.col + j] +
l.mat[i * l.col + k] * r.mat[k * r.col + j]);
return ret;
}
public static Matrix Pow(Matrix m, long n) {
var ret = new Matrix(m.row, m.col);
for (int i = 0; i < m.row; i++)
ret.mat[i * m.col + i] = 1;
for (; n > 0; m *= m, n >>= 1)
if ((n & 1) == 1)
ret = ret * m;
return ret;
}
public static Matrix[] PowTable(Matrix m, int k) {
var ret = new Matrix[k];
ret[0] = m;
for (int i = 1; i < k; i++)
ret[i] = ret[i - 1] * ret[i - 1];
return ret;
}
public static Matrix PowWithTable(Matrix m, long n, Matrix[] table) {
var ret = new Matrix(m.row, m.col);
for (int i = 0; i < m.row; i++)
ret.mat[i * m.col + i] = 1;
for (int i = 0; i < table.Length; i++) {
if ((n & 1) == 1)
ret = ret * table[i];
}
return ret;
}
public static Matrix Trans(Matrix m) {
var ret = new Matrix(m.col, m.row);
for (int i = 0; i < m.row; i++)
for (int j = 0; j < m.col; j++)
ret.mat[j * m.col + i] = m.mat[i * m.col + j];
return ret;
}
[System.Diagnostics.Conditional("DEBUG")]
static private void check(Matrix a, Matrix b) {
if (a.row != b.row || a.col != b.col)
throw new Exception("row and col have to be same.");
}
[System.Diagnostics.Conditional("DEBUG")]
static private void checkMul(Matrix a, Matrix b) {
if (a.col != b.row)
throw new Exception("row and col have to be same.");
}
public Number[][] Items {
get {
var a = new Number[row][];
for (int i = 0; i < row; i++) {
a[i] = new Number[col];
for (int j = 0; j < col; j++)
a[i][j] = mat[i * col + j];
}
return a;
}
}
public override string ToString() {
return string.Format("{0}*{1}", row, col);
}
}
#endregion
#region ModNumber
public partial struct ModInteger {
public const long Mod = (long)1e9 + 7;
public long num;
public ModInteger(long n) : this() {
num = n % Mod;
if (num < 0)
num += Mod;
}
public override string ToString() { return num.ToString(); }
public static ModInteger operator +(ModInteger l, ModInteger r) {
var n = l.num + r.num;
if (n >= Mod)
n -= Mod;
return new ModInteger() { num = n };
}
public static ModInteger operator -(ModInteger l, ModInteger r) {
var n = l.num + Mod - r.num;
if (n >= Mod)
n -= Mod;
return new ModInteger() { num = n };
}
public static ModInteger operator *(ModInteger l, ModInteger r) {
return new ModInteger(l.num * r.num);
}
public static ModInteger operator ^(ModInteger l, long r) {
return ModInteger.Pow(l, r);
}
public static implicit operator ModInteger(long n) {
return new ModInteger() { num = n };
}
public static ModInteger Pow(ModInteger v, long k) {
ModInteger ret = 1;
var n = k;
for (; n > 0; n >>= 1, v *= v) {
if ((n & 1) == 1)
ret = ret * v;
}
return ret;
}
}
#endregion
|
using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
// using Point = System.Numerics.Complex;
using Number = System.Int64;
namespace Program {
public class Solver {
public void Solve() {
var k = sc.Integer();
var s = sc.Long();
var ans = 0L;
for (int i = 0; i <= k; i++)
for (int j = 0; j <= k; j++)
if (i + j <= s && i + j + k >= s)
ans++;
IO.Printer.Out.WriteLine(ans);
}
ModInteger f(long k) {
var mat = new Matrix(2, 2);
mat[0, 0] = mat[0, 1] = 1;
mat[1, 0] = 1;
var ret = Matrix.Pow(mat, k);
return ret[0, 0] + ret[0, 1];
}
public IO.StreamScanner sc =
new IO.StreamScanner(Console.OpenStandardInput());
static T[] Enumerate<T>(int n, Func<int, T> f) {
var a = new T[n];
for (int i = 0; i < n; ++i)
a[i] = f(i);
return a;
}
static public void Swap<T>(ref T a, ref T b) {
var tmp = a;
a = b;
b = tmp;
}
}
}
#region main
static class Ex {
// static public string AsString(this IEnumerable<char> ie) { return new
// string(System.Linq.Enumerable.ToArray(ie)); } static public string
// AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return
// string.Join(st, ie); }
static public void Main() {
var solver = new Program.Solver();
solver.Solve();
Program.IO.Printer.Out.Flush();
}
}
#endregion
#region Ex
namespace Program.IO {
using System.IO;
using System.Text;
using System.Globalization;
public class Printer : StreamWriter {
static Printer() {
Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
}
public static Printer Out { get; set; }
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(System.IO.Stream stream)
: base(stream, new UTF8Encoding(false, true)) {}
public Printer(System.IO.Stream stream, Encoding encoding)
: base(stream, encoding) {}
public void Write<T>(string format, T[] source) {
base.Write(format, source.OfType<object>().ToArray());
}
public void WriteLine<T>(string format, T[] source) {
base.WriteLine(format, source.OfType<object>().ToArray());
}
}
public class StreamScanner {
public StreamScanner(Stream stream) { str = stream; }
public readonly Stream str;
private readonly byte[] buf = new byte[1024];
private int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
private byte read() {
if (isEof)
return 0;
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
public char Char() {
byte b = 0;
do
b = read();
while ((b < 33 || 126 < b) && !isEof);
return (char)b;
}
public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
public string ScanLine() {
var sb = new StringBuilder();
for (var b = Char(); b != '\n'; b = (char)read())
if (b == 0)
break;
else if (b != '\r')
sb.Append(b);
return sb.ToString();
}
public long Long() {
if (isEof)
return long.MinValue;
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != 0 && b != '-' && (b < '0' || '9' < b));
if (b == 0)
return long.MinValue;
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
public double Double() {
var s = Scan();
return s != "" ? double.Parse(s, CultureInfo.InvariantCulture)
: double.NaN;
}
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 char[] Char(int n) { return enumerate(n, Char); }
public string[] Scan(int n) { return enumerate(n, Scan); }
public double[] Double(int n) { return enumerate(n, Double); }
public int[] Integer(int n) { return enumerate(n, Integer); }
public long[] Long(int n) { return enumerate(n, Long); }
}
}
#endregion
#region Matrix
public class Matrix {
int row, col;
public Number[] mat;
public Number this[int r, int c] {
get { return mat[r * col + c]; }
set { mat[r * col + c] = value; }
}
public Matrix(int r, int c) {
row = r;
col = c;
mat = new Number[row * col];
}
public static Matrix operator +(Matrix l, Matrix r) {
check(l, r);
var ret = new Matrix(l.row, l.col);
for (int i = 0; i < l.row; i++)
for (int j = 0; j < l.col; j++)
ret.mat[i * ret.col + j] = l.mat[i * l.col + j] + r.mat[i * r.col + j];
return ret;
}
public static Matrix operator *(Matrix l, Matrix r) {
checkMul(l, r);
var ret = new Matrix(l.row, r.col);
for (int i = 0; i < l.row; i++)
for (int k = 0; k < l.col; k++)
for (int j = 0; j < r.col; j++)
ret.mat[i * r.col + j] =
(ret.mat[i * r.col + j] +
l.mat[i * l.col + k] * r.mat[k * r.col + j]);
return ret;
}
public static Matrix Pow(Matrix m, long n) {
var ret = new Matrix(m.row, m.col);
for (int i = 0; i < m.row; i++)
ret.mat[i * m.col + i] = 1;
for (; n > 0; m *= m, n >>= 1)
if ((n & 1) == 1)
ret = ret * m;
return ret;
}
public static Matrix[] PowTable(Matrix m, int k) {
var ret = new Matrix[k];
ret[0] = m;
for (int i = 1; i < k; i++)
ret[i] = ret[i - 1] * ret[i - 1];
return ret;
}
public static Matrix PowWithTable(Matrix m, long n, Matrix[] table) {
var ret = new Matrix(m.row, m.col);
for (int i = 0; i < m.row; i++)
ret.mat[i * m.col + i] = 1;
for (int i = 0; i < table.Length; i++) {
if ((n & 1) == 1)
ret = ret * table[i];
}
return ret;
}
public static Matrix Trans(Matrix m) {
var ret = new Matrix(m.col, m.row);
for (int i = 0; i < m.row; i++)
for (int j = 0; j < m.col; j++)
ret.mat[j * m.col + i] = m.mat[i * m.col + j];
return ret;
}
[System.Diagnostics.Conditional("DEBUG")]
static private void check(Matrix a, Matrix b) {
if (a.row != b.row || a.col != b.col)
throw new Exception("row and col have to be same.");
}
[System.Diagnostics.Conditional("DEBUG")]
static private void checkMul(Matrix a, Matrix b) {
if (a.col != b.row)
throw new Exception("row and col have to be same.");
}
public Number[][] Items {
get {
var a = new Number[row][];
for (int i = 0; i < row; i++) {
a[i] = new Number[col];
for (int j = 0; j < col; j++)
a[i][j] = mat[i * col + j];
}
return a;
}
}
public override string ToString() {
return string.Format("{0}*{1}", row, col);
}
}
#endregion
#region ModNumber
public partial struct ModInteger {
public const long Mod = (long)1e9 + 7;
public long num;
public ModInteger(long n) : this() {
num = n % Mod;
if (num < 0)
num += Mod;
}
public override string ToString() { return num.ToString(); }
public static ModInteger operator +(ModInteger l, ModInteger r) {
var n = l.num + r.num;
if (n >= Mod)
n -= Mod;
return new ModInteger() { num = n };
}
public static ModInteger operator -(ModInteger l, ModInteger r) {
var n = l.num + Mod - r.num;
if (n >= Mod)
n -= Mod;
return new ModInteger() { num = n };
}
public static ModInteger operator *(ModInteger l, ModInteger r) {
return new ModInteger(l.num * r.num);
}
public static ModInteger operator ^(ModInteger l, long r) {
return ModInteger.Pow(l, r);
}
public static implicit operator ModInteger(long n) {
return new ModInteger() { num = n };
}
public static ModInteger Pow(ModInteger v, long k) {
ModInteger ret = 1;
var n = k;
for (; n > 0; n >>= 1, v *= v) {
if ((n & 1) == 1)
ret = ret * v;
}
return ret;
}
}
#endregion
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 7, 8, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 7, 8, 57, 15, 16, 12, 16, 17, 20]]
| 8
| 2,397
| 6
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC051D_2 {
class Program {
static void Main(string[] args) {
var N = RInt;
var M = RInt;
WarshallFloyd wf = new WarshallFloyd(N);
Edge[] edges = new Edge[M];
for (int i = 0; i < M; i++) {
var a = RInt - 1;
var b = RInt - 1;
var c = RInt;
wf.AddEdge(a, b, c);
wf.AddEdge(b, a, c);
edges[i] = new Edge { f = a, t = b, c = c };
}
bool negative = false;
var d = wf.Start(out negative);
Draw2D(d);
int ans = 0;
foreach (var e in edges) {
bool contain = false;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (d[i, j] == d[i, e.t] + e.c + d[e.f, j])
contain = true;
}
}
if (contain)
ans++;
}
Console.WriteLine(ans);
}
struct Edge {
public int f;
public int t;
public int c;
}
}
/// <summary>
/// 全頂点間距離 負の辺に対応、O(V^3)
/// </summary>
class WarshallFloyd {
long INF = long.MaxValue;
int _v;
long[,] dp;
public WarshallFloyd(int V) {
_v = V;
dp = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (i != j)
dp[i, j] = INF;
}
}
}
public void AddEdge(int from, int to, long cost) { dp[from, to] = cost; }
public long[,] Start(out bool negativeCycle) {
negativeCycle = false;
for (int k = 0; k < _v; k++) {
for (int i = 0; i < _v; i++) {
for (int j = 0; j < _v; j++) {
if (dp[i, k] == long.MaxValue || dp[k, j] == long.MaxValue)
continue;
dp[i, j] = Math.Min(dp[i, j], dp[i, k] + dp[k, j]);
}
if (dp[i, i] < 0)
negativeCycle = true;
}
}
return dp;
}
public long Distance(int from, int to) { return dp[from, to]; }
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
namespace ABC051D_2 {
class Program {
static void Main(string[] args) {
var N = RInt;
var M = RInt;
WarshallFloyd wf = new WarshallFloyd(N);
Edge[] edges = new Edge[M];
for (int i = 0; i < M; i++) {
var a = RInt - 1;
var b = RInt - 1;
var c = RInt;
wf.AddEdge(a, b, c);
wf.AddEdge(b, a, c);
edges[i] = new Edge { f = a, t = b, c = c };
}
bool negative = false;
var d = wf.Start(out negative);
Draw2D(d);
int ans = M;
foreach (var e in edges) {
bool contain = false;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (d[i, j] == d[i, e.t] + e.c + d[e.f, j])
contain = true;
}
}
if (contain)
ans--;
}
Console.WriteLine(ans);
}
struct Edge {
public int f;
public int t;
public int c;
}
}
/// <summary>
/// 全頂点間距離 負の辺に対応、O(V^3)
/// </summary>
class WarshallFloyd {
long INF = long.MaxValue;
int _v;
long[,] dp;
public WarshallFloyd(int V) {
_v = V;
dp = new long[V, V];
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
if (i != j)
dp[i, j] = INF;
}
}
}
public void AddEdge(int from, int to, long cost) { dp[from, to] = cost; }
public long[,] Start(out bool negativeCycle) {
negativeCycle = false;
for (int k = 0; k < _v; k++) {
for (int i = 0; i < _v; i++) {
for (int j = 0; j < _v; j++) {
if (dp[i, k] == long.MaxValue || dp[k, j] == long.MaxValue)
continue;
dp[i, j] = Math.Min(dp[i, j], dp[i, k] + dp[k, j]);
}
if (dp[i, i] < 0)
negativeCycle = true;
}
}
return dp;
}
public long Distance(int from, int to) { return dp[from, to]; }
}
}
namespace Assistant {
static class Input {
static List<string> line = new List<string>();
static int index = 0;
static String RNext() {
if (line.Count <= index)
line.AddRange(Console.ReadLine().Split());
return line[index++];
}
public static int RInt => int.Parse(RNext());
public static long RLong => long.Parse(RNext());
public static int[] RInts =>
Console.ReadLine().Split().Select(int.Parse).ToArray();
public static long[] RLongs =>
Console.ReadLine().Split().Select(long.Parse).ToArray();
public static string RString => RNext();
//以下未テスト
public static int[] RIntsC(int c) =>
Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
public static long[] RLongsC(int c) =>
Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
public static char[][] RMap(int h) =>
Enumerable.Repeat(0, h)
.Select(x => Console.ReadLine().ToCharArray())
.ToArray();
}
public struct Mlong {
long _v;
const long mod = 1000000007;
public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; }
public static implicit operator Mlong(long _x) => new Mlong(_x);
public static implicit operator long(Mlong _x) => _x._v;
public static Mlong operator +(Mlong m1, Mlong m2) {
long m = m1._v + m2._v;
return m >= mod ? m - mod : m;
}
public static Mlong operator -(Mlong m1, Mlong m2) {
long m = m1._v - m2._v;
return m >= 0 ? m : m + mod;
}
public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod;
public static Mlong
operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod;
public static long ModPow(long a, long n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return a * ModPow(a, n - 1) % mod;
else
return ModPow(a * a % mod, n / 2);
}
static Mlong[] fac, finv, inv;
public static void nCkInit(int max) {
fac = new Mlong[max];
finv = new Mlong[max];
inv = new Mlong[max];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < max; i++) {
fac[i] = fac[i - 1] * i;
inv[i] = mod - inv[mod % i] * (mod / i);
finv[i] = finv[i - 1] * inv[i];
}
}
public static Mlong nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k] * finv[n - k];
}
}
static class Debug {
static public void Draw2D<T>(T[,] map, int mode = 1) {
#if DEBUG
int W = map.GetLength(0);
int H = map.GetLength(1);
string[,] map2 = new string[W + 1, H + 1];
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (i == 0 && j == 0)
map2[i, j] = 0.ToString();
else if (i == 0)
map2[i, j] = (j - 1).ToString();
else if (j == 0)
map2[i, j] = (i - 1).ToString();
else
map2[i, j] = map[i - 1, j - 1].ToString();
}
}
for (int i = 0; i < W + 1; i++) {
for (int j = 0; j < H + 1; j++) {
if (mode == 0)
Console.Write(map2[i, j].Last());
if (mode == 1)
Console.Write(map2[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
#endif
}
public static void Draw1D<T>(T[] array, int mode = 0) {
#if DEBUG
Console.WriteLine(string.Join(" ", array));
#endif
}
}
}
|
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 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, 57, 64, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 68]]
| 8
| 1,634
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Numerics;
using static System.Math;
using static System.Array;
using static AtCoder.IO_ShortCut;
using static AtCoder.Tool;
using static AtCoder.ModInt;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
// const int MOD = 998244353;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 };
static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 };
// static List<List<int>> G = new List<List<int>>();
static List<List<Edge>> G = new List<List<Edge>>();
// static List<Edge> E = new List<Edge>();
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
int N, M;
Input(out N, out M);
var D = new long[N, N];
for (var i = 0; i < N; i++)
for (var j = 0; j < N; j++)
D[i, j] = i == j ? 0 : SINF;
var Ea = new int[M];
var Eb = new int[M];
var len = new long[M];
for (var i = 0; i < M; i++) {
int a, b;
long c;
Input(out a, out b, out c);
a--;
b--;
Ea[i] = a;
Eb[i] = b;
len[i] = c;
D[a, b] = D[b, a] = c;
}
for (var k = 0; k < N; k++) {
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
D[i, j] = Min(D[i, j], D[i, k] + D[k, j]);
}
}
}
int ans = 0;
for (var k = 0; k < M; k++) {
bool ok = true;
int a = Ea[k];
int b = Eb[k];
for (var i = 0; i < N; i++) {
for (var j = i + 1; j < N; j++) {
ok &= (D[i, a] + len[k] + D[b, j] != D[i, j]);
}
}
if (ok)
ans++;
}
OutL(ans);
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
}
struct ModInt {
public long value;
private const int MOD = 1000000007;
// private const int MOD = 998244353;
public ModInt(long value) { this.value = value; }
public static implicit operator ModInt(long a) {
var ret = a % MOD;
return new ModInt(ret < 0 ? (ret + MOD) : ret);
}
public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value);
public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value);
public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value);
public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2);
public static ModInt operator <<(ModInt a, int n) => (a.value << n);
public static ModInt operator>>(ModInt a, int n) => (a.value >> n);
public static ModInt operator ++(ModInt a) => a.value + 1;
public static ModInt operator --(ModInt a) => a.value - 1;
public static ModInt Modpow(ModInt a, long n) {
var k = a;
ModInt ret = 1;
while (n > 0) {
if ((n & 1) != 0)
ret *= k;
k *= k;
n >>= 1;
}
return ret;
}
private static readonly List<long> Factorials = new List<long>() { 1 };
public static ModInt Fac(long n) {
for (var i = Factorials.Count(); i <= n; i++) {
Factorials.Add((Factorials[i - 1] * i) % MOD);
}
return Factorials[(int)n];
}
public static ModInt nCr(long n, long r) {
return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(ModInt a) => (int)a.value;
}
static class IO_ShortCut {
public static string[] _ReadSplit => Console.ReadLine().Split();
public static int[] _ReadSplitInt =>
ConvertAll(Console.ReadLine().Split(), int.Parse);
public static long[] _ReadSplitLong =>
ConvertAll(Console.ReadLine().Split(), long.Parse);
public static double[] _ReadSplit_Double =>
ConvertAll(Console.ReadLine().Split(), double.Parse);
public static string Str => Console.ReadLine();
public static int Int => int.Parse(Console.ReadLine());
public static long Long => long.Parse(Console.ReadLine());
public static double Double => double.Parse(Console.ReadLine());
public static T Conv<T>(string input) {
if (typeof(T).Equals(typeof(ModInt))) {
return (T)(dynamic)(long.Parse(input));
}
return (T)Convert.ChangeType(input, typeof(T));
}
public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine());
public static void Input<T, U>(out T a, out U b) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
}
public static void Input<T, U, V>(out T a, out U b, out V c) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
}
public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
d = Conv<W>(q[3]);
}
public static void OutL(object s) => Console.WriteLine(s);
public static void
Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s));
public static void Out_Sep<T>(IEnumerable<T> s, string sep) =>
Console.WriteLine(string.Join($"{sep}", s));
public static void
Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s));
public static void Out_One(object s) => Console.Write($"{s} ");
public static void Out_One(object s,
string sep) => Console.Write($"{s}{sep}");
public static void Endl() => Console.WriteLine();
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = ConvertAll(array, x => initialvalue);
}
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Display<T>(T[,] array2d, int n, int m) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
Console.Write($"{array2d[i, j]} ");
}
Console.WriteLine();
}
}
static public long LPow(int a, int b) => (long)Pow(a, b);
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a));
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Numerics;
using static System.Math;
using static System.Array;
using static AtCoder.IO_ShortCut;
using static AtCoder.Tool;
using static AtCoder.ModInt;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
// const int MOD = 998244353;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 };
static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 };
// static List<List<int>> G = new List<List<int>>();
static List<List<Edge>> G = new List<List<Edge>>();
// static List<Edge> E = new List<Edge>();
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
static void Solve() {
int N, M;
Input(out N, out M);
var D = new long[N, N];
for (var i = 0; i < N; i++)
for (var j = 0; j < N; j++)
D[i, j] = i == j ? 0 : SINF;
var Ea = new int[M];
var Eb = new int[M];
var len = new long[M];
for (var i = 0; i < M; i++) {
int a, b;
long c;
Input(out a, out b, out c);
a--;
b--;
Ea[i] = a;
Eb[i] = b;
len[i] = c;
D[a, b] = D[b, a] = c;
}
for (var k = 0; k < N; k++) {
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
D[i, j] = Min(D[i, j], D[i, k] + D[k, j]);
}
}
}
int ans = 0;
for (var k = 0; k < M; k++) {
bool ok = true;
int a = Ea[k];
int b = Eb[k];
for (var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
ok &= (D[i, a] + len[k] + D[b, j] != D[i, j]);
}
}
if (ok)
ans++;
}
OutL(ans);
}
public struct Edge {
public int from;
public int to;
public long dist;
public Edge(int t, long c) {
from = -1;
to = t;
dist = c;
}
public Edge(int f, int t, long c) {
from = f;
to = t;
dist = c;
}
}
}
struct ModInt {
public long value;
private const int MOD = 1000000007;
// private const int MOD = 998244353;
public ModInt(long value) { this.value = value; }
public static implicit operator ModInt(long a) {
var ret = a % MOD;
return new ModInt(ret < 0 ? (ret + MOD) : ret);
}
public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value);
public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value);
public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value);
public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2);
public static ModInt operator <<(ModInt a, int n) => (a.value << n);
public static ModInt operator>>(ModInt a, int n) => (a.value >> n);
public static ModInt operator ++(ModInt a) => a.value + 1;
public static ModInt operator --(ModInt a) => a.value - 1;
public static ModInt Modpow(ModInt a, long n) {
var k = a;
ModInt ret = 1;
while (n > 0) {
if ((n & 1) != 0)
ret *= k;
k *= k;
n >>= 1;
}
return ret;
}
private static readonly List<long> Factorials = new List<long>() { 1 };
public static ModInt Fac(long n) {
for (var i = Factorials.Count(); i <= n; i++) {
Factorials.Add((Factorials[i - 1] * i) % MOD);
}
return Factorials[(int)n];
}
public static ModInt nCr(long n, long r) {
return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r));
}
public static explicit operator int(ModInt a) => (int)a.value;
}
static class IO_ShortCut {
public static string[] _ReadSplit => Console.ReadLine().Split();
public static int[] _ReadSplitInt =>
ConvertAll(Console.ReadLine().Split(), int.Parse);
public static long[] _ReadSplitLong =>
ConvertAll(Console.ReadLine().Split(), long.Parse);
public static double[] _ReadSplit_Double =>
ConvertAll(Console.ReadLine().Split(), double.Parse);
public static string Str => Console.ReadLine();
public static int Int => int.Parse(Console.ReadLine());
public static long Long => long.Parse(Console.ReadLine());
public static double Double => double.Parse(Console.ReadLine());
public static T Conv<T>(string input) {
if (typeof(T).Equals(typeof(ModInt))) {
return (T)(dynamic)(long.Parse(input));
}
return (T)Convert.ChangeType(input, typeof(T));
}
public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine());
public static void Input<T, U>(out T a, out U b) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
}
public static void Input<T, U, V>(out T a, out U b, out V c) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
}
public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) {
var q = _ReadSplit;
a = Conv<T>(q[0]);
b = Conv<U>(q[1]);
c = Conv<V>(q[2]);
d = Conv<W>(q[3]);
}
public static void OutL(object s) => Console.WriteLine(s);
public static void
Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s));
public static void Out_Sep<T>(IEnumerable<T> s, string sep) =>
Console.WriteLine(string.Join($"{sep}", s));
public static void
Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s));
public static void Out_One(object s) => Console.Write($"{s} ");
public static void Out_One(object s,
string sep) => Console.Write($"{s}{sep}");
public static void Endl() => Console.WriteLine();
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
array = ConvertAll(array, x => initialvalue);
}
static public void Swap<T>(ref T a, ref T b) {
T keep = a;
a = b;
b = keep;
}
static public void Display<T>(T[,] array2d, int n, int m) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
Console.Write($"{array2d[i, j]} ");
}
Console.WriteLine();
}
}
static public long LPow(int a, int b) => (long)Pow(a, b);
static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0;
static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a));
}
}
|
[["-", 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
| 1,934
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dx = { 0, 1, 0, -1 };
static readonly int[] dy = { 1, 0, -1, 0 };
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
var p = cin.SplitRead();
int N = p[0];
int M = p[1];
var d = new long[N, N];
for (var i = 0; i < N; i++)
for (var j = 0; j < N; j++)
d[i, j] = i == j ? 0 : SINF;
var a = new int[N];
var b = new int[N];
var c = new long[N];
for (var i = 0; i < M; i++) {
var input = cin.SplitRead();
a[i] = input[0] - 1;
b[i] = input[1] - 1;
c[i] = input[2];
d[a[i], b[i]] = c[i];
d[b[i], a[i]] = c[i];
}
Warshall_floyd(N, d);
int ans = M;
for (var i = 0; i < M; i++) {
bool nouse = true;
for (var j = 0; j < N; j++) {
if (d[j, a[i]] + c[i] == d[j, b[i]]) {
nouse = false;
}
}
ans -= nouse ? 0 : 1;
}
Console.WriteLine(ans);
}
static public void Warshall_floyd(int n, long[,] dist) {
for (var k = 0; k < n; k++) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < n; j++) {
dist[i, j] = Min(dist[i, j], dist[i, k] + dist[k, j]);
}
}
}
}
}
public class Scanner {
public int[] SplitRead() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] SplitReadL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder {
class AC {
const int MOD = 1000000007;
const int INF = int.MaxValue / 2;
const long SINF = long.MaxValue / 2;
const double EPS = 1e-8;
static readonly int[] dx = { 0, 1, 0, -1 };
static readonly int[] dy = { 1, 0, -1, 0 };
static void Main(string[] args) {
// var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush =
// false }; Console.SetOut(sw);
var cin = new Scanner();
var p = cin.SplitRead();
int N = p[0];
int M = p[1];
var d = new long[N, N];
for (var i = 0; i < N; i++)
for (var j = 0; j < N; j++)
d[i, j] = i == j ? 0 : SINF;
var a = new int[M];
var b = new int[M];
var c = new long[M];
for (var i = 0; i < M; i++) {
var input = cin.SplitRead();
a[i] = input[0] - 1;
b[i] = input[1] - 1;
c[i] = input[2];
d[a[i], b[i]] = c[i];
d[b[i], a[i]] = c[i];
}
Warshall_floyd(N, d);
int ans = M;
for (var i = 0; i < M; i++) {
bool nouse = true;
for (var j = 0; j < N; j++) {
if (d[j, a[i]] + c[i] == d[j, b[i]]) {
nouse = false;
}
}
ans -= nouse ? 0 : 1;
}
Console.WriteLine(ans);
}
static public void Warshall_floyd(int n, long[,] dist) {
for (var k = 0; k < n; k++) {
for (var i = 0; i < n; i++) {
for (var j = 0; j < n; j++) {
dist[i, j] = Min(dist[i, j], dist[i, k] + dist[k, j]);
}
}
}
}
}
public class Scanner {
public int[] SplitRead() {
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
return array;
}
public long[] SplitReadL() {
long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
return array;
}
}
public static class Tool {
static public void Initialize<T>(ref T[] array, T initialvalue) {
for (var i = 0; i < array.Length; i++) {
array[i] = initialvalue;
}
}
}
}
|
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22]]
| 8
| 664
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
// using static System.Globalization.CultureInfo;
class Program {
struct P {
public int index;
public List<int> ad;
public Dictionary<int, int> weights;
public P(int index) {
this.index = index;
ad = new List<int>();
weights = new Dictionary<int, int>();
}
}
class E {
public int index1;
public int index2;
public int weight;
public E(int index1, int index2, int weight) {
this.index1 = index1;
this.index2 = index2;
this.weight = weight;
}
}
static void Main(string[] args) {
var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var ps = new P[nm[0]];
var eg = new E[nm[1]];
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);
ps[input[1] - 1].ad.Add(input[0] - 1);
ps[input[0] - 1].weights[input[1] - 1] = input[2];
ps[input[1] - 1].weights[input[0] - 1] = input[2];
eg[i] = new E(input[0] - 1, input[1] - 1, input[2]);
}
var wei = new int[nm[0], nm[0]];
for (var i = 0; i < nm[0]; i++) {
for (var j = 0; j < nm[0]; j++)
wei[i, j] = int.MaxValue;
wei[i, i] = 0;
var set = new HashSet<int>();
while (true) {
var min = int.MaxValue;
var minj = -1;
for (var j = 0; j < nm[0]; j++)
if (!set.Contains(j) && min > wei[i, j]) {
min = wei[i, j];
minj = j;
}
if (minj == -1)
break;
set.Add(minj);
foreach (var a in ps[minj].ad) {
if (!set.Contains(a) &&
wei[i, a] > wei[i, minj] + ps[minj].weights[a])
wei[i, a] = wei[i, minj] + ps[minj].weights[a];
}
}
}
var res = 0;
foreach (var ege in eg) {
var isTh = false;
for (var i = 0; i < nm[0]; i++)
for (var j = i + 1; j < nm[0]; j++)
if (wei[i, ege.index1] + ege.weight + wei[ege.index2, j] ==
wei[i, j]) {
isTh = true;
break;
}
if (!isTh)
res++;
}
WriteLine(res);
}
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 {
struct P {
public int index;
public List<int> ad;
public Dictionary<int, int> weights;
public P(int index) {
this.index = index;
ad = new List<int>();
weights = new Dictionary<int, int>();
}
}
class E {
public int index1;
public int index2;
public int weight;
public E(int index1, int index2, int weight) {
this.index1 = index1;
this.index2 = index2;
this.weight = weight;
}
}
static void Main(string[] args) {
var nm = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var ps = new P[nm[0]];
var eg = new E[nm[1]];
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);
ps[input[1] - 1].ad.Add(input[0] - 1);
ps[input[0] - 1].weights[input[1] - 1] = input[2];
ps[input[1] - 1].weights[input[0] - 1] = input[2];
eg[i] = new E(input[0] - 1, input[1] - 1, input[2]);
}
var wei = new int[nm[0], nm[0]];
for (var i = 0; i < nm[0]; i++) {
for (var j = 0; j < nm[0]; j++)
wei[i, j] = int.MaxValue;
wei[i, i] = 0;
var set = new HashSet<int>();
while (true) {
var min = int.MaxValue;
var minj = -1;
for (var j = 0; j < nm[0]; j++)
if (!set.Contains(j) && min > wei[i, j]) {
min = wei[i, j];
minj = j;
}
if (minj == -1)
break;
set.Add(minj);
foreach (var a in ps[minj].ad) {
if (!set.Contains(a) &&
wei[i, a] > wei[i, minj] + ps[minj].weights[a])
wei[i, a] = wei[i, minj] + ps[minj].weights[a];
}
}
}
var res = 0;
foreach (var ege in eg) {
var isTh = false;
for (var i = 0; i < nm[0]; i++)
for (var j = 0; j < nm[0]; j++)
if (wei[i, ege.index1] + ege.weight + wei[ege.index2, j] ==
wei[i, j]) {
isTh = true;
break;
}
if (!isTh)
res++;
}
WriteLine(res);
}
private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
private const int MOD = 1000000007;
}
|
[["-", 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], ["+", 8, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 761
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Node {
public List<Edge> edges;
public int cost;
}
class Edge {
public Node node1;
public Node node2;
public int cost;
}
class Procon {
public Procon() {}
static void Main(string[] agrs) { new Procon().Do(); }
Scanner cin;
public int calc(Node[] n, Edge[] e, Node start, Node end) {
for (int i = 0; i < n.Count(); i++) {
n[1].cost = 0;
}
Queue<Node> que = new Queue<Node>();
que.Enqueue(start);
while (que.Count() > 0) {
var node = que.Dequeue();
for (int i = 0; i < node.edges.Count(); i++) {
var edge = node.edges[i];
var cost = node.cost + edge.cost;
if (edge.node1 == node) {
if (edge.node2.cost == 0 || cost < edge.node2.cost) {
edge.node2.cost = cost;
que.Enqueue(edge.node2);
}
} else if (edge.node2 == node) {
if (edge.node1.cost == 0 || cost < edge.node1.cost) {
edge.node1.cost = cost;
que.Enqueue(edge.node1);
}
}
}
}
return end.cost;
}
public void Do() {
cin = new Scanner();
var N = cin.nextInt();
var M = cin.nextInt();
Node[] nodes = new Node[N];
for (int i = 0; i < N; i++) {
nodes[i] = new Node();
nodes[i].edges = new List<Edge>();
}
Edge[] edges = new Edge[M];
for (int i = 0; i < M; i++) {
edges[i] = new Edge();
edges[i].node1 = nodes[cin.nextInt() - 1];
edges[i].node2 = nodes[cin.nextInt() - 1];
edges[i].cost = cin.nextInt();
edges[i].node1.edges.Add(edges[i]);
edges[i].node2.edges.Add(edges[i]);
}
int ret = 0;
for (int i = 0; i < M; i++) {
var cost = calc(nodes, edges, edges[i].node1, edges[i].node2);
if (cost < edges[i].cost) {
ret++;
}
}
Console.WriteLine(ret);
}
}
class Scanner {
string[] s;
int i;
int max_i;
public Scanner() {
s = new string[0];
max_i = 0;
i = 0;
}
public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
} else {
return s[i++];
}
}
public int nextInt() { return int.Parse(nextString()); }
public long nextLong() { return long.Parse(nextString()); }
public double nextDouble() { return double.Parse(nextString()); }
public string[] arrayString() { return Console.ReadLine().Split(' '); }
public int[] arrayInt() {
string[] str = Console.ReadLine().Split(' ');
int[] array = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = int.Parse(str[i]);
}
return array;
}
public long[] arrayLong() {
string[] str = Console.ReadLine().Split(' ');
long[] array = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = long.Parse(str[i]);
}
return array;
}
public double[] arrayDouble() {
string[] str = Console.ReadLine().Split(' ');
double[] array = new double[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = double.Parse(str[i]);
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Node {
public List<Edge> edges;
public int cost;
}
class Edge {
public Node node1;
public Node node2;
public int cost;
}
class Procon {
public Procon() {}
static void Main(string[] agrs) { new Procon().Do(); }
Scanner cin;
public int calc(Node[] n, Edge[] e, Node start, Node end) {
for (int i = 0; i < n.Count(); i++) {
n[i].cost = 0;
}
Queue<Node> que = new Queue<Node>();
que.Enqueue(start);
while (que.Count() > 0) {
var node = que.Dequeue();
for (int i = 0; i < node.edges.Count(); i++) {
var edge = node.edges[i];
var cost = node.cost + edge.cost;
if (edge.node1 == node) {
if (edge.node2.cost == 0 || cost < edge.node2.cost) {
edge.node2.cost = cost;
que.Enqueue(edge.node2);
}
} else if (edge.node2 == node) {
if (edge.node1.cost == 0 || cost < edge.node1.cost) {
edge.node1.cost = cost;
que.Enqueue(edge.node1);
}
}
}
}
return end.cost;
}
public void Do() {
cin = new Scanner();
var N = cin.nextInt();
var M = cin.nextInt();
Node[] nodes = new Node[N];
for (int i = 0; i < N; i++) {
nodes[i] = new Node();
nodes[i].edges = new List<Edge>();
}
Edge[] edges = new Edge[M];
for (int i = 0; i < M; i++) {
edges[i] = new Edge();
edges[i].node1 = nodes[cin.nextInt() - 1];
edges[i].node2 = nodes[cin.nextInt() - 1];
edges[i].cost = cin.nextInt();
edges[i].node1.edges.Add(edges[i]);
edges[i].node2.edges.Add(edges[i]);
}
int ret = 0;
for (int i = 0; i < M; i++) {
var cost = calc(nodes, edges, edges[i].node1, edges[i].node2);
if (cost < edges[i].cost) {
ret++;
}
}
Console.WriteLine(ret);
}
}
class Scanner {
string[] s;
int i;
int max_i;
public Scanner() {
s = new string[0];
max_i = 0;
i = 0;
}
public string nextString() {
if (i >= s.Length) {
s = Console.ReadLine().Split(' ');
max_i = s.Length;
i = 0;
if (max_i == 0) {
return "";
}
return s[i++];
} else {
return s[i++];
}
}
public int nextInt() { return int.Parse(nextString()); }
public long nextLong() { return long.Parse(nextString()); }
public double nextDouble() { return double.Parse(nextString()); }
public string[] arrayString() { return Console.ReadLine().Split(' '); }
public int[] arrayInt() {
string[] str = Console.ReadLine().Split(' ');
int[] array = new int[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = int.Parse(str[i]);
}
return array;
}
public long[] arrayLong() {
string[] str = Console.ReadLine().Split(' ');
long[] array = new long[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = long.Parse(str[i]);
}
return array;
}
public double[] arrayDouble() {
string[] str = Console.ReadLine().Split(' ');
double[] array = new double[str.Length];
for (int i = 0; i < str.Length; i++) {
array[i] = double.Parse(str[i]);
}
return array;
}
}
|
[["-", 31, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 214, 205, 204, 206, 207, 0, 28, 0, 22]]
| 8
| 997
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
// libs ----------
internal class Solution {
public int N, M;
public Graph G;
public void Run() {
// Input
{
var line = Input.ReadIntArray();
N = line[0];
M = line[1];
}
// Graph
G = new Graph(N);
for (int i = 0; i < M; i++) {
var line = Input.ReadIntArray();
int u = line[0] - 1;
int v = line[1] - 1;
int c = line[2];
// 無向グラフ
var e1 = new Edge(u, v, c);
var e2 = new Edge(v, u, c);
e1.Rev = e2;
e2.Rev = e1;
G[u].Edges.Add(e1);
G[v].Edges.Add(e2);
}
for (int i = 0; i < N; i++) {
Dijkstra(i);
}
int ret = 0;
for (int i = 0; i < N; i++) {
var n = G[i];
foreach (var ee in n.Edges) {
if (!ee.Used && !ee.Rev.Used)
ret++;
}
}
Console.WriteLine(ret / 2);
}
public void Dijkstra(int start) {
var pq = new PriorityQueue<EdgeData>();
pq.Push(new EdgeData(0, new Edge(-1, 0, 0)));
for (int i = 0; i < N; i++) {
G[i].Dist = int.MaxValue;
}
while (pq.Count() > 0) {
var d = pq.Pop();
var n = G[d.Edge.To];
if (n.Dist != int.MaxValue) {
if (n.Dist == d.Dist)
d.Edge.Used = true;
continue;
}
d.Edge.Used = true;
n.Dist = d.Dist;
foreach (var ee in n.Edges) {
pq.Push(new EdgeData(d.Dist + ee.Cost, ee));
}
}
}
}
// 通常はIComparableのみが必要
class EdgeData : IComparable<EdgeData>, IComparable {
public int Dist;
public Edge Edge;
public EdgeData(int dist, Edge edge) {
Dist = dist;
Edge = edge;
}
public int CompareTo(EdgeData other) { return Dist.CompareTo(other.Dist); }
public int CompareTo(object obj) {
if (obj == null)
return 1;
if (GetType() != obj.GetType())
throw new ArgumentException();
return CompareTo((EdgeData)obj);
}
}
public class PriorityQueue<T>
where T : IComparable<T> {
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(IComparer<T> comparer) {
_heap = new T[128];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int type = 0) {
_heap = new T[128];
_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++;
if (_count > _heap.Length) {
var newheap = new T[_heap.Length * 2];
for (int n = 0; n < _heap.Length; n++)
newheap[n] = _heap[n];
_heap = newheap;
}
// 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;
}
}
internal class Graph {
public List<Node> Nodes;
public Node this[int i] {
set { Nodes[i] = value; }
get { return Nodes[i]; }
}
public Graph(int N) {
Nodes = new List<Node>();
for (int i = 0; i < N; i++) {
Nodes.Add(new Node(i));
}
}
}
internal class Node {
public List<Edge> Edges;
public int Dist;
public int No;
public Node(int no) {
this.No = no;
Dist = int.MaxValue;
Edges = new List<Edge>();
}
}
internal class Edge {
public int From;
public int To;
public int Cost;
public Edge Rev;
public bool Used;
public Edge(int fr, int to, int cost = 0) {
From = fr;
To = to;
Cost = cost;
}
public bool IsRev(Edge e) { return Rev != null && (e == Rev); }
}
// 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.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive {
// libs ----------
internal class Solution {
public int N, M;
public Graph G;
public void Run() {
// Input
{
var line = Input.ReadIntArray();
N = line[0];
M = line[1];
}
// Graph
G = new Graph(N);
for (int i = 0; i < M; i++) {
var line = Input.ReadIntArray();
int u = line[0] - 1;
int v = line[1] - 1;
int c = line[2];
// 無向グラフ
var e1 = new Edge(u, v, c);
var e2 = new Edge(v, u, c);
e1.Rev = e2;
e2.Rev = e1;
G[u].Edges.Add(e1);
G[v].Edges.Add(e2);
}
for (int i = 0; i < N; i++) {
Dijkstra(i);
}
int ret = 0;
for (int i = 0; i < N; i++) {
var n = G[i];
foreach (var ee in n.Edges) {
if (!ee.Used && !ee.Rev.Used)
ret++;
}
}
Console.WriteLine(ret / 2);
}
public void Dijkstra(int start) {
var pq = new PriorityQueue<EdgeData>();
pq.Push(new EdgeData(0, new Edge(-1, start, 0)));
for (int i = 0; i < N; i++) {
G[i].Dist = int.MaxValue;
}
while (pq.Count() > 0) {
var d = pq.Pop();
var n = G[d.Edge.To];
// Console.Error.WriteLine($"{d.Edge.From} -> {d.Edge.To}, d-dist:{d.Dist}
// n-dist{n.Dist} ");
if (n.Dist != int.MaxValue) {
if (n.Dist == d.Dist) {
d.Edge.Used = true;
// Console.Error.WriteLine($"{d.Edge.From} -> {d.Edge.To},
// d-dist:{d.Dist} n-dist{n.Dist} ");
}
continue;
}
d.Edge.Used = true;
// Console.Error.WriteLine($"{d.Edge.From} -> {d.Edge.To}, d-dist:{d.Dist}
// n-dist{n.Dist} ");
n.Dist = d.Dist;
foreach (var ee in n.Edges) {
pq.Push(new EdgeData(d.Dist + ee.Cost, ee));
}
}
}
}
// 通常はIComparableのみが必要
class EdgeData : IComparable<EdgeData>, IComparable {
public int Dist;
public Edge Edge;
public EdgeData(int dist, Edge edge) {
Dist = dist;
Edge = edge;
}
public int CompareTo(EdgeData other) { return Dist.CompareTo(other.Dist); }
public int CompareTo(object obj) {
if (obj == null)
return 1;
if (GetType() != obj.GetType())
throw new ArgumentException();
return CompareTo((EdgeData)obj);
}
}
public class PriorityQueue<T>
where T : IComparable<T> {
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(IComparer<T> comparer) {
_heap = new T[128];
_comparer = comparer;
}
/// <summary>
/// Priority queue
/// </summary>
/// <param name="type">0: asc, 1:desc</param>
public PriorityQueue(int type = 0) {
_heap = new T[128];
_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++;
if (_count > _heap.Length) {
var newheap = new T[_heap.Length * 2];
for (int n = 0; n < _heap.Length; n++)
newheap[n] = _heap[n];
_heap = newheap;
}
// 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;
}
}
internal class Graph {
public List<Node> Nodes;
public Node this[int i] {
set { Nodes[i] = value; }
get { return Nodes[i]; }
}
public Graph(int N) {
Nodes = new List<Node>();
for (int i = 0; i < N; i++) {
Nodes.Add(new Node(i));
}
}
}
internal class Node {
public List<Edge> Edges;
public int Dist;
public int No;
public Node(int no) {
this.No = no;
Dist = int.MaxValue;
Edges = new List<Edge>();
}
}
internal class Edge {
public int From;
public int To;
public int Cost;
public Edge Rev;
public bool Used;
public Edge(int fr, int to, int cost = 0) {
From = fr;
To = to;
Cost = cost;
}
public bool IsRev(Edge e) { return Rev != null && (e == Rev); }
}
// 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, 28, 0, 230, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 230, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 1,604
| 4
|
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;
class Simple {
int N, M;
int[] a, b, c;
void Solve() {
// input
N = io.Int;
M = io.Int;
a = new int[M];
b = new int[M];
c = new int[M];
for (int i = 0; i < M; ++i) {
a[i] = io.Int;
b[i] = io.Int;
c[i] = io.Int;
a[i]--;
b[i]--;
c[i]--;
}
// cal
int INF = (int)1e9;
int[,] shortestPath = new int[N, N];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
shortestPath[i, j] = INF;
for (int i = 0; i < N; ++i)
shortestPath[i, i] = 0;
for (int i = 0; i < M; ++i)
shortestPath[a[i], b[i]] = shortestPath[b[i], a[i]] = c[i];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
for (int k = 0; k < N; ++k)
shortestPath[j, k] = Math.Min(
shortestPath[j, k], shortestPath[j, i] + shortestPath[i, k]);
int ans = M;
for (int i = 0; i < M; ++i)
for (int j = 0; j < N; ++j)
if (shortestPath[j, a[i]] + c[i] == shortestPath[j, b[i]]) {
ans--;
break;
}
// res
Console.WriteLine(ans);
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) { new Simple().Stream(); }
void Stream() {
Solve();
io.writeFlush();
}
}
class SimpleIO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public SimpleIO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void writeFlush() { Console.Out.Flush(); }
}
|
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;
class Simple {
int N, M;
int[] a, b, c;
void Solve() {
// input
N = io.Int;
M = io.Int;
a = new int[M];
b = new int[M];
c = new int[M];
for (int i = 0; i < M; ++i) {
a[i] = io.Int;
b[i] = io.Int;
c[i] = io.Int;
a[i]--;
b[i]--;
}
// cal
int INF = (int)1e9;
int[,] shortestPath = new int[N, N];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
shortestPath[i, j] = INF;
for (int i = 0; i < N; ++i)
shortestPath[i, i] = 0;
for (int i = 0; i < M; ++i)
shortestPath[a[i], b[i]] = shortestPath[b[i], a[i]] = c[i];
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
for (int k = 0; k < N; ++k)
shortestPath[j, k] = Math.Min(
shortestPath[j, k], shortestPath[j, i] + shortestPath[i, k]);
int ans = M;
for (int i = 0; i < M; ++i)
for (int j = 0; j < N; ++j)
if (shortestPath[j, a[i]] + c[i] == shortestPath[j, b[i]]) {
ans--;
break;
}
// res
Console.WriteLine(ans);
}
SimpleIO io = new SimpleIO();
public static void Main(string[] args) { new Simple().Stream(); }
void Stream() {
Solve();
io.writeFlush();
}
}
class SimpleIO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public SimpleIO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void writeFlush() { Console.Out.Flush(); }
}
|
[["-", 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], ["-", 0, 1, 0, 223, 0, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 68], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
| 8
| 694
| 6
|
//#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();
}
int V, E, C;
List<E> all;
List<E>[] es;
void Solve() {
var I = G();
V = I[0];
E = I[1];
all = new List<E>();
es = new List<E>[V];
for (var i = 0; i < V; i++)
es[i] = new List<E>();
for (var i = 0; i < E; i++) {
I = G();
AddEdge(I[0] - 1, I[1] - 1, I[2]);
}
var d = new int[V, V];
for (var i = 0; i < V; i++) {
var e = DijkstraFrom(0);
for (var j = 0; j < V; j++)
d[i, j] = e[j];
}
var c = E;
foreach (var e in all) {
var flag = false;
for (var i = 0; i < V; i++)
if (d[i, e.From] + e.Cost == d[i, e.To]) {
flag = true;
break;
}
if (flag)
c--;
}
WriteLine(c);
}
void AddEdge(int f, int t, int c) {
var e = new E(f, t, c);
es[f].Add(e);
es[t].Add(new E(t, f, c));
all.Add(e);
C = Max(C, c);
}
int[] DijkstraFrom(int from) {
var d = Enumerable.Repeat(MOD, V).ToArray();
var queue = new DialQueue(C);
d[from] = 0;
queue.Add(from, 0);
while (queue.Any) {
var p = queue.Pop();
var v = p.To;
if (d[v] < p.Cost)
continue;
foreach (var e in es[v]) {
var tmp = d[v] + e.Cost;
if (d[e.To] > tmp) {
if (d[e.To] != MOD)
queue.Move(e.To, d[e.To], tmp);
else
queue.Add(e.To, tmp);
d[e.To] = tmp;
}
}
}
return d;
}
}
struct E {
public int From, To, Cost;
public E(int f, int t, int c) {
From = f;
To = t;
Cost = c;
}
public override string ToString() {
return string.Format("From = {0}, To = {1}, Cost = {2}", From, To, Cost);
}
}
class DialQueue {
public int Count { get; private set; }
int C, offset;
HashSet<int>[] buckets;
HashSet<int> this[int n] {
get { return buckets[(n - offset + offset % C) % C]; }
}
public DialQueue(int c) {
C = c + 1;
buckets = new HashSet<int>[C];
for (var i = 0; i < C; i++)
buckets[i] = new HashSet<int>();
}
public void Add(int v, int d) {
Count++;
this[d].Add(v);
}
public void Move(int v, int prev, int now) {
this[prev].Remove(v);
this[now].Add(v);
}
public bool Any {
get { return Count > 0; }
}
public E Pop() {
Count--;
var t = offset;
while (true) {
var s = this[t];
if (s.Count > 0) {
var v = s.First();
s.Remove(v);
offset = t;
return new E(-1, v, t);
}
t++;
}
}
public override string ToString() {
return string.Format("C = {0}, Offset = {1}, count = {2}", C, offset,
Count);
}
}
|
//#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();
}
int V, E, C;
List<E> all;
List<E>[] es;
void Solve() {
var I = G();
V = I[0];
E = I[1];
all = new List<E>();
es = new List<E>[V];
for (var i = 0; i < V; i++)
es[i] = new List<E>();
for (var i = 0; i < E; i++) {
I = G();
AddEdge(I[0] - 1, I[1] - 1, I[2]);
}
var d = new int[V, V];
for (var i = 0; i < V; i++) {
var e = DijkstraFrom(i);
for (var j = 0; j < V; j++)
d[i, j] = e[j];
}
var c = E;
foreach (var e in all) {
var flag = false;
for (var i = 0; i < V; i++)
if (d[i, e.From] + e.Cost == d[i, e.To]) {
flag = true;
break;
}
if (flag)
c--;
}
WriteLine(c);
}
void AddEdge(int f, int t, int c) {
var e = new E(f, t, c);
es[f].Add(e);
es[t].Add(new E(t, f, c));
all.Add(e);
C = Max(C, c);
}
int[] DijkstraFrom(int from) {
var d = Enumerable.Repeat(MOD, V).ToArray();
var queue = new DialQueue(C);
d[from] = 0;
queue.Add(from, 0);
while (queue.Any) {
var p = queue.Pop();
var v = p.To;
if (d[v] < p.Cost)
continue;
foreach (var e in es[v]) {
var tmp = d[v] + e.Cost;
if (d[e.To] > tmp) {
if (d[e.To] != MOD)
queue.Move(e.To, d[e.To], tmp);
else
queue.Add(e.To, tmp);
d[e.To] = tmp;
}
}
}
return d;
}
}
struct E {
public int From, To, Cost;
public E(int f, int t, int c) {
From = f;
To = t;
Cost = c;
}
public override string ToString() {
return string.Format("From = {0}, To = {1}, Cost = {2}", From, To, Cost);
}
}
class DialQueue {
public int Count { get; private set; }
int C, offset;
HashSet<int>[] buckets;
HashSet<int> this[int n] {
get { return buckets[(n - offset + offset % C) % C]; }
}
public DialQueue(int c) {
C = c + 1;
buckets = new HashSet<int>[C];
for (var i = 0; i < C; i++)
buckets[i] = new HashSet<int>();
}
public void Add(int v, int d) {
Count++;
this[d].Add(v);
}
public void Move(int v, int prev, int now) {
this[prev].Remove(v);
this[now].Add(v);
}
public bool Any {
get { return Count > 0; }
}
public E Pop() {
Count--;
var t = offset;
while (true) {
var s = this[t];
if (s.Count > 0) {
var v = s.First();
s.Remove(v);
offset = t;
return new E(-1, v, t);
}
t++;
}
}
public override string ToString() {
return string.Format("C = {0}, Offset = {1}, count = {2}", C, offset,
Count);
}
}
|
[["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 1,096
| 2
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14 {
enum qResult { REJECT, ENQUEUED, HIT }
class Node {
public Dictionary<int, int> fLen = new Dictionary<int, int>();
public HashSet<int> Checked = new HashSet<int>();
}
class LocalQueue {
Queue<int> nodeNum = new Queue<int>();
Queue<int> totalLen = new Queue<int>();
Queue<HashSet<int>> History = new Queue<HashSet<int>>();
int targetNum;
int th;
public LocalQueue(int target, int len, ref Node[] nodeAry, int me) {
targetNum = target;
th = len;
foreach (var p in nodeAry[me].fLen.Keys) {
if (p == target)
continue;
nodeNum.Enqueue(p);
totalLen.Enqueue(nodeAry[me].fLen[p]);
HashSet<int> h = new HashSet<int>();
h.Add(me);
History.Enqueue(h);
}
}
public qResult Enqueue(int nNum, int tLen, HashSet<int> h) {
//探索済みは捨てる
if (h.Contains(nNum))
return qResult.REJECT;
//現時点でthより距離が大ならば捨ててよい
if (tLen > th)
return qResult.REJECT;
//ターゲットに到達かつ距離が短い場合はHITを返す
//特にEnqueueの必要はない
if (nNum == targetNum)
return qResult.HIT;
//ターゲットに到達してないのでEnqueueして
//次の階層を探す様にする
nodeNum.Enqueue(nNum);
totalLen.Enqueue(tLen);
HashSet<int> newH = new HashSet<int>(h);
newH.Add(nNum);
History.Enqueue(newH);
return qResult.ENQUEUED;
}
public bool Dequeue(out int nNum, out int tLen, out HashSet<int> h) {
//もしQueue枯渇ならばfalseを返す
nNum = -1;
tLen = -1;
h = null;
if (nodeNum.Count == 0)
return false;
// Dequeueする
nNum = nodeNum.Dequeue();
tLen = totalLen.Dequeue();
h = History.Dequeue();
return true;
}
public void ClrQueue() {
nodeNum.Clear();
totalLen.Clear();
History.Clear();
}
}
class Program {
static void Main(string[] args) {
string[] msg = Console.ReadLine().Split(' ');
int N = int.Parse(msg[0]);
int M = int.Parse(msg[1]);
Node[] nodeAry = new Node[N];
for (int i = 0; i < N; i++)
nodeAry[i] = new Node();
for (int i = 0; i < M; i++) {
msg = Console.ReadLine().Split(' ');
int ai = int.Parse(msg[0]) - 1;
int bi = int.Parse(msg[1]) - 1;
int ci = int.Parse(msg[2]);
nodeAry[ai].fLen.Add(bi, ci);
nodeAry[bi].fLen.Add(ai, ci);
}
int count = 0;
for (int i = 0; i < N; i++) {
// Nodeを取得
foreach (var f in nodeAry[i].fLen.Keys) {
if (nodeAry[i].Checked.Contains(f) || nodeAry[f].Checked.Contains(i))
continue;
//取得Nodeとfriendな関係を持つNodeへの
//迂回リンクより最短のリンクを手繰る
//もし直リンクがより迂回リンクの方が距離が短いならばカウンタをインクリメント
//(幅優先検索で距離を算出するが、途中で直リンクより最短が見えた時点で
// 検索を中断して良いはず&直リンクより遠距離確定時点でQueueから捨てて良いはず)
LocalQueue lq = new LocalQueue(f, nodeAry[i].fLen[f], ref nodeAry, i);
int nNum;
int tLen;
HashSet<int> his;
while (lq.Dequeue(out nNum, out tLen, out his)) {
foreach (var nf in nodeAry[nNum].fLen.Keys) {
if (lq.Enqueue(nf, tLen + nodeAry[nNum].fLen[nf], his) ==
qResult.HIT) {
count++;
lq.ClrQueue();
nodeAry[i].Checked.Add(nf);
break;
}
}
}
}
}
Console.WriteLine(count.ToString());
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14 {
enum qResult { REJECT, ENQUEUED, HIT }
class Node {
public Dictionary<int, int> fLen = new Dictionary<int, int>();
public HashSet<int> Checked = new HashSet<int>();
}
class LocalQueue {
Queue<int> nodeNum = new Queue<int>();
Queue<int> totalLen = new Queue<int>();
Queue<HashSet<int>> History = new Queue<HashSet<int>>();
int targetNum;
int th;
public LocalQueue(int target, int len, ref Node[] nodeAry, int me) {
targetNum = target;
th = len;
foreach (var p in nodeAry[me].fLen.Keys) {
if (p == target)
continue;
nodeNum.Enqueue(p);
totalLen.Enqueue(nodeAry[me].fLen[p]);
HashSet<int> h = new HashSet<int>();
h.Add(me);
History.Enqueue(h);
}
}
public qResult Enqueue(int nNum, int tLen, HashSet<int> h) {
//探索済みは捨てる
if (h.Contains(nNum))
return qResult.REJECT;
//現時点でthより距離が大ならば捨ててよい
if (tLen >= th)
return qResult.REJECT;
//ターゲットに到達かつ距離が短い場合はHITを返す
//特にEnqueueの必要はない
if (nNum == targetNum)
return qResult.HIT;
//ターゲットに到達してないのでEnqueueして
//次の階層を探す様にする
nodeNum.Enqueue(nNum);
totalLen.Enqueue(tLen);
HashSet<int> newH = new HashSet<int>(h);
newH.Add(nNum);
History.Enqueue(newH);
return qResult.ENQUEUED;
}
public bool Dequeue(out int nNum, out int tLen, out HashSet<int> h) {
//もしQueue枯渇ならばfalseを返す
nNum = -1;
tLen = -1;
h = null;
if (nodeNum.Count == 0)
return false;
// Dequeueする
nNum = nodeNum.Dequeue();
tLen = totalLen.Dequeue();
h = History.Dequeue();
return true;
}
public void ClrQueue() {
nodeNum.Clear();
totalLen.Clear();
History.Clear();
}
}
class Program {
static void Main(string[] args) {
string[] msg = Console.ReadLine().Split(' ');
int N = int.Parse(msg[0]);
int M = int.Parse(msg[1]);
Node[] nodeAry = new Node[N];
for (int i = 0; i < N; i++)
nodeAry[i] = new Node();
for (int i = 0; i < M; i++) {
msg = Console.ReadLine().Split(' ');
int ai = int.Parse(msg[0]) - 1;
int bi = int.Parse(msg[1]) - 1;
int ci = int.Parse(msg[2]);
nodeAry[ai].fLen.Add(bi, ci);
nodeAry[bi].fLen.Add(ai, ci);
}
int count = 0;
for (int i = 0; i < N; i++) {
// Nodeを取得
foreach (var f in nodeAry[i].fLen.Keys) {
//既に確認済みの組み合わせは省略
if (nodeAry[i].Checked.Contains(f) || nodeAry[f].Checked.Contains(i))
continue;
//取得Nodeとfriendな関係を持つNodeへの
//迂回リンクより最短のリンクを手繰る
//もし直リンクがより迂回リンクの方が距離が短いならばカウンタをインクリメント
//(幅優先検索で距離を算出するが、途中で直リンクより最短が見えた時点で
// 検索を中断して良いはず&直リンクより遠距離確定時点でQueueから捨てて良いはず)
LocalQueue lq = new LocalQueue(f, nodeAry[i].fLen[f], ref nodeAry, i);
int nNum;
int tLen;
HashSet<int> his;
while (lq.Dequeue(out nNum, out tLen, out his)) {
foreach (var nf in nodeAry[nNum].fLen.Keys) {
if (lq.Enqueue(nf, tLen + nodeAry[nNum].fLen[nf], his) ==
qResult.HIT) {
count++;
lq.ClrQueue();
nodeAry[i].Checked.Add(nf);
break;
}
}
}
}
}
Console.WriteLine(count.ToString());
Console.ReadLine();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
| 8
| 845
| 2
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var o = Longs;
var x = o[0];
var y = o[1];
if (x == y) {
Write(0);
return;
}
if (x == 0) {
long a = 0;
if (y < 0) {
++a;
}
a += Abs(y);
Write(a);
return;
}
if (x > y && y > 0) {
Write(x - y + 1);
}
if (y == 0) {
long a = 0;
if (x > 0)
++a;
a += Abs(x);
Write(a);
return;
}
long ans = 0;
if (x < 0 && y < 0) {
if (Abs(x) > Abs(y)) {
Write(Abs(x - y));
return;
}
ans += 2;
} else if (x > 0 && y > 0)
;
else
++ans;
ans += Abs(Abs(y) - Abs(x));
Write(ans);
return;
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long i, long N, long MOD = 1000000007) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long Power2(long i, long N) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i;
i = i * i;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static Math2;
using static io;
using static Utils;
public class CompetitiveProgramming {
public void Solve() {
var o = Longs;
var x = o[0];
var y = o[1];
if (x == y) {
Write(0);
return;
}
if (x == 0) {
long a = 0;
if (y < 0) {
++a;
}
a += Abs(y);
Write(a);
return;
}
if (x > y && y > 0) {
Write(x - y + 2);
return;
}
if (y == 0) {
long a = 0;
if (x > 0)
++a;
a += Abs(x);
Write(a);
return;
}
long ans = 0;
if (x < 0 && y < 0) {
if (Abs(x) > Abs(y)) {
Write(Abs(x - y));
return;
}
ans += 2;
} else if (x > 0 && y > 0)
;
else
++ans;
ans += Abs(Abs(y) - Abs(x));
Write(ans);
return;
}
}
public static class Math2 {
public const int INF = 1 << 29;
public const long INFL = 1L << 60;
public const long MOD = 1000000007;
public const int MOD2 = 998244353;
public static long Power(long i, long N, long MOD = 1000000007) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i % MOD;
i = i * i % MOD;
N >>= 1;
}
return res;
}
public static long Power2(long i, long N) // i^N
{
long res = 1;
while (N > 0) {
if ((N & 1) != 0)
res = res * i;
i = i * i;
N >>= 1;
}
return res;
}
public static long GCD(long i, long N) {
if (i > N)
Swap(ref i, ref N);
if (i == 0)
return N;
while (N != 0) {
var r = i % N;
i = N;
N = r;
}
return i;
}
public static long LCM(long i, long N) => i * N / GCD(i, N);
public static long Comb(long N, long R, int MOD = 1000000007) {
long ret = 1;
long x = 1;
for (long i = N; i >= N - R + 1; --i) {
ret = ret / x * i;
ret %= MOD;
x++;
}
return ret;
}
public static long Comb2(long N, long R) {
long Nume = 1;
long Deno = 1;
if (R > N - R)
Swap(ref N, ref R);
for (long i = 1; i <= R; ++i) {
Deno *= i;
Nume *= N - i + 1;
}
return Deno / Nume;
}
}
public static class Utils {
public static void Swap<T>(ref T A, ref T B) {
T x = A;
A = B;
B = x;
}
public static int DigitSum(int N) {
string s = N.ToString();
int ret = 0;
for (int i = 0; i < s.Length; ++i)
ret += s[i] - '0';
return ret;
}
}
class Program {
static void Main(string[] args) {
var CompetitiveProgramming = new CompetitiveProgramming();
CompetitiveProgramming.Solve();
}
}
public static class io {
public static string Str => Console.ReadLine();
public static string[] Strs => Str.Split(' ');
public static long[] Longs => Strs.Select(long.Parse).ToArray();
public static int[] Ints => Strs.Select(int.Parse).ToArray();
public static char[] Chars => Str.ToArray();
public static double[] Doubles => Strs.Select(double.Parse).ToArray();
public static long Long1 => Longs[0];
public static int Int1 => Ints[0];
public static char Char1 => Chars[0];
public static double Double1 => Doubles[0];
public static long[] VerticalRead(int N) {
long[] A = new long[N];
for (int i = 0; i < N; ++i)
A[i] = Long1;
return A;
}
public static void Write(string a) => Console.WriteLine(a);
public static void Write(params object[] i) => Write(string.Join(" ", i));
public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
public static void Verticalwrite<T>(IEnumerable<T> a) {
foreach (var z in a)
Write(z);
}
public static void YN(bool i) {
if (i)
Write("Yes");
else
Write("No");
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 1,132
| 4
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var X = sc.ReadLong();
var Y = sc.ReadLong();
long ans = 0;
if (X < Y) {
ans = Math.Abs(Math.Abs(Y) - Math.Abs(X));
if (X * Y < -1)
ans++;
} else {
ans = Math.Abs(Math.Abs(Y) - Math.Abs(X)) + 1;
if (X < 0 && Y < 0)
ans++;
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var X = sc.ReadLong();
var Y = sc.ReadLong();
long ans = 0;
if (X < Y) {
ans = Math.Abs(Math.Abs(Y) - Math.Abs(X));
if (X * Y < -1)
ans++;
} else {
ans = Math.Abs(Math.Abs(Y) - Math.Abs(X)) + 1;
if (X * Y > 0)
ans++;
}
Console.WriteLine(ans);
}
static Scanner sc = new Scanner();
}
class Scanner {
string[] S = new string[0];
int Index = 0;
char[] Separators = new char[] { ' ' };
public string Next() {
if (this.Index < this.S.Length)
return this.S[this.Index++];
var line = "";
while (line == "")
line = Console.ReadLine();
this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
if (this.S.Length == 0)
return this.Next();
this.Index = 0;
return this.S[this.Index++];
}
public string ReadStr() { return this.Next(); }
public char ReadChar() { return this.Next()[0]; }
public int ReadInt() { return int.Parse(this.Next()); }
public uint ReadUInt() { return uint.Parse(this.Next()); }
public long ReadLong() { return long.Parse(this.Next()); }
public double ReadDouble() { return double.Parse(this.Next()); }
public int[] ReadIntArray(int n) {
var array = new int[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadInt();
}
return array;
}
public long[] ReadLongArray(int n) {
var array = new long[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadLong();
}
return array;
}
public double[] ReadDoubleArray(int n) {
var array = new double[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadDouble();
}
return array;
}
public char[] ReadCharArray(int n) {
var array = new char[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadChar();
}
return array;
}
public string[] ReadStrArray(int n) {
var array = new string[n];
for (int i = 0; i < array.Length; i++) {
array[i] = this.ReadStr();
}
return array;
}
}
|
[["-", 75, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 75, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 98], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["-", 75, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47]]
| 8
| 653
| 6
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
int x = l[0], y = l[1];
var count = 0;
if (x < y) {
if (x >= 0)
count = y - x;
else
count = Math.Min(y - x, Math.Abs(y + x) + 1);
} else {
if (x >= 0) {
count = Math.Max(x + y + 1, Math.Abs(x + y) + 1);
} else {
count = x - y + 2;
}
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Algorithm {
class Program {
static void Main(string[] args) {
var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
int x = l[0], y = l[1];
var count = 0;
if (x < y) {
if (x >= 0)
count = y - x;
else
count = Math.Min(y - x, Math.Abs(y + x) + 1);
} else {
if (x >= 0) {
count = Math.Min(x - y + 2, Math.Abs(x + y) + 1);
} else {
count = x - y + 2;
}
}
Console.WriteLine(count);
}
}
}
|
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 174
| 6
|
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 xy = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var result = 0;
if (xy[0] < xy[1]) {
if (Abs(xy[0]) >= Abs(xy[1]))
result += xy[1] < 0 ? xy[1] - xy[0] : 1 - xy[1] - xy[0];
else
result += xy[0] >= 0 ? xy[1] - xy[0] : 1 + xy[1] - Abs(xy[0]);
} else {
if (Abs(xy[0]) <= Abs(xy[1]))
result += xy[0] < 0 ? 2 - xy[1] + xy[0] : -xy[1] - xy[0] + 1;
else
result += xy[1] < 0 ? 1 + xy[1] + xy[0] : 2 + xy[0] - xy[1];
}
WriteLine(result);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var xy = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
var result = 0;
if (xy[0] < xy[1]) {
if (Abs(xy[0]) >= Abs(xy[1]))
result += xy[1] <= 0 ? xy[1] - xy[0] : 1 - xy[1] - xy[0];
else
result += xy[0] >= 0 ? xy[1] - xy[0] : 1 + xy[1] - Abs(xy[0]);
} else {
if (Abs(xy[0]) <= Abs(xy[1]))
result += xy[0] < 0 ? 2 - xy[1] + xy[0] : -xy[1] - xy[0] + 1;
else
result += xy[1] <= 0 ? 1 + xy[1] + xy[0] : 2 + xy[0] - xy[1];
}
WriteLine(result);
}
}
|
[["-", 64, 1, 0, 11, 12, 41, 15, 16, 17, 18], ["+", 64, 1, 0, 11, 12, 41, 15, 16, 17, 19], ["-", 75, 1, 0, 11, 12, 41, 15, 16, 17, 18], ["+", 75, 1, 0, 11, 12, 41, 15, 16, 17, 19]]
| 8
| 268
| 4
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
long x = long.Parse(input[0]);
long y = long.Parse(input[1]);
long answer = Math.Abs(Math.Abs(x) - Math.Abs(y));
if (x < y && y < 0 || 0 <= x && x < y)
answer += 0;
else if (y < x && x < 0 || 0 < y && y < x)
answer += 2;
else
answer += 1;
Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。
}
}
|
using System;
using System.Linq; //リストの使用
using System.Collections.Generic;
using System.Text; //テキストの高速出力に必要
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
long x = long.Parse(input[0]);
long y = long.Parse(input[1]);
long answer = Math.Abs(Math.Abs(x) - Math.Abs(y));
if (x < y && y <= 0 || 0 <= x && x < y)
answer += 0;
else if (y < x && x < 0 || 0 < y && y < x)
answer += 2;
else
answer += 1;
Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。
}
}
|
[["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19]]
| 8
| 158
| 2
|
using System.Linq;
using System;
public class Hello {
public const long INF = 99999999999999;
public static void Main() {
var ret = new long[4];
for (int i = 0; i < 4; i++)
ret[i] = INF;
string[] line = Console.ReadLine().Trim().Split(' ');
var x = long.Parse(line[0]);
var y = long.Parse(line[1]);
ret[0] = getAns(x, y);
ret[1] = getAns(x, -y) + 1;
ret[2] = getAns(-x, y) + 1;
ret[3] = getAns(-x, -y) + 2;
Console.WriteLine(ret.Min());
}
public static long getAns(long a, long b) { return a < b ? b - a : INF; }
}
|
using System.Linq;
using System;
public class Hello {
public const long INF = 99999999999999999;
public static void Main() {
var ret = new long[4];
for (int i = 0; i < 4; i++)
ret[i] = INF;
string[] line = Console.ReadLine().Trim().Split(' ');
var x = long.Parse(line[0]);
var y = long.Parse(line[1]);
ret[0] = getAns(x, y);
ret[1] = getAns(x, -y) + 1;
ret[2] = getAns(-x, y) + 1;
ret[3] = getAns(-x, -y) + 2;
Console.WriteLine(ret.Min());
}
public static long getAns(long a, long b) { return a <= b ? b - a : INF; }
}
|
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 37, 0, 41, 15, 16, 17, 18], ["+", 8, 196, 0, 37, 0, 41, 15, 16, 17, 19]]
| 8
| 199
| 4
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int res = 0;
if (a[0] < 0 && a[1] < 0) {
if (a[0] > a[1]) {
res = a[0] - a[1] + 2;
} else {
res = a[1] - a[0];
}
} else if (a[0] >= 0 && a[1] >= 0) {
if (a[0] > a[1]) {
res = a[0] - a[1] + 2;
} else {
res = a[1] - a[0];
}
} else {
res = Math.Min(Math.Abs(a[1] + a[0]) + 1,
(a[1] - a[0] >= 0 ? a[1] - a[0] : int.MaxValue));
}
Console.WriteLine(res);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
int res = 0;
if (a[0] < 0 && a[1] < 0) {
if (a[0] > a[1]) {
res = a[0] - a[1] + 2;
} else {
res = a[1] - a[0];
}
} else if (a[0] > 0 && a[1] > 0) {
if (a[0] > a[1]) {
res = a[0] - a[1] + 2;
} else {
res = a[1] - a[0];
}
} else {
res = Math.Min(Math.Abs(a[1] + a[0]) + 1,
(a[1] - a[0] >= 0 ? a[1] - a[0] : int.MaxValue));
}
Console.WriteLine(res);
}
}
|
[["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 20], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 47], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 20], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 47]]
| 8
| 242
| 4
|
using System;
using System.Linq;
namespace agc008_a {
class Program {
static void Main(string[] args) {
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int min = 2147483647;
if (x[0] <= x[1]) {
min = Math.Min(min, x[1] - x[0]);
}
if (x[0] * -1 <= x[1]) {
min = Math.Min(min, x[1] - x[0] * -1);
}
if (x[0] <= x[1] * -1) {
min = Math.Min(min, x[1] * -1 - x[0]);
}
if (x[0] * -1 <= x[1] * -1) {
min = Math.Min(min, x[1] * -1 - x[0] * -1);
}
Console.WriteLine(min);
}
}
}
|
using System;
using System.Linq;
namespace agc008_a {
class Program {
static void Main(string[] args) {
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int min = 2147483647;
if (x[0] <= x[1]) {
min = Math.Min(min, x[1] - x[0]);
}
if (x[0] * -1 <= x[1]) {
min = Math.Min(min, x[1] - x[0] * -1 + 1);
}
if (x[0] <= x[1] * -1) {
min = Math.Min(min, x[1] * -1 - x[0] + 1);
}
if (x[0] * -1 <= x[1] * -1) {
min = Math.Min(min, x[1] * -1 - x[0] * -1 + 2);
}
Console.WriteLine(min);
}
}
}
|
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
| 8
| 221
| 6
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program {
public void Proc() {
Reader.IsDebug = false;
long[] inpt =
Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
long abs1 = Math.Abs(inpt[0]);
long abs2 = Math.Abs(inpt[1]);
long ans = Math.Abs(abs1 - abs2);
if (inpt[0] == 0) {
ans = Math.Abs(inpt[1]);
if (inpt[1] < 0) {
ans++;
}
} else if (inpt[1] == 0) {
ans = Math.Abs(inpt[0]);
if (inpt[0] >= 0) {
ans++;
}
} else if (abs1 > abs2) {
if (inpt[0] >= 0) {
ans++;
if (inpt[1] > 0) {
ans++;
}
}
} else if (abs1 < abs2) {
if (inpt[0] < 0) {
ans++;
if (inpt[1] < 0) {
ans++;
}
}
} else {
ans++;
}
Console.WriteLine(ans);
}
public class Reader {
public static bool IsDebug = true;
private static String PlainInput = @"
0 -1
";
private static System.IO.StringReader Sr = null;
public static string ReadLine() {
if (IsDebug) {
if (Sr == null) {
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
} else {
return Console.ReadLine();
}
}
}
static void Main() {
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program {
public void Proc() {
Reader.IsDebug = false;
long[] inpt =
Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
long abs1 = Math.Abs(inpt[0]);
long abs2 = Math.Abs(inpt[1]);
long ans = Math.Abs(abs1 - abs2);
if (inpt[0] == 0) {
ans = Math.Abs(inpt[1]);
if (inpt[1] < 0) {
ans++;
}
} else if (inpt[1] == 0) {
ans = Math.Abs(inpt[0]);
if (inpt[0] >= 0) {
ans++;
}
} else if (abs1 > abs2) {
if (inpt[0] >= 0) {
ans++;
}
if (inpt[1] > 0) {
ans++;
}
} else if (abs1 < abs2) {
if (inpt[0] < 0) {
ans++;
}
if (inpt[1] < 0) {
ans++;
}
} else {
ans++;
}
Console.WriteLine(ans);
}
public class Reader {
public static bool IsDebug = true;
private static String PlainInput = @"
-4 3
";
private static System.IO.StringReader Sr = null;
public static string ReadLine() {
if (IsDebug) {
if (Sr == null) {
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
} else {
return Console.ReadLine();
}
}
}
static void Main() {
Program prg = new Program();
prg.Proc();
}
}
|
[["+", 75, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
| 8
| 377
| 6
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AGC008 {
public class A {
private void Run() {
var input = Console.ReadLine().Trim().Split();
var x = long.Parse(input[0]);
var y = long.Parse(input[1]);
long res = Math.Abs(Math.Abs(x) - Math.Abs(y));
if (x >= 0) {
if (x > y) {
if (y > 0) {
res += 2;
} else {
res += 1;
}
}
} else {
if (-x <= y) {
res += 1;
}
if (x > y) {
res += 2;
}
}
Console.WriteLine(res);
}
public static void Main() {
var old = Console.Out;
using (var writer = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false }) {
Console.SetOut(writer);
new A().Run();
Console.Out.Flush();
Console.SetOut(old);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AGC008 {
public class A {
private void Run() {
var input = Console.ReadLine().Trim().Split();
var x = long.Parse(input[0]);
var y = long.Parse(input[1]);
long res = Math.Abs(Math.Abs(x) - Math.Abs(y));
if (x >= 0) {
if (x > y) {
if (y > 0) {
res += 2;
} else {
res += 1;
}
}
} else {
if (y > 0) {
res += 1;
}
if (x > y) {
res += 2;
}
}
Console.WriteLine(res);
}
public static void Main() {
var old = Console.Out;
using (var writer = new System.IO.StreamWriter(
Console.OpenStandardOutput()) { AutoFlush = false }) {
Console.SetOut(writer);
new A().Run();
Console.Out.Flush();
Console.SetOut(old);
}
}
}
}
|
[["-", 75, 196, 0, 57, 15, 16, 31, 241, 0, 33], ["-", 75, 196, 0, 57, 15, 16, 31, 241, 0, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203]]
| 8
| 243
| 5
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { AGC008.B(); }
class AGC008 {
public static void A() {
var X = Read.Int();
var Y = Read.Int();
var AX = Math.Abs(X);
var AY = Math.Abs(Y);
if (AX == AY) {
Console.WriteLine(1);
} else if (AX < AY) {
Console.WriteLine(AY - AX + (X < 0 ? 1 : 0) + (Y < 0 ? 1 : 0));
} else {
Console.WriteLine(AX - AY + (X > 0 ? 1 : 0) + (Y > 0 ? 1 : 0));
}
}
public static void B() {
var N = Read.Int();
var K = Read.Long();
var A = Read.LongN();
var Asum = new long[N + 1];
var Bsum = new long[N + 1];
for (int i = 0; i < N; ++i) {
Asum[i + 1] = Asum[i] + A[i];
Bsum[i + 1] = Bsum[i] + Math.Max(0, A[i]);
}
long max = 0;
for (int i = 0; i < N - K + 1; ++i) {
long score = Bsum[i] - Bsum[0] +
Math.Max(0, Asum[i + K] - Asum[i + 1]) + Bsum[N] -
Bsum[K + i];
max = Math.Max(max, score);
}
Console.WriteLine(max);
}
public static void C() {
var A = Read.LongN();
var AI = A[0];
var AO = A[1];
var AJ = A[3];
var AL = A[4];
var K1 = AI / 2 * 2 + AO + AJ / 2 * 2 + AL / 2 * 2;
var K2 =
AI > 0 && AJ > 0 && AL > 0
? (AI - 1) / 2 * 2 + AO + (AJ - 1) / 2 * 2 + (AL - 1) / 2 * 2 + 2
: 0;
Console.WriteLine(Math.Max(K1, K2));
}
}
class Util {}
static class Read {
static Queue<string> queue = new Queue<string>();
static void Enqueue() {
var ss = Console.ReadLine().Split(' ');
foreach (var s in ss) {
queue.Enqueue(s);
}
}
public static int Int() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt32(queue.Dequeue());
}
public static long Long() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt64(queue.Dequeue());
}
public static string Str() {
if (queue.Count == 0) {
Enqueue();
}
return queue.Dequeue();
}
public static int[] IntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
public static long[] LongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = Read.IntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<long, long>[] TupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<string, string>[] TupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = Read.StrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<double, double>[] TupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
public static long[,] LongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = Read.LongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) {
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new HashSet<int>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1]);
dict[ab[1]].Add(ab[0]);
}
return dict;
}
public static Dictionary<int, Dictionary<int, long>>
AdjacencyListWithWeight(int N, int M) {
Dictionary<int, Dictionary<int, long>> dict =
new Dictionary<int, Dictionary<int, long>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new Dictionary<int, long>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1], ab[2]);
dict[ab[1]].Add(ab[0], ab[2]);
}
return dict;
}
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
namespace Contest {
class Program {
static void Main(string[] args) { AGC008.B(); }
class AGC008 {
public static void A() {
var X = Read.Int();
var Y = Read.Int();
var AX = Math.Abs(X);
var AY = Math.Abs(Y);
if (AX == AY) {
Console.WriteLine(1);
} else if (AX < AY) {
Console.WriteLine(AY - AX + (X < 0 ? 1 : 0) + (Y < 0 ? 1 : 0));
} else {
Console.WriteLine(AX - AY + (X > 0 ? 1 : 0) + (Y > 0 ? 1 : 0));
}
}
public static void B() {
var N = Read.Int();
var K = Read.Long();
var A = Read.LongN();
var Asum = new long[N + 1];
var Bsum = new long[N + 1];
for (int i = 0; i < N; ++i) {
Asum[i + 1] = Asum[i] + A[i];
Bsum[i + 1] = Bsum[i] + Math.Max(0, A[i]);
}
long max = 0;
for (int i = 0; i < N - K + 1; ++i) {
long score = Bsum[i] - Bsum[0] + Math.Max(0, Asum[i + K] - Asum[i]) +
Bsum[N] - Bsum[i + K];
max = Math.Max(max, score);
}
Console.WriteLine(max);
}
public static void C() {
var A = Read.LongN();
var AI = A[0];
var AO = A[1];
var AJ = A[3];
var AL = A[4];
var K1 = AI / 2 * 2 + AO + AJ / 2 * 2 + AL / 2 * 2;
var K2 =
AI > 0 && AJ > 0 && AL > 0
? (AI - 1) / 2 * 2 + AO + (AJ - 1) / 2 * 2 + (AL - 1) / 2 * 2 + 2
: 0;
Console.WriteLine(Math.Max(K1, K2));
}
}
class Util {}
static class Read {
static Queue<string> queue = new Queue<string>();
static void Enqueue() {
var ss = Console.ReadLine().Split(' ');
foreach (var s in ss) {
queue.Enqueue(s);
}
}
public static int Int() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt32(queue.Dequeue());
}
public static long Long() {
if (queue.Count == 0) {
Enqueue();
}
return Convert.ToInt64(queue.Dequeue());
}
public static string Str() {
if (queue.Count == 0) {
Enqueue();
}
return queue.Dequeue();
}
public static int[] IntN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt32(s))
.ToArray();
}
public static long[] LongN() {
return Console.ReadLine()
.Split(' ')
.Select(s => Convert.ToInt64(s))
.ToArray();
}
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) {
List<Tuple<int, int>> list = new List<Tuple<int, int>>();
for (int i = 0; i < n; ++i) {
var ab = Read.IntN();
list.Add(new Tuple<int, int>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<long, long>[] TupleLong(int n) {
List<Tuple<long, long>> list = new List<Tuple<long, long>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<long, long>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<string, string>[] TupleStr(int n) {
List<Tuple<string, string>> list = new List<Tuple<string, string>>();
for (int i = 0; i < n; ++i) {
var ab = Read.StrN();
list.Add(new Tuple<string, string>(ab[0], ab[1]));
}
return list.ToArray();
}
public static Tuple<double, double>[] TupleDouble(int n) {
List<Tuple<double, double>> list = new List<Tuple<double, double>>();
for (int i = 0; i < n; ++i) {
var ab = Read.LongN();
list.Add(new Tuple<double, double>(ab[0], ab[1]));
}
return list.ToArray();
}
public static long[,] LongMatrix(int r, int c) {
var mat = new long[r, c];
for (int i = 0; i < r; ++i) {
var x = Read.LongN();
for (int j = 0; j < c; ++j) {
mat[i, j] = x[j];
}
}
return mat;
}
public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) {
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new HashSet<int>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1]);
dict[ab[1]].Add(ab[0]);
}
return dict;
}
public static Dictionary<int, Dictionary<int, long>>
AdjacencyListWithWeight(int N, int M) {
Dictionary<int, Dictionary<int, long>> dict =
new Dictionary<int, Dictionary<int, long>>();
for (int i = 0; i <= N; ++i) {
dict.Add(i, new Dictionary<int, long>());
}
for (int i = 0; i < M; ++i) {
var ab = Read.IntN();
dict[ab[0]].Add(ab[1], ab[2]);
dict[ab[1]].Add(ab[0], ab[2]);
}
return dict;
}
}
}
}
|
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
| 8
| 1,540
| 6
|
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 k = long.Parse(input[1]);
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long[] sums = new long[n]; //累積和
long[] sumsPlus = new long[n]; //正のみの累積和
long answer = 0;
sums[0] = nums[0];
if (nums[0] > 0)
sumsPlus[0] = nums[0];
for (long i = 1; i < n; i++) //累積和の計算
{
sums[i] = sums[i - 1] + nums[i];
if (nums[i] > 0)
sumsPlus[i] = sumsPlus[i - 1] + nums[i];
else
sumsPlus[i] = sumsPlus[i - 1];
}
for (long i = 0; i < n - k; i++) {
long memo = 0;
if (i > 0)
memo = sumsPlus[i - 1]; //左の自由和
memo += sumsPlus[n - 1] - sumsPlus[k + i - 1]; //右の自由和
if (i > 0) {
if (sums[k + i - 1] - sums[i - 1] > 0)
memo += sums[k + i - 1] - sums[i - 1];
} else {
if (sums[k + i - 1] > 0)
memo += sums[k + i - 1];
}
answer = Math.Max(answer, memo);
}
Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。
}
}
|
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 k = long.Parse(input[1]);
long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long[] sums = new long[n]; //累積和
long[] sumsPlus = new long[n]; //正のみの累積和
long answer = 0;
sums[0] = nums[0];
if (nums[0] > 0)
sumsPlus[0] = nums[0];
for (long i = 1; i < n; i++) //累積和の計算
{
sums[i] = sums[i - 1] + nums[i];
if (nums[i] > 0)
sumsPlus[i] = sumsPlus[i - 1] + nums[i];
else
sumsPlus[i] = sumsPlus[i - 1];
}
for (long i = 0; i < n - k + 1; i++) {
long memo = 0;
if (i > 0)
memo = sumsPlus[i - 1]; //左の自由和
memo += sumsPlus[n - 1] - sumsPlus[k + i - 1]; //右の自由和
if (i > 0) {
if (sums[k + i - 1] - sums[i - 1] > 0)
memo += sums[k + i - 1] - sums[i - 1];
} else {
if (sums[k + i - 1] > 0)
memo += sums[k + i - 1];
}
answer = Math.Max(answer, memo);
}
Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。
}
}
|
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
| 8
| 380
| 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.